KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_group_load_save.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
25#include <boost/test/data/test_case.hpp>
26
27#include <board.h>
28#include <kiid.h>
29#include <pcb_group.h>
33
34namespace
35{
36struct GROUP_LOAD_TEST_CASE
37{
38 // Which one to look at in the file?
39 KIID m_searchUuid;
40 // Expected values
41 bool m_expectedLocked;
42 wxString m_expectedName;
43 unsigned m_expectedMemberCount;
44};
45
46
47struct GROUP_LOAD_BOARD_TEST_CASE: public KI_TEST::BOARD_LOAD_TEST_CASE
48{
49 // List of items to check on this board
50 std::vector<GROUP_LOAD_TEST_CASE> m_groupCases;
51};
52
53
54const std::vector<GROUP_LOAD_BOARD_TEST_CASE> GroupsLoadSave_testCases{
55 {
56 "groups_load_save",
57 20231231,
58 {
59 // From top to bottom in the board file
60 {
61 "a78cc65c-451e-451e-9147-4460cc669685",
62 true,
63 "GroupName",
64 2,
65 },
66 },
67 },
68 {
69 // Before 20231231, 'id' was used in group s-exprs
70 // and we need to continue to load it for compatibility
71 "groups_load_save_v20231212",
72 20231212,
73 {
74 // From top to bottom in the board file
75 {
76 "a78cc65c-451e-451e-9147-4460cc669685",
77 true,
78 "GroupName",
79 2,
80 },
81 },
82 },
83};
84
85} // namespace
86
97BOOST_DATA_TEST_CASE( GroupsLoadSave, boost::unit_test::data::make( GroupsLoadSave_testCases ),
98 testCase )
99{
100 const auto doBoardTest = [&]( const BOARD& aBoard )
101 {
102 for( const GROUP_LOAD_TEST_CASE& groupTestCase : testCase.m_groupCases )
103 {
104 BOOST_TEST_MESSAGE( "Checking for group with UUID: "
105 << groupTestCase.m_searchUuid.AsString()
106 << " and name: " << groupTestCase.m_expectedName );
107
108 const auto& group = static_cast<PCB_GROUP&>( KI_TEST::RequireBoardItemWithTypeAndId(
109 aBoard, PCB_GROUP_T, groupTestCase.m_searchUuid ) );
110
111 BOOST_CHECK_EQUAL( group.IsLocked(), groupTestCase.m_expectedLocked );
112 BOOST_CHECK_EQUAL( group.GetName(), groupTestCase.m_expectedName );
113 BOOST_CHECK_EQUAL( group.GetItems().size(), groupTestCase.m_expectedMemberCount );
114 }
115 };
116
117 KI_TEST::LoadAndTestBoardFile( testCase.m_BoardFileRelativePath, true, doBoardTest,
118 testCase.m_ExpectedBoardVersion );
119}
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:295
Definition: kiid.h:49
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
void LoadAndTestBoardFile(const wxString aRelativePath, bool aRoundtrip, std::function< void(BOARD &)> aBoardTestFunction, std::optional< int > aExpectedBoardVersion)
Perform "some test" on a board file loaded from the path, then optionally save and reload and run the...
BOARD_ITEM & RequireBoardItemWithTypeAndId(const BOARD &aBoard, KICAD_T aItemType, const KIID &aID)
Get an item from the given board with a certain type and UUID.
Class to handle a set of BOARD_ITEMs.
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_DATA_TEST_CASE(GroupsLoadSave, boost::unit_test::data::make(GroupsLoadSave_testCases), testCase)
This is similar to group_saveload.cpp's HealthyGroups, but runs the other way around: it loads a fixe...
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110