-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
125 lines (100 loc) · 2.24 KB
/
test.cpp
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
#include <carefree-objects.hpp>
#include <carefree-types.hpp>
class base
{
public:
const std::string name;
inline base(const std::string &name = "base") :
name(name)
{}
virtual void _()
{}
cfo_MANAGED_BASIC_CONST_METHODS
(base,
public:
inline const std::string& name() const
{
return (*this)->name;
})
cfo_MANAGED_BASIC_METHODS(base, )
};
class object : public base
{
public:
inline object(const std::string &name = "object") :
base(name)
{
if (name == "error")
throw std::invalid_argument(name);
}
cfo_MANAGED_CONST_METHODS(object, base, )
cfo_MANAGED_METHODS(object, base, )
};
typedef cfo::managed<base, false> Base;
typedef cfo::managed<object, false> Object;
int main(int, char**)
{
cfo::character::_test();
cfo::ip::v6::address::_test();
{
Base b;
assert(!b.error_());
assert(b.name() == "base");
assert(b.is(b));
assert(b.is_<Base>());
assert(b.is_managed<base>());
assert(!b.is_<Object>());
assert(!b.is_managed<object>());
}
{
Base b("name");
assert(!b.error_());
assert(b.name() == "name");
assert(b.is(b));
assert(b.is_<Base>());
assert(b.is_managed<base>());
assert(!b.is_<Object>());
assert(!b.is_managed<object>());
}
{
Object obj("bla");
assert(!obj.error_());
assert(obj.name() == "bla");
assert(obj.is(obj));
assert(obj.is_<Object>());
assert(obj.is_managed<object>());
assert(obj.is_<Base>());
assert(obj.is_managed<base>());
Base b = obj;
assert(!b.error_());
assert(obj.is(b));
assert(b.name() == "bla");
assert(b.is(b));
assert(b.is(obj));
assert(b.is_<Base>());
assert(b.is_managed<base>());
assert(b.is_<Object>());
assert(b.is_managed<object>());
}
{
Object obj("error");
assert(obj.error_());
assert(obj.error_().what() == "error");
assert(obj.error_().is_<std::invalid_argument>());
assert(obj.error_().type() == typeid(std::invalid_argument));
}
{
bool thrown = false;
try
{
Object::except obj("error");
}
catch (const std::invalid_argument &e)
{
thrown = true;
assert(e.what() == std::string("error"));
}
assert(thrown);
}
return 0;
}