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>
32
33
34BOOST_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.
41BOOST_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 );
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 );
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.
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.
94BOOST_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 );
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
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
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:835
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:50
const wxString & GetNetChain() const
Definition netinfo.h:115
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:118
void SetNetChain(const wxString &aNetChain)
Definition netinfo.h:116
void SetTerminalPad(int aIndex, PAD *aPad)
Definition netinfo.h:119
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition pad.h:55
void SetFrontShape(PAD_SHAPE aShape)
Definition pad.cpp:1424
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
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.h:259
@ F_Cu
Definition layer_ids.h:64
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(DryRunLeavesNetChainAndTerminalPadsUntouched)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687