Coverage Report

Created: 2024-04-30 09:35

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