diff options
author | Pixel <pixel@nobis-crew.org> | 2012-04-08 18:23:22 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2012-04-08 18:23:22 -0700 |
commit | 3d28d1e64d164139a75c2bb19ead725c7bef9c55 (patch) | |
tree | 7b52ba44c8380d87b73ee17c3c5bf6e6c1fca38f /tests | |
parent | 0e9a58842a03ca7e15cf81a9954684d29a025798 (diff) |
Adding a small unit test for Stackless tasks.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-Tasks.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test-Tasks.cc b/tests/test-Tasks.cc index da5346f..5a1955c 100644 --- a/tests/test-Tasks.cc +++ b/tests/test-Tasks.cc @@ -1,6 +1,7 @@ #include <Main.h> #include <Task.h> #include <TaskMan.h> +#include <StacklessTask.h> using namespace Balau; @@ -20,6 +21,33 @@ class TestTask : public Task { } }; +class TestOperation { + public: + TestOperation() : m_count(0), m_completed(false) { } + void Do() { + if (m_count++ == 0) + Task::yield(NULL, true); + m_completed = true; + } + bool completed() { return m_completed; } + private: + int m_count; + bool m_completed; +}; + +class TestStackless : public StacklessTask { + public: + virtual const char * getName() const { return "TestStackless"; } + private: + virtual void Do() { + StacklessBegin(); + m_operation = new TestOperation(); + StacklessOperation(m_operation->Do()); + StacklessEnd(); + } + TestOperation * m_operation; +}; + static void yieldingFunction() { Events::Timeout timeout(0.2); Task::yield(&timeout); @@ -38,6 +66,13 @@ void MainTask::Do() { TAssert(taskEvt.gotSignal()); taskEvt.ack(); + Task * testStackless = TaskMan::registerTask(new TestStackless(), &taskEvt); + waitFor(&taskEvt); + TAssert(!taskEvt.gotSignal()); + yield(); + TAssert(taskEvt.gotSignal()); + taskEvt.ack(); + Events::Timeout timeout(0.1); waitFor(&timeout); TAssert(!timeout.gotSignal()); |