KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_footprint_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 <footprint.h>
33
34
35namespace
36{
37
38struct FOOTPRINT_LOAD_TEST_CASE
39{
40 // Which footprint to look at in the file
41 KIID m_footprintUuid;
42 // Expected values
43 bool m_expectedLocked;
44 VECTOR2I m_expectedPos;
45};
46
47
48struct FOOTPRINT_LOAD_BOARD_TEST_CASE: public KI_TEST::BOARD_LOAD_TEST_CASE
49{
50 // List of images to check
51 std::vector<FOOTPRINT_LOAD_TEST_CASE> m_fpCases;
52};
53
54
55const std::vector<FOOTPRINT_LOAD_BOARD_TEST_CASE> FootprintLoadSave_testCases{
56 {
57 "footprints_load_save",
58 std::nullopt,
59 {
60 // From top to bottom in the board file
61 {
62 "898cf321-03c7-40bb-8d78-4bc5e52986c2",
63 false,
64 { 100, 80 },
65 },
66 {
67 "0775cd70-2e84-4592-a160-456c37a8f4f6",
68 true,
69 { 100, 100 },
70 },
71 },
72 },
73};
74
75} // namespace
76
82BOOST_DATA_TEST_CASE( FootprintLoadSave,
83 boost::unit_test::data::make( FootprintLoadSave_testCases ), testCase )
84{
85 const auto doBoardTest = [&]( const BOARD& aBoard )
86 {
87 for( const FOOTPRINT_LOAD_TEST_CASE& fooprintTestCase : testCase.m_fpCases )
88 {
89 BOOST_TEST_MESSAGE( "Checking for footprint with UUID: "
90 << fooprintTestCase.m_footprintUuid.AsString() );
91
92 const auto& fp = static_cast<FOOTPRINT&>( KI_TEST::RequireBoardItemWithTypeAndId(
93 aBoard, PCB_FOOTPRINT_T, fooprintTestCase.m_footprintUuid ) );
94
95 BOOST_CHECK_EQUAL( fp.IsLocked(), fooprintTestCase.m_expectedLocked );
96 BOOST_CHECK_EQUAL( fp.GetPosition(), fooprintTestCase.m_expectedPos * 1000000 );
97 }
98 };
99
100 KI_TEST::LoadAndTestBoardFile( testCase.m_BoardFileRelativePath, true, doBoardTest,
101 testCase.m_ExpectedBoardVersion );
102}
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
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_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_DATA_TEST_CASE(FootprintLoadSave, boost::unit_test::data::make(FootprintLoadSave_testCases), testCase)
Simple tests cases that load a board file and check expected properties of the footprints.
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86