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, 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
30BOOST_AUTO_TEST_SUITE( ApplyChainAssignmentsDryRun )
31
32
33// A dry-run pass through ApplyChainAssignments must not mutate the board. The function
34// writes net->SetNetChain() and net->ClearTerminalPad() unconditionally if the dry-run
35// flag is not honored, so seed each net with a distinct chain label and a sentinel
36// terminal pad and check both survive the call.
37BOOST_AUTO_TEST_CASE( DryRunLeavesNetChainAndTerminalPadsUntouched )
38{
39 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
40
41 NETINFO_ITEM* n1 = new NETINFO_ITEM( board.get(), wxS( "Net1" ), 1 );
42 NETINFO_ITEM* n2 = new NETINFO_ITEM( board.get(), wxS( "Net2" ), 2 );
43 board->Add( n1 );
44 board->Add( n2 );
45
46 n1->SetNetChain( wxS( "BUS_OLD" ) );
47 n2->SetNetChain( wxS( "BUS_OLD" ) );
48
49 FOOTPRINT* fp = new FOOTPRINT( board.get() );
50 fp->SetReference( wxS( "U1" ) );
51 board->Add( fp );
52
53 PAD* pA = new PAD( fp );
55 pA->SetSize( F_Cu, VECTOR2I( 1000000, 1000000 ) );
56 pA->SetNumber( wxS( "1" ) );
57 pA->SetNet( n1 );
58 fp->Add( pA );
59
60 PAD* pB = new PAD( fp );
62 pB->SetSize( F_Cu, VECTOR2I( 1000000, 1000000 ) );
63 pB->SetNumber( wxS( "2" ) );
64 pB->SetNet( n2 );
65 fp->Add( pB );
66
67 n1->SetTerminalPad( 0, pA );
68 n2->SetTerminalPad( 1, pB );
69
70 // Netlist proposes a new chain assignment that differs from what is on the board.
71 // A live run would write "BUS_NEW" and clear both terminal slots; a dry run must
72 // not.
74 netlist.SetNetChainFor( wxS( "Net1" ), wxS( "BUS_NEW" ) );
75 netlist.SetNetChainFor( wxS( "Net2" ), wxString() );
76
77 BOARD_NETLIST_UPDATER::ApplyChainAssignments( board.get(), netlist, nullptr, true );
78
79 BOOST_CHECK_EQUAL( n1->GetNetChain(), wxS( "BUS_OLD" ) );
80 BOOST_CHECK_EQUAL( n2->GetNetChain(), wxS( "BUS_OLD" ) );
81
82 BOOST_CHECK_EQUAL( n1->GetTerminalPad( 0 ), pA );
83 BOOST_CHECK_EQUAL( n2->GetTerminalPad( 1 ), pB );
84}
85
86
87// The live path (aDryRun=false) is exercised here as a positive control so a future
88// regression that no-ops the function entirely cannot pass the dry-run test in
89// isolation.
90BOOST_AUTO_TEST_CASE( LiveRunAppliesChainAndClearsTerminals )
91{
92 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
93
94 NETINFO_ITEM* n1 = new NETINFO_ITEM( board.get(), wxS( "Net1" ), 1 );
95 board->Add( n1 );
96
97 n1->SetNetChain( wxS( "BUS_OLD" ) );
98
99 FOOTPRINT* fp = new FOOTPRINT( board.get() );
100 fp->SetReference( wxS( "U1" ) );
101 board->Add( fp );
102
103 PAD* pA = new PAD( fp );
105 pA->SetSize( F_Cu, VECTOR2I( 1000000, 1000000 ) );
106 pA->SetNumber( wxS( "1" ) );
107 pA->SetNet( n1 );
108 fp->Add( pA );
109
110 n1->SetTerminalPad( 0, pA );
111
113 netlist.SetNetChainFor( wxS( "Net1" ), wxS( "BUS_NEW" ) );
114
115 BOARD_NETLIST_UPDATER::ApplyChainAssignments( board.get(), netlist, nullptr, false );
116
117 BOOST_CHECK_EQUAL( n1->GetNetChain(), wxS( "BUS_NEW" ) );
118 BOOST_CHECK( n1->GetTerminalPad( 0 ) == nullptr );
119}
120
121
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
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.
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
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
void SetFrontShape(PAD_SHAPE aShape)
Definition pad.cpp:1669
void SetNumber(const wxString &aNumber)
Set the pad number (note that it can be alphanumeric, such as the array reference "AA12").
Definition pad.h:142
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.cpp:254
@ F_Cu
Definition layer_ids.h:60
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(DryRunLeavesNetChainAndTerminalPadsUntouched)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
std::string netlist
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683