20#include <boost/test/unit_test.hpp>
45 m_model.SetShowColumn( referenceCol,
true );
48 void AddTestColumn(
const wxString& aFieldName,
bool aAddedByUser =
false )
50 m_model.AddColumn( aFieldName, aFieldName, aAddedByUser );
56 BOOST_REQUIRE_EQUAL(
m_model.GetNumberRows(), 1 );
67 m_model.ApplyData( commit, templates );
82 const wxString fieldName = wxS(
"UninstantiatedPresetField" );
84 AddTestColumn( fieldName );
90 BOOST_CHECK( m_footprint->GetField( fieldName ) ==
nullptr );
96 const wxString fieldName = wxS(
"ExplicitlyEmptyField" );
98 AddTestColumn( fieldName );
101 m_model.SetValue( 0, m_col, wxEmptyString );
108 const PCB_FIELD* field = m_footprint->GetField( fieldName );
110 BOOST_CHECK( field->
GetText().IsEmpty() );
116 const wxString fieldName = wxS(
"ExistingEmptyField" );
119 AddTestColumn( fieldName );
124 m_model.ClearCell( 0, m_col );
131 BOOST_CHECK( m_footprint->GetField( fieldName ) ==
nullptr );
137 const wxString fieldName = wxS(
"UserAddedEmptyField" );
139 AddTestColumn( fieldName,
true );
146 const PCB_FIELD* field = m_footprint->GetField( fieldName );
148 BOOST_CHECK( field->
GetText().IsEmpty() );
154 const wxString fieldName = wxS(
"${EXCLUDE_FROM_SIM}" );
156 AddTestColumn( fieldName );
158 BOOST_CHECK( !m_model.ColIsReadOnly( m_col ) );
161 m_model.SetValue( 0, m_col, wxS(
"1" ) );
164 BOOST_CHECK( m_footprint->IsExcludedFromSim() );
170 const wxString fieldName = wxS(
"${EXCLUDE_FROM_SIM}" );
171 const wxString variantName = wxS(
"Production" );
173 m_board.AddVariant( variantName );
174 m_model.SetCurrentVariant( variantName );
175 AddTestColumn( fieldName );
177 m_model.SetValue( 0, m_col, wxS(
"1" ) );
180 BOOST_CHECK( !m_footprint->IsExcludedFromSim() );
181 BOOST_CHECK( m_footprint->GetExcludedFromSimForVariant( variantName ) );
187 const wxString ordinaryFieldName = wxS(
"OrdinaryField" );
188 const wxString computedFieldName = wxS(
"@{1+2}" );
191 field->
SetText( wxS(
"Ordinary value" ) );
192 m_footprint->Add( field );
193 AddTestColumn( ordinaryFieldName );
195 m_model.RenameColumn( m_col, computedFieldName );
199 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxString( wxS(
"3" ) ) );
201 m_model.RenameColumn( m_col, ordinaryFieldName );
204 BOOST_CHECK( m_model.GetValue( 0, m_col ).IsEmpty() );
208 field = m_footprint->GetField( ordinaryFieldName );
210 BOOST_CHECK( field->
GetText().IsEmpty() );
211 BOOST_CHECK( m_footprint->GetField( computedFieldName ) ==
nullptr );
218 const wxString
name = wxS(
"MPN" );
220 field->
SetText( wxS(
"original" ) );
221 m_footprint->Add( field );
222 AddTestColumn(
name );
223 int editedCol = m_col;
226 m_model.SetValue( 0, editedCol, wxS(
"staged" ) );
227 m_footprint->SetPosition(
VECTOR2I( 100, 200 ) );
228 m_footprint->SetValue( wxS(
"external value" ) );
229 m_model.UpdateReferences( m_model.GetReferenceList() );
233 BOOST_CHECK( m_model.IsEdited() );
238 BOOST_CHECK( !m_model.IsEdited() );
240 m_model.SetValue( 0, editedCol, wxS(
"another staged edit" ) );
241 field->
SetText( wxS(
"newer external edit" ) );
242 m_model.UpdateReferences( m_model.GetReferenceList() );
243 BOOST_CHECK_EQUAL( m_model.GetValue( 0, editedCol ), wxS(
"newer external edit" ) );
244 BOOST_CHECK( !m_model.IsEdited() );
250 const wxString removed = wxS(
"Removed" );
252 AddTestColumn( removed );
253 int removedCol = m_col;
254 m_model.ClearCell( 0, removedCol );
256 const wxString created = wxS(
"Created" );
257 AddTestColumn( created );
258 m_model.SetValue( 0, m_col, wxEmptyString );
259 m_model.UpdateReferences( m_model.GetReferenceList() );
261 BOOST_CHECK( m_model.IsCellClear( 0, removedCol ) );
262 BOOST_CHECK( !m_model.IsCellClear( 0, m_col ) );
264 BOOST_CHECK( !m_footprint->GetField( removed ) );
266 BOOST_CHECK( m_footprint->GetField( created )->GetText().IsEmpty() );
274 m_footprint->SetValue( wxS(
"base" ) );
275 m_board.AddVariant( wxS(
"A" ) );
276 m_board.AddVariant( wxS(
"B" ) );
277 AddTestColumn(
name );
279 m_model.SetCurrentVariant( wxS(
"A" ) );
280 m_model.SetValue( 0, m_col, wxS(
"A staged" ) );
281 m_model.SetCurrentVariant( wxS(
"B" ) );
283 m_model.SetValue( 0, m_col, wxS(
"B staged" ) );
284 m_model.SetCurrentVariant( wxS(
"A" ) );
288 BOOST_CHECK( m_model.IsEdited() );
294 BOOST_CHECK( !m_model.IsEdited() );
295 m_model.UpdateReferences( m_model.GetReferenceList() );
296 BOOST_CHECK( !m_model.IsEdited() );
302 m_footprint->SetValue( wxS(
"base" ) );
308 model.SetShowColumn( 0,
true );
311 model.SetValue( 0, 1, wxS(
"discard me" ) );
312 model.SetCurrentVariant( wxS(
"Another" ) );
313 BOOST_CHECK(
model.IsEdited() );
323 m_footprint->SetValue( wxS(
"base" ) );
324 AddTestColumn(
name );
325 m_model.SetCurrentVariant( wxS(
"A" ) );
326 m_model.SetValue( 0, m_col, wxS(
"A staged" ) );
327 m_model.SetCurrentVariant( wxS(
"B" ) );
328 m_model.CopyCellFromVariant( 0, m_col, wxS(
"A" ) );
331 m_model.SetCurrentVariant( wxEmptyString );
332 m_model.CopyCellFromVariant( 0, m_col, wxS(
"B" ) );
334 m_model.SetValue( 0, m_col, wxS(
"default staged" ) );
335 m_model.SetCurrentVariant( wxS(
"A" ) );
342 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS(
"A" ),
name ), wxS(
"default staged" ) );
350 m_footprint->SetValue( wxS(
"base" ) );
351 m_footprint->AddVariant( wxS(
"A" ) )->SetFieldValue(
name, wxS(
"first" ) );
352 AddTestColumn(
name );
357 m_board.Add( other );
359 m_model.SetGroupingEnabled(
true );
360 m_model.SetGroupColumn( m_col,
true );
361 m_model.RebuildRows();
362 BOOST_REQUIRE_EQUAL( m_model.GetNumberRows(), 1 );
363 BOOST_REQUIRE_EQUAL( m_model.GetRowReferences( 0 ).size(), 2u );
365 m_model.CopyCellFromVariant( 0, m_col, wxS(
"A" ) );
376 m_footprint->SetValue( wxS(
"base" ) );
377 AddTestColumn(
name );
378 m_model.SetCurrentVariant( wxS(
"Untouched" ) );
379 m_model.SetCurrentVariant( wxEmptyString );
380 m_model.SetValue( 0, m_col, wxS(
"new base" ) );
381 m_model.SetCurrentVariant( wxS(
"Untouched" ) );
384 BOOST_CHECK_EQUAL( m_footprint->GetFieldValueForVariant( wxS(
"Untouched" ),
name ), wxS(
"new base" ) );
385 BOOST_CHECK( !m_footprint->GetVariant( wxS(
"Untouched" ) ) );
392 const wxString
name = wxS(
"SharedPresence" );
394 field->
SetText( wxS(
"base" ) );
395 m_footprint->Add( field );
396 AddTestColumn(
name );
397 m_model.SetCurrentVariant( wxS(
"A" ) );
398 m_model.ClearCell( 0, m_col );
399 m_model.SetCurrentVariant( wxS(
"B" ) );
400 BOOST_CHECK( m_model.IsCellClear( 0, m_col ) );
401 m_model.RevertRow( 0 );
403 BOOST_CHECK( !m_model.IsEdited() );
404 m_model.ClearCell( 0, m_col );
405 m_model.SetCurrentVariant( wxS(
"A" ) );
407 BOOST_CHECK( !m_footprint->GetField(
name ) );
413 m_footprint->SetValue( wxS(
"base" ) );
415 m_model.SetCurrentVariant( wxS(
"A" ) );
416 m_model.SetValue( 0, m_col, wxS(
"A staged" ) );
417 wxString snapshot = m_model.SerializeUndoState();
418 m_model.SetCurrentVariant( wxS(
"B" ) );
419 m_model.SetValue( 0, m_col, wxS(
"B staged" ) );
420 m_model.RestoreUndoState( snapshot );
422 m_model.SetCurrentVariant( wxS(
"A" ) );
425 m_footprint->SetValue( wxS(
"external" ) );
426 m_model.UpdateReferences( m_model.GetReferenceList() );
427 m_model.RestoreUndoState( snapshot );
429 BOOST_CHECK( !m_model.IsEdited() );
435 const wxString
name = wxS(
"MPN" );
437 field->
SetText( wxS(
"base" ) );
438 m_footprint->Add( field );
439 AddTestColumn(
name );
440 m_model.SetCurrentVariant( wxS(
"A" ) );
441 m_model.SetValue( 0, m_col, wxS(
"A staged" ) );
442 m_model.SetCurrentVariant( wxS(
"B" ) );
443 m_model.SetValue( 0, m_col, wxS(
"B staged" ) );
445 m_footprint->AddVariant( wxS(
"A" ) )->SetFieldValue(
name, wxS(
"A external" ) );
446 m_model.UpdateReferences( m_model.GetReferenceList() );
448 m_model.SetCurrentVariant( wxS(
"A" ) );
450 m_model.SetCurrentVariant( wxS(
"B" ) );
453 m_footprint->Remove( field );
455 m_model.UpdateReferences( m_model.GetReferenceList() );
456 BOOST_CHECK( m_model.IsCellClear( 0, m_col ) );
457 BOOST_CHECK( !m_model.IsEdited() );
459 BOOST_CHECK( !m_footprint->GetField(
name ) );
465 m_footprint->SetValue( wxS(
"base" ) );
467 m_model.SetCurrentVariant( wxS(
"A" ) );
468 m_model.SetValue( 0, m_col, wxS(
"A staged" ) );
469 m_model.SetCurrentVariant( wxS(
"B" ) );
470 m_model.SetValue( 0, m_col, wxS(
"B staged" ) );
471 m_model.RevertRow( 0 );
473 BOOST_CHECK( m_model.IsEdited() );
474 m_model.SetCurrentVariant( wxS(
"A" ) );
486 m_footprint->SetValue( wxS(
"10k" ) );
488 nested->
SetText( wxS(
"Value: ${VALUE}" ) );
489 m_footprint->Add( nested );
491 report->
SetText( wxS(
"${REFERENCE}: ${Nested} ${NESTED}" ) );
492 m_footprint->Add( report );
494 int valueCol = m_col;
495 AddTestColumn( wxS(
"Nested" ) );
496 AddTestColumn( wxS(
"Report" ) );
497 m_model.SetCurrentVariant( wxS(
"A" ) );
498 m_model.SetValue( 0, valueCol, wxS(
"4.7k" ) );
501 const wxString
expected = wxS(
"U1: Value: 4.7k ${NESTED}" );
505 m_model.SetCurrentVariant( wxS(
"B" ) );
506 m_model.SetValue( 0, valueCol, wxS(
"B staged" ) );
507 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS(
"U1: Value: B staged ${NESTED}" ) );
508 m_model.SetCurrentVariant( wxS(
"A" ) );
510 BOOST_CHECK( m_board.GetCurrentVariant().IsEmpty() );
518 field->
SetText( wxS(
"live" ) );
519 m_footprint->Add( field );
520 AddTestColumn( wxS(
"MPN" ) );
521 int fieldCol = m_col;
522 AddTestColumn( wxS(
"Report" ),
true );
523 m_model.SetValue( 0, m_col, wxS(
"[${MPN}] ${Unknown}" ) );
524 m_model.ClearCell( 0, fieldCol );
525 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS(
"[] ${Unknown}" ) );
526 m_model.SetValue( 0, fieldCol, wxEmptyString );
527 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS(
"[] ${Unknown}" ) );
528 m_model.SetValue( 0, fieldCol, wxS(
"staged" ) );
529 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, m_col ), wxS(
"[staged] ${Unknown}" ) );
530 m_model.RemoveColumn( fieldCol );
531 int reportCol = m_model.GetFieldNameCol( wxS(
"Report" ) );
532 BOOST_CHECK_EQUAL( m_model.GetResolvedValue( 0, reportCol ), wxS(
"[] ${Unknown}" ) );
Information pertinent to a Pcbnew printed circuit board.
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual void SetText(const wxString &aText)
wxString GetDefaultVariantName()
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(UntouchedMissingPresetFieldRemainsAbsent)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_EQUAL(result, "25.4")
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
VECTOR2< int32_t > VECTOR2I