KiCad PCB EDA Suite
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 #include <eda_rect.h>
31 
32 
34 {
35 public:
37  {
38  m_parent_part = new LIB_SYMBOL( "parent_part", nullptr );
39 
42 
43  // give the pin some kind of data we can use to test
44  m_lib_pin->SetNumber( "42" );
45  m_lib_pin->SetName( "pinname" );
47  m_lib_pin->SetPosition( wxPoint( 1, -2 ) ); // local coord system is upside-down
48 
51  &path, 0, 0, wxPoint( 1, 2 ) );
52  m_parent_symbol->SetRef( &path, "U2" );
54 
56  }
57 
59  {
60  delete m_parent_symbol;
61  delete m_parent_part;
62  }
63 
66 
68  SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us
69 };
70 
71 
75 BOOST_FIXTURE_TEST_SUITE( SchPin, TEST_SCH_PIN_FIXTURE )
76 
77 
80 BOOST_AUTO_TEST_CASE( DefaultProperties )
81 {
82  BOOST_CHECK_EQUAL( m_sch_pin->GetParentSymbol(), m_parent_symbol );
83 
84  // Note: local coord system is upside-down; schematic coord system is not.
85  BOOST_CHECK_EQUAL( m_sch_pin->GetLocalPosition(), wxPoint( 1, -2 ) );
86  BOOST_CHECK_EQUAL( m_sch_pin->GetPosition(), wxPoint( 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->IsPowerConnection(), m_lib_pin->IsPowerConnection() );
95 }
96 
101 {
102  SCH_PIN assigned = *m_sch_pin;
103 
104  BOOST_CHECK_EQUAL( assigned.GetParentSymbol(), m_parent_symbol );
105  BOOST_CHECK_EQUAL( assigned.GetNumber(), m_lib_pin->GetNumber() );
106 }
107 
112 {
113  SCH_PIN copied( *m_sch_pin );
114 
115  BOOST_CHECK_EQUAL( copied.GetParentSymbol(), m_parent_symbol );
116  BOOST_CHECK_EQUAL( copied.GetNumber(), m_lib_pin->GetNumber() );
117 }
118 
122 BOOST_AUTO_TEST_CASE( PinDangling )
123 {
124  // dangles by default
125  BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
126 
127  // all you have to do to un-dangle is say so
128  m_sch_pin->SetIsDangling( false );
129  BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), false );
130 
131  // and the same to re-dangle
132  m_sch_pin->SetIsDangling( true );
133  BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
134 }
135 
139 BOOST_AUTO_TEST_CASE( PinNumbering )
140 {
142 
143  const wxString name = m_sch_pin->GetDefaultNetName( path );
144  BOOST_CHECK_EQUAL( name, "Net-(U2-Pad42)" );
145 
146  // do it again: this should now (transparently) go though the net name map
147  // can't really check directly, but coverage tools should see this
148  const wxString map_name = m_sch_pin->GetDefaultNetName( path );
149  BOOST_CHECK_EQUAL( map_name, name );
150 }
151 
155 BOOST_AUTO_TEST_CASE( PinNumberingPower )
156 {
157  // but if we set isPower...
158  m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
159  m_parent_part->SetPower();
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(),
165  &path, 0, 0, wxPoint( 1, 2 ) );
166  m_parent_symbol->SetRef( &path, "U2" );
167  m_parent_symbol->UpdatePins();
168 
169  m_sch_pin = m_parent_symbol->GetPins( &path )[0];
170 
171  // ... then the name is just the pin name
172  const wxString pwr_name = m_sch_pin->GetDefaultNetName( path );
173  BOOST_CHECK_EQUAL( pwr_name, "pinname" );
174 }
175 
176 BOOST_AUTO_TEST_SUITE_END()
power input (GND, VCC for ICs). Must be connected to a power output.
LIB_SYMBOL * m_parent_part
SCH_SYMBOL * GetParentSymbol() const
Definition: sch_pin.cpp:166
wxString GetNumber() const
Definition: sch_pin.h:108
void SetPosition(const wxPoint &aPos) override
Definition: lib_pin.h:211
Define a library symbol object.
Definition: lib_symbol.h:96
BOOST_CHECK(v2.Cross(v1)==1)
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:118
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:85
LIB_ID GetLibId() const override
Definition: lib_symbol.h:135
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:284
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:653
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void SetName(const wxString &aName)
Definition: lib_pin.h:108
Schematic symbol object.
Definition: sch_symbol.h:78
const char * name
Definition: DXF_plotter.cpp:56
usual pin input: must be connected
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:481
SCH_SYMBOL * m_parent_symbol
BOOST_AUTO_TEST_CASE(DefaultProperties)
Declare the test suite.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
Definition: sch_symbol.cpp:866