KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_reference_list.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) 2022 Roberto Fernandez Bautista <[email protected]>
5 * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include "eeschema_test_utils.h"
23
24#include <sch_reference_list.h>
25#include <sch_sheet_path.h> // SCH_MULTI_UNIT_REFERENCE_MAP
26
27
29{
30 wxString m_KIID;
31 wxString m_OriginalRef;
32 wxString m_ExpectedRef;
34};
35
36
38{
39protected:
40 void loadTestCase( wxString aSchematicRelativePath, std::vector<REANNOTATED_REFERENCE> aRefs );
41
42 SCH_SYMBOL* getSymbolByKIID( wxString aKIID, SCH_SHEET_PATH* aSymbolPath );
43
45
46 void checkAnnotation( std::vector<REANNOTATED_REFERENCE> aRefs );
47
50};
51
52
53void TEST_SCH_REFERENCE_LIST_FIXTURE::loadTestCase( wxString aSchematicRelativePath,
54 std::vector<REANNOTATED_REFERENCE> aRefs )
55{
57 m_lockedRefs.clear();
58
59 LoadSchematic( aSchematicRelativePath );
60
61 // Create list of references to reannotate
62 for( REANNOTATED_REFERENCE ref : aRefs )
63 {
64 SCH_SHEET_PATH symbolPath;
65 SCH_SYMBOL* symbol = getSymbolByKIID( ref.m_KIID, &symbolPath );
66
67 //Make sure test case is built properly
68 BOOST_REQUIRE_NE( symbol, nullptr );
69 BOOST_REQUIRE_EQUAL( symbol->GetRef( &symbolPath, true ), ref.m_OriginalRef );
70
71 if( ref.m_IncludeInReannotationList )
72 {
73 symbolPath.AppendSymbol( m_refsToReannotate, symbol );
74 symbolPath.AppendMultiUnitSymbol( m_lockedRefs, symbol );
75 }
76 }
77}
78
79
81 SCH_SHEET_PATH* aSymbolPath )
82{
83 KIID symKIID( aKIID );
84 SCH_ITEM* foundItem = m_schematic.GetItem( symKIID, aSymbolPath );
85 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( foundItem );
86
87 return symbol;
88};
89
90
92{
93 // Build List of additional references to pass into Annotate()
94 SCH_REFERENCE_LIST allRefs, additionalRefs;
95
97
98 for( size_t i = 0; i < allRefs.GetCount(); ++i )
99 {
100 if( !m_refsToReannotate.Contains( allRefs[i] ) )
101 additionalRefs.AddItem( allRefs[i] );
102 }
103
104 return additionalRefs;
105}
106
107
108void TEST_SCH_REFERENCE_LIST_FIXTURE::checkAnnotation( std::vector<REANNOTATED_REFERENCE> aRefs )
109{
110 for( REANNOTATED_REFERENCE ref : aRefs )
111 {
112 SCH_SHEET_PATH symbolPath;
113 SCH_SYMBOL* symbol = getSymbolByKIID( ref.m_KIID, &symbolPath );
114
115 BOOST_CHECK_EQUAL( symbol->GetRef( &symbolPath, true ), ref.m_ExpectedRef );
116 }
117}
118
119
120BOOST_FIXTURE_TEST_SUITE( SchReferenceList, TEST_SCH_REFERENCE_LIST_FIXTURE )
121
122
124{
125 std::string m_caseName;
128 std::vector<REANNOTATED_REFERENCE> m_ExpectedReannotations;
129};
130
131// Case 1: same value, same libref
132// Case 2: same value, different libref
133// Case 3: different value, same libref
134// Case 4: Not annotated unit to reannotate
135// Case 5: Duplicate references
136static const std::vector<REANNOTATION_CASE> reannotationCases = {
137 { "CASE 1. Rename only selected. All units selected",
138 "test_multiunit_reannotate",
139 1,
140 {
141 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U3A", true },
142 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
143 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U3C", true },
144 } },
145 { "CASE 1. Rename only selected. Only unit B selected (A and C should NOT be reannotated)",
146 "test_multiunit_reannotate",
147 1,
148 {
149 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U99A", false },
150 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U2B", true },
151 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U99C", false },
152 } },
153 { "CASE 1. Rename only selected. Only units B and C selected (A should NOT be reannotated)",
154 "test_multiunit_reannotate",
155 1,
156 {
157 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U99A", false },
158 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
159 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U3C", true },
160 } },
161 { "CASE 2. Rename only selected. All units selected",
162 "test_multiunit_reannotate_2",
163 1,
164 {
165 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U3A", true },
166 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
167 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U3C", true },
168 } },
169 { "CASE 2. Rename only selected. Only unit B selected (A and C should NOT be reannotated)",
170 "test_multiunit_reannotate_2",
171 1,
172 {
173 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U99A", false },
174 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
175 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U99C", false },
176 } },
177 { "CASE 2. Rename only selected. Only units B and C selected (A should NOT be reannotated)",
178 "test_multiunit_reannotate_2",
179 1,
180 {
181 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U99A", false },
182 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
183 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U3C", true },
184 } },
185 { "CASE 3. Rename only selected. All units selected",
186 "test_multiunit_reannotate_3",
187 1,
188 {
189 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U3A", true },
190 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
191 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U3C", true },
192 } },
193 { "CASE 3. Rename only selected. Only unit B selected (A and C should NOT be reannotated)",
194 "test_multiunit_reannotate_3",
195 1,
196 {
197 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U99A", false },
198 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
199 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U99C", false },
200 } },
201 { "CASE 3. Rename only selected. Only units B and C selected (A should NOT be reannotated)",
202 "test_multiunit_reannotate_3",
203 1,
204 {
205 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U99A", "U99A", false },
206 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U99B", "U3B", true },
207 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U99C", "U3C", true },
208 } },
209 { "CASE 4 - Not previously annotated (does not get added to multi-unit locked group)",
210 "test_multiunit_reannotate_4",
211 1,
212 {
213 { "549455c3-ab6e-454e-94b0-5ca9e521ae0b", "U?B", "U2B", true },
214 } },
215 { "CASE 5 - Duplicate annotation. 1 selected",
216 "test_multiunit_reannotate_5",
217 10,
218 {
219 { "d43a1d25-d37a-467a-8b09-10cf2e2ace09", "U2A", "U2A", false },
220 { "cd562bae-2426-44e6-8196-59eee5439809", "U2B", "U2B", false },
221 { "3f20a749-efe3-4804-8fef-435caaa8dacb", "U2C", "U2C", false },
222 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U2A", "U2A", false },
223 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U2B", "U11B", true },
224 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U2C", "U2C", false },
225 } },
226 { "CASE 5 - Duplicate annotation. 2 selected",
227 "test_multiunit_reannotate_5",
228 10,
229 {
230 { "d43a1d25-d37a-467a-8b09-10cf2e2ace09", "U2A", "U2A", false },
231 { "cd562bae-2426-44e6-8196-59eee5439809", "U2B", "U11B", true },
232 { "3f20a749-efe3-4804-8fef-435caaa8dacb", "U2C", "U2C", false },
233 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U2A", "U2A", false },
234 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U2B", "U12B", true },
235 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U2C", "U2C", false },
236 } },
237};
238
239// @todo simplify or refactor this test case.
240// Currently it simulates part of SCH_EDIT_FRAME::AnnotateSymbols
242{
243 for( const REANNOTATION_CASE& c : reannotationCases )
244 {
245 BOOST_TEST_INFO_SCOPE( c.m_caseName );
246
247 loadTestCase( c.m_SchematicRelativePath, c.m_ExpectedReannotations );
248
249 m_refsToReannotate.RemoveAnnotation();
250 m_refsToReannotate.SplitReferences();
251 m_refsToReannotate.Annotate( false, 0, c.m_StartNumber, m_lockedRefs, getAdditionalRefs() );
252 m_refsToReannotate.UpdateAnnotation();
253
254 checkAnnotation( c.m_ExpectedReannotations );
255 }
256}
257
258
260{
261 std::string m_caseName;
263 std::vector<REANNOTATED_REFERENCE> m_ExpectedReannotations;
264};
265
266
267static const std::vector<DUPLICATE_REANNOTATION_CASE> reannotateDuplicatesCases = {
268 { "Reannotate Duplicates. Simple case",
269 "test_multiunit_reannotate_5",
270 {
271 { "d43a1d25-d37a-467a-8b09-10cf2e2ace09", "U2A", "U2A", false },
272 { "cd562bae-2426-44e6-8196-59eee5439809", "U2B", "U2B", false },
273 { "3f20a749-efe3-4804-8fef-435caaa8dacb", "U2C", "U2C", false },
274 { "cf058f25-2bad-4c49-a0c4-f059825c427f", "U2A", "U3A", true },
275 { "e6c8127f-e282-4128-8744-05f7893bc3ec", "U2B", "U3B", true },
276 { "db066797-b21c-4c1c-9591-8c7c549f8087", "U2C", "U3C", true },
277 } },
278};
279
280
281BOOST_AUTO_TEST_CASE( ReannotateDuplicates )
282{
284 {
285 BOOST_TEST_INFO_SCOPE( c.m_caseName );
286
287 loadTestCase( c.m_SchematicRelativePath, c.m_ExpectedReannotations );
288
289 m_refsToReannotate.ReannotateDuplicates( getAdditionalRefs() );
290 m_refsToReannotate.UpdateAnnotation();
291
292 checkAnnotation( c.m_ExpectedReannotations );
293 }
294}
295
296
Definition: kiid.h:49
A generic fixture for loading schematics and associated settings for qa tests.
virtual void LoadSchematic(const wxString &aRelativePath)
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Definition: schematic.h:116
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const override
Definition: schematic.h:97
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
bool Contains(const SCH_REFERENCE &aItem) const
Return true if aItem exists in this list.
size_t GetCount() const
void AddItem(const SCH_REFERENCE &aItem)
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void AppendMultiUnitSymbol(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true) const
Append a SCH_REFERENCE_LIST object to aRefList based on aSymbol, storing same-reference set of multi-...
void AppendSymbol(SCH_REFERENCE_LIST &aReferences, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Append a SCH_REFERENCE object to aReferences based on aSymbol.
Schematic symbol object.
Definition: sch_symbol.h:104
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:736
void checkAnnotation(std::vector< REANNOTATED_REFERENCE > aRefs)
SCH_MULTI_UNIT_REFERENCE_MAP m_lockedRefs
void loadTestCase(wxString aSchematicRelativePath, std::vector< REANNOTATED_REFERENCE > aRefs)
SCH_SYMBOL * getSymbolByKIID(wxString aKIID, SCH_SHEET_PATH *aSymbolPath)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
std::vector< REANNOTATED_REFERENCE > m_ExpectedReannotations
wxString m_KIID
KIID of the symbol to reannotate.
wxString m_ExpectedRef
Expected Reference Designator (after reannotating)
wxString m_OriginalRef
Original Reference Designator (prior to reannotating)
bool m_IncludeInReannotationList
True if reference is "selected" for reannotation.
std::vector< REANNOTATED_REFERENCE > m_ExpectedReannotations
BOOST_AUTO_TEST_SUITE_END()
static const std::vector< REANNOTATION_CASE > reannotationCases
BOOST_AUTO_TEST_CASE(Reannotate)
static const std::vector< DUPLICATE_REANNOTATION_CASE > reannotateDuplicatesCases