diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-03-15 11:39:31 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-03-15 11:39:31 +0100 |
commit | 68a6e9658047aa04f16870dbc48ba79a2963a650 (patch) | |
tree | ce8c206d0e2da384362a8dd805881d5bfb250663 /modules/async/tests | |
parent | e69e7b542f9a0aa3101cc5a13e2be30975e6a301 (diff) |
async: Introducing minor tests for immediate conveyors
Diffstat (limited to 'modules/async/tests')
-rw-r--r-- | modules/async/tests/SConscript | 31 | ||||
-rw-r--r-- | modules/async/tests/immediate.cpp | 52 |
2 files changed, 83 insertions, 0 deletions
diff --git a/modules/async/tests/SConscript b/modules/async/tests/SConscript new file mode 100644 index 0000000..f8ffc92 --- /dev/null +++ b/modules/async/tests/SConscript @@ -0,0 +1,31 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +test_cases_env = env.Clone(); + +test_cases_env.Append(LIBS=['forstio-test']); + +test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += test_cases_env.sources; +env.headers += test_cases_env.headers; + +objects_static = [] +test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False); +test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static, env.library_static]); + +# Set Alias +env.Alias('test', test_cases_env.program); +env.Alias('check', test_cases_env.program); + +env.targets += ['test','check']; diff --git a/modules/async/tests/immediate.cpp b/modules/async/tests/immediate.cpp new file mode 100644 index 0000000..a5d9b2f --- /dev/null +++ b/modules/async/tests/immediate.cpp @@ -0,0 +1,52 @@ +#include <forstio/test/suite.hpp> + +#include <forstio/templates.hpp> + +#include "../c++/async.hpp" + +namespace { +SAW_TEST("Immediate Conveyor"){ + using namespace saw; + + event_loop loop; + wait_scope wait{loop}; + + int val = 5; + conveyor<int> immediately_done{val}; + + int passed = 0; + auto res = immediately_done.then([&passed](int a) { + passed = a; + }).sink(); + + wait.poll(); + + SAW_EXPECT(passed == val, "Expected a 5 in passed value."); +} + +SAW_TEST("Immediate Conveyor Queueing"){ + using namespace saw; + + event_loop loop; + wait_scope wait{loop}; + + int val = 5; + conveyor<int> immediately_done{val}; + + int passed = 0; + auto res = immediately_done.then([&passed](int a) { + passed = a; + }).sink([](auto err){ + SAW_EXPECT(false, "No error should occur. This code path shouldn't be reachable."); + return err; + }); + + wait.poll(); + wait.poll(); + wait.poll(); + wait.poll(); + wait.poll(); + + SAW_EXPECT(passed == val, "Expected a 5 in passed value."); +} +} |