1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/CONCEPT/classTest.h>
///////////////////////////
#include <BALL/CONCEPT/embeddable.h>
#include <BALL/common.h>
using namespace BALL;
///////////////////////////
class A
: public Embeddable
{
public:
BALL_EMBEDDABLE(A, Embeddable)
};
class B
{
public:
};
class C
: public B,
public A
{
public:
BALL_EMBEDDABLE(C, A)
};
START_TEST(Embeddable)
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
// avoid nasty error messages when
// testing multiple registrateion/deregistration
Log.remove(std::cout);
CHECK(~Embeddable() throw())
A* a_ptr = new A;
TEST_NOT_EQUAL(a_ptr, 0)
delete a_ptr;
RESULT
CHECK(Embeddable(const Embeddable& embeddable) throw())
// ???
RESULT
CHECK(Embeddable(const String& identifier = "<Embeddable>") throw())
// ???
RESULT
CHECK(void setIdentifier(const String& identifier) throw())
// ???
RESULT
CHECK(const String& getIdentifier() const throw())
// ???
RESULT
CHECK([EXTRA] Size countInstances() throw())
TEST_EQUAL(A::countInstances(), 0)
TEST_EQUAL(C::countInstances(), 0)
RESULT
A* a_ptr = 0;
C* c_ptr = 0;
CHECK(void registerThis() throw())
a_ptr = new A;
TEST_EQUAL(A::countInstances(), 0)
TEST_EQUAL(C::countInstances(), 0)
a_ptr->registerThis();
TEST_EQUAL(A::countInstances(), 1)
TEST_EQUAL(C::countInstances(), 0)
a_ptr->registerThis();
TEST_EQUAL(A::countInstances(), 1)
TEST_EQUAL(C::countInstances(), 0)
a_ptr->registerThis();
TEST_EQUAL(A::countInstances(), 1)
TEST_EQUAL(C::countInstances(), 0)
c_ptr = new C;
TEST_EQUAL(A::countInstances(), 1)
TEST_EQUAL(C::countInstances(), 0)
c_ptr->registerThis();
TEST_EQUAL(A::countInstances(), 2)
TEST_EQUAL(C::countInstances(), 1)
c_ptr->registerThis();
TEST_EQUAL(A::countInstances(), 2)
TEST_EQUAL(C::countInstances(), 1)
c_ptr->registerThis();
TEST_EQUAL(A::countInstances(), 2)
TEST_EQUAL(C::countInstances(), 1)
RESULT
CHECK(void unregisterThis() throw())
TEST_EQUAL(A::countInstances(), 2)
TEST_EQUAL(C::countInstances(), 1)
a_ptr->unregisterThis();
TEST_EQUAL(A::countInstances(), 1)
TEST_EQUAL(C::countInstances(), 1)
a_ptr->unregisterThis();
TEST_EQUAL(A::countInstances(), 1)
TEST_EQUAL(C::countInstances(), 1)
delete a_ptr;
TEST_EQUAL(A::countInstances(), 1)
TEST_EQUAL(C::countInstances(), 1)
delete c_ptr;
TEST_EQUAL(A::countInstances(), 0)
TEST_EQUAL(C::countInstances(), 0)
RESULT
CHECK([EXTRA] getInstance(Position index))
A a1;
A a2;
A a3;
a3.registerThis();
a2.registerThis();
a1.registerThis();
TEST_EQUAL(A::countInstances(), 3)
TEST_EQUAL(A::getInstance(0), &a3)
TEST_EQUAL(A::getInstance(1), &a2)
TEST_EQUAL(A::getInstance(2), &a1)
TEST_EQUAL(A::getInstance(3), 0)
TEST_EQUAL(A::getInstance(1234), 0)
RESULT
CHECK([EXTRA] getInstance(const String& identifier))
A a1;
a1.setIdentifier(String("One"));
A a2;
a2.setIdentifier(String("Two"));
A a3;
a3.setIdentifier(String("Three"));
a3.registerThis();
a2.registerThis();
a1.registerThis();
STATUS(" &a1 = " << &a1)
STATUS(" &a2 = " << &a2)
STATUS(" &a3 = " << &a3)
TEST_EQUAL(A::countInstances(), 3)
TEST_EQUAL(A::getInstance("Three"), &a3)
TEST_EQUAL(A::getInstance("Two"), &a2)
TEST_EQUAL(A::getInstance("One"), &a1)
TEST_EQUAL(A::getInstance("Four"), 0)
RESULT
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|