KiCad PCB EDA Suite
test_sch_rtree.cpp File Reference

Test suite for SCH_SHEET. More...

Go to the source code of this file.

Classes

class  TEST_SCH_RTREE_FIXTURE
 

Functions

 BOOST_AUTO_TEST_CASE (Default)
 Declare the test suite. More...
 
 BOOST_AUTO_TEST_CASE (Junctions)
 
 BOOST_AUTO_TEST_CASE (MixedElements)
 
 BOOST_AUTO_TEST_CASE (SingleElementTree)
 

Detailed Description

Test suite for SCH_SHEET.

Definition in file test_sch_rtree.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( Default  )

Declare the test suite.

Check default iterators

Definition at line 61 of file test_sch_rtree.cpp.

62 {
63  BOOST_CHECK_EQUAL( m_tree.empty(), true );
64 
65  int count = 0;
66  for( auto item : m_tree )
67  {
68  static_cast<void>( item );
69  count++;
70  }
71 
72  BOOST_CHECK_EQUAL( count, 0 );
73 
74  for( int type = 0; type <= MAX_STRUCT_TYPE_ID; type++ )
75  {
76  count = 0;
77  for( auto item : m_tree.OfType( KICAD_T( type ) ) )
78  {
79  static_cast<void>( item );
80  count++;
81  }
82 
83  BOOST_CHECK_EQUAL( count, 0 );
84  }
85 
86  EDA_RECT bbox;
87 
88  for( int type = 0; type <= MAX_STRUCT_TYPE_ID; type++ )
89  {
90  count = 0;
91  for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, bbox ) )
92  {
93  static_cast<void>( item );
94  count++;
95  }
96 
97  BOOST_CHECK_EQUAL( count, 0 );
98  }
99 }
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
Handle the component boundary box.
Definition: eda_rect.h:42

References MAX_STRUCT_TYPE_ID, and SCH_JUNCTION_T.

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( Junctions  )

Definition at line 101 of file test_sch_rtree.cpp.

