diff options
author | Hugh Tong <hugh.tong@mongodb.com> | 2023-03-01 20:20:24 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-03-02 01:30:20 +0000 |
commit | 95069850eaaa9a1eacf20d0ac082e4773da97ce3 (patch) | |
tree | f71f65afc0038c53dd430a5a0f2e2d7d63f2defa /buildscripts/idl | |
parent | 7a80f01c3a56292904a87856ea60124beab5c44a (diff) | |
download | mongo-95069850eaaa9a1eacf20d0ac082e4773da97ce3.tar.gz |
SERVER-73109 Build idl infrastructure to pass context to nss serializers
Diffstat (limited to 'buildscripts/idl')
-rw-r--r-- | buildscripts/idl/idl/ast.py | 1 | ||||
-rw-r--r-- | buildscripts/idl/idl/binder.py | 31 | ||||
-rw-r--r-- | buildscripts/idl/idl/cpp_types.py | 34 | ||||
-rw-r--r-- | buildscripts/idl/idl/generator.py | 81 | ||||
-rw-r--r-- | buildscripts/idl/idl/parser.py | 1 | ||||
-rw-r--r-- | buildscripts/idl/idl/syntax.py | 1 | ||||
-rw-r--r-- | buildscripts/idl/tests/test_binder.py | 176 | ||||
-rw-r--r-- | buildscripts/idl/tests/test_generator.py | 7 | ||||
-rw-r--r-- | buildscripts/idl/tests/test_import.py | 17 |
9 files changed, 201 insertions, 148 deletions
diff --git a/buildscripts/idl/idl/ast.py b/buildscripts/idl/idl/ast.py index 6198670eb7e..af98c74d61a 100644 --- a/buildscripts/idl/idl/ast.py +++ b/buildscripts/idl/idl/ast.py @@ -108,6 +108,7 @@ class Type(common.SourceLocation): self.variant_struct_types = None # type: List[Type] self.first_element_field_name = None # type: str self.deserialize_with_tenant = False # type: bool + self.internal_only = False # type: bool super(Type, self).__init__(file_name, line, column) diff --git a/buildscripts/idl/idl/binder.py b/buildscripts/idl/idl/binder.py index 8213dbb262b..e48bfc6f5d8 100644 --- a/buildscripts/idl/idl/binder.py +++ b/buildscripts/idl/idl/binder.py @@ -186,8 +186,9 @@ def _validate_type_properties(ctxt, idl_type, syntax_type): if bson_type == "any": # For 'any', a deserializer is required but the user can try to get away with the default - # serialization for their C++ type. - if idl_type.deserializer is None: + # serialization for their C++ type. An internal_only type is not associated with BSON + # and thus should not have a deserializer defined. + if idl_type.deserializer is None and not idl_type.internal_only: ctxt.add_missing_ast_required_field_error(idl_type, syntax_type, idl_type.name, "deserializer") elif bson_type == "chain": @@ -257,6 +258,8 @@ def _get_struct_qualified_cpp_name(struct): def _bind_struct_common(ctxt, parsed_spec, struct, ast_struct): # type: (errors.ParserContext, syntax.IDLSpec, syntax.Struct, ast.Struct) -> None + _inject_hidden_fields(struct) + ast_struct.name = struct.name ast_struct.description = struct.description ast_struct.strict = struct.strict @@ -344,6 +347,26 @@ def _bind_struct_common(ctxt, parsed_spec, struct, ast_struct): pos += 1 +def _inject_hidden_fields(struct): + # type: (syntax.Struct) -> None + """Inject hidden fields to aid deserialization/serialization for structs.""" + + # Don't generate if no fields exist or it's already included in this struct + if struct.fields is None: + struct.fields = [] + + serialization_context_field = syntax.Field(struct.file_name, struct.line, struct.column) + serialization_context_field.name = "serialization_context" # This comes from basic_types.idl + serialization_context_field.type = syntax.FieldTypeSingle(struct.file_name, struct.line, + struct.column) + serialization_context_field.type.type_name = "serialization_context" + serialization_context_field.cpp_name = "serializationContext" + serialization_context_field.optional = False + serialization_context_field.default = "SerializationContext()" + + struct.fields.append(serialization_context_field) + + def _bind_struct(ctxt, parsed_spec, struct): # type: (errors.ParserContext, syntax.IDLSpec, syntax.Struct) -> ast.Struct """ @@ -965,6 +988,7 @@ def _bind_type(idltype): ast_type.serializer = _normalize_method_name(idltype.cpp_type, idltype.serializer) ast_type.deserializer = _normalize_method_name(idltype.cpp_type, idltype.deserializer) ast_type.deserialize_with_tenant = idltype.deserialize_with_tenant + ast_type.internal_only = idltype.internal_only return ast_type @@ -1142,6 +1166,9 @@ def _bind_chained_struct(ctxt, parsed_spec, ast_struct, chained_struct): # Merge all the fields from resolved struct into this ast struct. for field in struct.fields or []: ast_field = _bind_field(ctxt, parsed_spec, field) + # Don't use internal fields in chained types, stick to local access only + if ast_field.type.internal_only: + continue if ast_field and not _is_duplicate_field(ctxt, chained_struct.name, ast_struct.fields, ast_field): diff --git a/buildscripts/idl/idl/cpp_types.py b/buildscripts/idl/idl/cpp_types.py index af0c97a89df..054b3303892 100644 --- a/buildscripts/idl/idl/cpp_types.py +++ b/buildscripts/idl/idl/cpp_types.py @@ -458,6 +458,7 @@ class _CppTypeOptional(_CppTypeDelegating): def get_cpp_type_from_cpp_type_name(field, cpp_type_name, array): # type: (ast.Field, str, bool) -> CppTypeBase """Get the C++ Type information for the given C++ type name, e.g. std::string.""" + # print('get_cpp_type_from_cpp_type_name field: ' + field.name + ', cpp type: ' + cpp_type_name) cpp_type_info: CppTypeBase if cpp_type_name == 'std::string': cpp_type_info = _CppTypeView(field, 'std::string', 'std::string', 'StringData') @@ -517,8 +518,8 @@ class BsonCppTypeBase(object, metaclass=ABCMeta): pass -def _call_method_or_global_function(expression, method_name): - # type: (str, str) -> str +def _call_method_or_global_function(expression, ast_type): + # type: (str, ast.Type) -> str """ Given a fully-qualified method name, call it correctly. @@ -526,13 +527,20 @@ def _call_method_or_global_function(expression, method_name): not treated as a global C++ function though. This notion of functions is designed to support enum deserializers/serializers which are not methods. """ + method_name = ast_type.serializer + serializer_flags = 'getSerializationContext()' if ast_type.deserialize_with_tenant else '' + short_method_name = writer.get_method_name(method_name) if writer.is_function(method_name): - return common.template_args('${method_name}(${expression})', expression=expression, - method_name=method_name) + if ast_type.deserialize_with_tenant: + serializer_flags = ', ' + serializer_flags + return common.template_args('${method_name}(${expression}${serializer_flags})', + expression=expression, method_name=method_name, + serializer_flags=serializer_flags) - return common.template_args('${expression}.${method_name}()', expression=expression, - method_name=short_method_name) + return common.template_args('${expression}.${method_name}(${serializer_flags})', + expression=expression, method_name=short_method_name, + serializer_flags=serializer_flags) class _CommonBsonCppTypeBase(BsonCppTypeBase): @@ -555,7 +563,7 @@ class _CommonBsonCppTypeBase(BsonCppTypeBase): def gen_serializer_expression(self, indented_writer, expression): # type: (writer.IndentedTextWriter, str) -> str - return _call_method_or_global_function(expression, self._ast_type.serializer) + return _call_method_or_global_function(expression, self._ast_type) class _ObjectBsonCppTypeBase(BsonCppTypeBase): @@ -580,9 +588,15 @@ class _ObjectBsonCppTypeBase(BsonCppTypeBase): def gen_serializer_expression(self, indented_writer, expression): # type: (writer.IndentedTextWriter, str) -> str method_name = writer.get_method_name(self._ast_type.serializer) - indented_writer.write_line( - common.template_args('const BSONObj localObject = ${expression}.${method_name}();', - expression=expression, method_name=method_name)) + if self._ast_type.deserialize_with_tenant: # SerializationContext is tied to tenant deserialization + indented_writer.write_line( + common.template_args( + 'const BSONObj localObject = ${expression}.${method_name}(getSerializationContext());', + expression=expression, method_name=method_name)) + else: + indented_writer.write_line( + common.template_args('const BSONObj localObject = ${expression}.${method_name}();', + expression=expression, method_name=method_name)) return "localObject" diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py index 2c6367af54c..59a642b0bce 100644 --- a/buildscripts/idl/idl/generator.py +++ b/buildscripts/idl/idl/generator.py @@ -198,7 +198,7 @@ class _FastFieldUsageChecker(_FieldUsageCheckerBase): bit_id = 0 for field in fields: - if field.chained: + if field.chained or (field.type and field.type.internal_only): continue self._writer.write_line( @@ -784,8 +784,9 @@ class _CppHeaderFileWriter(_CppFileWriterBase): with self._block("auto _relopTuple() const {", "}"): sorted_fields = sorted([ - field - for field in struct.fields if (not field.ignore) and field.comparison_order != -1 + field for field in struct.fields + if (not field.ignore and not (field.type and field.type.internal_only)) + and field.comparison_order != -1 ], key=lambda f: f.comparison_order) self._writer.write_line("return std::tuple({});".format(", ".join( map(lambda f: "idl::relop::Ordering{{{}}}".format(_get_field_member_name(f)), @@ -1051,6 +1052,7 @@ class _CppHeaderFileWriter(_CppFileWriterBase): 'mongo/idl/idl_parser.h', 'mongo/rpc/op_msg.h', 'mongo/stdx/unordered_map.h', + 'mongo/util/serialization_context.h', ] + spec.globals.cpp_includes if spec.configs: @@ -1135,8 +1137,10 @@ class _CppHeaderFileWriter(_CppFileWriterBase): if field.description: self.gen_description_comment(field.description) self.gen_getter(struct, field) - if not struct.immutable and not field.chained_struct_field: - self.gen_setter(field) + if not field.chained_struct_field: + if not struct.immutable or (field.type + and field.type.internal_only): + self.gen_setter(field) # Generate getters for any constexpr/compile-time struct data self.write_empty_line() @@ -1224,10 +1228,11 @@ class _CppSourceFileWriter(_CppFileWriterBase): Writes multiple lines into the generated file. Returns the final statement to access the deserialized value. """ - + serialization_context = "getSerializationContext()" if ast_type.is_struct: - self._writer.write_line('IDLParserContext tempContext(%s, &ctxt, %s);' % - (_get_field_constant_name(field), tenant)) + self._writer.write_line( + 'IDLParserContext tempContext(%s, &ctxt, %s, %s);' % + (_get_field_constant_name(field), tenant, serialization_context)) self._writer.write_line('const auto localObject = %s.Obj();' % (element_name)) return '%s::parse(tempContext, localObject)' % (ast_type.cpp_type, ) elif ast_type.deserializer and 'BSONElement::' in ast_type.deserializer: @@ -1251,15 +1256,17 @@ class _CppSourceFileWriter(_CppFileWriterBase): # For fields which are enums, pass a IDLParserContext if ast_type.is_enum: - self._writer.write_line('IDLParserContext tempContext(%s, &ctxt, %s);' % - (_get_field_constant_name(field), tenant)) + self._writer.write_line( + 'IDLParserContext tempContext(%s, &ctxt, %s, %s);' % + (_get_field_constant_name(field), tenant, serialization_context)) return common.template_args("${method_name}(tempContext, ${expression})", method_name=method_name, expression=expression) if ast_type.deserialize_with_tenant: - return common.template_args("${method_name}(${tenant}, ${expression})", - method_name=method_name, tenant=tenant, - expression=expression) + return common.template_args( + "${method_name}(${tenant}, ${expression}, ${context})", + method_name=method_name, tenant=tenant, expression=expression, + context=serialization_context) else: return common.template_args("${method_name}(${expression})", method_name=method_name, expression=expression) @@ -1272,7 +1279,7 @@ class _CppSourceFileWriter(_CppFileWriterBase): # Class Class::method(const BSONElement& value) method_name = writer.get_method_name_from_qualified_method_name(ast_type.deserializer) - if ast_type.deserialize_with_tenant: + if ast_type.deserialize_with_tenant: # TODO SERVER-74029 pass in SerializationContext return '%s(%s, %s)' % (method_name, tenant, element_name) else: return '%s(%s)' % (method_name, element_name) @@ -1285,8 +1292,9 @@ class _CppSourceFileWriter(_CppFileWriterBase): cpp_type = cpp_type_info.get_type_name() self._writer.write_line('std::uint32_t expectedFieldNumber{0};') - self._writer.write_line('const IDLParserContext arrayCtxt(%s, &ctxt, %s);' % - (_get_field_constant_name(field), tenant)) + self._writer.write_line( + 'const IDLParserContext arrayCtxt(%s, &ctxt, %s, getSerializationContext());' % + (_get_field_constant_name(field), tenant)) self._writer.write_line('std::vector<%s> values;' % (cpp_type)) self._writer.write_empty_line() @@ -1477,6 +1485,11 @@ class _CppSourceFileWriter(_CppFileWriterBase): If field_type is scalar and check_type is True (the default), generate type-checking code. Array elements are always type-checked. """ + + # Internal-only types aren't serialized or deserialized. + if field_type.internal_only: + return + if field_type.is_array: predicate = "MONGO_likely(ctxt.checkAndAssertType(%s, Array))" % (bson_element) with self._predicate(predicate): @@ -1566,8 +1579,9 @@ class _CppSourceFileWriter(_CppFileWriterBase): # Either we are deserializing BSON Objects or IDL structs if field.type.is_struct: - self._writer.write_line('IDLParserContext tempContext(%s, &ctxt, %s);' % - (_get_field_constant_name(field), tenant)) + self._writer.write_line( + 'IDLParserContext tempContext(%s, &ctxt, %s, getSerializationContext());' % + (_get_field_constant_name(field), tenant)) array_value = '%s::parse(tempContext, sequenceObject)' % (field.type.cpp_type, ) elif field.type.is_variant: self._writer.write_line('%s _tmp;' % field.type.cpp_type) @@ -1707,6 +1721,18 @@ class _CppSourceFileWriter(_CppFileWriterBase): if isinstance(struct, ast.Command): self._writer.write_line('BSONElement commandElement;') self._writer.write_line('bool firstFieldFound = false;') + self._writer.write_empty_line() + + # set the local serializer flags to a command request type + self._writer.write_line( + 'setSerializationContext(SerializationContext(SerializationContext::Source::Command, SerializationContext::CallerType::Request));' + ) + else: + # set the local serializer flags according to the constexpr set by is_command_reply + self._writer.write_empty_line() + self._writer.write_line( + 'setSerializationContext(_isCommandReply ? SerializationContext(SerializationContext::Source::Command, SerializationContext::CallerType::Reply) : ctxt.getSerializationContext());' + ) self._writer.write_empty_line() @@ -1732,6 +1758,9 @@ class _CppSourceFileWriter(_CppFileWriterBase): # Do not parse chained fields as fields since they are actually chained types. if field.chained and not field.chained_struct_field: continue + # Internal only fields are not parsed from BSON objects + if field.type and field.type.internal_only: + continue field_predicate = 'fieldName == %s' % (_get_field_constant_name(field)) @@ -1913,6 +1942,9 @@ class _CppSourceFileWriter(_CppFileWriterBase): # If the struct contains no fields, there's nothing to deserialize, so we write an empty function stub. if not struct.fields: return + # if the only field is an internal only field, there's also nothing to deserialize + if len(struct.fields) == 1 and any(field.type.internal_only for field in struct.fields): + return # Deserialize all the fields field_usage_check = self._gen_fields_deserializer_common(struct, variable_name, @@ -2149,6 +2181,11 @@ class _CppSourceFileWriter(_CppFileWriterBase): def _gen_serializer_method_common(self, field): # type: (ast.Field) -> None """Generate the serialize method definition.""" + + # Internal-only types aren't serialized or deserialized. + if field.type and field.type.internal_only: + return + member_name = _get_field_member_name(field) # Is this a scalar bson C++ type? @@ -2348,6 +2385,10 @@ class _CppSourceFileWriter(_CppFileWriterBase): """Generate a StringData constant for field name in the cpp file.""" for field in _get_all_fields(struct): + # Internal only fields are not parsed from BSON objects + if field.type and field.type.internal_only: + continue + self._writer.write_line( common.template_args('constexpr StringData ${class_name}::${constant_name};', class_name=common.title_case(struct.cpp_name), @@ -2417,6 +2458,10 @@ class _CppSourceFileWriter(_CppFileWriterBase): ], key=lambda f: f.cpp_name) for field in sorted_fields: + # Internal only fields are not parsed from BSON objects + if field.type and field.type.internal_only: + continue + self._writer.write_line( common.template_args('${class_name}::${constant_name},', class_name=common.title_case(struct.cpp_name), diff --git a/buildscripts/idl/idl/parser.py b/buildscripts/idl/idl/parser.py index 712b2154a1b..a5f74e3b8c6 100644 --- a/buildscripts/idl/idl/parser.py +++ b/buildscripts/idl/idl/parser.py @@ -252,6 +252,7 @@ def _parse_type(ctxt, spec, name, node): "serializer": _RuleDesc('scalar'), "deserializer": _RuleDesc('scalar'), "deserialize_with_tenant": _RuleDesc('bool_scalar'), + "internal_only": _RuleDesc('bool_scalar'), "default": _RuleDesc('scalar'), }) diff --git a/buildscripts/idl/idl/syntax.py b/buildscripts/idl/idl/syntax.py index a46188d6be8..57466a27d81 100644 --- a/buildscripts/idl/idl/syntax.py +++ b/buildscripts/idl/idl/syntax.py @@ -391,6 +391,7 @@ class Type(common.SourceLocation): self.description = None # type: str self.deserialize_with_tenant = False # type: bool self.default = None # type: str + self.internal_only = False # type: bool super(Type, self).__init__(file_name, line, column) diff --git a/buildscripts/idl/tests/test_binder.py b/buildscripts/idl/tests/test_binder.py index 65b98a16c86..14f025e6ce7 100644 --- a/buildscripts/idl/tests/test_binder.py +++ b/buildscripts/idl/tests/test_binder.py @@ -106,6 +106,11 @@ class TestBinder(testcase.IDLTestcase): serializer: foo deserializer: foo + serialization_context: + bson_serialization_type: any + description: foo + cpp_type: foo + internal_only: true """) def test_empty(self): @@ -564,21 +569,15 @@ class TestBinder(testcase.IDLTestcase): """Positive struct tests.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - default: foo + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" int: description: foo cpp_type: std::int32_t bson_serialization_type: int deserializer: mongo::BSONElement::_numberInt - """) + """)) self.assert_bind(test_preamble + textwrap.dedent(""" structs: @@ -603,21 +602,15 @@ class TestBinder(testcase.IDLTestcase): """Negative struct tests.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - default: foo + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" int: description: foo cpp_type: std::int32_t bson_serialization_type: int deserializer: mongo::BSONElement::_numberInt - """) + """)) # Test array as name self.assert_bind_fail( @@ -644,15 +637,9 @@ class TestBinder(testcase.IDLTestcase): """Positive variant test cases.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - default: foo + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" int: description: foo cpp_type: std::int32_t @@ -664,7 +651,7 @@ class TestBinder(testcase.IDLTestcase): description: "A BSON bindata of function sub type" cpp_type: "std::vector<std::uint8_t>" deserializer: "mongo::BSONElement::_binDataVector" - """) + """)) self.assert_bind(test_preamble + textwrap.dedent(""" structs: @@ -728,22 +715,9 @@ class TestBinder(testcase.IDLTestcase): """Negative variant test cases.""" # Setup some common types - test_preamble = textwrap.dedent(""" - enums: - foo_enum: - description: foo - type: int - values: - v1: 0 - v2: 1 - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - default: foo + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" int: description: foo cpp_type: std::int32_t @@ -758,6 +732,14 @@ class TestBinder(testcase.IDLTestcase): description: foo cpp_type: "std::int32_t" deserializer: "mongo::BSONElement::safeNumberInt" + """)) + textwrap.dedent(""" + enums: + foo_enum: + description: foo + type: int + values: + v1: 0 + v2: 1 """) self.assert_bind_fail( @@ -915,15 +897,7 @@ class TestBinder(testcase.IDLTestcase): """Positive test cases for field.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - """) + test_preamble = self.common_types # Short type self.assert_bind(test_preamble + textwrap.dedent(""" @@ -969,16 +943,16 @@ class TestBinder(testcase.IDLTestcase): """)) # Test array as field type - self.assert_bind( + self.assert_bind(self.common_types + indent_text( + 1, textwrap.dedent(""" - types: - arrayfake: + arrayfake: description: foo cpp_type: foo bson_serialization_type: string serializer: foo deserializer: foo - + """)) + textwrap.dedent(""" structs: foo: description: foo @@ -1037,6 +1011,12 @@ class TestBinder(testcase.IDLTestcase): cpp_type: foo bson_serialization_type: bindata bindata_subtype: uuid + + serialization_context: + bson_serialization_type: any + description: foo + cpp_type: foo + internal_only: true """) # Test field of a struct type with a non-true default @@ -1092,15 +1072,7 @@ class TestBinder(testcase.IDLTestcase): # Test non-inherited default with array self.assert_bind_fail( - textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - + self.common_types + textwrap.dedent(""" structs: foo: description: foo @@ -1190,7 +1162,7 @@ class TestBinder(testcase.IDLTestcase): "default: foo", ]: self.assert_bind_fail( - textwrap.dedent(""" + self.common_types + textwrap.dedent(""" structs: foo: description: foo @@ -1206,17 +1178,9 @@ class TestBinder(testcase.IDLTestcase): # type: () -> None """Positive parser chaining test cases.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - default: foo - - + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" foo1: description: foo cpp_type: foo @@ -1224,8 +1188,7 @@ class TestBinder(testcase.IDLTestcase): serializer: foo deserializer: foo default: foo - - """) + """)) # Chaining only self.assert_bind(test_preamble + textwrap.dedent(""" @@ -1241,23 +1204,16 @@ class TestBinder(testcase.IDLTestcase): # type: () -> None """Negative parser chaining test cases.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" foo1: description: foo cpp_type: foo bson_serialization_type: chain serializer: foo deserializer: foo - - """) + """)) # Chaining with strict struct self.assert_bind_fail( @@ -1334,17 +1290,9 @@ class TestBinder(testcase.IDLTestcase): # type: () -> None """Positive parser chaining test cases.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - default: foo - - + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" foo1: description: foo cpp_type: foo @@ -1352,7 +1300,7 @@ class TestBinder(testcase.IDLTestcase): serializer: foo deserializer: foo default: foo - + """)) + textwrap.dedent(""" structs: chained: description: foo @@ -1463,17 +1411,9 @@ class TestBinder(testcase.IDLTestcase): # type: () -> None """Negative parser chaining test cases.""" # Setup some common types - test_preamble = textwrap.dedent(""" - types: - string: - description: foo - cpp_type: foo - bson_serialization_type: string - serializer: foo - deserializer: foo - default: foo - - + test_preamble = self.common_types + indent_text( + 1, + textwrap.dedent(""" foo1: description: foo cpp_type: foo @@ -1481,7 +1421,7 @@ class TestBinder(testcase.IDLTestcase): serializer: foo deserializer: foo default: foo - + """)) + textwrap.dedent(""" structs: chained: description: foo @@ -1720,7 +1660,7 @@ class TestBinder(testcase.IDLTestcase): # type: () -> None """Negative enum test cases.""" - test_preamble = textwrap.dedent(""" + test_preamble = self.common_types + textwrap.dedent(""" enums: foo: description: foo diff --git a/buildscripts/idl/tests/test_generator.py b/buildscripts/idl/tests/test_generator.py index ee8a251aa53..dcdcecc7712 100644 --- a/buildscripts/idl/tests/test_generator.py +++ b/buildscripts/idl/tests/test_generator.py @@ -100,6 +100,13 @@ class TestGenerator(testcase.IDLTestcase): # type: () -> None """Validate enums are not marked as const in getters.""" header, _ = self.assert_generate(""" + types: + serialization_context: + bson_serialization_type: any + description: foo + cpp_type: foo + internal_only: true + enums: StringEnum: diff --git a/buildscripts/idl/tests/test_import.py b/buildscripts/idl/tests/test_import.py index 67cd2a7dcd6..46f7df2eb28 100644 --- a/buildscripts/idl/tests/test_import.py +++ b/buildscripts/idl/tests/test_import.py @@ -120,6 +120,11 @@ class TestImport(testcase.IDLTestcase): serializer: foo deserializer: foo default: foo + serialization_context: + bson_serialization_type: any + description: foo + cpp_type: foo + internal_only: true structs: bar: @@ -139,6 +144,7 @@ class TestImport(testcase.IDLTestcase): cpp_type: foo bson_serialization_type: int deserializer: BSONElement::fake + """), "recurse2.idl": textwrap.dedent(""" @@ -151,6 +157,7 @@ class TestImport(testcase.IDLTestcase): cpp_type: foo bson_serialization_type: double deserializer: BSONElement::fake + """), "recurse1b.idl": textwrap.dedent(""" @@ -180,6 +187,11 @@ class TestImport(testcase.IDLTestcase): serializer: foo deserializer: foo default: foo + serialization_context: + bson_serialization_type: any + description: foo + cpp_type: foo + internal_only: true structs: bar: @@ -228,6 +240,11 @@ class TestImport(testcase.IDLTestcase): serializer: foo deserializer: foo default: foo + serialization_context: + bson_serialization_type: any + description: foo + cpp_type: foo + internal_only: true """), } |