summaryrefslogtreecommitdiff
path: root/src/mongo/idl/unittest.idl
blob: ac25607aa6edb3f5322a4ceee2f741f6cd137922 (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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# Copyright (C) 2018-present MongoDB, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the Server Side Public License, version 1,
# as published by MongoDB, Inc.
#
# 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
# Server Side Public License for more details.
#
# You should have received a copy of the Server Side Public License
# along with this program. If not, see
# <http://www.mongodb.com/licensing/server-side-public-license>.
#
# As a special exception, the copyright holders give permission to link the
# code of portions of this program with the OpenSSL library under certain
# conditions as described in each individual source file and distribute
# linked combinations including the program with the OpenSSL library. You
# must comply with the Server Side Public License in all respects for
# all of the code used other than as permitted herein. If you modify file(s)
# with this exception, you may extend this exception to your version of the
# file(s), but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version. If you delete this
# exception statement from all source files in the program, then also delete
# it in the license file.
#

# 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/idl/idl_test_types.h"
        - "mongo/idl/idl_test.h"

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

types:

##################################################################################################
#
# 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::serializeToBSON
        deserializer: mongo::BinDataCustomType::parseFromBSON

##################################################################################################
#
# 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::serializeToBSON
        deserializer: mongo::AnyBasicType::parseFromBSON

##################################################################################################
#
# 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::serializeToBSON
        deserializer: mongo::ObjectBasicType::parseFromBSON

##################################################################################################
#
# 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::serializeToBSON
        deserializer: mongo::ChainedType::parseFromBSON

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


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

    StringEnum:
        description: "An example string enum"
        type: string
        values:
            s0: "zero"
            s1: "one"
            s2: "two"

structs:

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

    one_plain_optional_object:
        description: UnitTest for optional BSONObj
        generate_comparison_operators: true
        fields:
            value: object
            value2: object
            opt_value:
                type: object
                optional: true
            opt_value2:
                type: object
                optional: true

##################################################################################################
#
# 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: cppField1
            2:
                type: int
                cpp_name: cppField2
            3:
                type: int
                cpp_name: cppField3

##################################################################################################
#
# Structs to test comparison options
#
##################################################################################################
    CompareAllField3:
        description: UnitTest for a struct with 3 int fields to test comparison
        generate_comparison_operators: true
        fields:
            field1: int
            field2: int
            field3: int

    CompareSomeField3:
        description: |
            UnitTest for a struct with 3 int fields to test comparison, but only 2 are compared.
        generate_comparison_operators: true
        fields:
            field3:
                type: int
                comparison_order: 3
            field2: int
            field1:
                type: int
                comparison_order: 1

##################################################################################################
#
# 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 : ChainedType
            AnotherChainedType : AnotherChainedType

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

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

    chained_string_inline_basic_type:
        description: Base struct type for a chained string
        strict: true
        fields:
            stringField: string

    chained_struct_inline:
        description: Chained struct with chained structs and fields
        strict: true
        inline_chained_structs: true
        chained_structs:
            chained_string_inline_basic_type : chained_string_inline_basic_type
        fields:
            field3: string


##################################################################################################
#
# Test struct with enum
#
##################################################################################################
    one_int_enum:
        description: mock
        fields:
            value: IntEnum

    one_string_enum:
        description: mock
        fields:
            value: StringEnum

    StructWithEnum:
        description: mock
        fields:
            field1: IntEnum
            field2: StringEnum
            field1o:
                type: IntEnum
                optional: true
            field2o:
                type: StringEnum
                optional: true
            fieldDefault:
                type: StringEnum
                default: s1

##################################################################################################
#
# Using Validators
#
##################################################################################################

    int_basic_ranges:
        description: Struct using basic range validators on ints
        fields:
            positive_int:
                type: int
                validator: { gt: 0 }
            negative_int:
                type: int
                validator: { lt: 0 }
            non_negative_int:
                type: int
                validator: { gte: 0 }
            non_positive_int:
                type: int
                validator: { lte: 0 }
            byte_range_int:
                type: int
                validator: { gte: 0, lt: 256 }
            range_int:
                type: int
                # Use INT32_MIN+1 for min since MSVC does not like -2147483647 as a constant.
                validator: { gte: -2147483647, lte: 2147483647 }

    double_basic_ranges:
        description: Struct using basic range validators on doubles
        fields:
            positive_double:
                type: double
                validator: { gt: 0.0 }
            negative_double:
                type: double
                validator: { lt: 0.0 }
            non_negative_double:
                type: double
                validator: { gte: 0.0 }
            non_positive_double:
                type: double
                validator: { lte: 0.0 }
            range_double:
                type: double
                validator: { gte: -12345678901234500000, lte: 12345678901234500000 }

    callback_validators:
        description: Struct using fields with callback validators
        fields:
            int_even:
                type: int
                validator: { callback: 'validateEvenNumber' }
            double_nearly_int:
                type: double
                validator: { callback: 'validateNearlyInt' }
            string_starts_with_x:
                type: string
                validator: { callback: "validateStartsWith<'x'>" }
            string_starts_with_x2:
                type: string
                optional: true
                validator: { callback: "validateStartsWith<'x'>" }


##################################################################################################
#
# Test commands
#
##################################################################################################

commands:
    BasicIgnoredCommand:
        description: UnitTest for a basic ignored command
        namespace: ignored
        fields:
            field1: int
            field2: string

    BasicConcatenateWithDbCommand:
        description: UnitTest for a basic concatenate_with_db command
        namespace: concatenate_with_db
        fields:
            field1: int
            field2: string

    KnownFieldCommand:
        description: UnitTest for a command that has a field that is special known generic command field
        namespace: concatenate_with_db
        fields:
            field1: int
            maxTimeMS: int

    DocSequenceCommand:
        description: UnitTest for a basic command with fields marked with supports_doc_sequence
        namespace: concatenate_with_db
        fields:
            field1: int
            field2: string
            structs:
                type: array<one_string>
                supports_doc_sequence: true
            objects:
                type: array<object>
                supports_doc_sequence: true
            objects_custom:
                type: array<object_basic_type>
                supports_doc_sequence: true
                optional: true

    DocSequenceCommandNonStrict:
        description: UnitTest for a basic command with fields marked with supports_doc_sequence and non-strict parsing
        namespace: concatenate_with_db
        strict: false
        fields:
            field1: int
            field2: string
            structs:
                type: array<one_string>
                supports_doc_sequence: true
            objects:
                type: array<object>
                supports_doc_sequence: true
            objects_custom:
                type: array<object_basic_type>
                supports_doc_sequence: true
                optional: true

    chained_command_type_mixed:
        description: Chained command with chained types, structs, and fields
        namespace: concatenate_with_db
        strict: false
        chained_types:
            ChainedType : chained_type
            AnotherChainedType:
                cpp_name: AnotherChainedType
        chained_structs:
            chained_string_basic_type:
                cpp_name: ChainedStringBasicType
        fields:
            field3:
                type: int

    CommandTypeStringCommand:
        description: Command with custom type string
        namespace: type
        type: string
        fields:
            field1: int

    CommandTypeArrayObjectCommand:
        description: Command with just an array of object parameter
        namespace: type
        type: array<object>

    CommandTypeStructCommand:
        description: Command with just a struct parameter
        namespace: type
        type: one_string

    CommandTypeArrayStructCommand:
        description: Command with just an array of struct parameter
        namespace: type
        type: array<one_string>

    _underscore_command:
        description: Command with custom type string
        namespace: type
        type: string
        cpp_name: WellNamedCommand
        fields:
            field1: int

    int_type_command:
        description: Command with custom type int
        namespace: type
        type: int
        fields:
            field1: int

    int_array_type_command:
        description: Command with custom type for array of int
        namespace: type
        type: array<int>
        fields:
            field1: int