KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_netname_validator.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <validators.h>
23
24
25BOOST_AUTO_TEST_SUITE( NetnameValidator )
26
27
38
39
40BOOST_FIXTURE_TEST_CASE( DefaultValidatorAllowsSpaces, ValidatorFixture )
41{
42 // Default validator should allow spaces (issue #9258)
43 BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net with spaces" ) ).IsEmpty() );
44 BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Single_word" ) ).IsEmpty() );
45 BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net name with multiple spaces" ) ).IsEmpty() );
46}
47
48
49BOOST_FIXTURE_TEST_CASE( ValidatorAllowsSpacesWhenConfigured, ValidatorFixture )
50{
51 // Validator with allowSpaces=true should allow spaces
52 BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Net with spaces" ) ).IsEmpty() );
53 BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Single_word" ) ).IsEmpty() );
54}
55
56
57BOOST_FIXTURE_TEST_CASE( ValidatorRejectsSpacesWhenConfigured, ValidatorFixture )
58{
59 // Validator with allowSpaces=false should reject spaces
60 BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net with spaces" ) ).IsEmpty() );
61 BOOST_CHECK( m_validatorNoSpaces.IsValid( wxS( "Single_word" ) ).IsEmpty() );
62}
63
64
65BOOST_FIXTURE_TEST_CASE( ValidatorRejectsControlCharacters, ValidatorFixture )
66{
67 // All validators should reject CR and LF
68 BOOST_CHECK( !m_validatorDefault.IsValid( wxS( "Net\nname" ) ).IsEmpty() );
69 BOOST_CHECK( !m_validatorDefault.IsValid( wxS( "Net\rname" ) ).IsEmpty() );
70 BOOST_CHECK( !m_validatorAllowSpaces.IsValid( wxS( "Net\nname" ) ).IsEmpty() );
71 BOOST_CHECK( !m_validatorAllowSpaces.IsValid( wxS( "Net\rname" ) ).IsEmpty() );
72 BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\nname" ) ).IsEmpty() );
73 BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\rname" ) ).IsEmpty() );
74}
75
76
77BOOST_FIXTURE_TEST_CASE( ValidatorRejectsTabsWhenSpacesDisallowed, ValidatorFixture )
78{
79 // Validator with allowSpaces=false should reject tabs
80 BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() );
81
82 // Default and allowSpaces=true should accept tabs (they're treated like spaces)
83 BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() );
84 BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() );
85}
86
87
NETNAME_VALIDATOR m_validatorAllowSpaces
NETNAME_VALIDATOR m_validatorNoSpaces
NETNAME_VALIDATOR m_validatorDefault
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(DefaultValidatorAllowsSpaces, ValidatorFixture)
Custom text control validator definitions.