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 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 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 <lib_symbol.h>
29#include <pin_type.h>
30#include <sch_pin.h>
31#include <sch_symbol.h>
32
33
35{
36public:
38 {
39 m_parent_part = new LIB_SYMBOL( "parent_part", nullptr );
40
43
44 // give the pin some kind of data we can use to test
45 m_lib_pin->SetNumber( "42" );
46 m_lib_pin->SetName( "pinname" );
47 m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
48 m_lib_pin->SetPosition( VECTOR2I( 1, 2 ) );
49
52 VECTOR2I( 1, 2 ) );
53 m_parent_symbol->SetRef( &path, "U2" );
55
57 }
58
60 {
61 delete m_parent_symbol;
62 delete m_parent_part;
63 }
64
67
69 SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us
70};
71
72
76BOOST_FIXTURE_TEST_SUITE( SchPin, TEST_SCH_PIN_FIXTURE )
77
78
81BOOST_AUTO_TEST_CASE( DefaultProperties )
82{
83 BOOST_CHECK_EQUAL( m_sch_pin->GetParentSymbol(), m_parent_symbol );
84
85 BOOST_CHECK_EQUAL( m_sch_pin->GetLocalPosition(), VECTOR2I( 1, 2 ) );
86 BOOST_CHECK_EQUAL( m_sch_pin->GetPosition(), VECTOR2I( 2, 4 ) );
87
88 BOOST_CHECK_EQUAL( m_sch_pin->IsVisible(), m_lib_pin->IsVisible() );
89 BOOST_CHECK_EQUAL( m_sch_pin->GetName(), m_lib_pin->GetName() );
90 BOOST_CHECK_EQUAL( m_sch_pin->GetNumber(), m_lib_pin->GetNumber() );
91
92 BOOST_CHECK( ( m_sch_pin->GetType() == m_lib_pin->GetType() ) );
93
94 BOOST_CHECK_EQUAL( m_sch_pin->IsGlobalPower(), m_lib_pin->IsGlobalPower() );
95 BOOST_CHECK_EQUAL( m_sch_pin->IsLocalPower(), m_lib_pin->IsLocalPower() );
96}
97
102{
103 SCH_PIN assigned = *m_sch_pin;
104
105 BOOST_CHECK_EQUAL( assigned.GetParentSymbol(), m_parent_symbol );
106 BOOST_CHECK_EQUAL( assigned.GetNumber(), m_lib_pin->GetNumber() );
107}
108
113{
114 SCH_PIN copied( *m_sch_pin );
115
116 BOOST_CHECK_EQUAL( copied.GetParentSymbol(), m_parent_symbol );
117 BOOST_CHECK_EQUAL( copied.GetNumber(), m_lib_pin->GetNumber() );
118 BOOST_CHECK_EQUAL( copied.GetAlt(), wxEmptyString );
119
120 SCH_PIN::ALT alt;
121 alt.m_Name = wxS( "alt" );
124 copied.GetAlternates()[ wxS( "alt" ) ] = alt;
125
126 // Set some non-default values
127 copied.SetAlt( "alt" );
128
129 SCH_PIN copied2( copied );
130 BOOST_CHECK_EQUAL( copied2.GetAlt(), "alt" );
131}
132
137{
138 // dangles by default
139 BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
140
141 // all you have to do to un-dangle is say so
142 m_sch_pin->SetIsDangling( false );
143 BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), false );
144
145 // and the same to re-dangle
146 m_sch_pin->SetIsDangling( true );
147 BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
148}
149
153BOOST_AUTO_TEST_CASE( PinNumbering )
154{
156
157 const wxString name = m_sch_pin->GetDefaultNetName( path );
158 BOOST_CHECK_EQUAL( name, "Net-(U2-pinname)" );
159
160 // do it again: this should now (transparently) go though the net name map
161 // can't really check directly, but coverage tools should see this
162 const wxString map_name = m_sch_pin->GetDefaultNetName( path );
163 BOOST_CHECK_EQUAL( map_name, name );
164}
165
169BOOST_AUTO_TEST_CASE( PinNumberingPower )
170{
171 // but if we set isPower...
172 m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
173 m_parent_part->SetGlobalPower();
174 BOOST_CHECK_EQUAL( m_lib_pin->IsGlobalPower(), true );
175
176 // and update symbol from library...
178 delete m_parent_symbol;
179 m_parent_symbol = new SCH_SYMBOL( *m_parent_part, m_parent_part->GetLibId(), &path, 0, 0,
180 VECTOR2I( 1, 2 ) );
181 m_parent_symbol->SetRef( &path, "U2" );
182 m_parent_symbol->SetValueFieldText( "voltage_value" );
183 m_parent_symbol->UpdatePins();
184
185 m_sch_pin = m_parent_symbol->GetPins( &path )[0];
186
187 // ... then the name is just the pin name
188 const wxString pwr_name = m_sch_pin->GetDefaultNetName( path );
189 BOOST_CHECK_EQUAL( pwr_name, "voltage_value" );
190}
191
const char * name
Definition: DXF_plotter.cpp:62
Define a library symbol object.
Definition: lib_symbol.h:85
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:155
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:786
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:218
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:554
ALT GetAlt(const wxString &aAlt)
Definition: sch_pin.h:147
void SetName(const wxString &aName)
Definition: sch_pin.cpp:405
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_pin.h:224
void SetType(ELECTRICAL_PINTYPE aType)
Definition: sch_pin.cpp:315
const wxString & GetNumber() const
Definition: sch_pin.h:123
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:75
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:288
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:592
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
SCH_SYMBOL * m_parent_symbol
LIB_SYMBOL * m_parent_part
@ PT_OUTPUT
usual output
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
wxString m_Name
Definition: sch_pin.h:44
GRAPHIC_PINSHAPE m_Shape
Definition: sch_pin.h:45
ELECTRICAL_PINTYPE m_Type
Definition: sch_pin.h:46
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_AUTO_TEST_SUITE_END()
bool copied
BOOST_AUTO_TEST_CASE(DefaultProperties)
Declare the test suite.
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695