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 <zone.h>
35
36
38{
40
42};
43
44
48BOOST_FIXTURE_TEST_SUITE( KiCadSexprIO, KICAD_SEXPR_FIXTURE )
49
50
51
54BOOST_AUTO_TEST_CASE( Issue19775_ZoneLayerWildcards )
55{
56 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/kicad_sexpr/Issue19775_ZoneLayers/";
57
58 BOOST_TEST_CONTEXT( "Zone layers with wildcards" )
59 {
60 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
61
62 kicadPlugin.LoadBoard( dataPath + "LayerWildcard.kicad_pcb", testBoard.get() );
63
64 // One zone in the file
65 BOOST_CHECK( testBoard->Zones().size() == 1 );
66
67 ZONE* z = testBoard->Zones()[0];
68
69 // On both front and back layers, with zone fill on both
70 BOOST_CHECK( z->GetLayerSet().Contains( F_Cu ) && z->GetLayerSet().Contains( B_Cu ) );
71 BOOST_CHECK( z->GetFilledPolysList( F_Cu )->TotalVertices() > 0 );
72 BOOST_CHECK( z->GetFilledPolysList( B_Cu )->TotalVertices() > 0 );
73 }
74
75 BOOST_TEST_CONTEXT( "Round trip layers" )
76 {
77 auto tmpBoard = std::filesystem::temp_directory_path() / "Issue19775_RoundTrip.kicad_pcb";
78
79 // Load and save the board from above to test how we write the zones into it
80 {
81 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
82 kicadPlugin.LoadBoard( dataPath + "LayerEnumerate.kicad_pcb", testBoard.get() );
83 kicadPlugin.SaveBoard( tmpBoard.string(), testBoard.get() );
84 }
85
86 // Read the new board
87 std::unique_ptr<BOARD> testBoard = std::make_unique<BOARD>();
88 kicadPlugin.LoadBoard( tmpBoard.string(), testBoard.get() );
89
90 // One zone in the file
91 BOOST_CHECK( testBoard->Zones().size() == 1 );
92
93 ZONE* z = testBoard->Zones()[0];
94
95 // On both front and back layers, with zone fill on both
96 BOOST_CHECK( z->GetLayerSet().Contains( F_Cu ) && z->GetLayerSet().Contains( B_Cu ) );
97 BOOST_CHECK( z->GetFilledPolysList( F_Cu )->TotalVertices() > 0 );
98 BOOST_CHECK( z->GetFilledPolysList( B_Cu )->TotalVertices() > 0 );
99 }
100}
101
102
General utilities for PCB file IO for QA programs.
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.
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:627
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:133
@ 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_SUITE_END()
BOOST_AUTO_TEST_CASE(Issue19775_ZoneLayerWildcards)
Declares the struct as the Boost test fixture.
BOOST_TEST_CONTEXT("Test Clearance")