GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/zserio/TypeInfoTest.cpp Lines: 390 390 100.0 %
Date: 2023-12-13 14:51:09 Branches: 1982 9296 21.3 %

Line Branch Exec 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
25
    static const ITypeInfo& typeInfo()
17
    {
18

25
        static const RecursiveTypeInfo<std::allocator<uint8_t>> recursiveTypeInfo(&RecursiveObject::typeInfo);
19
        static const std::array<FieldInfo, 1> fields = {
20
            FieldInfo{
21
                "recursive"_sv,
22
                recursiveTypeInfo,
23
                {},
24
                false, // isExtended
25
                {},
26
                {},
27
                {},
28
                true, // isOptional
29
                {},
30
                {},
31
                false,
32
                {},
33
                false,
34
                false
35
            }
36

25
        };
37
38
        static const StructTypeInfo<std::allocator<uint8_t>> structTypeInfo(
39
            "RecursiveObject"_sv, nullptr, ""_sv, {}, fields, {}, {}
40


25
        );
41
25
        return structTypeInfo;
42
    }
43
};
44
45
} // namespace
46
47
22
class TypeInfoTest : public ::testing::Test
48
{
49
protected:
50
280
    void checkBuiltinTypeInfo(const ITypeInfo& typeInfo, StringView schemaName, SchemaType schemaType,
51
            CppType cppType, uint8_t bitSize = 0)
52
    {
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
        else
59










280
            ASSERT_THROW(typeInfo.getBitSize(), CppRuntimeException);
60
61










560
        ASSERT_THROW(typeInfo.getFields(), CppRuntimeException);
62










560
        ASSERT_THROW(typeInfo.getParameters(), CppRuntimeException);
63










560
        ASSERT_THROW(typeInfo.getFunctions(), CppRuntimeException);
64
65










560
        ASSERT_THROW(typeInfo.getSelector(), CppRuntimeException);
66










560
        ASSERT_THROW(typeInfo.getCases(), CppRuntimeException);
67
68










560
        ASSERT_THROW(typeInfo.getUnderlyingType(), CppRuntimeException);
69










560
        ASSERT_THROW(typeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
70










560
        ASSERT_THROW(typeInfo.getEnumItems(), CppRuntimeException);
71










560
        ASSERT_THROW(typeInfo.getBitmaskValues(), CppRuntimeException);
72
73










560
        ASSERT_THROW(typeInfo.getColumns(), CppRuntimeException);
74










560
        ASSERT_THROW(typeInfo.getSqlConstraint(), CppRuntimeException);
75










560
        ASSERT_THROW(typeInfo.getVirtualTableUsing(), CppRuntimeException);
76










560
        ASSERT_THROW(typeInfo.isWithoutRowId(), CppRuntimeException);
77
78










560
        ASSERT_THROW(typeInfo.getTables(), CppRuntimeException);
79
80










560
        ASSERT_THROW(typeInfo.getTemplateName(), CppRuntimeException);
81










560
        ASSERT_THROW(typeInfo.getTemplateArguments(), CppRuntimeException);
82
83










560
        ASSERT_THROW(typeInfo.getMessages(), CppRuntimeException);
84
85










560
        ASSERT_THROW(typeInfo.getMethods(), CppRuntimeException);
86
87









560
        ASSERT_THROW(typeInfo.createInstance(), CppRuntimeException);
88
    }
89
};
90
91
// TODO[Mi-L@]: Test all structures (e.g. FieldInfo).
92
93


802
TEST_F(TypeInfoTest, builtinTypeInfo)
94
{
95
    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









2
    ASSERT_THROW(Builtin::getFixedSignedBitField(bitSize), CppRuntimeException);
132
9
    for (++bitSize ; bitSize <= 8; ++bitSize)
133
    {
134

24
        checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" +
135
24
                std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, bitSize);
136
    }
137
17
    for (; bitSize <= 16; ++bitSize)
138
    {
139

24
        checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" +
140
24
                std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, bitSize);
141
    }
