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 (C) 2023 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
21
25
26#include <pcbnew/io_mgr.h>
27
28
29
31
32
34{
35 std::string m_case_name;
36 std::string m_file_rel_path;
38};
39
40
41// clang-format off
42static const std::vector<PCB_IO_PLUGIN_CASE> BoardPluginCases = {
43
44 //
45 // FAKE Boards (should return FILE_TYPE_NONE):
46 //
47 {
48 "Fake Board file (KiCad *Legacy* / EAGLE file ext)",
49 "plugins/fakeboard.brd",
51 },
52 {
53 "Fake Board file (KiCad file ext)",
54 "plugins/fakeboard.kicad_pcb",
56 },
57 {
58 "Fake Board file (PCAD file ext)",
59 "plugins/fakeboard.pcb",
61 },
62 {
63 "Fake Board file (CADSTAR file ext)",
64 "plugins/fakeboard.cpa",
66 },
67 {
68 "Fake Board file (Altium Circuit Studio file ext)",
69 "plugins/fakeboard.CSPcbDoc",
71 },
72 {
73 "Fake Board file (Altium Circuit Maker file ext)",
74 "plugins/fakeboard.CMPcbDoc",
76 },
77 {
78 "Fake Board file (Altium Designer file ext)",
79 "plugins/fakeboard.PcbDoc",
81 },
82
83 {
84 "Fake Board file (Solid Works PCB file ext)",
85 "plugins/fakeboard.SWPcbDoc",
87 },
88
89 //
90 // REAL Boards:
91 //
92
93 {
94 "Basic KiCad *Legacy* board file",
95 "plugins/legacy_demos/flat_hierarchy/flat_hierarchy.brd",
97 },
98 {
99 "Basic KiCad board file",
100 "complex_hierarchy.kicad_pcb",
102 },
103 {
104 "Basic Eagle board file",
105 "plugins/eagle/Adafruit-AHT20-PCB/Adafruit AHT20 Temperature & Humidity.brd",
107 },
108 {
109 "Basic PCAD board file",
110 "plugins/pcad/pcad_4layer_glyph_test_ascii.PCB",
112 },
113 {
114 "Basic CADSTAR board file",
115 "plugins/cadstar/route_offset/minimal_route_offset_curved_track.cpa",
117 },
118 {
119 "Basic EasyEDA Std board json file",
120 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
122 },
123 {
124 "Basic EasyEDA Std backup file",
125 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
127 },
128 {
129 "Basic EasyEDA Pro zip board project",
130 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
132 },
133 {
134 "Basic EasyEDA Pro epro project",
135 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
137 },
138 {
139 "Basic Altium Designer board file",
140 "plugins/altium/eDP_adapter_dvt1_source/eDP_adapter_dvt1.PcbDoc",
142 }
143 // Todo: Add Altium derivatives and Fabmaster tests
144};
145
146
147static const std::vector<PCB_IO_PLUGIN_CASE> LibraryPluginCases = {
148
149 //
150 // NOT libraries (should return FILE_TYPE_NONE):
151 //
152 {
153 "Non-Library file (KiCad *Legacy* / EAGLE file ext)",
154 "plugins/fakeboard.brd",
156 },
157 {
158 "Non-Library file (KiCad file ext)",
159 "plugins/fakeboard.kicad_pcb",
161 },
162 {
163 "Non-Library file (PCAD file ext)",
164 "plugins/fakeboard.pcb",
166 },
167 {
168 "Non-Library file (CADSTAR file ext)",
169 "plugins/fakeboard.cpa",
171 },
172 {
173 "Non-Library file (Altium Circuit Studio file ext)",
174 "plugins/fakeboard.CSPcbDoc",
176 },
177 {
178 "Non-Library file (Altium Circuit Maker file ext)",
179 "plugins/fakeboard.CMPcbDoc",
181 },
182 {
183 "Non-Library file (Altium Designer file ext)",
184 "plugins/fakeboard.PcbDoc",
186 },
187
188 {
189 "Non-Library file (Solid Works PCB file ext)",
190 "plugins/fakeboard.SWPcbDoc",
192 },
193
194 //
195 // REAL Libraries:
196 //
197
198 {
199 "Basic KiCad footprint .pretty library",
200 "plugins/eagle/lbr/SparkFun-GPS.pretty",
202 },
203 {
204 "Basic Eagle library file",
205 "plugins/eagle/lbr/SparkFun-GPS.lbr",
207 },
208 {
209 "Basic CADSTAR PCB Archive library file",
210 "plugins/cadstar/lib/footprint-with-thermal-pad.cpa",
212 },
213 {
214 "Basic EasyEDA Std board json file",
215 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
217 },
218 {
219 "Basic EasyEDA Std backup file",
220 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
222 },
223 {
224 "Basic EasyEDA Pro zip board project",
225 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
227 },
228 {
229 "Basic EasyEDA Pro epro project",
230 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
232 },
233 {
234 "Altium Designer 'Espressif ESP32-WROOM-32.PcbLib' library file",
235 "plugins/altium/pcblib/Espressif ESP32-WROOM-32.PcbLib",
237 },
238 {
239 "Altium Designer 'Tracks.v6.PcbLib' library file",
240 "plugins/altium/pcblib/Tracks.v6.PcbLib",
242 }
243 // Todo: Add Altium derivatives and Fabmaster tests
244};
245// clang-format on
246
247
248BOOST_AUTO_TEST_CASE( FindBoardPluginType )
249{
250 for( auto& c : BoardPluginCases )
251 {
252 BOOST_TEST_CONTEXT( c.m_case_name )
253 {
254 wxString dataPath =
255 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
256
257 BOOST_CHECK_EQUAL( IO_MGR::FindPluginTypeFromBoardPath( dataPath ),
258 c.m_expected_type );
259
260 // Todo add tests to check if it still works with upper/lower case ext.
261 // ( FindPluginTypeFromBoardPath should be case insensitive)
262 }
263 }
264}
265
266
267BOOST_AUTO_TEST_CASE( GuessLibraryPluginType )
268{
269 for( auto& c : LibraryPluginCases )
270 {
271 BOOST_TEST_CONTEXT( c.m_case_name )
272 {
273 wxString dataPath =
274 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
275
276 BOOST_CHECK_EQUAL( IO_MGR::GuessPluginTypeFromLibPath( dataPath ), c.m_expected_type );
277
278 // Todo add tests to check if it still works with upper/lower case ext.
279 // ( GuessPluginTypeFromLibPath should be case insensitive)
280 }
281 }
282}
283
284
285BOOST_AUTO_TEST_CASE( CheckCanReadBoard )
286{
287 for( auto& c : BoardPluginCases )
288 {
289 BOOST_TEST_CONTEXT( c.m_case_name )
290 {
291 wxString dataPath =
292 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
293
294 auto& pluginEntries = IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins();
295
296 for( auto& entry : pluginEntries )
297 {
298 BOOST_TEST_CONTEXT( entry.m_name )
299 {
300 auto plugin = PLUGIN::RELEASER( IO_MGR::PluginFind( entry.m_type ) );
301 bool expectValidHeader = c.m_expected_type == entry.m_type;
302
303 BOOST_CHECK_EQUAL( plugin->CanReadBoard( dataPath ), expectValidHeader );
304 }
305 }
306 }
307 }
308}
309
310BOOST_AUTO_TEST_SUITE_END()
General utilities for PCB file IO for QA programs.
const std::vector< ENTRY > & AllPlugins() const
Definition: io_mgr.h:125
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:91
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
Definition: io_mgr.cpp:141
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written,...
Definition: io_mgr.h:54
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:57
@ ALTIUM_DESIGNER
Definition: io_mgr.h:60
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: io_mgr.h:56
@ EASYEDA
Definition: io_mgr.h:63
@ PCAD
Definition: io_mgr.h:67
@ EAGLE
Definition: io_mgr.h:62
@ FILE_TYPE_NONE
Definition: io_mgr.h:74
@ CADSTAR_PCB_ARCHIVE
Definition: io_mgr.h:61
@ EASYEDAPRO
Definition: io_mgr.h:64
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
Definition: io_mgr.cpp:117
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:64
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:614
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:36
IO_MGR::PCB_FILE_T m_expected_type
Definition: test_io_mgr.cpp:37
std::string m_case_name
Definition: test_io_mgr.cpp:35
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static const std::vector< PCB_IO_PLUGIN_CASE > BoardPluginCases
Definition: test_io_mgr.cpp:42
BOOST_AUTO_TEST_CASE(FindBoardPluginType)
static const std::vector< PCB_IO_PLUGIN_CASE > LibraryPluginCases
#define BOOST_TEST_CONTEXT(A)