summaryrefslogtreecommitdiff
path: root/modules/codec/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/tests')
-rw-r--r--modules/codec/tests/forst.cpp29
-rw-r--r--modules/codec/tests/schema.cpp69
2 files changed, 98 insertions, 0 deletions
diff --git a/modules/codec/tests/forst.cpp b/modules/codec/tests/forst.cpp
new file mode 100644
index 0000000..cb0442d
--- /dev/null
+++ b/modules/codec/tests/forst.cpp
@@ -0,0 +1,29 @@
+#include <forstio/test/suite.hpp>
+#include "../c++/data.hpp"
+#include "../c++/forst.hpp"
+
+#include <iostream>
+
+namespace {
+namespace schema {
+using namespace saw::schema;
+
+using TestStruct = Struct<
+ Member<String, "string">,
+ Member<UInt64, "number">,
+ Member<Int8, "signed">
+>;
+
+using TestArray = Array<
+ TestStruct
+>;
+
+SAW_TEST("Codec Forst Info"){
+ using namespace saw;
+
+ SAW_EXPECT(impl::forst_codec_info<schema::UInt64>::layers == 0, "Layer info is wrong");
+ SAW_EXPECT(impl::forst_codec_info<TestStruct>::layers == 1, "Layer info is wrong");
+ SAW_EXPECT(impl::forst_codec_info<TestArray>::layers == 2, "Layer info is wrong");
+}
+}
+}
diff --git a/modules/codec/tests/schema.cpp b/modules/codec/tests/schema.cpp
index 408a142..77d369d 100644
--- a/modules/codec/tests/schema.cpp
+++ b/modules/codec/tests/schema.cpp
@@ -3,6 +3,7 @@
#include <forstio/templates.hpp>
#include "../c++/schema.hpp"
#include "../c++/schema_hash.hpp"
+#include "../c++/schema_factory.hpp"
namespace {
template<typename T>
@@ -70,4 +71,72 @@ SAW_TEST("Schema Hashes"){
schema_test_pair<schema::HashIface, 3365712860>
>::check();
}
+
+SAW_TEST("Schema Factory Compiles"){
+ using namespace saw;
+
+ auto factory = build_schema<schema::Struct<>>();
+
+ auto str = factory
+ .add<schema::UInt32, "foo">()
+ .add<schema::Int16, "bar">()
+ .add_maybe<schema::Int16, "bar">()
+ .add_maybe<schema::String, "baz">()
+ ;
+
+ using FactorySchema = decltype(str)::Schema;
+
+ using Schema = schema::Struct<
+ schema::Member<schema::UInt32, "foo">,
+ schema::Member<schema::Int16, "bar">,
+ schema::Member<schema::String, "baz">
+ >;
+
+ SAW_EXPECT(is_struct<FactorySchema>::value, "Expected a struct");
+
+ schema_hash_test_multi<
+ schema_test_pair<FactorySchema, 86402530>,
+ schema_test_pair<Schema, 86402530>
+ >::check();
+}
+
+template<typename Schema>
+auto ensure_types_one(saw::schema_factory<Schema> builder){
+ return builder
+ .template add_maybe<schema::Array<schema::Int32>, "foo">()
+ .template add_maybe<schema::Int32, "bar">()
+ ;
+}
+
+template<typename Schema>
+auto ensure_types_two(saw::schema_factory<Schema> builder){
+ return builder
+ .template add_maybe<schema::Array<schema::Int32>, "foo">()
+ .template add_maybe<schema::UInt64, "baz">()
+ ;
+}
+
+SAW_TEST("Schema Factory Multimethod"){
+ using namespace saw;
+ auto builder = build_schema<schema::Struct<>>();
+
+ /**
+ * This would basically be multiple components
+ */
+ auto b2 = ensure_types_one(builder);
+ auto b3 = ensure_types_two(b2);
+
+ using Schema = schema::Struct<
+ schema::Member<schema::Array<schema::Int32>, "foo">,
+ schema::Member<schema::Int32, "bar">,
+ schema::Member<schema::UInt64, "baz">
+ >;
+
+ schema_hash_test_multi<
+ schema_test_pair<decltype(b3)::Schema, 2324362429>,
+ schema_test_pair<Schema, 2324362429>
+ >::check();
+
+
+}
}