test_tb_object.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #include "tb_test.h"
  6. #include "tb_object.h"
  7. #ifdef TB_UNIT_TESTING
  8. using namespace tb;
  9. TB_TEST_GROUP(tb_object)
  10. {
  11. class Car : public TBTypedObject
  12. {
  13. public:
  14. TBOBJECT_SUBCLASS(Car, TBTypedObject);
  15. };
  16. class Fruit : public TBTypedObject
  17. {
  18. public:
  19. TBOBJECT_SUBCLASS(Fruit, TBTypedObject);
  20. };
  21. class Apple : public Fruit
  22. {
  23. public:
  24. TBOBJECT_SUBCLASS(Apple, Fruit);
  25. };
  26. TB_TEST(safe_cast)
  27. {
  28. Fruit fruit;
  29. Apple apple;
  30. Car car;
  31. TB_VERIFY(TBSafeCast<TBTypedObject>(&fruit));
  32. TB_VERIFY(TBSafeCast<TBTypedObject>(&apple));
  33. TB_VERIFY(TBSafeCast<TBTypedObject>(&car));
  34. TB_VERIFY(TBSafeCast<Fruit>(&fruit));
  35. TB_VERIFY(TBSafeCast<Fruit>(&apple));
  36. TB_VERIFY(!TBSafeCast<Fruit>(&car));
  37. TB_VERIFY(!TBSafeCast<Apple>(&fruit));
  38. TB_VERIFY(TBSafeCast<Apple>(&apple));
  39. TB_VERIFY(!TBSafeCast<Apple>(&car));
  40. TB_VERIFY(!TBSafeCast<Car>(&fruit));
  41. TB_VERIFY(!TBSafeCast<Car>(&apple));
  42. TB_VERIFY(TBSafeCast<Car>(&car));
  43. }
  44. }
  45. #endif // TB_UNIT_TESTING