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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <boost/test/data/test_case.hpp>
22
23#include <board.h>
24#include <kiid.h>
25#include <pcb_group.h>
29
30namespace
31{
32struct GROUP_LOAD_TEST_CASE
33{
34 // Which one to look at in the file?
35 KIID m_searchUuid;
36 // Expected values
37 bool m_expectedLocked;
38 wxString m_expectedName;
39 unsigned m_expectedMemberCount;
40};
41
42
43struct GROUP_LOAD_BOARD_TEST_CASE: public KI_TEST::BOARD_LOAD_TEST_CASE
44{
45 // List of items to check on this board
46 std::vector<GROUP_LOAD_TEST_CASE> m_groupCases;
47};
48
49
50const std::vector<GROUP_LOAD_BOARD_TEST_CASE> GroupsLoadSave_testCases{
51 {
52 "groups_load_save",
53 20231231,
54 {
55 // From top to bottom in the board file
56 {
57 "a78cc65c-451e-451e-9147-4460cc669685",
58 true,
59 "GroupName",
60 2,
61 },
62 },
63 },
64 {
65 // Before 20231231, 'id' was used in group s-exprs
66 // and we need to continue to load it for compatibility
67 "groups_load_save_v20231212",
68 20231212,
69 {
70 // From top to bottom in the board file
71 {
72 "a78cc65c-451e-451e-9147-4460cc669685",
73 true,
74 "GroupName",
75 2,
76 },
77 },
78 },
79};
80
81} // namespace
82
93BOOST_DATA_TEST_CASE( GroupsLoadSave, boost::unit_test::data::make( GroupsLoadSave_testCases ),
94 testCase )
95{
96 const auto doBoardTest = [&]( const BOARD& aBoard )
97 {
98 for( const GROUP_LOAD_TEST_CASE& groupTestCase : testCase.m_groupCases )
99 {
100 BOOST_TEST_MESSAGE( "Checking for group with UUID: "
101 << groupTestCase.m_searchUuid.AsString()
102 << " and name: " << groupTestCase.m_expectedName );
103
104 const auto& group = static_cast<PCB_GROUP&>( KI_TEST::RequireBoardItemWithTypeAndId(
105 aBoard, PCB_GROUP_T, groupTestCase.m_searchUuid ) );
106
107 BOOST_CHECK_EQUAL( group.IsLocked(), groupTestCase.m_expectedLocked );
108 BOOST_CHECK_EQUAL( group.GetName(), groupTestCase.m_expectedName );
109 BOOST_CHECK_EQUAL( group.GetItems().size(), groupTestCase.m_expectedMemberCount );
110 }
111 };
112
113 KI_TEST::LoadAndTestBoardFile( testCase.m_BoardFileRelativePath, true, doBoardTest,
114 testCase.m_ExpectedBoardVersion );
115}
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
wxString AsString() const
Definition kiid.cpp:242
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:49
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_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("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:104