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 KiCad Developers, see CHANGELOG.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 
32 
33 // Code under test
34 #include <sch_pin.h>
35 
36 #include <sch_component.h>
37 
38 #include <eda_rect.h>
39 
40 
42 {
43 public:
45  : m_parent_part( "parent_part", nullptr ),
47  m_parent_comp( wxPoint( 0, 0 ), nullptr ),
49  {
50  // give the pin some kind of data we can use to test
51  m_lib_pin.SetNumber( "42" );
52  m_lib_pin.SetName( "pinname" );
54 
55  SCH_SHEET_PATH path;
56  m_parent_comp.SetRef( &path, "U2" );
57  }
58 
61 
64 };
65 
66 
70 BOOST_FIXTURE_TEST_SUITE( SchPin, TEST_SCH_PIN_FIXTURE )
71 
72 
75 BOOST_AUTO_TEST_CASE( DefaultProperties )
76 {
77  BOOST_CHECK_EQUAL( m_sch_pin.GetParentComponent(), &m_parent_comp );
78  BOOST_CHECK_EQUAL( m_sch_pin.GetLibPin(), &m_lib_pin );
79 
80  BOOST_CHECK_EQUAL( m_sch_pin.GetLocalPosition(), wxPoint( 0, 0 ) );
81 
82  // These just forward to LIB_PIN for now, so this isn't very interesting
83  // but later we will want to test these functions for SCH_PIN's own functionality
84  BOOST_CHECK_EQUAL( m_sch_pin.IsVisible(), m_lib_pin.IsVisible() );
85  BOOST_CHECK_EQUAL( m_sch_pin.GetName(), m_lib_pin.GetName() );
86  BOOST_CHECK_EQUAL( m_sch_pin.GetNumber(), m_lib_pin.GetNumber() );
87 
88  BOOST_CHECK( ( m_sch_pin.GetType() == m_lib_pin.GetType() ) );
89 
90  BOOST_CHECK_EQUAL( m_sch_pin.IsPowerConnection(), m_lib_pin.IsPowerConnection() );
91 }
92 
97 {
98  SCH_PIN assigned = m_sch_pin;
99 
100  BOOST_CHECK_EQUAL( assigned.GetParentComponent(), &m_parent_comp );
101 }
102 
107 {
108  SCH_PIN copied( m_sch_pin );
109 
110  BOOST_CHECK_EQUAL( copied.GetParentComponent(), &m_parent_comp );
111 }
112 
116 BOOST_AUTO_TEST_CASE( PinDangling )
117 {
118  // dangles by default
119  BOOST_CHECK_EQUAL( m_sch_pin.IsDangling(), true );
120 
121  // all you have to do to un-dangle is say so
122  m_sch_pin.SetIsDangling( false );
123  BOOST_CHECK_EQUAL( m_sch_pin.IsDangling(), false );
124 
125  // and the same to re-dangle
126  m_sch_pin.SetIsDangling( true );
127  BOOST_CHECK_EQUAL( m_sch_pin.IsDangling(), true );
128 }
129 
133 BOOST_AUTO_TEST_CASE( PinNumbering )
134 {
135  SCH_SHEET_PATH path;
136 
137  const wxString name = m_sch_pin.GetDefaultNetName( path );
138  BOOST_CHECK_EQUAL( name, "Net-(U2-Pad42)" );
139 
140  // do it again: this should now (transparently) go though the net name map
141  // can't really check directly, but coverage tools should see this
142  const wxString map_name = m_sch_pin.GetDefaultNetName( path );
143  BOOST_CHECK_EQUAL( map_name, name );
144 }
145 
149 BOOST_AUTO_TEST_CASE( PinNumberingPower )
150 {
151  // but if we set is power...
152  m_lib_pin.SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
153  m_parent_part.SetPower();
154 
155  // the name is just the pin name
156  SCH_SHEET_PATH path;
157  const wxString pwr_name = m_sch_pin.GetDefaultNetName( path );
158  BOOST_CHECK_EQUAL( pwr_name, "pinname" );
159 }
160 
161 BOOST_AUTO_TEST_SUITE_END()
power input (GND, VCC for ICs). Must be connected to a power output.
SCH_COMPONENT m_parent_comp
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:193
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:162
Define a library symbol object.
SCH_SHEET_PATH.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void SetName(const wxString &aName)
Definition: lib_pin.h:184
const char * name
Definition: DXF_plotter.cpp:60
usual pin input: must be connected
Schematic symbol object.
Definition: sch_component.h:88
BOOST_AUTO_TEST_CASE(DefaultProperties)
Declare the test suite.
SCH_COMPONENT * GetParentComponent() const
Definition: sch_pin.cpp:81