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