KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_lib_part.cpp File Reference

Test suite for LIB_SYMBOL. More...

#include <qa_utils/wx_utils/unit_test_utils.h>
#include <sch_shape.h>
#include <sch_pin.h>
#include <lib_symbol.h>
#include <functional>
#include <connectivity/conn_facts.h>
#include <font/font.h>
#include <locale_io.h>
#include <sch_file_versions.h>
#include <sch_io/sch_io.h>
#include <sch_io/sch_io_mgr.h>
#include <sch_io/kicad_sexpr/sch_io_kicad_sexpr.h>
#include <richio.h>
#include <units_provider.h>
#include <wx/file.h>
#include <wx/filename.h>
#include "lib_field_test_utils.h"

Go to the source code of this file.

Classes

class  TEST_LIB_SYMBOL_FIXTURE
 
class  SCOPED_TEMP_LIB
 A temporary symbol library that is removed when it goes out of scope. More...
 
struct  TEST_LIB_SYMBOL_SUBREF_CASE
 

Functions

void CheckDuplicatePins (LIB_SYMBOL *aSymbol, std::vector< wxString > &aMessages, UNITS_PROVIDER *aUnitsProvider)
 
static int alternateBodyStyleItemCount (LIB_SYMBOL &aSymbol)
 Return the number of draw items belonging to a body style beyond the standard one.
 
static std::unique_ptr< LIB_SYMBOL > loadDeMorganSymbol ()
 Load 4001, a four unit NOR gate carrying a De Morgan alternate body style.
 
static void saveToLib (const wxString &aLibPath, const LIB_SYMBOL &aSymbol)
 Write a symbol to its own library file.
 
static wxArrayString filterList (const std::vector< wxString > &aFilters)
 Build a footprint filter list.
 
static wxString formatted (LIB_SYMBOL &aSymbol)
 Serialize one symbol the way the library writer would.
 
 BOOST_AUTO_TEST_CASE (DefaultProperties)
 Declare the test suite.
 
 BOOST_AUTO_TEST_CASE (DefaultDrawings)
 Check the drawings on a "blank" LIB_SYMBOL.
 
 BOOST_AUTO_TEST_CASE (DefaultFields)
 Check the default fields are present as expected.
 
 BOOST_AUTO_TEST_CASE (AddedFields)
 Test adding fields to a LIB_SYMBOL.
 
 BOOST_AUTO_TEST_CASE (AddedDrawItems)
 Test adding draw items to a LIB_SYMBOL.
 
 BOOST_AUTO_TEST_CASE (StackedPinNumberLookup)
 A stacked pin is one drawn pin standing for several numbered contacts, written as a bracketed list.
 
 BOOST_AUTO_TEST_CASE (RangeStackedPinNumberLookup)
 The same, for range notation.
 
 BOOST_AUTO_TEST_CASE (SubReference)
 Test the subreference indexing.
 
 BOOST_AUTO_TEST_CASE (NativeBezierComparisonHandlesUnequalCaches)
 
 BOOST_AUTO_TEST_CASE (NativeCapturedDuplicatePinsMatchChecker)
 
 BOOST_AUTO_TEST_CASE (NativeLibrarySnapshotsMatchLiveComparison)
 
 BOOST_AUTO_TEST_CASE (NativeSymbolAttributesMatchCompareFlags)
 
 BOOST_AUTO_TEST_CASE (Compare)
 Check the compare method.
 
 BOOST_AUTO_TEST_CASE (GetUnitItems)
 Check the fetch unit items code.
 
 BOOST_AUTO_TEST_CASE (GetUnitDrawItems)
 Check the fetch unit draw items code.
 
 BOOST_AUTO_TEST_CASE (Inheritance)
 Check inheritance support.
 
 BOOST_AUTO_TEST_CASE (CopyConstructor)
 Check the copy constructor.
 
 BOOST_AUTO_TEST_CASE (IsPowerTest)
 Check the power and legacy power symbol tests.
 
 BOOST_AUTO_TEST_CASE (SetUnitCountRejectsInvalidValues)
 Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23788.
 
 BOOST_AUTO_TEST_CASE (DeleteDeMorganBodyStyleDrawItems)
 Regression test for https://gitlab.com/kicad/code/kicad/-/issues/25004.
 
 BOOST_AUTO_TEST_CASE (OrphanedBodyStyleItemsAreNotLoaded)
 Libraries already written with orphaned alternate drawings must load without them.
 
 BOOST_AUTO_TEST_CASE (NativeComparisonDetectsPinTypeChanges)
 
 BOOST_AUTO_TEST_CASE (NativeComparisonDetectsAddedPins)
 
 BOOST_AUTO_TEST_CASE (NativeComparisonHonorsMissingAndExtraFieldFlags)
 
 BOOST_AUTO_TEST_CASE (NativeComparisonHonorsPinVisibilityFlag)
 
 BOOST_AUTO_TEST_CASE (NativeComparisonHonorsAlternateDefinitionFlag)
 
 BOOST_AUTO_TEST_CASE (InheritedFootprintFiltersAreNotWritten)
 A derived symbol that defines no filters of its own must not be written carrying its parent's, because the parser assigns whatever it reads straight onto the symbol, so a written inherited value comes back as an override and the symbol stops following its parent.
 
 BOOST_AUTO_TEST_CASE (OwnFootprintFiltersAreWritten)
 Filters the derived symbol does own are a deliberate override and must still be written.
 
 BOOST_AUTO_TEST_CASE (ClearingOwnFootprintFiltersReturnsToInheriting)
 Clearing a derived symbol's filters returns it to inheriting rather than writing a copy of the parent's list onto it.
 
 BOOST_AUTO_TEST_CASE (FootprintFiltersSurviveSaveAndReload)
 The round trip through a real library file is what makes the leak permanent: write, read back, and the child owns filters nobody set on it.
 

