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, 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
36
39
41
42#include <board.h>
43#include <footprint.h>
44#include <lib_id.h>
45
46#include <wx/filefn.h>
47#include <wx/filename.h>
48
49
50BOOST_AUTO_TEST_SUITE( EagleManagedLibNaming )
51
52
53BOOST_AUTO_TEST_CASE( FootprintNamesHaveNoUrnSuffix )
54{
55 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
56 + "plugins/eagle/issue18515_managed_lib.brd";
57
58 BOOST_REQUIRE_MESSAGE( wxFileName::FileExists( dataPath ),
59 "Test board file not found: " + dataPath );
60
61 // This board carries no Eagle clearance matrix, so loading it must not leave an
62 // empty .kicad_dru sidecar behind in the source tree.
63 wxFileName rulesFn( dataPath );
64 rulesFn.SetExt( wxT( "kicad_dru" ) );
65
66 BOOST_REQUIRE_MESSAGE( !rulesFn.FileExists(),
67 "Stale rules sidecar present before load: "
68 + rulesFn.GetFullPath().ToStdString() );
69
70 PCB_IO_EAGLE eaglePlugin;
71 BOARD* rawBoard = nullptr;
72
73 try
74 {
75 rawBoard = eaglePlugin.LoadBoard( dataPath, nullptr, nullptr );
76 }
77 catch( const IO_ERROR& e )
78 {
79 BOOST_FAIL( "IO_ERROR loading Eagle board: " + e.What().ToStdString() );
80 }
81 catch( const std::exception& e )
82 {
83 BOOST_FAIL( std::string( "Exception loading Eagle board: " ) + e.what() );
84 }
85
86 std::unique_ptr<BOARD> board( rawBoard );
87
88 BOOST_REQUIRE( board );
89
90 // The demo project has two elements: D1 (LED-0603) and R1 (R0603).
91 BOOST_REQUIRE_EQUAL( board->Footprints().size(), 2 );
92
93 bool sawLed = false;
94 bool sawRes = false;
95
96 for( FOOTPRINT* fp : board->Footprints() )
97 {
98 const wxString itemName = fp->GetFPID().GetUniStringLibItemName();
99
100 // The fix's invariant: bare Eagle package names with no
101 // "_<urn-ordinal>" suffix appended.
103 !itemName.Contains( wxT( "_38243636" ) ),
104 "Footprint name '" + itemName.ToStdString()
105 + "' should not carry the Eagle library URN ordinal." );
106
107 if( itemName == wxT( "LED-0603" ) )
108 sawLed = true;
109 else if( itemName == wxT( "R0603" ) )
110 sawRes = true;
111 }
112
113 BOOST_CHECK_MESSAGE( sawLed, "Expected footprint named 'LED-0603' (no URN suffix)" );
114 BOOST_CHECK_MESSAGE( sawRes, "Expected footprint named 'R0603' (no URN suffix)" );
115
116 // With no clearance matrix to convert, the importer must not write an empty
117 // rules sidecar into the source tree.
118 if( rulesFn.FileExists() )
119 {
120 wxRemoveFile( rulesFn.GetFullPath() );
121 BOOST_ERROR( "Importer wrote an empty rules sidecar: "
122 + rulesFn.GetFullPath().ToStdString() );
123 }
124}
125
126
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
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 ...
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
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()
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")