diff --git a/qa/common/CMakeLists.txt b/qa/common/CMakeLists.txt index 1fafa607cb..54a6d3fb73 100644 --- a/qa/common/CMakeLists.txt +++ b/qa/common/CMakeLists.txt @@ -45,7 +45,7 @@ set( common_srcs libeval/test_numeric_evaluator.cpp - plugin/altium/test_altium_parser.cpp + plugins/altium/test_altium_parser.cpp view/test_zoom_controller.cpp ) diff --git a/qa/common/plugin/altium/test_altium_parser.cpp b/qa/common/plugins/altium/test_altium_parser.cpp similarity index 99% rename from qa/common/plugin/altium/test_altium_parser.cpp rename to qa/common/plugins/altium/test_altium_parser.cpp index 5c2cdd68a6..11f8bd3652 100644 --- a/qa/common/plugin/altium/test_altium_parser.cpp +++ b/qa/common/plugins/altium/test_altium_parser.cpp @@ -22,7 +22,7 @@ */ /** - * @file test_altium_parserr.cpp + * @file test_altium_parser.cpp * Test suite for #ALTIUM_PARSER */ diff --git a/qa/eeschema/CMakeLists.txt b/qa/eeschema/CMakeLists.txt index daa3632a83..5d4c488c9b 100644 --- a/qa/eeschema/CMakeLists.txt +++ b/qa/eeschema/CMakeLists.txt @@ -48,6 +48,8 @@ set( QA_EESCHEMA_SRCS ${CMAKE_SOURCE_DIR}/qa/common/test_format_units.cpp ${CMAKE_SOURCE_DIR}/qa/common/test_array_options.cpp + sch_plugins/altium/test_altium_parser_sch.cpp + test_eagle_plugin.cpp test_lib_arc.cpp test_lib_part.cpp diff --git a/qa/eeschema/sch_plugins/altium/test_altium_parser_sch.cpp b/qa/eeschema/sch_plugins/altium/test_altium_parser_sch.cpp new file mode 100644 index 0000000000..9e152b7839 --- /dev/null +++ b/qa/eeschema/sch_plugins/altium/test_altium_parser_sch.cpp @@ -0,0 +1,107 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2021 KiCad Developers, see CHANGELOG.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 2 + * 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, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * @file test_altium_parser_sch.cpp + * Test suite for #ALTIUM_PARSER_SCH + */ + +#include + +#include + +// Function declarations of private methods to test +int PropertiesReadKiCadUnitFrac( const std::map& aProperties, + const wxString& aKey ); + + +struct ALTIUM_PARSER_SCH_FIXTURE +{ + ALTIUM_PARSER_SCH_FIXTURE() {} +}; + + +/** + * Declares the struct as the Boost test fixture. + */ +BOOST_FIXTURE_TEST_SUITE( AltiumParserSch, ALTIUM_PARSER_SCH_FIXTURE ) + +struct ALTIUM_TO_KICAD_UNIT_FRAC_CASE +{ + wxString input; + wxString input_frac; + int exp_result; +}; + +/** + * A list of valid internal unit conversation factors + */ +static const std::vector altium_to_kicad_unit_frac = { + // Some simple values + { "0", "0", 0 }, + { "1", "0", 2540 }, + { "2", "0", 5080 }, + { "-1", "0", -2540 }, + { "-2", "0", -5080 }, + // Decimal Places + { "0", "1", 0 }, + { "0", "10", 0 }, + { "0", "100", 2 }, + { "0", "1000", 25 }, + { "0", "10000", 254 }, + { "1", "10000", 2794 }, + { "0", "-1", 0 }, + { "0", "-10", 0 }, + { "0", "-100", -2 }, + { "0", "-1000", -25 }, + { "0", "-10000", -254 }, + { "-1", "-10000", -2794 }, + // Edge Cases + // Clamp bigger values + // imperial rounded units as input + // metric rounded units as input +}; + +/** + * Test conversation from Altium internal units into KiCad internal units using properties with FRAC + */ +BOOST_AUTO_TEST_CASE( PropertiesReadKiCadUnitFracConversation ) +{ + for( const auto& c : altium_to_kicad_unit_frac ) + { + BOOST_TEST_CONTEXT( + wxString::Format( wxT( "%s FRAC %s -> %i" ), c.input, c.input_frac, c.exp_result ) ) + { + std::map properties = { { "TEST", c.input }, + { "TEST_FRAC", c.input_frac } }; + + int result = PropertiesReadKiCadUnitFrac( properties, "TEST" ); + + // These are all valid + BOOST_CHECK_EQUAL( result, c.exp_result ); + } + } +} + + +BOOST_AUTO_TEST_SUITE_END()