102 {
103  for( int i = 0; i < 100; i++ )
104  {
105  SCH_JUNCTION* junction =
106  new SCH_JUNCTION( wxPoint( Mils2iu( 100 ) * i, Mils2iu( 100 ) * i ) );
107  m_tree.insert( junction );
108  }
109 
110  int count = 0;
111 
112  for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
113  {
114  static_cast<void>( item );
115  count++;
116  }
117 
118  BOOST_CHECK_EQUAL( count, 100 );
119 
120  count = 0;
121  for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
122  {
123  static_cast<void>( item );
124  count++;
125  }
126 
127  BOOST_CHECK_EQUAL( count, 0 );
128 
129  EDA_RECT small_bbox( wxPoint( -1, -1 ), wxSize( Mils2iu( 2 ), Mils2iu( 2 ) ) );
130  EDA_RECT med_bbox( wxPoint( 0, 0 ), wxSize( Mils2iu( 100 ), Mils2iu( 100 ) ) );
131  EDA_RECT big_bbox( wxPoint( 0, 0 ), wxSize( Mils2iu( 5000 ), Mils2iu( 5000 ) ) );
132 
133  count = 0;
134  for( auto item : m_tree.Overlapping( small_bbox ) )
135  {
136  BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
137  count++;
138  }
139 
140  BOOST_CHECK_EQUAL( count, 1 );
141 
142  count = 0;
143  for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
144  {
145  BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
146  count++;
147  }
148 
149  BOOST_CHECK_EQUAL( count, 1 );
150 
151  count = 0;
152  for( auto item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
153  {
154  BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
155  count++;
156  }
157 
158  BOOST_CHECK_EQUAL( count, 0 );
159 
160  count = 0;
161  for( auto item : m_tree.Overlapping( med_bbox ) )
162  {
163  BOOST_CHECK( med_bbox.Intersects( item->GetBoundingBox() ) );
164  count++;
165  }
166 
167  BOOST_CHECK_EQUAL( count, 2 );
168 
169  count = 0;
170  for( auto item : m_tree.Overlapping( big_bbox ) )
171  {
172  BOOST_CHECK( big_bbox.Intersects( item->GetBoundingBox() ) );
173  count++;
174  }
175 
176  BOOST_CHECK_EQUAL( count, 51 );
177 
178  for( SCH_ITEM* item : m_tree )
179  delete item;
180 }
BOOST_CHECK(v2.Cross(v1)==1)
Handle the component boundary box.
Definition: eda_rect.h:42
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196

References BOOST_CHECK(), EDA_RECT::Intersects(), SCH_JUNCTION_T, and SCH_NO_CONNECT_T.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( MixedElements  )

Definition at line 182 of file test_sch_rtree.cpp.

183 {
184  for( int i = 0; i < 100; i++ )
185  {
186  int x_sign = ( i % 2 == 0 ) ? -1 : 1;
187  int y_sign = ( i % 3 == 0 ) ? -1 : 1;
188 
189  SCH_JUNCTION* junction = new SCH_JUNCTION(
190  wxPoint( Mils2iu( 100 ) * i * x_sign, Mils2iu( 100 ) * i * y_sign ) );
191  m_tree.insert( junction );
192 
193  SCH_NO_CONNECT* nc = new SCH_NO_CONNECT(
194  wxPoint( Mils2iu( 150 ) * i * y_sign, Mils2iu( 150 ) * i * x_sign ) );
195  m_tree.insert( nc );
196  }
197 
198  int count = 0;
199 
200  for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
201  {
202  static_cast<void>( item );
203  count++;
204  }
205 
206  BOOST_CHECK_EQUAL( count, 100 );
207 
208  count = 0;
209  for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
210  {
211  static_cast<void>( item );
212  count++;
213  }
214 
215  BOOST_CHECK_EQUAL( count, 100 );
216 
217  EDA_RECT small_bbox( wxPoint( -1, -1 ), wxSize( Mils2iu( 2 ), Mils2iu( 2 ) ) );
218 
219  count = 0;
220  for( auto item : m_tree.Overlapping( small_bbox ) )
221  {
222  BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
223  count++;
224  }
225 
226  BOOST_CHECK_EQUAL( count, 2 );
227 
228  count = 0;
229  for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
230  {
231  BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
232  count++;
233  }
234 
235  BOOST_CHECK_EQUAL( count, 1 );
236 
237  count = 0;
238  for( auto item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
239  {
240  BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
241  count++;
242  }
243 
244  BOOST_CHECK_EQUAL( count, 1 );
245 
246  for( SCH_ITEM* item : m_tree )
247  delete item;
248 }
BOOST_CHECK(v2.Cross(v1)==1)
Handle the component boundary box.
Definition: eda_rect.h:42
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196

References BOOST_CHECK(), EDA_RECT::Intersects(), SCH_JUNCTION_T, and SCH_NO_CONNECT_T.

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( SingleElementTree  )

Definition at line 252 of file test_sch_rtree.cpp.

253 {
254  SCH_JUNCTION* junction = new SCH_JUNCTION( wxPoint( Mils2iu( 100 ), Mils2iu( 100 ) ) );
255  m_tree.insert( junction );
256 
257  SCH_NO_CONNECT* nc = new SCH_NO_CONNECT( wxPoint( Mils2iu( 150 ), Mils2iu( 150 ) ) );
258  m_tree.insert( nc );
259 
260  int count = 0;
261 
262  for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
263  {
264  static_cast<void>( item );
265  count++;
266  }
267 
268  BOOST_CHECK_EQUAL( count, 1 );
269 
270  count = 0;
271  for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
272  {
273  static_cast<void>( item );
274  count++;
275  }
276 
277  BOOST_CHECK_EQUAL( count, 1 );
278 
279  for( SCH_ITEM* item : m_tree )
280  delete item;
281 }
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196

References SCH_JUNCTION_T, and SCH_NO_CONNECT_T.