142
33
    for (; bitSize <= 32; ++bitSize)
143
    {
144

48
        checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" +
145
48
                std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, bitSize);
146
    }
147
65
    for (; bitSize <= 64; ++bitSize)
148
    {
149

96
        checkBuiltinTypeInfo(Builtin::getFixedSignedBitField(bitSize), "int:" +
150

96
                std::to_string(bitSize), SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, bitSize);
151
    }
152
381
    for (; bitSize < 255; ++bitSize)
153
    {
154










380
        ASSERT_THROW(Builtin::getFixedSignedBitField(bitSize), CppRuntimeException);
155
    }
156










2
    ASSERT_THROW(Builtin::getFixedSignedBitField(bitSize), CppRuntimeException);
157
158
    // fixed unsigned bit fields
159
1
    bitSize = 0;
160









2
    ASSERT_THROW(Builtin::getFixedUnsignedBitField(bitSize), CppRuntimeException);
161
9
    for (++bitSize ; bitSize <= 8; ++bitSize)
162
    {
163

24
        checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" +
164
24
                std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, bitSize);
165
    }
166
17
    for (; bitSize <= 16; ++bitSize)
167
    {
168

24
        checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" +
169
24
                std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, bitSize);
170
    }
171
33
    for (; bitSize <= 32; ++bitSize)
172
    {
173

48
        checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" +
174
48
                std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, bitSize);
175
    }
176
65
    for (; bitSize <= 64; ++bitSize)
177
    {
178

96
        checkBuiltinTypeInfo(Builtin::getFixedUnsignedBitField(bitSize), "bit:" +
179

96
                std::to_string(bitSize), SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, bitSize);
180
    }
181
381
    for (; bitSize < 255; ++bitSize)
182
    {
183










380
        ASSERT_THROW(Builtin::getFixedUnsignedBitField(bitSize), CppRuntimeException);
184
    }
185










2
    ASSERT_THROW(Builtin::getFixedUnsignedBitField(bitSize), CppRuntimeException);
186
187
    // dynamic signed bit fields
188
1
    uint8_t maxBitSize = 0;
189









2
    ASSERT_THROW(Builtin::getDynamicSignedBitField(maxBitSize), CppRuntimeException);
190
9
    for (++maxBitSize ; maxBitSize <= 8; ++maxBitSize)
191
    {
192
16
        checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>",
193
8
                SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT8);
194
    }
195
17
    for (; maxBitSize <= 16; ++maxBitSize)
196
    {
197
16
        checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>",
198
8
                SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT16);
199
    }
200
33
    for (; maxBitSize <= 32; ++maxBitSize)
201
    {
202
32
        checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>",
203
16
                SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT32);
204
    }
205
65
    for (; maxBitSize <= 64; ++maxBitSize)
206
    {
207

64
        checkBuiltinTypeInfo(Builtin::getDynamicSignedBitField(maxBitSize), "int<>",
208
32
                SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT64);
209
    }
210
381
    for (; maxBitSize < 255; ++maxBitSize)
211
    {
212










380
        ASSERT_THROW(Builtin::getDynamicSignedBitField(maxBitSize), CppRuntimeException);
213
    }
214










2
    ASSERT_THROW(Builtin::getDynamicSignedBitField(maxBitSize), CppRuntimeException);
215
216
    // dynamic unsigned bit fields
217
1
    maxBitSize = 0;
218









2
    ASSERT_THROW(Builtin::getDynamicUnsignedBitField(maxBitSize), CppRuntimeException);
219
9
    for (++maxBitSize ; maxBitSize <= 8; ++maxBitSize)
220
    {
221
16
        checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>",
222
8
                SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT8);
223
    }
224
17
    for (; maxBitSize <= 16; ++maxBitSize)
225
    {
226
16
        checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>",
227
8
                SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT16);
228
    }
229
33
    for (; maxBitSize <= 32; ++maxBitSize)
230
    {
231
32
        checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>",
232
16
                SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT32);
