KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_pin.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 (C) 2019-2021 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 2
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/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 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
26
27// Code under test
28#include <sch_pin.h>
29#include <sch_symbol.h>
30
31
33{
34public:
36 {
37 m_parent_part = new LIB_SYMBOL( "parent_part", nullptr );
38
41
42 // give the pin some kind of data we can use to test
43 m_lib_pin->SetNumber( "42" );
44 m_lib_pin->SetName( "pinname" );
45 m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
46 m_lib_pin->SetPosition( VECTOR2I( 1, -2 ) ); // local coord system is upside-down
47
50 VECTOR2I( 1, 2 ) );
51 m_parent_symbol->SetRef( &path, "U2" );
53
55 }
56
58 {
59 delete m_parent_symbol;
60 delete m_parent_part;
61 }
62
65
67 SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us
68};
69
70
74BOOST_FIXTURE_TEST_SUITE( SchPin, TEST_SCH_PIN_FIXTURE )
75
76
79BOOST_AUTO_TEST_CASE( DefaultProperties )
80{
81 BOOST_CHECK_EQUAL( m_sch_pin->GetParentSymbol(), m_parent_symbol );
82
83 // Note: local coord system is upside-down; schematic coord system is not.
84 BOOST_CHECK_EQUAL( m_sch_pin->GetLocalPosition(), VECTOR2I( 1, -2 ) );
85 BOOST_CHECK_EQUAL( m_sch_pin->GetPosition(), VECTOR2I( 2, 4 ) );
86
87 BOOST_CHECK_EQUAL( m_sch_pin->IsVisible(), m_lib_pin->IsVisible() );
88 BOOST_CHECK_EQUAL( m_sch_pin->GetName(), m_lib_pin->GetName() );
89 BOOST_CHECK_EQUAL( m_sch_pin->GetNumber(), m_lib_pin->GetNumber() );
90
91 BOOST_CHECK( ( m_sch_pin->GetType() == m_lib_pin->GetType() ) );
92
93 BOOST_CHECK_EQUAL( m_sch_pin->IsGlobalPower(), m_lib_pin->IsGlobalPower() );
94}
95
100{
101 SCH_PIN assigned = *m_sch_pin;
102
103 BOOST_CHECK_EQUAL( assigned.GetParentSymbol(), m_parent_symbol );
104 BOOST_CHECK_EQUAL( assigned.GetNumber(), m_lib_pin->GetNumber() );
105}
106
111{
112 SCH_PIN copied( *m_sch_pin );
113
114 BOOST_CHECK_EQUAL( copied.GetParentSymbol(), m_parent_symbol );
115 BOOST_CHECK_EQUAL( copied.GetNumber(), m_lib_pin->GetNumber() );
116}
117
122{
123 // dangles by default
124 BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
125
126 // all you have to do to un-dangle is say so
127 m_sch_pin->SetIsDangling( false );
128 BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), false );
129
130 // and the same to re-dangle
131 m_sch_pin->SetIsDangling( true );
132 BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
133}
134
138BOOST_AUTO_TEST_CASE( PinNumbering )
139{
141
142 const wxString name = m_sch_pin->GetDefaultNetName( path );
143 BOOST_CHECK_EQUAL( name, "Net-(U2-pinname)" );
144
145 // do it again: this should now (transparently) go though the net name map
146 // can't really check directly, but coverage tools should see this
147 const wxString map_name = m_sch_pin->GetDefaultNetName( path );
148 BOOST_CHECK_EQUAL( map_name, name );
149}
150
154BOOST_AUTO_TEST_CASE( PinNumberingPower )
155{
156 // but if we set isPower...
157 m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
158 m_parent_part->SetPower();
159 BOOST_CHECK_EQUAL( m_lib_pin->IsGlobalPower(), true );
160
161 // and update symbol from library...
163 delete m_parent_symbol;
164 m_parent_symbol = new SCH_SYMBOL( *m_parent_part, m_parent_part->GetLibId(), &path, 0, 0,
165 VECTOR2I( 1, 2 ) );
166 m_parent_symbol->SetRef( &path, "U2" );
167 m_parent_symbol->SetValueFieldText( "voltage_value" );
168 m_parent_symbol->UpdatePins();
169
170 m_sch_pin = m_parent_symbol->GetPins( &path )[0];
171
172 // ... then the name is just the pin name
173 const wxString pwr_name = m_sch_pin->GetDefaultNetName( path );
174 BOOST_CHECK_EQUAL( pwr_name, "voltage_value" );
175}
176
177BOOST_AUTO_TEST_SUITE_END()
const char * name
Definition: DXF_plotter.cpp:57
Define a library symbol object.
Definition: lib_symbol.h:77
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:142
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:969
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:155
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:463
void SetName(const wxString &aName)
Definition: sch_pin.cpp:360
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_pin.h:190
void SetType(ELECTRICAL_PINTYPE aType)
Definition: sch_pin.h:99
const wxString & GetNumber() const
Definition: sch_pin.h:110
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:108
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:310
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:750
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
SCH_SYMBOL * m_parent_symbol
LIB_SYMBOL * m_parent_part
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
BOOST_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
BOOST_AUTO_TEST_CASE(DefaultProperties)
Declare the test suite.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588