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 (C) 2023 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 <board.h>
25#include <kiid.h>
26#include <pcb_group.h>
31
32namespace
33{
34
35struct GROUP_LOAD_TEST_FIXTURE
36{
37 GROUP_LOAD_TEST_FIXTURE() {}
38};
39
40
41struct GROUP_LOAD_TEST_CASE
42{
43 // Which one to look at in the file?
44 KIID m_searchUuid;
45 // Expected values
46 bool m_expectedLocked;
47 wxString m_expectedName;
48 unsigned m_expectedMemberCount;
49};
50
51
52struct GROUP_LOAD_BOARD_TEST_CASE
53{
54 // The board to load
55 wxString m_boardFileRelativePath;
56
57 // These tests may well test specific versions of the board file format,
58 // so don't let it change accidentally!
59 int m_expectedBoardVersion;
60
61 // List of items to check on this board
62 std::vector<GROUP_LOAD_TEST_CASE> m_groupCases;
63};
64
65} // namespace
66
77BOOST_FIXTURE_TEST_CASE( GroupsLoadSave, GROUP_LOAD_TEST_FIXTURE )
78{
79 const std::vector<GROUP_LOAD_BOARD_TEST_CASE> groupTestCases{
80 {
81 "groups_load_save",
82 20231231,
83 {
84 // From top to bottom in the board file
85 {
86 "a78cc65c-451e-451e-9147-4460cc669685",
87 true,
88 "GroupName",
89 2,
90 },
91 },
92 },
93 {
94 // Before 20231231, 'id' was used in group s-exprs
95 // and we need to continue to load it for compatibility
96 "groups_load_save_v20231212",
97 20231212,
98 {
99 // From top to bottom in the board file
100 {
101 "a78cc65c-451e-451e-9147-4460cc669685",
102 true,
103 "GroupName",
104 2,
105 },
106 },
107 },
108 };
109
110 for( const GROUP_LOAD_BOARD_TEST_CASE& testCase : groupTestCases )
111 {
112 BOOST_TEST_MESSAGE( "Test case on file: " << testCase.m_boardFileRelativePath );
113
114 const auto doBoardTest = [&]( const BOARD& aBoard )
115 {
116 for( const GROUP_LOAD_TEST_CASE& groupTestCase : testCase.m_groupCases )
117 {
118 BOOST_TEST_MESSAGE( "Checking for group with UUID: "
119 << groupTestCase.m_searchUuid.AsString()
120 << " and name: " << groupTestCase.m_expectedName );
121
122 const auto& group = static_cast<PCB_GROUP&>( KI_TEST::RequireBoardItemWithTypeAndId(
123 aBoard, PCB_GROUP_T, groupTestCase.m_searchUuid ) );
124
125 BOOST_CHECK_EQUAL( group.IsLocked(), groupTestCase.m_expectedLocked );
126 BOOST_CHECK_EQUAL( group.GetName(), groupTestCase.m_expectedName );
127 BOOST_CHECK_EQUAL( group.GetItems().size(), groupTestCase.m_expectedMemberCount );
128 }
129 };
130
131 KI_TEST::LoadAndTestBoardFile( testCase.m_boardFileRelativePath, true, doBoardTest,
132 testCase.m_expectedBoardVersion );
133 }
134}
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
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_FIXTURE_TEST_CASE(GroupsLoadSave, GROUP_LOAD_TEST_FIXTURE)
This is similar to group_saveload.cpp's HealthyGroups, but runs the other way around: it loads a fixe...
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110