diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-03-22 17:34:13 +0100 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-03-26 13:05:02 +0100 |
commit | 9a87cb5347a888a104cab47c17f05f1f0aa7a133 (patch) | |
tree | 4c247ab28ab0d067a55f90fde1061ad88d05a90f /tests | |
parent | 883dee678eca4f55faf3848a248253d4b4b8a40e (diff) |
Use function binding generator from QtConcurrent.
* Copy tools/codegenerator and tools/generatebuild from QtConcurrent
and adapt for Coroutines. This allows coroutines from various callables
to be created with a call to build(...).
* Add initial tests.
* Fix incorrect use of QThreadStorage.
* Fix severe typo in Coroutine::yieldHelper.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 2 | ||||
-rw-r--r-- | tests/auto/basic/basic.pro | 3 | ||||
-rw-r--r-- | tests/auto/basic/tst_basic.cpp | 37 | ||||
-rw-r--r-- | tests/auto/build/build.pro | 3 | ||||
-rw-r--r-- | tests/auto/build/tst_build.cpp | 58 | ||||
-rw-r--r-- | tests/tests.pro | 2 |
6 files changed, 105 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 0000000..675ee12 --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = basic build diff --git a/tests/auto/basic/basic.pro b/tests/auto/basic/basic.pro new file mode 100644 index 0000000..c0d2002 --- /dev/null +++ b/tests/auto/basic/basic.pro @@ -0,0 +1,3 @@ +QT += testlib +SOURCES += tst_basic.cpp +include(../../../use_coroutine.pri) diff --git a/tests/auto/basic/tst_basic.cpp b/tests/auto/basic/tst_basic.cpp new file mode 100644 index 0000000..c33ef40 --- /dev/null +++ b/tests/auto/basic/tst_basic.cpp @@ -0,0 +1,37 @@ +#include <QtTest/QtTest> +#include <coroutine.h> + +class tst_basic : public QObject +{ +Q_OBJECT + +private slots: + void noYield(); +}; + +class NoYieldCoro : public Coroutine +{ +public: + virtual void run() + { + i++; + QCOMPARE(status(), Running); + QCOMPARE(currentCoroutine(), this); + } + + int i; +}; + +void tst_basic::noYield() +{ + NoYieldCoro coro; + coro.i = 0; + QCOMPARE(coro.status(), Coroutine::NotStarted); + QCOMPARE(coro.cont(), false); + QCOMPARE(coro.i, 1); + QCOMPARE(coro.status(), Coroutine::Terminated); + Q_ASSERT(Coroutine::currentCoroutine() != &coro); +} + +QTEST_MAIN(tst_basic) +#include "tst_basic.moc" diff --git a/tests/auto/build/build.pro b/tests/auto/build/build.pro new file mode 100644 index 0000000..9b60fc4 --- /dev/null +++ b/tests/auto/build/build.pro @@ -0,0 +1,3 @@ +QT += testlib +SOURCES += tst_build.cpp +include(../../../use_coroutine.pri) diff --git a/tests/auto/build/tst_build.cpp b/tests/auto/build/tst_build.cpp new file mode 100644 index 0000000..c557d34 --- /dev/null +++ b/tests/auto/build/tst_build.cpp @@ -0,0 +1,58 @@ +#include <QtTest/QtTest> +#include <coroutine.h> +#include <coroutinebuild.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 = 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 = 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" diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..7fbc8a9 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = auto |