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#include <boost/test/data/test_case.hpp>
31
33
35{
37};
38
39
43BOOST_FIXTURE_TEST_SUITE( AltiumParserUtils, ALTIUM_PARSER_UTILS_FIXTURE )
44
45
47{
48 wxString input;
49 wxString exp_result;
50 std::map<wxString, wxString> override;
51};
52
53std::ostream & operator<<(std::ostream & strm, SPECIAL_STRINGS_TO_KICAD const & data) {
54 return strm << "[" << data.input << " -> " << data.exp_result << "]";
55}
56
60static const std::vector<SPECIAL_STRINGS_TO_KICAD> sch_special_string_to_kicad_property = {
61 // Empty
62 { "", "", {} },
63 // No Special Strings
64 { "A", "A", {} },
65 { " A", " A", {} },
66 { "A ", "A ", {} },
67 { "A=B", "A=B", {} },
68 { "A=B+C", "A=B+C", {} },
69 { "A\nB", "A\nB", {} },
70 { "A\tB", "A\tB", {} },
71 { "This is a long text with spaces", "This is a long text with spaces", {} },
72 // Text format (underscore,...), TODO: add
73 // Escaping, TODO: add
74 { "+", "+", {} },
75 { "'", "'", {} },
76 { "'A'", "'A'", {} },
77 { "A+B", "A+B", {} },
78 { "A=B", "A=B", {} },
79 { "$", "$", {} },
80 { "{", "{", {} },
81 { "}", "}", {} },
82 { "${A}", "${A}", {} }, // TODO: correct substitution
83 // Simple special strings
84 { "=A", "${A}", {} },
85 { "=A", "${C}", { { "A", "C" } } },
86 { "=A_B", "${A_B}", {} },
87 // Combined special strings
88 { "=A+B", "${A}${B}", {} },
89 { "=A+B", "${A}${B}", {} },
90 { "=A+B", "${C}${B}", { { "A", "C" } } },
91 { "=A+B", "${C}${D}", { { "A", "C" }, { "B", "D" } } },
92 // Case-insensitive special strings
93 { "=A", "${C}", { { "A", "C" } } },
94 { "=a", "${C}", { { "A", "C" } } },
95 { "=AB", "${C}", { { "AB", "C" } } },
96 { "=aB", "${C}", { { "AB", "C" } } },
97 { "=Ab", "${C}", { { "AB", "C" } } },
98 { "=ab", "${C}", { { "AB", "C" } } },
99 // Special strings with text
100 { "='A'", "A", {} },
101 { "='This is a long text with spaces'", "This is a long text with spaces", {} },
102 { "='='", "=", {} },
103 { "='+'", "+", {} },
104 { "='$'", "$", {} },
105 { "='{'", "{", {} },
106 { "='}'", "}", {} },
107 { "='${A}'", "${A}", {} }, // TODO: correct substitution
108 { "='A'+'B'", "AB", {} },
109 { "='A'+' '", "A ", {} },
110 { "=' '+'B'", " B", {} },
111 { "='A'+B", "A${B}", {} },
112 { "='A'+\"B\"", "A${B}", {} },
113 { "='A' + \"B\"", "A${B}", {} },
114 { "=\"A\"+'B'", "${A}B", {} },
115 { "=\"A\" + 'B'", "${A}B", {} },
116 { "=A+'B'", "${A}B", {} },
117 { "=A+' '+B", "${A} ${B}", {} },
118 { "='A'+B+'C'+D", "A${B}C${D}", {} },
119 // Some special cases we do not know yet how to handle correctly. But we should not crash ;)
120 { "=+", "", {} },
121 { "=++", "", {} },
122 { "=+++", "", {} },
123 { "=B+", "${B}", {} },
124 { "=+B", "${B}", {} },
125 { "=B++", "${B}", {} },
126 { "=+B+", "${B}", {} },
127 { "=++B", "${B}", {} },
128 { " =", " =", {} },
129 { "= ", "", {} },
130 { "= A", "${A}", {} },
131 { "=A ", "${A}", {} },
132 { "='A'B", "A", {} },
133 { "=A'B'", "B", {} },
134 { "=A'B", "B", {} },
135 { "=A+ 'B'", "${A}B", {} },
136};
137
138
142BOOST_DATA_TEST_CASE( AltiumSchSpecialStringsToKiCadVariablesProperties,
143 boost::unit_test::data::make(sch_special_string_to_kicad_property),
144 data )
145{
146 wxString result = AltiumSchSpecialStringsToKiCadVariables( data.input, data.override );
147
148 // These are all valid
149 BOOST_CHECK_EQUAL( result, data.exp_result );
150}
151
152
156static const std::vector<SPECIAL_STRINGS_TO_KICAD> pcb_special_string_to_kicad_property = {
157 // Empty
158 { "", "", {} },
159 // No Special Strings
160 { "A", "A", {} },
161 { " A", " A", {} },
162 { "A ", "A ", {} },
163 { "A=B", "A=B", {} },
164 { "A=B+C", "A=B+C", {} },
165 { "A\nB", "A\nB", {} },
166 { "A\tB", "A\tB", {} },
167 { "This is a long text with spaces", "This is a long text with spaces", {} },
168 // Text format (underscore,...), TODO: add
169 // Escaping, TODO: add
170 { "'", "'", {} },
171 { "'A'", "'A'", {} },
172 { "$", "$", {} },
173 { "{", "{", {} },
174 { "}", "}", {} },
175 { "${A}", "${A}", {} }, // TODO: correct substitution
176 // Simple special strings starting with dot
177 { ".A", "${A}", {} },
178 { ".A", "${C}", { { "A", "C" } } },
179 { ".A_B", "${A_B}", {} },
180 // Concatenated special strings
181 /*{ "'.A'", "${A}", {} },
182 { "'.A''.B'", "${A}${B}", {} },
183 { "'.A''.B'", "${C}${B}", { { "A", "C" } } },
184 { "'.A''.B'", "${C}${D}", { { "A", "C" }, { "B", "D" } } },
185 { "A='.A', B='.B'", "A=${A}, B=${B}", {} },*/
186 // Case-insensitive special strings
187 { ".A", "${C}", { { "A", "C" } } },
188 { ".a", "${C}", { { "A", "C" } } },
189 { ".AB", "${C}", { { "AB", "C" } } },
190 { ".aB", "${C}", { { "AB", "C" } } },
191 { ".Ab", "${C}", { { "AB", "C" } } },
192 { ".ab", "${C}", { { "AB", "C" } } },
193 // Some special cases we do not know yet how to handle correctly. But we should not crash ;)
194 { "''", "''", {} },
195 { " .", " .", {} },
196 { ". ", "${ }", {} },
197 { ". A", "${ A}", {} },
198 { ".A ", "${A }", {} },
199 { " .A", " .A", {} },
200 { "...", "${..}", {} },
201};
202
203
207BOOST_DATA_TEST_CASE( AltiumPcbSpecialStringsToKiCadStringsProperties,
208 boost::unit_test::data::make(pcb_special_string_to_kicad_property),
209 data )
210{
211 wxString result = AltiumPcbSpecialStringsToKiCadStrings( data.input, data.override );
212
213 // These are all valid
214 BOOST_CHECK_EQUAL( result, data.exp_result );
215}
216
wxString AltiumSchSpecialStringsToKiCadVariables(const wxString &aString, const std::map< wxString, wxString > &aOverrides)
wxString AltiumPcbSpecialStringsToKiCadStrings(const wxString &aString, const std::map< wxString, wxString > &aOverrides)
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1210
Declares the struct as the Boost test fixture.
BOOST_DATA_TEST_CASE(AltiumSchSpecialStringsToKiCadVariablesProperties, boost::unit_test::data::make(sch_special_string_to_kicad_property), data)
Test conversation from Altium Schematic Special String to a KiCad String with variables.
static const std::vector< SPECIAL_STRINGS_TO_KICAD > sch_special_string_to_kicad_property
A list of valid test strings and the expected results.
static const std::vector< SPECIAL_STRINGS_TO_KICAD > pcb_special_string_to_kicad_property
A list of valid test strings and the expected results.
BOOST_AUTO_TEST_SUITE_END()