KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_io_mgr.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 Roberto Fernandez Bautista <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <boost/test/data/test_case.hpp>
23
26
29
30
32
33
35{
36 std::string m_case_name;
37 std::string m_file_rel_path;
39
40 friend std::ostream& operator<<( std::ostream& os, const PCB_IO_PLUGIN_CASE& aCase )
41 {
42 os << aCase.m_case_name;
43 return os;
44 }
45};
46
47
48// clang-format off
49static const std::vector<PCB_IO_PLUGIN_CASE> BoardPluginCases = {
50
51 //
52 // FAKE Boards (should return FILE_TYPE_NONE):
53 //
54 {
55 "Fake Board file (KiCad *Legacy* / EAGLE file ext)",
56 "plugins/fakeboard.brd",
58 },
59 {
60 "Fake Board file (KiCad file ext)",
61 "plugins/fakeboard.kicad_pcb",
63 },
64 {
65 "Fake Board file (PCAD file ext)",
66 "plugins/fakeboard.pcb",
68 },
69 {
70 "Fake Board file (CADSTAR file ext)",
71 "plugins/fakeboard.cpa",
73 },
74 {
75 "Fake Board file (Altium Circuit Studio file ext)",
76 "plugins/fakeboard.CSPcbDoc",
78 },
79 {
80 "Fake Board file (Altium Circuit Maker file ext)",
81 "plugins/fakeboard.CMPcbDoc",
83 },
84 {
85 "Fake Board file (Altium Designer file ext)",
86 "plugins/fakeboard.PcbDoc",
88 },
89
90 {
91 "Fake Board file (Solid Works PCB file ext)",
92 "plugins/fakeboard.SWPcbDoc",
94 },
95
96 //
97 // REAL Boards:
98 //
99
100 {
101 "Basic KiCad *Legacy* board file",
102 "plugins/legacy_demos/flat_hierarchy/flat_hierarchy.brd",
104 },
105 {
106 "Basic KiCad board file",
107 "complex_hierarchy.kicad_pcb",
109 },
110 {
111 "Basic Eagle board file",
112 "plugins/eagle/Adafruit-AHT20-PCB/Adafruit AHT20 Temperature & Humidity.brd",
114 },
115 {
116 "Basic PCAD board file",
117 "plugins/pcad/pcad_4layer_glyph_test_ascii.PCB",
119 },
120 {
121 "Basic CADSTAR board file",
122 "plugins/cadstar/route_offset/minimal_route_offset_curved_track.cpa",
124 },
125 {
126 "Basic EasyEDA Std board json file",
127 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
129 },
130 {
131 "Basic EasyEDA Std backup file",
132 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
134 },
135 {
136 "Basic EasyEDA Pro zip board project",
137 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
139 },
140 {
141 "Basic EasyEDA Pro epro project",
142 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
144 },
145 {
146 "Basic Altium Designer board file",
147 "plugins/altium/eDP_adapter_dvt1_source/eDP_adapter_dvt1.PcbDoc",
149 }
150 // Todo: Add Altium derivatives and Fabmaster tests
151};
152
153
154static const std::vector<PCB_IO_PLUGIN_CASE> LibraryPluginCases = {
155
156 //
157 // NOT libraries (should return FILE_TYPE_NONE):
158 //
159 {
160 "Non-Library file (KiCad *Legacy* / EAGLE file ext)",
161 "plugins/fakeboard.brd",
163 },
164 {
165 "Non-Library file (KiCad file ext)",
166 "plugins/fakeboard.kicad_pcb",
168 },
169 {
170 "Non-Library file (PCAD file ext)",
171 "plugins/fakeboard.pcb",
173 },
174 {
175 "Non-Library file (CADSTAR file ext)",
176 "plugins/fakeboard.cpa",
178 },
179 {
180 "Non-Library file (Altium Circuit Studio file ext)",
181 "plugins/fakeboard.CSPcbDoc",
183 },
184 {
185 "Non-Library file (Altium Circuit Maker file ext)",
186 "plugins/fakeboard.CMPcbDoc",
188 },
189 {
190 "Non-Library file (Altium Designer file ext)",
191 "plugins/fakeboard.PcbDoc",
193 },
194
195 {
196 "Non-Library file (Solid Works PCB file ext)",
197 "plugins/fakeboard.SWPcbDoc",
199 },
200
201 //
202 // REAL Libraries:
203 //
204
205 {
206 "Basic KiCad footprint .pretty library",
207 "plugins/eagle/lbr/SparkFun-GPS.pretty",
209 },
210 {
211 "Basic Eagle library file",
212 "plugins/eagle/lbr/SparkFun-GPS.lbr",
214 },
215 {
216 "Basic CADSTAR PCB Archive library file",
217 "plugins/cadstar/lib/footprint-with-thermal-pad.cpa",
219 },
220 {
221 "Basic EasyEDA Std board json file",
222 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
224 },
225 {
226 "Basic EasyEDA Std backup file",
227 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
229 },
230 {
231 "Basic EasyEDA Pro zip board project",
232 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
234 },
235 {
236 "Basic EasyEDA Pro epro project",
237 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
239 },
240 {
241 "Altium Designer 'Espressif ESP32-WROOM-32.PcbLib' library file",
242 "plugins/altium/pcblib/Espressif ESP32-WROOM-32.PcbLib",
244 },
245 {
246 "Altium Designer 'Tracks.v6.PcbLib' library file",
247 "plugins/altium/pcblib/Tracks.v6.PcbLib",
249 }
250 // Todo: Add Altium derivatives and Fabmaster tests
251};
252// clang-format on
253
254
255BOOST_DATA_TEST_CASE( FindBoardPluginType, boost::unit_test::data::make( BoardPluginCases ), c )
256{
257 wxString dataPath =
258 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
259
261 c.m_expected_type );
262
263 // Todo add tests to check if it still works with upper/lower case ext.
264 // ( FindPluginTypeFromBoardPath should be case insensitive)
265}
266
267
268BOOST_DATA_TEST_CASE( GuessLibraryPluginType, boost::unit_test::data::make( LibraryPluginCases ), c )
269{
270 wxString dataPath =
271 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
272
274
275 // Todo add tests to check if it still works with upper/lower case ext.
276 // ( GuessPluginTypeFromLibPath should be case insensitive)
277}
278
279
280BOOST_DATA_TEST_CASE( CheckCanReadBoard, boost::unit_test::data::make( BoardPluginCases ), c )
281{
282 wxString dataPath =
283 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
284
286
287 for( auto& entry : pluginEntries )
288 {
289 BOOST_TEST_CONTEXT( entry.m_name )
290 {
291 auto plugin = IO_RELEASER<PCB_IO>( PCB_IO_MGR::PluginFind( entry.m_type ) );
292 bool expectValidHeader = c.m_expected_type == entry.m_type;
293
294 BOOST_CHECK_EQUAL( plugin->CanReadBoard( dataPath ), expectValidHeader );
295 }
296 }
297}
298
General utilities for PCB file IO for QA programs.
const std::vector< ENTRY > & AllPlugins() const
Definition: pcb_io_mgr.h:128
static PLUGIN_REGISTRY * Instance()
Definition: pcb_io_mgr.h:94
static PCB_IO * PluginFind(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: pcb_io_mgr.cpp:69
PCB_FILE_T
The set of file types that the PCB_IO_MGR knows about, and for which there has been a plugin written,...
Definition: pcb_io_mgr.h:56
@ FILE_TYPE_NONE
Definition: pcb_io_mgr.h:77
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: pcb_io_mgr.h:58
@ ALTIUM_DESIGNER
Definition: pcb_io_mgr.h:62
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition: pcb_io_mgr.h:59
@ CADSTAR_PCB_ARCHIVE
Definition: pcb_io_mgr.h:63
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
Definition: pcb_io_mgr.cpp:112
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
Definition: pcb_io_mgr.cpp:136
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::string m_file_rel_path
Definition: test_io_mgr.cpp:37
PCB_IO_MGR::PCB_FILE_T m_expected_type
Definition: test_io_mgr.cpp:38
friend std::ostream & operator<<(std::ostream &os, const PCB_IO_PLUGIN_CASE &aCase)
Definition: test_io_mgr.cpp:40
std::string m_case_name
Definition: test_io_mgr.cpp:36
BOOST_DATA_TEST_CASE(ConvertToKicadUnit, boost::unit_test::data::make(altium_to_kicad_unit), input_value, expected_result)
Test conversation from Altium internal units into KiCad internal units.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
static const std::vector< PCB_IO_PLUGIN_CASE > BoardPluginCases
Definition: test_io_mgr.cpp:49
BOOST_CHECK_EQUAL(PCB_IO_MGR::FindPluginTypeFromBoardPath(dataPath), c.m_expected_type)
auto & pluginEntries
static const std::vector< PCB_IO_PLUGIN_CASE > LibraryPluginCases
BOOST_TEST_CONTEXT("Test Clearance")