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
32
35
36#include <board.h>
37#include <footprint.h>
38
39#include <wx/dir.h>
40#include <wx/filefn.h>
41#include <wx/filename.h>
42
43#include <algorithm>
44#include <memory>
45#include <vector>
46
47
48BOOST_AUTO_TEST_SUITE( EasyedaproV3Import )
49
50
52{
53 return wxString::FromUTF8( KI_TEST::GetTestDataRootDir() + "eeschema/plugins/easyedapro/LS2K0300_Symbol.elibz2" );
54}
55
56
58{
59 return wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir()
60 + "plugins/easyedapro/LS2K0300_Footprint_2025-11-14.elibz2" );
61}
62
63
64static std::vector<wxString> listDirEntries( const wxString& aPath )
65{
66 std::vector<wxString> entries;
67 wxDir dir( aPath );
68 wxString name;
69
70 if( !dir.IsOpened() )
71 return entries;
72
73 for( bool more = dir.GetFirst( &name, wxEmptyString, wxDIR_DIRS | wxDIR_FILES ); more;
74 more = dir.GetNext( &name ) )
75 {
76 entries.push_back( name );
77 }
78
79 std::sort( entries.begin(), entries.end() );
80
81 return entries;
82}
83
84
85BOOST_AUTO_TEST_CASE( FootprintLibraryCanReadOnlyFootprintElibz2 )
86{
88 BOOST_REQUIRE( plugin );
89
90 BOOST_CHECK( plugin->CanReadLibrary( getEasyEdaProV3FootprintLibPath() ) );
91 BOOST_CHECK( !plugin->CanReadLibrary( getEasyEdaProV3SymbolLibPath() ) );
92}
93
94
95BOOST_AUTO_TEST_CASE( FootprintLibraryEnumeratesAndLoadsElibz2 )
96{
98 BOOST_REQUIRE( plugin );
99
100 wxArrayString footprintNames;
101 BOOST_REQUIRE_NO_THROW( plugin->FootprintEnumerate( footprintNames, getEasyEdaProV3FootprintLibPath(), false ) );
102
103 BOOST_REQUIRE_EQUAL( footprintNames.GetCount(), 1 );
104 BOOST_CHECK_EQUAL( footprintNames[0], wxString( wxS( "BGA-286_17x17_12.0x12.0mm" ) ) );
105
106 std::unique_ptr<FOOTPRINT> footprint(
107 plugin->FootprintLoad( getEasyEdaProV3FootprintLibPath(), wxS( "BGA-286_17x17_12.0x12.0mm" ) ) );
108
109 BOOST_REQUIRE( footprint );
110 BOOST_CHECK_EQUAL( footprint->GetFPID().GetLibItemName(), UTF8( "BGA-286_17x17_12.0x12.0mm" ) );
111 BOOST_CHECK_EQUAL( footprint->Pads().size(), 286 );
112}
113
114
115BOOST_AUTO_TEST_CASE( BoardLoadImportsInnerLayers )
116{
117 // Import from a private copy so a stray write lands here rather than in the shared test data
118 KI_TEST::TEMPORARY_DIRECTORY tempDir( "easyedapro_v3_board_load", "" );
119
120 const wxString archiveName = wxS( "ProProject_LS2K0300Core_2025-11-14.epro2" );
121 wxString sourceDir = wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() + "plugins/easyedapro/" );
122 wxString tempDirPath = wxString::FromUTF8( tempDir.GetPath().string() );
123
124 wxFileName dataFile( tempDirPath, archiveName );
125 BOOST_REQUIRE( wxCopyFile( sourceDir + archiveName, dataFile.GetFullPath() ) );
126
127 std::map<std::string, UTF8> properties;
128 properties["pcb_id"] = "eb9fbfba682940f7a002816e66fbb3d7";
129
131 BOOST_REQUIRE( plugin );
132
133 std::unique_ptr<BOARD> board( plugin->LoadBoard( dataFile.GetFullPath(), nullptr, &properties ) );
134 BOOST_REQUIRE( board );
135
136 // Loading a board is a read, so nothing may appear beside the archive
137 std::vector<wxString> entries = listDirEntries( tempDirPath );
138 BOOST_REQUIRE_EQUAL( entries.size(), 1 );
139 BOOST_CHECK_EQUAL( entries[0], archiveName );
140
141 std::vector<FOOTPRINT*> definitions = plugin->GetImportedCachedLibraryFootprints();
142 BOOST_CHECK( definitions.size() > 0 );
143
144 for( FOOTPRINT* definition : definitions )
145 {
146 BOOST_CHECK( !definition->GetFPID().GetLibItemName().empty() );
147 delete definition;
148 }
149
150 BOOST_CHECK( board->Footprints().size() > 0 );
151 BOOST_CHECK( board->GetNetCount() > 0 );
152
153 // A 4-layer board whose inner and back copper carry their EasyEDA names.
154 BOOST_CHECK_EQUAL( board->GetCopperLayerCount(), 4 );
155 BOOST_CHECK_EQUAL( board->GetLayerName( In1_Cu ), wxString( wxS( "Inner1" ) ) );
156 BOOST_CHECK_EQUAL( board->GetLayerName( In2_Cu ), wxString( wxS( "Inner2" ) ) );
157 BOOST_CHECK_EQUAL( board->GetLayerName( B_Cu ), wxString( wxS( "Bottom Layer" ) ) );
158}
159
160
const char * name
General utilities for PCB file IO for QA programs.
A temporary directory that will be deleted when it goes out of scope.
const std::filesystem::path & GetPath() const
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")