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