KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_kicad_sexpr.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <filesystem>
25#include <string>
26
30
32
33#include <board.h>
36#include <pcb_shape.h>
37#include <zone.h>
38
39
46
47
51BOOST_FIXTURE_TEST_SUITE( KiCadSexprIO, KICAD_SEXPR_FIXTURE )
52
53
54
57BOOST_AUTO_TEST_CASE( Issue19775_ZoneLayerWildcards )
58{
59 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/kicad_sexpr/Issue19775_ZoneLayers/";
60
61 BOOST_TEST_CONTEXT( "Zone layers with wildcards" )
62 {
63 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
64
65 kicadPlugin.LoadBoard( dataPath + "LayerWildcard.kicad_pcb", testBoard.get() );
66
67 // One zone in the file
68 BOOST_CHECK( testBoard->Zones().size() == 1 );
69
70 ZONE* z = testBoard->Zones()[0];
71
72 // On both front and back layers, with zone fill on both
73 BOOST_CHECK( z->GetLayerSet().Contains( F_Cu ) && z->GetLayerSet().Contains( B_Cu ) );
74 BOOST_CHECK( z->GetFilledPolysList( F_Cu )->TotalVertices() > 0 );
75 BOOST_CHECK( z->GetFilledPolysList( B_Cu )->TotalVertices() > 0 );
76 }
77
78 BOOST_TEST_CONTEXT( "Round trip layers" )
79 {
80 auto tmpBoard = std::filesystem::temp_directory_path() / "Issue19775_RoundTrip.kicad_pcb";
81
82 // Load and save the board from above to test how we write the zones into it
83 {
84 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
85 kicadPlugin.LoadBoard( dataPath + "LayerEnumerate.kicad_pcb", testBoard.get() );
86 kicadPlugin.SaveBoard( tmpBoard.string(), testBoard.get() );
87 }
88
89 // Read the new board
90 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
91 kicadPlugin.LoadBoard( tmpBoard.string(), testBoard.get() );
92
93 // One zone in the file
94 BOOST_CHECK( testBoard->Zones().size() == 1 );
95
96 ZONE* z = testBoard->Zones()[0];
97
98 // On both front and back layers, with zone fill on both
99 BOOST_CHECK( z->GetLayerSet().Contains( F_Cu ) && z->GetLayerSet().Contains( B_Cu ) );
100 BOOST_CHECK( z->GetFilledPolysList( F_Cu )->TotalVertices() > 0 );
101 BOOST_CHECK( z->GetFilledPolysList( B_Cu )->TotalVertices() > 0 );
102 BOOST_CHECK( z->LayerProperties().contains( F_Cu ) );
103 }
104}
105
106
114BOOST_AUTO_TEST_CASE( Issue23125_EmptyZoneDiscarded )
115{
116 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
117 + "plugins/kicad_sexpr/Issue23125_EmptyZone/";
118
119 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
120
121 kicadPlugin.LoadBoard( dataPath + "EmptyZone.kicad_pcb", testBoard.get() );
122
123 // The file contains 3 zones: 1 valid (with polygon) and 2 empty (no polygon).
124 // The 2 empty zones should have been discarded during loading.
125 BOOST_CHECK_EQUAL( testBoard->Zones().size(), 1 );
126
127 // The surviving zone should have a valid position
128 ZONE* z = testBoard->Zones()[0];
129 BOOST_CHECK_NO_THROW( z->GetPosition() );
130 BOOST_CHECK( z->GetNumCorners() > 0 );
131}
132
133
139BOOST_AUTO_TEST_CASE( ScientificNotationLoading )
140{
141 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
142 + "plugins/kicad_sexpr/";
143
144 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
145
146 kicadPlugin.LoadBoard( dataPath + "ScientificNotation.kicad_pcb", testBoard.get() );
147
148 // The file contains 1 arc with scientific notation in its coordinates
149 BOOST_CHECK_EQUAL( testBoard->Drawings().size(), 1 );
150
151 PCB_SHAPE* arc = dynamic_cast<PCB_SHAPE*>( testBoard->Drawings().front() );
152
153 // The arc's midpoint should be located at (4.17, -4.5e-05) in file units
154 BOOST_REQUIRE( arc );
155 BOOST_TEST( arc->GetArcMid().x == 4170000 );
156 BOOST_TEST( arc->GetArcMid().y == -45 );
157}
158
159
166BOOST_AUTO_TEST_CASE( Issue23625_CorruptedStackupCapped )
167{
168 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
169 + "plugins/kicad_sexpr/Issue23625_CorruptedStackup/";
170
171 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
172
173 BOOST_CHECK_NO_THROW( kicadPlugin.LoadBoard( dataPath + "corrupted_stackup.kicad_pcb",
174 testBoard.get() ) );
175
176 const BOARD_STACKUP& stackup =
177 testBoard->GetDesignSettings().GetStackupDescriptor();
178
179 // The test file has 200 dielectric layers (plus copper, silk, mask), well
180 // beyond the parser's 128-item cap. After loading, the count must be
181 // clamped and the board must still be usable.
182 BOOST_CHECK_LE( stackup.GetCount(), 128 );
183 BOOST_CHECK_GT( stackup.GetCount(), 0 );
184}
185
186
General utilities for PCB file IO for QA programs.
Manage layers needed to make a physical board.
int GetCount() const
VECTOR2I GetArcMid() const
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
int TotalVertices() const
Return total number of vertices stored in the set.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
ZONE_LAYER_PROPERTIES & LayerProperties(PCB_LAYER_ID aLayer)
Definition zone.h:150
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:602
VECTOR2I GetPosition() const override
Definition zone.cpp:492
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:137
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition zone.h:520
@ B_Cu
Definition layer_ids.h:65
@ F_Cu
Definition layer_ids.h:64
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
PCB_IO_KICAD_SEXPR kicadPlugin
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_TEST(contains==c.ExpectedContains)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Issue19775_ZoneLayerWildcards)
Declares the struct as the Boost test fixture.
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")