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

Unit tests for the PCB variant system including FOOTPRINT_VARIANT, BOARD variant registry, and variant-aware filtering. More...

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (FootprintVariantBasics)
 Test FOOTPRINT_VARIANT class basic operations.
 
 BOOST_AUTO_TEST_CASE (BoardVariantRegistry)
 Test BOARD variant registry operations.
 
 BOOST_AUTO_TEST_CASE (FootprintDNPForVariant)
 Test footprint DNP for variant.
 
 BOOST_AUTO_TEST_CASE (FootprintBOMExclusionForVariant)
 Test footprint BOM exclusion for variant.
 
 BOOST_AUTO_TEST_CASE (FootprintPosFileExclusionForVariant)
 Test footprint position file exclusion for variant.
 
 BOOST_AUTO_TEST_CASE (VariantCaseInsensitivity)
 Test variant case insensitivity for all operations.
 
 BOOST_AUTO_TEST_CASE (EmptyVariantReturnsBase)
 Test that empty variant name returns base attributes.
 
 BOOST_AUTO_TEST_CASE (UnknownVariantReturnsBase)
 Test that unknown variant name returns base attributes.
 
 BOOST_AUTO_TEST_CASE (FootprintVariantCopyAssignment)
 
 BOOST_AUTO_TEST_CASE (FootprintFieldShownTextForVariant)
 
 BOOST_AUTO_TEST_CASE (BoardVariantTextVars)
 
 BOOST_AUTO_TEST_CASE (NetlistComponentVariantsParsing)
 
 BOOST_AUTO_TEST_CASE (MultipleVariantsIndependent)
 Test adding multiple variants and verifying they're independent.
 
 BOOST_AUTO_TEST_CASE (VariantFieldUnicodeAndSpecialChars)
 Test variant field values with unicode and special characters.
 
 BOOST_AUTO_TEST_CASE (VariantDeletionClearsRegistry)
 Test variant deletion clears board variant registry.
 
 BOOST_AUTO_TEST_CASE (RenameVariantPreservesData)
 Test renaming variant to existing name fails or merges appropriately.
 
 BOOST_AUTO_TEST_CASE (GetVariantNamesForUIFormat)
 Test GetVariantNamesForUI returns sorted list with default first.
 
 BOOST_AUTO_TEST_CASE (VariantMultipleFlagsCombinations)
 Test multiple flags can be set independently for each variant.
 
 BOOST_AUTO_TEST_CASE (ComponentVariantToFootprintTransfer)
 Test that COMPONENT_VARIANT data from netlist transfers correctly to FOOTPRINT_VARIANT.
 
 BOOST_AUTO_TEST_CASE (ComponentVariantPartialOverride)
 Test that variant m_has* flags are properly respected during transfer.
 
 BOOST_AUTO_TEST_CASE (NetlistVariantAttributeParsing)
 Test that all variant attributes are properly parsed from netlist including exclude_from_pos_files.
 
 BOOST_AUTO_TEST_CASE (VariantAttributeTransferWithReset)
 Test the complete variant attribute transfer flow simulating board_netlist_updater behavior.
 
 BOOST_AUTO_TEST_CASE (VariantTestR2FootprintAttributeVerification)
 Test that recreates the user's observed bug:
 
 BOOST_AUTO_TEST_CASE (VariantTestProjectLoad)
 Test loading and verifying variant data from the variant_test project files.
 
 BOOST_AUTO_TEST_CASE (PosExportVariantValue)
 Test that PLACE_FILE_EXPORTER uses variant-specific Value fields (issue #23547).
 
 BOOST_AUTO_TEST_CASE (ExcessVariantsCleanedWhenNetlistEmpty)
 Regression test for issue #23564: stale footprint variant data must be cleaned up when the netlist contains no variant overrides for a component.
 
 BOOST_AUTO_TEST_CASE (ExcessVariantsSelectiveCleanup)
 Verify that excess-variants cleanup is selective: only variants NOT in the netlist are removed, while variants present in the netlist are preserved.
 

Detailed Description

Unit tests for the PCB variant system including FOOTPRINT_VARIANT, BOARD variant registry, and variant-aware filtering.

Definition in file test_variant.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/27]

◆ BOOST_AUTO_TEST_CASE() [2/27]

