KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_fp_lib_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 <footprint.h>
29
30namespace
31{
32
33struct FPLIB_LOAD_FP_TEST_CASE
34{
35 // The FP to load
36 wxString m_libraryPath;
37 wxString m_fpName;
38
39 std::optional<unsigned> m_expectedFootprintVersion;
40
41 // If set, the expected number of pads in the footprint
42 std::optional<unsigned> m_expectedPadCount;
43
44 // If set, the expected number of zones in the footprint
45 std::optional<unsigned> m_expectedZoneCount;
46
47 // For printing the test name
48 friend std::ostream& operator<<( std::ostream& os, const FPLIB_LOAD_FP_TEST_CASE& aTestCase )
49 {
50 os << aTestCase.m_fpName;
51 return os;
52 }
53};
54
55
56const std::vector<FPLIB_LOAD_FP_TEST_CASE> FpLibLoadSave_testCases{
57 {
58 "plugins/kicad_sexpr/fp.pretty",
59 "R_0201_0603Metric",
60 20240108U,
61 // 2 SMD pads, 2 paste pads
62 4U,
63 0U,
64 },
65 {
66 "plugins/kicad_sexpr/Issue25447_FpHasZoneWithNetName",
67 "zone_with_netname",
68 20260831U,
69 1U,
70 1U,
71 }
72};
73
74} // namespace
75
83BOOST_DATA_TEST_CASE( FpLibLoadSave, boost::unit_test::data::make( FpLibLoadSave_testCases ),
84 testCase )
85{
86 const auto doFootprintTest = [&]( const FOOTPRINT& aBoard )
87 {
88 if( testCase.m_expectedPadCount )
89 {
90 BOOST_CHECK_EQUAL( aBoard.Pads().size(), *testCase.m_expectedPadCount );
91 }
92 if( testCase.m_expectedZoneCount )
93 {
94 BOOST_CHECK_EQUAL( aBoard.Zones().size(), *testCase.m_expectedZoneCount );
95 }
96 };
97
98 KI_TEST::LoadAndTestFootprintFile( testCase.m_libraryPath, testCase.m_fpName, true,
99 doFootprintTest, testCase.m_expectedFootprintVersion );
100}
General utilities for PCB file IO for QA programs.
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
void LoadAndTestFootprintFile(const wxString &aLibRelativePath, const wxString &aFpName, bool aRoundtrip, std::function< void(FOOTPRINT &)> aFootprintTestFunction, std::optional< int > aExpectedFootprintVersion)
Same as LoadAndTestBoardFile, but for footprints.
BOOST_DATA_TEST_CASE(FpLibLoadSave, boost::unit_test::data::make(FpLibLoadSave_testCases), testCase)
Simple tests cases that run though the given FPs and checks some simple properties.
BOOST_CHECK_EQUAL(result, "25.4")