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 ( Default  )

Declare the test suite.

Check default properties

Definition at line 79 of file test_sch_sheet.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( SchematicParent  )

Test setting parent schematic.

Definition at line 94 of file test_sch_sheet.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( AddPins  )

Test adding pins to a sheet.

Definition at line 108 of file test_sch_sheet.cpp.

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

References CHECK_WX_ASSERT.

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( PinRenumbering  )

Check that pins are added and renumbered to be unique.

Definition at line 147 of file test_sch_sheet.cpp.

148 {
149  for( int i = 0; i < 5; ++i )
150  {
151  SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( &m_sheet, wxPoint{ i, i }, "name" );
152 
153  // set the pins to have the same number going in
154  pin->SetNumber( 2 );
155 
156  m_sheet.AddPin( pin );
157  }
158 
159  std::vector<SCH_SHEET_PIN*>& pins = m_sheet.GetPins();
160 
161  std::vector<int> numbers;
162 
163  for( SCH_SHEET_PIN* pin : pins )
164  numbers.push_back( pin->GetNumber() );
165 
166  // and now...they are all unique
167  BOOST_CHECK_PREDICATE( KI_TEST::CollectionHasNoDuplicates<decltype( numbers )>, ( numbers ) );
168 }
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
int GetNumber() const
Get the sheet label number.
Definition: sch_sheet.h:143
bool CollectionHasNoDuplicates(const T &aCollection)
Predicate to check a collection has no duplicate elements.
void SetNumber(int aNumber)
Set the sheet label number.

References KI_TEST::CollectionHasNoDuplicates(), and SCH_SHEET_PIN::SetNumber().

◆ BOOST_AUTO_TEST_CASE() [5/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 182 of file test_sch_sheet.cpp.

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

References SHEET_LABEL_END.

◆ 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 63 of file test_sch_sheet.cpp.

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

References DANGLING_END_ITEM::GetItem(), DANGLING_END_ITEM::GetParent(), DANGLING_END_ITEM::GetPosition(), DANGLING_END_ITEM::GetType(), wxPoint::x, and wxPoint::y.