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>
34#include <pcb_shape.h>
35#include <zone.h>
36
37
44
45
49BOOST_FIXTURE_TEST_SUITE( KiCadSexprIO, KICAD_SEXPR_FIXTURE )
50
51
52
55BOOST_AUTO_TEST_CASE( Issue19775_ZoneLayerWildcards )
56{
57 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/kicad_sexpr/Issue19775_ZoneLayers/";
58
59 BOOST_TEST_CONTEXT( "Zone layers with wildcards" )
60 {
61 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
62
63 kicadPlugin.LoadBoard( dataPath + "LayerWildcard.kicad_pcb", testBoard.get() );
64
65 // One zone in the file
66 BOOST_CHECK( testBoard->Zones().size() == 1 );
67
68 ZONE* z = testBoard->Zones()[0];
69
70 // On both front and back layers, with zone fill on both
71 BOOST_CHECK( z->GetLayerSet().Contains( F_Cu ) && z->GetLayerSet().Contains( B_Cu ) );
72 BOOST_CHECK( z->GetFilledPolysList( F_Cu )->TotalVertices() > 0 );
73 BOOST_CHECK( z->GetFilledPolysList( B_Cu )->TotalVertices() > 0 );
74 }
75
76 BOOST_TEST_CONTEXT( "Round trip layers" )
77 {
78 auto tmpBoard = std::filesystem::temp_directory_path() / "Issue19775_RoundTrip.kicad_pcb";
79
80 // Load and save the board from above to test how we write the zones into it
81 {
82 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
83 kicadPlugin.LoadBoard( dataPath + "LayerEnumerate.kicad_pcb", testBoard.get() );
84 kicadPlugin.SaveBoard( tmpBoard.string(), testBoard.get() );
85 }
86
87 // Read the new board
88 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
89 kicadPlugin.LoadBoard( tmpBoard.string(), testBoard.get() );
90
91 // One zone in the file
92 BOOST_CHECK( testBoard->Zones().size() == 1 );
93
94 ZONE* z = testBoard->Zones()[0];
95
96 // On both front and back layers, with zone fill on both
97 BOOST_CHECK( z->GetLayerSet().Contains( F_Cu ) && z->GetLayerSet().Contains( B_Cu ) );
98 BOOST_CHECK( z->GetFilledPolysList( F_Cu )->TotalVertices() > 0 );
99 BOOST_CHECK( z->GetFilledPolysList( B_Cu )->TotalVertices() > 0 );
100 BOOST_CHECK( z->LayerProperties().contains( F_Cu ) );
101 }
102}
103
104
112BOOST_AUTO_TEST_CASE( Issue23125_EmptyZoneDiscarded )
113{
114 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
115 + "plugins/kicad_sexpr/Issue23125_EmptyZone/";
116
117 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
118
119 kicadPlugin.LoadBoard( dataPath + "EmptyZone.kicad_pcb", testBoard.get() );
120
121 // The file contains 3 zones: 1 valid (with polygon) and 2 empty (no polygon).
122 // The 2 empty zones should have been discarded during loading.
123 BOOST_CHECK_EQUAL( testBoard->Zones().size(), 1 );
124
125 // The surviving zone should have a valid position
126 ZONE* z = testBoard->Zones()[0];
127 BOOST_CHECK_NO_THROW( z->GetPosition() );
128 BOOST_CHECK( z->GetNumCorners() > 0 );
129}
130
131
137BOOST_AUTO_TEST_CASE( ScientificNotationLoading )
138{
139 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
140 + "plugins/kicad_sexpr/";
141
142 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
143
144 kicadPlugin.LoadBoard( dataPath + "ScientificNotation.kicad_pcb", testBoard.get() );
145
146 // The file contains 1 arc with scientific notation in its coordinates
147 BOOST_CHECK_EQUAL( testBoard->Drawings().size(), 1 );
148
149 PCB_SHAPE* arc = dynamic_cast<PCB_SHAPE*>( testBoard->Drawings().front() );
150
151 // The arc's midpoint should be located at (4.17, -4.5e-05) in file units
152 BOOST_REQUIRE( arc );
153 BOOST_TEST( arc->GetArcMid().x == 4170000 );
154 BOOST_TEST( arc->GetArcMid().y == -45 );
155}
156
157
General utilities for PCB file IO for QA programs.
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:73
ZONE_LAYER_PROPERTIES & LayerProperties(PCB_LAYER_ID aLayer)
Definition zone.h:149
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:606
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:136
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition zone.h:524
@ 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")