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
28
29
30
32
33
35{
36 std::string m_case_name;
37 std::string m_file_rel_path;
39};
40
41
42// clang-format off
43static const std::vector<PCB_IO_PLUGIN_CASE> BoardPluginCases = {
44
45 //
46 // FAKE Boards (should return FILE_TYPE_NONE):
47 //
48 {
49 "Fake Board file (KiCad *Legacy* / EAGLE file ext)",
50 "plugins/fakeboard.brd",
52 },
53 {
54 "Fake Board file (KiCad file ext)",
55 "plugins/fakeboard.kicad_pcb",
57 },
58 {
59 "Fake Board file (PCAD file ext)",
60 "plugins/fakeboard.pcb",
62 },
63 {
64 "Fake Board file (CADSTAR file ext)",
65 "plugins/fakeboard.cpa",
67 },
68 {
69 "Fake Board file (Altium Circuit Studio file ext)",
70 "plugins/fakeboard.CSPcbDoc",
72 },
73 {
74 "Fake Board file (Altium Circuit Maker file ext)",
75 "plugins/fakeboard.CMPcbDoc",
77 },
78 {
79 "Fake Board file (Altium Designer file ext)",
80 "plugins/fakeboard.PcbDoc",
82 },
83
84 {
85 "Fake Board file (Solid Works PCB file ext)",
86 "plugins/fakeboard.SWPcbDoc",
88 },
89
90 //
91 // REAL Boards:
92 //
93
94 {
95 "Basic KiCad *Legacy* board file",
96 "plugins/legacy_demos/flat_hierarchy/flat_hierarchy.brd",
98 },
99 {
100 "Basic KiCad board file",
101 "complex_hierarchy.kicad_pcb",
103 },
104 {
105 "Basic Eagle board file",
106 "plugins/eagle/Adafruit-AHT20-PCB/Adafruit AHT20 Temperature & Humidity.brd",
108 },
109 {
110 "Basic PCAD board file",
111 "plugins/pcad/pcad_4layer_glyph_test_ascii.PCB",
113 },
114 {
115 "Basic CADSTAR board file",
116 "plugins/cadstar/route_offset/minimal_route_offset_curved_track.cpa",
118 },
119 {
120 "Basic EasyEDA Std board json file",
121 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
123 },
124 {
125 "Basic EasyEDA Std backup file",
126 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
128 },
129 {
130 "Basic EasyEDA Pro zip board project",
131 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
133 },
134 {
135 "Basic EasyEDA Pro epro project",
136 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
138 },
139 {
140 "Basic Altium Designer board file",
141 "plugins/altium/eDP_adapter_dvt1_source/eDP_adapter_dvt1.PcbDoc",
143 }
144 // Todo: Add Altium derivatives and Fabmaster tests
145};
146
147
148static const std::vector<PCB_IO_PLUGIN_CASE> LibraryPluginCases = {
149
150 //
151 // NOT libraries (should return FILE_TYPE_NONE):
152 //
153 {
154 "Non-Library file (KiCad *Legacy* / EAGLE file ext)",
155 "plugins/fakeboard.brd",
157 },
158 {
159 "Non-Library file (KiCad file ext)",
160 "plugins/fakeboard.kicad_pcb",
162 },
163 {
164 "Non-Library file (PCAD file ext)",
165 "plugins/fakeboard.pcb",
167 },
168 {
169 "Non-Library file (CADSTAR file ext)",
170 "plugins/fakeboard.cpa",
172 },
173 {
174 "Non-Library file (Altium Circuit Studio file ext)",
175 "plugins/fakeboard.CSPcbDoc",
177 },
178 {
179 "Non-Library file (Altium Circuit Maker file ext)",
180 "plugins/fakeboard.CMPcbDoc",
182 },
183 {
184 "Non-Library file (Altium Designer file ext)",
185 "plugins/fakeboard.PcbDoc",
187 },
188
189 {
190 "Non-Library file (Solid Works PCB file ext)",
191 "plugins/fakeboard.SWPcbDoc",
193 },
194
195 //
196 // REAL Libraries:
197 //
198
199 {
200 "Basic KiCad footprint .pretty library",
201 "plugins/eagle/lbr/SparkFun-GPS.pretty",
203 },
204 {
205 "Basic Eagle library file",
206 "plugins/eagle/lbr/SparkFun-GPS.lbr",
208 },
209 {
210 "Basic CADSTAR PCB Archive library file",
211 "plugins/cadstar/lib/footprint-with-thermal-pad.cpa",
213 },
214 {
215 "Basic EasyEDA Std board json file",
216 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
218 },
219 {
220 "Basic EasyEDA Std backup file",
221 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
223 },
224 {
225 "Basic EasyEDA Pro zip board project",
226 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
228 },
229 {
230 "Basic EasyEDA Pro epro project",
231 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
233 },
234 {
235 "Altium Designer 'Espressif ESP32-WROOM-32.PcbLib' library file",
236 "plugins/altium/pcblib/Espressif ESP32-WROOM-32.PcbLib",
238 },
239 {
240 "Altium Designer 'Tracks.v6.PcbLib' library file",
241 "plugins/altium/pcblib/Tracks.v6.PcbLib",
243 }
244 // Todo: Add Altium derivatives and Fabmaster tests
245};
246// clang-format on
247
248
249BOOST_AUTO_TEST_CASE( FindBoardPluginType )
250{
251 for( auto& c : BoardPluginCases )
252 {
253 BOOST_TEST_CONTEXT( c.m_case_name )
254 {
255 wxString dataPath =
256 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
257
258 BOOST_CHECK_EQUAL( PCB_IO_MGR::FindPluginTypeFromBoardPath( dataPath ),
259 c.m_expected_type );
260
261 // Todo add tests to check if it still works with upper/lower case ext.
262 // ( FindPluginTypeFromBoardPath should be case insensitive)
263 }
264 }
265}
266
267
268BOOST_AUTO_TEST_CASE( GuessLibraryPluginType )
269{
270 for( auto& c : LibraryPluginCases )
271 {
272 BOOST_TEST_CONTEXT( c.m_case_name )
273 {
274 wxString dataPath =
275 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
276
277 BOOST_CHECK_EQUAL( PCB_IO_MGR::GuessPluginTypeFromLibPath( dataPath ), c.m_expected_type );
278
279 // Todo add tests to check if it still works with upper/lower case ext.
280 // ( GuessPluginTypeFromLibPath should be case insensitive)
281 }
282 }
283}
284
285
286BOOST_AUTO_TEST_CASE( CheckCanReadBoard )
287{
288 for( auto& c : BoardPluginCases )
289 {
290 BOOST_TEST_CONTEXT( c.m_case_name )
291 {
292 wxString dataPath =
293 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
294
295 auto& pluginEntries = PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins();
296
297 for( auto& entry : pluginEntries )
298 {
299 BOOST_TEST_CONTEXT( entry.m_name )
300 {
301 auto plugin = IO_RELEASER<PCB_IO>( PCB_IO_MGR::PluginFind( entry.m_type ) );
302 bool expectValidHeader = c.m_expected_type == entry.m_type;
303
304 BOOST_CHECK_EQUAL( plugin->CanReadBoard( dataPath ), expectValidHeader );
305 }
306 }
307 }
308 }
309}
310
311BOOST_AUTO_TEST_SUITE_END()
General utilities for PCB file IO for QA programs.
const std::vector< ENTRY > & AllPlugins() const
Definition: pcb_io_mgr.h:127
static PLUGIN_REGISTRY * Instance()
Definition: pcb_io_mgr.h:93
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:65
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:76
@ 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:108
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:132
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
std::string m_case_name
Definition: test_io_mgr.cpp:36
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static const std::vector< PCB_IO_PLUGIN_CASE > BoardPluginCases
Definition: test_io_mgr.cpp:43
BOOST_AUTO_TEST_CASE(FindBoardPluginType)
static const std::vector< PCB_IO_PLUGIN_CASE > LibraryPluginCases
#define BOOST_TEST_CONTEXT(A)