KiCad PCB EDA Suite
test_property.cpp File Reference
#include <qa_utils/wx_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)
Definition: property.h:59

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 
311  D item ;
312  wxString str;
313 
314  item.setGlobEnum( static_cast<enum_glob>( -1 ) );
315  wxAny any = item.Get( prop );
316  BOOST_CHECK_EQUAL( any.GetAs<wxString>( &str ), false );
317 
319  any = item.Get( prop );
320  BOOST_CHECK_EQUAL( any.GetAs<wxString>( &str ), true );
321 }
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:216
#define TYPE_HASH(x)
Definition: property.h:59
BOOST_CHECK(v2.Cross(v1)==1)
wxAny Get(PROPERTY_BASE *aProperty)
Definition: inspectable.h:86
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition: property.h:198
void setGlobEnum(enum_glob val)

References BOOST_CHECK(), PROPERTY_BASE::Choices(), INSPECTABLE::Get(), PROPERTY_BASE::HasChoices(), D::setGlobEnum(), TEST1, TEST2, TEST3, and TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [8/12]

BOOST_AUTO_TEST_CASE ( EnumClass  )

Definition at line 323 of file test_property.cpp.

324 {
325  PROPERTY_BASE* prop = propMgr.GetProperty( TYPE_HASH( D ), "enumClass" );
326  BOOST_CHECK( prop->HasChoices() );
327 
328  wxArrayInt values;
329  values.Add( D::enum_class::TESTA );
330  values.Add( D::enum_class::TESTB );
331  values.Add( D::enum_class::TESTC );
332  wxArrayString labels;
333  labels.Add( "TESTA" );
334  labels.Add( "TESTB" );
335  labels.Add( "TESTC" );
336 
337  const wxPGChoices& v = prop->Choices();
338  BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() );
339  BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() );
340 
341  for (int i = 0; i < values.GetCount(); ++i )
342  {
343  BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] );
344  }
345 
346  for (int i = 0; i < labels.GetCount(); ++i )
347  {
348  BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] );
349  }
350 }
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:216
#define TYPE_HASH(x)
Definition: property.h:59
BOOST_CHECK(v2.Cross(v1)==1)
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition: property.h:198

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

◆ BOOST_AUTO_TEST_CASE() [9/12]

BOOST_AUTO_TEST_CASE ( Availability  )

Definition at line 353 of file test_property.cpp.

354 {
355  PROPERTY_BASE* propCond = propMgr.GetProperty( TYPE_HASH( D ), "cond" );
356  ptr = &d;
357 
358  // "cond" property is available only when "a" field is greater than 50
359  d.setA( 0 );
360  BOOST_CHECK( !propCond->Available( ptr ) );
361 
362  d.setA( 100 );
363  BOOST_CHECK( propCond->Available( ptr ) );
364 }
#define TYPE_HASH(x)
Definition: property.h:59
BOOST_CHECK(v2.Cross(v1)==1)
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
Definition: property.h:224

References PROPERTY_BASE::Available(), BOOST_CHECK(), and TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [10/12]

BOOST_AUTO_TEST_CASE ( Alias  )

Definition at line 367 of file test_property.cpp.

368 {
369  ptr = &d;
370 
371  ptr->Set( "point", wxPoint( 100, 100 ) );
372  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point" ), wxPoint( 100, 100 ) );
373  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point_alias" ), wxPoint( 100, 100 ) );
374 
375  ptr->Set( "point_alias", wxPoint( 300, 300 ) );
376  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point" ), wxPoint( 300, 300 ) );
377  BOOST_CHECK_EQUAL( *ptr->Get<wxPoint>( "point_alias" ), wxPoint( 300, 300 ) );
378 }

◆ BOOST_AUTO_TEST_CASE() [11/12]

BOOST_AUTO_TEST_CASE ( Rename  )

Definition at line 381 of file test_property.cpp.

382 {
383  PROPERTY_BASE* prop;
384 
385  prop = propMgr.GetProperty( TYPE_HASH( D ), "bool" );
386  BOOST_CHECK_EQUAL( prop, nullptr );
387 
388  prop = propMgr.GetProperty( TYPE_HASH( D ), "replaced_bool" );
389  BOOST_CHECK( prop );
390 }
#define TYPE_HASH(x)
Definition: property.h:59
BOOST_CHECK(v2.Cross(v1)==1)

References BOOST_CHECK(), and TYPE_HASH.

◆ BOOST_AUTO_TEST_CASE() [12/12]

BOOST_AUTO_TEST_CASE ( AlternativeEnum  )

Definition at line 393 of file test_property.cpp.

394 {
395  PROPERTY_BASE* prop = propMgr.GetProperty( TYPE_HASH( E ), "enumGlob" );
396  BOOST_CHECK( prop->HasChoices() );
397 
398  wxArrayInt values;
399  values.Add( enum_glob::TEST1 );
400  values.Add( enum_glob::TEST3 );
401  wxArrayString labels;
402  labels.Add( "T1" );
403  labels.Add( "T3" );
404 
405  const wxPGChoices& v = prop->Choices();
406  BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() );
407  BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() );
408 
409  for (int i = 0; i < values.GetCount(); ++i )
410  {
411  BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] );
412  }
413 
414  for (int i = 0; i < labels.GetCount(); ++i )
415  {
416  BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] );
417  }
418 }
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:216
#define TYPE_HASH(x)
Definition: property.h:59
BOOST_CHECK(v2.Cross(v1)==1)
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition: property.h:198

References BOOST_CHECK(), 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