summaryrefslogtreecommitdiff
path: root/src/mongo/idl/unittest.idl
blob: 6b6337ed69ad6b9e22cca511f9a0456dc9dfbc65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# Copyright (C) 2017 MongoDB Inc.
#
# This program is free software: you can redistribute it and/or  modify
# it under the terms of the GNU Affero General Public License, version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# IDL Unit Tests IDL file
global:
    # Use a nested namespace simply to exercise nested namespace support for the code generator.
    cpp_namespace: "mongo::idl::test"
    cpp_includes:
        - "mongo/db/namespace_string.h"
        - "mongo/idl/idl_test_types.h"

imports:
    - "mongo/idl/basic_types.idl"
    - "mongo/idl/unittest_import.idl"

types:
##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for a string type
#
##################################################################################################

    namespacestring:
        bson_serialization_type: string
        description: "A MongoDB NamespaceString"
        cpp_type: "mongo::NamespaceString"
        serializer: mongo::NamespaceString::toString
        deserializer: mongo::NamespaceString

##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for a bindata type
#
##################################################################################################

    bindata_custom:
        bson_serialization_type: bindata
        bindata_subtype: generic
        description: "A MongoDB BinDataCustomType"
        cpp_type: "mongo::BinDataCustomType"
        serializer: mongo::BinDataCustomType::serialize
        deserializer: mongo::BinDataCustomType::parse

##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for an any type
#
##################################################################################################

    any_basic_type:
        bson_serialization_type: any
        description: "An Any Type"
        cpp_type: "mongo::AnyBasicType"
        serializer: mongo::AnyBasicType::serialize
        deserializer: mongo::AnyBasicType::parse

##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for an object type
#
##################################################################################################

    object_basic_type:
        bson_serialization_type: object
        description: "An object Type"
        cpp_type: "mongo::ObjectBasicType"
        serializer: mongo::ObjectBasicType::serialize
        deserializer: mongo::ObjectBasicType::parse

##################################################################################################
#
# Test types that accept multiple serialization types
#
##################################################################################################

    safeInt32:
        description: Accepts any numerical type within int32 range
        cpp_type: std::int64_t
        bson_serialization_type: 
                                - long
                                - int
                                - decimal
                                - double
        deserializer: "mongo::BSONElement::numberInt"

##################################################################################################
#
# Test types used in parser chaining testing
#
##################################################################################################

    ChainedType:
        bson_serialization_type: chain
        description: "An Chain Type to test chaining"
        cpp_type: "mongo::ChainedType"
        serializer: mongo::ChainedType::serialize
        deserializer: mongo::ChainedType::parse

    AnotherChainedType:
        bson_serialization_type: chain
        description: "Another Chain Type to test chaining"
        cpp_type: "mongo::AnotherChainedType"
        serializer: mongo::AnotherChainedType::serialize
        deserializer: mongo::AnotherChainedType::parse


##################################################################################################
#
# Unit test structs for a single value to ensure type validation works correctly
#
##################################################################################################

structs:

    one_plain_object:
        description: UnitTest for a single BSONObj
        fields:
            value: object


##################################################################################################
#
# Structs to test derived parsers
#
##################################################################################################

    DerivedBaseStruct:
        description: UnitTest for parser that will derive from a type
        fields:
            field1: int
            field2: int


##################################################################################################
#
# Structs to test various options for structs/fields
#
##################################################################################################
    RequiredStrictField3:
        description: UnitTest for a strict struct with 3 required fields
        fields:
            field1: int
            field2: int
            field3: int

    RequiredNonStrictField3:
        description: UnitTest for a non-strict struct with 3 required fields
        strict: false
        fields:
            1:
                type: int
                cpp_name: field1
            2:
                type: int
                cpp_name: field2
            3:
                type: int
                cpp_name: field3


##################################################################################################
#
# Nested Structs with duplicate types
#
##################################################################################################
    NestedWithDuplicateTypes:
        description: UnitTest for a non-strict struct with 3 required fields
        strict: false
        fields:
            field1: RequiredStrictField3
            field2: 
                type: RequiredNonStrictField3
                optional: true
            field3: RequiredStrictField3

##################################################################################################
#
# Structs to test various options for fields
#
##################################################################################################
    ignoredField:
        description: UnitTest for a struct with an ignored_field
        fields:
            required_field: int
            ignored_field:
                type: int
                ignore: true


