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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#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 TestStruct = Struct<
Member<Int32, "a">,
Member<Float64, "b">
>;
using TestArray = Array<
Int64, 1
>;
using TestStructArray = Struct<
Member<TestArray, "array">,
Member<UInt64, "un_int_num">
>;
using TestStructMore = Struct<
Member<Int64, "int">,
Member<UInt16, "uint">,
Member<Float32, "float">,
Member<Float64, "double">
>;
using TestEmptyInterface = Interface<>;
using TestOneFunctionInterface = Interface<
Member<Function<Int32, Int32>, "one">
>;
using TestStructFunctionInterface = Interface<
Member<Function<TestStruct, Int32>, "two">
>;
using TestArrayFunctionInterface = Interface<
Member<Function<TestArray, Int32>, "three">
>;
using TestStructArrayFunctionInterface = Interface<
Member<Function<TestStructArray, Int32>, "three">
>;
using TestMultiFunctionInterface = Interface<
Member<Function<TestArray, Float32>, "foo">,
Member<Function<Float64, Int8>, "bar">,
Member<Function<UInt32, TestArray>, "baz">,
Member<Function<UInt32, Float64>, "banana">,
Member<Function<TestStructMore, Float32>, "struct">
>;
}
template<typename Schema>
void test_generate(std::string& res, std::string& src){
using namespace saw;
ring_buffer r_buff{4u * 1024u * 1024u};
ring_buffer r_src_buff{4u * 1024u * 1024u};
{
auto eov = language_binding<Schema, binding::SyncC>::generate(r_buff, r_src_buff, {"prefix"});
SAW_EXPECT(eov.is_value(), std::string{"Couldn't generate interface info: "} + std::string{eov.get_error().get_message()});
}
res = convert_to_string(r_buff);
src = convert_to_string(r_src_buff);
}
SAW_TEST("CIface Empty Interface"){
using namespace saw;
std::string res;
std::string src;
test_generate<schema::TestEmptyInterface>(res,src);
std::cout<<"\n"<<res<<"\n"<<std::endl;
std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
}
SAW_TEST("CIface One Function Interface"){
using namespace saw;
std::string res;
std::string src;
test_generate<schema::TestOneFunctionInterface>(res, src);
std::cout<<"\n"<<res<<"\n"<<std::endl;
std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
}
SAW_TEST("CIface Multi Function Interface"){
using namespace saw;
std::string res;
std::string src;
test_generate<schema::TestMultiFunctionInterface>(res, src);
std::cout<<"\n"<<res<<"\n"<<std::endl;
std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
}
SAW_TEST("CIface Array Function Interface"){
using namespace saw;
std::string res;
std::string src;
test_generate<schema::TestArrayFunctionInterface>(res, src);
std::cout<<"\n"<<res<<"\n"<<std::endl;
std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
}
SAW_TEST("CIface Struct Array Function Interface"){
using namespace saw;
std::string res;
std::string src;
test_generate<schema::TestStructArrayFunctionInterface>(res, src);
std::cout<<"\n"<<res<<"\n"<<std::endl;
std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
}
}
|