Detailed Description

Test suite for LIB_SYMBOL.

Definition in file test_lib_part.cpp.

Function Documentation

◆ alternateBodyStyleItemCount()

static int alternateBodyStyleItemCount ( LIB_SYMBOL & aSymbol)
static

Return the number of draw items belonging to a body style beyond the standard one.

Definition at line 96 of file test_lib_part.cpp.

References BASE, and LIB_SYMBOL::GetDrawItems().

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ BOOST_AUTO_TEST_CASE() [1/30]

BOOST_AUTO_TEST_CASE ( AddedDrawItems )

Test adding draw items to a LIB_SYMBOL.

Definition at line 270 of file test_lib_part.cpp.

References BOOST_CHECK(), BOOST_CHECK_EQUAL(), and pin.

◆ BOOST_AUTO_TEST_CASE() [2/30]

BOOST_AUTO_TEST_CASE ( AddedFields )

◆ BOOST_AUTO_TEST_CASE() [3/30]

BOOST_AUTO_TEST_CASE ( ClearingOwnFootprintFiltersReturnsToInheriting )

Clearing a derived symbol's filters returns it to inheriting rather than writing a copy of the parent's list onto it.

An empty own-list is how a symbol says "inherit", so a derived symbol cannot express "deliberately no filters" at all, the same as for its keywords and its empty mandatory fields.

Definition at line 1432 of file test_lib_part.cpp.

References BOOST_CHECK(), filterList(), formatted(), LIB_SYMBOL::GetFPFilters(), LIB_SYMBOL::GetRawFPFilters(), LIB_SYMBOL::SetFPFilters(), and LIB_SYMBOL::SetParent().

◆ BOOST_AUTO_TEST_CASE() [4/30]

◆ BOOST_AUTO_TEST_CASE() [5/30]

BOOST_AUTO_TEST_CASE ( CopyConstructor )

Check the copy constructor.

Definition at line 1111 of file test_lib_part.cpp.

References BOOST_CHECK(), and copy.

◆ BOOST_AUTO_TEST_CASE() [6/30]

BOOST_AUTO_TEST_CASE ( DefaultDrawings )

Check the drawings on a "blank" LIB_SYMBOL.

Definition at line 200 of file test_lib_part.cpp.

References BOOST_CHECK_EQUAL().

◆ BOOST_AUTO_TEST_CASE() [7/30]

BOOST_AUTO_TEST_CASE ( DefaultFields )

Check the default fields are present as expected.

Definition at line 211 of file test_lib_part.cpp.

References KI_TEST::AreDefaultFieldsCorrect(), BOOST_CHECK_EQUAL(), BOOST_CHECK_PREDICATE(), DATASHEET, DESCRIPTION, KI_TEST::FieldNameIdMatches(), FOOTPRINT, REFERENCE, and VALUE.

◆ BOOST_AUTO_TEST_CASE() [8/30]

