2021-03-14 15:40:36 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-10-06 02:46:53 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.TXT for contributors.
|
2021-03-14 15:40:36 +00:00
|
|
|
*
|
|
|
|
* 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_utils.cpp
|
|
|
|
* Test suite for #ALTIUM_PARSER
|
|
|
|
*/
|
|
|
|
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2021-03-14 15:40:36 +00:00
|
|
|
|
|
|
|
#include <common/plugins/altium/altium_parser_utils.h>
|
|
|
|
|
|
|
|
struct ALTIUM_PARSER_UTILS_FIXTURE
|
|
|
|
{
|
|
|
|
ALTIUM_PARSER_UTILS_FIXTURE() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declares the struct as the Boost test fixture.
|
|
|
|
*/
|
|
|
|
BOOST_FIXTURE_TEST_SUITE( AltiumParserUtils, ALTIUM_PARSER_UTILS_FIXTURE )
|
|
|
|
|
|
|
|
|
|
|
|
struct SPECIAL_STRINGS_TO_KICAD
|
|
|
|
{
|
2021-07-08 13:14:27 +00:00
|
|
|
wxString input;
|
|
|
|
wxString exp_result;
|
|
|
|
std::map<wxString, wxString> override;
|
2021-03-14 15:40:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of valid test strings and the expected results
|
|
|
|
*/
|
|
|
|
static const std::vector<SPECIAL_STRINGS_TO_KICAD> special_string_to_kicad_property = {
|
|
|
|
// Empty
|
|
|
|
{ "", "", {} },
|
|
|
|
// No Special Strings
|
|
|
|
{ "A", "A", {} },
|
|
|
|
{ " A", " A", {} },
|
|
|
|
{ "A ", "A ", {} },
|
|
|
|
{ "A=B", "A=B", {} },
|
|
|
|
{ "A=B+C", "A=B+C", {} },
|
|
|
|
{ "A\nB", "A\nB", {} },
|
|
|
|
{ "A\tB", "A\tB", {} },
|
|
|
|
{ "This is a long text with spaces", "This is a long text with spaces", {} },
|
|
|
|
// Text format (underscore,...), TODO: add
|
|
|
|
// Escaping, TODO: add
|
2021-03-20 18:25:15 +00:00
|
|
|
{ "+", "+", {} },
|
|
|
|
{ "'", "'", {} },
|
|
|
|
{ "'A'", "'A'", {} },
|
|
|
|
{ "A+B", "A+B", {} },
|
2021-03-14 15:40:36 +00:00
|
|
|
{ "A=B", "A=B", {} },
|
2021-03-20 18:25:15 +00:00
|
|
|
{ "$", "$", {} },
|
|
|
|
{ "{", "{", {} },
|
|
|
|
{ "}", "}", {} },
|
|
|
|
{ "${A}", "${A}", {} }, // TODO: correct substitution
|
2021-03-14 15:40:36 +00:00
|
|
|
// Simple special strings
|
|
|
|
{ "=A", "${A}", {} },
|
2021-07-08 13:14:27 +00:00
|
|
|
{ "=A", "${C}", { { "A", "C" } } },
|
2021-03-14 15:40:36 +00:00
|
|
|
{ "=A_B", "${A_B}", {} },
|
|
|
|
// Combined special strings
|
|
|
|
{ "=A+B", "${A}${B}", {} },
|
|
|
|
{ "=A+B", "${A}${B}", {} },
|
2021-07-08 13:14:27 +00:00
|
|
|
{ "=A+B", "${C}${B}", { { "A", "C" } } },
|
|
|
|
{ "=A+B", "${C}${D}", { { "A", "C" }, { "B", "D" } } },
|
2021-03-20 19:41:51 +00:00
|
|
|
// Case insensitive special strings
|
2021-07-08 13:14:27 +00:00
|
|
|
{ "=A", "${C}", { { "A", "C" } } },
|
|
|
|
{ "=a", "${C}", { { "A", "C" } } },
|
|
|
|
{ "=AB", "${C}", { { "AB", "C" } } },
|
|
|
|
{ "=aB", "${C}", { { "AB", "C" } } },
|
|
|
|
{ "=Ab", "${C}", { { "AB", "C" } } },
|
|
|
|
{ "=ab", "${C}", { { "AB", "C" } } },
|
2021-03-20 18:25:15 +00:00
|
|
|
// Special strings with text
|
|
|
|
{ "='A'", "A", {} },
|
|
|
|
{ "='This is a long text with spaces'", "This is a long text with spaces", {} },
|
|
|
|
{ "='='", "=", {} },
|
|
|
|
{ "='+'", "+", {} },
|
|
|
|
{ "='$'", "$", {} },
|
|
|
|
{ "='{'", "{", {} },
|
|
|
|
{ "='}'", "}", {} },
|
|
|
|
{ "='${A}'", "${A}", {} }, // TODO: correct substitution
|
|
|
|
{ "='A'+'B'", "AB", {} },
|
|
|
|
{ "='A'+' '", "A ", {} },
|
|
|
|
{ "=' '+'B'", " B", {} },
|
|
|
|
{ "='A'+B", "A${B}", {} },
|
2021-07-08 13:14:27 +00:00
|
|
|
{ "='A'+\"B\"", "A${B}", {} },
|
|
|
|
{ "='A' + \"B\"", "A${B}", {} },
|
|
|
|
{ "=\"A\"+'B'", "${A}B", {} },
|
|
|
|
{ "=\"A\" + 'B'", "${A}B", {} },
|
2021-03-20 18:25:15 +00:00
|
|
|
{ "=A+'B'", "${A}B", {} },
|
|
|
|
{ "=A+' '+B", "${A} ${B}", {} },
|
|
|
|
{ "='A'+B+'C'+D", "A${B}C${D}", {} },
|
2021-03-14 15:40:36 +00:00
|
|
|
// Some special cases we do not know yet how to handle correctly. But we should not crash ;)
|
|
|
|
{ "=+", "", {} },
|
|
|
|
{ "=++", "", {} },
|
|
|
|
{ "=+++", "", {} },
|
|
|
|
{ "=B+", "${B}", {} },
|
|
|
|
{ "=+B", "${B}", {} },
|
|
|
|
{ "=B++", "${B}", {} },
|
|
|
|
{ "=+B+", "${B}", {} },
|
|
|
|
{ "=++B", "${B}", {} },
|
|
|
|
{ " =", " =", {} },
|
|
|
|
{ "= ", "", {} },
|
2021-07-08 17:23:11 +00:00
|
|
|
{ "= A", "${A}", {} },
|
2021-03-14 15:40:36 +00:00
|
|
|
{ "=A ", "${A}", {} },
|
2021-03-20 18:25:15 +00:00
|
|
|
{ "='A'B", "A", {} },
|
|
|
|
{ "=A'B'", "B", {} },
|
|
|
|
{ "=A'B", "B", {} },
|
|
|
|
{ "=A+ 'B'", "${A}B", {} },
|
2021-03-14 15:40:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test conversation from Altium Special String to a KiCad String with variables
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( AltiumSpecialStringsToKiCadVariablesProperties )
|
|
|
|
{
|
|
|
|
for( const auto& c : special_string_to_kicad_property )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( wxString::Format( wxT( "'%s' -> '%s'" ), c.input, c.exp_result ) )
|
|
|
|
{
|
|
|
|
wxString result = AltiumSpecialStringsToKiCadVariables( c.input, c.override );
|
|
|
|
|
|
|
|
// These are all valid
|
|
|
|
BOOST_CHECK_EQUAL( result, c.exp_result );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|