KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_field_case_conflicts.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <fields_data_model.h>
23#include <sch_field.h>
24#include <sch_reference_list.h>
25#include <sch_sheet_path.h>
26#include <sch_symbol.h>
27
28
30{
31 SCH_SYMBOL makeSymbol( const wxString& aRef,
32 std::initializer_list<std::pair<wxString, wxString>> aUserFields )
33 {
34 SCH_SYMBOL sym;
35
36 SCH_FIELD* refField = sym.GetField( FIELD_T::REFERENCE );
37 wxASSERT( refField );
38 refField->SetText( aRef );
39
40 for( const auto& [name, value] : aUserFields )
41 {
42 SCH_FIELD f( &sym, FIELD_T::USER, name );
43 f.SetText( value );
44 sym.AddField( f );
45 }
46
47 return sym;
48 }
49
50 SCH_REFERENCE_LIST buildList( std::vector<SCH_SYMBOL>& aSymbols )
51 {
54
55 for( SCH_SYMBOL& sym : aSymbols )
56 {
57 SCH_REFERENCE ref( &sym, path );
58 ref.SetRef( sym.GetField( FIELD_T::REFERENCE )->GetText() );
59 list.AddItem( ref );
60 }
61
62 return list;
63 }
64};
65
66
67BOOST_FIXTURE_TEST_SUITE( FieldCaseConflicts, FIELD_CASE_CONFLICT_FIXTURE )
68
69
70BOOST_AUTO_TEST_CASE( EmptyListYieldsNoConflicts )
71{
73 BOOST_CHECK( DetectFieldCaseConflicts( list ).empty() );
74}
75
76
77BOOST_AUTO_TEST_CASE( SingleSymbolWithoutUserFieldsYieldsNoConflicts )
78{
79 std::vector<SCH_SYMBOL> symbols;
80 symbols.push_back( makeSymbol( "R1", {} ) );
81
82 SCH_REFERENCE_LIST list = buildList( symbols );
83
84 BOOST_CHECK( DetectFieldCaseConflicts( list ).empty() );
85}
86
87
88BOOST_AUTO_TEST_CASE( DifferentSymbolsWithCaseVariantsYieldNoConflicts )
89{
90 std::vector<SCH_SYMBOL> symbols;
91 symbols.push_back( makeSymbol( "R1", { { "Manufacturer", "Vishay" } } ) );
92 symbols.push_back( makeSymbol( "R2", { { "MANUFACTURER", "Neutrik" } } ) );
93
94 SCH_REFERENCE_LIST list = buildList( symbols );
95
96 BOOST_CHECK( DetectFieldCaseConflicts( list ).empty() );
97}
98
99
100BOOST_AUTO_TEST_CASE( SameSymbolWithBothCaseVariantsYieldsOneConflict )
101{
102 std::vector<SCH_SYMBOL> symbols;
103 symbols.push_back( makeSymbol( "R1", { { "Manufacturer", "Vishay" },
104 { "MANUFACTURER", "Yageo" } } ) );
105
106 SCH_REFERENCE_LIST list = buildList( symbols );
107
108 auto conflicts = DetectFieldCaseConflicts( list );
109
110 BOOST_REQUIRE_EQUAL( conflicts.size(), 1u );
111 BOOST_CHECK_EQUAL( conflicts[0].reference, "R1" );
112 BOOST_CHECK_EQUAL( conflicts[0].caseFoldedKey, "manufacturer" );
113 BOOST_REQUIRE_EQUAL( conflicts[0].variants.size(), 2u );
114}
115
116
117BOOST_AUTO_TEST_CASE( ThreeCaseVariantsOnSameSymbolYieldOneConflictWithThreeMembers )
118{
119 std::vector<SCH_SYMBOL> symbols;
120 symbols.push_back( makeSymbol( "R1", { { "Manufacturer", "A" },
121 { "MANUFACTURER", "B" },
122 { "manufacturer", "C" } } ) );
123
124 SCH_REFERENCE_LIST list = buildList( symbols );
125
126 auto conflicts = DetectFieldCaseConflicts( list );
127
128 BOOST_REQUIRE_EQUAL( conflicts.size(), 1u );
129 BOOST_CHECK_EQUAL( conflicts[0].variants.size(), 3u );
130}
131
132
133BOOST_AUTO_TEST_CASE( MultipleSymbolsWithConflictsAreAllReported )
134{
135 std::vector<SCH_SYMBOL> symbols;
136 symbols.push_back( makeSymbol( "R1", { { "Manufacturer", "A" },
137 { "MANUFACTURER", "B" } } ) );
138 symbols.push_back( makeSymbol( "R2", { { "Tolerance", "1%" },
139 { "tolerance", "5%" } } ) );
140 symbols.push_back( makeSymbol( "R3", { { "Manufacturer", "C" } } ) );
141
142 SCH_REFERENCE_LIST list = buildList( symbols );
143
144 auto conflicts = DetectFieldCaseConflicts( list );
145
146 BOOST_CHECK_EQUAL( conflicts.size(), 2u );
147}
148
149
150BOOST_AUTO_TEST_CASE( DistinctFieldNamesOnSameSymbolYieldNoConflict )
151{
152 std::vector<SCH_SYMBOL> symbols;
153 symbols.push_back( makeSymbol( "R1", { { "Manufacturer", "A" },
154 { "PartNumber", "B" } } ) );
155
156 SCH_REFERENCE_LIST list = buildList( symbols );
157
158 BOOST_CHECK( DetectFieldCaseConflicts( list ).empty() );
159}
160
161
const char * name
void SetText(const wxString &aText) override
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A helper to define a symbol's reference designator in a schematic.
void SetRef(const wxString &aReference)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:76
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
static bool empty(const wxTextEntryBase *aCtrl)
std::vector< FIELD_CASE_CONFLICT > DetectFieldCaseConflicts(const SCH_REFERENCE_LIST &aSymbols)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SCH_SYMBOL makeSymbol(const wxString &aRef, std::initializer_list< std::pair< wxString, wxString > > aUserFields)
SCH_REFERENCE_LIST buildList(std::vector< SCH_SYMBOL > &aSymbols)
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(EmptyListYieldsNoConflicts)
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_CHECK_EQUAL(result, "25.4")