blob: 88899f7cab2d4289675000226941f2aa84630e43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#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_config<encode::Json> j_config;
j_config.pretty = true;
codec<schema::CIface, encode::Json> j_codec{j_config};
{
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;
}
}
|