diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2012-09-01 00:12:35 -0700 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2012-09-01 00:12:35 -0700 |
commit | 06674e57649d536cf19715524ee40c5ad4a9026d (patch) | |
tree | d519fc72a6e3946150cc5ee21ed01cb73e82747b /tests | |
parent | d2db92f6b5d275b3150deb7a52a8da142a7cc953 (diff) |
Adding async operations; first step towards tossing libeio out.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-Async.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test-Async.cc b/tests/test-Async.cc new file mode 100644 index 0000000..5f93217 --- /dev/null +++ b/tests/test-Async.cc @@ -0,0 +1,56 @@ +#include <Async.h> +#include <Task.h> +#include <TaskMan.h> +#include <Main.h> + +using namespace Balau; + +class AsyncOpTest : public AsyncOperation { + public: + AsyncOpTest(Events::Custom * evt) : m_evt(evt) { } + virtual void run() { + Printer::log(M_STATUS, "Async operation running"); + TAssert(!m_ran); + TAssert(!m_finished); + TAssert(!m_done); + m_ran = true; + } + virtual void finish() { + Printer::log(M_STATUS, "Async operation finishing"); + TAssert(m_ran); + TAssert(!m_finished); + TAssert(!m_done); + m_finished = true; + } + virtual void done() { + Printer::log(M_STATUS, "Async operation done"); + TAssert(m_ran); + TAssert(m_finished); + TAssert(!m_done); + m_done = true; + m_evt->doSignal(); + } + virtual bool needsFinishWorker() { return true; } + + bool m_ran = false; + bool m_finished = false; + bool m_done = false; + Events::Custom * m_evt; +}; + +void MainTask::Do() { + Printer::log(M_STATUS, "Test::Async running."); + + Events::Custom evt; + AsyncOpTest * op = createAsyncOp(new AsyncOpTest(&evt)); + waitFor(&evt); + TAssert(!evt.gotSignal()); + yield(); + TAssert(evt.gotSignal()); + TAssert(op->m_ran); + TAssert(op->m_finished); + TAssert(op->m_done); + delete op; + + Printer::log(M_STATUS, "Test::Async passed."); +} |