|
KiCad PCB EDA Suite
|
#include <algorithm>#include <chrono>#include <filesystem>#include <fstream>#include <memory>#include <sstream>#include <string>#include <thread>#include <qa_utils/file_utils.h>#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 <io/kicad/kicad_io_utils.h>#include <progress_reporter.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 <pcb_track.h>#include <zone.h>Go to the source code of this file.
Classes | |
| struct | KICAD_SEXPR_FIXTURE |
Macros | |
| #define | CHECK_ENUM_CLASS_EQUAL(L, R) |
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 (CoincidentDrawingsSurviveSave) | |
| Verify the parser still can read floating point values written in scientific notation. | |
| BOOST_AUTO_TEST_CASE (ScientificNotationLoading) | |
| BOOST_AUTO_TEST_CASE (Issue23625_CorruptedStackupCapped) | |
| Verify that a corrupted file with thousands of stackup items does not crash KiCad. | |
| BOOST_AUTO_TEST_CASE (Issue24133_DuplicatedStackupNotInflated) | |
| Verify that a file whose stackup was duplicated (the whole layer sequence repeated several times, as could happen after a board append in older versions) is reconciled on load so the board thickness is not inflated by the number of copies. | |
| 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 (Issue24642_AppendBoardPreservesDestinationLayerNames) | |
| Verify that appending a board into an existing one keeps the destination's layer names instead of overwriting them with the appended board's names, while still adding the extra copper layers the appended board needs. | |
| BOOST_AUTO_TEST_CASE (Issue24642_AppendBoardRemapsLayersViaHandler) | |
| Verify that a registered layer-mapping handler remaps the appended board's layers onto the destination layers the handler chooses. | |
| BOOST_AUTO_TEST_CASE (Issue24642_AppendBoardPromptsOnlyOnNameMismatch) | |
| Verify the mapping dialog is only triggered when the appended layers do not already correspond to the destination by name: appending a board onto one with identical layer names must not prompt, while appending one with differently-named layers must. | |
| 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 (MalformedDimensionTextThrowsCleanly) | |
| 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. | |
| BOOST_AUTO_TEST_CASE (Issue24955_AppendDoesNotInheritSessionZoneDefaults) | |
| Zone tokens at their format defaults are omitted from the file. | |
| BOOST_AUTO_TEST_CASE (Issue24911_CancelledAppendLeavesBoardUntouched) | |
| Cancelling a load that appends into an existing board must not leave any partially parsed items or nets behind (issue 24911) | |
| BOOST_AUTO_TEST_CASE (MissingLibraryThrowsOnEveryEnumerate) | |
| #define CHECK_ENUM_CLASS_EQUAL | ( | L, | |
| R ) |
Definition at line 51 of file test_kicad_sexpr.cpp.
Referenced by BOOST_AUTO_TEST_CASE().
| BOOST_AUTO_TEST_CASE | ( | CoincidentDrawingsSurviveSave | ) |
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 148 of file test_kicad_sexpr.cpp.
References BOARD::Add(), APPEND, BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), BOARD::Drawings(), F_SilkS, path, pcbIUScale, SEGMENT, PCB_SHAPE::SetEnd(), PCB_SHAPE::SetLayer(), PCB_SHAPE::SetStart(), and PCB_SHAPE::SetWidth().
| BOOST_AUTO_TEST_CASE | ( | CopperThievingZone_AllPatternsRoundTrip | ) |
Each THIEVING_PATTERN enum value should round-trip through the file format.
Catches token-table mistakes that only affect a specific pattern.
Definition at line 687 of file test_kicad_sexpr.cpp.
References ZONE::AppendCorner(), BOOST_TEST_CONTEXT(), COPPER_THIEVING, DOTS, F_Cu, ZONE::GetThievingSettings(), HATCH, PCB_IO::LoadBoard(), THIEVING_SETTINGS::pattern, pcbIUScale, PCB_IO_KICAD_SEXPR::SaveBoard(), ZONE::SetFillMode(), ZONE::SetLayer(), ZONE::SetThievingSettings(), and SQUARES.
| 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 738 of file test_kicad_sexpr.cpp.
References PCB_IO::LoadBoard().
| 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 789 of file test_kicad_sexpr.cpp.
References THIEVING_SETTINGS::element_size, THIEVING_SETTINGS::gap, THIEVING_SETTINGS::line_width, and PCB_IO::LoadBoard().
| 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 631 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::LoadBoard(), THIEVING_SETTINGS::orientation, THIEVING_SETTINGS::pattern, pcbIUScale, PCB_IO_KICAD_SEXPR::SaveBoard(), ZONE::SetFillMode(), ZONE::SetLayer(), ZONE::SetThievingSettings(), and THIEVING_SETTINGS::stagger.
| 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 521 of file test_kicad_sexpr.cpp.
References FOOTPRINT::Add(), PADSTACK::ALL_LAYERS, BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), CIRCLE, FOOTPRINT::Clone(), F_Cu, FOOTPRINT, BOARD_CONNECTED_ITEM::GetNet(), PADSTACK::NORMAL, NETINFO_LIST::OrphanedItem(), PAD, pad, PCB_PAD_T, PCB_SHAPE_T, PCB_ZONE_T, pcbIUScale, RECURSE, SEGMENT, PCB_SHAPE::SetEnd(), FOOTPRINT::SetFPID(), PCB_SHAPE::SetLayer(), ZONE::SetLayer(), BOARD_CONNECTED_ITEM::SetNet(), ZONE::SetNet(), PCB_SHAPE::SetStart(), and EDA_ITEM::Type().
| 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 72 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 | ( | 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 125 of file test_kicad_sexpr.cpp.
References BOOST_CHECK_EQUAL(), ZONE::GetNumCorners(), KI_TEST::GetPcbnewTestDataDir(), and ZONE::GetPosition().
| 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 207 of file test_kicad_sexpr.cpp.
References BOARD_STACKUP::GetCount(), and KI_TEST::GetPcbnewTestDataDir().
| 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.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23752
Definition at line 260 of file test_kicad_sexpr.cpp.
References PCB_IO_LOAD_PROPERTIES::APPEND_PRESERVE_DESTINATION_STACKUP, BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), BS_ITEM_TYPE_COPPER, BS_ITEM_TYPE_DIELECTRIC, BOARD_STACKUP_ITEM::GetMaterial(), KI_TEST::GetPcbnewTestDataDir(), BOARD_STACKUP_ITEM::GetThickness(), and BOARD_STACKUP::m_FinishType.
| BOOST_AUTO_TEST_CASE | ( | Issue24133_DuplicatedStackupNotInflated | ) |
Verify that a file whose stackup was duplicated (the whole layer sequence repeated several times, as could happen after a board append in older versions) is reconciled on load so the board thickness is not inflated by the number of copies.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24133
Definition at line 234 of file test_kicad_sexpr.cpp.
References BOOST_CHECK_EQUAL(), BOARD_STACKUP::BuildBoardThicknessFromStackup(), BOARD_STACKUP::GetCount(), KI_TEST::GetPcbnewTestDataDir(), and pcbIUScale.
| BOOST_AUTO_TEST_CASE | ( | Issue24642_AppendBoardPreservesDestinationLayerNames | ) |
Verify that appending a board into an existing one keeps the destination's layer names instead of overwriting them with the appended board's names, while still adding the extra copper layers the appended board needs.
Regression test for #24642
Definition at line 350 of file test_kicad_sexpr.cpp.
References PCB_IO_LOAD_PROPERTIES::APPEND_PRESERVE_DESTINATION_STACKUP, B_Cu, BOOST_CHECK_EQUAL(), F_Cu, KI_TEST::GetPcbnewTestDataDir(), In1_Cu, In2_Cu, In3_Cu, and In4_Cu.
| BOOST_AUTO_TEST_CASE | ( | Issue24642_AppendBoardPromptsOnlyOnNameMismatch | ) |
Verify the mapping dialog is only triggered when the appended layers do not already correspond to the destination by name: appending a board onto one with identical layer names must not prompt, while appending one with differently-named layers must.
Definition at line 468 of file test_kicad_sexpr.cpp.
References PCB_IO_LOAD_PROPERTIES::APPEND_PRESERVE_DESTINATION_STACKUP, and KI_TEST::GetPcbnewTestDataDir().
| BOOST_AUTO_TEST_CASE | ( | Issue24642_AppendBoardRemapsLayersViaHandler | ) |
Verify that a registered layer-mapping handler remaps the appended board's layers onto the destination layers the handler chooses.
The same source board is appended twice, once with an identity mapping and once swapping its two inner copper layers, and the per-layer track counts must swap accordingly.
Definition at line 390 of file test_kicad_sexpr.cpp.
References PCB_IO_LOAD_PROPERTIES::APPEND_PRESERVE_DESTINATION_STACKUP, B_Cu, BOOST_CHECK_EQUAL(), F_Cu, KI_TEST::GetPcbnewTestDataDir(), In1_Cu, In2_Cu, and BOARD::Tracks().
| BOOST_AUTO_TEST_CASE | ( | Issue24911_CancelledAppendLeavesBoardUntouched | ) |
Cancelling a load that appends into an existing board must not leave any partially parsed items or nets behind (issue 24911)
Definition at line 897 of file test_kicad_sexpr.cpp.
References PROGRESS_REPORTER::AddPhases(), PROGRESS_REPORTER::AdvancePhase(), PROGRESS_REPORTER::AdvanceProgress(), PROGRESS_REPORTER::BeginPhase(), BOOST_CHECK_EQUAL(), F_Cu, STRING_FORMATTER::GetString(), PROGRESS_REPORTER::IsCancelled(), PROGRESS_REPORTER::KeepRefreshing(), LINE_READER::LineNumber(), KICAD_FORMAT::Prettify(), STRING_LINE_READER::ReadLine(), PROGRESS_REPORTER::Report(), reporter, PROGRESS_REPORTER::SetCurrentProgress(), PCB_TRACK::SetEnd(), BOARD_CONNECTED_ITEM::SetLayer(), PROGRESS_REPORTER::SetMaxProgress(), BOARD_CONNECTED_ITEM::SetNet(), PROGRESS_REPORTER::SetNumPhases(), PCB_TRACK::SetStart(), PROGRESS_REPORTER::SetTitle(), PCB_TRACK::SetWidth(), STRING_LINE_READER::STRING_LINE_READER(), and text.
| BOOST_AUTO_TEST_CASE | ( | Issue24955_AppendDoesNotInheritSessionZoneDefaults | ) |
Zone tokens at their format defaults are omitted from the file.
When appending into a live board (design block placement, paste) the parsed zone must get the format defaults, not the destination board's default zone settings.
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24955
Definition at line 831 of file test_kicad_sexpr.cpp.
References BOOST_CHECK_EQUAL(), CHECK_ENUM_CLASS_EQUAL, ZONE_SETTINGS::FILLET, FULL, ZONE::GetCornerRadius(), ZONE::GetCornerSmoothingType(), ZONE::GetFillMode(), ZONE::GetHatchSmoothingLevel(), ZONE::GetPadConnection(), HATCH_PATTERN, BOARD_ITEM::IsLocked(), ZONE_SETTINGS::m_FillMode, ZONE_SETTINGS::m_HatchSmoothingLevel, ZONE_SETTINGS::m_Locked, ZONE_SETTINGS::NO_SMOOTHING, KI_TEST::SCOPED_TEMP_DIR::Path(), pcbIUScale, POLYGONS, ZONE_SETTINGS::SetCornerRadius(), ZONE_SETTINGS::SetCornerSmoothingType(), ZONE_SETTINGS::SetPadConnection(), and THERMAL.
| BOOST_AUTO_TEST_CASE | ( | MalformedDimensionTextThrowsCleanly | ) |
Definition at line 765 of file test_kicad_sexpr.cpp.
References PCB_IO::LoadBoard(), and KI_TEST::SCOPED_TEMP_DIR::Path().
| BOOST_AUTO_TEST_CASE | ( | MissingLibraryThrowsOnEveryEnumerate | ) |
Definition at line 1008 of file test_kicad_sexpr.cpp.
References BOOST_REQUIRE().
| BOOST_AUTO_TEST_CASE | ( | ScientificNotationLoading | ) |
Definition at line 182 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.