KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_apply_chain_assignments_dry_run.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
* or you may search the http://www.gnu.org website for the version 3 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
24
#include <boost/test/unit_test.hpp>
25
#include <
board.h
>
26
#include <
footprint.h
>
27
#include <
pad.h
>
28
#include <
netinfo.h
>
29
#include <
netlist_reader/board_netlist_updater.h
>
30
#include <
netlist_reader/pcb_netlist.h
>
31
#include <
qa_utils/wx_utils/unit_test_utils.h
>
32
33
34
BOOST_AUTO_TEST_SUITE
( ApplyChainAssignmentsDryRun )
35
36
37
// A dry-run pass through ApplyChainAssignments must not mutate the board. The function
38
// writes net->SetNetChain() and net->ClearTerminalPad() unconditionally if the dry-run
39
// flag is not honored, so seed each net with a distinct chain label and a sentinel
40
// terminal pad and check both survive the call.
41
BOOST_AUTO_TEST_CASE
( DryRunLeavesNetChainAndTerminalPadsUntouched )
42
{
43
std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
44
45
NETINFO_ITEM
* n1 =
new
NETINFO_ITEM
( board.get(), wxS(
"Net1"
), 1 );
46
NETINFO_ITEM
* n2 =
new
NETINFO_ITEM
( board.get(), wxS(
"Net2"
), 2 );
47
board->Add( n1 );
48
board->Add( n2 );
49
50
n1->
SetNetChain
( wxS(
"BUS_OLD"
) );
51
n2->
SetNetChain
( wxS(
"BUS_OLD"
) );
52
53
FOOTPRINT
* fp =
new
FOOTPRINT
( board.get() );
54
fp->
SetReference
( wxS(
"U1"
) );
55
board->Add( fp );
56
57
PAD
* pA =
new
PAD
( fp );
58
pA->
SetFrontShape
(
PAD_SHAPE::CIRCLE
);
59
pA->
SetSize
(
F_Cu
,
VECTOR2I
( 1000000, 1000000 ) );
60
pA->
SetNumber
( wxS(
"1"
) );
61
pA->
SetNet
( n1 );
62
fp->
Add
( pA );
63
64
PAD
* pB =
new
PAD
( fp );
65
pB->
SetFrontShape
(
PAD_SHAPE::CIRCLE
);
66
pB->
SetSize
(
F_Cu
,
VECTOR2I
( 1000000, 1000000 ) );
67
pB->
SetNumber
( wxS(
"2"
) );
68
pB->
SetNet
( n2 );
69
fp->
Add
( pB );
70
71
n1->
SetTerminalPad
( 0, pA );
72
n2->
SetTerminalPad
( 1, pB );
73
74
// Netlist proposes a new chain assignment that differs from what is on the board.
75
// A live run would write "BUS_NEW" and clear both terminal slots; a dry run must
76
// not.
77
NETLIST
netlist
;
78
netlist
.SetNetChainFor( wxS(
"Net1"
), wxS(
"BUS_NEW"
) );
79
netlist
.SetNetChainFor( wxS(
"Net2"
), wxString() );
80
81
BOARD_NETLIST_UPDATER::ApplyChainAssignments
( board.get(),
netlist
,
nullptr
,
true
);
82
83
BOOST_CHECK_EQUAL
( n1->
GetNetChain
(), wxS(
"BUS_OLD"
) );
84
BOOST_CHECK_EQUAL
( n2->
GetNetChain
(), wxS(
"BUS_OLD"
) );
85
86
BOOST_CHECK_EQUAL
( n1->
GetTerminalPad
( 0 ), pA );
87
BOOST_CHECK_EQUAL
( n2->
GetTerminalPad
( 1 ), pB );
88
}
89
90
91
// The live path (aDryRun=false) is exercised here as a positive control so a future
92
// regression that no-ops the function entirely cannot pass the dry-run test in
93
// isolation.
94
BOOST_AUTO_TEST_CASE
( LiveRunAppliesChainAndClearsTerminals )
95
{
96
std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
97
98
NETINFO_ITEM
* n1 =
new
NETINFO_ITEM
( board.get(), wxS(
"Net1"
), 1 );
99
board->Add( n1 );
100
101
n1->
SetNetChain
( wxS(
"BUS_OLD"
) );
102
103
FOOTPRINT
* fp =
new
FOOTPRINT
( board.get() );
104
fp->
SetReference
( wxS(
"U1"
) );
105
board->Add( fp );
106
107
PAD
* pA =
new
PAD
( fp );
108
pA->
SetFrontShape
(
PAD_SHAPE::CIRCLE
);
109
pA->
SetSize
(
F_Cu
,
VECTOR2I
( 1000000, 1000000 ) );
110
pA->
SetNumber
( wxS(
"1"
) );
111
pA->
SetNet
( n1 );
112
fp->
Add
( pA );
113
114
n1->
SetTerminalPad
( 0, pA );
115
116
NETLIST
netlist
;
117
netlist
.SetNetChainFor( wxS(
"Net1"
), wxS(
"BUS_NEW"
) );
118
119
BOARD_NETLIST_UPDATER::ApplyChainAssignments
( board.get(),
netlist
,
nullptr
,
false
);
120
121
BOOST_CHECK_EQUAL
( n1->
GetNetChain
(), wxS(
"BUS_NEW"
) );
122
BOOST_CHECK( n1->
GetTerminalPad
( 0 ) ==
nullptr
);
123
}
124
125
126
BOOST_AUTO_TEST_SUITE_END
()
ALTIUM_RECORD::PAD
@ PAD
Definition
altium_parser_pcb.h:137
BITMAPS::netlist
@ netlist
Definition
bitmaps_list.h:390
board.h
board_netlist_updater.h
BOARD_CONNECTED_ITEM::SetNet
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
Definition
board_connected_item.h:97
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
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::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
PAD::SetFrontShape
void SetFrontShape(PAD_SHAPE aShape)
Definition
pad.cpp:1424
PAD::SetNumber
void SetNumber(const wxString &aNumber)
Set the pad number (note that it can be alphanumeric, such as the array reference "AA12").
Definition
pad.h:136
PAD::SetSize
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition
pad.h:259
footprint.h
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_CASE
BOOST_AUTO_TEST_CASE(DryRunLeavesNetChainAndTerminalPadsUntouched)
Definition
test_apply_chain_assignments_dry_run.cpp:41
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
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_apply_chain_assignments_dry_run.cpp
Generated on Sat May 16 2026 00:07:12 for KiCad PCB EDA Suite by
1.13.2