233
    }
234
65
    for (; maxBitSize <= 64; ++maxBitSize)
235
    {
236

64
        checkBuiltinTypeInfo(Builtin::getDynamicUnsignedBitField(maxBitSize), "bit<>",
237
32
                SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT64);
238
    }
239
381
    for (; maxBitSize < 255; ++maxBitSize)
240
    {
241










380
        ASSERT_THROW(Builtin::getDynamicUnsignedBitField(maxBitSize), CppRuntimeException);
242
    }
243










2
    ASSERT_THROW(Builtin::getDynamicUnsignedBitField(maxBitSize), CppRuntimeException);
244
}
245
246


802
TEST_F(TypeInfoTest, structTypeInfo)
247
{
248
2
    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









2
    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










2
    ASSERT_THROW(structTypeInfo.getSelector(), CppRuntimeException);
259










2
    ASSERT_THROW(structTypeInfo.getCases(), CppRuntimeException);
260
261










2
    ASSERT_THROW(structTypeInfo.getUnderlyingType(), CppRuntimeException);
262










2
    ASSERT_THROW(structTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
263










2
    ASSERT_THROW(structTypeInfo.getEnumItems(), CppRuntimeException);
264










2
    ASSERT_THROW(structTypeInfo.getBitmaskValues(), CppRuntimeException);
265
266










2
    ASSERT_THROW(structTypeInfo.getColumns(), CppRuntimeException);
267










2
    ASSERT_THROW(structTypeInfo.getSqlConstraint(), CppRuntimeException);
268










2
    ASSERT_THROW(structTypeInfo.getVirtualTableUsing(), CppRuntimeException);
269










2
    ASSERT_THROW(structTypeInfo.isWithoutRowId(), CppRuntimeException);
270
271









2
    ASSERT_THROW(structTypeInfo.getTables(), CppRuntimeException);
272
273



1
    ASSERT_EQ(""_sv, structTypeInfo.getTemplateName());
274



1
    ASSERT_EQ(0, structTypeInfo.getTemplateArguments().size());
275
276










2
    ASSERT_THROW(structTypeInfo.getMessages(), CppRuntimeException);
277
278









2
    ASSERT_THROW(structTypeInfo.getMethods(), CppRuntimeException);
279
280










2
    ASSERT_THROW(structTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
281
}
282
283


802
TEST_F(TypeInfoTest, unionTypeInfo)
284
{
285
2
    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









2
    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










2
    ASSERT_THROW(unionTypeInfo.getSelector(), CppRuntimeException);
296










2
    ASSERT_THROW(unionTypeInfo.getCases(), CppRuntimeException);
297
298










2
    ASSERT_THROW(unionTypeInfo.getUnderlyingType(), CppRuntimeException);
299










2
    ASSERT_THROW(unionTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
300










2
    ASSERT_THROW(unionTypeInfo.getEnumItems(), CppRuntimeException);
301










2
    ASSERT_THROW(unionTypeInfo.getBitmaskValues(), CppRuntimeException);
302
303










2
    ASSERT_THROW(unionTypeInfo.getColumns(), CppRuntimeException);
304










2
    ASSERT_THROW(unionTypeInfo.getSqlConstraint(), CppRuntimeException);
305










2
    ASSERT_THROW(unionTypeInfo.getVirtualTableUsing(), CppRuntimeException);
306










2
    ASSERT_THROW(unionTypeInfo.isWithoutRowId(), CppRuntimeException);
307
308









2
    ASSERT_THROW(unionTypeInfo.getTables(), CppRuntimeException);
309
310



1
    ASSERT_EQ(""_sv, unionTypeInfo.getTemplateName());
311



1
    ASSERT_EQ(0, unionTypeInfo.getTemplateArguments().size());
312
313










2
    ASSERT_THROW(unionTypeInfo.getMessages(), CppRuntimeException);
314
315









2
    ASSERT_THROW(unionTypeInfo.getMethods(), CppRuntimeException);
316
317










2
    ASSERT_THROW(unionTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
318
}
319
320


802
TEST_F(TypeInfoTest, choiceTypeInfo)
321
{
322
    const ChoiceTypeInfo<std::allocator<uint8_t>> choiceTypeInfo(
323
2
            ""_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









2
    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










2
    ASSERT_THROW(choiceTypeInfo.getUnderlyingType(), CppRuntimeException);
337










2
    ASSERT_THROW(choiceTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
338










2
    ASSERT_THROW(choiceTypeInfo.getEnumItems(), CppRuntimeException);
339










2
    ASSERT_THROW(choiceTypeInfo.getBitmaskValues(), CppRuntimeException);
340
341










2
    ASSERT_THROW(choiceTypeInfo.getColumns(), CppRuntimeException);
342










2
    ASSERT_THROW(choiceTypeInfo.getSqlConstraint(), CppRuntimeException);
343










2
    ASSERT_THROW(choiceTypeInfo.getVirtualTableUsing(), CppRuntimeException);
344










2
    ASSERT_THROW(choiceTypeInfo.isWithoutRowId(), CppRuntimeException);
345
346









2
    ASSERT_THROW(choiceTypeInfo.getTables(), CppRuntimeException);
347
348



1
    ASSERT_EQ(""_sv, choiceTypeInfo.getTemplateName());
349



1
    ASSERT_EQ(0, choiceTypeInfo.getTemplateArguments().size());
350
351










2
    ASSERT_THROW(choiceTypeInfo.getMessages(), CppRuntimeException);
352
353









2
    ASSERT_THROW(choiceTypeInfo.getMethods(), CppRuntimeException);
354
355










2
    ASSERT_THROW(choiceTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
356
}
357
358


802
TEST_F(TypeInfoTest, sqlTableTypeInfo)
359
{
360
2
    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










2
    ASSERT_THROW(sqlTableTypeInfo.getBitSize(), CppRuntimeException);
365
366










2
    ASSERT_THROW(sqlTableTypeInfo.getFields(), CppRuntimeException);
367










2
    ASSERT_THROW(sqlTableTypeInfo.getParameters(), CppRuntimeException);
368










2
    ASSERT_THROW(sqlTableTypeInfo.getFunctions(), CppRuntimeException);
369
370










2
    ASSERT_THROW(sqlTableTypeInfo.getSelector(), CppRuntimeException);
371










2
    ASSERT_THROW(sqlTableTypeInfo.getCases(), CppRuntimeException);
372
373










2
    ASSERT_THROW(sqlTableTypeInfo.getUnderlyingType(), CppRuntimeException);
374










2
    ASSERT_THROW(sqlTableTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
375










2
    ASSERT_THROW(sqlTableTypeInfo.getEnumItems(), CppRuntimeException);
376









2
    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









2
    ASSERT_THROW(sqlTableTypeInfo.getTables(), CppRuntimeException);
384
385



1
    ASSERT_EQ(""_sv, sqlTableTypeInfo.getTemplateName());
386



1
    ASSERT_EQ(0, sqlTableTypeInfo.getTemplateArguments().size());
387
388










2
    ASSERT_THROW(sqlTableTypeInfo.getMessages(), CppRuntimeException);
389
390









2
    ASSERT_THROW(sqlTableTypeInfo.getMethods(), CppRuntimeException);
391
392










2
    ASSERT_THROW(sqlTableTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
393
}
394
395


802
TEST_F(TypeInfoTest, sqlDatabaseTypeInfo)
396
{
397
2
    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










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getBitSize(), CppRuntimeException);
402
403










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getFields(), CppRuntimeException);
404










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getParameters(), CppRuntimeException);
405










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getFunctions(), CppRuntimeException);
406
407










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getSelector(), CppRuntimeException);
408










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getCases(), CppRuntimeException);
409
410










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getUnderlyingType(), CppRuntimeException);
411










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
412










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getEnumItems(), CppRuntimeException);
413










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getBitmaskValues(), CppRuntimeException);
414
415










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getColumns(), CppRuntimeException);
416










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getSqlConstraint(), CppRuntimeException);
417










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getVirtualTableUsing(), CppRuntimeException);
418









