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, see <https://www.gnu.org/licenses/>.
18 */
19
24
26
28
29
34
35
36BOOST_FIXTURE_TEST_SUITE( PadsAttributeMapper, PADS_ATTRIBUTE_MAPPER_FIXTURE )
37
38
39BOOST_AUTO_TEST_CASE( ReferenceFieldMapping )
40{
42
43 // Various PADS reference designator formats
49
50 // Verify IsReferenceField
51 BOOST_CHECK( mapper.IsReferenceField( "Ref.Des." ) );
52 BOOST_CHECK( mapper.IsReferenceField( "refdes" ) );
53 BOOST_CHECK( !mapper.IsReferenceField( "Part Type" ) );
54}
55
56
57BOOST_AUTO_TEST_CASE( ValueFieldMapping )
58{
60
61 // Various PADS value/part type formats
67
68 // Verify IsValueField
69 BOOST_CHECK( mapper.IsValueField( "Part Type" ) );
70 BOOST_CHECK( mapper.IsValueField( "value" ) );
71 BOOST_CHECK( !mapper.IsValueField( "Ref.Des." ) );
72}
73
74
75BOOST_AUTO_TEST_CASE( FootprintFieldMapping )
76{
78
79 // Various PADS footprint/decal formats
85
86 // Verify IsFootprintField
87 BOOST_CHECK( mapper.IsFootprintField( "PCB Decal" ) );
88 BOOST_CHECK( mapper.IsFootprintField( "decal" ) );
89 BOOST_CHECK( !mapper.IsFootprintField( "Value" ) );
90}
91
92
102
103
115
116
126
127
128BOOST_AUTO_TEST_CASE( UnknownAttributePassthrough )
129{
131
132 // Unknown attributes should pass through unchanged
133 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "CustomField" ), "CustomField" );
134 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "My Custom Attr" ), "My Custom Attr" );
135 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "XYZ_123" ), "XYZ_123" );
136
137 // Unknown attributes are not standard fields
138 BOOST_CHECK( !mapper.IsStandardField( "CustomField" ) );
139 BOOST_CHECK( !mapper.IsReferenceField( "CustomField" ) );
140 BOOST_CHECK( !mapper.IsValueField( "CustomField" ) );
141 BOOST_CHECK( !mapper.IsFootprintField( "CustomField" ) );
142}
143
144
145BOOST_AUTO_TEST_CASE( CaseInsensitivity )
146{
148
149 // All lookups should be case-insensitive
154
155 // Case insensitivity for standard field checks
156 BOOST_CHECK( mapper.IsStandardField( "REF.DES." ) );
157 BOOST_CHECK( mapper.IsStandardField( "ref.des." ) );
158 BOOST_CHECK( mapper.IsStandardField( "PART TYPE" ) );
159 BOOST_CHECK( mapper.IsStandardField( "pcb decal" ) );
160}
161
162
163BOOST_AUTO_TEST_CASE( IsStandardFieldMethod )
164{
166
167 // Standard fields (Reference, Value, Footprint)
168 BOOST_CHECK( mapper.IsStandardField( "Ref.Des." ) );
169 BOOST_CHECK( mapper.IsStandardField( "Part Type" ) );
170 BOOST_CHECK( mapper.IsStandardField( "PCB Decal" ) );
171
172 // Non-standard fields (MPN, Manufacturer, Datasheet)
173 BOOST_CHECK( !mapper.IsStandardField( "Part Number" ) );
174 BOOST_CHECK( !mapper.IsStandardField( "Manufacturer" ) );
175 BOOST_CHECK( !mapper.IsStandardField( "Datasheet" ) );
176}
177
178
179BOOST_AUTO_TEST_CASE( CustomMappingOverride )
180{
182
183 // Add a custom mapping that overrides a standard one
184 mapper.AddMapping( "Part Type", "CustomValue" );
185
186 // Custom mapping should take precedence
187 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Part Type" ), "CustomValue" );
188 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "PART TYPE" ), "CustomValue" );
189
190 // Other standard mappings should still work
192}
193
194
195BOOST_AUTO_TEST_CASE( CustomMappingNew )
196{
198
199 // Add a completely new custom mapping
200 mapper.AddMapping( "My PADS Attr", "MyKiCadField" );
201
202 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "My PADS Attr" ), "MyKiCadField" );
203 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "MY PADS ATTR" ), "MyKiCadField" );
204
205 // Verify it appears in GetMappings
206 const auto& mappings = mapper.GetMappings();
207 BOOST_CHECK_EQUAL( mappings.size(), 1 );
208 BOOST_CHECK_EQUAL( mappings.at( "my pads attr" ), "MyKiCadField" );
209}
210
211
212BOOST_AUTO_TEST_CASE( MultipleCustomMappings )
213{
215
216 mapper.AddMapping( "Attr1", "Field1" );
217 mapper.AddMapping( "Attr2", "Field2" );
218 mapper.AddMapping( "Attr3", "Field3" );
219
220 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Attr1" ), "Field1" );
221 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Attr2" ), "Field2" );
222 BOOST_CHECK_EQUAL( mapper.GetKiCadFieldName( "Attr3" ), "Field3" );
223
224 const auto& mappings = mapper.GetMappings();
225 BOOST_CHECK_EQUAL( mappings.size(), 3 );
226}
227
228
229BOOST_AUTO_TEST_CASE( FieldConstants )
230{
231 // Verify the field constants have expected values
232 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_REFERENCE ), "Reference" );
233 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_VALUE ), "Value" );
234 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_FOOTPRINT ), "Footprint" );
235 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_DATASHEET ), "Datasheet" );
237 BOOST_CHECK_EQUAL( std::string( PADS_ATTRIBUTE_MAPPER::FIELD_MANUFACTURER ), "Manufacturer" );
238}
239
240
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")