BOOST_AUTO_TEST_CASE ( DefaultProperties )

Declare the test suite.

Check that we can get the basic properties out as expected

Definition at line 175 of file test_lib_part.cpp.

References BOOST_AUTO_TEST_CASE(), and BOOST_CHECK_EQUAL().

◆ BOOST_AUTO_TEST_CASE() [9/30]

BOOST_AUTO_TEST_CASE ( DeleteDeMorganBodyStyleDrawItems )

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/25004.

Dropping a symbol back to a single body style must delete the alternate drawings whichever order the caller updates the body style metadata in. DIALOG_LIB_SYMBOL_PROPERTIES cleared the De Morgan flag first, which made SetBodyStyleCount() see a previous count of 1 and skip the deletion. The orphans then drew on top of the standard body style because renderers ask for body style 0 (all) when a symbol has only one.

Definition at line 1209 of file test_lib_part.cpp.

References alternateBodyStyleItemCount(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), and loadDeMorganSymbol().

◆ BOOST_AUTO_TEST_CASE() [10/30]

BOOST_AUTO_TEST_CASE ( FootprintFiltersSurviveSaveAndReload )

The round trip through a real library file is what makes the leak permanent: write, read back, and the child owns filters nobody set on it.

Definition at line 1462 of file test_lib_part.cpp.

References BOOST_CHECK(), BOOST_REQUIRE(), filterList(), LIB_SYMBOL::GetFPFilters(), SCOPED_TEMP_LIB::GetPath(), LIB_SYMBOL::GetRawFPFilters(), LIB_SYMBOL::GetValueField(), LIB_SYMBOL::IsDerived(), LIB_SYMBOL::SetFPFilters(), LIB_SYMBOL::SetParent(), and SCH_FIELD::SetText().

◆ BOOST_AUTO_TEST_CASE() [11/30]

BOOST_AUTO_TEST_CASE ( GetUnitDrawItems )

Check the fetch unit draw items code.

Definition at line 976 of file test_lib_part.cpp.

References BOOST_CHECK(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE_EQUAL(), and pin1.

◆ BOOST_AUTO_TEST_CASE() [12/30]

BOOST_AUTO_TEST_CASE ( GetUnitItems )

Check the fetch unit items code.

Definition at line 934 of file test_lib_part.cpp.

References ALL_BODY_STYLES, ALL_UNITS, BOOST_CHECK(), pin1, SCH_ITEM::SetBodyStyle(), SCH_PIN::SetNumber(), and SCH_ITEM::SetUnit().

◆ BOOST_AUTO_TEST_CASE() [13/30]

BOOST_AUTO_TEST_CASE ( Inheritance )

Check inheritance support.

Definition at line 1031 of file test_lib_part.cpp.

References BOOST_CHECK(), BOOST_CHECK_EQUAL(), DATASHEET, EDA_ITEM::SetParent(), SCH_FIELD::SetText(), and USER.

◆ BOOST_AUTO_TEST_CASE() [14/30]

BOOST_AUTO_TEST_CASE ( InheritedFootprintFiltersAreNotWritten )

A derived symbol that defines no filters of its own must not be written carrying its parent's, because the parser assigns whatever it reads straight onto the symbol, so a written inherited value comes back as an override and the symbol stops following its parent.

Definition at line 1379 of file test_lib_part.cpp.

References BOOST_CHECK(), BOOST_REQUIRE(), filterList(), LIB_SYMBOL::Flatten(), formatted(), LIB_SYMBOL::GetFPFilters(), LIB_SYMBOL::GetRawFPFilters(), LIB_SYMBOL::IsDerived(), LIB_SYMBOL::SetFPFilters(), and LIB_SYMBOL::SetParent().

◆ BOOST_AUTO_TEST_CASE() [15/30]

BOOST_AUTO_TEST_CASE ( IsPowerTest )

Check the power and legacy power symbol tests.

Definition at line 1121 of file test_lib_part.cpp.

References BOOST_CHECK(), pin, and PT_POWER_IN.

◆ BOOST_AUTO_TEST_CASE() [16/30]

◆ BOOST_AUTO_TEST_CASE() [17/30]

◆ BOOST_AUTO_TEST_CASE() [18/30]

◆ BOOST_AUTO_TEST_CASE() [19/30]

BOOST_AUTO_TEST_CASE ( NativeComparisonDetectsPinTypeChanges )

◆ BOOST_AUTO_TEST_CASE() [20/30]

◆ BOOST_AUTO_TEST_CASE() [21/30]

◆ BOOST_AUTO_TEST_CASE() [22/30]

◆ BOOST_AUTO_TEST_CASE() [23/30]

◆ BOOST_AUTO_TEST_CASE() [24/30]

◆ BOOST_AUTO_TEST_CASE() [25/30]

BOOST_AUTO_TEST_CASE ( OrphanedBodyStyleItemsAreNotLoaded )

Libraries already written with orphaned alternate drawings must load without them.

The declared body style count is authoritative for V10 and later files.

Definition at line 1241 of file test_lib_part.cpp.

References alternateBodyStyleItemCount(), BASE, BOOST_CHECK(), BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), LIB_SYMBOL::GetBodyStyleCount(), SCOPED_TEMP_LIB::GetPath(), LIB_SYMBOL::GetUnitCount(), LIB_SYMBOL::GetUnitDrawItems(), loadDeMorganSymbol(), and saveToLib().

