KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_cadstar_footprints.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 (C) 2023 Roberto Fernandez Bautista <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
29
33
34#include <board.h>
35#include <footprint.h>
36#include <pad.h>
37#include <pcb_track.h>
38#include <zone.h>
39#include <wx/log.h>
40
41
43{
45 {
46 // Don't internally throw on font substitution warnings
47 wxLog::SetTimestamp( wxEmptyString );
48 }
49
52};
53
54
55BOOST_FIXTURE_TEST_SUITE( CadstarFootprintsImport, CADSTAR_IMPORT_FIXTURE )
56
57
58
63BOOST_AUTO_TEST_CASE( CadstarFootprintImport )
64{
65 std::vector<std::pair<wxString, wxString>> tests = {
66 { "footprint-with-thermal-pad.cpa", "footprint-with-thermal-pad.pretty" }
67 };
68
69 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/cadstar/lib/";
70
71 for( const std::pair<wxString, wxString>& libName : tests )
72 {
73 wxString cstarLibraryPath = dataPath + libName.first;
74 wxString kicadLibraryPath = dataPath + libName.second;
75
76 wxArrayString cstarFootprintNames;
77 wxArrayString kicadFootprintNames;
78
79 BOOST_REQUIRE_NO_THROW(
80 cstarPlugin.FootprintEnumerate( cstarFootprintNames, cstarLibraryPath, true, nullptr ) );
81 BOOST_REQUIRE_NO_THROW(
82 kicadPlugin.FootprintEnumerate( kicadFootprintNames, kicadLibraryPath, true, nullptr ) );
83
84 BOOST_CHECK_EQUAL( cstarFootprintNames.GetCount(), kicadFootprintNames.GetCount() );
85
86 for( size_t i = 0; i < cstarFootprintNames.GetCount(); i++ )
87 {
88 wxString footprintName = cstarFootprintNames[i];
89
90 BOOST_TEST_CONTEXT( wxString::Format( wxT( "Import '%s' from '%s'" ),
91 footprintName,
92 libName.first ) )
93 {
94 std::unique_ptr<FOOTPRINT> eagleFp =
95 cstarPlugin.FootprintLoad( cstarLibraryPath, footprintName, false, nullptr );
96 BOOST_CHECK( eagleFp );
97
98 BOOST_CHECK_EQUAL( "REF**", eagleFp->GetReference() );
99 BOOST_CHECK_EQUAL( footprintName, eagleFp->GetValue() );
100
101 std::unique_ptr<FOOTPRINT> kicadFp =
102 kicadPlugin.FootprintLoad( kicadLibraryPath, footprintName, true, nullptr );
103 BOOST_CHECK( kicadFp );
104
105 KI_TEST::CheckFootprint( kicadFp.get(), eagleFp.get() );
106 }
107 }
108 }
109}
110
111
116BOOST_AUTO_TEST_CASE( CadstarRevision7FormatImport )
117{
118 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/cadstar/route_offset/";
119 wxString filePath = dataPath + "revision7_format_no_routewidth.cpa";
120
121 std::unique_ptr<BOARD> board;
122
123 BOOST_CHECK_NO_THROW( board = cstarPlugin.LoadBoard( filePath ) );
124
125 BOOST_REQUIRE( board != nullptr );
126
127 // The test file has 5 nets with routes
128 std::vector<PCB_TRACK*> tracks;
129
130 for( PCB_TRACK* track : board->Tracks() )
131 tracks.push_back( track );
132
133 // Should have imported some tracks
134 BOOST_CHECK( tracks.size() > 0 );
135
136 // All nets use route code W1 (OptimalWidth 100000 hundredth-micron = 1.0 mm). Track widths
137 // are derived from that route code since the routes have no explicit ROUTEWIDTH nodes.
138 const int expectedWidth = pcbIUScale.mmToIU( 1.0 );
139 bool foundRouteCodeWidth = false;
140
141 for( PCB_TRACK* track : tracks )
142 {
143 // No track should be left at zero width by the missing-ROUTEWIDTH fallback
144 BOOST_CHECK( track->GetWidth() > 0 );
145
146 if( track->GetWidth() == expectedWidth )
147 foundRouteCodeWidth = true;
148 }
149
150 // At least one track must take the route-code-derived width, proving the fallback was used
151 BOOST_CHECK( foundRouteCodeWidth );
152}
153
154
160BOOST_AUTO_TEST_CASE( UnknownReassignShapeIsSkipped )
161{
162 XNODE padReassign( wxXML_ELEMENT_NODE, wxT( "PADREASSIGN" ) );
163 padReassign.AddAttribute( wxT( "attr0" ), wxT( "TOP" ) );
164 padReassign.AddChild( new XNODE( wxXML_ELEMENT_NODE, wxT( "FUTURE_SHAPE" ) ) );
165
168
169 BOOST_CHECK_NO_THROW( padParser.Parse( &padReassign, &ctx ) );
170 BOOST_CHECK( !padParser.HasShape );
171
172 XNODE viaReassign( wxXML_ELEMENT_NODE, wxT( "VIAREASSIGN" ) );
173 viaReassign.AddAttribute( wxT( "attr0" ), wxT( "TOP" ) );
174 viaReassign.AddChild( new XNODE( wxXML_ELEMENT_NODE, wxT( "FUTURE_SHAPE" ) ) );
175
177
178 BOOST_CHECK_NO_THROW( viaParser.Parse( &viaReassign, &ctx ) );
179 BOOST_CHECK( !viaParser.HasShape );
180
181 // An empty reassignment (no shape child at all) must not crash either
182 XNODE emptyReassign( wxXML_ELEMENT_NODE, wxT( "PADREASSIGN" ) );
183 emptyReassign.AddAttribute( wxT( "attr0" ), wxT( "TOP" ) );
184
186
187 BOOST_CHECK_NO_THROW( emptyParser.Parse( &emptyReassign, &ctx ) );
188 BOOST_CHECK( !emptyParser.HasShape );
189}
190
191
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
General utilities for PCB file IO for QA programs.
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:67
void AddAttribute(const wxString &aName, const wxString &aValue) override
Definition xnode.cpp:88
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
void CheckFootprint(const FOOTPRINT *expected, const FOOTPRINT *fp)
Helper method to check if two footprints are semantically the same.
PCB_IO_CADSTAR_ARCHIVE cstarPlugin
bool HasShape
False when the shape node was unknown and skipped.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool HasShape
False when the shape node was unknown and skipped.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(CadstarFootprintImport)
Compare all footprints with their KiCad reference footprint TODO: Refactor this code so it can be mad...
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")