KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_kicad_sexpr.cpp File Reference
#include <filesystem>
#include <fstream>
#include <memory>
#include <sstream>
#include <string>
#include <pcbnew_utils/board_test_utils.h>
#include <pcbnew_utils/board_file_utils.h>
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
#include <richio.h>
#include <board.h>
#include <board_connected_item.h>
#include <board_design_settings.h>
#include <board_stackup_manager/board_stackup.h>
#include <footprint.h>
#include <netinfo.h>
#include <pad.h>
#include <pcb_shape.h>
#include <zone.h>

Go to the source code of this file.

Classes

struct  KICAD_SEXPR_FIXTURE
 

Functions

 BOOST_AUTO_TEST_CASE (Issue19775_ZoneLayerWildcards)
 Declares the struct as the Boost test fixture.
 
 BOOST_AUTO_TEST_CASE (Issue23125_EmptyZoneDiscarded)
 Verify that zones with no polygon outline are silently discarded during loading rather than being added to the board where they would cause crashes in GetPosition().
 
 BOOST_AUTO_TEST_CASE (ScientificNotationLoading)
 Verify the parser still can read floating point values written in scientific notation.
 
 BOOST_AUTO_TEST_CASE (Issue23625_CorruptedStackupCapped)
 Verify that a corrupted file with thousands of stackup items does not crash KiCad.
 
 BOOST_AUTO_TEST_CASE (Issue23752_AppendBoardPreservesStackupAndGrowsToSixCopperLayers)
 Verify that append-board preserves the destination stackup while still growing it to match a source board with more copper layers.
 
 BOOST_AUTO_TEST_CASE (FootprintSave_OmitsNetsOnAllBoardConnectedItems)
 Regression for the footprint-save SIGSEGV observed in KiCad 10.0.0 (introduced by b335ce6e2c "Don't save netcodes to files", which switched PCB_SHAPE/PCB_TRACK/ZONE serialization from writing the netcode to writing the netname).
 
 BOOST_AUTO_TEST_CASE (CopperThievingZone_RoundTrip)
 Verify that a copper-thieving zone round-trips through the kicad_sexpr writer and parser, preserving every THIEVING_SETTINGS field plus the netless invariant.
 
 BOOST_AUTO_TEST_CASE (CopperThievingZone_AllPatternsRoundTrip)
 Each THIEVING_PATTERN enum value should round-trip through the file format.
 
 BOOST_AUTO_TEST_CASE (CopperThievingZone_RejectedInOldFileVersion)
 Loading a .kicad_pcb that declares an old format version must reject (mode thieving) and (thieving ...) tokens.
 
 BOOST_AUTO_TEST_CASE (CopperThievingZone_RejectsMalformedGeometry)
 The parser must reject non-positive size / gap / width values inline so a hand-edited or corrupted file cannot leave the zone in a state that would deadlock the filler.
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/10]

BOOST_AUTO_TEST_CASE ( CopperThievingZone_AllPatternsRoundTrip )

◆ BOOST_AUTO_TEST_CASE() [2/10]

BOOST_AUTO_TEST_CASE ( CopperThievingZone_RejectedInOldFileVersion )

Loading a .kicad_pcb that declares an old format version must reject (mode thieving) and (thieving ...) tokens.

Otherwise a misversioned file could load on this build but silently corrupt on an older reader because the format never went through a proper transition.

Definition at line 517 of file test_kicad_sexpr.cpp.

References PCB_IO_KICAD_SEXPR::LoadBoard(), and readBoard().

◆ BOOST_AUTO_TEST_CASE() [3/10]

BOOST_AUTO_TEST_CASE ( CopperThievingZone_RejectsMalformedGeometry )

The parser must reject non-positive size / gap / width values inline so a hand-edited or corrupted file cannot leave the zone in a state that would deadlock the filler.

Verifies the inline clamp keeps the constructor defaults for any malformed field.

Definition at line 551 of file test_kicad_sexpr.cpp.

References THIEVING_SETTINGS::element_size, THIEVING_SETTINGS::gap, THIEVING_SETTINGS::line_width, PCB_IO_KICAD_SEXPR::LoadBoard(), and readBoard().

◆ BOOST_AUTO_TEST_CASE() [4/10]

BOOST_AUTO_TEST_CASE ( CopperThievingZone_RoundTrip )

Verify that a copper-thieving zone round-trips through the kicad_sexpr writer and parser, preserving every THIEVING_SETTINGS field plus the netless invariant.

Tests the writer's (mode thieving) emission, the (thieving ...) sub-block format, and the parser's case for both. Independently exercises each pattern value to catch keyword-table omissions.

Definition at line 408 of file test_kicad_sexpr.cpp.

