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
|
#include <QtTest/QtTest>
#include <coroutine.h>
class tst_build: public QObject
{
Q_OBJECT
private slots:
void staticFn();
};
static int fnCounter = -99;
static void fnNoArg()
{
fnCounter = 0;
Coroutine::yield();
fnCounter++;
Coroutine::yield();
fnCounter++;
}
static void fnArg(int start)
{
fnCounter = start;
Coroutine::yield();
fnCounter++;
Coroutine::yield();
fnCounter++;
}
void tst_build::staticFn()
{
Coroutine* c1 = Coroutine::build(32000, &fnNoArg);
QCOMPARE(fnCounter, -99);
QCOMPARE(c1->cont(), true);
QCOMPARE(fnCounter, 0);
QCOMPARE(c1->cont(), true);
QCOMPARE(fnCounter, 1);
QCOMPARE(c1->cont(), false);
QCOMPARE(fnCounter, 2);
delete c1;
Coroutine* c2 = Coroutine::build(32000, &fnArg, 40);
QCOMPARE(c2->cont(), true);
QCOMPARE(fnCounter, 40);
QCOMPARE(c2->cont(), true);
QCOMPARE(fnCounter, 41);
QCOMPARE(c2->cont(), false);
QCOMPARE(fnCounter, 42);
delete c2;
}
QTEST_MAIN(tst_build)
#include "tst_build.moc"
|