2
    ASSERT_THROW(sqlDatabaseTypeInfo.isWithoutRowId(), CppRuntimeException);
419
420



1
    ASSERT_EQ(0, sqlDatabaseTypeInfo.getTables().size());
421
422










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getTemplateName(), CppRuntimeException);
423










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getTemplateArguments(), CppRuntimeException);
424
425










2
    ASSERT_THROW(sqlDatabaseTypeInfo.getMessages(), CppRuntimeException);
426
427









2
    ASSERT_THROW(sqlDatabaseTypeInfo.getMethods(), CppRuntimeException);
428
429










2
    ASSERT_THROW(sqlDatabaseTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
430
}
431
432


802
TEST_F(TypeInfoTest, enumTypeInfo)
433
{
434
1
    const ITypeInfo& underlyingTypeInfo = BuiltinTypeInfo<>::getInt8();
435
1
    std::array<ItemInfo, 1> enumItems = { ItemInfo("ONE"_sv, 1, false, false) };
436
2
    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










2
    ASSERT_THROW(enumTypeInfo.getBitSize(), CppRuntimeException);
441
442










2
    ASSERT_THROW(enumTypeInfo.getFields(), CppRuntimeException);
443










2
    ASSERT_THROW(enumTypeInfo.getParameters(), CppRuntimeException);
444










2
    ASSERT_THROW(enumTypeInfo.getFunctions(), CppRuntimeException);
445
446










2
    ASSERT_THROW(enumTypeInfo.getSelector(), CppRuntimeException);
447









2
    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










2
    ASSERT_THROW(enumTypeInfo.getBitmaskValues(), CppRuntimeException);
457
458










2
    ASSERT_THROW(enumTypeInfo.getColumns(), CppRuntimeException);
459










2
    ASSERT_THROW(enumTypeInfo.getSqlConstraint(), CppRuntimeException);
460










2
    ASSERT_THROW(enumTypeInfo.getVirtualTableUsing(), CppRuntimeException);
461










2
    ASSERT_THROW(enumTypeInfo.isWithoutRowId(), CppRuntimeException);
462
463










2
    ASSERT_THROW(enumTypeInfo.getTables(), CppRuntimeException);
464
465










2
    ASSERT_THROW(enumTypeInfo.getTemplateName(), CppRuntimeException);
466










2
    ASSERT_THROW(enumTypeInfo.getTemplateArguments(), CppRuntimeException);
467
468










2
    ASSERT_THROW(enumTypeInfo.getMessages(), CppRuntimeException);
469
470









2
    ASSERT_THROW(enumTypeInfo.getMethods(), CppRuntimeException);
471
472










2
    ASSERT_THROW(enumTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
473
}
474
475


802
TEST_F(TypeInfoTest, bitmaskTypeInfo)
476
{
477
1
    const ITypeInfo& underlyingTypeInfo = BuiltinTypeInfo<>::getInt8();
478
1
    std::array<ItemInfo, 1> bitmaskValues = { ItemInfo("FIRST_BIT"_sv, 1, false, false )};
479
    const BitmaskTypeInfo<std::allocator<uint8_t>> bitmaskTypeInfo(""_sv, underlyingTypeInfo, {},
480
2
            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










2
    ASSERT_THROW(bitmaskTypeInfo.getBitSize(), CppRuntimeException);
485
486










2
    ASSERT_THROW(bitmaskTypeInfo.getFields(), CppRuntimeException);
487










2
    ASSERT_THROW(bitmaskTypeInfo.getParameters(), CppRuntimeException);
488










2
    ASSERT_THROW(bitmaskTypeInfo.getFunctions(), CppRuntimeException);
489
490










2
    ASSERT_THROW(bitmaskTypeInfo.getSelector(), CppRuntimeException);
491









2
    ASSERT_THROW(bitmaskTypeInfo.getCases(), CppRuntimeException);
492
493



1
    ASSERT_EQ(&underlyingTypeInfo, &bitmaskTypeInfo.getUnderlyingType());
494



1
    ASSERT_EQ(0, bitmaskTypeInfo.getUnderlyingTypeArguments().size());
495









2
    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










2
    ASSERT_THROW(bitmaskTypeInfo.getColumns(), CppRuntimeException);
503










2
    ASSERT_THROW(bitmaskTypeInfo.getSqlConstraint(), CppRuntimeException);
504










2
    ASSERT_THROW(bitmaskTypeInfo.getVirtualTableUsing(), CppRuntimeException);
505










2
    ASSERT_THROW(bitmaskTypeInfo.isWithoutRowId(), CppRuntimeException);
506
507










2
    ASSERT_THROW(bitmaskTypeInfo.getTables(), CppRuntimeException);
508
509










2
    ASSERT_THROW(bitmaskTypeInfo.getTemplateName(), CppRuntimeException);
510










2
    ASSERT_THROW(bitmaskTypeInfo.getTemplateArguments(), CppRuntimeException);
511
512










2
    ASSERT_THROW(bitmaskTypeInfo.getMessages(), CppRuntimeException);
513
514









2
    ASSERT_THROW(bitmaskTypeInfo.getMethods(), CppRuntimeException);
515
516










2
    ASSERT_THROW(bitmaskTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
517
}
518
519


802
TEST_F(TypeInfoTest, pubsubTypeInfo)
520
{
521
2
    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










2
    ASSERT_THROW(pubsubTypeInfo.getBitSize(), CppRuntimeException);
526
527










2
    ASSERT_THROW(pubsubTypeInfo.getFields(), CppRuntimeException);
528










2
    ASSERT_THROW(pubsubTypeInfo.getParameters(), CppRuntimeException);
529










2
    ASSERT_THROW(pubsubTypeInfo.getFunctions(), CppRuntimeException);
530
531










2
    ASSERT_THROW(pubsubTypeInfo.getSelector(), CppRuntimeException);
532










2
    ASSERT_THROW(pubsubTypeInfo.getCases(), CppRuntimeException);
533
534










2
    ASSERT_THROW(pubsubTypeInfo.getUnderlyingType(), CppRuntimeException);
535










2
    ASSERT_THROW(pubsubTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
536










2
    ASSERT_THROW(pubsubTypeInfo.getEnumItems(), CppRuntimeException);
537










2
    ASSERT_THROW(pubsubTypeInfo.getBitmaskValues(), CppRuntimeException);
538
539










2
    ASSERT_THROW(pubsubTypeInfo.getColumns(), CppRuntimeException);
540










2
    ASSERT_THROW(pubsubTypeInfo.getSqlConstraint(), CppRuntimeException);
541










2
    ASSERT_THROW(pubsubTypeInfo.getVirtualTableUsing(), CppRuntimeException);
542










2
    ASSERT_THROW(pubsubTypeInfo.isWithoutRowId(), CppRuntimeException);
543
544










2
    ASSERT_THROW(pubsubTypeInfo.getTables(), CppRuntimeException);
545
546










2
    ASSERT_THROW(pubsubTypeInfo.getTemplateName(), CppRuntimeException);
547









2
    ASSERT_THROW(pubsubTypeInfo.getTemplateArguments(), CppRuntimeException);
548
549



1
    ASSERT_EQ(0, pubsubTypeInfo.getMessages().size());
550
551









2
    ASSERT_THROW(pubsubTypeInfo.getMethods(), CppRuntimeException);
552
553










2
    ASSERT_THROW(pubsubTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
554
}
555
556


802
TEST_F(TypeInfoTest, serviceTypeInfo)
557
{
558
2
    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










2
    ASSERT_THROW(serviceTypeInfo.getBitSize(), CppRuntimeException);
563
564










2
    ASSERT_THROW(serviceTypeInfo.getFields(), CppRuntimeException);
565










2
    ASSERT_THROW(serviceTypeInfo.getParameters(), CppRuntimeException);
566










2
    ASSERT_THROW(serviceTypeInfo.getFunctions(), CppRuntimeException);
567
568










2
    ASSERT_THROW(serviceTypeInfo.getSelector(), CppRuntimeException);
569










2
    ASSERT_THROW(serviceTypeInfo.getCases(), CppRuntimeException);
570
571










2
    ASSERT_THROW(serviceTypeInfo.getUnderlyingType(), CppRuntimeException);
572










2
    ASSERT_THROW(serviceTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
573










2
    ASSERT_THROW(serviceTypeInfo.getEnumItems(), CppRuntimeException);
574










2
    ASSERT_THROW(serviceTypeInfo.getBitmaskValues(), CppRuntimeException);
575
576










2
    ASSERT_THROW(serviceTypeInfo.getColumns(), CppRuntimeException);
577










2
    ASSERT_THROW(serviceTypeInfo.getSqlConstraint(), CppRuntimeException);
578










2
    ASSERT_THROW(serviceTypeInfo.getVirtualTableUsing(), CppRuntimeException);
579










2
    ASSERT_THROW(serviceTypeInfo.isWithoutRowId(), CppRuntimeException);
580
581










2
    ASSERT_THROW(serviceTypeInfo.getTables(), CppRuntimeException);
582
583










2
    ASSERT_THROW(serviceTypeInfo.getTemplateName(), CppRuntimeException);
584










2
    ASSERT_THROW(serviceTypeInfo.getTemplateArguments(), CppRuntimeException);
585
586









2
    ASSERT_THROW(serviceTypeInfo.getMessages(), CppRuntimeException);
587
588



1
    ASSERT_EQ(0, serviceTypeInfo.getMethods().size());
589
590










2
    ASSERT_THROW(serviceTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
591
}
592
593


802
TEST_F(TypeInfoTest, recursiveTypeInfo)
594
{
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









2
    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










2
    ASSERT_THROW(recursiveTypeInfo.getSelector(), CppRuntimeException);
608










2
    ASSERT_THROW(recursiveTypeInfo.getCases(), CppRuntimeException);
609
610










2
    ASSERT_THROW(recursiveTypeInfo.getUnderlyingType(), CppRuntimeException);
611










2
    ASSERT_THROW(recursiveTypeInfo.getUnderlyingTypeArguments(), CppRuntimeException);
612










2
    ASSERT_THROW(recursiveTypeInfo.getEnumItems(), CppRuntimeException);
613










2
    ASSERT_THROW(recursiveTypeInfo.getBitmaskValues(), CppRuntimeException);
614
615










2
    ASSERT_THROW(recursiveTypeInfo.getColumns(), CppRuntimeException);
616










2
    ASSERT_THROW(recursiveTypeInfo.getSqlConstraint(), CppRuntimeException);
617










2
    ASSERT_THROW(recursiveTypeInfo.getVirtualTableUsing(), CppRuntimeException);
618










2
    ASSERT_THROW(recursiveTypeInfo.isWithoutRowId(), CppRuntimeException);
619
620









2
    ASSERT_THROW(recursiveTypeInfo.getTables(), CppRuntimeException);
621
622




1
    ASSERT_EQ(typeInfo.getTemplateName(), recursiveTypeInfo.getTemplateName());
623




1
    ASSERT_EQ(0, recursiveTypeInfo.getTemplateArguments().size());
624
625










2
    ASSERT_THROW(recursiveTypeInfo.getMessages(), CppRuntimeException);
626
627









2
    ASSERT_THROW(recursiveTypeInfo.getMethods(), CppRuntimeException);
628
629











2
    ASSERT_THROW(recursiveTypeInfo.createInstance(std::allocator<uint8_t>()), CppRuntimeException);
630









2
    ASSERT_THROW(recursiveTypeInfo.createInstance(), CppRuntimeException);
631
}
632
633

2394
} // namespace zserio