KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
42BOOST_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
55static const std::vector<SPECIAL_STRINGS_TO_KICAD> sch_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
137BOOST_AUTO_TEST_CASE( AltiumSchSpecialStringsToKiCadVariablesProperties )
138{
139 for( const auto& c : sch_special_string_to_kicad_property )
140 {
141 BOOST_TEST_CONTEXT( wxString::Format( wxT( "'%s' -> '%s'" ), c.input, c.exp_result ) )
142 {
143 wxString result = AltiumSchSpecialStringsToKiCadVariables( c.input, c.override );
144
145 // These are all valid
146 BOOST_CHECK_EQUAL( result, c.exp_result );
147 }
148 }
149}
150
154static const std::vector<SPECIAL_STRINGS_TO_KICAD> pcb_special_string_to_kicad_property = {
155 // Empty
156 { "", "", {} },
157 // No Special Strings
158 { "A", "A", {} },
159 { " A", " A", {} },
160 { "A ", "A ", {} },
161 { "A=B", "A=B", {} },
162 { "A=B+C", "A=B+C", {} },
163 { "A\nB", "A\nB", {} },
164 { "A\tB", "A\tB", {} },
165 { "This is a long text with spaces", "This is a long text with spaces", {} },
166 // Text format (underscore,...), TODO: add
167 // Escaping, TODO: add
168 { "'", "'", {} },
169 { "'A'", "'A'", {} },
170 { "$", "$", {} },
171 { "{", "{", {} },
172 { "}", "}", {} },
173 { "${A}", "${A}", {} }, // TODO: correct substitution
174 // Simple special strings starting with dot
175 { ".A", "${A}", {} },
176 { ".A", "${C}", { { "A", "C" } } },
177 { ".A_B", "${A_B}", {} },
178 // Concatenated special strings
179 /*{ "'.A'", "${A}", {} },
180 { "'.A''.B'", "${A}${B}", {} },
181 { "'.A''.B'", "${C}${B}", { { "A", "C" } } },
182 { "'.A''.B'", "${C}${D}", { { "A", "C" }, { "B", "D" } } },
183 { "A='.A', B='.B'", "A=${A}, B=${B}", {} },*/
184 // Case-insensitive special strings
185 { ".A", "${C}", { { "A", "C" } } },
186 { ".a", "${C}", { { "A", "C" } } },
187 { ".AB", "${C}", { { "AB", "C" } } },
188 { ".aB", "${C}", { { "AB", "C" } } },
189 { ".Ab", "${C}", { { "AB", "C" } } },
190 { ".ab", "${C}", { { "AB", "C" } } },
191 // Some special cases we do not know yet how to handle correctly. But we should not crash ;)
192 { "''", "''", {} },
193 { " .", " .", {} },
194 { ". ", "${ }", {} },
195 { ". A", "${ A}", {} },
196 { ".A ", "${A }", {} },
197 { " .A", " .A", {} },
198 { "...", "${..}", {} },
199};
200
201
205BOOST_AUTO_TEST_CASE( AltiumPcbSpecialStringsToKiCadStringsProperties )
206{
207 for( const auto& c : pcb_special_string_to_kicad_property )
208 {
209 BOOST_TEST_CONTEXT( wxString::Format( wxT( "'%s' -> '%s'" ), c.input, c.exp_result ) )
210 {
211 wxString result = AltiumPcbSpecialStringsToKiCadStrings( c.input, c.override );
212
213 // These are all valid
214 BOOST_CHECK_EQUAL( result, c.exp_result );
215 }
216 }
217}
218
219BOOST_AUTO_TEST_SUITE_END()
wxString AltiumSchSpecialStringsToKiCadVariables(const wxString &aString, const std::map< wxString, wxString > &aOverrides)
wxString AltiumPcbSpecialStringsToKiCadStrings(const wxString &aString, const std::map< wxString, wxString > &aOverrides)
Declares the struct as the Boost test fixture.
static const std::vector< SPECIAL_STRINGS_TO_KICAD > sch_special_string_to_kicad_property
A list of valid test strings and the expected results.
BOOST_AUTO_TEST_CASE(AltiumSchSpecialStringsToKiCadVariablesProperties)
Test conversation from Altium Schematic Special String to a KiCad String with variables.
static const std::vector< SPECIAL_STRINGS_TO_KICAD > pcb_special_string_to_kicad_property
A list of valid test strings and the expected results.
#define BOOST_TEST_CONTEXT(A)