summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-03-23 13:06:46 +0100
committerChristian Kamm <christian.d.kamm@nokia.com>2010-03-26 13:05:03 +0100
commit1e8ffb1124c339c89b9d460209e1d887524df455 (patch)
tree9cebed90a626cd01aa520e5ac3d081176393ba1a
parent5548690f4a9f45c2d276bf36cfa8ca325a71dfc0 (diff)
Add tests for stack reusing.
-rw-r--r--tests/auto/basic/tst_basic.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/basic/tst_basic.cpp b/tests/auto/basic/tst_basic.cpp
index bbc9977..d4c6e46 100644
--- a/tests/auto/basic/tst_basic.cpp
+++ b/tests/auto/basic/tst_basic.cpp
@@ -8,6 +8,8 @@ Q_OBJECT
private slots:
void noYield();
void coroutineStartingCoroutine();
+ void smallStack();
+ void reuseStack();
};
class NoYieldCoro : public Coroutine
@@ -113,6 +115,61 @@ void tst_basic::coroutineStartingCoroutine()
QCOMPARE(base->status(), Coroutine::Terminated);
QCOMPARE(c1->status(), Coroutine::Terminated);
QCOMPARE(Coroutine::currentCoroutine(), start);
+
+ delete c1;
+ delete base;
+}
+
+namespace StackTests {
+ static int counter = 0;
+ static void simpleCoroutine()
+ {
+ while(true) {
+ counter++;
+ Coroutine::yield();
+ }
+ }
+}
+
+void tst_basic::smallStack()
+{
+ using namespace StackTests;
+
+ Coroutine *c = Coroutine::build(&simpleCoroutine);
+ c->createStack(1000);
+ counter = 0;
+ QCOMPARE(c->cont(), true);
+ QCOMPARE(counter, 1);
+ QCOMPARE(c->cont(), true);
+ QCOMPARE(counter, 2);
+ delete c;
+}
+
+void tst_basic::reuseStack()
+{
+ using namespace StackTests;
+
+ char* p = new char[10000];
+
+ Coroutine *c1 = Coroutine::build(&simpleCoroutine);
+ c1->setStack(p, 10000);
+ counter = 0;
+ QCOMPARE(c1->cont(), true);
+ QCOMPARE(counter, 1);
+ QCOMPARE(c1->cont(), true);
+ QCOMPARE(counter, 2);
+ delete c1;
+
+ Coroutine *c2 = Coroutine::build(&simpleCoroutine);
+ c2->setStack(p, 10000);
+ counter = 0;
+ QCOMPARE(c2->cont(), true);
+ QCOMPARE(counter, 1);
+ QCOMPARE(c2->cont(), true);
+ QCOMPARE(counter, 2);
+ delete c2;
+
+ delete [] p;
}
QTEST_MAIN(tst_basic)