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 // For printing the test name
45 friend std::ostream& operator<<( std::ostream& os, const FPLIB_LOAD_FP_TEST_CASE& aTestCase )
46 {
47 os << aTestCase.m_fpName;
48 return os;
49 }
50};
51
52
53const std::vector<FPLIB_LOAD_FP_TEST_CASE> FpLibLoadSave_testCases{
54 {
55 "plugins/kicad_sexpr/fp.pretty",
56 "R_0201_0603Metric",
57 20240108U,
58 // 2 SMD pads, 2 paste pads
59 4U,
60 },
61};
62
63} // namespace
64
72BOOST_DATA_TEST_CASE( FpLibLoadSave, boost::unit_test::data::make( FpLibLoadSave_testCases ),
73 testCase )
74{
75 const auto doFootprintTest = [&]( const FOOTPRINT& aBoard )
76 {
77 if( testCase.m_expectedPadCount )
78 {
79 BOOST_CHECK_EQUAL( aBoard.Pads().size(), *testCase.m_expectedPadCount );
80 }
81 };
82
83 KI_TEST::LoadAndTestFootprintFile( testCase.m_libraryPath, testCase.m_fpName, true,
84 doFootprintTest, testCase.m_expectedFootprintVersion );
85}
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")