summaryrefslogtreecommitdiff
path: root/modules/core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/tests')
-rw-r--r--modules/core/tests/SConscript29
-rw-r--r--modules/core/tests/core.cpp67
-rw-r--r--modules/core/tests/tree.cpp24
3 files changed, 120 insertions, 0 deletions
diff --git a/modules/core/tests/SConscript b/modules/core/tests/SConscript
new file mode 100644
index 0000000..cec3132
--- /dev/null
+++ b/modules/core/tests/SConscript
@@ -0,0 +1,29 @@
+#!/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.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+test_cases_env.headers = sorted(glob.glob(dir_path + "/*.h"))
+
+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, env.test_library]);
+
+# Set Alias
+env.Alias('test', test_cases_env.program);
+env.Alias('check', test_cases_env.program);
+
+env.targets += ['test','check'];
diff --git a/modules/core/tests/core.cpp b/modules/core/tests/core.cpp
new file mode 100644
index 0000000..2b63b94
--- /dev/null
+++ b/modules/core/tests/core.cpp
@@ -0,0 +1,67 @@
+#include "../c++/test/suite.h"
+#include "../c++/id.h"
+#include "../c++/id_map.h"
+#include "../c++/string_literal.h"
+
+namespace {
+SAW_TEST("ID functionality") {
+ using namespace saw;
+ struct foo {};
+
+ id<foo> a{1};
+ id<foo> b{1};
+ id<foo> c{2};
+
+ /**
+ * The following doesn't compile, so it's commented out as an example
+ */
+ /**
+ * struct bar {};
+ *
+ * id<bar> d{1};
+ *
+ * SAW_EXPECT(a == d, "Shouldn't compile");
+ */
+
+ SAW_EXPECT(a == b, "Should be equal");
+ SAW_EXPECT(a != c, "Shouldn't be equal");
+ SAW_EXPECT(b != c, "Shouldn't be equal");
+ SAW_EXPECT(a.get_value() == 1, "Lost original value");
+}
+
+SAW_TEST("String Literal Append"){
+ using namespace saw;
+
+ constexpr string_literal a = "foo";
+ constexpr string_literal b = "bar";
+ constexpr string_literal c = a+b;
+
+ SAW_EXPECT(c == "foobar", "CT String sum is not \"foobar\"");
+}
+
+SAW_TEST("ID Map Insert"){
+ using namespace saw;
+
+ struct foo {};
+
+ id_map<foo> map;
+ {
+ auto eoid = map.insert(foo{});
+ SAW_EXPECT(eoid.is_value(), "First insert failed");
+
+ auto& id = eoid.get_value();
+
+ auto eoid_2 = map.insert(foo{});
+ SAW_EXPECT(eoid_2.is_value(), "Second Insert failed");
+ auto& id_2 = eoid_2.get_value();
+
+ SAW_EXPECT(id != id_2, "Shouldn't be equal");
+
+ auto eov = map.erase(id);
+ SAW_EXPECT(eov.is_value(), "Erase failed");
+
+ auto eov_2 = map.erase(id);
+ SAW_EXPECT(eov_2.is_error(), "This is a double free");
+ }
+}
+}
diff --git a/modules/core/tests/tree.cpp b/modules/core/tests/tree.cpp
new file mode 100644
index 0000000..78f72ef
--- /dev/null
+++ b/modules/core/tests/tree.cpp
@@ -0,0 +1,24 @@
+#include "../c++/test/suite.h"
+#include "../c++/tree.h"
+
+namespace {
+SAW_TEST("Tree add child"){
+ using namespace saw;
+
+ tree<int> tr;
+ {
+ auto eov = tr.add(10);
+ SAW_EXPECT(eov.is_value(), "Didn't manage to add value");
+ }
+ {
+ auto eov = tr.add();
+ SAW_EXPECT(eov.is_value(), "Didn't manage to add tree");
+ std::size_t index = eov.get_value();
+
+ auto& inner_tr = tr.at(index);
+
+ auto eov2 = inner_tr.get_tree().add(420);
+ SAW_EXPECT(eov2.is_value(), "Didn't manage to add to inner tree");
+ }
+}
+}