BOOST_AUTO_TEST_CASE ( BoardVariantTextVars )

◆ BOOST_AUTO_TEST_CASE() [3/27]

◆ BOOST_AUTO_TEST_CASE() [4/27]

◆ BOOST_AUTO_TEST_CASE() [5/27]

BOOST_AUTO_TEST_CASE ( EmptyVariantReturnsBase )

Test that empty variant name returns base attributes.

Definition at line 247 of file test_variant.cpp.

References BOARD::AddVariant(), FP_DNP, FOOTPRINT::GetDNPForVariant(), FOOTPRINT::SetAttributes(), FOOTPRINT_VARIANT::SetDNP(), and FOOTPRINT::SetVariant().

◆ BOOST_AUTO_TEST_CASE() [6/27]

BOOST_AUTO_TEST_CASE ( ExcessVariantsCleanedWhenNetlistEmpty )

Regression test for issue #23564: stale footprint variant data must be cleaned up when the netlist contains no variant overrides for a component.

The netlist exporter uses delta encoding and omits variant properties that match the base symbol. When ALL of a variant's properties match the base, no variant data is emitted, making the component's variant list empty. The excess-variants cleanup in applyComponentVariants must still run in this case.

Definition at line 1192 of file test_variant.cpp.

References _, BOARD::AddVariant(), FOOTPRINT::AddVariant(), BOOST_CHECK_EQUAL(), BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), FOOTPRINT::DeleteVariant(), FOOTPRINT::GetDNPForVariant(), FOOTPRINT::GetExcludedFromBOMForVariant(), FOOTPRINT::GetVariant(), FOOTPRINT::GetVariants(), FOOTPRINT::SetDNP(), FOOTPRINT_VARIANT::SetDNP(), FOOTPRINT::SetExcludedFromBOM(), FOOTPRINT_VARIANT::SetExcludedFromBOM(), FOOTPRINT::SetExcludedFromPosFiles(), FOOTPRINT::SetFPID(), and FOOTPRINT::SetReference().

◆ BOOST_AUTO_TEST_CASE() [7/27]

BOOST_AUTO_TEST_CASE ( ExcessVariantsSelectiveCleanup )

Verify that excess-variants cleanup is selective: only variants NOT in the netlist are removed, while variants present in the netlist are preserved.

Definition at line 1243 of file test_variant.cpp.

References _, BOARD::AddVariant(), FOOTPRINT::AddVariant(), BOOST_CHECK_EQUAL(), BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), FOOTPRINT::DeleteVariant(), FOOTPRINT::GetVariant(), FOOTPRINT::GetVariants(), FOOTPRINT::SetDNP(), FOOTPRINT_VARIANT::SetDNP(), FOOTPRINT_VARIANT::SetExcludedFromBOM(), FOOTPRINT::SetFPID(), and FOOTPRINT::SetReference().

◆ BOOST_AUTO_TEST_CASE() [8/27]

BOOST_AUTO_TEST_CASE ( FootprintBOMExclusionForVariant )

◆ BOOST_AUTO_TEST_CASE() [9/27]

BOOST_AUTO_TEST_CASE ( FootprintDNPForVariant )

◆ BOOST_AUTO_TEST_CASE() [10/27]

◆ BOOST_AUTO_TEST_CASE() [11/27]

BOOST_AUTO_TEST_CASE ( FootprintPosFileExclusionForVariant )

◆ BOOST_AUTO_TEST_CASE() [12/27]

◆ BOOST_AUTO_TEST_CASE() [13/27]

◆ BOOST_AUTO_TEST_CASE() [14/27]

BOOST_AUTO_TEST_CASE ( GetVariantNamesForUIFormat )

Test GetVariantNamesForUI returns sorted list with default first.

Definition at line 563 of file test_variant.cpp.

References BOARD::AddVariant(), and BOARD::GetVariantNamesForUI().

◆ BOOST_AUTO_TEST_CASE() [15/27]

◆ BOOST_AUTO_TEST_CASE() [16/27]

◆ BOOST_AUTO_TEST_CASE() [17/27]

BOOST_AUTO_TEST_CASE ( NetlistVariantAttributeParsing )

Test that all variant attributes are properly parsed from netlist including exclude_from_pos_files.

This verifies that the netlist parser correctly sets the m_has* flags for all attribute types.

