KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_template_fieldnames.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 */
20
22#include <boost/test/unit_test.hpp>
23
24#include <template_fieldnames.h>
25
26
27BOOST_AUTO_TEST_SUITE( TemplateFieldNames )
28
29
30
34BOOST_AUTO_TEST_CASE( MandatoryFieldsAreCaseInsensitive )
35{
36 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Value" ), wxS( "VALUE" ) ) );
37 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "VALUE" ), wxS( "value" ) ) );
38 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Reference" ), wxS( "REFERENCE" ) ) );
39 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Footprint" ), wxS( "footprint" ) ) );
40 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Datasheet" ), wxS( "DATASHEET" ) ) );
41 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Description" ), wxS( "DESCRIPTION" ) ) );
42}
43
44
50BOOST_AUTO_TEST_CASE( UserFieldsAreCaseSensitive )
51{
52 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Manufacturer" ), wxS( "MANUFACTURER" ) ) );
53 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "MPN" ), wxS( "mpn" ) ) );
54 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Supplier" ), wxS( "supplier" ) ) );
55}
56
57
61BOOST_AUTO_TEST_CASE( IdenticalNamesMatch )
62{
63 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Manufacturer" ), wxS( "Manufacturer" ) ) );
64 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Value" ), wxS( "Value" ) ) );
65 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "" ), wxS( "" ) ) );
66}
67
68
72BOOST_AUTO_TEST_CASE( DifferentUserNamesDoNotMatch )
73{
74 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Manufacturer" ), wxS( "Supplier" ) ) );
75 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "MPN" ), wxS( "Description" ) ) );
76}
77
78
83BOOST_AUTO_TEST_CASE( MandatoryNameDoesNotPullInUnrelatedNames )
84{
85 // "Value" matches "VALUE" (mandatory case-insensitive) but does not match "MyValue".
86 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Value" ), wxS( "MyValue" ) ) );
87 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "VALUE" ), wxS( "ValueAdded" ) ) );
88}
89
90
96BOOST_AUTO_TEST_CASE( SheetMandatoryFieldsAreCaseInsensitive )
97{
98 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Sheetname" ), wxS( "SHEETNAME" ),
100 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Sheetfile" ), wxS( "SHEETFILE" ),
102
103 // Symbol mandatory names ("Value") are NOT mandatory in a sheet context, so they remain
104 // case-sensitive there.
105 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Value" ), wxS( "VALUE" ),
107}
108
109
114BOOST_AUTO_TEST_CASE( GlobalLabelMandatoryFieldsAreCaseInsensitive )
115{
116 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Intersheetrefs" ), wxS( "INTERSHEETREFS" ),
118
119 // Symbol mandatory names are NOT mandatory in a global-label context.
120 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Value" ), wxS( "VALUE" ),
122}
123
124
129BOOST_AUTO_TEST_CASE( EmptyMandatorySetIsAlwaysCaseSensitive )
130{
131 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Value" ), wxS( "VALUE" ), {} ) );
132 BOOST_CHECK( !FieldNamesAreDuplicates( wxS( "Manufacturer" ), wxS( "MANUFACTURER" ), {} ) );
133 BOOST_CHECK( FieldNamesAreDuplicates( wxS( "Same" ), wxS( "Same" ), {} ) );
134}
135
136
137static bool hasTemplate( TEMPLATES& aTemplates, const wxString& aName )
138{
139 for( const TEMPLATE_FIELDNAME& tfn : aTemplates.GetTemplateFieldNames() )
140 {
141 if( tfn.m_Name == aName )
142 return true;
143 }
144
145 return false;
146}
147
148
154BOOST_AUTO_TEST_CASE( TemplateRejectsMandatoryCaseVariant )
155{
156 TEMPLATES templates;
157
158 templates.AddTemplateFieldName( TEMPLATE_FIELDNAME( wxS( "VALUE" ) ), false );
159 templates.AddTemplateFieldName( TEMPLATE_FIELDNAME( wxS( "reference" ) ), false );
160
161 BOOST_CHECK( !hasTemplate( templates, wxS( "VALUE" ) ) );
162 BOOST_CHECK( !hasTemplate( templates, wxS( "reference" ) ) );
163}
164
165
170BOOST_AUTO_TEST_CASE( TemplateKeepsUserCaseVariantsDistinct )
171{
172 TEMPLATES templates;
173
174 templates.AddTemplateFieldName( TEMPLATE_FIELDNAME( wxS( "Manufacturer" ) ), false );
175 templates.AddTemplateFieldName( TEMPLATE_FIELDNAME( wxS( "MANUFACTURER" ) ), false );
176
177 BOOST_CHECK( hasTemplate( templates, wxS( "Manufacturer" ) ) );
178 BOOST_CHECK( hasTemplate( templates, wxS( "MANUFACTURER" ) ) );
179 BOOST_CHECK_EQUAL( templates.GetTemplateFieldNames().size(), 2 );
180}
181
182
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
const std::vector< TEMPLATE_FIELDNAME > & GetTemplateFieldNames()
Return a template field name list for read only access.
Hold a name of a symbol's field, field value, and default visibility.
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
#define SHEET_MANDATORY_FIELDS
#define GLOBALLABEL_MANDATORY_FIELDS
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
static bool hasTemplate(TEMPLATES &aTemplates, const wxString &aName)
BOOST_AUTO_TEST_CASE(MandatoryFieldsAreCaseInsensitive)
Mandatory field names collide with any case variant (the s-expression parser folds case variants of m...
BOOST_CHECK_EQUAL(result, "25.4")