test/zserio/TypeInfoTest.cpp
Line | Count | Source |
1 | | #include <string> |
2 | | |
3 | | #include "gtest/gtest.h" |
4 | | |
5 | | #include "zserio/TypeInfo.h" |
6 | | |
7 | | namespace zserio |
8 | | { |
9 | | |
10 | | namespace |
11 | | { |
12 | | |
13 | | class RecursiveObject |
14 | | { |
15 | | public: |
16 | | static const ITypeInfo& typeInfo() |
17 | 25 | { |
18 | 25 | static const RecursiveTypeInfo<std::allocator<uint8_t>> recursiveTypeInfo(&RecursiveObject::typeInfo); |
19 | 25 | static const std::array<FieldInfo, 1> fields = { |
20 | 25 | FieldInfo{ |
21 | 25 | "recursive"_sv, |
22 | 25 | recursiveTypeInfo, |
23 | 25 | {}, |
24 | 25 | false, // isExtended |
25 | 25 | {}, |
26 | 25 | {}, |
27 | 25 | {}, |
28 | 25 | true, // isOptional |
29 | 25 | {}, |
30 | 25 | {}, |
31 | 25 | false, |
32 | 25 | {}, |
33 | 25 | false, |
34 | 25 | false |
35 | 25 | } |
36 | 25 | }; |
37 | | |
38 | 25 | static const StructTypeInfo<std::allocator<uint8_t>> structTypeInfo( |
39 | 25 | "RecursiveObject"_sv, nullptr, ""_sv, {}, fields, {}, {} |
40 | 25 | ); |
41 | 25 | return structTypeInfo; |
42 | 25 | } |
43 | | }; |
44 | | |
45 | | } // namespace |
46 | | |
47 | | class TypeInfoTest : public ::testing::Test |
48 | | { |
49 | | protected: |
50 | | void checkBuiltinTypeInfo(const ITypeInfo& typeInfo, StringView schemaName, SchemaType schemaType, |
51 | | CppType cppType, uint8_t bitSize = 0) |
52 | 280 | { |
53 | 280 | ASSERT_EQ(schemaName, typeInfo.getSchemaName()); |
54 | 280 | ASSERT_EQ(schemaType, typeInfo.getSchemaType()); |
55 | 280 | ASSERT_EQ(cppType, typeInfo.getCppType()); |
56 | 280 | if (bitSize > 0) |
57 | 140 | ASSERT_EQ(bitSize, typeInfo.getBitSize()); |
58 | 140 | else |
59 | 140 | ASSERT_THROW(typeInfo.getBitSize(), CppRuntimeException); |
60 | | |
61 | 280 | ASSERT_THROW(typeInfo.getFields(), CppRuntimeException); |
62 | 280 | ASSERT_THROW(typeInfo.getParameters(), CppRuntimeException); |
63 | 280 | ASSERT_THROW(typeInfo.getFunctions(), CppRuntimeException); |
64 | | |
65 | 280 | ASSERT_THROW(typeInfo.getSelector(), CppRuntimeException); |
66 | 280 | ASSERT_THROW(typeInfo.getCases(), CppRuntimeException); |
67 | | |
68 | 280 | ASSERT_THROW(typeInfo.getUnderlyingType(), CppRuntimeException); |
69 | 280 | ASSERT_THROW(typeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
70 | 280 | ASSERT_THROW(typeInfo.getEnumItems(), CppRuntimeException); |
71 | 280 | ASSERT_THROW(typeInfo.getBitmaskValues(), CppRuntimeException); |
72 | | |
73 | 280 | ASSERT_THROW(typeInfo.getColumns(), CppRuntimeException); |
74 | 280 | ASSERT_THROW(typeInfo.getSqlConstraint(), CppRuntimeException); |
75 | 280 | ASSERT_THROW(typeInfo.getVirtualTableUsing(), CppRuntimeException); |
76 | 280 | ASSERT_THROW(typeInfo.isWithoutRowId(), CppRuntimeException); |
77 | | |
78 | 280 | ASSERT_THROW(typeInfo.getTables(), CppRuntimeException); |
79 | | |
80 | 280 | ASSERT_THROW(typeInfo.getTemplateName(), CppRuntimeException); |
81 | 280 | ASSERT_THROW(typeInfo.getTemplateArguments(), CppRuntimeException); |
82 | | |
83 | 280 | ASSERT_THROW(typeInfo.getMessages(), CppRuntimeException); |
84 | | |
85 | 280 | ASSERT_THROW(typeInfo.getMethods(), CppRuntimeException); |
86 | | |
87 | 280 | ASSERT_THROW(typeInfo.createInstance(), CppRuntimeException); |
88 | 280 | } |
89 | | }; |
90 | | |
91 | | // TODO[Mi-L@]: Test all structures (e.g. FieldInfo). |
92 | | |
93 | | TEST_F(TypeInfoTest, builtinTypeInfo) |
94 | 1 | { |
95 | 1 | using Builtin = BuiltinTypeInfo<>; |
96 | | |
97 | 1 | checkBuiltinTypeInfo(Builtin::getBool(), "bool"_sv, SchemaType::BOOL, CppType::BOOL, 1); |
98 | | |
99 | 1 | checkBuiltinTypeInfo(Builtin::getInt8(), "int8"_sv, SchemaType::INT8, CppType::INT8, 8); |
100 | 1 | checkBuiltinTypeInfo(Builtin::getInt16(), "int16"_sv, SchemaType::INT16, CppType::INT16, 16); |
101 | 1 | checkBuiltinTypeInfo(Builtin::getInt32(), "int32"_sv, SchemaType::INT32, CppType::INT32, 32); |
102 | 1 | checkBuiltinTypeInfo(Builtin::getInt64(), "int64"_sv, SchemaType::INT64, CppType::INT64, 64); |
103 | | |
104 | 1 | checkBuiltinTypeInfo(Builtin::getUInt8(), "uint8"_sv, SchemaType::UINT8, CppType::UINT8, 8); |
105 | 1 | checkBuiltinTypeInfo(Builtin::getUInt16(), "uint16"_sv, SchemaType::UINT16, CppType::UINT16, 16); |
106 | 1 | checkBuiltinTypeInfo(Builtin::getUInt32(), "uint32"_sv, SchemaType::UINT32, CppType::UINT32, 32); |
107 | 1 | checkBuiltinTypeInfo(Builtin::getUInt64(), "uint64"_sv, SchemaType::UINT64, CppType::UINT64, 64); |
108 | | |
109 | 1 | checkBuiltinTypeInfo(Builtin::getVarInt16(), "varint16"_sv, SchemaType::VARINT16, CppType::INT16); |
110 | 1 | checkBuiltinTypeInfo(Builtin::getVarInt32(), "varint32"_sv, SchemaType::VARINT32, CppType::INT32); |
111 | 1 | checkBuiltinTypeInfo(Builtin::getVarInt64(), "varint64"_sv, SchemaType::VARINT64, CppType::INT64); |
112 | 1 | checkBuiltinTypeInfo(Builtin::getVarInt(), "varint"_sv, SchemaType::VARINT, CppType::INT64); |
113 | 1 | checkBuiltinTypeInfo(Builtin::getVarUInt16(), "varuint16"_sv, SchemaType::VARUINT16, CppType::UINT16); |
114 | 1 | checkBuiltinTypeInfo(Builtin::getVarUInt32(), "varuint32"_sv, SchemaType::VARUINT32, CppType::UINT32); |
115 | 1 | checkBuiltinTypeInfo(Builtin::getVarUInt64(), "varuint64"_sv, SchemaType::VARUINT64, CppType::UINT64); |
116 | 1 | checkBuiltinTypeInfo(Builtin::getVarUInt(), "varuint"_sv, SchemaType::VARUINT, CppType::UINT64); |
117 | 1 | checkBuiltinTypeInfo(Builtin::getVarSize(), "varsize"_sv, SchemaType::VARSIZE, CppType::UINT32); |
118 | | |
119 | 1 | checkBuiltinTypeInfo(Builtin::getFloat16(), "float16"_sv, SchemaType::FLOAT16, CppType::FLOAT, 16); |
120 | 1 | checkBuiltinTypeInfo(Builtin::getFloat32(), "float32"_sv, SchemaType::FLOAT32, CppType::FLOAT, 32); |
121 | 1 | checkBuiltinTypeInfo(Builtin::getFloat64(), "float64"_sv, SchemaType::FLOAT64, CppType::DOUBLE, 64); |
122 | | |
123 | 1 | checkBuiltinTypeInfo(Builtin::getString(), "string"_sv, SchemaType::STRING, CppType::STRING); |
124 | | |
125 | 1 | checkBuiltinTypeInfo(Builtin::getBitBuffer(), "extern"_sv, SchemaType::EXTERN, CppType::BIT_BUFFER); |
126 | | |
127 | 1 | checkBuiltinTypeInfo(Builtin::getBytes(), "bytes"_sv, SchemaType::BYTES, CppType::BYTES); |
128 | | |
129 | | // fixed signed bit fields |
130 | 1 | uint8_t bitSize = 0; |
131 | 1 | ASSERT_THROW(Builtin::getFixedSignedBitField(bitSize), CppRuntimeException); |
132 | 9 | for (++bitSize ; 1 bitSize <= 8; ++bitSize8 ) |
133 | 8 | { |
134 | 8 | checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" + |
135 | 8 | std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, bitSize); |
136 | 8 | } |
137 | 9 | for (; bitSize <= 16; ++bitSize8 ) |
138 | 8 | { |
139 | 8 | checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" + |
140 | 8 | std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, bitSize); |
141 | 8 | } |
142 | 17 | for (; bitSize <= 32; ++bitSize16 ) |
143 | 16 | { |
144 | 16 | checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" + |
145 | 16 | std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, bitSize); |
146 | 16 | } |
147 | 33 | for (; bitSize <= 64; ++bitSize32 ) |
148 | 32 | { |
149 | 32 | checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" + |
150 | 32 | std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, bitSize); |
151 | 32 | } |
152 | 191 | for (; bitSize < 255; ++bitSize190 ) |
153 | 190 | { |
154 | 190 | ASSERT_THROW(Builtin::getFixedSignedBitField(bitSize), CppRuntimeException); |
155 | 190 | } |
156 | 1 | ASSERT_THROW(Builtin::getFixedSignedBitField(bitSize), CppRuntimeException); |
157 | | |
158 | | // fixed unsigned bit fields |
159 | 1 | bitSize = 0; |
160 | 1 | ASSERT_THROW(Builtin::getFixedUnsignedBitField(bitSize), CppRuntimeException); |
161 | 9 | for (++bitSize ; 1 bitSize <= 8; ++bitSize8 ) |
162 | 8 | { |
163 | 8 | checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" + |
164 | 8 | std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, bitSize); |
165 | 8 | } |
166 | 9 | for (; bitSize <= 16; ++bitSize8 ) |
167 | 8 | { |
168 | 8 | checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" + |
169 | 8 | std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, bitSize); |
170 | 8 | } |
171 | 17 | for (; bitSize <= 32; ++bitSize16 ) |
172 | 16 | { |
173 | 16 | checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" + |
174 | 16 | std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, bitSize); |
175 | 16 | } |
176 | 33 | for (; bitSize <= 64; ++bitSize32 ) |
177 | 32 | { |
178 | 32 | checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" + |
179 | 32 | std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, bitSize); |
180 | 32 | } |
181 | 191 | for (; bitSize < 255; ++bitSize190 ) |
182 | 190 | { |
183 | 190 | ASSERT_THROW(Builtin::getFixedUnsignedBitField(bitSize), CppRuntimeException); |
184 | 190 | } |
185 | 1 | ASSERT_THROW(Builtin::getFixedUnsignedBitField(bitSize), CppRuntimeException); |
186 | | |
187 | | // dynamic signed bit fields |
188 | 1 | uint8_t maxBitSize = 0; |
189 | 1 | ASSERT_THROW(Builtin::getDynamicSignedBitField(maxBitSize), CppRuntimeException); |
190 | 9 | for (++maxBitSize ; 1 maxBitSize <= 8; ++maxBitSize8 ) |
191 | 8 | { |
192 | 8 | checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>", |
193 | 8 | SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT8); |
194 | 8 | } |
195 | 9 | for (; maxBitSize <= 16; ++maxBitSize8 ) |
196 | 8 | { |
197 | 8 | checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>", |
198 | 8 | SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT16); |
199 | 8 | } |
200 | 17 | for (; maxBitSize <= 32; ++maxBitSize16 ) |
201 | 16 | { |
202 | 16 | checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>", |
203 | 16 | SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT32); |
204 | 16 | } |
205 | 33 | for (; maxBitSize <= 64; ++maxBitSize32 ) |
206 | 32 | { |
207 | 32 | checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>", |
208 | 32 | SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT64); |
209 | 32 | } |
210 | 191 | for (; maxBitSize < 255; ++maxBitSize190 ) |
211 | 190 | { |
212 | 190 | ASSERT_THROW(Builtin::getDynamicSignedBitField(maxBitSize), CppRuntimeException); |
213 | 190 | } |
214 | 1 | ASSERT_THROW(Builtin::getDynamicSignedBitField(maxBitSize), CppRuntimeException); |
215 | | |
216 | | // dynamic unsigned bit fields |
217 | 1 | maxBitSize = 0; |
218 | 1 | ASSERT_THROW(Builtin::getDynamicUnsignedBitField(maxBitSize), CppRuntimeException); |
219 | 9 | for (++maxBitSize ; 1 maxBitSize <= 8; ++maxBitSize8 ) |
220 | 8 | { |
221 | 8 | checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>", |
222 | 8 | SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT8); |
223 | 8 | } |
224 | 9 | for (; maxBitSize <= 16; ++maxBitSize8 ) |
225 | 8 | { |
226 | 8 | checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>", |
227 | 8 | SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT16); |
228 | 8 | } |
229 | 17 | for (; maxBitSize <= 32; ++maxBitSize16 ) |
230 | 16 | { |
231 | 16 | checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>", |
232 | 16 | SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT32); |
233 | 16 | } |
234 | 33 | for (; maxBitSize <= 64; ++maxBitSize32 ) |
235 | 32 | { |
236 | 32 | checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>", |
237 | 32 | SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT64); |
238 | 32 | } |
239 | 191 | for (; maxBitSize < 255; ++maxBitSize190 ) |
240 | 190 | { |
241 | 190 | ASSERT_THROW(Builtin::getDynamicUnsignedBitField(maxBitSize), CppRuntimeException); |
242 | 190 | } |
243 | 1 | ASSERT_THROW(Builtin::getDynamicUnsignedBitField(maxBitSize), CppRuntimeException); |
244 | 1 | } |
245 | | |
246 | | TEST_F(TypeInfoTest, structTypeInfo) |
247 | 1 | { |
248 | 1 | const StructTypeInfo<std::allocator<uint8_t>> structTypeInfo(""_sv, nullptr, ""_sv, {}, {}, {}, {}); |
249 | 1 | ASSERT_EQ(""_sv, structTypeInfo.getSchemaName()); |
250 | 1 | ASSERT_EQ(SchemaType::STRUCT, structTypeInfo.getSchemaType()); |
251 | 1 | ASSERT_EQ(CppType::STRUCT, structTypeInfo.getCppType()); |
252 | 1 | ASSERT_THROW(structTypeInfo.getBitSize(), CppRuntimeException); |
253 | | |
254 | 1 | ASSERT_EQ(0, structTypeInfo.getFields().size()); |
255 | 1 | ASSERT_EQ(0, structTypeInfo.getParameters().size()); |
256 | 1 | ASSERT_EQ(0, structTypeInfo.getFunctions().size()); |
257 | | |
258 | 1 | ASSERT_THROW(structTypeInfo.getSelector(), CppRuntimeException); |
259 | 1 | ASSERT_THROW(structTypeInfo.getCases(), CppRuntimeException); |
260 | | |
261 | 1 | ASSERT_THROW(structTypeInfo.getUnderlyingType(), CppRuntimeException); |
262 | 1 | ASSERT_THROW(structTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
263 | 1 | ASSERT_THROW(structTypeInfo.getEnumItems(), CppRuntimeException); |
264 | 1 | ASSERT_THROW(structTypeInfo.getBitmaskValues(), CppRuntimeException); |
265 | | |
266 | 1 | ASSERT_THROW(structTypeInfo.getColumns(), CppRuntimeException); |
267 | 1 | ASSERT_THROW(structTypeInfo.getSqlConstraint(), CppRuntimeException); |
268 | 1 | ASSERT_THROW(structTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
269 | 1 | ASSERT_THROW(structTypeInfo.isWithoutRowId(), CppRuntimeException); |
270 | | |
271 | 1 | ASSERT_THROW(structTypeInfo.getTables(), CppRuntimeException); |
272 | | |
273 | 1 | ASSERT_EQ(""_sv, structTypeInfo.getTemplateName()); |
274 | 1 | ASSERT_EQ(0, structTypeInfo.getTemplateArguments().size()); |
275 | | |
276 | 1 | ASSERT_THROW(structTypeInfo.getMessages(), CppRuntimeException); |
277 | | |
278 | 1 | ASSERT_THROW(structTypeInfo.getMethods(), CppRuntimeException); |
279 | | |
280 | 1 | ASSERT_THROW(structTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
281 | 1 | } |
282 | | |
283 | | TEST_F(TypeInfoTest, unionTypeInfo) |
284 | 1 | { |
285 | 1 | const UnionTypeInfo<std::allocator<uint8_t>> unionTypeInfo(""_sv, nullptr, ""_sv, {}, {}, {}, {}); |
286 | 1 | ASSERT_EQ(""_sv, unionTypeInfo.getSchemaName()); |
287 | 1 | ASSERT_EQ(SchemaType::UNION, unionTypeInfo.getSchemaType()); |
288 | 1 | ASSERT_EQ(CppType::UNION, unionTypeInfo.getCppType()); |
289 | 1 | ASSERT_THROW(unionTypeInfo.getBitSize(), CppRuntimeException); |
290 | | |
291 | 1 | ASSERT_EQ(0, unionTypeInfo.getFields().size()); |
292 | 1 | ASSERT_EQ(0, unionTypeInfo.getParameters().size()); |
293 | 1 | ASSERT_EQ(0, unionTypeInfo.getFunctions().size()); |
294 | | |
295 | 1 | ASSERT_THROW(unionTypeInfo.getSelector(), CppRuntimeException); |
296 | 1 | ASSERT_THROW(unionTypeInfo.getCases(), CppRuntimeException); |
297 | | |
298 | 1 | ASSERT_THROW(unionTypeInfo.getUnderlyingType(), CppRuntimeException); |
299 | 1 | ASSERT_THROW(unionTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
300 | 1 | ASSERT_THROW(unionTypeInfo.getEnumItems(), CppRuntimeException); |
301 | 1 | ASSERT_THROW(unionTypeInfo.getBitmaskValues(), CppRuntimeException); |
302 | | |
303 | 1 | ASSERT_THROW(unionTypeInfo.getColumns(), CppRuntimeException); |
304 | 1 | ASSERT_THROW(unionTypeInfo.getSqlConstraint(), CppRuntimeException); |
305 | 1 | ASSERT_THROW(unionTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
306 | 1 | ASSERT_THROW(unionTypeInfo.isWithoutRowId(), CppRuntimeException); |
307 | | |
308 | 1 | ASSERT_THROW(unionTypeInfo.getTables(), CppRuntimeException); |
309 | | |
310 | 1 | ASSERT_EQ(""_sv, unionTypeInfo.getTemplateName()); |
311 | 1 | ASSERT_EQ(0, unionTypeInfo.getTemplateArguments().size()); |
312 | | |
313 | 1 | ASSERT_THROW(unionTypeInfo.getMessages(), CppRuntimeException); |
314 | | |
315 | 1 | ASSERT_THROW(unionTypeInfo.getMethods(), CppRuntimeException); |
316 | | |
317 | 1 | ASSERT_THROW(unionTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
318 | 1 | } |
319 | | |
320 | | TEST_F(TypeInfoTest, choiceTypeInfo) |
321 | 1 | { |
322 | 1 | const ChoiceTypeInfo<std::allocator<uint8_t>> choiceTypeInfo( |
323 | 1 | ""_sv, nullptr, ""_sv, {}, {}, {}, {}, ""_sv, {}); |
324 | 1 | ASSERT_EQ(""_sv, choiceTypeInfo.getSchemaName()); |
325 | 1 | ASSERT_EQ(SchemaType::CHOICE, choiceTypeInfo.getSchemaType()); |
326 | 1 | ASSERT_EQ(CppType::CHOICE, choiceTypeInfo.getCppType()); |
327 | 1 | ASSERT_THROW(choiceTypeInfo.getBitSize(), CppRuntimeException); |
328 | | |
329 | 1 | ASSERT_EQ(0, choiceTypeInfo.getFields().size()); |
330 | 1 | ASSERT_EQ(0, choiceTypeInfo.getParameters().size()); |
331 | 1 | ASSERT_EQ(0, choiceTypeInfo.getFunctions().size()); |
332 | | |
333 | 1 | ASSERT_EQ(""_sv, choiceTypeInfo.getSelector()); |
334 | 1 | ASSERT_EQ(0, choiceTypeInfo.getCases().size()); |
335 | | |
336 | 1 | ASSERT_THROW(choiceTypeInfo.getUnderlyingType(), CppRuntimeException); |
337 | 1 | ASSERT_THROW(choiceTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
338 | 1 | ASSERT_THROW(choiceTypeInfo.getEnumItems(), CppRuntimeException); |
339 | 1 | ASSERT_THROW(choiceTypeInfo.getBitmaskValues(), CppRuntimeException); |
340 | | |
341 | 1 | ASSERT_THROW(choiceTypeInfo.getColumns(), CppRuntimeException); |
342 | 1 | ASSERT_THROW(choiceTypeInfo.getSqlConstraint(), CppRuntimeException); |
343 | 1 | ASSERT_THROW(choiceTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
344 | 1 | ASSERT_THROW(choiceTypeInfo.isWithoutRowId(), CppRuntimeException); |
345 | | |
346 | 1 | ASSERT_THROW(choiceTypeInfo.getTables(), CppRuntimeException); |
347 | | |
348 | 1 | ASSERT_EQ(""_sv, choiceTypeInfo.getTemplateName()); |
349 | 1 | ASSERT_EQ(0, choiceTypeInfo.getTemplateArguments().size()); |
350 | | |
351 | 1 | ASSERT_THROW(choiceTypeInfo.getMessages(), CppRuntimeException); |
352 | | |
353 | 1 | ASSERT_THROW(choiceTypeInfo.getMethods(), CppRuntimeException); |
354 | | |
355 | 1 | ASSERT_THROW(choiceTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
356 | 1 | } |
357 | | |
358 | | TEST_F(TypeInfoTest, sqlTableTypeInfo) |
359 | 1 | { |
360 | 1 | const SqlTableTypeInfo<std::allocator<uint8_t>> sqlTableTypeInfo(""_sv, ""_sv, {}, {}, ""_sv, ""_sv, false); |
361 | 1 | ASSERT_EQ(""_sv, sqlTableTypeInfo.getSchemaName()); |
362 | 1 | ASSERT_EQ(SchemaType::SQL_TABLE, sqlTableTypeInfo.getSchemaType()); |
363 | 1 | ASSERT_EQ(CppType::SQL_TABLE, sqlTableTypeInfo.getCppType()); |
364 | 1 | ASSERT_THROW(sqlTableTypeInfo.getBitSize(), CppRuntimeException); |
365 | | |
366 | 1 | ASSERT_THROW(sqlTableTypeInfo.getFields(), CppRuntimeException); |
367 | 1 | ASSERT_THROW(sqlTableTypeInfo.getParameters(), CppRuntimeException); |
368 | 1 | ASSERT_THROW(sqlTableTypeInfo.getFunctions(), CppRuntimeException); |
369 | | |
370 | 1 | ASSERT_THROW(sqlTableTypeInfo.getSelector(), CppRuntimeException); |
371 | 1 | ASSERT_THROW(sqlTableTypeInfo.getCases(), CppRuntimeException); |
372 | | |
373 | 1 | ASSERT_THROW(sqlTableTypeInfo.getUnderlyingType(), CppRuntimeException); |
374 | 1 | ASSERT_THROW(sqlTableTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
375 | 1 | ASSERT_THROW(sqlTableTypeInfo.getEnumItems(), CppRuntimeException); |
376 | 1 | ASSERT_THROW(sqlTableTypeInfo.getBitmaskValues(), CppRuntimeException); |
377 | | |
378 | 1 | ASSERT_EQ(0, sqlTableTypeInfo.getColumns().size()); |
379 | 1 | ASSERT_EQ(""_sv, sqlTableTypeInfo.getSqlConstraint()); |
380 | 1 | ASSERT_EQ(""_sv, sqlTableTypeInfo.getVirtualTableUsing()); |
381 | 1 | ASSERT_EQ(false, sqlTableTypeInfo.isWithoutRowId()); |
382 | | |
383 | 1 | ASSERT_THROW(sqlTableTypeInfo.getTables(), CppRuntimeException); |
384 | | |
385 | 1 | ASSERT_EQ(""_sv, sqlTableTypeInfo.getTemplateName()); |
386 | 1 | ASSERT_EQ(0, sqlTableTypeInfo.getTemplateArguments().size()); |
387 | | |
388 | 1 | ASSERT_THROW(sqlTableTypeInfo.getMessages(), CppRuntimeException); |
389 | | |
390 | 1 | ASSERT_THROW(sqlTableTypeInfo.getMethods(), CppRuntimeException); |
391 | | |
392 | 1 | ASSERT_THROW(sqlTableTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
393 | 1 | } |
394 | | |
395 | | TEST_F(TypeInfoTest, sqlDatabaseTypeInfo) |
396 | 1 | { |
397 | 1 | const SqlDatabaseTypeInfo<std::allocator<uint8_t>> sqlDatabaseTypeInfo(""_sv, {}); |
398 | 1 | ASSERT_EQ(""_sv, sqlDatabaseTypeInfo.getSchemaName()); |
399 | 1 | ASSERT_EQ(SchemaType::SQL_DATABASE, sqlDatabaseTypeInfo.getSchemaType()); |
400 | 1 | ASSERT_EQ(CppType::SQL_DATABASE, sqlDatabaseTypeInfo.getCppType()); |
401 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getBitSize(), CppRuntimeException); |
402 | | |
403 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getFields(), CppRuntimeException); |
404 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getParameters(), CppRuntimeException); |
405 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getFunctions(), CppRuntimeException); |
406 | | |
407 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getSelector(), CppRuntimeException); |
408 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getCases(), CppRuntimeException); |
409 | | |
410 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getUnderlyingType(), CppRuntimeException); |
411 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
412 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getEnumItems(), CppRuntimeException); |
413 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getBitmaskValues(), CppRuntimeException); |
414 | | |
415 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getColumns(), CppRuntimeException); |
416 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getSqlConstraint(), CppRuntimeException); |
417 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
418 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.isWithoutRowId(), CppRuntimeException); |
419 | | |
420 | 1 | ASSERT_EQ(0, sqlDatabaseTypeInfo.getTables().size()); |
421 | | |
422 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getTemplateName(), CppRuntimeException); |
423 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getTemplateArguments(), CppRuntimeException); |
424 | | |
425 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getMessages(), CppRuntimeException); |
426 | | |
427 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.getMethods(), CppRuntimeException); |
428 | | |
429 | 1 | ASSERT_THROW(sqlDatabaseTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
430 | 1 | } |
431 | | |
432 | | TEST_F(TypeInfoTest, enumTypeInfo) |
433 | 1 | { |
434 | 1 | const ITypeInfo& underlyingTypeInfo = BuiltinTypeInfo<>::getInt8(); |
435 | 1 | std::array<ItemInfo, 1> enumItems = { ItemInfo("ONE"_sv, 1, false, false) }; |
436 | 1 | const EnumTypeInfo<std::allocator<uint8_t>> enumTypeInfo(""_sv, underlyingTypeInfo, {}, enumItems); |
437 | 1 | ASSERT_EQ(""_sv, enumTypeInfo.getSchemaName()); |
438 | 1 | ASSERT_EQ(SchemaType::ENUM, enumTypeInfo.getSchemaType()); |
439 | 1 | ASSERT_EQ(CppType::ENUM, enumTypeInfo.getCppType()); |
440 | 1 | ASSERT_THROW(enumTypeInfo.getBitSize(), CppRuntimeException); |
441 | | |
442 | 1 | ASSERT_THROW(enumTypeInfo.getFields(), CppRuntimeException); |
443 | 1 | ASSERT_THROW(enumTypeInfo.getParameters(), CppRuntimeException); |
444 | 1 | ASSERT_THROW(enumTypeInfo.getFunctions(), CppRuntimeException); |
445 | | |
446 | 1 | ASSERT_THROW(enumTypeInfo.getSelector(), CppRuntimeException); |
447 | 1 | ASSERT_THROW(enumTypeInfo.getCases(), CppRuntimeException); |
448 | | |
449 | 1 | ASSERT_EQ(&underlyingTypeInfo, &enumTypeInfo.getUnderlyingType()); |
450 | 1 | ASSERT_EQ(0, enumTypeInfo.getUnderlyingTypeArguments().size()); |
451 | 1 | ASSERT_EQ(1, enumTypeInfo.getEnumItems().size()); |
452 | 1 | ASSERT_EQ("ONE"_sv, enumTypeInfo.getEnumItems()[0].schemaName); |
453 | 1 | ASSERT_EQ(1, enumTypeInfo.getEnumItems()[0].value); |
454 | 1 | ASSERT_FALSE(enumTypeInfo.getEnumItems()[0].isDeprecated); |
455 | 1 | ASSERT_FALSE(enumTypeInfo.getEnumItems()[0].isRemoved); |
456 | 1 | ASSERT_THROW(enumTypeInfo.getBitmaskValues(), CppRuntimeException); |
457 | | |
458 | 1 | ASSERT_THROW(enumTypeInfo.getColumns(), CppRuntimeException); |
459 | 1 | ASSERT_THROW(enumTypeInfo.getSqlConstraint(), CppRuntimeException); |
460 | 1 | ASSERT_THROW(enumTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
461 | 1 | ASSERT_THROW(enumTypeInfo.isWithoutRowId(), CppRuntimeException); |
462 | | |
463 | 1 | ASSERT_THROW(enumTypeInfo.getTables(), CppRuntimeException); |
464 | | |
465 | 1 | ASSERT_THROW(enumTypeInfo.getTemplateName(), CppRuntimeException); |
466 | 1 | ASSERT_THROW(enumTypeInfo.getTemplateArguments(), CppRuntimeException); |
467 | | |
468 | 1 | ASSERT_THROW(enumTypeInfo.getMessages(), CppRuntimeException); |
469 | | |
470 | 1 | ASSERT_THROW(enumTypeInfo.getMethods(), CppRuntimeException); |
471 | | |
472 | 1 | ASSERT_THROW(enumTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
473 | 1 | } |
474 | | |
475 | | TEST_F(TypeInfoTest, bitmaskTypeInfo) |
476 | 1 | { |
477 | 1 | const ITypeInfo& underlyingTypeInfo = BuiltinTypeInfo<>::getInt8(); |
478 | 1 | std::array<ItemInfo, 1> bitmaskValues = { ItemInfo("FIRST_BIT"_sv, 1, false, false )}; |
479 | 1 | const BitmaskTypeInfo<std::allocator<uint8_t>> bitmaskTypeInfo(""_sv, underlyingTypeInfo, {}, |
480 | 1 | bitmaskValues); |
481 | 1 | ASSERT_EQ(""_sv, bitmaskTypeInfo.getSchemaName()); |
482 | 1 | ASSERT_EQ(SchemaType::BITMASK, bitmaskTypeInfo.getSchemaType()); |
483 | 1 | ASSERT_EQ(CppType::BITMASK, bitmaskTypeInfo.getCppType()); |
484 | 1 | ASSERT_THROW(bitmaskTypeInfo.getBitSize(), CppRuntimeException); |
485 | | |
486 | 1 | ASSERT_THROW(bitmaskTypeInfo.getFields(), CppRuntimeException); |
487 | 1 | ASSERT_THROW(bitmaskTypeInfo.getParameters(), CppRuntimeException); |
488 | 1 | ASSERT_THROW(bitmaskTypeInfo.getFunctions(), CppRuntimeException); |
489 | | |
490 | 1 | ASSERT_THROW(bitmaskTypeInfo.getSelector(), CppRuntimeException); |
491 | 1 | ASSERT_THROW(bitmaskTypeInfo.getCases(), CppRuntimeException); |
492 | | |
493 | 1 | ASSERT_EQ(&underlyingTypeInfo, &bitmaskTypeInfo.getUnderlyingType()); |
494 | 1 | ASSERT_EQ(0, bitmaskTypeInfo.getUnderlyingTypeArguments().size()); |
495 | 1 | ASSERT_THROW(bitmaskTypeInfo.getEnumItems(), CppRuntimeException); |
496 | 1 | ASSERT_EQ(1, bitmaskTypeInfo.getBitmaskValues().size()); |
497 | 1 | ASSERT_EQ("FIRST_BIT"_sv, bitmaskTypeInfo.getBitmaskValues()[0].schemaName); |
498 | 1 | ASSERT_EQ(1, bitmaskTypeInfo.getBitmaskValues()[0].value); |
499 | 1 | ASSERT_EQ(false, bitmaskTypeInfo.getBitmaskValues()[0].isDeprecated); |
500 | 1 | ASSERT_EQ(false, bitmaskTypeInfo.getBitmaskValues()[0].isRemoved); |
501 | | |
502 | 1 | ASSERT_THROW(bitmaskTypeInfo.getColumns(), CppRuntimeException); |
503 | 1 | ASSERT_THROW(bitmaskTypeInfo.getSqlConstraint(), CppRuntimeException); |
504 | 1 | ASSERT_THROW(bitmaskTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
505 | 1 | ASSERT_THROW(bitmaskTypeInfo.isWithoutRowId(), CppRuntimeException); |
506 | | |
507 | 1 | ASSERT_THROW(bitmaskTypeInfo.getTables(), CppRuntimeException); |
508 | | |
509 | 1 | ASSERT_THROW(bitmaskTypeInfo.getTemplateName(), CppRuntimeException); |
510 | 1 | ASSERT_THROW(bitmaskTypeInfo.getTemplateArguments(), CppRuntimeException); |
511 | | |
512 | 1 | ASSERT_THROW(bitmaskTypeInfo.getMessages(), CppRuntimeException); |
513 | | |
514 | 1 | ASSERT_THROW(bitmaskTypeInfo.getMethods(), CppRuntimeException); |
515 | | |
516 | 1 | ASSERT_THROW(bitmaskTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
517 | 1 | } |
518 | | |
519 | | TEST_F(TypeInfoTest, pubsubTypeInfo) |
520 | 1 | { |
521 | 1 | const PubsubTypeInfo<std::allocator<uint8_t>> pubsubTypeInfo(""_sv, {}); |
522 | 1 | ASSERT_EQ(""_sv, pubsubTypeInfo.getSchemaName()); |
523 | 1 | ASSERT_EQ(SchemaType::PUBSUB, pubsubTypeInfo.getSchemaType()); |
524 | 1 | ASSERT_EQ(CppType::PUBSUB, pubsubTypeInfo.getCppType()); |
525 | 1 | ASSERT_THROW(pubsubTypeInfo.getBitSize(), CppRuntimeException); |
526 | | |
527 | 1 | ASSERT_THROW(pubsubTypeInfo.getFields(), CppRuntimeException); |
528 | 1 | ASSERT_THROW(pubsubTypeInfo.getParameters(), CppRuntimeException); |
529 | 1 | ASSERT_THROW(pubsubTypeInfo.getFunctions(), CppRuntimeException); |
530 | | |
531 | 1 | ASSERT_THROW(pubsubTypeInfo.getSelector(), CppRuntimeException); |
532 | 1 | ASSERT_THROW(pubsubTypeInfo.getCases(), CppRuntimeException); |
533 | | |
534 | 1 | ASSERT_THROW(pubsubTypeInfo.getUnderlyingType(), CppRuntimeException); |
535 | 1 | ASSERT_THROW(pubsubTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
536 | 1 | ASSERT_THROW(pubsubTypeInfo.getEnumItems(), CppRuntimeException); |
537 | 1 | ASSERT_THROW(pubsubTypeInfo.getBitmaskValues(), CppRuntimeException); |
538 | | |
539 | 1 | ASSERT_THROW(pubsubTypeInfo.getColumns(), CppRuntimeException); |
540 | 1 | ASSERT_THROW(pubsubTypeInfo.getSqlConstraint(), CppRuntimeException); |
541 | 1 | ASSERT_THROW(pubsubTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
542 | 1 | ASSERT_THROW(pubsubTypeInfo.isWithoutRowId(), CppRuntimeException); |
543 | | |
544 | 1 | ASSERT_THROW(pubsubTypeInfo.getTables(), CppRuntimeException); |
545 | | |
546 | 1 | ASSERT_THROW(pubsubTypeInfo.getTemplateName(), CppRuntimeException); |
547 | 1 | ASSERT_THROW(pubsubTypeInfo.getTemplateArguments(), CppRuntimeException); |
548 | | |
549 | 1 | ASSERT_EQ(0, pubsubTypeInfo.getMessages().size()); |
550 | | |
551 | 1 | ASSERT_THROW(pubsubTypeInfo.getMethods(), CppRuntimeException); |
552 | | |
553 | 1 | ASSERT_THROW(pubsubTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
554 | 1 | } |
555 | | |
556 | | TEST_F(TypeInfoTest, serviceTypeInfo) |
557 | 1 | { |
558 | 1 | const ServiceTypeInfo<std::allocator<uint8_t>> serviceTypeInfo(""_sv, {}); |
559 | 1 | ASSERT_EQ(""_sv, serviceTypeInfo.getSchemaName()); |
560 | 1 | ASSERT_EQ(SchemaType::SERVICE, serviceTypeInfo.getSchemaType()); |
561 | 1 | ASSERT_EQ(CppType::SERVICE, serviceTypeInfo.getCppType()); |
562 | 1 | ASSERT_THROW(serviceTypeInfo.getBitSize(), CppRuntimeException); |
563 | | |
564 | 1 | ASSERT_THROW(serviceTypeInfo.getFields(), CppRuntimeException); |
565 | 1 | ASSERT_THROW(serviceTypeInfo.getParameters(), CppRuntimeException); |
566 | 1 | ASSERT_THROW(serviceTypeInfo.getFunctions(), CppRuntimeException); |
567 | | |
568 | 1 | ASSERT_THROW(serviceTypeInfo.getSelector(), CppRuntimeException); |
569 | 1 | ASSERT_THROW(serviceTypeInfo.getCases(), CppRuntimeException); |
570 | | |
571 | 1 | ASSERT_THROW(serviceTypeInfo.getUnderlyingType(), CppRuntimeException); |
572 | 1 | ASSERT_THROW(serviceTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
573 | 1 | ASSERT_THROW(serviceTypeInfo.getEnumItems(), CppRuntimeException); |
574 | 1 | ASSERT_THROW(serviceTypeInfo.getBitmaskValues(), CppRuntimeException); |
575 | | |
576 | 1 | ASSERT_THROW(serviceTypeInfo.getColumns(), CppRuntimeException); |
577 | 1 | ASSERT_THROW(serviceTypeInfo.getSqlConstraint(), CppRuntimeException); |
578 | 1 | ASSERT_THROW(serviceTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
579 | 1 | ASSERT_THROW(serviceTypeInfo.isWithoutRowId(), CppRuntimeException); |
580 | | |
581 | 1 | ASSERT_THROW(serviceTypeInfo.getTables(), CppRuntimeException); |
582 | | |
583 | 1 | ASSERT_THROW(serviceTypeInfo.getTemplateName(), CppRuntimeException); |
584 | 1 | ASSERT_THROW(serviceTypeInfo.getTemplateArguments(), CppRuntimeException); |
585 | | |
586 | 1 | ASSERT_THROW(serviceTypeInfo.getMessages(), CppRuntimeException); |
587 | | |
588 | 1 | ASSERT_EQ(0, serviceTypeInfo.getMethods().size()); |
589 | | |
590 | 1 | ASSERT_THROW(serviceTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
591 | 1 | } |
592 | | |
593 | | TEST_F(TypeInfoTest, recursiveTypeInfo) |
594 | 1 | { |
595 | 1 | const ITypeInfo& typeInfo = RecursiveObject::typeInfo(); |
596 | 1 | const ITypeInfo& recursiveTypeInfo = typeInfo.getFields()[0].typeInfo; |
597 | | |
598 | 1 | ASSERT_EQ(typeInfo.getSchemaName(), recursiveTypeInfo.getSchemaName()); |
599 | 1 | ASSERT_EQ(typeInfo.getSchemaType(), recursiveTypeInfo.getSchemaType()); |
600 | 1 | ASSERT_EQ(typeInfo.getCppType(), recursiveTypeInfo.getCppType()); |
601 | 1 | ASSERT_THROW(recursiveTypeInfo.getBitSize(), CppRuntimeException); |
602 | | |
603 | 1 | ASSERT_EQ(typeInfo.getFields().data(), recursiveTypeInfo.getFields().data()); |
604 | 1 | ASSERT_EQ(0, recursiveTypeInfo.getParameters().size()); |
605 | 1 | ASSERT_EQ(0, recursiveTypeInfo.getFunctions().size()); |
606 | | |
607 | 1 | ASSERT_THROW(recursiveTypeInfo.getSelector(), CppRuntimeException); |
608 | 1 | ASSERT_THROW(recursiveTypeInfo.getCases(), CppRuntimeException); |
609 | | |
610 | 1 | ASSERT_THROW(recursiveTypeInfo.getUnderlyingType(), CppRuntimeException); |
611 | 1 | ASSERT_THROW(recursiveTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException); |
612 | 1 | ASSERT_THROW(recursiveTypeInfo.getEnumItems(), CppRuntimeException); |
613 | 1 | ASSERT_THROW(recursiveTypeInfo.getBitmaskValues(), CppRuntimeException); |
614 | | |
615 | 1 | ASSERT_THROW(recursiveTypeInfo.getColumns(), CppRuntimeException); |
616 | 1 | ASSERT_THROW(recursiveTypeInfo.getSqlConstraint(), CppRuntimeException); |
617 | 1 | ASSERT_THROW(recursiveTypeInfo.getVirtualTableUsing(), CppRuntimeException); |
618 | 1 | ASSERT_THROW(recursiveTypeInfo.isWithoutRowId(), CppRuntimeException); |
619 | | |
620 | 1 | ASSERT_THROW(recursiveTypeInfo.getTables(), CppRuntimeException); |
621 | | |
622 | 1 | ASSERT_EQ(typeInfo.getTemplateName(), recursiveTypeInfo.getTemplateName()); |
623 | 1 | ASSERT_EQ(0, recursiveTypeInfo.getTemplateArguments().size()); |
624 | | |
625 | 1 | ASSERT_THROW(recursiveTypeInfo.getMessages(), CppRuntimeException); |
626 | | |
627 | 1 | ASSERT_THROW(recursiveTypeInfo.getMethods(), CppRuntimeException); |
628 | | |
629 | 1 | ASSERT_THROW(recursiveTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException); |
630 | 1 | ASSERT_THROW(recursiveTypeInfo.createInstance(), CppRuntimeException); |
631 | 1 | } |
632 | | |
633 | | } // namespace zserio |