KiCad PCB EDA Suite
test_sch_sheet.cpp File Reference

Test suite for SCH_SHEET. More...

Go to the source code of this file.

Classes

class  TEST_SCH_SHEET_FIXTURE
 
struct  TEST_END_CONN_PIN
 

Functions

std::ostream & operator<< (std::ostream &os, DANGLING_END_ITEM const &d)
 Print helper. More...
 
 BOOST_AUTO_TEST_CASE (Default)
 Declare the test suite. More...
 
 BOOST_AUTO_TEST_CASE (SchematicParent)
 Test setting parent schematic. More...
 
 BOOST_AUTO_TEST_CASE (AddPins)
 Test adding pins to a sheet. More...
 
 BOOST_AUTO_TEST_CASE (PinRenumbering)
 Check that pins are added and renumbered to be unique. More...
 
 BOOST_AUTO_TEST_CASE (EndconnectionPoints)
 Test the endpoint and connection point collections: we should be able to add pins, then have them appear as endpoints. More...
 

Detailed Description

Test suite for SCH_SHEET.

Definition in file test_sch_sheet.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( AddPins  )

Test adding pins to a sheet.

Definition at line 109 of file test_sch_sheet.cpp.

110{
111 const wxPoint pinPos{ 42, 13 };
112
113 // we should catch null insertions
114 CHECK_WX_ASSERT( m_sheet.AddPin( nullptr ) );
115
116 auto newPin = std::make_unique<SCH_SHEET_PIN>( &m_sheet, pinPos, "pinname" );
117
118 // can't be const because of RemovePin (?!)
119 SCH_SHEET_PIN& pinRef = *newPin;
120
121 m_sheet.AddPin( newPin.release() );
122
123 // now we can find it in the list
124 BOOST_CHECK_EQUAL( m_sheet.HasPins(), true );
125 BOOST_CHECK_EQUAL( m_sheet.HasPin( "pinname" ), true );
126 BOOST_CHECK_EQUAL( m_sheet.HasPin( "PINname" ), true );
127
128 BOOST_CHECK_EQUAL( m_sheet.GetPin( pinPos ), &pinRef );
129
130 // check the actual list can be retrieved
131 std::vector<SCH_SHEET_PIN*>& pins = m_sheet.GetPins();
132 BOOST_CHECK_EQUAL( pins[0], &pinRef );
133
134 // catch the bad call
135 CHECK_WX_ASSERT( m_sheet.RemovePin( nullptr ) );
136
137 m_sheet.RemovePin( &pinRef );
138
139 // and it's gone
140 BOOST_CHECK_EQUAL( m_sheet.HasPins(), false );
141 BOOST_CHECK_EQUAL( m_sheet.HasPin( "pinname" ), false );
142 BOOST_CHECK_EQUAL( m_sheet.GetPin( pinPos ), nullptr );
143
144 delete &pinRef;
145}
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
#define CHECK_WX_ASSERT(STATEMENT)
A test macro to check a wxASSERT is thrown.

References CHECK_WX_ASSERT.

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( Default  )

Declare the test suite.

Check default properties

Definition at line 80 of file test_sch_sheet.cpp.

81{
82 BOOST_CHECK_EQUAL( m_csheet.GetPosition(), wxPoint( 0, 0 ) );
83
84 BOOST_CHECK_EQUAL( m_sheet.GetParent(), nullptr );
85 BOOST_CHECK_EQUAL( m_sheet.CountSheets(), 1 );
86
87 BOOST_CHECK_EQUAL( m_csheet.GetScreenCount(), 0 );
88
89 BOOST_CHECK_EQUAL( m_sheet.SymbolCount(), 0 );
90}

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( EndconnectionPoints  )

Test the endpoint and connection point collections: we should be able to add pins, then have them appear as endpoints.

Definition at line 185 of file test_sch_sheet.cpp.

