KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_eagle_managed_lib_naming.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, see <https://www.gnu.org/licenses/>.
18 */
19
32
35
37
38#include <board.h>
39#include <footprint.h>
40#include <lib_id.h>
41
42#include <wx/filefn.h>
43#include <wx/filename.h>
44
45
46BOOST_AUTO_TEST_SUITE( EagleManagedLibNaming )
47
48
49BOOST_AUTO_TEST_CASE( FootprintNamesHaveNoUrnSuffix )
50{
51 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
52 + "plugins/eagle/issue18515_managed_lib.brd";
53
54 BOOST_REQUIRE_MESSAGE( wxFileName::FileExists( dataPath ),
55 "Test board file not found: " + dataPath );
56
57 // This board carries no Eagle clearance matrix, so loading it must not leave an
58 // empty .kicad_dru sidecar behind in the source tree.
59 wxFileName rulesFn( dataPath );
60 rulesFn.SetExt( wxT( "kicad_dru" ) );
61
62 BOOST_REQUIRE_MESSAGE( !rulesFn.FileExists(),
63 "Stale rules sidecar present before load: "
64 + rulesFn.GetFullPath().ToStdString() );
65
66 PCB_IO_EAGLE eaglePlugin;
67 std::unique_ptr<BOARD> board;
68
69 try
70 {
71 board = eaglePlugin.LoadBoard( dataPath );
72 }
73 catch( const IO_ERROR& e )
74 {
75 BOOST_FAIL( "IO_ERROR loading Eagle board: " + e.What().ToStdString() );
76 }
77 catch( const std::exception& e )
78 {
79 BOOST_FAIL( std::string( "Exception loading Eagle board: " ) + e.what() );
80 }
81
82 BOOST_REQUIRE( board );
83
84 // The demo project has two elements: D1 (LED-0603) and R1 (R0603).
85 BOOST_REQUIRE_EQUAL( board->Footprints().size(), 2 );
86
87 bool sawLed = false;
88 bool sawRes = false;
89
90 for( FOOTPRINT* fp : board->Footprints() )
91 {
92 const wxString itemName = fp->GetFPID().GetUniStringLibItemName();
93
94 // The fix's invariant: bare Eagle package names with no
95 // "_<urn-ordinal>" suffix appended.
96 BOOST_CHECK_MESSAGE(
97 !itemName.Contains( wxT( "_38243636" ) ),
98 "Footprint name '" + itemName.ToStdString()
99 + "' should not carry the Eagle library URN ordinal." );
100
101 if( itemName == wxT( "LED-0603" ) )
102 sawLed = true;
103 else if( itemName == wxT( "R0603" ) )
104 sawRes = true;
105 }
106
107 BOOST_CHECK_MESSAGE( sawLed, "Expected footprint named 'LED-0603' (no URN suffix)" );
108 BOOST_CHECK_MESSAGE( sawRes, "Expected footprint named 'R0603' (no URN suffix)" );
109
110 // With no clearance matrix to convert, the importer must not write an empty
111 // rules sidecar into the source tree.
112 if( rulesFn.FileExists() )
113 {
114 wxRemoveFile( rulesFn.GetFullPath() );
115 BOOST_ERROR( "Importer wrote an empty rules sidecar: "
116 + rulesFn.GetFullPath().ToStdString() );
117 }
118}
119
120
General utilities for PCB file IO for QA programs.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const char * what() const override
std::exception interface, returned as UTF-8
Works with Eagle 6.x XML board files and footprints to implement the Pcbnew #PLUGIN API or a portion ...
std::unique_ptr< BOARD > LoadBoard(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PCB_IO implementation knows about into new BOA...
Definition pcb_io.cpp:72
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()