Definition at line 826 of file test_variant.cpp.

References COMPONENT_VARIANT::m_dnp, COMPONENT_VARIANT::m_excludedFromBOM, COMPONENT_VARIANT::m_excludedFromPosFiles, COMPONENT_VARIANT::m_hasDnp, COMPONENT_VARIANT::m_hasExcludedFromBOM, and COMPONENT_VARIANT::m_hasExcludedFromPosFiles.

◆ BOOST_AUTO_TEST_CASE() [18/27]

BOOST_AUTO_TEST_CASE ( PosExportVariantValue )

Test that PLACE_FILE_EXPORTER uses variant-specific Value fields (issue #23547).

When a variant overrides a component's Value, the pos file export must reflect the variant's value, not the default footprint value. Both ASCII and CSV formats must respect the variant.

Definition at line 1113 of file test_variant.cpp.

References BOARD::Add(), BOARD::AddVariant(), FOOTPRINT, PLACE_FILE_EXPORTER::GenPositionData(), PLACE_FILE_EXPORTER::GenReportData(), PCB_FIELD::GetName(), INSERT, FOOTPRINT_VARIANT::SetFieldValue(), FOOTPRINT::SetReference(), FOOTPRINT::SetValue(), FOOTPRINT::SetVariant(), PLACE_FILE_EXPORTER::SetVariant(), and FOOTPRINT::Value().

◆ BOOST_AUTO_TEST_CASE() [19/27]

BOOST_AUTO_TEST_CASE ( RenameVariantPreservesData )

◆ BOOST_AUTO_TEST_CASE() [20/27]

BOOST_AUTO_TEST_CASE ( UnknownVariantReturnsBase )

Test that unknown variant name returns base attributes.

Definition at line 274 of file test_variant.cpp.

References BOARD::AddVariant(), FP_DNP, FOOTPRINT::GetDNPForVariant(), FOOTPRINT::SetAttributes(), FOOTPRINT_VARIANT::SetDNP(), and FOOTPRINT::SetVariant().

◆ BOOST_AUTO_TEST_CASE() [21/27]

◆ BOOST_AUTO_TEST_CASE() [22/27]

BOOST_AUTO_TEST_CASE ( VariantCaseInsensitivity )

Test variant case insensitivity for all operations.

Definition at line 220 of file test_variant.cpp.

References BOARD::AddVariant(), FOOTPRINT::GetDNPForVariant(), BOARD::HasVariant(), FOOTPRINT_VARIANT::SetDNP(), and FOOTPRINT::SetVariant().

◆ BOOST_AUTO_TEST_CASE() [23/27]

BOOST_AUTO_TEST_CASE ( VariantDeletionClearsRegistry )

◆ BOOST_AUTO_TEST_CASE() [24/27]

◆ BOOST_AUTO_TEST_CASE() [25/27]

◆ BOOST_AUTO_TEST_CASE() [26/27]

◆ BOOST_AUTO_TEST_CASE() [27/27]

BOOST_AUTO_TEST_CASE ( VariantTestR2FootprintAttributeVerification )

Test that recreates the user's observed bug:

  • R2 in schematic has Variant A with ONLY a Footprint field override (no attribute overrides)
  • On the board, there are TWO R2 footprints:
    1. C_1210 footprint (variant footprint) - should have NO explicit attribute overrides
    2. C_3640 footprint (base footprint) - SHOULD have DNP/ExcludedFromBOM/ExcludedFromPosFiles because this footprint is NOT used when building Variant A

The reported bug: "R2:Variant A has no attributes set in schematic but has 3 attributes on board" This test verifies which footprint has which attributes and whether that's correct behavior.

Definition at line 942 of file test_variant.cpp.

References BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), BOOST_TEST_MESSAGE(), FOOTPRINT_VARIANT::GetDNP(), FOOTPRINT_VARIANT::GetExcludedFromBOM(), FOOTPRINT_VARIANT::GetExcludedFromPosFiles(), KI_TEST::GetPcbnewTestDataDir(), FOOTPRINT::GetVariant(), FOOTPRINT::IsDNP(), FOOTPRINT::IsExcludedFromBOM(), FOOTPRINT::IsExcludedFromPosFiles(), and PCB_IO_KICAD_SEXPR::LoadBoard().