summaryrefslogtreecommitdiff
path: root/modules/tools/tests/c_iface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/tools/tests/c_iface.cpp')
-rw-r--r--modules/tools/tests/c_iface.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/modules/tools/tests/c_iface.cpp b/modules/tools/tests/c_iface.cpp
new file mode 100644
index 0000000..121605a
--- /dev/null
+++ b/modules/tools/tests/c_iface.cpp
@@ -0,0 +1,56 @@
+#include <forstio/test/suite.hpp>
+#include <forstio/codec/json/json.hpp>
+
+#include "../c++/c_gen_iface.hpp"
+
+#include <iostream>
+
+namespace {
+namespace schema {
+using namespace saw::schema;
+
+using TestEmptyInterface = Interface<>;
+
+using TestOneFunctionInterface = Interface<
+ Member<Function<Int32, Int32>, "one">
+>;
+}
+
+template<typename Schema>
+void test_generate(std::string& res){
+ using namespace saw;
+
+ data<schema::CIface> c_iface;
+ {
+ auto eov = generate_c_interface<Schema>(c_iface);
+ SAW_EXPECT(eov.is_value(), "Couldn't generate interface info");
+ }
+
+ data<schema::CIface, encode::Json> j_data;
+ codec<schema::CIface, encode::Json> j_codec;
+
+ {
+ auto eov = j_codec.encode(c_iface, j_data);
+ SAW_EXPECT(eov.is_value(), "Couldn't encode data");
+ }
+
+ res = convert_to_string(j_data.get_buffer());
+}
+
+SAW_TEST("CIface Empty Interface"){
+ using namespace saw;
+
+ std::string res;
+ test_generate<schema::TestEmptyInterface>(res);
+
+ std::cout<<"\n"<<res<<"\n"<<std::endl;
+}
+
+SAW_TEST("CIface One Function Interface"){
+ using namespace saw;
+
+ std::string res;
+ test_generate<schema::TestOneFunctionInterface>(res);
+ std::cout<<"\n"<<res<<"\n"<<std::endl;
+}
+}