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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <boost/test/data/test_case.hpp>
23
24#include <cstring>
25
26#include <wx/filename.h>
27#include <wx/wfstream.h>
28
31
35
36
38
39
41{
42 std::string m_case_name;
43 std::string m_file_rel_path;
45
46 friend std::ostream& operator<<( std::ostream& os, const PCB_IO_PLUGIN_CASE& aCase )
47 {
48 os << aCase.m_case_name;
49 return os;
50 }
51};
52
53
54// clang-format off
55static const std::vector<PCB_IO_PLUGIN_CASE> BoardPluginCases = {
56
57 //
58 // FAKE Boards (should return FILE_TYPE_NONE):
59 //
60 {
61 "Fake Board file (KiCad *Legacy* / EAGLE file ext)",
62 "plugins/fakeboard.brd",
64 },
65 {
66 "Fake Board file (KiCad file ext)",
67 "plugins/fakeboard.kicad_pcb",
69 },
70 {
71 "Fake Board file (PCAD file ext)",
72 "plugins/fakeboard.pcb",
74 },
75 {
76 "Fake Board file (CADSTAR file ext)",
77 "plugins/fakeboard.cpa",
79 },
80 {
81 "Fake Board file (Altium Circuit Studio file ext)",
82 "plugins/fakeboard.CSPcbDoc",
84 },
85 {
86 "Fake Board file (Altium Circuit Maker file ext)",
87 "plugins/fakeboard.CMPcbDoc",
89 },
90 {
91 "Fake Board file (Altium Designer file ext)",
92 "plugins/fakeboard.PcbDoc",
94 },
95
96 {
97 "Fake Board file (Solid Works PCB file ext)",
98 "plugins/fakeboard.SWPcbDoc",
100 },
101
102 //
103 // REAL Boards:
104 //
105
106 {
107 "Basic KiCad *Legacy* board file",
108 "plugins/legacy_demos/flat_hierarchy/flat_hierarchy.brd",
110 },
111 {
112 "Basic KiCad board file",
113 "complex_hierarchy.kicad_pcb",
115 },
116 {
117 "Basic Eagle board file",
118 "plugins/eagle/Adafruit-AHT20-PCB/Adafruit AHT20 Temperature & Humidity.brd",
120 },
121 {
122 "Basic PCAD board file",
123 "plugins/pcad/pcad_4layer_glyph_test_ascii.PCB",
125 },
126 {
127 "Basic CADSTAR board file",
128 "plugins/cadstar/route_offset/minimal_route_offset_curved_track.cpa",
130 },
131 {
132 "Basic EasyEDA Std board json file",
133 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
135 },
136 {
137 "Basic EasyEDA Std backup file",
138 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
140 },
141 {
142 "Basic EasyEDA Pro zip board project",
143 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
145 },
146 {
147 "Basic EasyEDA Pro epro project",
148 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
150 },
151 {
152 "Basic Altium Designer board file",
153 "plugins/altium/eDP_adapter_dvt1_source/eDP_adapter_dvt1.PcbDoc",
155 }
156 // Todo: Add Altium derivatives and Fabmaster tests
157};
158
159
160static const std::vector<PCB_IO_PLUGIN_CASE> LibraryPluginCases = {
161
162 //
163 // NOT libraries (should return FILE_TYPE_NONE):
164 //
165 {
166 "Non-Library file (KiCad *Legacy* / EAGLE file ext)",
167 "plugins/fakeboard.brd",
169 },
170 {
171 "Non-Library file (KiCad file ext)",
172 "plugins/fakeboard.kicad_pcb",
174 },
175 {
176 "Non-Library file (PCAD file ext)",
177 "plugins/fakeboard.pcb",
179 },
180 {
181 "Non-Library file (CADSTAR file ext)",
182 "plugins/fakeboard.cpa",
184 },
185 {
186 "Non-Library file (Altium Circuit Studio file ext)",
187 "plugins/fakeboard.CSPcbDoc",
189 },
190 {
191 "Non-Library file (Altium Circuit Maker file ext)",
192 "plugins/fakeboard.CMPcbDoc",
194 },
195 {
196 "Non-Library file (Altium Designer file ext)",
197 "plugins/fakeboard.PcbDoc",
199 },
200
201 {
202 "Non-Library file (Solid Works PCB file ext)",
203 "plugins/fakeboard.SWPcbDoc",
205 },
206
207 //
208 // REAL Libraries:
209 //
210
211 {
212 "Basic KiCad footprint .pretty library",
213 "plugins/eagle/lbr/SparkFun-GPS.pretty",
215 },
216 {
217 "Basic Eagle library file",
218 "plugins/eagle/lbr/SparkFun-GPS.lbr",
220 },
221 {
222 "Basic CADSTAR PCB Archive library file",
223 "plugins/cadstar/lib/footprint-with-thermal-pad.cpa",
225 },
226 {
227 "Basic EasyEDA Std board json file",
228 "plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
230 },
231 {
232 "Basic EasyEDA Std backup file",
233 "plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
235 },
236 {
237 "Basic EasyEDA Pro zip board project",
238 "plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
240 },
241 {
242 "Basic EasyEDA Pro epro project",
243 "plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
245 },
246 {
247 "Altium Designer 'Espressif ESP32-WROOM-32.PcbLib' library file",
248 "plugins/altium/pcblib/Espressif ESP32-WROOM-32.PcbLib",
250 },
251 {
252 "Altium Designer 'Tracks.v6.PcbLib' library file",
253 "plugins/altium/pcblib/Tracks.v6.PcbLib",
255 }
256 // Todo: Add Altium derivatives and Fabmaster tests
257};
258// clang-format on
259
260
261BOOST_DATA_TEST_CASE( FindBoardPluginType, boost::unit_test::data::make( BoardPluginCases ), c )
262{
263 wxString dataPath =
264 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
265
267 c.m_expected_type );
268
269 // Todo add tests to check if it still works with upper/lower case ext.
270 // ( FindPluginTypeFromBoardPath should be case insensitive)
271}
272
273
274BOOST_DATA_TEST_CASE( GuessLibraryPluginType, boost::unit_test::data::make( LibraryPluginCases ), c )
275{
276 wxString dataPath =
277 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
278
280
281 // Todo add tests to check if it still works with upper/lower case ext.
282 // ( GuessPluginTypeFromLibPath should be case insensitive)
283}
284
285
286BOOST_DATA_TEST_CASE( CheckCanReadBoard, boost::unit_test::data::make( BoardPluginCases ), c )
287{
288 wxString dataPath =
289 wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
290
292
293 for( auto& entry : pluginEntries )
294 {
295 BOOST_TEST_CONTEXT( entry.m_name )
296 {
297 auto plugin = IO_RELEASER<PCB_IO>( PCB_IO_MGR::FindPlugin( entry.m_type ) );
298 bool expectValidHeader = c.m_expected_type == entry.m_type;
299
300 BOOST_CHECK_EQUAL( plugin->CanReadBoard( dataPath ), expectValidHeader );
301 }
302 }
303}
304
306
307
308
312BOOST_AUTO_TEST_SUITE( Issue23291NestedTableMigrate )
313
314
315BOOST_AUTO_TEST_CASE( NestedTableRejectedByConvertLibrary )
316{
317 wxFileName table( wxFileName::CreateTempFileName( "kicad_qa_issue23291_" ) );
318
319 {
320 wxFFileOutputStream out( table.GetFullPath() );
321 BOOST_REQUIRE( out.IsOk() );
322 const char* contents =
323 "(fp_lib_table\n"
324 " (version 7)\n"
325 " (lib (name \"Battery\") (type \"KiCad\")"
326 " (uri \"${KICAD9_FOOTPRINT_DIR}/Battery.pretty\") (options \"\") (descr \"\"))\n"
327 ")\n";
328 out.WriteAll( contents, std::strlen( contents ) );
329 }
330
331 BOOST_REQUIRE_EQUAL( PCB_IO_MGR::GuessPluginTypeFromLibPath( table.GetFullPath() ),
333
334 // Migration appends the destination name as a .pretty directory; mirror that to confirm
335 // nothing is written for a nested table.
336 wxFileName outLib( table );
338
339 std::map<std::string, UTF8> props;
340
341 BOOST_CHECK( !PCB_IO_MGR::ConvertLibrary( props, table.GetFullPath(), outLib.GetFullPath(),
342 nullptr ) );
343
344 // DirExists() on a full path tests the directory portion.
345 BOOST_CHECK( !wxFileName::DirExists( outLib.GetFullPath() ) );
346
347 wxRemoveFile( table.GetFullPath() );
348}
349
350
General utilities for PCB file IO for QA programs.
const std::vector< ENTRY > & AllPlugins() const
Definition pcb_io_mgr.h:130
static PLUGIN_REGISTRY * Instance()
Definition pcb_io_mgr.h:96
static bool ConvertLibrary(const std::map< std::string, UTF8 > &aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilePath, REPORTER *aReporter)
Convert a schematic symbol library to the latest KiCad format.
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:52
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
@ ALTIUM_DESIGNER
Definition pcb_io_mgr.h:59
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition pcb_io_mgr.h:55
@ CADSTAR_PCB_ARCHIVE
Definition pcb_io_mgr.h:60
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
static const std::string KiCadFootprintLibPathExtension
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
PCB_IO_MGR::PCB_FILE_T m_expected_type
friend std::ostream & operator<<(std::ostream &os, const PCB_IO_PLUGIN_CASE &aCase)
std::string m_case_name
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_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
static const std::vector< PCB_IO_PLUGIN_CASE > BoardPluginCases
BOOST_CHECK_EQUAL(PCB_IO_MGR::FindPluginTypeFromBoardPath(dataPath), c.m_expected_type)
auto & pluginEntries
static const std::vector< PCB_IO_PLUGIN_CASE > LibraryPluginCases
std::vector< std::vector< std::string > > table
BOOST_TEST_CONTEXT("Test Clearance")
Definition of file extensions used in Kicad.