KiCad PCB EDA Suite
test_board_item.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <eda_item_test_utils.h>
#include <core/typeinfo.h>
#include <drc/drc_item.h>
#include <board.h>
#include <board_item.h>
#include <footprint.h>
#include <pad.h>
#include <pcb_shape.h>
#include <pcb_text.h>
#include <pcb_textbox.h>
#include <pcb_bitmap.h>
#include <fp_text.h>
#include <fp_textbox.h>
#include <fp_shape.h>
#include <zone.h>
#include <pcb_track.h>
#include <pcb_marker.h>
#include <pcb_dimension.h>
#include <pcb_target.h>
#include <netinfo.h>
#include <pcb_group.h>

Go to the source code of this file.

Classes

class  TEST_BOARD_ITEM_FIXTURE
 

Functions

 BOOST_AUTO_TEST_CASE (Move)
 
 BOOST_AUTO_TEST_CASE (Rotate)
 
 BOOST_AUTO_TEST_CASE (FlipLeftRight)
 
 BOOST_AUTO_TEST_CASE (FlipUpDown)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( FlipLeftRight  )

Definition at line 279 of file test_board_item.cpp.

280{
281 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
282 {
283 KICAD_T type = static_cast<KICAD_T>( i );
284
285 auto item = std::unique_ptr<BOARD_ITEM>( Instantiate( type ) );
286
287 if( item == nullptr )
288 continue;
289
290 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
291 {
292 IterateOverPositionsAndReferences<BOARD_ITEM>(
293 item.get(),
294 []( BOARD_ITEM* aOriginalItem, wxPoint aRef )
295 {
296 FP_SHAPE* originalFpShape = dynamic_cast<FP_SHAPE*>( aOriginalItem );
297
298 if( originalFpShape != nullptr )
299 originalFpShape->SetDrawCoord();
300
301 // FIXME: Update() has to be called after SetPosition() to update dimension
302 // shapes.
303 PCB_DIMENSION_BASE* originalDimension =
304 dynamic_cast<PCB_DIMENSION_BASE*>( aOriginalItem );
305
306 if( originalDimension != nullptr )
307 originalDimension->Update();
308
309 auto item = std::unique_ptr<BOARD_ITEM>( aOriginalItem->Duplicate() );
310
311 // Two equivalent flips are an identity.
312
313 item->Flip( aRef, true );
314 item->Flip( aRef, true );
315
316 FP_SHAPE* fpShape = dynamic_cast<FP_SHAPE*>( aOriginalItem );
317
318 if( fpShape != nullptr )
319 fpShape->SetDrawCoord();
320
321 CompareItems( item.get(), aOriginalItem );
322 } );
323 }
324 }
325}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ MAX_STRUCT_TYPE_ID
Definition: typeinfo.h:241
#define BOOST_TEST_CONTEXT(A)

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( FlipUpDown  )

Definition at line 328 of file test_board_item.cpp.

329{
330 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
331 {
332 KICAD_T type = static_cast<KICAD_T>( i );
333
334 auto item = std::unique_ptr<BOARD_ITEM>( Instantiate( type ) );
335
336 if( item == nullptr )
337 continue;
338
339 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
340 {
341 IterateOverPositionsAndReferences<BOARD_ITEM>(
342 item.get(),
343 []( BOARD_ITEM* aOriginalItem, wxPoint aRef )
344 {
345 FP_SHAPE* originalFpShape = dynamic_cast<FP_SHAPE*>( aOriginalItem );
346
347 if( originalFpShape != nullptr )
348 originalFpShape->SetDrawCoord();
349
350 // FIXME: Update() has to be called after SetPosition() to update dimension
351 // shapes.
352 PCB_DIMENSION_BASE* originalDimension =
353 dynamic_cast<PCB_DIMENSION_BASE*>( aOriginalItem );
354
355 if( originalDimension != nullptr )
356 originalDimension->Update();
357
358 auto item = std::unique_ptr<BOARD_ITEM>( aOriginalItem->Duplicate() );
359
360 // Two equivalent flips are an identity.
361
362 item->Flip( aRef, false );
363 item->Flip( aRef, false );
364
365 FP_SHAPE* fpShape = dynamic_cast<FP_SHAPE*>( aOriginalItem );
366
367 if( fpShape != nullptr )
368 fpShape->SetDrawCoord();
369
370 CompareItems( item.get(), aOriginalItem );
371 } );
372 }
373 }
374}

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( Move  )

