KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew/pcb_io/easyedapro/test_easyedapro_v3_import.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
28
29#include <qa_utils/file_utils.h>
33
36
37#include <board.h>
38#include <footprint.h>
39
40#include <wx/dir.h>
41#include <wx/filefn.h>
42#include <wx/filename.h>
43
44#include <algorithm>
45#include <memory>
46#include <vector>
47
48
49BOOST_AUTO_TEST_SUITE( EasyedaproV3Import )
50
51
53{
54 return wxString::FromUTF8( KI_TEST::GetTestDataRootDir() + "eeschema/plugins/easyedapro/LS2K0300_Symbol.elibz2" );
55}
56
57
59{
60 return wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir()
61 + "plugins/easyedapro/LS2K0300_Footprint_2025-11-14.elibz2" );
62}
63
64
65static std::vector<wxString> listDirEntries( const wxString& aPath )
66{
67 std::vector<wxString> entries;
68 wxDir dir( aPath );
69 wxString name;
70
71 if( !dir.IsOpened() )
72 return entries;
73
74 for( bool more = dir.GetFirst( &name, wxEmptyString, wxDIR_DIRS | wxDIR_FILES ); more;
75 more = dir.GetNext( &name ) )
76 {
77 entries.push_back( name );
78 }
79
80 std::sort( entries.begin(), entries.end() );
81
82 return entries;
83}
84
85
86BOOST_AUTO_TEST_CASE( FootprintLibraryCanReadOnlyFootprintElibz2 )
87{
89 BOOST_REQUIRE( plugin );
90
91 BOOST_CHECK( plugin->CanReadLibrary( getEasyEdaProV3FootprintLibPath() ) );
92 BOOST_CHECK( !plugin->CanReadLibrary( getEasyEdaProV3SymbolLibPath() ) );
93}
94
95
96BOOST_AUTO_TEST_CASE( FootprintLibraryEnumeratesAndLoadsElibz2 )
97{
99 BOOST_REQUIRE( plugin );
100
101 wxArrayString footprintNames;
102 BOOST_REQUIRE_NO_THROW( plugin->FootprintEnumerate( footprintNames, getEasyEdaProV3FootprintLibPath(), false ) );
103
104 BOOST_REQUIRE_EQUAL( footprintNames.GetCount(), 1 );
105 BOOST_CHECK_EQUAL( footprintNames[0], wxString( wxS( "BGA-286_17x17_12.0x12.0mm" ) ) );
106
107 std::unique_ptr<FOOTPRINT> footprint =
108 plugin->FootprintLoad( getEasyEdaProV3FootprintLibPath(), wxS( "BGA-286_17x17_12.0x12.0mm" ) );
109
110 BOOST_REQUIRE( footprint );
111 BOOST_CHECK_EQUAL( footprint->GetFPID().GetLibItemName(), UTF8( "BGA-286_17x17_12.0x12.0mm" ) );
112 BOOST_CHECK_EQUAL( footprint->Pads().size(), 286 );
113}
114
115
116BOOST_AUTO_TEST_CASE( BoardLoadImportsInnerLayers )
117{
118 // Import from a private copy so a stray write lands here rather than in the shared test data
119 KI_TEST::SCOPED_TEMP_DIR tempDir( "easyedapro_v3_board_load" );
120
121 const wxString archiveName = wxS( "ProProject_LS2K0300Core_2025-11-14.epro2" );
122 wxString sourceDir = wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + "plugins/easyedapro/" );
123 const wxString tempDirPath = tempDir.PathStr();
124
125 wxFileName dataFile( tempDirPath, archiveName );
126 BOOST_REQUIRE( wxCopyFile( sourceDir + archiveName, dataFile.GetFullPath() ) );
127
128 std::map<std::string, UTF8> properties;
129 properties["pcb_id"] = "eb9fbfba682940f7a002816e66fbb3d7";
130
132 BOOST_REQUIRE( plugin );
133
134 std::unique_ptr<BOARD> board = plugin->LoadBoard( dataFile.GetFullPath(), &properties );
135 BOOST_REQUIRE( board );
136
137 // Loading a board is a read, so nothing may appear beside the archive
138 std::vector<wxString> entries = listDirEntries( tempDirPath );
139 BOOST_REQUIRE_EQUAL( entries.size(), 1 );
140 BOOST_CHECK_EQUAL( entries[0], archiveName );
141
142 std::vector<FOOTPRINT*> definitions = plugin->GetImportedCachedLibraryFootprints();
143 BOOST_CHECK( definitions.size() > 0 );
144
145 for( FOOTPRINT* definition : definitions )
146 {
147 BOOST_CHECK( !definition->GetFPID().GetLibItemName().empty() );
148 delete definition;
149 }
150
151 BOOST_CHECK( board->Footprints().size() > 0 );
152 BOOST_CHECK( board->GetNetCount() > 0 );
153
154 // A 4-layer board whose inner and back copper carry their EasyEDA names.
155 BOOST_CHECK_EQUAL( board->GetCopperLayerCount(), 4 );
156 BOOST_CHECK_EQUAL( board->GetLayerName( In1_Cu ), wxString( wxS( "Inner1" ) ) );
157 BOOST_CHECK_EQUAL( board->GetLayerName( In2_Cu ), wxString( wxS( "Inner2" ) ) );
158 BOOST_CHECK_EQUAL( board->GetLayerName( B_Cu ), wxString( wxS( "Bottom Layer" ) ) );
159}
160
161
const char * name
General utilities for PCB file IO for QA programs.
wxString PathStr() const
Get the path to the temporary directory as a wxString.
Definition file_utils.h:62
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition utf8.h:67
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
@ B_Cu
Definition layer_ids.h:61
@ In2_Cu
Definition layer_ids.h:63
@ In1_Cu
Definition layer_ids.h:62
std::string GetTestDataRootDir()
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
static std::vector< wxString > listDirEntries(const wxString &aPath)
static wxString getEasyEdaProV3FootprintLibPath()
BOOST_AUTO_TEST_CASE(FootprintLibraryCanReadOnlyFootprintElibz2)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static wxString getEasyEdaProV3SymbolLibPath()
static wxString getEasyEdaProV3FootprintLibPath()
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")