KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_net_chain_terminal_pad_stale.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 3
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
20#include <boost/test/unit_test.hpp>
21#include <board.h>
22#include <footprint.h>
23#include <pad.h>
24#include <netinfo.h>
28
29
30namespace
31{
32
33PAD* MakePad( FOOTPRINT* aFp, NETINFO_ITEM* aNet, const wxString& aNumber, const VECTOR2I& aPos )
34{
35 PAD* pad = new PAD( aFp );
36 pad->SetFrontShape( PAD_SHAPE::CIRCLE );
37 pad->SetSize( F_Cu, VECTOR2I( 1000000, 1000000 ) );
38 pad->SetPosition( aPos );
39 pad->SetNumber( aNumber );
40 pad->SetNet( aNet );
41 aFp->Add( pad );
42 return pad;
43}
44
45} // namespace
46
47
48BOOST_AUTO_TEST_SUITE( NetChainTerminalPadStaleness )
49
50
51// H-2: Removing a chain assignment via the netlist update must drop the prior-session
52// terminal pads on the affected net. Otherwise the s-expr writer will synthesize a chain
53// from the netname when it serialises the orphaned pad, and DRC matched-length will keep
54// treating the net as on-trunk.
55BOOST_AUTO_TEST_CASE( ChainRemovalClearsTerminalPads )
56{
57 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
58
59 NETINFO_ITEM* n1 = new NETINFO_ITEM( board.get(), wxS( "Net1" ), 1 );
60 NETINFO_ITEM* n2 = new NETINFO_ITEM( board.get(), wxS( "Net2" ), 2 );
61 board->Add( n1 );
62 board->Add( n2 );
63
64 n1->SetNetChain( wxS( "BUS_X" ) );
65 n2->SetNetChain( wxS( "BUS_X" ) );
66
67 FOOTPRINT* fp1 = new FOOTPRINT( board.get() );
68 fp1->SetReference( wxS( "U1" ) );
69 board->Add( fp1 );
70
71 FOOTPRINT* fp2 = new FOOTPRINT( board.get() );
72 fp2->SetReference( wxS( "U2" ) );
73 board->Add( fp2 );
74
75 PAD* pA = MakePad( fp1, n1, wxS( "1" ), VECTOR2I( 0, 0 ) );
76 PAD* pB = MakePad( fp2, n2, wxS( "1" ), VECTOR2I( 10000000, 0 ) );
77
78 n1->SetTerminalPad( 0, pA );
79 n1->SetTerminalPadUuid( 0, pA->m_Uuid );
80 n2->SetTerminalPad( 1, pB );
81 n2->SetTerminalPadUuid( 1, pB->m_Uuid );
82
84
85 BOARD_NETLIST_UPDATER::ApplyChainAssignments( board.get(), netlist, nullptr, false );
86
87 BOOST_CHECK( n1->GetNetChain().IsEmpty() );
88 BOOST_CHECK( n2->GetNetChain().IsEmpty() );
89
90 BOOST_CHECK( n1->GetTerminalPad( 0 ) == nullptr );
91 BOOST_CHECK( n1->GetTerminalPad( 1 ) == nullptr );
92 BOOST_CHECK( n2->GetTerminalPad( 0 ) == nullptr );
93 BOOST_CHECK( n2->GetTerminalPad( 1 ) == nullptr );
94
95 BOOST_CHECK( n1->GetTerminalPadUuid( 0 ) == niluuid );
96 BOOST_CHECK( n2->GetTerminalPadUuid( 1 ) == niluuid );
97}
98
99
100// Renaming a chain (BUS_OLD -> BUS_NEW) must drop prior-session pads on every member net so
101// the netlist's terminal-pin map starts from a clean slate. A net dropped from the chain
102// during the rename (Net2 here) must end up with both slots null.
103BOOST_AUTO_TEST_CASE( ChainRenameClearsStaleTerminalPads )
104{
105 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
106
107 NETINFO_ITEM* n1 = new NETINFO_ITEM( board.get(), wxS( "Net1" ), 1 );
108 NETINFO_ITEM* n2 = new NETINFO_ITEM( board.get(), wxS( "Net2" ), 2 );
109 board->Add( n1 );
110 board->Add( n2 );
111
112 n1->SetNetChain( wxS( "BUS_OLD" ) );
113 n2->SetNetChain( wxS( "BUS_OLD" ) );
114
115 FOOTPRINT* fp1 = new FOOTPRINT( board.get() );
116 fp1->SetReference( wxS( "U1" ) );
117 board->Add( fp1 );
118
119 FOOTPRINT* fp2 = new FOOTPRINT( board.get() );
120 fp2->SetReference( wxS( "U2" ) );
121 board->Add( fp2 );
122
123 PAD* pA = MakePad( fp1, n1, wxS( "1" ), VECTOR2I( 0, 0 ) );
124 PAD* pB = MakePad( fp2, n2, wxS( "1" ), VECTOR2I( 10000000, 0 ) );
125
126 n1->SetTerminalPad( 0, pA );
127 n1->SetTerminalPadUuid( 0, pA->m_Uuid );
128 n2->SetTerminalPad( 1, pB );
129 n2->SetTerminalPadUuid( 1, pB->m_Uuid );
130
132 netlist.SetNetChainFor( wxS( "Net1" ), wxS( "BUS_NEW" ) );
133
134 BOARD_NETLIST_UPDATER::ApplyChainAssignments( board.get(), netlist, nullptr, false );
135
136 BOOST_CHECK_EQUAL( n1->GetNetChain(), wxS( "BUS_NEW" ) );
137 BOOST_CHECK( n2->GetNetChain().IsEmpty() );
138
139 BOOST_CHECK( n1->GetTerminalPad( 0 ) == nullptr );
140 BOOST_CHECK( n1->GetTerminalPad( 1 ) == nullptr );
141 BOOST_CHECK( n2->GetTerminalPad( 0 ) == nullptr );
142 BOOST_CHECK( n2->GetTerminalPad( 1 ) == nullptr );
143
144 BOOST_CHECK( n1->GetTerminalPadUuid( 0 ) == niluuid );
145 BOOST_CHECK( n2->GetTerminalPadUuid( 1 ) == niluuid );
146}
147
148
149// Sanity: a net whose chain assignment is unchanged must keep its prior terminal pads.
150// The clearing rule must NOT fire on stable chains, otherwise a benign netlist refresh
151// would wipe the s-expr-restored bindings before the terminal-pin reapply pass runs.
152BOOST_AUTO_TEST_CASE( UnchangedChainPreservesTerminalPads )
153{
154 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
155
156 NETINFO_ITEM* n1 = new NETINFO_ITEM( board.get(), wxS( "Net1" ), 1 );
157 board->Add( n1 );
158 n1->SetNetChain( wxS( "BUS_K" ) );
159
160 FOOTPRINT* fp = new FOOTPRINT( board.get() );
161 fp->SetReference( wxS( "U1" ) );
162 board->Add( fp );
163
164 PAD* pA = MakePad( fp, n1, wxS( "1" ), VECTOR2I( 0, 0 ) );
165
166 n1->SetTerminalPad( 0, pA );
167 n1->SetTerminalPadUuid( 0, pA->m_Uuid );
168
170 netlist.SetNetChainFor( wxS( "Net1" ), wxS( "BUS_K" ) );
171
172 BOARD_NETLIST_UPDATER::ApplyChainAssignments( board.get(), netlist, nullptr, false );
173
174 BOOST_CHECK_EQUAL( n1->GetNetChain(), wxS( "BUS_K" ) );
175 BOOST_CHECK_EQUAL( n1->GetTerminalPad( 0 ), pA );
176 BOOST_CHECK( n1->GetTerminalPadUuid( 0 ) == pA->m_Uuid );
177}
178
179
static void ApplyChainAssignments(BOARD *aBoard, const NETLIST &aNetlist, REPORTER *aReporter, bool aDryRun)
Apply the netlist's chain assignments to every NETINFO_ITEM on the board.
const KIID m_Uuid
Definition eda_item.h:531
void SetReference(const wxString &aReference)
Definition footprint.h:847
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Handle the data for a net.
Definition netinfo.h:46
const wxString & GetNetChain() const
Definition netinfo.h:112
const KIID & GetTerminalPadUuid(int aIndex) const
Definition netinfo.h:118
void SetTerminalPadUuid(int aIndex, const KIID &aUuid)
Definition netinfo.h:117
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:115
void SetNetChain(const wxString &aNetChain)
Definition netinfo.h:113
void SetTerminalPad(int aIndex, PAD *aPad)
Definition netinfo.h:116
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition pad.h:61
KIID niluuid(0)
@ F_Cu
Definition layer_ids.h:60
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
std::string netlist
BOOST_AUTO_TEST_CASE(ChainRemovalClearsTerminalPads)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683