diff options
author | Nao Pross <naopross@thearcway.org> | 2019-01-23 15:06:02 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-01-23 15:06:02 +0100 |
commit | 3c9184a2e3eb3583dfd2d6ff1ed60903aac9ba78 (patch) | |
tree | 817bd4de9c9f38861609674e19a39885d3ea0340 /test | |
parent | Use custom comparison for core::prioritize (instead of std::less) (diff) | |
download | flatland-3c9184a2e3eb3583dfd2d6ff1ed60903aac9ba78.tar.gz flatland-3c9184a2e3eb3583dfd2d6ff1ed60903aac9ba78.zip |
Make job hold RAII pointers that can expire, update test
Note: does not work, idk why
Diffstat (limited to 'test')
-rw-r--r-- | test/task_test.cpp | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/test/task_test.cpp b/test/task_test.cpp index 074eb94..199d510 100644 --- a/test/task_test.cpp +++ b/test/task_test.cpp @@ -1,39 +1,74 @@ -#include "task.hpp" +#include "core/task.hpp" #include <functional> #include <iostream> -struct hello_class { - const std::string motd = "hello world!"; +// test class +struct message { + std::string motd = "today we have no motd!"; + std::string date = "1 Jan 1970"; + + void print_date() { + std::cout << date << std::endl; + } void print_motd() { std::cout << motd << std::endl; } }; - +// test functions void hello() { std::cout << "hello!" << std::endl; } +void ciao() { + std::cout << "ciao!" << std::endl; +} + + int main(int argc, char *argv[]) { using namespace flat::core; - job job; + + std::cout << "Testing functions" << std::endl; + std::cout << "should print once: hello!" << std::endl; + + job f_job; // test a function - task t_func(hello); - job.add_task(t_func); + auto ciao_fn_task = f_job.make_task(hello); + + // test a function ad make the pointer go out of scope + { + auto hello_fn_task = f_job.make_task(ciao); + } + + f_job.invoke_tasks(); - // test a member function - hello_class h; - task t_mem([&](){ h.print_motd(); }); - job.add_task(t_mem); + std::cout << std::endl; + std::cout << "Testing methods" << std::endl; + std::cout << " should print once: today we have no motd!" << std::endl; + job m_job; + + // test a method + message m; + m_job.make_task(std::bind(&message::print_motd, m)); + + // test a method of an object that goes out of scope + { + message out; + m_job.make_task(std::bind(&message::print_date, out)); + } // invoke tasks - job.invoke_tasks(); + // should print: + // + // hello! + // hello world! + m_job.invoke_tasks(); return 0; } |