summaryrefslogtreecommitdiff
path: root/tests/test-Async.cc
blob: 5f932177ce6defc2267f5d0de62816b132be142f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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.");
}