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 <locale_io.h>
#include <sch_file_versions.h>
#include <sch_io/sch_io.h>
#include <sch_io/sch_io_mgr.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

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_SYMBOLloadDeMorganSymbol ()
 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.
 
 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 (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)
 

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 87 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/23]

BOOST_AUTO_TEST_CASE ( AddedDrawItems )

Test adding draw items to a LIB_SYMBOL.

Definition at line 236 of file test_lib_part.cpp.

References BOOST_CHECK_EQUAL(), and pin.

◆ BOOST_AUTO_TEST_CASE() [2/23]

BOOST_AUTO_TEST_CASE ( AddedFields )

Test adding fields to a LIB_SYMBOL.

Definition at line 205 of file test_lib_part.cpp.

References KI_TEST::AreDefaultFieldsCorrect(), BOOST_CHECK_PREDICATE(), KI_TEST::FieldNameIdMatches(), and USER.

◆ BOOST_AUTO_TEST_CASE() [3/23]

◆ BOOST_AUTO_TEST_CASE() [4/23]

BOOST_AUTO_TEST_CASE ( CopyConstructor )

Check the copy constructor.

Definition at line 873 of file test_lib_part.cpp.

References copy.

◆ BOOST_AUTO_TEST_CASE() [5/23]

BOOST_AUTO_TEST_CASE ( DefaultDrawings )

Check the drawings on a "blank" LIB_SYMBOL.

Definition at line 166 of file test_lib_part.cpp.

References BOOST_CHECK_EQUAL().

◆ BOOST_AUTO_TEST_CASE() [6/23]

BOOST_AUTO_TEST_CASE ( DefaultFields )

Check the default fields are present as expected.

Definition at line 177 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() [7/23]

BOOST_AUTO_TEST_CASE ( DefaultProperties )

Declare the test suite.

Check that we can get the basic properties out as expected

Definition at line 141 of file test_lib_part.cpp.

References BOOST_AUTO_TEST_CASE(), and BOOST_CHECK_EQUAL().

◆ BOOST_AUTO_TEST_CASE() [8/23]

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 971 of file test_lib_part.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [9/23]

BOOST_AUTO_TEST_CASE ( GetUnitDrawItems )

Check the fetch unit draw items code.

Definition at line 738 of file test_lib_part.cpp.

References BOOST_CHECK_EQUAL(), and pin1.

◆ BOOST_AUTO_TEST_CASE() [10/23]

BOOST_AUTO_TEST_CASE ( GetUnitItems )

Check the fetch unit items code.

Definition at line 696 of file test_lib_part.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [11/23]

BOOST_AUTO_TEST_CASE ( Inheritance )

Check inheritance support.

Definition at line 793 of file test_lib_part.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [12/23]

BOOST_AUTO_TEST_CASE ( IsPowerTest )

Check the power and legacy power symbol tests.

Definition at line 883 of file test_lib_part.cpp.

References pin, and PT_POWER_IN.

◆ BOOST_AUTO_TEST_CASE() [13/23]

◆ BOOST_AUTO_TEST_CASE() [14/23]

◆ BOOST_AUTO_TEST_CASE() [15/23]

BOOST_AUTO_TEST_CASE ( NativeComparisonDetectsPinTypeChanges )

◆ BOOST_AUTO_TEST_CASE() [16/23]

BOOST_AUTO_TEST_CASE ( NativeComparisonHonorsAlternateDefinitionFlag )

◆ BOOST_AUTO_TEST_CASE() [17/23]

◆ BOOST_AUTO_TEST_CASE() [18/23]

◆ BOOST_AUTO_TEST_CASE() [19/23]

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 1003 of file test_lib_part.cpp.

References alternateBodyStyleItemCount(), BASE, 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() [20/23]

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 286 of file test_lib_part.cpp.

References pin.

◆ BOOST_AUTO_TEST_CASE() [21/23]

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 922 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() [22/23]

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 264 of file test_lib_part.cpp.

References pin.

◆ BOOST_AUTO_TEST_CASE() [23/23]

BOOST_AUTO_TEST_CASE ( SubReference )

Test the subreference indexing.

Definition at line 312 of file test_lib_part.cpp.

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

◆ loadDeMorganSymbol()

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

Load 4001, a four unit NOR gate carrying a De Morgan alternate body style.

Definition at line 104 of file test_lib_part.cpp.

References KI_TEST::GetEeschemaTestDataDir().

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

◆ saveToLib()

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

Write a symbol to its own library file.

Definition at line 122 of file test_lib_part.cpp.

Referenced by BOOST_AUTO_TEST_CASE().