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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
#include <QtTest/QtTest>
#include <TelepathyQt/Callbacks>
using namespace Tp;
class TestCallbacks : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testMemFun();
void testPtrFun();
};
struct MyCallbacks
{
MyCallbacks()
{
reset();
}
void testVV() { mVVCalled = true; }
void testVI1(int a1)
{
QCOMPARE(a1, 1);
mVI1Called = true;
}
void testVI2(int a1, int a2)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2);
mVI2Called = true;
}
void testVI3(int a1, int a2, int a3)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3);
mVI3Called = true;
}
void testVI4(int a1, int a2, int a3, int a4)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4);
mVI4Called = true;
}
void testVI5(int a1, int a2, int a3, int a4, int a5)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4); QCOMPARE(a5, 5);
mVI5Called = true;
}
void testVI6(int a1, int a2, int a3, int a4, int a5, int a6)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4); QCOMPARE(a5, 5); QCOMPARE(a6, 6);
mVI6Called = true;
}
void testVI7(int a1, int a2, int a3, int a4, int a5, int a6, int a7)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4); QCOMPARE(a5, 5); QCOMPARE(a6, 6); QCOMPARE(a7, 7);
mVI7Called = true;
}
void reset()
{
mVVCalled = false;
mVI1Called = false;
mVI2Called = false;
mVI3Called = false;
mVI4Called = false;
mVI5Called = false;
mVI6Called = false;
mVI7Called = false;
}
void verifyCalled(bool vv, bool vi1, bool vi2, bool vi3,
bool vi4, bool vi5, bool vi6, bool vi7)
{
QCOMPARE(mVVCalled, vv);
QCOMPARE(mVI1Called, vi1);
QCOMPARE(mVI2Called, vi2);
QCOMPARE(mVI3Called, vi3);
QCOMPARE(mVI4Called, vi4);
QCOMPARE(mVI5Called, vi5);
QCOMPARE(mVI6Called, vi6);
QCOMPARE(mVI7Called, vi7);
}
bool mVVCalled;
bool mVI1Called;
bool mVI2Called;
bool mVI3Called;
bool mVI4Called;
bool mVI5Called;
bool mVI6Called;
bool mVI7Called;
};
namespace
{
bool mVVCalled;
bool mVI1Called;
bool mVI2Called;
bool mVI3Called;
bool mVI4Called;
bool mVI5Called;
bool mVI6Called;
bool mVI7Called;
void testVV() { mVVCalled = true; }
void testVI1(int a1)
{
QCOMPARE(a1, 1);
mVI1Called = true;
}
void testVI2(int a1, int a2)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2);
mVI2Called = true;
}
void testVI3(int a1, int a2, int a3)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3);
mVI3Called = true;
}
void testVI4(int a1, int a2, int a3, int a4)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4);
mVI4Called = true;
}
void testVI5(int a1, int a2, int a3, int a4, int a5)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4); QCOMPARE(a5, 5);
mVI5Called = true;
}
void testVI6(int a1, int a2, int a3, int a4, int a5, int a6)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4); QCOMPARE(a5, 5); QCOMPARE(a6, 6);
mVI6Called = true;
}
void testVI7(int a1, int a2, int a3, int a4, int a5, int a6, int a7)
{
QCOMPARE(a1, 1); QCOMPARE(a2, 2); QCOMPARE(a3, 3); QCOMPARE(a4, 4); QCOMPARE(a5, 5); QCOMPARE(a6, 6); QCOMPARE(a7, 7);
mVI7Called = true;
}
void reset()
{
mVVCalled = false;
mVI1Called = false;
mVI2Called = false;
mVI3Called = false;
mVI4Called = false;
mVI5Called = false;
mVI6Called = false;
mVI7Called = false;
}
void verifyCalled(bool vv, bool vi1, bool vi2, bool vi3,
bool vi4, bool vi5, bool vi6, bool vi7)
{
QCOMPARE(mVVCalled, vv);
QCOMPARE(mVI1Called, vi1);
QCOMPARE(mVI2Called, vi2);
QCOMPARE(mVI3Called, vi3);
QCOMPARE(mVI4Called, vi4);
QCOMPARE(mVI5Called, vi5);
QCOMPARE(mVI6Called, vi6);
QCOMPARE(mVI7Called, vi7);
}
}
void TestCallbacks::testMemFun()
{
MyCallbacks cbs;
Callback0<void> cbVV = memFun(&cbs, &MyCallbacks::testVV);
cbVV();
cbs.verifyCalled(true, false, false, false, false, false, false, false);
cbs.reset();
Callback1<void, int> cbVI1 = memFun(&cbs, &MyCallbacks::testVI1);
cbVI1(1);
cbs.verifyCalled(false, true, false, false, false, false, false, false);
cbs.reset();
Callback2<void, int, int> cbVI2 = memFun(&cbs, &MyCallbacks::testVI2);
cbVI2(1, 2);
cbs.verifyCalled(false, false, true, false, false, false, false, false);
cbs.reset();
Callback3<void, int, int, int> cbVI3 = memFun(&cbs, &MyCallbacks::testVI3);
cbVI3(1, 2, 3);
cbs.verifyCalled(false, false, false, true, false, false, false, false);
cbs.reset();
Callback4<void, int, int, int, int> cbVI4 = memFun(&cbs, &MyCallbacks::testVI4);
cbVI4(1, 2, 3, 4);
cbs.verifyCalled(false, false, false, false, true, false, false, false);
cbs.reset();
Callback5<void, int, int, int, int, int> cbVI5 = memFun(&cbs, &MyCallbacks::testVI5);
cbVI5(1, 2, 3, 4, 5);
cbs.verifyCalled(false, false, false, false, false, true, false, false);
cbs.reset();
Callback6<void, int, int, int, int, int, int> cbVI6 = memFun(&cbs, &MyCallbacks::testVI6);
cbVI6(1, 2, 3, 4, 5, 6);
cbs.verifyCalled(false, false, false, false, false, false, true, false);
cbs.reset();
Callback7<void, int, int, int, int, int, int, int> cbVI7 = memFun(&cbs, &MyCallbacks::testVI7);
cbVI7(1, 2, 3, 4, 5, 6, 7);
cbs.verifyCalled(false, false, false, false, false, false, false, true);
cbs.reset();
}
void TestCallbacks::testPtrFun()
{
reset();
Callback0<void> cbVV = ptrFun(&testVV);
cbVV();
verifyCalled(true, false, false, false, false, false, false, false);
reset();
Callback1<void, int> cbVI1 = ptrFun(&testVI1);
cbVI1(1);
verifyCalled(false, true, false, false, false, false, false, false);
reset();
Callback2<void, int, int> cbVI2 = ptrFun(&testVI2);
cbVI2(1, 2);
verifyCalled(false, false, true, false, false, false, false, false);
reset();
Callback3<void, int, int, int> cbVI3 = ptrFun(&testVI3);
cbVI3(1, 2, 3);
verifyCalled(false, false, false, true, false, false, false, false);
reset();
Callback4<void, int, int, int, int> cbVI4 = ptrFun(&testVI4);
cbVI4(1, 2, 3, 4);
verifyCalled(false, false, false, false, true, false, false, false);
reset();
Callback5<void, int, int, int, int, int> cbVI5 = ptrFun(&testVI5);
cbVI5(1, 2, 3, 4, 5);
verifyCalled(false, false, false, false, false, true, false, false);
reset();
Callback6<void, int, int, int, int, int, int> cbVI6 = ptrFun(&testVI6);
cbVI6(1, 2, 3, 4, 5, 6);
verifyCalled(false, false, false, false, false, false, true, false);
reset();
Callback7<void, int, int, int, int, int, int, int> cbVI7 = ptrFun(&testVI7);
cbVI7(1, 2, 3, 4, 5, 6, 7);
verifyCalled(false, false, false, false, false, false, false, true);
reset();
}
QTEST_MAIN(TestCallbacks)
#include "_gen/callbacks.cpp.moc.hpp"
|