KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pin_map_erc.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <memory>
23
24#include <pin_map.h>
25#include <lib_symbol.h>
26#include <sch_pin.h>
27#include <sch_symbol.h>
28#include <sch_screen.h>
29#include <sch_sheet.h>
30#include <sch_sheet_path.h>
31#include <schematic.h>
33#include <erc/erc.h>
34
35
37{
39 {
40 m_settingsManager.LoadProject( "" );
41 m_schematic = std::make_unique<SCHEMATIC>( &m_settingsManager.Prj() );
42 m_schematic->Reset();
43
44 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
45 SCH_SHEET* root = new SCH_SHEET( m_schematic.get() );
46 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic.get() );
47 root->SetScreen( screen );
48
49 m_schematic->AddTopLevelSheet( root );
50 m_schematic->RemoveTopLevelSheet( defaultSheet );
51 delete defaultSheet;
52 }
53
55 void placeSymbol( PIN_MAP aMap, const std::set<wxString>& aJumperGroup = {} )
56 {
58 path.push_back( &m_schematic->Root() );
59
60 m_libSym = std::make_unique<LIB_SYMBOL>( "DUT", nullptr );
61
62 for( const wxString& number : { wxString( "1" ), wxString( "2" ) } )
63 {
64 SCH_PIN* pin = new SCH_PIN( m_libSym.get() );
65 pin->SetNumber( number );
67 m_libSym->AddDrawItem( pin );
68 }
69
70 m_libSym->PinMaps().AddOrReplace( std::move( aMap ) );
71
72 if( !aJumperGroup.empty() )
73 m_libSym->JumperPinGroups().push_back( aJumperGroup );
74
75 SCH_SYMBOL* sym = new SCH_SYMBOL( *m_libSym, m_libSym->GetLibId(), &path, 0, 0,
76 VECTOR2I( 0, 0 ) );
77 sym->UpdatePins();
78 m_schematic->RootScreen()->Append( sym );
79 }
80
81 int runPinMapErc() { return ERC_TESTER( m_schematic.get() ).TestPinMap( nullptr, nullptr ); }
82
84 std::unique_ptr<SCHEMATIC> m_schematic;
85 std::unique_ptr<LIB_SYMBOL> m_libSym;
86};
87
88
89BOOST_FIXTURE_TEST_SUITE( PinMapErc, PIN_MAP_ERC_FIXTURE )
90
91
92BOOST_AUTO_TEST_CASE( StalePinReferenceFires )
93{
94 PIN_MAP map( wxS( "M" ) );
95 map.SetEntry( wxS( "1" ), wxS( "1" ) );
96 map.SetEntry( wxS( "9" ), wxS( "9" ) ); // pin 9 does not exist on the symbol
97
98 placeSymbol( std::move( map ) );
99
100 BOOST_CHECK_EQUAL( runPinMapErc(), 1 );
101}
102
103
104BOOST_AUTO_TEST_CASE( DuplicatePadFires )
105{
106 PIN_MAP map( wxS( "M" ) );
107 map.SetEntry( wxS( "1" ), wxS( "5" ) );
108 map.SetEntry( wxS( "2" ), wxS( "5" ) ); // two different pins -> same pad
109
110 placeSymbol( std::move( map ) );
111
112 BOOST_CHECK_EQUAL( runPinMapErc(), 1 );
113}
114
115
116BOOST_AUTO_TEST_CASE( CleanMapStaysQuiet )
117{
118 PIN_MAP map( wxS( "M" ) );
119 map.SetEntry( wxS( "1" ), wxS( "1" ) );
120 map.SetEntry( wxS( "2" ), wxS( "2" ) );
121
122 placeSymbol( std::move( map ) );
123
124 BOOST_CHECK_EQUAL( runPinMapErc(), 0 );
125}
126
127
128BOOST_AUTO_TEST_CASE( JumperedDuplicateStaysQuiet )
129{
130 // Two pins deliberately jumpered (internally connected) may share a pad.
131 PIN_MAP map( wxS( "M" ) );
132 map.SetEntry( wxS( "1" ), wxS( "5" ) );
133 map.SetEntry( wxS( "2" ), wxS( "5" ) );
134
135 placeSymbol( std::move( map ), { wxS( "1" ), wxS( "2" ) } );
136
137 BOOST_CHECK_EQUAL( runPinMapErc(), 0 );
138}
139
140
141BOOST_AUTO_TEST_CASE( StackedSamePinStaysQuiet )
142{
143 // One pin mapped to several pads (stacked) is not a duplicate-target collision.
144 PIN_MAP map( wxS( "M" ) );
145 map.SetEntry( wxS( "1" ), wxS( "[4,9]" ) );
146 map.SetEntry( wxS( "2" ), wxS( "2" ) );
147
148 placeSymbol( std::move( map ) );
149
150 BOOST_CHECK_EQUAL( runPinMapErc(), 0 );
151}
152
153
int TestPinMap(KIFACE *aCvPcb, PROJECT *aProject)
Check pin-to-pad maps (issue #2282): stale pin references, duplicate pad targets, bad pads and unmapp...
Definition erc.cpp:186
A named pin map.
Definition pin_map.h:64
void SetEntry(const wxString &aPinNumber, const wxString &aPadNumber)
Set the pad number for a symbol pin.
Definition pin_map.cpp:59
SCH_SHEET & Root() const
Definition schematic.h:134
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::unique_ptr< SCHEMATIC > m_schematic
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< LIB_SYMBOL > m_libSym
void placeSymbol(PIN_MAP aMap, const std::set< wxString > &aJumperGroup={})
Build a two-pin symbol carrying aMap (+ optional symbol jumper group) and place it.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
std::string path
KIBIS_PIN * pin
BOOST_AUTO_TEST_CASE(StalePinReferenceFires)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683