48 const std::vector<SCH_REFERENCE>& aExistingRefs,
49 const std::vector<int>& aRequiredUnits )
52 for(
int unit : aRequiredUnits )
54 for(
const auto& ref : aExistingRefs )
56 if( ref.GetUnit() == unit
57 && ref.CompareValue( aTestRef ) == 0 )
87 "Units available - no conflicts",
88 "U",
"LM358",
"OpAmp_Dual",
90 "LM358",
"OpAmp_Dual",
93 "Requested units don't conflict with existing units"
96 "Units conflict - same unit requested",
97 "U",
"LM358",
"OpAmp_Dual",
99 "LM358",
"OpAmp_Dual",
102 "Unit 2 is already in use"
105 "Value mismatch - can't share reference",
106 "R",
"1k",
"Resistor",
111 "Can't share reference designator with different values"
114 "Library mismatch - can't share reference",
115 "U",
"LM358",
"OpAmp_Dual",
117 "LM358",
"OpAmp_Single",
120 "Can't share reference designator with different library parts"
123 "Empty existing units - should be available",
124 "IC",
"74HC00",
"Logic_Gate",
126 "74HC00",
"Logic_Gate",
129 "No existing units to conflict with"
132 "Negative units filtered out",
133 "U",
"LM324",
"OpAmp_Quad",
135 "LM324",
"OpAmp_Quad",
138 "Negative unit numbers are filtered out, only units 1,3 considered"
141 "All units conflict",
142 "U",
"LM324",
"OpAmp_Quad",
144 "LM324",
"OpAmp_Quad",
147 "All requested units are already in use"
150 "Partial conflict with mixed values",
151 "R",
"1k",
"Resistor",
156 "Unit 1 conflicts even with same value (already occupied)"
159 "Complex multi-unit scenario",
160 "U",
"LM339",
"Comparator_Quad",
162 "LM339",
"Comparator_Quad",
165 "Units 2,4 don't conflict with existing 1,3"
175 BOOST_TEST_INFO_SCOPE( testCase.m_caseName );
188 bool valueMatches = ( aTestCase.m_refValue == aTestCase.m_existingValue );
191 bool libMatches = ( aTestCase.m_refLibName == aTestCase.m_existingLibName );
194 bool hasUnitConflict =
false;
195 for(
int requestedUnit : aTestCase.m_requestedUnits )
197 if( requestedUnit < 0 )
continue;
199 for(
int existingUnit : aTestCase.m_existingUnits )
201 if( requestedUnit == existingUnit )
203 hasUnitConflict =
true;
207 if( hasUnitConflict )
break;
212 bool shouldBeAvailable = valueMatches && libMatches && !hasUnitConflict;
216 if( shouldBeAvailable != aTestCase.m_expectedAvailable )
222 BOOST_TEST_MESSAGE(
" Expected: " + std::to_string( aTestCase.m_expectedAvailable ) );
227 validateUnitConflictLogic( testCase );
235 setupRefDesTracker( tracker );
245 SCH_REFERENCE testRef = createTestReference(
"U",
"LM358", 1 );
246 std::map<int, std::vector<SCH_REFERENCE>> emptyMap;
247 std::vector<int> emptyUnits;
257 BOOST_CHECK( tracker.
Contains(
"U2" ) );
258 BOOST_CHECK( tracker.
Contains(
"U10" ) );
261 SCH_REFERENCE icRef = createTestReference(
"IC",
"74HC00", 1 );
264 BOOST_CHECK( tracker.
Contains(
"IC1" ) );
270 setupRefDesTracker( tracker );
275 BOOST_CHECK( tracker.
Insert(
"R1" ) );
276 BOOST_CHECK( tracker.
Insert(
"R3" ) );
277 BOOST_CHECK( tracker.
Insert(
"R5" ) );
280 BOOST_CHECK( tracker.
Contains(
"R1" ) );
281 BOOST_CHECK( tracker.
Contains(
"R3" ) );
282 BOOST_CHECK( tracker.
Contains(
"R5" ) );
283 BOOST_CHECK( !tracker.
Contains(
"R2" ) );
284 BOOST_CHECK( !tracker.
Contains(
"R4" ) );
288 std::map<int, std::vector<SCH_REFERENCE>> emptyMap;
289 std::vector<int> emptyUnits;
293 BOOST_CHECK( tracker.
Contains(
"R2" ) );
298 BOOST_CHECK( tracker.
Contains(
"R4" ) );
303 BOOST_CHECK( tracker.
Contains(
"R6" ) );
312 setupRefDesTracker( tracker );
321 SCH_REFERENCE testRef = createTestReference(
"C",
"100nF", 1 );
322 std::map<int, std::vector<SCH_REFERENCE>> emptyMap;
323 std::vector<int> emptyUnits;
341 BOOST_CHECK( tracker.
Contains(
"C1" ) );
342 BOOST_CHECK( tracker.
Contains(
"C2" ) );
343 BOOST_CHECK( tracker.
Contains(
"C3" ) );
344 BOOST_CHECK( tracker.
Contains(
"C4" ) );
345 BOOST_CHECK( tracker.
Contains(
"C5" ) );
346 BOOST_CHECK( !tracker.
Contains(
"C6" ) );
347 BOOST_CHECK( tracker.
Contains(
"C7" ) );
348 BOOST_CHECK( tracker.
Contains(
"C10" ) );
354 setupRefDesTracker( tracker );
357 BOOST_CHECK( tracker.
Insert(
"U1" ) );
358 BOOST_CHECK( tracker.
Contains(
"U1" ) );
361 SCH_REFERENCE testRef = createTestReference(
"U",
"LM358", 1 );
362 std::map<int, std::vector<SCH_REFERENCE>> emptyMap;
363 std::vector<int> emptyUnits;
369 std::string serialized = tracker.
Serialize();
370 BOOST_CHECK( !serialized.empty() );
374 BOOST_CHECK( tracker2.
Contains(
"U1" ) );
375 BOOST_CHECK( tracker2.
Contains(
"U2" ) );
A generic fixture for loading schematics and associated settings for qa tests.
Class to efficiently track reference designators and provide next available designators.
bool Deserialize(const std::string &aData)
Deserialize tracker data from string representation.
int GetNextRefDesForUnits(const SCH_REFERENCE &aRef, const std::map< int, std::vector< SCH_REFERENCE > > &aRefNumberMap, const std::vector< int > &aRequiredUnits, int aMinValue)
Get the next available reference designator number for multi-unit symbols.
void SetReuseRefDes(bool aReuse)
bool Insert(const std::string &aRefDes)
Insert a reference designator into the tracker.
size_t Size() const
Get the total count of stored reference designators.
void SetUnitsChecker(const UNITS_CHECKER_FUNC< SCH_REFERENCE > &aChecker)
Set an external units checker function for SCH_REFERENCE objects.
std::string Serialize() const
Serialize the tracker data to a compact string representation.
bool Contains(const std::string &aRefDes) const
Check if a reference designator exists in the tracker.
A helper to define a symbol's reference designator in a schematic.
void SetValue(const wxString &aValue)
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...
SCH_REFERENCE createTestReference(const wxString &aRef, const wxString &aValue, int aUnit)
void setupRefDesTracker(REFDES_TRACKER &tracker)
std::string m_existingLibName
std::vector< int > m_existingUnits
std::vector< int > m_requestedUnits
std::string m_existingValue
static const std::vector< UNIT_CONFLICT_TEST_CASE > unitConflictCases
BOOST_AUTO_TEST_CASE(ValidateUnitConflictDetection)
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")