KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_graphics_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_shape.h>
31
32namespace
33{
34
35struct GRAPHICS_LOAD_TEST_CASE
36{
37 // Which one to look at in the file?
38 KIID m_searchUuid;
39 // Expected values
40 bool m_expectedFilled;
41};
42
43
44struct GRAPHICS_LOAD_BOARD_TEST_CASE
45{
46 // The board to load
47 wxString m_boardFileRelativePath;
48
49 // These tests may well test specific versions of the board file format,
50 // so don't let it change accidentally!
51 int m_expectedBoardVersion;
52
53 // List of images to check
54 std::vector<GRAPHICS_LOAD_TEST_CASE> m_generatorCases;
55};
56
57} // namespace
58
59BOOST_AUTO_TEST_CASE( GraphicsLoad )
60{
61 const std::vector<GRAPHICS_LOAD_BOARD_TEST_CASE> testCases{
62 {
63 // Before 20241129, 'fill' would be solid or none
64 // in PCB shapes
65 "graphics_load_save_v20240108",
66 20240108,
67 {
68 // Filled poly
69 {
70 "65596b4f-7b03-48e9-8be7-5824316ea7fd",
71 true,
72 },
73 // Unfilled poly
74 {
75 "cf265305-49c9-43d8-bb2a-ad34997b22d6",
76 false,
77 },
78 // Filled rect
79 {
80 "d0669ae2-442f-427f-af0f-bc3008af779a",
81 true,
82 },
83 // Unfilled rect
84 {
85 "fd1649a3-9a92-4dd3-96b4-88469cb257ba",
86 false,
87 },
88 },
89 },
90 };
91
92 for( const GRAPHICS_LOAD_BOARD_TEST_CASE& testCase : testCases )
93 {
94 const auto doBoardTest = [&]( const BOARD& aBoard )
95 {
96 for( const GRAPHICS_LOAD_TEST_CASE& testCase : testCase.m_generatorCases )
97 {
98 BOOST_TEST_MESSAGE(
99 "Checking for graphic with UUID: " << testCase.m_searchUuid.AsString() );
100
101 const auto& graphic =
103 aBoard, PCB_SHAPE_T, testCase.m_searchUuid ) );
104
105 BOOST_CHECK_EQUAL( graphic.IsFilled(), testCase.m_expectedFilled );
106 }
107 };
108
109 KI_TEST::LoadAndTestBoardFile( testCase.m_boardFileRelativePath, true, doBoardTest,
110 testCase.m_expectedBoardVersion );
111 }
112}
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
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.
BOOST_AUTO_TEST_CASE(GraphicsLoad)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88