2023-09-07 09:56:53 +00:00
|
|
|
/*
|
2023-08-12 14:37:02 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <pcbnew_utils/board_test_utils.h>
|
|
|
|
#include <pcbnew_utils/board_file_utils.h>
|
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <pcbnew/pcb_io/pcb_io.h>
|
|
|
|
#include <pcbnew/pcb_io/pcb_io_mgr.h>
|
2023-08-12 14:37:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE( IOMGR )
|
|
|
|
|
|
|
|
|
2023-08-31 00:15:09 +00:00
|
|
|
struct PCB_IO_PLUGIN_CASE
|
2023-08-12 14:37:02 +00:00
|
|
|
{
|
2023-12-19 17:39:26 +00:00
|
|
|
std::string m_case_name;
|
|
|
|
std::string m_file_rel_path;
|
|
|
|
PCB_IO_MGR::PCB_FILE_T m_expected_type;
|
2023-08-12 14:37:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-31 00:15:09 +00:00
|
|
|
// clang-format off
|
|
|
|
static const std::vector<PCB_IO_PLUGIN_CASE> BoardPluginCases = {
|
2023-08-12 14:37:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// FAKE Boards (should return FILE_TYPE_NONE):
|
|
|
|
//
|
|
|
|
{
|
|
|
|
"Fake Board file (KiCad *Legacy* / EAGLE file ext)",
|
|
|
|
"plugins/fakeboard.brd",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Fake Board file (KiCad file ext)",
|
|
|
|
"plugins/fakeboard.kicad_pcb",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Fake Board file (PCAD file ext)",
|
|
|
|
"plugins/fakeboard.pcb",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Fake Board file (CADSTAR file ext)",
|
|
|
|
"plugins/fakeboard.cpa",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
2023-08-18 12:46:59 +00:00
|
|
|
{
|
|
|
|
"Fake Board file (Altium Circuit Studio file ext)",
|
|
|
|
"plugins/fakeboard.CSPcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-18 12:46:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Fake Board file (Altium Circuit Maker file ext)",
|
|
|
|
"plugins/fakeboard.CMPcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-18 12:46:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Fake Board file (Altium Designer file ext)",
|
|
|
|
"plugins/fakeboard.PcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-18 12:46:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"Fake Board file (Solid Works PCB file ext)",
|
|
|
|
"plugins/fakeboard.SWPcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-18 12:46:59 +00:00
|
|
|
},
|
2023-08-12 14:37:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// REAL Boards:
|
|
|
|
//
|
|
|
|
|
|
|
|
{
|
|
|
|
"Basic KiCad *Legacy* board file",
|
|
|
|
"plugins/legacy_demos/flat_hierarchy/flat_hierarchy.brd",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::LEGACY
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic KiCad board file",
|
|
|
|
"complex_hierarchy.kicad_pcb",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::KICAD_SEXP
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic Eagle board file",
|
|
|
|
"plugins/eagle/Adafruit-AHT20-PCB/Adafruit AHT20 Temperature & Humidity.brd",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EAGLE
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic PCAD board file",
|
|
|
|
"plugins/pcad/pcad_4layer_glyph_test_ascii.PCB",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::PCAD
|
2023-08-12 14:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic CADSTAR board file",
|
|
|
|
"plugins/cadstar/route_offset/minimal_route_offset_curved_track.cpa",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::CADSTAR_PCB_ARCHIVE
|
2023-08-18 12:46:59 +00:00
|
|
|
},
|
2023-09-07 00:49:15 +00:00
|
|
|
{
|
|
|
|
"Basic EasyEDA Std board json file",
|
|
|
|
"plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDA
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic EasyEDA Std backup file",
|
|
|
|
"plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDA
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic EasyEDA Pro zip board project",
|
|
|
|
"plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDAPRO
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic EasyEDA Pro epro project",
|
|
|
|
"plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDAPRO
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
2023-08-18 12:46:59 +00:00
|
|
|
{
|
|
|
|
"Basic Altium Designer board file",
|
|
|
|
"plugins/altium/eDP_adapter_dvt1_source/eDP_adapter_dvt1.PcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::ALTIUM_DESIGNER
|
2023-08-12 14:37:02 +00:00
|
|
|
}
|
2023-08-18 12:46:59 +00:00
|
|
|
// Todo: Add Altium derivatives and Fabmaster tests
|
2023-08-12 14:37:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-31 00:15:09 +00:00
|
|
|
static const std::vector<PCB_IO_PLUGIN_CASE> LibraryPluginCases = {
|
|
|
|
|
|
|
|
//
|
|
|
|
// NOT libraries (should return FILE_TYPE_NONE):
|
|
|
|
//
|
|
|
|
{
|
|
|
|
"Non-Library file (KiCad *Legacy* / EAGLE file ext)",
|
|
|
|
"plugins/fakeboard.brd",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Non-Library file (KiCad file ext)",
|
|
|
|
"plugins/fakeboard.kicad_pcb",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Non-Library file (PCAD file ext)",
|
|
|
|
"plugins/fakeboard.pcb",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Non-Library file (CADSTAR file ext)",
|
|
|
|
"plugins/fakeboard.cpa",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Non-Library file (Altium Circuit Studio file ext)",
|
|
|
|
"plugins/fakeboard.CSPcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Non-Library file (Altium Circuit Maker file ext)",
|
|
|
|
"plugins/fakeboard.CMPcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Non-Library file (Altium Designer file ext)",
|
|
|
|
"plugins/fakeboard.PcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"Non-Library file (Solid Works PCB file ext)",
|
|
|
|
"plugins/fakeboard.SWPcbDoc",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::FILE_TYPE_NONE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// REAL Libraries:
|
|
|
|
//
|
|
|
|
|
|
|
|
{
|
|
|
|
"Basic KiCad footprint .pretty library",
|
|
|
|
"plugins/eagle/lbr/SparkFun-GPS.pretty",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::KICAD_SEXP
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic Eagle library file",
|
|
|
|
"plugins/eagle/lbr/SparkFun-GPS.lbr",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EAGLE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic CADSTAR PCB Archive library file",
|
|
|
|
"plugins/cadstar/lib/footprint-with-thermal-pad.cpa",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::CADSTAR_PCB_ARCHIVE
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
2023-09-07 00:49:15 +00:00
|
|
|
{
|
|
|
|
"Basic EasyEDA Std board json file",
|
|
|
|
"plugins/easyeda/PCB_USBMETER-PD QC修改版_2023-09-02.json",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDA
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic EasyEDA Std backup file",
|
|
|
|
"plugins/easyeda/BackupProjects_ESP32-PICO-D4_smart_watch.zip",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDA
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic EasyEDA Pro zip board project",
|
|
|
|
"plugins/easyedapro/Scanning Tunneling Microscope OpenSTM ControlBoard.zip",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDAPRO
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Basic EasyEDA Pro epro project",
|
|
|
|
"plugins/easyedapro/ProProject_Yuzuki Chameleon_2023-09-02.epro",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::EASYEDAPRO
|
2023-09-07 00:49:15 +00:00
|
|
|
},
|
2023-08-31 00:15:09 +00:00
|
|
|
{
|
|
|
|
"Altium Designer 'Espressif ESP32-WROOM-32.PcbLib' library file",
|
|
|
|
"plugins/altium/pcblib/Espressif ESP32-WROOM-32.PcbLib",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::ALTIUM_DESIGNER
|
2023-08-31 00:15:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Altium Designer 'Tracks.v6.PcbLib' library file",
|
|
|
|
"plugins/altium/pcblib/Tracks.v6.PcbLib",
|
2023-12-19 17:39:26 +00:00
|
|
|
PCB_IO_MGR::ALTIUM_DESIGNER
|
2023-08-31 00:15:09 +00:00
|
|
|
}
|
|
|
|
// Todo: Add Altium derivatives and Fabmaster tests
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
2023-08-12 14:37:02 +00:00
|
|
|
BOOST_AUTO_TEST_CASE( FindBoardPluginType )
|
|
|
|
{
|
|
|
|
for( auto& c : BoardPluginCases )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( c.m_case_name )
|
|
|
|
{
|
2023-09-07 09:56:53 +00:00
|
|
|
wxString dataPath =
|
|
|
|
wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
|
2023-08-12 14:37:02 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
BOOST_CHECK_EQUAL( PCB_IO_MGR::FindPluginTypeFromBoardPath( dataPath ),
|
2023-08-12 14:37:02 +00:00
|
|
|
c.m_expected_type );
|
|
|
|
|
|
|
|
// Todo add tests to check if it still works with upper/lower case ext.
|
|
|
|
// ( FindPluginTypeFromBoardPath should be case insensitive)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-31 00:15:09 +00:00
|
|
|
BOOST_AUTO_TEST_CASE( GuessLibraryPluginType )
|
|
|
|
{
|
|
|
|
for( auto& c : LibraryPluginCases )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( c.m_case_name )
|
|
|
|
{
|
2023-09-07 09:56:53 +00:00
|
|
|
wxString dataPath =
|
|
|
|
wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
|
2023-08-31 00:15:09 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
BOOST_CHECK_EQUAL( PCB_IO_MGR::GuessPluginTypeFromLibPath( dataPath ), c.m_expected_type );
|
2023-08-31 00:15:09 +00:00
|
|
|
|
|
|
|
// Todo add tests to check if it still works with upper/lower case ext.
|
|
|
|
// ( GuessPluginTypeFromLibPath should be case insensitive)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-12 14:37:02 +00:00
|
|
|
BOOST_AUTO_TEST_CASE( CheckCanReadBoard )
|
|
|
|
{
|
|
|
|
for( auto& c : BoardPluginCases )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( c.m_case_name )
|
|
|
|
{
|
2023-09-07 09:56:53 +00:00
|
|
|
wxString dataPath =
|
|
|
|
wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + c.m_file_rel_path );
|
2023-08-12 14:37:02 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
auto& pluginEntries = PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins();
|
2023-08-12 14:37:02 +00:00
|
|
|
|
|
|
|
for( auto& entry : pluginEntries )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( entry.m_name )
|
|
|
|
{
|
2023-12-27 20:39:29 +00:00
|
|
|
auto plugin = IO_RELEASER<PCB_IO>( PCB_IO_MGR::PluginFind( entry.m_type ) );
|
2023-08-12 14:37:02 +00:00
|
|
|
bool expectValidHeader = c.m_expected_type == entry.m_type;
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( plugin->CanReadBoard( dataPath ), expectValidHeader );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|