This repository was archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.cpp
193 lines (180 loc) · 4.91 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "stdafx.h"
#include "main.h"
#include "test.h"
#include <Stamina\ObjectImpl.h>
class TestClassObj: public Stamina::SharedObject<Stamina::iSharedObject> {
public:
typedef Stamina::SharedObject<Stamina::iSharedObject> parent_type;
TestClassObj(const CStdString & id) {
this->id = id;
IMDEBUG(DBG_TEST, "%s::ctor", id.c_str());
counter++;
}
~TestClassObj() {
IMDEBUG(DBG_TEST, "%s::dtor", id.c_str());
counter--;
}
bool __stdcall hold() {
IMDEBUG(DBG_TEST, "%s::hold", id.c_str());
return parent_type::hold();
}
void __stdcall release() {
IMDEBUG(DBG_TEST, "%s::release", id.c_str());
parent_type::release();
}
void __stdcall destroy() {
IMDEBUG(DBG_TEST, "%s::destroy", id.c_str());
parent_type::destroy();
}
CStdString id;
static int counter;
};
int TestClassObj::counter = 0;
class TestClassObj2: public TestClassObj {
public:
TestClassObj2(const CStdString & id):TestClassObj(id) {
}
void __stdcall destroy() {
{
IMDEBUG(DBG_TEST_TITLE, "%s::destroy_rec.test", id.c_str());
Stamina::SharedPtr<TestClassObj2> test2(*this);
testResult(0, test2->getUseCount());
Stamina::SharedPtr<TestClassObj2> test3;
test3 = test2;
testResult(0, test2->getUseCount());
}
TestClassObj::destroy();
}
};
/*class TestClass: public KObject<TestClassObj> {
};*/
unsigned int __stdcall makeCrash(void* p) {
char * crash = 0;
crash[0] = 0;
return 0;
}
unsigned int __stdcall makeCrashThrow(void* p) {
throw "Crash";
return 0;
}
class PureVirtualTest {
public:
virtual ~PureVirtualTest() {
this->test();
}
void test() {
this->pure();
}
virtual void pure() = 0;
};
class PureVirtualTest2:public PureVirtualTest {
public:
void pure() {}
};
unsigned int __stdcall makePureVirtualCall(void*pa) {
PureVirtualTest* p = new PureVirtualTest2();
delete p;
return 0;
}
void Konnekt::command_test(sIMessage_debugCommand * arg) {
#ifdef __TEST
if (arg->argc < 2) {
IMDEBUG(DBG_COMMAND, "- Dostêpne testy:");
IMDEBUG(DBG_COMMAND, " object");
} else {
if (arg->argEq(1, "crash")) {
if (arg->argEq(2, "thread")) {
Ctrl->BeginThread("Crashtest", 0, 0, makeCrash);
} else if (arg->argEq(2, "threadThrow")) {
Ctrl->BeginThread("Crashtest", 0, 0, makeCrashThrow);
} else if (arg->argEq(2, "throw")) {
makeCrashThrow(0);
} else if (arg->argEq(2, "threadVirtual")) {
Ctrl->BeginThread("Crashtest", 0, 0, makePureVirtualCall);
} else if (arg->argEq(2, "virtual")) {
makePureVirtualCall(0);
} else {
makeCrash(0);
}
} else if (arg->argEq(1, "object")) {
IMDEBUG(DBG_TEST_TITLE, "- Konnekt::KObject {{{");
typedef Stamina::SharedPtr<TestClassObj> TestClass;
IMDEBUG(DBG_TEST_TITLE, "Create - Delete");
{
TestClass t1 (new TestClassObj("o1"));
}
IMDEBUG(DBG_TEST_TITLE, "Create empty - set - Delete");
{
TestClass t1;
t1 = new TestClassObj("o2");
}
IMDEBUG(DBG_TEST_TITLE, "Create - copy - Delete");
{
TestClass t1 (new TestClassObj("o3"));
{
IMDEBUG(DBG_TEST, "copy");
TestClass t2 (t1);
}
testResult(2, t1->getUseCount());
}
IMDEBUG(DBG_TEST_TITLE, "Create x2 - Delete");
{
TestClass t1 (TestClass(new TestClassObj("o4")));
}
IMDEBUG(DBG_TEST_TITLE, "Create1 - Create2 - Delete1 Delete2");
{
TestClass * t1 = new TestClass(new TestClassObj("o5"));
IMDEBUG(DBG_TEST, "Create2");
TestClass * t2 = new TestClass(*t1);
IMDEBUG(DBG_TEST, "Delete1");
delete t1;
testResult(2, (*t2)->getUseCount());
IMDEBUG(DBG_TEST, "Delete2");
delete t2;
}
IMDEBUG(DBG_TEST_TITLE, "Create - hold - copy - release");
{
TestClassObj * o = new TestClassObj("o6");
o->hold();
{
IMDEBUG(DBG_TEST, "set");
TestClass t1(o);
testResult(3, o->getUseCount());
}
testResult(2, o->getUseCount());
o->release();
}
IMDEBUG(DBG_TEST_TITLE, "Createx2 - swap");
{
TestClass t1 (new TestClassObj("o7-1"));
t1.set(new TestClassObj("o7-2"));
}
IMDEBUG(DBG_TEST_TITLE, "Createx2 - copy - swap");
{
TestClass t1 (new TestClassObj("o7-1"));
{
TestClass t2 (t1);
t1.set(new TestClassObj("o7-2"));
}
}
IMDEBUG(DBG_TEST_TITLE, "Create - reset");
{
TestClass t1 (new TestClassObj("o7-1"));
t1.set(0);
}
IMDEBUG(DBG_TEST_TITLE, "Create - Delete - instance");
{
Stamina::SharedPtr<TestClassObj2> t1(new TestClassObj2("o8"));
}
IMDEBUG(DBG_TEST_TITLE, "Create - copy - (Delete - instance)");
{
Stamina::SharedPtr<TestClassObj2> t1(new TestClassObj2("o9-1"));
IMDEBUG(DBG_TEST, "ustawia nowy obiekt");
t1 = new TestClassObj2("o9-1");
}
testResult("Wyciek³o obiektów:", 0, TestClassObj::counter);
IMDEBUG(DBG_TEST_TITLE, "- Konnekt::KObject }}}");
}
}
#endif
}