KiCad PCB EDA Suite
test_property.cpp File Reference
#include <unit_test_utils/unit_test_utils.h>
#include <wx/gdicmn.h>
#include <inspectable.h>
#include <property_mgr.h>

Go to the source code of this file.

Classes

class  A
 
class  B
 
class  C
 
class  D
 
class  E
 
struct  ENUM_GLOB_DESC
 
struct  CLASS_A_DESC
 
struct  CLASS_B_DESC
 
struct  CLASS_C_DESC
 
struct  CLASS_D_DESC
 
struct  CLASS_E_DESC
 
struct  PropertiesFixture
 

Enumerations

enum  enum_glob { TEST1 = 0, TEST2 = 1, TEST3 = 4 }
 

Functions

 ENUM_TO_WXANY (enum_glob)
 
 ENUM_TO_WXANY (D::enum_class)
 
 BOOST_AUTO_TEST_CASE (Init)
 
 BOOST_AUTO_TEST_CASE (SetGet)
 
 BOOST_AUTO_TEST_CASE (VirtualMethods)
 
 BOOST_AUTO_TEST_CASE (NotexistingProperties)
 
 BOOST_AUTO_TEST_CASE (IncorrectType)
 
 BOOST_AUTO_TEST_CASE (TypeCasting)
 
 BOOST_AUTO_TEST_CASE (EnumGlob)
 
 BOOST_AUTO_TEST_CASE (EnumClass)
 
 BOOST_AUTO_TEST_CASE (Availability)
 
 BOOST_AUTO_TEST_CASE (Alias)
 
 BOOST_AUTO_TEST_CASE (Rename)
 
 BOOST_AUTO_TEST_CASE (AlternativeEnum)
 

Variables

static struct ENUM_GLOB_DESC _ENUM_GLOB_DESC
 
static struct CLASS_A_DESC _CLASS_A_DESC
 
static struct CLASS_B_DESC _CLASS_B_DESC
 
static struct CLASS_C_DESC _CLASS_C_DESC
 
static struct CLASS_D_DESC _CLASS_D_DESC
 
static struct CLASS_E_DESC _CLASS_E_DESC
 

Enumeration Type Documentation

◆ enum_glob

enum enum_glob
Enumerator
TEST1 
TEST2 
TEST3 

Definition at line 77 of file test_property.cpp.

77 { TEST1 = 0, TEST2 = 1, TEST3 = 4 };

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/12]

BOOST_AUTO_TEST_CASE ( Init  )

Definition at line 223 of file test_property.cpp.

224 {
225  propMgr.Rebuild();
226 }

◆ BOOST_AUTO_TEST_CASE() [2/12]

BOOST_AUTO_TEST_CASE ( SetGet  )

Definition at line 229 of file test_property.cpp.

230 {
231  ptr = &b;
232  ptr->Set( "A", 100 );
233  ptr->Set( "point", wxPoint( 100, 200 ) );
234  BOOST_CHECK_EQUAL( *ptr->Get<int>( "A" ), 100 );
235  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point" ), wxPoint( 100, 200 ) );
236 
237  ptr = &d;
238  ptr->Set( "enumGlob", enum_glob::TEST2 );
239  ptr->Set( "enumClass", D::enum_class::TESTC );
240  BOOST_CHECK_EQUAL( *ptr->Get<enum_glob>( "enumGlob" ), enum_glob::TEST2 );
241  BOOST_CHECK_EQUAL( *ptr->Get<D::enum_class>( "enumClass" ), D::enum_class::TESTC );
242 }
enum_glob
enum_class

References TEST2.

◆ BOOST_AUTO_TEST_CASE() [3/12]

BOOST_AUTO_TEST_CASE ( VirtualMethods  )

Definition at line 245 of file test_property.cpp.

246 {
247  // D::setA() saves a doubled value, while B::setA() saves unmodified value
248  ptr = &b;
249  ptr->Set( "A", 23 );
250  BOOST_CHECK_EQUAL( *ptr->Get<int>( "A" ), 23 ); // unmodified == 23
251 
252  ptr = &d;
253  ptr->Set( "A", 23 );
254  BOOST_CHECK_EQUAL( *ptr->Get<int>( "A" ), 46 ); // doubled == 46
255 }

