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
49
50
51BOOST_FIXTURE_TEST_SUITE( CadstarFootprintsImport, CADSTAR_IMPORT_FIXTURE )
52
53
54
59BOOST_AUTO_TEST_CASE( CadstarFootprintImport )
60{
61 std::vector<std::pair<wxString, wxString>> tests = {
62 { "footprint-with-thermal-pad.cpa", "footprint-with-thermal-pad.pretty" }
63 };
64
65 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/cadstar/lib/";
66
67 for( const std::pair<wxString, wxString>& libName : tests )
68 {
69 wxString cstarLibraryPath = dataPath + libName.first;
70 wxString kicadLibraryPath = dataPath + libName.second;
71
72 wxArrayString cstarFootprintNames;
73 wxArrayString kicadFootprintNames;
74
75 BOOST_REQUIRE_NO_THROW(
76 cstarPlugin.FootprintEnumerate( cstarFootprintNames, cstarLibraryPath, true, nullptr ) );
77 BOOST_REQUIRE_NO_THROW(
78 kicadPlugin.FootprintEnumerate( kicadFootprintNames, kicadLibraryPath, true, nullptr ) );
79
80 BOOST_CHECK_EQUAL( cstarFootprintNames.GetCount(), kicadFootprintNames.GetCount() );
81
82 for( size_t i = 0; i < cstarFootprintNames.GetCount(); i++ )
83 {
84 wxString footprintName = cstarFootprintNames[i];
85
86 BOOST_TEST_CONTEXT( wxString::Format( wxT( "Import '%s' from '%s'" ),
87 footprintName,
88 libName.first ) )
89 {
90 FOOTPRINT* eagleFp = cstarPlugin.FootprintLoad( cstarLibraryPath, footprintName,
91 false, nullptr );
92 BOOST_CHECK( eagleFp );
93
94 BOOST_CHECK_EQUAL( "REF**", eagleFp->GetReference() );
95 BOOST_CHECK_EQUAL( footprintName, eagleFp->GetValue() );
96
97 FOOTPRINT* kicadFp = kicadPlugin.FootprintLoad( kicadLibraryPath, footprintName,
98 true, nullptr );
99 BOOST_CHECK( kicadFp );
100
101 KI_TEST::CheckFootprint( kicadFp, eagleFp );
102 }
103 }
104 }
105}
106
107
112BOOST_AUTO_TEST_CASE( CadstarRevision7FormatImport )
113{
114 std::string dataPath = KI_TEST::GetPcbnewTestDataDir() + "plugins/cadstar/route_offset/";
115 wxString filePath = dataPath + "revision7_format_no_routewidth.cpa";
116
117 BOARD* board = nullptr;
118
119 BOOST_CHECK_NO_THROW( board = cstarPlugin.LoadBoard( filePath, nullptr, nullptr, nullptr ) );
120
121 BOOST_REQUIRE( board != nullptr );
122
123 // The test file has 5 nets with routes
124 std::vector<PCB_TRACK*> tracks;
125
126 for( PCB_TRACK* track : board->Tracks() )
127 tracks.push_back( track );
128
129 // Should have imported some tracks
130 BOOST_CHECK( tracks.size() > 0 );
131
132 // All nets use route code W1 (OptimalWidth 100000 hundredth-micron = 1.0 mm). Track widths
133 // are derived from that route code since the routes have no explicit ROUTEWIDTH nodes.
134 const int expectedWidth = pcbIUScale.mmToIU( 1.0 );
135 bool foundRouteCodeWidth = false;
136
137 for( PCB_TRACK* track : tracks )
138 {
139 // No track should be left at zero width by the missing-ROUTEWIDTH fallback
140 BOOST_CHECK( track->GetWidth() > 0 );
141
142 if( track->GetWidth() == expectedWidth )
143 foundRouteCodeWidth = true;
144 }
145
146 // At least one track must take the route-code-derived width, proving the fallback was used
147 BOOST_CHECK( foundRouteCodeWidth );
148
149 delete board;
150}
151
152
158BOOST_AUTO_TEST_CASE( UnknownReassignShapeIsSkipped )
159{
160 wxLogNull suppress;
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.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
const TRACKS & Tracks() const
Definition board.h:419
const wxString & GetValue() const
Definition footprint.h:863
const wxString & GetReference() const
Definition footprint.h:841
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")