diff --git a/common/validators.cpp b/common/validators.cpp index c8296c951e..eb0adad19d 100644 --- a/common/validators.cpp +++ b/common/validators.cpp @@ -167,7 +167,7 @@ void ENV_VAR_NAME_VALIDATOR::OnTextChanged( wxCommandEvent& event ) NETNAME_VALIDATOR::NETNAME_VALIDATOR( wxString *aVal ) : wxTextValidator(), - m_allowSpaces( false ) + m_allowSpaces( true ) { } diff --git a/qa/tests/common/CMakeLists.txt b/qa/tests/common/CMakeLists.txt index 967f03fb6a..9f6dcb325a 100644 --- a/qa/tests/common/CMakeLists.txt +++ b/qa/tests/common/CMakeLists.txt @@ -92,6 +92,8 @@ set( QA_COMMON_SRCS view/test_zoom_controller.cpp + test_netname_validator.cpp + # GAL tests test_gal_xor_mode.cpp diff --git a/qa/tests/common/test_netname_validator.cpp b/qa/tests/common/test_netname_validator.cpp new file mode 100644 index 0000000000..9c9bf8f192 --- /dev/null +++ b/qa/tests/common/test_netname_validator.cpp @@ -0,0 +1,88 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include + +#include + + +BOOST_AUTO_TEST_SUITE( NetnameValidator ) + + +struct ValidatorFixture +{ + ValidatorFixture() : m_validatorAllowSpaces( true ), m_validatorNoSpaces( false ) + { + } + + NETNAME_VALIDATOR m_validatorDefault; + NETNAME_VALIDATOR m_validatorAllowSpaces; + NETNAME_VALIDATOR m_validatorNoSpaces; +}; + + +BOOST_FIXTURE_TEST_CASE( DefaultValidatorAllowsSpaces, ValidatorFixture ) +{ + // Default validator should allow spaces (issue #9258) + BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net with spaces" ) ).IsEmpty() ); + BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Single_word" ) ).IsEmpty() ); + BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net name with multiple spaces" ) ).IsEmpty() ); +} + + +BOOST_FIXTURE_TEST_CASE( ValidatorAllowsSpacesWhenConfigured, ValidatorFixture ) +{ + // Validator with allowSpaces=true should allow spaces + BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Net with spaces" ) ).IsEmpty() ); + BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Single_word" ) ).IsEmpty() ); +} + + +BOOST_FIXTURE_TEST_CASE( ValidatorRejectsSpacesWhenConfigured, ValidatorFixture ) +{ + // Validator with allowSpaces=false should reject spaces + BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net with spaces" ) ).IsEmpty() ); + BOOST_CHECK( m_validatorNoSpaces.IsValid( wxS( "Single_word" ) ).IsEmpty() ); +} + + +BOOST_FIXTURE_TEST_CASE( ValidatorRejectsControlCharacters, ValidatorFixture ) +{ + // All validators should reject CR and LF + BOOST_CHECK( !m_validatorDefault.IsValid( wxS( "Net\nname" ) ).IsEmpty() ); + BOOST_CHECK( !m_validatorDefault.IsValid( wxS( "Net\rname" ) ).IsEmpty() ); + BOOST_CHECK( !m_validatorAllowSpaces.IsValid( wxS( "Net\nname" ) ).IsEmpty() ); + BOOST_CHECK( !m_validatorAllowSpaces.IsValid( wxS( "Net\rname" ) ).IsEmpty() ); + BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\nname" ) ).IsEmpty() ); + BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\rname" ) ).IsEmpty() ); +} + + +BOOST_FIXTURE_TEST_CASE( ValidatorRejectsTabsWhenSpacesDisallowed, ValidatorFixture ) +{ + // Validator with allowSpaces=false should reject tabs + BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() ); + + // Default and allowSpaces=true should accept tabs (they're treated like spaces) + BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() ); + BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() ); +} + + +BOOST_AUTO_TEST_SUITE_END()