◆ BOOST_AUTO_TEST_CASE() [4/12]

BOOST_AUTO_TEST_CASE ( NotexistingProperties  )

Definition at line 258 of file test_property.cpp.

259 {
260  ptr = &d;
261  BOOST_CHECK_EQUAL( ptr->Set<int>( "does not exist", 5 ), false );
262  //BOOST_CHECK_EQUAL( ptr->Get<int>( "neither" ).has_value(), false );
263 }

◆ BOOST_AUTO_TEST_CASE() [5/12]

BOOST_AUTO_TEST_CASE ( IncorrectType  )

Definition at line 266 of file test_property.cpp.

267 {
268  ptr = &d;
269  BOOST_CHECK_THROW( ptr->Get<wxPoint>( "A" ), std::invalid_argument );
270 }

◆ BOOST_AUTO_TEST_CASE() [6/12]

BOOST_AUTO_TEST_CASE ( TypeCasting  )

Definition at line 273 of file test_property.cpp.

274 {
275  ptr = &d;
276  A* D_to_A = static_cast<A*>( propMgr.TypeCast( ptr, TYPE_HASH( D ), TYPE_HASH( A ) ) );
277  BOOST_CHECK_EQUAL( D_to_A, dynamic_cast<A*>( ptr ) );
278 
279  C* D_to_C = static_cast<C*>( propMgr.TypeCast( ptr, TYPE_HASH( D ), TYPE_HASH( C ) ) );
280  BOOST_CHECK_EQUAL( D_to_C, dynamic_cast<C*>( ptr ) );
281 }
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53

References TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [7/12]

BOOST_AUTO_TEST_CASE ( EnumGlob  )

Definition at line 283 of file test_property.cpp.

