KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pads_attribute_mapper.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 The 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
28
30
32
33
38
39
40BOOST_FIXTURE_TEST_SUITE( PadsAttributeMapper, PADS_ATTRIBUTE_MAPPER_FIXTURE )
41
42
43BOOST_AUTO_TEST_CASE( ReferenceFieldMapping )
44{
46
47 // Various PADS reference designator formats
53
54 // Verify IsReferenceField
55 BOOST_CHECK( mapper.IsReferenceField( "Ref.Des." ) );
56 BOOST_CHECK( mapper.IsReferenceField( "refdes" ) );
57 BOOST_CHECK( !mapper.IsReferenceField( "Part Type" ) );
58}
59
60
61BOOST_AUTO_TEST_CASE( ValueFieldMapping )
62{
64
65 // Various PADS value/part type formats
71
72 // Verify IsValueField
73 BOOST_CHECK( mapper.IsValueField( "Part Type" ) );
74 BOOST_CHECK( mapper.IsValueField( "value" ) );
75 BOOST_CHECK( !mapper.IsValueField( "Ref.Des." ) );
76}
77
78
79BOOST_AUTO_TEST_CASE( FootprintFieldMapping )
80{
82
83 // Various PADS footprint/decal formats
89
90 // Verify IsFootprintField
91 BOOST_CHECK( mapper.IsFootprintField( "PCB Decal" ) );
92 BOOST_CHECK( mapper.IsFootprintField( "decal" ) );
93 BOOST_CHECK( !mapper.IsFootprintField( "Value" ) );
94}
95
96
106
107
119
120
130
131
132BOOST_AUTO_TEST_CASE( UnknownAttributePassthrough )
133{
135
136 // Unknown attributes should pass through unchanged
137 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "CustomField" ), "CustomField" );
138 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "My Custom Attr" ), "My Custom Attr" );
139 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "XYZ_123" ), "XYZ_123" );
140
141 // Unknown attributes are not standard fields
142 BOOST_CHECK( !mapper.IsStandardField( "CustomField" ) );
143 BOOST_CHECK( !mapper.IsReferenceField( "CustomField" ) );
144 BOOST_CHECK( !mapper.IsValueField( "CustomField" ) );
145 BOOST_CHECK( !mapper.IsFootprintField( "CustomField" ) );
146}
147
148
149BOOST_AUTO_TEST_CASE( CaseInsensitivity )
150{
152
153 // All lookups should be case-insensitive
158
159 // Case insensitivity for standard field checks
160 BOOST_CHECK( mapper.IsStandardField( "REF.DES." ) );
161 BOOST_CHECK( mapper.IsStandardField( "ref.des." ) );
162 BOOST_CHECK( mapper.IsStandardField( "PART TYPE" ) );
163 BOOST_CHECK( mapper.IsStandardField( "pcb decal" ) );
164}
165
166
167BOOST_AUTO_TEST_CASE( IsStandardFieldMethod )
168{
170
171 // Standard fields (Reference, Value, Footprint)
172 BOOST_CHECK( mapper.IsStandardField( "Ref.Des." ) );
173 BOOST_CHECK( mapper.IsStandardField( "Part Type" ) );
174 BOOST_CHECK( mapper.IsStandardField( "PCB Decal" ) );
175
176 // Non-standard fields (MPN, Manufacturer, Datasheet)
177 BOOST_CHECK( !mapper.IsStandardField( "Part Number" ) );
178 BOOST_CHECK( !mapper.IsStandardField( "Manufacturer" ) );
179 BOOST_CHECK( !mapper.IsStandardField( "Datasheet" ) );
180}
181
182
183BOOST_AUTO_TEST_CASE( CustomMappingOverride )
184{
186
187 // Add a custom mapping that overrides a standard one
188 mapper.AddMapping( "Part Type", "CustomValue" );
189
190 // Custom mapping should take precedence
191 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Part Type" ), "CustomValue" );
192 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "PART TYPE" ), "CustomValue" );
193
194 // Other standard mappings should still work
196}
197
198
199BOOST_AUTO_TEST_CASE( CustomMappingNew )
200{
202
203 // Add a completely new custom mapping
204 mapper.AddMapping( "My PADS Attr", "MyKiCadField" );
205
206 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "My PADS Attr" ), "MyKiCadField" );
207 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "MY PADS ATTR" ), "MyKiCadField" );
208
209 // Verify it appears in GetMappings
210 const auto& mappings = mapper.GetMappings();
211 BOOST_CHECK_EQUAL( mappings.size(), 1 );
212 BOOST_CHECK_EQUAL( mappings.at( "my pads attr" ), "MyKiCadField" );
213}
214
215
216BOOST_AUTO_TEST_CASE( MultipleCustomMappings )
217{
219
220 mapper.AddMapping( "Attr1", "Field1" );
221 mapper.AddMapping( "Attr2", "Field2" );
222 mapper.AddMapping( "Attr3", "Field3" );
223
224 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Attr1" ), "Field1" );
225 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Attr2" ), "Field2" );
226 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Attr3" ), "Field3" );
227
228 const auto& mappings = mapper.GetMappings();
229 BOOST_CHECK_EQUAL( mappings.size(), 3 );
230}
231
232
233BOOST_AUTO_TEST_CASE( FieldConstants )
234{
235 // Verify the field constants have expected values
236 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_REFERENCE ), "Reference" );
237 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_VALUE ), "Value" );
238 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_FOOTPRINT ), "Footprint" );
239 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_DATASHEET ), "Datasheet" );
241 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_MANUFACTURER ), "Manufacturer" );
242}
243
244
Maps PADS attribute names to KiCad field names.
static constexpr const char * FIELD_MANUFACTURER
static constexpr const char * FIELD_DATASHEET
const std::map< std::string, std::string > & GetMappings() const
Get all custom mappings.
bool IsReferenceField(const std::string &aPadsAttr) const
Check if a PADS attribute maps to the Reference field.
std::string GetKiCadFieldName(const std::string &aPadsAttr) const
Get the KiCad field name for a PADS attribute.
bool IsFootprintField(const std::string &aPadsAttr) const
Check if a PADS attribute maps to the Footprint field.
static constexpr const char * FIELD_REFERENCE
static constexpr const char * FIELD_MPN
bool IsStandardField(const std::string &aPadsAttr) const
Check if a PADS attribute maps to a standard KiCad field.
void AddMapping(const std::string &aPadsAttr, const std::string &aKiCadField)
Add or override a custom attribute mapping.
static constexpr const char * FIELD_VALUE
bool IsValueField(const std::string &aPadsAttr) const
Check if a PADS attribute maps to the Value field.
static constexpr const char * FIELD_FOOTPRINT
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ReferenceFieldMapping)
BOOST_CHECK_EQUAL(result, "25.4")