summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-22 04:31:30 +0100
committerNao Pross <naopross@thearcway.org>2019-01-22 04:31:30 +0100
commite584e04c5f8ffb14e50c701c1fd8178457a51743 (patch)
tree369599a34ae52ade9119d08a19c3fffe2a15b63d
parentUpdate .gitignore, delete test/test (diff)
downloadflatland-e584e04c5f8ffb14e50c701c1fd8178457a51743.tar.gz
flatland-e584e04c5f8ffb14e50c701c1fd8178457a51743.zip
Add test for task and job, fix bug in job
By being a std::set job did not allow to add duplicate elements, changing it to a std::multiset fixed the issue.
-rw-r--r--engine/include/task.hpp4
-rw-r--r--engine/task.cpp1
-rw-r--r--test/task_test.cpp39
3 files changed, 41 insertions, 3 deletions
diff --git a/engine/include/task.hpp b/engine/include/task.hpp
index 8c4f48f..9422a23 100644
--- a/engine/include/task.hpp
+++ b/engine/include/task.hpp
@@ -27,9 +27,9 @@ namespace flat {
std::function<void()> m_callback;
};
- struct job : public std::set<task> {
+ struct job : public std::multiset<task> {
inline void add_task(task t) {
- insert(begin(), t);
+ this->insert(t);
}
void invoke_tasks();
diff --git a/engine/task.cpp b/engine/task.cpp
index 537a6b1..c09fa8b 100644
--- a/engine/task.cpp
+++ b/engine/task.cpp
@@ -1,7 +1,6 @@
#include "task.hpp"
#include <functional>
-#include <set>
namespace flat {
diff --git a/test/task_test.cpp b/test/task_test.cpp
new file mode 100644
index 0000000..074eb94
--- /dev/null
+++ b/test/task_test.cpp
@@ -0,0 +1,39 @@
+#include "task.hpp"
+
+#include <functional>
+#include <iostream>
+
+
+struct hello_class {
+ const std::string motd = "hello world!";
+
+ void print_motd() {
+ std::cout << motd << std::endl;
+ }
+};
+
+
+void hello() {
+ std::cout << "hello!" << std::endl;
+}
+
+int main(int argc, char *argv[]) {
+
+ using namespace flat::core;
+
+ job job;
+
+ // test a function
+ task t_func(hello);
+ job.add_task(t_func);
+
+ // test a member function
+ hello_class h;
+ task t_mem([&](){ h.print_motd(); });
+ job.add_task(t_mem);
+
+ // invoke tasks
+ job.invoke_tasks();
+
+ return 0;
+}