##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for a string type
#
##################################################################################################

    one_namespacestring:
        description: UnitTest for a single namespacestring
        fields:
            value: namespacestring

##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for a bindata type
#
##################################################################################################

    one_bindata_custom:
        description: UnitTest for a custom bindata
        fields:
            value: bindata_custom

##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for an any type
#
##################################################################################################

    one_any_basic_type:
        description: UnitTest for a single any type
        fields:
            value: any_basic_type


##################################################################################################
#
# Test a custom non-BSONElement deserialization and serialization methods for an object type
#
##################################################################################################

    one_object_basic_type:
        description: UnitTest for a single object type
        fields:
            value: object_basic_type


##################################################################################################
#
# Test types that accept multiple serialization types
#
##################################################################################################

    one_safeint32:
        description: UnitTest for a single safeInt32
        fields:
            value: safeInt32

##################################################################################################
#
# Test fields with default values
#
##################################################################################################

    default_values:
        description: UnitTest for a single safeInt32
        fields:
            V_string:
                type: string
                default: '"a default"'
            V_int:
                type: int
                default: 42
            V_long:
                type: long
                default: 423
            V_double:
                type: double
                default: 3.14159
            V_bool:
                type: bool
                default: true

##################################################################################################
#
# Test fields with optional values
#
##################################################################################################

    optional_field:
        description: UnitTest for a optional field
        fields:
            field1:
                type: string
                optional: true
            field2:
                type: int
                optional: true
            field3:
                type: object
                optional: true
            field4:
                type: bindata_generic
                optional: true
            field5:
                type: bindata_uuid
                optional: true

##################################################################################################
#
# Test array of simple types
#
##################################################################################################
    simple_int_array:
        description: UnitTest for arrays of ints
        fields:
            field1:
                type: array<int>

    simple_array_fields:
        description: UnitTest for arrays of simple types
        fields:
            field1:
                type: array<string>
            field2:
                type: array<int>
            field3:
                type: array<double>
            field4:
                type: array<bindata_generic>
            field5:
                type: array<bindata_uuid>

    optional_array_fields:
        description: UnitTest for arrays of optional simple types
        fields:
            field1:
                type: array<string>
                optional: true
            field2:
                type: array<int>
                optional: true
            field3:
                type: array<double>
                optional: true
            field4:
                type: array<bindata_generic>
                optional: true
            field5:
                type: array<bindata_uuid>
                optional: true

##################################################################################################
#
# Test array of complex types
#
##################################################################################################

    complex_array_fields:
        description: UnitTest for arrays of complex optional and non-optional simple types
        fields:
            field1:
                type: array<safeInt32>
            field2:
                type: array<namespacestring>
            field3:
                type: array<any_basic_type>
            field4:
                type: array<object_basic_type>
            field5:
                type: array<object>
            field6:
                type: array<one_string>
            field1o:
                type: array<safeInt32>
                optional: true
            field2o:
                type: array<namespacestring>
                optional: true
            field3o:
                type: array<any_basic_type>
                optional: true
            field4o:
                type: array<object_basic_type>
                optional: true
            field5o:
                type: array<object>
                optional: true
            field6o:
                type: array<one_string>
                optional: true

##################################################################################################
#
# Test Chained Types
#
##################################################################################################

    chained_string_basic_type:
        description: Base struct type for a chained string
        strict: false
        fields:
            stringField: string

    chained_any_basic_type:
        description: Base struct type for a chained any
        strict: false
        fields:
            anyField: any_basic_type

    chained_object_basic_type:
        description: Base struct type for a chained object
        strict: false
        fields:
            objectField: object_basic_type

    chained_struct_only:
        description: UnitTest for chained struct with only chained types
        strict: false
        chained_types:
            - ChainedType
            - AnotherChainedType

    chained_struct_mixed:
        description: Chained struct with chained structs and fields
        strict: true
        chained_structs:
            - chained_any_basic_type
            - chained_object_basic_type
        fields:
            field3: string

    chained_struct_type_mixed:
        description: Chained struct with chained types, structs, and fields
        strict: false
        chained_types:
            - ChainedType
            - AnotherChainedType
        chained_structs:
            - chained_string_basic_type
        fields:
            field3:
                type: int