summaryrefslogtreecommitdiff
path: root/modules/codec/tests/schema.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/tests/schema.cpp')
-rw-r--r--modules/codec/tests/schema.cpp69
1 files changed, 69 insertions, 0 deletions
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();
+
+
+}
}