186{
187 // x = zero because the pin is clamped to the left side by default
188 const std::vector<TEST_END_CONN_PIN> pin_defs = {
189 {
190 "1name",
191 { 0, 13 },
192 },
193 {
194 "2name",
195 { 0, 130 },
196 },
197 };
198
199 // Insert the pins into the sheet
200 for( const auto& pin : pin_defs )
201 m_sheet.AddPin( new SCH_SHEET_PIN( &m_sheet, pin.m_pos, pin.m_pin_name ) );
202
203 std::vector<SCH_SHEET_PIN*>& pins = m_sheet.GetPins();
204
205 // make sure the pins made it in
206 BOOST_CHECK_EQUAL( pins.size(), pin_defs.size() );
207
208 // Check that the EndPoint getter gets the right things
209 {
210 std::vector<DANGLING_END_ITEM> expectedDangling;
211
212 // Construct expected from the pin, not defs, as we need the pin address
213 for( SCH_SHEET_PIN* pin : pins )
214 {
215 expectedDangling.emplace_back( DANGLING_END_T::SHEET_LABEL_END, pin,
216 pin->GetPosition(), pin );
217 }
218
219 std::vector<DANGLING_END_ITEM> dangling;
220 m_sheet.GetEndPoints( dangling );
221
222 BOOST_CHECK_EQUAL_COLLECTIONS( dangling.begin(), dangling.end(),
223 expectedDangling.begin(), expectedDangling.end() );
224 }
225
226 // And check the connection getter
227 {
228 std::vector<wxPoint> expectedConnections;
229
230 // we want to see every pin that we just added
231 for( const auto& pin : pin_defs )
232 {
233 expectedConnections.push_back( pin.m_pos );
234 }
235
236 std::vector<VECTOR2I> connections = m_sheet.GetConnectionPoints();
237
238 BOOST_CHECK_EQUAL_COLLECTIONS( connections.begin(), connections.end(),
239 expectedConnections.begin(), expectedConnections.end() );
240 }
241}
@ SHEET_LABEL_END
Definition: sch_item.h:70

References pin, and SHEET_LABEL_END.

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( PinRenumbering  )

Check that pins are added and renumbered to be unique.

Definition at line 150 of file test_sch_sheet.cpp.

151{
152 for( int i = 0; i < 5; ++i )
153 {
154 SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( &m_sheet, wxPoint{ i, i }, "name" );
155
156 // set the pins to have the same number going in
157 pin->SetNumber( 2 );
158
159 m_sheet.AddPin( pin );
160 }
161
162 std::vector<SCH_SHEET_PIN*>& pins = m_sheet.GetPins();
163
164 std::vector<int> numbers;
165
166 for( SCH_SHEET_PIN* pin : pins )
167 numbers.push_back( pin->GetNumber() );
168
169 // and now...they are all unique
170 BOOST_CHECK_PREDICATE( KI_TEST::CollectionHasNoDuplicates<decltype( numbers )>, ( numbers ) );
171}
bool CollectionHasNoDuplicates(const T &aCollection)
Predicate to check a collection has no duplicate elements.

References KI_TEST::CollectionHasNoDuplicates(), and pin.

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( SchematicParent  )

Test setting parent schematic.

Definition at line 95 of file test_sch_sheet.cpp.

96{
97 m_sheet.SetParent( &m_schematic );
98
99 BOOST_CHECK_EQUAL( m_sheet.IsRootSheet(), false );
100
101 m_schematic.SetRoot( &m_sheet );
102
103 BOOST_CHECK_EQUAL( m_sheet.IsRootSheet(), true );
104}

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
DANGLING_END_ITEM const &  d 
)

Print helper.

Not a print_log_value because old Boosts don't like that in BOOST_CHECK_EQUAL_COLLECTIONS

Definition at line 64 of file test_sch_sheet.cpp.

65{
66 os << "DANGLING_END_ITEM[ type " << d.GetType() << " @(" << d.GetPosition().x << ", "
67 << d.GetPosition().y << "), item " << d.GetItem() << ", parent " << d.GetParent() << " ]";
68 return os;
69}

References DANGLING_END_ITEM::GetItem(), DANGLING_END_ITEM::GetParent(), DANGLING_END_ITEM::GetPosition(), DANGLING_END_ITEM::GetType(), VECTOR2< T >::x, and VECTOR2< T >::y.