summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2012-09-01 10:04:05 -0700
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2012-09-01 10:27:52 -0700
commit4a893f72cadaa875a920db8949171b002f656e43 (patch)
tree1e08a3cb6f579cab9c3c9a138d36ababdf76121b /tests
parent56d91ddd2cd42b782cde0bb3fdf4eb9ebe7597be (diff)
parent06674e57649d536cf19715524ee40c5ad4a9026d (diff)
Merge commit '06674e57649d536cf19715524ee40c5ad4a9026d'
Conflicts: includes/LuaTask.h includes/TaskMan.h includes/Threads.h src/TaskMan.cc src/Threads.cc
Diffstat (limited to 'tests')
-rw-r--r--tests/test-Async.cc56
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.");
+}