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 274 of file test_board_item.cpp.

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

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

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( Move  )

Definition at line 164 of file test_board_item.cpp.

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

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( Rotate  )

Definition at line 221 of file test_board_item.cpp.

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

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.