284 {
285  PROPERTY_BASE* prop = propMgr.GetProperty( TYPE_HASH( D ), "enumGlob" );
286  BOOST_CHECK( prop->HasChoices() );
287 
288  wxArrayInt values;
289  values.Add( enum_glob::TEST1 );
290  values.Add( enum_glob::TEST2 );
291  values.Add( enum_glob::TEST3 );
292  wxArrayString labels;
293  labels.Add( "TEST1" );
294  labels.Add( "TEST2" );
295  labels.Add( "TEST3" );
296 
297  const wxPGChoices& v = prop->Choices();
298  BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() );
299  BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() );
300 
301  for (int i = 0; i < values.GetCount(); ++i )
302  {
303  BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] );
304  }
305 
306  for (int i = 0; i < labels.GetCount(); ++i )
307  {
308  BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] );
309  }
310 }
virtual bool HasChoices() const
Returns true if this PROPERTY has a limited set of possible values.
Definition: property.h:213
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53
virtual const wxPGChoices & Choices() const
Returns a limited set of possible values (e.g.
Definition: property.h:195

References PROPERTY_BASE::Choices(), PROPERTY_BASE::HasChoices(), TEST1, TEST2, TEST3, and TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [8/12]

BOOST_AUTO_TEST_CASE ( EnumClass  )

Definition at line 312 of file test_property.cpp.

313 {
314  PROPERTY_BASE* prop = propMgr.GetProperty( TYPE_HASH( D ), "enumClass" );
315  BOOST_CHECK( prop->HasChoices() );
316 
317  wxArrayInt values;
318  values.Add( D::enum_class::TESTA );
319  values.Add( D::enum_class::TESTB );
320  values.Add( D::enum_class::TESTC );
321  wxArrayString labels;
322  labels.Add( "TESTA" );
323  labels.Add( "TESTB" );
324  labels.Add( "TESTC" );
325 
326  const wxPGChoices& v = prop->Choices();
327  BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() );
328  BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() );
329 
330  for (int i = 0; i < values.GetCount(); ++i )
331  {
332  BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] );
333  }
334 
335  for (int i = 0; i < labels.GetCount(); ++i )
336  {
337  BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] );
338  }
339 }
virtual bool HasChoices() const
Returns true if this PROPERTY has a limited set of possible values.
Definition: property.h:213
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53
virtual const wxPGChoices & Choices() const
Returns a limited set of possible values (e.g.
Definition: property.h:195

References PROPERTY_BASE::Choices(), PROPERTY_BASE::HasChoices(), and TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [9/12]

BOOST_AUTO_TEST_CASE ( Availability  )

Definition at line 342 of file test_property.cpp.

343 {
344  PROPERTY_BASE* propCond = propMgr.GetProperty( TYPE_HASH( D ), "cond" );
345  ptr = &d;
346 
347  // "cond" property is available only when "a" field is greater than 50
348  d.setA( 0 );
349  BOOST_CHECK( !propCond->Available( ptr ) );
350 
351  d.setA( 100 );
352  BOOST_CHECK( propCond->Available( ptr ) );
353 }
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53
bool Available(INSPECTABLE *aObject) const
Returns true if aObject offers this PROPERTY.
Definition: property.h:221

References PROPERTY_BASE::Available(), and TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [10/12]

BOOST_AUTO_TEST_CASE ( Alias  )

Definition at line 356 of file test_property.cpp.

357 {
358  ptr = &d;
359 
360  ptr->Set( "point", wxPoint( 100, 100 ) );
361  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point" ), wxPoint( 100, 100 ) );
362  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point_alias" ), wxPoint( 100, 100 ) );
363 
364  ptr->Set( "point_alias", wxPoint( 300, 300 ) );
365  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point" ), wxPoint( 300, 300 ) );
366  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point_alias" ), wxPoint( 300, 300 ) );
367 }

◆ BOOST_AUTO_TEST_CASE() [11/12]

BOOST_AUTO_TEST_CASE ( Rename  )

Definition at line 370 of file test_property.cpp.

371 {
372  PROPERTY_BASE* prop;
373 
374  prop = propMgr.GetProperty( TYPE_HASH( D ), "bool" );
375  BOOST_CHECK_EQUAL( prop, nullptr );
376 
377  prop = propMgr.GetProperty( TYPE_HASH( D ), "replaced_bool" );
378  BOOST_CHECK( prop );
379 }
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53

References TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [12/12]

BOOST_AUTO_TEST_CASE ( AlternativeEnum  )

Definition at line 382 of file test_property.cpp.

383 {
384  PROPERTY_BASE* prop = propMgr.GetProperty( TYPE_HASH( E ), "enumGlob" );
385  BOOST_CHECK( prop->HasChoices() );
386 
387  wxArrayInt values;
388  values.Add( enum_glob::TEST1 );
389  values.Add( enum_glob::TEST3 );
390  wxArrayString labels;
391  labels.Add( "T1" );
392  labels.Add( "T3" );
393 
394  const wxPGChoices& v = prop->Choices();
395  BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() );
396  BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() );
397 
398  for (int i = 0; i < values.GetCount(); ++i )
399  {
400  BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] );
401  }
402 
403  for (int i = 0; i < labels.GetCount(); ++i )
404  {
405  BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] );
406  }
407 }
virtual bool HasChoices() const
Returns true if this PROPERTY has a limited set of possible values.
Definition: property.h:213
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53
virtual const wxPGChoices & Choices() const
Returns a limited set of possible values (e.g.
Definition: property.h:195

References PROPERTY_BASE::Choices(), PROPERTY_BASE::HasChoices(), TEST1, TEST3, and TYPE_HASH.

◆ ENUM_TO_WXANY() [1/2]

ENUM_TO_WXANY ( enum_glob  )

◆ ENUM_TO_WXANY() [2/2]

ENUM_TO_WXANY ( D::enum_class  )

Variable Documentation

◆ _CLASS_A_DESC

struct CLASS_A_DESC _CLASS_A_DESC
static

◆ _CLASS_B_DESC

struct CLASS_B_DESC _CLASS_B_DESC
static

◆ _CLASS_C_DESC

struct CLASS_C_DESC _CLASS_C_DESC
static

◆ _CLASS_D_DESC

struct CLASS_D_DESC _CLASS_D_DESC
static

◆ _CLASS_E_DESC

struct CLASS_E_DESC _CLASS_E_DESC
static

◆ _ENUM_GLOB_DESC

struct ENUM_GLOB_DESC _ENUM_GLOB_DESC
static