diff options
-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()); |