◆ BOOST_AUTO_TEST_CASE() [26/30]

BOOST_AUTO_TEST_CASE ( OwnFootprintFiltersAreWritten )

Filters the derived symbol does own are a deliberate override and must still be written.

Definition at line 1408 of file test_lib_part.cpp.

References BOOST_CHECK(), filterList(), formatted(), LIB_SYMBOL::GetFPFilters(), LIB_SYMBOL::SetFPFilters(), LIB_SYMBOL::SetParent(), and text.

◆ BOOST_AUTO_TEST_CASE() [27/30]

BOOST_AUTO_TEST_CASE ( RangeStackedPinNumberLookup )

The same, for range notation.

The bracketed form must keep matching: it is the spelling that works today and is stored in existing symbols.

Definition at line 320 of file test_lib_part.cpp.

References BOOST_CHECK(), and pin.

◆ BOOST_AUTO_TEST_CASE() [28/30]

BOOST_AUTO_TEST_CASE ( SetUnitCountRejectsInvalidValues )

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23788.

SetUnitCount() must reject values less than 1. Previously, an importer (Altium .schdoc) could pass a negative or zero unit count, which caused the deletion loop to erase the mandatory fields (REFERENCE, VALUE, etc.) because their m_unit (== 0) was greater than the requested aCount. The symbol then crashed later when GetReferenceField() returned a null pointer that was implicitly dereferenced.

Definition at line 1160 of file test_lib_part.cpp.

References BOOST_CHECK_EQUAL(), CHECK_WX_ASSERT, DATASHEET, DESCRIPTION, FOOTPRINT, REFERENCE, LIB_SYMBOL::SetUnitCount(), and VALUE.

◆ BOOST_AUTO_TEST_CASE() [29/30]

BOOST_AUTO_TEST_CASE ( StackedPinNumberLookup )

A stacked pin is one drawn pin standing for several numbered contacts, written as a bracketed list.

Both the list itself and each contact it names are pins of the symbol.

Definition at line 298 of file test_lib_part.cpp.

References BOOST_CHECK(), and pin.

◆ BOOST_AUTO_TEST_CASE() [30/30]

BOOST_AUTO_TEST_CASE ( SubReference )

Test the subreference indexing.

Definition at line 346 of file test_lib_part.cpp.

References BOOST_CHECK_EQUAL(), BOOST_TEST_CONTEXT(), and LIB_SYMBOL::LetterSubReference().

◆ CheckDuplicatePins()

void CheckDuplicatePins ( LIB_SYMBOL * aSymbol,
std::vector< wxString > & aMessages,
UNITS_PROVIDER * aUnitsProvider )
extern

Definition at line 34 of file symbol_checker.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ filterList()

static wxArrayString filterList ( const std::vector< wxString > & aFilters)
static

Build a footprint filter list.

Definition at line 144 of file test_lib_part.cpp.

References filter, and filters.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ formatted()

◆ loadDeMorganSymbol()

static std::unique_ptr< LIB_SYMBOL > loadDeMorganSymbol ( )
static

◆ saveToLib()

static void saveToLib ( const wxString & aLibPath,
const LIB_SYMBOL & aSymbol )
static

Write a symbol to its own library file.

Definition at line 131 of file test_lib_part.cpp.

Referenced by BOOST_AUTO_TEST_CASE().