References ZONE::AppendCorner(), BOOST_CHECK_EQUAL(), COPPER_THIEVING, DEGREES_T, THIEVING_SETTINGS::element_size, F_Cu, THIEVING_SETTINGS::gap, ZONE::GetFillMode(), BOARD_CONNECTED_ITEM::GetNetCode(), ZONE::GetThievingSettings(), HATCH, ZONE::IsCopperThieving(), THIEVING_SETTINGS::line_width, PCB_IO_KICAD_SEXPR::LoadBoard(), THIEVING_SETTINGS::orientation, THIEVING_SETTINGS::pattern, pcbIUScale, readBoard(), PCB_IO_KICAD_SEXPR::SaveBoard(), ZONE::SetFillMode(), ZONE::SetLayer(), ZONE::SetThievingSettings(), and THIEVING_SETTINGS::stagger.

◆ BOOST_AUTO_TEST_CASE() [5/10]

BOOST_AUTO_TEST_CASE ( FootprintSave_OmitsNetsOnAllBoardConnectedItems )

Regression for the footprint-save SIGSEGV observed in KiCad 10.0.0 (introduced by b335ce6e2c "Don't save netcodes to files", which switched PCB_SHAPE/PCB_TRACK/ZONE serialization from writing the netcode to writing the netname).

If a footprint's descendants carry m_netinfo pointers that belong to a different (possibly destroyed) board, the library serializer reads through those pointers and can SEGV inside BOARD_CONNECTED_ITEM::GetNetname().

The library-save path must (a) skip writing (net ...) tokens for pads/shapes/tracks/zones when CTL_OMIT_PAD_NETS is set (as it is under CTL_FOR_LIBRARY) and (b) orphan every BOARD_CONNECTED_ITEM descendant on the cloned footprint before serialization, so that any downstream code reading m_netinfo lands on the board-independent ORPHANED singleton.

This test exercises the library-save path with a footprint whose pad, copper shape and copper zone all reference a real net on a locally-built board. The emitted .kicad_mod must contain no "(net " tokens, and ClearAllNets() must orphan every connected item.

Definition at line 303 of file test_kicad_sexpr.cpp.

References FOOTPRINT::Add(), PADSTACK::ALL_LAYERS, BOOST_CHECK_EQUAL(), BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), CIRCLE, FOOTPRINT::Clone(), F_Cu, FOOTPRINT, BOARD_CONNECTED_ITEM::GetNet(), NETINFO_LIST::OrphanedItem(), PAD, pad, PCB_PAD_T, PCB_SHAPE_T, PCB_ZONE_T, pcbIUScale, RECURSE, SEGMENT, EDA_SHAPE::SetEnd(), FOOTPRINT::SetFPID(), PCB_SHAPE::SetLayer(), ZONE::SetLayer(), BOARD_CONNECTED_ITEM::SetNet(), ZONE::SetNet(), EDA_SHAPE::SetStart(), and EDA_ITEM::Type().

◆ BOOST_AUTO_TEST_CASE() [6/10]

BOOST_AUTO_TEST_CASE ( Issue19775_ZoneLayerWildcards )

Declares the struct as the Boost test fixture.

Compare all footprints declared in a *.lbr file with their KiCad reference footprint

Definition at line 65 of file test_kicad_sexpr.cpp.

References B_Cu, BOOST_AUTO_TEST_CASE(), BOOST_TEST_CONTEXT(), LSET::Contains(), F_Cu, ZONE::GetFilledPolysList(), ZONE::GetLayerSet(), KI_TEST::GetPcbnewTestDataDir(), ZONE::LayerProperties(), and SHAPE_POLY_SET::TotalVertices().

◆ BOOST_AUTO_TEST_CASE() [7/10]

BOOST_AUTO_TEST_CASE ( Issue23125_EmptyZoneDiscarded )

Verify that zones with no polygon outline are silently discarded during loading rather than being added to the board where they would cause crashes in GetPosition().

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

Definition at line 122 of file test_kicad_sexpr.cpp.

References BOOST_CHECK_EQUAL(), ZONE::GetNumCorners(), KI_TEST::GetPcbnewTestDataDir(), and ZONE::GetPosition().

◆ BOOST_AUTO_TEST_CASE() [8/10]

BOOST_AUTO_TEST_CASE ( Issue23625_CorruptedStackupCapped )

Verify that a corrupted file with thousands of stackup items does not crash KiCad.

The parser should silently cap the stackup item count.

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

Definition at line 174 of file test_kicad_sexpr.cpp.

References BOARD_STACKUP::GetCount(), and KI_TEST::GetPcbnewTestDataDir().

◆ BOOST_AUTO_TEST_CASE() [9/10]

BOOST_AUTO_TEST_CASE ( Issue23752_AppendBoardPreservesStackupAndGrowsToSixCopperLayers )

◆ BOOST_AUTO_TEST_CASE() [10/10]

BOOST_AUTO_TEST_CASE ( ScientificNotationLoading )

Verify the parser still can read floating point values written in scientific notation.

Even though the KiCad file writter doesn't write using scientific notation anymore, at one point it did, so the parser must still support reading it.

Definition at line 147 of file test_kicad_sexpr.cpp.

References BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), BOOST_TEST(), EDA_SHAPE::GetArcMid(), KI_TEST::GetPcbnewTestDataDir(), VECTOR2< T >::x, and VECTOR2< T >::y.