asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
task_unit.hpp
1
11#pragma once
12
13#include "../asrtlpp/task.hpp"
14#include "./reactor.hpp"
15
16#include <ecor/ecor.hpp>
17
18namespace asrt
19{
20
21
25{
26 task_test( task_ctx& ctx )
27 : _ctx( ctx )
28 {
29 }
30
31 template < typename T >
32 auto& query( T&& q )
33 {
34 return _ctx.query( (T&&) q );
35 }
36
37private:
38 task_ctx& _ctx;
39};
40
41using ecor::suspend;
42using ecor::with_error;
43
50template < typename T >
52{
53
54 struct recv
55 {
56 using receiver_concept = ecor::receiver_t;
57
58 record* rec;
59
60 void set_value() { rec->state = ASRT_TEST_PASS; }
61 void set_error( ecor::task_error ) { rec->state = ASRT_TEST_FAIL; }
62 void set_error( test_fail_t ) { rec->state = ASRT_TEST_FAIL; }
63 void set_error( asrt::status ) { rec->state = ASRT_TEST_ERROR; }
64 void set_stopped() { rec->state = ASRT_TEST_FAIL; }
65 };
66
67 task_unit( T def )
68 : _def( std::move( def ) )
69 {
70 asrt_test_init( this, _def.name, static_cast< task_unit* >( this ), task_unit::cb );
71 }
72
73 static asrt_status cb( record* rec )
74 {
75 auto& self = *static_cast< task_unit* >( rec->inpt->test_ptr );
76
77 if ( rec->state == ASRT_TEST_INIT ) {
78 rec->state = ASRT_TEST_RUNNING;
79 self._op = self._def.exec().connect( recv{ rec } );
80 self._op.start();
81 }
82
83 return ASRT_SUCCESS;
84 }
85
86private:
87 T _def;
88 // XXX: note that this being here is waste of memory - it is needed only per active test
89 ecor::connect_type< task< void >, recv > _op;
90};
91
92} // namespace asrt
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: callback.hpp:17
Event-loop context that owns a coroutine task scheduler.
Definition: task.hpp:30
Coroutine context object passed to task tests.
Definition: task_unit.hpp:25
Definition: task_unit.hpp:55
Coroutine test adaptor that wraps a definition type T into an asrt_test driven by an ecor coroutine.
Definition: task_unit.hpp:52
Definition: task.hpp:53
Mutable test state passed to the test entry point on every tick.
Definition: record.h:46
struct asrt_test_input const * inpt
Immutable per-invocation context.
Definition: record.h:49
enum asrt_test_state state
Current state; updated by assertions and by the reactor.
Definition: record.h:47
void * test_ptr
Context pointer registered with asrt_test_init().
Definition: record.h:39
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: reactor.h:35