# 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 # . # # 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" - "mongo/db/auth/access_checks.idl" - "mongo/db/auth/action_type.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 reply_type_struct: description: Used for testing the IDL command reply_type field fields: reply_field: int ################################################################################################## # # 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_safeint64: description: UnitTest for a single safeInt64 fields: value: safeInt64 ################################################################################################## # # Test fields with default values # ################################################################################################## default_values: description: UnitTest for default values 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 always_serialize_field: description: UnitTest for always_serialize fields fields: field1: type: string always_serialize: true optional: true field2: type: int always_serialize: true optional: true field3: type: object always_serialize: true optional: true field4: type: object always_serialize: true optional: true field5: type: object always_serialize: false optional: true ################################################################################################## # # Test array of simple types # ################################################################################################## simple_int_array: description: UnitTest for arrays of ints fields: field1: type: array simple_array_fields: description: UnitTest for arrays of simple types fields: field1: type: array field2: type: array field3: type: array field4: type: array field5: type: array optional_array_fields: description: UnitTest for arrays of optional simple types fields: field1: type: array optional: true field2: type: array optional: true field3: type: array optional: true field4: type: array optional: true field5: type: array 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 field2: type: array field3: type: array field4: type: array field5: type: array field6: type: array field1o: type: array optional: true field2o: type: array optional: true field3o: type: array optional: true field4o: type: array optional: true field5o: type: array optional: true field6o: type: array 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 field1o: type: string optional: true field2o: type: int optional: true field3o: type: object optional: true field4o: type: bindata_generic optional: true field5o: type: bindata_uuid optional: true 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 ################################################################################################## # # Test struct with variant # ################################################################################################## one_variant: description: UnitTest for a single variant which accepts int or string strict: false fields: value: type: variant: [int, string] one_variant_safeInt: description: UnitTest for a single variant with an alternative type which has multiple BSON serialization types strict: false fields: value: type: variant: [safeInt, string] one_variant_compound: description: UnitTest for a single variant which accepts string, doc, or array of string strict: false fields: value: type: variant: - string - object - array one_variant_struct: description: UnitTest for a single variant which accepts an int or a struct strict: false fields: value: type: variant: - int - one_string one_variant_safeInt_array: description: UnitTest for a single variant which accepts a string or array of safeInt strict: false fields: value: type: variant: - string - array one_variant_struct_array: description: UnitTest for a single variant which accepts an int or array of structs strict: false fields: value: type: variant: - int - array one_variant_two_arrays: description: UnitTest for a single variant which accepts array of int or array of string strict: false fields: value: type: variant: - array - array one_variant_optional: description: UnitTest for a single optional variant strict: false fields: value: type: variant: [int, string] optional: true two_variants: description: UnitTest for a struct with two variant fields strict: false fields: value0: type: variant: [int, string] value1: type: variant: [object, array] chained_struct_variant: description: Struct with chained variant strict: false inline_chained_structs: false chained_structs: one_variant_compound: one_variant_compound fields: field1: string chained_struct_variant_inline: description: Struct with inline chained variant strict: false inline_chained_structs: true chained_structs: one_variant_compound: one_variant_compound fields: field1: string chained_struct_variant_struct: description: Struct with chained variant that has a struct alternative type strict: false inline_chained_structs: false chained_structs: one_variant_struct: one_variant_struct fields: field1: string chained_struct_variant_struct_inline: description: Struct with inline chained variant that has a struct alternative type strict: false inline_chained_structs: true chained_structs: one_variant_struct: one_variant_struct fields: field1: string ################################################################################################## # # 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'>" } chained_validators: description: Uses a chained struct that includes fields with validators chained_structs: int_basic_ranges: int_basic_ranges unusual_callback_validators: description: Struct using fields with unusual callback validators fields: int_even: type: int optional: true validator: { callback: 'validateEvenNumber' } string_starts_with_x: type: string optional: true validator: { callback: "validateStartsWith<'x'>" } array_of_int: type: array validator: { callback: "validateEvenNumber" } array_of_int_optional: type: array optional: true validator: { callback: "validateEvenNumber" } one_int: type: one_int validator: { callback: 'validateOneInt' } one_int_optional: type: one_int optional: true validator: { callback: 'validateOneInt' } one_int_array: type: array validator: { callback: 'validateOneInt' } ################################################################################################## # # Test commands # ################################################################################################## commands: BasicIgnoredCommand: description: UnitTest for a basic ignored command command_name: BasicIgnoredCommand namespace: ignored api_version: "" fields: field1: int field2: string BasicConcatenateWithDbCommand: description: UnitTest for a basic concatenate_with_db command command_name: BasicConcatenateWithDbCommand namespace: concatenate_with_db api_version: "" fields: field1: int field2: string BasicConcatenateWithDbOrUUIDCommand: description: UnitTest for a basic concatenate_with_db_or_uuid command command_name: BasicConcatenateWithDbOrUUIDCommand namespace: concatenate_with_db_or_uuid api_version: "" fields: field1: int field2: string BasicNamespaceConstGetterCommand: description: UnitTest for a basic concatenate_with_db_or_uuid command command_name: BasicNamespaceConstGetterCommand namespace: concatenate_with_db_or_uuid api_version: "" non_const_getter: true fields: field1: int KnownFieldCommand: description: UnitTest for a command that has a field that is special known generic command field command_name: KnownFieldCommand namespace: concatenate_with_db api_version: "" fields: field1: int maxTimeMS: int DocSequenceCommand: description: UnitTest for a basic command with fields marked with supports_doc_sequence command_name: DocSequenceCommand namespace: concatenate_with_db api_version: "" fields: field1: int field2: string structs: type: array supports_doc_sequence: true objects: type: array supports_doc_sequence: true objects_custom: type: array supports_doc_sequence: true optional: true DocSequenceCommandNonStrict: description: UnitTest for a basic command with fields marked with supports_doc_sequence and non-strict parsing command_name: DocSequenceCommandNonStrict namespace: concatenate_with_db api_version: "" strict: false fields: field1: int field2: string structs: type: array supports_doc_sequence: true objects: type: array supports_doc_sequence: true objects_custom: type: array supports_doc_sequence: true optional: true chained_command_type_mixed: description: Chained command with chained types, structs, and fields command_name: chained_command_type_mixed namespace: concatenate_with_db api_version: "" 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 command_name: CommandTypeStringCommand namespace: type api_version: "" type: string fields: field1: int CommandTypeArrayObjectCommand: description: Command with just an array of object parameter command_name: CommandTypeArrayObjectCommand namespace: type api_version: "" type: array CommandTypeStructCommand: description: Command with just a struct parameter command_name: CommandTypeStructCommand namespace: type api_version: "" type: one_string CommandTypeArrayStructCommand: description: Command with just an array of struct parameter command_name: CommandTypeArrayStructCommand namespace: type api_version: "" type: array CommandTypeStructValidatorCommand: description: Command with a struct type that has a validator command_name: CommandTypeStructValidatorCommand namespace: type api_version: "" type: int_basic_ranges CommandTypeVariantCommand: description: Command with a variant parameter command_name: CommandTypeVariantCommand namespace: type api_version: "" type: variant: [int, string, array] CommandTypeVariantStructCommand: description: Command with a variant parameter that can be a struct command_name: CommandTypeVariantStructCommand namespace: type api_version: "" type: variant: [bool, one_string] _underscore_command: description: Command with custom type string command_name: _underscore_command namespace: type api_version: "" type: string cpp_name: WellNamedCommand fields: field1: int int_type_command: description: Command with custom type int command_name: int_type_command namespace: type api_version: "" type: int fields: field1: int int_array_type_command: description: Command with custom type for array of int command_name: int_array_type_command namespace: type api_version: "" type: array fields: field1: int validated_command: description: Renamed command with validator command_name: validated_command namespace: ignored api_version: "" cpp_name: doubleBasicRanges fields: positive_double: type: double validator: { gt: 0.0 } negative_double: type: double validator: { lt: 0.0 } CommandWithReplyType: description: A command with its reply type specified by an IDL struct command_name: CommandWithReplyType namespace: ignored api_version: "" reply_type: reply_type_struct CommandWithOkReply: description: "A mock command that replies with only {ok: 1}" command_name: CommandWithOkReply namespace: ignored api_version: "" reply_type: OkReply CommandWithAnyTypeMember: description: "A mock command to test IDLAnyType" command_name: CommandWithValueTypeMember namespace: ignored api_version: "" reply_type: OkReply fields: anyTypeField: IDLAnyType CommandWithAnyTypeOwnedMember: description: "A mock command to test IDLAnyTypeOwned" command_name: CommandWithAnyTypeOwnedMember namespace: ignored api_version: "" reply_type: OkReply fields: anyTypeField: IDLAnyTypeOwned AccessCheckNone: description: A versioned API command with access_check and none command_name: AccessCheckNoneCommandName namespace: ignored strict: true api_version: "1" access_check: none: true reply_type: OkReply AccessCheckSimpleAccessCheck: description: A versioned API command with access_check and simple check command_name: AccessCheckSimpleAccessCheckCommandName namespace: ignored strict: true api_version: "1" access_check: simple: check: is_authenticated reply_type: OkReply AccessCheckSimplePrivilege: description: A versioned API command with access_check and privilege command_name: AccessCheckSimplePrivilegeCommandName namespace: ignored strict: true api_version: "1" access_check: simple: privilege: resource_pattern: cluster action_type: [addShard, serverStatus] reply_type: OkReply AccessCheckComplexPrivilege: description: A versioned API command with access_check complex command_name: AccessCheckComplexPrivilegeCommandName namespace: ignored strict: true api_version: "1" access_check: complex: - privilege: resource_pattern: cluster action_type: [addShard, serverStatus] - privilege: resource_pattern: database action_type: trafficRecord - privilege: resource_pattern: any action_type: splitVector - check: is_authenticated - check: is_authorized_to_parse_namespace_element reply_type: OkReply # Test that we correctly generate C++ base classes for versioned API commands with different # key names, command names, and C++ names. APIVersion1CommandIDLName: description: A versioned API command command_name: APIVersion1CommandRuntimeName namespace: ignored strict: true api_version: "1" access_check: none: true reply_type: OkReply APIVersion1CommandIDLName2: description: A versioned API command command_name: APIVersion1CommandRuntimeName2 cpp_name: APIVersion1CommandCPPName2 namespace: ignored strict: true api_version: "1" access_check: none: true reply_type: OkReply # Test whether the C++ code for a command with alias name is currently generated. APIVersion1CommandWithAlias: description: A versioned API command with alias command_name: NewCommandName command_alias: OldCommandName namespace: ignored strict: true api_version: "1" access_check: none: true reply_type: OkReply ################################################################################################## # # Test field lists # ################################################################################################## generic_argument_lists: my_generic_args_list: description: UnitTest for generic arguments list fields: my_generic_field_0: forward_to_shards: false my_generic_field_1: forward_to_shards: true my_generic_field_3: {} generic_reply_field_lists: my_generic_reply_field_list: description: UnitTest for generic reply fields list fields: my_generic_field_0: forward_from_shards: false my_generic_field_1: forward_from_shards: true my_generic_field_3: {}