Definition at line 169 of file test_board_item.cpp.

170{
171 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
172 {
173 KICAD_T type = static_cast<KICAD_T>( i );
174
175 auto item = std::unique_ptr<BOARD_ITEM>( Instantiate( type ) );
176
177 if( item == nullptr )
178 continue;
179
180 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
181 {
182 IterateOverPositionsAndReferences<BOARD_ITEM>(
183 item.get(),
184 []( BOARD_ITEM* aOriginalItem, wxPoint aRef )
185 {
186 FP_SHAPE* originalFpShape = dynamic_cast<FP_SHAPE*>( aOriginalItem );
187
188 if( originalFpShape != nullptr )
189 originalFpShape->SetDrawCoord();
190
191 // FIXME: Update() has to be called after SetPosition() to update dimension
192 // shapes.
193 PCB_DIMENSION_BASE* originalDimension =
194 dynamic_cast<PCB_DIMENSION_BASE*>( aOriginalItem );
195
196 if( originalDimension != nullptr )
197 originalDimension->Update();
198
199 auto item = std::unique_ptr<BOARD_ITEM>( aOriginalItem->Duplicate() );
200 VECTOR2I originalPos = item->GetPosition();
201
202 // Move to a point, then go back.
203 // This has to be an identity transformation.
204
205 item->Move( aRef );
206
207 FP_SHAPE* fpShape = dynamic_cast<FP_SHAPE*>( item.get() );
208
209 if( fpShape != nullptr )
210 fpShape->SetDrawCoord();
211
212 BOOST_CHECK_EQUAL( item->GetPosition(), originalPos + aRef );
213
214 item->Move( -aRef );
215
216 if( fpShape != nullptr )
217 fpShape->SetDrawCoord();
218
219 CompareItems( item.get(), aOriginalItem );
220 } );
221 }
222 }
223}

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( Rotate  )

Definition at line 226 of file test_board_item.cpp.

227{
228 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
229 {
230 KICAD_T type = static_cast<KICAD_T>( i );
231
232 auto item = std::unique_ptr<BOARD_ITEM>( Instantiate( type ) );
233
234 if( item == nullptr )
235 continue;
236
237 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
238 {
239 // Four same 90 degree rotations are an identity.
240
241 IterateOverPositionsAndReferences<BOARD_ITEM>(
242 item.get(),
243 []( BOARD_ITEM* aOriginalItem, wxPoint aRef )
244 {
245 FP_SHAPE* originalFpShape = dynamic_cast<FP_SHAPE*>( aOriginalItem );
246
247 if( originalFpShape != nullptr )
248 originalFpShape->SetDrawCoord();
249
250 // FIXME: Update() has to be called after SetPosition() to update dimension
251 // shapes.
252 PCB_DIMENSION_BASE* originalDimension =
253 dynamic_cast<PCB_DIMENSION_BASE*>( aOriginalItem );
254
255 if( originalDimension != nullptr )
256 originalDimension->Update();
257
258 auto item = std::unique_ptr<BOARD_ITEM>( aOriginalItem->Duplicate() );
259
260 // Four equivalent 90 degree rotations are an identity.
261
262 item->Rotate( aRef, EDA_ANGLE( 90.0, DEGREES_T ) );
263 item->Rotate( aRef, EDA_ANGLE( 90.0, DEGREES_T ) );
264 item->Rotate( aRef, EDA_ANGLE( 90.0, DEGREES_T ) );
265 item->Rotate( aRef, EDA_ANGLE( 90.0, DEGREES_T ) );
266
267 FP_SHAPE* fpShape = dynamic_cast<FP_SHAPE*>( aOriginalItem );
268
269 if( fpShape != nullptr )
270 fpShape->SetDrawCoord();
271
272 CompareItems( item.get(), aOriginalItem );
273 } );
274 }
275 }
276}

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.