KiCad PCB EDA Suite
test_altium_parser_utils.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 (C) 2021 KiCad Developers, see AUTHORS.TXT for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
30 
32 
34 {
36 };
37 
38 
42 BOOST_FIXTURE_TEST_SUITE( AltiumParserUtils, ALTIUM_PARSER_UTILS_FIXTURE )
43 
44 
46 {
47  wxString input;
48  wxString exp_result;
49  std::map<wxString, wxString> override;
50 };
51 
55 static const std::vector<SPECIAL_STRINGS_TO_KICAD> special_string_to_kicad_property = {
56  // Empty
57  { "", "", {} },
58  // No Special Strings
59  { "A", "A", {} },
60  { " A", " A", {} },
61  { "A ", "A ", {} },
62  { "A=B", "A=B", {} },
63  { "A=B+C", "A=B+C", {} },
64  { "A\nB", "A\nB", {} },
65  { "A\tB", "A\tB", {} },
66  { "This is a long text with spaces", "This is a long text with spaces", {} },
67  // Text format (underscore,...), TODO: add
68  // Escaping, TODO: add
69  { "+", "+", {} },
70  { "'", "'", {} },
71  { "'A'", "'A'", {} },
72  { "A+B", "A+B", {} },
73  { "A=B", "A=B", {} },
74  { "$", "$", {} },
75  { "{", "{", {} },
76  { "}", "}", {} },
77  { "${A}", "${A}", {} }, // TODO: correct substitution
78  // Simple special strings
79  { "=A", "${A}", {} },
80  { "=A", "${C}", { { "A", "C" } } },
81  { "=A_B", "${A_B}", {} },
82  // Combined special strings
83  { "=A+B", "${A}${B}", {} },
84  { "=A+B", "${A}${B}", {} },
85  { "=A+B", "${C}${B}", { { "A", "C" } } },
86  { "=A+B", "${C}${D}", { { "A", "C" }, { "B", "D" } } },
87  // Case insensitive special strings
88  { "=A", "${C}", { { "A", "C" } } },
89  { "=a", "${C}", { { "A", "C" } } },
90  { "=AB", "${C}", { { "AB", "C" } } },
91  { "=aB", "${C}", { { "AB", "C" } } },
92  { "=Ab", "${C}", { { "AB", "C" } } },
93  { "=ab", "${C}", { { "AB", "C" } } },
94  // Special strings with text
95  { "='A'", "A", {} },
96  { "='This is a long text with spaces'", "This is a long text with spaces", {} },
97  { "='='", "=", {} },
98  { "='+'", "+", {} },
99  { "='$'", "$", {} },
100  { "='{'", "{", {} },
101  { "='}'", "}", {} },
102  { "='${A}'", "${A}", {} }, // TODO: correct substitution
103  { "='A'+'B'", "AB", {} },
104  { "='A'+' '", "A ", {} },
105  { "=' '+'B'", " B", {} },
106  { "='A'+B", "A${B}", {} },
107  { "='A'+\"B\"", "A${B}", {} },
108  { "='A' + \"B\"", "A${B}", {} },
109  { "=\"A\"+'B'", "${A}B", {} },
110  { "=\"A\" + 'B'", "${A}B", {} },
111  { "=A+'B'", "${A}B", {} },
112  { "=A+' '+B", "${A} ${B}", {} },
113  { "='A'+B+'C'+D", "A${B}C${D}", {} },
114  // Some special cases we do not know yet how to handle correctly. But we should not crash ;)
115  { "=+", "", {} },
116  { "=++", "", {} },
117  { "=+++", "", {} },
118  { "=B+", "${B}", {} },
119  { "=+B", "${B}", {} },
120  { "=B++", "${B}", {} },
121  { "=+B+", "${B}", {} },
122  { "=++B", "${B}", {} },
123  { " =", " =", {} },
124  { "= ", "", {} },
125  { "= A", "${A}", {} },
126  { "=A ", "${A}", {} },
127  { "='A'B", "A", {} },
128  { "=A'B'", "B", {} },
129  { "=A'B", "B", {} },
130  { "=A+ 'B'", "${A}B", {} },
131 };
132 
133 
137 BOOST_AUTO_TEST_CASE( AltiumSpecialStringsToKiCadVariablesProperties )
138 {
139  for( const auto& c : special_string_to_kicad_property )
140  {
141  BOOST_TEST_CONTEXT( wxString::Format( wxT( "'%s' -> '%s'" ), c.input, c.exp_result ) )
142  {
143  wxString result = AltiumSpecialStringsToKiCadVariables( c.input, c.override );
144 
145  // These are all valid
146  BOOST_CHECK_EQUAL( result, c.exp_result );
147  }
148  }
149 }
150 
151 BOOST_AUTO_TEST_SUITE_END()
static const std::vector< SPECIAL_STRINGS_TO_KICAD > special_string_to_kicad_property
A list of valid test strings and the expected results.
Declares the struct as the Boost test fixture.
BOOST_AUTO_TEST_CASE(AltiumSpecialStringsToKiCadVariablesProperties)
Test conversation from Altium Special String to a KiCad String with variables.
#define BOOST_TEST_CONTEXT(A)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxString AltiumSpecialStringsToKiCadVariables(const wxString &aString, const std::map< wxString, wxString > &aOverrides)