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
|
#include <meowpp/debug/assert.h>
#include <meowpp/utility/object.h>
#include <meowpp/utility/object.h>
#include <meowpp/utility/object.h>
static bool destructor_be_called = false;
class A : public meow::Object {
public:
~A() {
destructor_be_called = true;
}
} _;
class B : public meow::Object {
public:
meow::Object* Copy() const {
return static_cast<meow::Object*>(&_);
}
bool Equals(meow::Object const* b) const {
return false;;
}
meow::Object* CopyFrom(meow::Object const* ptr) {
return const_cast<meow::Object*>(ptr);
}
};
int main() {
meow::Object* ptr = new A, *ptr2 = new B;
delete ptr;
if (!destructor_be_called) {
return 1;
}
ptr = new A;
Assert(ptr->Copy() == NULL, "");
Assert(ptr->Equals(NULL) == false, "");
Assert(ptr->CopyFrom(ptr2) == NULL, "");
ptr = new B;
Assert(ptr->Copy() == &_, "");
Assert(ptr->Equals(NULL) == false, "");
Assert(ptr->CopyFrom(ptr2) == ptr2, "");
////////////////////////////////////////
meow::Int32 a;
Assert(a == 0, "");
Assert(0 == a, "");
Assert(!a, "");
Assert(a || true, "");
Assert(true || a, "");
a = 10;
Assert(a && true, "");
Assert(true && a, "");
Assert(a == 10, "");
Assert(a > 9, "");
Assert(11 > a, "");
Assert((a + 3) == 13, "");
Assert((3 + a) == 13, "");
Assert((a - 3) == 7, "");
Assert((3 - a) == -7, "");
Assert((a * 3) == 30, "");
Assert((3 * a) == 30, "");
Assert((a / 2) == 5, "");
Assert((20 / a) == 2, "");
Assert((~a) == ~10, "");
a += 3;
Assert(a == 13, "");
meow::Double b(a);
Assert(b == 13.0, "");
Assert(b == 13, "");
meow::Double* k = static_cast<meow::Double*>(b.Copy());
Assert((*k) == b, "");
Assert(k->Equals(&b), "");
(*k) = 5;
Assert((*k) == 5, "");
Assert(k->CopyFrom(&b) == k, "");
Assert((*k) == 13, "");
delete k;
return 0;
}
|