protoc 2.6.1.1 → 2.6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/protoc/Makefile.in +10 -13
- data/ext/protoc/extconf.rb +0 -1
- data/ext/protoc/protobuf/CHANGES.txt +593 -0
- data/ext/protoc/protobuf/CONTRIBUTORS.txt +93 -0
- data/ext/protoc/protobuf/INSTALL.txt +237 -0
- data/ext/protoc/protobuf/LICENSE +33 -0
- data/ext/protoc/protobuf/Makefile.am +267 -0
- data/ext/protoc/protobuf/README.md +167 -0
- data/ext/protoc/protobuf/autogen.sh +41 -0
- data/ext/protoc/protobuf/benchmarks/ProtoBench.java +203 -0
- data/ext/protoc/protobuf/benchmarks/google_message1.dat +0 -0
- data/ext/protoc/protobuf/benchmarks/google_message2.dat +0 -0
- data/ext/protoc/protobuf/benchmarks/google_size.proto +136 -0
- data/ext/protoc/protobuf/benchmarks/google_speed.proto +136 -0
- data/ext/protoc/protobuf/benchmarks/readme.txt +50 -0
- data/ext/protoc/protobuf/configure.ac +159 -0
- data/ext/protoc/protobuf/editors/README.txt +5 -0
- data/ext/protoc/protobuf/editors/proto.vim +105 -0
- data/ext/protoc/protobuf/editors/protobuf-mode.el +220 -0
- data/ext/protoc/protobuf/examples/AddPerson.java +95 -0
- data/ext/protoc/protobuf/examples/ListPeople.java +50 -0
- data/ext/protoc/protobuf/examples/Makefile +58 -0
- data/ext/protoc/protobuf/examples/README.txt +29 -0
- data/ext/protoc/protobuf/examples/add_person.cc +95 -0
- data/ext/protoc/protobuf/examples/add_person.py +58 -0
- data/ext/protoc/protobuf/examples/addressbook.proto +30 -0
- data/ext/protoc/protobuf/examples/list_people.cc +68 -0
- data/ext/protoc/protobuf/examples/list_people.py +38 -0
- data/ext/protoc/protobuf/generate_descriptor_proto.sh +33 -0
- data/ext/protoc/protobuf/java/README.txt +96 -0
- data/ext/protoc/protobuf/java/pom.xml +217 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessage.java +466 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessageLite.java +355 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractParser.java +253 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java +51 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingService.java +64 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BoundedByteString.java +163 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ByteString.java +1022 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedInputStream.java +1311 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedOutputStream.java +1297 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Descriptors.java +2238 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/DynamicMessage.java +622 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Extension.java +96 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistry.java +392 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +185 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/FieldSet.java +907 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessage.java +2213 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java +949 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Internal.java +391 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +122 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyField.java +154 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyFieldLite.java +176 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java +367 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringList.java +163 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LiteralByteString.java +362 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Message.java +244 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLite.java +320 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +60 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageOrBuilder.java +143 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageReflection.java +931 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Parser.java +261 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java +58 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolStringList.java +48 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +696 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RopeByteString.java +957 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcCallback.java +47 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcChannel.java +71 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcController.java +118 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcUtil.java +134 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Service.java +117 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ServiceException.java +52 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SingleFieldBuilder.java +241 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SmallSortedMap.java +618 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/TextFormat.java +1984 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UninitializedMessageException.java +99 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnknownFieldSet.java +995 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java +205 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Utf8.java +349 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/WireFormat.java +163 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/AbstractMessageTest.java +527 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/BoundedByteStringTest.java +68 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ByteStringTest.java +759 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CheckUtf8Test.java +141 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedInputStreamTest.java +769 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +401 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java +80 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DescriptorsTest.java +735 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DynamicMessageTest.java +326 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java +48 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/GeneratedMessageTest.java +1515 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8Test.java +180 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +421 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +134 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldTest.java +121 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java +319 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +174 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +143 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +85 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteTest.java +148 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java +396 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/MessageTest.java +353 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/NestedBuildersTest.java +185 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ParserTest.java +381 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java +190 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +97 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringTest.java +115 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ServiceTest.java +320 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java +155 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java +420 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestBadIdentifiers.java +96 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestUtil.java +4124 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TextFormatTest.java +994 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +653 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java +227 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/WireFormatTest.java +606 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lazy_fields_lite.proto +61 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto +55 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/multiple_files_test.proto +77 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_builders_test.proto +53 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension.proto +46 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension_lite.proto +48 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension.proto +49 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto +50 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test.proto +38 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test2.proto +42 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test3.proto +43 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_bad_identifiers.proto +157 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8.proto +50 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8_size.proto +51 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_custom_options.proto +43 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_extra_interfaces.proto +60 -0
- data/ext/protoc/protobuf/m4/ac_system_extensions.m4 +37 -0
- data/ext/protoc/protobuf/m4/acx_check_suncc.m4 +75 -0
- data/ext/protoc/protobuf/m4/acx_pthread.m4 +397 -0
- data/ext/protoc/protobuf/m4/stl_hash.m4 +72 -0
- data/ext/protoc/protobuf/more_tests/Makefile +41 -0
- data/ext/protoc/protobuf/post_process_dist.sh +60 -0
- data/ext/protoc/protobuf/protobuf-lite.pc.in +13 -0
- data/ext/protoc/protobuf/protobuf.pc.in +14 -0
- data/ext/protoc/protobuf/python/README.txt +105 -0
- data/ext/protoc/protobuf/python/ez_setup.py +284 -0
- data/ext/protoc/protobuf/python/google/__init__.py +1 -0
- data/ext/protoc/protobuf/python/google/protobuf/__init__.py +0 -0
- data/ext/protoc/protobuf/python/google/protobuf/descriptor.py +849 -0
- data/ext/protoc/protobuf/python/google/protobuf/descriptor_database.py +137 -0
- data/ext/protoc/protobuf/python/google/protobuf/descriptor_pool.py +643 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/__init__.py +0 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.cc +139 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.py +89 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation_default_test.py +63 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/containers.py +269 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/cpp_message.py +663 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/decoder.py +831 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_database_test.py +63 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test.py +564 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto +94 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto +70 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_python_test.py +54 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_test.py +669 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/encoder.py +788 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/enum_type_wrapper.py +89 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test1.proto +57 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test2.proto +92 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/generator_test.py +343 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_python_test.py +54 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_test.py +131 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_listener.py +78 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_python_test.py +54 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_test.py +681 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/missing_enum_values.proto +50 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions.proto +58 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto +49 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/more_messages.proto +51 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/python_message.py +1251 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/reflection_test.py +2934 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/service_reflection_test.py +136 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/symbol_database_test.py +120 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto +52 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/test_util.py +662 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/text_encoding_test.py +68 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/text_format_test.py +743 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/type_checkers.py +328 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/unknown_fields_test.py +231 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format.py +268 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format_test.py +253 -0
- data/ext/protoc/protobuf/python/google/protobuf/message.py +284 -0
- data/ext/protoc/protobuf/python/google/protobuf/message_factory.py +155 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/README +6 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/__init__.py +0 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/cpp_message.py +61 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.cc +357 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.h +96 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor_cpp2_test.py +58 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.cc +338 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.h +123 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/message.cc +2561 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/message.h +305 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/message_factory_cpp2_test.py +56 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/proto2_api_test.proto +38 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/python.proto +66 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/python_protobuf.h +57 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/reflection_cpp2_generated_test.py +94 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc +763 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.h +172 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc +825 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h +112 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h +95 -0
- data/ext/protoc/protobuf/python/google/protobuf/reflection.py +205 -0
- data/ext/protoc/protobuf/python/google/protobuf/service.py +226 -0
- data/ext/protoc/protobuf/python/google/protobuf/service_reflection.py +284 -0
- data/ext/protoc/protobuf/python/google/protobuf/symbol_database.py +185 -0
- data/ext/protoc/protobuf/python/google/protobuf/text_encoding.py +110 -0
- data/ext/protoc/protobuf/python/google/protobuf/text_format.py +873 -0
- data/ext/protoc/protobuf/python/mox.py +1401 -0
- data/ext/protoc/protobuf/python/setup.py +201 -0
- data/ext/protoc/protobuf/python/stubout.py +140 -0
- data/ext/protoc/protobuf/src/Makefile.am +418 -0
- data/ext/protoc/protobuf/src/google/protobuf/SEBS +240 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.cc +84 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.h +145 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.cc +1603 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.h +378 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc +1654 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +158 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc +288 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h +103 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +431 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h +122 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc +210 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h +86 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc +166 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h +185 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc +665 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h +99 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc +125 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc +494 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h +206 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc +2645 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h +175 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc +375 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h +121 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h +58 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc +123 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +451 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +123 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc +334 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc +642 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h +127 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto +132 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc +2074 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h +51 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.cc +480 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.h +317 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/importer_unittest.cc +617 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.cc +195 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.h +95 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc +233 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h +69 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc +67 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.cc +333 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.h +99 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc +778 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.h +158 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.cc +207 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.h +109 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.cc +213 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.h +162 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.cc +534 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.h +115 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.cc +158 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.h +72 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc +77 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h +101 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.cc +737 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.h +322 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc +826 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h +121 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.cc +1666 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.h +140 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.cc +1343 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.h +173 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc +266 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h +124 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc +124 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc +877 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h +160 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.cc +473 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.h +135 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc +201 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h +90 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.cc +1056 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.h +160 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/main.cc +61 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.cc +240 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.h +117 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/package_info.h +64 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.cc +1750 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.h +522 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/parser_unittest.cc +2612 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.cc +163 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.h +72 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.cc +1148 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.h +897 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.proto +147 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.cc +1262 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.h +166 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc +118 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.cc +463 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.h +108 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/test_plugin.cc +51 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh +91 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.cc +218 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.h +93 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.cc +5420 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.h +1691 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.cc +9135 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.h +6761 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.proto +687 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.cc +543 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.h +369 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_database_unittest.cc +748 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_pb2_test.py +54 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_unittest.cc +5501 -0
- data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.cc +764 -0
- data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.h +148 -0
- data/ext/protoc/protobuf/src/google/protobuf/dynamic_message_unittest.cc +230 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set.cc +1663 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set.h +1234 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set_heavy.cc +734 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set_unittest.cc +1095 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_enum_reflection.h +91 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.cc +1683 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.h +504 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc +795 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.cc +65 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.h +113 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.cc +914 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.h +1220 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_inl.h +69 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_unittest.cc +1378 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.cc +326 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.h +209 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh +44 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/package_info.h +54 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/printer.cc +198 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/printer.h +136 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/printer_unittest.cc +285 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/strtod.cc +113 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/strtod.h +50 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.cc +1127 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.h +402 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer_unittest.cc +999 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.cc +57 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.h +248 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc +473 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h +358 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +405 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h +354 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc +965 -0
- data/ext/protoc/protobuf/src/google/protobuf/lite_unittest.cc +350 -0
- data/ext/protoc/protobuf/src/google/protobuf/message.cc +358 -0
- data/ext/protoc/protobuf/src/google/protobuf/message.h +866 -0
- data/ext/protoc/protobuf/src/google/protobuf/message_lite.cc +335 -0
- data/ext/protoc/protobuf/src/google/protobuf/message_lite.h +247 -0
- data/ext/protoc/protobuf/src/google/protobuf/message_unittest.cc +427 -0
- data/ext/protoc/protobuf/src/google/protobuf/package_info.h +64 -0
- data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.cc +269 -0
- data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.h +81 -0
- data/ext/protoc/protobuf/src/google/protobuf/reflection_ops_unittest.cc +475 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field.cc +87 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field.h +1603 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc +195 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field_unittest.cc +1442 -0
- data/ext/protoc/protobuf/src/google/protobuf/service.cc +46 -0
- data/ext/protoc/protobuf/src/google/protobuf/service.h +291 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops.h +227 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h +325 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h +151 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h +146 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h +122 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +137 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_macosx.h +225 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h +313 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_pnacl.h +73 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h +188 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h +219 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc +137 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h +293 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc +112 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h +150 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/common.cc +395 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/common.h +1226 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/common_unittest.cc +357 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/hash.h +232 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/map_util.h +771 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/once.cc +99 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/once.h +166 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/once_unittest.cc +253 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/platform_macros.h +103 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/shared_ptr.h +470 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stl_util.h +121 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.cc +175 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.h +76 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc +152 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid.cc +536 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc +40 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.cc +1279 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.h +562 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil_unittest.cc +73 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.cc +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.h +170 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util.h +138 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util_unittest.cc +130 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits.h +336 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc +628 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util.cc +3345 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util.h +215 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.cc +1585 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.h +101 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/bad_utf8_string +1 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message +0 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented +0 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_packed_fields_message +0 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt +129 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt +129 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/file.cc +194 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/file.h +97 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.cc +255 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.h +102 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/zcgunzip.cc +73 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/zcgzip.cc +79 -0
- data/ext/protoc/protobuf/src/google/protobuf/text_format.cc +1746 -0
- data/ext/protoc/protobuf/src/google/protobuf/text_format.h +473 -0
- data/ext/protoc/protobuf/src/google/protobuf/text_format_unittest.cc +1479 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest.proto +861 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_custom_options.proto +393 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto +50 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_empty.proto +37 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto +1046 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import.proto +64 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import_lite.proto +51 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public.proto +40 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public_lite.proto +42 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_lite.proto +384 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto +43 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_mset.proto +83 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_no_generic_services.proto +53 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_optimize_for.proto +66 -0
- data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.cc +265 -0
- data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.h +318 -0
- data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set_unittest.cc +599 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format.cc +1101 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format.h +336 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.cc +471 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.h +661 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite_inl.h +860 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_unittest.cc +1120 -0
- data/ext/protoc/protobuf/src/solaris/libstdc++.la +51 -0
- data/ext/protoc/protobuf/vsprojects/config.h +29 -0
- data/ext/protoc/protobuf/vsprojects/convert2008to2005.sh +20 -0
- data/ext/protoc/protobuf/vsprojects/extract_includes.bat +50 -0
- data/ext/protoc/protobuf/vsprojects/libprotobuf-lite.vcproj +302 -0
- data/ext/protoc/protobuf/vsprojects/libprotobuf.vcproj +470 -0
- data/ext/protoc/protobuf/vsprojects/libprotoc.vcproj +466 -0
- data/ext/protoc/protobuf/vsprojects/lite-test.vcproj +305 -0
- data/ext/protoc/protobuf/vsprojects/protobuf.sln +92 -0
- data/ext/protoc/protobuf/vsprojects/protoc.vcproj +192 -0
- data/ext/protoc/protobuf/vsprojects/readme.txt +114 -0
- data/ext/protoc/protobuf/vsprojects/test_plugin.vcproj +209 -0
- data/ext/protoc/protobuf/vsprojects/tests.vcproj +681 -0
- data/lib/protoc/version.rb +1 -1
- metadata +480 -3
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
|
2
|
+
// Copyright 2008 Google Inc. All rights reserved.
|
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
|
4
|
+
//
|
|
5
|
+
// Redistribution and use in source and binary forms, with or without
|
|
6
|
+
// modification, are permitted provided that the following conditions are
|
|
7
|
+
// met:
|
|
8
|
+
//
|
|
9
|
+
// * Redistributions of source code must retain the above copyright
|
|
10
|
+
// notice, this list of conditions and the following disclaimer.
|
|
11
|
+
// * Redistributions in binary form must reproduce the above
|
|
12
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
13
|
+
// in the documentation and/or other materials provided with the
|
|
14
|
+
// distribution.
|
|
15
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
16
|
+
// contributors may be used to endorse or promote products derived from
|
|
17
|
+
// this software without specific prior written permission.
|
|
18
|
+
//
|
|
19
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
20
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
21
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
22
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
23
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
24
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
25
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
26
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
27
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
|
|
31
|
+
package com.google.protobuf;
|
|
32
|
+
|
|
33
|
+
import com.google.protobuf.Descriptors.EnumDescriptor;
|
|
34
|
+
import com.google.protobuf.Descriptors.FieldDescriptor;
|
|
35
|
+
import com.google.protobuf.Descriptors.OneofDescriptor;
|
|
36
|
+
|
|
37
|
+
import protobuf_unittest.UnittestProto.TestAllExtensions;
|
|
38
|
+
import protobuf_unittest.UnittestProto.TestAllTypes;
|
|
39
|
+
import protobuf_unittest.UnittestProto.TestEmptyMessage;
|
|
40
|
+
import protobuf_unittest.UnittestProto.TestPackedTypes;
|
|
41
|
+
|
|
42
|
+
import junit.framework.TestCase;
|
|
43
|
+
import java.util.Arrays;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Unit test for {@link DynamicMessage}. See also {@link MessageTest}, which
|
|
47
|
+
* tests some {@link DynamicMessage} functionality.
|
|
48
|
+
*
|
|
49
|
+
* @author kenton@google.com Kenton Varda
|
|
50
|
+
*/
|
|
51
|
+
public class DynamicMessageTest extends TestCase {
|
|
52
|
+
TestUtil.ReflectionTester reflectionTester =
|
|
53
|
+
new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
|
|
54
|
+
|
|
55
|
+
TestUtil.ReflectionTester extensionsReflectionTester =
|
|
56
|
+
new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
|
|
57
|
+
TestUtil.getExtensionRegistry());
|
|
58
|
+
TestUtil.ReflectionTester packedReflectionTester =
|
|
59
|
+
new TestUtil.ReflectionTester(TestPackedTypes.getDescriptor(), null);
|
|
60
|
+
|
|
61
|
+
public void testDynamicMessageAccessors() throws Exception {
|
|
62
|
+
Message.Builder builder =
|
|
63
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
64
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
65
|
+
Message message = builder.build();
|
|
66
|
+
reflectionTester.assertAllFieldsSetViaReflection(message);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public void testSettersAfterBuild() throws Exception {
|
|
70
|
+
Message.Builder builder =
|
|
71
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
72
|
+
Message firstMessage = builder.build();
|
|
73
|
+
// double build()
|
|
74
|
+
builder.build();
|
|
75
|
+
// clear() after build()
|
|
76
|
+
builder.clear();
|
|
77
|
+
// setters after build()
|
|
78
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
79
|
+
Message message = builder.build();
|
|
80
|
+
reflectionTester.assertAllFieldsSetViaReflection(message);
|
|
81
|
+
// repeated setters after build()
|
|
82
|
+
reflectionTester.modifyRepeatedFieldsViaReflection(builder);
|
|
83
|
+
message = builder.build();
|
|
84
|
+
reflectionTester.assertRepeatedFieldsModifiedViaReflection(message);
|
|
85
|
+
// firstMessage shouldn't have been modified.
|
|
86
|
+
reflectionTester.assertClearViaReflection(firstMessage);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public void testUnknownFields() throws Exception {
|
|
90
|
+
Message.Builder builder =
|
|
91
|
+
DynamicMessage.newBuilder(TestEmptyMessage.getDescriptor());
|
|
92
|
+
builder.setUnknownFields(UnknownFieldSet.newBuilder()
|
|
93
|
+
.addField(1, UnknownFieldSet.Field.newBuilder().addVarint(1).build())
|
|
94
|
+
.addField(2, UnknownFieldSet.Field.newBuilder().addFixed32(1).build())
|
|
95
|
+
.build());
|
|
96
|
+
Message message = builder.build();
|
|
97
|
+
assertEquals(2, message.getUnknownFields().asMap().size());
|
|
98
|
+
// clone() with unknown fields
|
|
99
|
+
Message.Builder newBuilder = builder.clone();
|
|
100
|
+
assertEquals(2, newBuilder.getUnknownFields().asMap().size());
|
|
101
|
+
// clear() with unknown fields
|
|
102
|
+
newBuilder.clear();
|
|
103
|
+
assertTrue(newBuilder.getUnknownFields().asMap().isEmpty());
|
|
104
|
+
// serialize/parse with unknown fields
|
|
105
|
+
newBuilder.mergeFrom(message.toByteString());
|
|
106
|
+
assertEquals(2, newBuilder.getUnknownFields().asMap().size());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public void testDynamicMessageSettersRejectNull() throws Exception {
|
|
110
|
+
Message.Builder builder =
|
|
111
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
112
|
+
reflectionTester.assertReflectionSettersRejectNull(builder);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public void testDynamicMessageExtensionAccessors() throws Exception {
|
|
116
|
+
// We don't need to extensively test DynamicMessage's handling of
|
|
117
|
+
// extensions because, frankly, it doesn't do anything special with them.
|
|
118
|
+
// It treats them just like any other fields.
|
|
119
|
+
Message.Builder builder =
|
|
120
|
+
DynamicMessage.newBuilder(TestAllExtensions.getDescriptor());
|
|
121
|
+
extensionsReflectionTester.setAllFieldsViaReflection(builder);
|
|
122
|
+
Message message = builder.build();
|
|
123
|
+
extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public void testDynamicMessageExtensionSettersRejectNull() throws Exception {
|
|
127
|
+
Message.Builder builder =
|
|
128
|
+
DynamicMessage.newBuilder(TestAllExtensions.getDescriptor());
|
|
129
|
+
extensionsReflectionTester.assertReflectionSettersRejectNull(builder);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public void testDynamicMessageRepeatedSetters() throws Exception {
|
|
133
|
+
Message.Builder builder =
|
|
134
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
135
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
136
|
+
reflectionTester.modifyRepeatedFieldsViaReflection(builder);
|
|
137
|
+
Message message = builder.build();
|
|
138
|
+
reflectionTester.assertRepeatedFieldsModifiedViaReflection(message);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public void testDynamicMessageRepeatedSettersRejectNull() throws Exception {
|
|
142
|
+
Message.Builder builder =
|
|
143
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
144
|
+
reflectionTester.assertReflectionRepeatedSettersRejectNull(builder);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public void testDynamicMessageDefaults() throws Exception {
|
|
148
|
+
reflectionTester.assertClearViaReflection(
|
|
149
|
+
DynamicMessage.getDefaultInstance(TestAllTypes.getDescriptor()));
|
|
150
|
+
reflectionTester.assertClearViaReflection(
|
|
151
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor()).build());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public void testDynamicMessageSerializedSize() throws Exception {
|
|
155
|
+
TestAllTypes message = TestUtil.getAllSet();
|
|
156
|
+
|
|
157
|
+
Message.Builder dynamicBuilder =
|
|
158
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
159
|
+
reflectionTester.setAllFieldsViaReflection(dynamicBuilder);
|
|
160
|
+
Message dynamicMessage = dynamicBuilder.build();
|
|
161
|
+
|
|
162
|
+
assertEquals(message.getSerializedSize(),
|
|
163
|
+
dynamicMessage.getSerializedSize());
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public void testDynamicMessageSerialization() throws Exception {
|
|
167
|
+
Message.Builder builder =
|
|
168
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
169
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
170
|
+
Message message = builder.build();
|
|
171
|
+
|
|
172
|
+
ByteString rawBytes = message.toByteString();
|
|
173
|
+
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
|
|
174
|
+
|
|
175
|
+
TestUtil.assertAllFieldsSet(message2);
|
|
176
|
+
|
|
177
|
+
// In fact, the serialized forms should be exactly the same, byte-for-byte.
|
|
178
|
+
assertEquals(TestUtil.getAllSet().toByteString(), rawBytes);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public void testDynamicMessageParsing() throws Exception {
|
|
182
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
183
|
+
TestUtil.setAllFields(builder);
|
|
184
|
+
TestAllTypes message = builder.build();
|
|
185
|
+
|
|
186
|
+
ByteString rawBytes = message.toByteString();
|
|
187
|
+
|
|
188
|
+
Message message2 =
|
|
189
|
+
DynamicMessage.parseFrom(TestAllTypes.getDescriptor(), rawBytes);
|
|
190
|
+
reflectionTester.assertAllFieldsSetViaReflection(message2);
|
|
191
|
+
|
|
192
|
+
// Test Parser interface.
|
|
193
|
+
Message message3 = message2.getParserForType().parseFrom(rawBytes);
|
|
194
|
+
reflectionTester.assertAllFieldsSetViaReflection(message3);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public void testDynamicMessageExtensionParsing() throws Exception {
|
|
198
|
+
ByteString rawBytes = TestUtil.getAllExtensionsSet().toByteString();
|
|
199
|
+
Message message = DynamicMessage.parseFrom(
|
|
200
|
+
TestAllExtensions.getDescriptor(), rawBytes,
|
|
201
|
+
TestUtil.getExtensionRegistry());
|
|
202
|
+
extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
|
|
203
|
+
|
|
204
|
+
// Test Parser interface.
|
|
205
|
+
Message message2 = message.getParserForType().parseFrom(
|
|
206
|
+
rawBytes, TestUtil.getExtensionRegistry());
|
|
207
|
+
extensionsReflectionTester.assertAllFieldsSetViaReflection(message2);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public void testDynamicMessagePackedSerialization() throws Exception {
|
|
211
|
+
Message.Builder builder =
|
|
212
|
+
DynamicMessage.newBuilder(TestPackedTypes.getDescriptor());
|
|
213
|
+
packedReflectionTester.setPackedFieldsViaReflection(builder);
|
|
214
|
+
Message message = builder.build();
|
|
215
|
+
|
|
216
|
+
ByteString rawBytes = message.toByteString();
|
|
217
|
+
TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
|
|
218
|
+
|
|
219
|
+
TestUtil.assertPackedFieldsSet(message2);
|
|
220
|
+
|
|
221
|
+
// In fact, the serialized forms should be exactly the same, byte-for-byte.
|
|
222
|
+
assertEquals(TestUtil.getPackedSet().toByteString(), rawBytes);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public void testDynamicMessagePackedParsing() throws Exception {
|
|
226
|
+
TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
|
|
227
|
+
TestUtil.setPackedFields(builder);
|
|
228
|
+
TestPackedTypes message = builder.build();
|
|
229
|
+
|
|
230
|
+
ByteString rawBytes = message.toByteString();
|
|
231
|
+
|
|
232
|
+
Message message2 =
|
|
233
|
+
DynamicMessage.parseFrom(TestPackedTypes.getDescriptor(), rawBytes);
|
|
234
|
+
packedReflectionTester.assertPackedFieldsSetViaReflection(message2);
|
|
235
|
+
|
|
236
|
+
// Test Parser interface.
|
|
237
|
+
Message message3 = message2.getParserForType().parseFrom(rawBytes);
|
|
238
|
+
packedReflectionTester.assertPackedFieldsSetViaReflection(message3);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public void testDynamicMessageCopy() throws Exception {
|
|
242
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
243
|
+
TestUtil.setAllFields(builder);
|
|
244
|
+
TestAllTypes message = builder.build();
|
|
245
|
+
|
|
246
|
+
DynamicMessage copy = DynamicMessage.newBuilder(message).build();
|
|
247
|
+
reflectionTester.assertAllFieldsSetViaReflection(copy);
|
|
248
|
+
|
|
249
|
+
// Test oneof behavior
|
|
250
|
+
FieldDescriptor bytesField =
|
|
251
|
+
TestAllTypes.getDescriptor().findFieldByName("oneof_bytes");
|
|
252
|
+
FieldDescriptor uint32Field =
|
|
253
|
+
TestAllTypes.getDescriptor().findFieldByName("oneof_uint32");
|
|
254
|
+
assertTrue(copy.hasField(bytesField));
|
|
255
|
+
assertFalse(copy.hasField(uint32Field));
|
|
256
|
+
DynamicMessage copy2 =
|
|
257
|
+
DynamicMessage.newBuilder(message).setField(uint32Field, 123).build();
|
|
258
|
+
assertFalse(copy2.hasField(bytesField));
|
|
259
|
+
assertTrue(copy2.hasField(uint32Field));
|
|
260
|
+
assertEquals(123, copy2.getField(uint32Field));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public void testToBuilder() throws Exception {
|
|
264
|
+
DynamicMessage.Builder builder =
|
|
265
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
266
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
267
|
+
int unknownFieldNum = 9;
|
|
268
|
+
long unknownFieldVal = 90;
|
|
269
|
+
builder.setUnknownFields(UnknownFieldSet.newBuilder()
|
|
270
|
+
.addField(unknownFieldNum,
|
|
271
|
+
UnknownFieldSet.Field.newBuilder()
|
|
272
|
+
.addVarint(unknownFieldVal).build())
|
|
273
|
+
.build());
|
|
274
|
+
DynamicMessage message = builder.build();
|
|
275
|
+
|
|
276
|
+
DynamicMessage derived = message.toBuilder().build();
|
|
277
|
+
reflectionTester.assertAllFieldsSetViaReflection(derived);
|
|
278
|
+
assertEquals(Arrays.asList(unknownFieldVal),
|
|
279
|
+
derived.getUnknownFields().getField(unknownFieldNum).getVarintList());
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public void testDynamicOneofMessage() throws Exception {
|
|
283
|
+
DynamicMessage.Builder builder =
|
|
284
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
285
|
+
OneofDescriptor oneof = TestAllTypes.getDescriptor().getOneofs().get(0);
|
|
286
|
+
assertFalse(builder.hasOneof(oneof));
|
|
287
|
+
assertSame(null, builder.getOneofFieldDescriptor(oneof));
|
|
288
|
+
|
|
289
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
290
|
+
assertTrue(builder.hasOneof(oneof));
|
|
291
|
+
FieldDescriptor field = oneof.getField(3);
|
|
292
|
+
assertSame(field, builder.getOneofFieldDescriptor(oneof));
|
|
293
|
+
|
|
294
|
+
DynamicMessage message = builder.buildPartial();
|
|
295
|
+
assertTrue(message.hasOneof(oneof));
|
|
296
|
+
|
|
297
|
+
DynamicMessage.Builder mergedBuilder =
|
|
298
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
299
|
+
FieldDescriptor mergedField = oneof.getField(0);
|
|
300
|
+
mergedBuilder.setField(mergedField, 123);
|
|
301
|
+
assertTrue(mergedBuilder.hasField(mergedField));
|
|
302
|
+
mergedBuilder.mergeFrom(message);
|
|
303
|
+
assertTrue(mergedBuilder.hasField(field));
|
|
304
|
+
assertFalse(mergedBuilder.hasField(mergedField));
|
|
305
|
+
|
|
306
|
+
builder.clearOneof(oneof);
|
|
307
|
+
assertSame(null, builder.getOneofFieldDescriptor(oneof));
|
|
308
|
+
message = builder.build();
|
|
309
|
+
assertSame(null, message.getOneofFieldDescriptor(oneof));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Regression test for a bug that makes setField() not work for repeated
|
|
313
|
+
// enum fields.
|
|
314
|
+
public void testSettersForRepeatedEnumField() throws Exception {
|
|
315
|
+
DynamicMessage.Builder builder =
|
|
316
|
+
DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
|
|
317
|
+
FieldDescriptor repeatedEnumField =
|
|
318
|
+
TestAllTypes.getDescriptor().findFieldByName(
|
|
319
|
+
"repeated_nested_enum");
|
|
320
|
+
EnumDescriptor enumDescriptor = TestAllTypes.NestedEnum.getDescriptor();
|
|
321
|
+
builder.setField(repeatedEnumField, enumDescriptor.getValues());
|
|
322
|
+
DynamicMessage message = builder.build();
|
|
323
|
+
assertEquals(
|
|
324
|
+
enumDescriptor.getValues(), message.getField(repeatedEnumField));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
|
2
|
+
// Copyright 2008 Google Inc. All rights reserved.
|
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
|
4
|
+
//
|
|
5
|
+
// Redistribution and use in source and binary forms, with or without
|
|
6
|
+
// modification, are permitted provided that the following conditions are
|
|
7
|
+
// met:
|
|
8
|
+
//
|
|
9
|
+
// * Redistributions of source code must retain the above copyright
|
|
10
|
+
// notice, this list of conditions and the following disclaimer.
|
|
11
|
+
// * Redistributions in binary form must reproduce the above
|
|
12
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
13
|
+
// in the documentation and/or other materials provided with the
|
|
14
|
+
// distribution.
|
|
15
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
16
|
+
// contributors may be used to endorse or promote products derived from
|
|
17
|
+
// this software without specific prior written permission.
|
|
18
|
+
//
|
|
19
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
20
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
21
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
22
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
23
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
24
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
25
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
26
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
27
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
|
|
31
|
+
package com.google.protobuf;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A prerun for a test suite that allows running the full protocol buffer
|
|
35
|
+
* tests in a mode that disables the optimization for not using
|
|
36
|
+
* {@link RepeatedFieldBuilder} and {@link SingleFieldBuilder} until they are
|
|
37
|
+
* requested. This allows us to run all the tests through both code paths
|
|
38
|
+
* and ensures that both code paths produce identical results.
|
|
39
|
+
*
|
|
40
|
+
* @author jonp@google.com (Jon Perlow)
|
|
41
|
+
*/
|
|
42
|
+
public class ForceFieldBuildersPreRun implements Runnable {
|
|
43
|
+
|
|
44
|
+
//@Override (Java 1.6 override semantics, but we must support 1.5)
|
|
45
|
+
public void run() {
|
|
46
|
+
GeneratedMessage.enableAlwaysUseFieldBuildersForTesting();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,1515 @@
|
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
|
2
|
+
// Copyright 2008 Google Inc. All rights reserved.
|
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
|
4
|
+
//
|
|
5
|
+
// Redistribution and use in source and binary forms, with or without
|
|
6
|
+
// modification, are permitted provided that the following conditions are
|
|
7
|
+
// met:
|
|
8
|
+
//
|
|
9
|
+
// * Redistributions of source code must retain the above copyright
|
|
10
|
+
// notice, this list of conditions and the following disclaimer.
|
|
11
|
+
// * Redistributions in binary form must reproduce the above
|
|
12
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
13
|
+
// in the documentation and/or other materials provided with the
|
|
14
|
+
// distribution.
|
|
15
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
16
|
+
// contributors may be used to endorse or promote products derived from
|
|
17
|
+
// this software without specific prior written permission.
|
|
18
|
+
//
|
|
19
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
20
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
21
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
22
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
23
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
24
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
25
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
26
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
27
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
|
|
31
|
+
package com.google.protobuf;
|
|
32
|
+
|
|
33
|
+
import com.google.protobuf.Descriptors.Descriptor;
|
|
34
|
+
import com.google.protobuf.Descriptors.FieldDescriptor;
|
|
35
|
+
import com.google.protobuf.UnittestLite.TestAllExtensionsLite;
|
|
36
|
+
import com.google.protobuf.test.UnittestImport;
|
|
37
|
+
import protobuf_unittest.EnumWithNoOuter;
|
|
38
|
+
import protobuf_unittest.MessageWithNoOuter;
|
|
39
|
+
import protobuf_unittest.MultipleFilesTestProto;
|
|
40
|
+
import protobuf_unittest.NestedExtension.MyNestedExtension;
|
|
41
|
+
import protobuf_unittest.NestedExtensionLite.MyNestedExtensionLite;
|
|
42
|
+
import protobuf_unittest.NonNestedExtension;
|
|
43
|
+
import protobuf_unittest.NonNestedExtension.MessageToBeExtended;
|
|
44
|
+
import protobuf_unittest.NonNestedExtension.MyNonNestedExtension;
|
|
45
|
+
import protobuf_unittest.NonNestedExtensionLite;
|
|
46
|
+
import protobuf_unittest.NonNestedExtensionLite.MessageLiteToBeExtended;
|
|
47
|
+
import protobuf_unittest.NonNestedExtensionLite.MyNonNestedExtensionLite;
|
|
48
|
+
import protobuf_unittest.OuterClassNameTest2OuterClass;
|
|
49
|
+
import protobuf_unittest.OuterClassNameTest3OuterClass;
|
|
50
|
+
import protobuf_unittest.OuterClassNameTestOuterClass;
|
|
51
|
+
import protobuf_unittest.ServiceWithNoOuter;
|
|
52
|
+
import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
|
|
53
|
+
import protobuf_unittest.UnittestOptimizeFor.TestOptionalOptimizedForSize;
|
|
54
|
+
import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize;
|
|
55
|
+
import protobuf_unittest.UnittestProto;
|
|
56
|
+
import protobuf_unittest.UnittestProto.ForeignEnum;
|
|
57
|
+
import protobuf_unittest.UnittestProto.ForeignMessage;
|
|
58
|
+
import protobuf_unittest.UnittestProto.ForeignMessageOrBuilder;
|
|
59
|
+
import protobuf_unittest.UnittestProto.TestAllExtensions;
|
|
60
|
+
import protobuf_unittest.UnittestProto.TestAllTypes;
|
|
61
|
+
import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
|
|
62
|
+
import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
|
|
63
|
+
import protobuf_unittest.UnittestProto.TestExtremeDefaultValues;
|
|
64
|
+
import protobuf_unittest.UnittestProto.TestOneof2;
|
|
65
|
+
import protobuf_unittest.UnittestProto.TestPackedTypes;
|
|
66
|
+
import protobuf_unittest.UnittestProto.TestUnpackedTypes;
|
|
67
|
+
|
|
68
|
+
import junit.framework.TestCase;
|
|
69
|
+
|
|
70
|
+
import java.io.ByteArrayInputStream;
|
|
71
|
+
import java.io.ByteArrayOutputStream;
|
|
72
|
+
import java.io.ObjectInputStream;
|
|
73
|
+
import java.io.ObjectOutputStream;
|
|
74
|
+
import java.util.Arrays;
|
|
75
|
+
import java.util.Collections;
|
|
76
|
+
import java.util.Iterator;
|
|
77
|
+
import java.util.List;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Unit test for generated messages and generated code. See also
|
|
81
|
+
* {@link MessageTest}, which tests some generated message functionality.
|
|
82
|
+
*
|
|
83
|
+
* @author kenton@google.com Kenton Varda
|
|
84
|
+
*/
|
|
85
|
+
public class GeneratedMessageTest extends TestCase {
|
|
86
|
+
TestUtil.ReflectionTester reflectionTester =
|
|
87
|
+
new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
|
|
88
|
+
|
|
89
|
+
public void testDefaultInstance() throws Exception {
|
|
90
|
+
assertSame(TestAllTypes.getDefaultInstance(),
|
|
91
|
+
TestAllTypes.getDefaultInstance().getDefaultInstanceForType());
|
|
92
|
+
assertSame(TestAllTypes.getDefaultInstance(),
|
|
93
|
+
TestAllTypes.newBuilder().getDefaultInstanceForType());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public void testMessageOrBuilder() throws Exception {
|
|
97
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
98
|
+
TestUtil.setAllFields(builder);
|
|
99
|
+
TestAllTypes message = builder.build();
|
|
100
|
+
TestUtil.assertAllFieldsSet(message);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public void testUsingBuilderMultipleTimes() throws Exception {
|
|
104
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
105
|
+
// primitive field scalar and repeated
|
|
106
|
+
builder.setOptionalSfixed64(100);
|
|
107
|
+
builder.addRepeatedInt32(100);
|
|
108
|
+
// enum field scalar and repeated
|
|
109
|
+
builder.setOptionalImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
|
|
110
|
+
builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
|
|
111
|
+
// proto field scalar and repeated
|
|
112
|
+
builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(1));
|
|
113
|
+
builder.addRepeatedForeignMessage(ForeignMessage.newBuilder().setC(1));
|
|
114
|
+
|
|
115
|
+
TestAllTypes value1 = builder.build();
|
|
116
|
+
|
|
117
|
+
assertEquals(100, value1.getOptionalSfixed64());
|
|
118
|
+
assertEquals(100, value1.getRepeatedInt32(0));
|
|
119
|
+
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
|
|
120
|
+
value1.getOptionalImportEnum());
|
|
121
|
+
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
|
|
122
|
+
value1.getRepeatedImportEnum(0));
|
|
123
|
+
assertEquals(1, value1.getOptionalForeignMessage().getC());
|
|
124
|
+
assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
|
|
125
|
+
|
|
126
|
+
// Make sure that builder didn't update previously created values
|
|
127
|
+
builder.setOptionalSfixed64(200);
|
|
128
|
+
builder.setRepeatedInt32(0, 200);
|
|
129
|
+
builder.setOptionalImportEnum(UnittestImport.ImportEnum.IMPORT_FOO);
|
|
130
|
+
builder.setRepeatedImportEnum(0, UnittestImport.ImportEnum.IMPORT_FOO);
|
|
131
|
+
builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(2));
|
|
132
|
+
builder.setRepeatedForeignMessage(0, ForeignMessage.newBuilder().setC(2));
|
|
133
|
+
|
|
134
|
+
TestAllTypes value2 = builder.build();
|
|
135
|
+
|
|
136
|
+
// Make sure value1 didn't change.
|
|
137
|
+
assertEquals(100, value1.getOptionalSfixed64());
|
|
138
|
+
assertEquals(100, value1.getRepeatedInt32(0));
|
|
139
|
+
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
|
|
140
|
+
value1.getOptionalImportEnum());
|
|
141
|
+
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
|
|
142
|
+
value1.getRepeatedImportEnum(0));
|
|
143
|
+
assertEquals(1, value1.getOptionalForeignMessage().getC());
|
|
144
|
+
assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
|
|
145
|
+
|
|
146
|
+
// Make sure value2 is correct
|
|
147
|
+
assertEquals(200, value2.getOptionalSfixed64());
|
|
148
|
+
assertEquals(200, value2.getRepeatedInt32(0));
|
|
149
|
+
assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
|
|
150
|
+
value2.getOptionalImportEnum());
|
|
151
|
+
assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
|
|
152
|
+
value2.getRepeatedImportEnum(0));
|
|
153
|
+
assertEquals(2, value2.getOptionalForeignMessage().getC());
|
|
154
|
+
assertEquals(2, value2.getRepeatedForeignMessage(0).getC());
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public void testProtosShareRepeatedArraysIfDidntChange() throws Exception {
|
|
158
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
159
|
+
builder.addRepeatedInt32(100);
|
|
160
|
+
builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
|
|
161
|
+
builder.addRepeatedForeignMessage(ForeignMessage.getDefaultInstance());
|
|
162
|
+
|
|
163
|
+
TestAllTypes value1 = builder.build();
|
|
164
|
+
TestAllTypes value2 = value1.toBuilder().build();
|
|
165
|
+
|
|
166
|
+
assertSame(value1.getRepeatedInt32List(), value2.getRepeatedInt32List());
|
|
167
|
+
assertSame(value1.getRepeatedImportEnumList(),
|
|
168
|
+
value2.getRepeatedImportEnumList());
|
|
169
|
+
assertSame(value1.getRepeatedForeignMessageList(),
|
|
170
|
+
value2.getRepeatedForeignMessageList());
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public void testRepeatedArraysAreImmutable() throws Exception {
|
|
174
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
175
|
+
builder.addRepeatedInt32(100);
|
|
176
|
+
builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
|
|
177
|
+
builder.addRepeatedForeignMessage(ForeignMessage.getDefaultInstance());
|
|
178
|
+
assertIsUnmodifiable(builder.getRepeatedInt32List());
|
|
179
|
+
assertIsUnmodifiable(builder.getRepeatedImportEnumList());
|
|
180
|
+
assertIsUnmodifiable(builder.getRepeatedForeignMessageList());
|
|
181
|
+
assertIsUnmodifiable(builder.getRepeatedFloatList());
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
TestAllTypes value = builder.build();
|
|
185
|
+
assertIsUnmodifiable(value.getRepeatedInt32List());
|
|
186
|
+
assertIsUnmodifiable(value.getRepeatedImportEnumList());
|
|
187
|
+
assertIsUnmodifiable(value.getRepeatedForeignMessageList());
|
|
188
|
+
assertIsUnmodifiable(value.getRepeatedFloatList());
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public void testParsedMessagesAreImmutable() throws Exception {
|
|
192
|
+
TestAllTypes value = TestAllTypes.PARSER.parseFrom(
|
|
193
|
+
TestUtil.getAllSet().toByteString());
|
|
194
|
+
assertIsUnmodifiable(value.getRepeatedInt32List());
|
|
195
|
+
assertIsUnmodifiable(value.getRepeatedInt64List());
|
|
196
|
+
assertIsUnmodifiable(value.getRepeatedUint32List());
|
|
197
|
+
assertIsUnmodifiable(value.getRepeatedUint64List());
|
|
198
|
+
assertIsUnmodifiable(value.getRepeatedSint32List());
|
|
199
|
+
assertIsUnmodifiable(value.getRepeatedSint64List());
|
|
200
|
+
assertIsUnmodifiable(value.getRepeatedFixed32List());
|
|
201
|
+
assertIsUnmodifiable(value.getRepeatedFixed64List());
|
|
202
|
+
assertIsUnmodifiable(value.getRepeatedSfixed32List());
|
|
203
|
+
assertIsUnmodifiable(value.getRepeatedSfixed64List());
|
|
204
|
+
assertIsUnmodifiable(value.getRepeatedFloatList());
|
|
205
|
+
assertIsUnmodifiable(value.getRepeatedDoubleList());
|
|
206
|
+
assertIsUnmodifiable(value.getRepeatedBoolList());
|
|
207
|
+
assertIsUnmodifiable(value.getRepeatedStringList());
|
|
208
|
+
assertIsUnmodifiable(value.getRepeatedBytesList());
|
|
209
|
+
assertIsUnmodifiable(value.getRepeatedGroupList());
|
|
210
|
+
assertIsUnmodifiable(value.getRepeatedNestedMessageList());
|
|
211
|
+
assertIsUnmodifiable(value.getRepeatedForeignMessageList());
|
|
212
|
+
assertIsUnmodifiable(value.getRepeatedImportMessageList());
|
|
213
|
+
assertIsUnmodifiable(value.getRepeatedNestedEnumList());
|
|
214
|
+
assertIsUnmodifiable(value.getRepeatedForeignEnumList());
|
|
215
|
+
assertIsUnmodifiable(value.getRepeatedImportEnumList());
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private void assertIsUnmodifiable(List<?> list) {
|
|
219
|
+
if (list == Collections.emptyList()) {
|
|
220
|
+
// OKAY -- Need to check this b/c EmptyList allows you to call clear.
|
|
221
|
+
} else {
|
|
222
|
+
try {
|
|
223
|
+
list.clear();
|
|
224
|
+
fail("List wasn't immutable");
|
|
225
|
+
} catch (UnsupportedOperationException e) {
|
|
226
|
+
// good
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public void testSettersRejectNull() throws Exception {
|
|
232
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
233
|
+
try {
|
|
234
|
+
builder.setOptionalString(null);
|
|
235
|
+
fail("Exception was not thrown");
|
|
236
|
+
} catch (NullPointerException e) {
|
|
237
|
+
// We expect this exception.
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
builder.setOptionalBytes(null);
|
|
241
|
+
fail("Exception was not thrown");
|
|
242
|
+
} catch (NullPointerException e) {
|
|
243
|
+
// We expect this exception.
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
builder.setOptionalNestedMessage((TestAllTypes.NestedMessage) null);
|
|
247
|
+
fail("Exception was not thrown");
|
|
248
|
+
} catch (NullPointerException e) {
|
|
249
|
+
// We expect this exception.
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
builder.setOptionalNestedMessage(
|
|
253
|
+
(TestAllTypes.NestedMessage.Builder) null);
|
|
254
|
+
fail("Exception was not thrown");
|
|
255
|
+
} catch (NullPointerException e) {
|
|
256
|
+
// We expect this exception.
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
builder.setOptionalNestedEnum(null);
|
|
260
|
+
fail("Exception was not thrown");
|
|
261
|
+
} catch (NullPointerException e) {
|
|
262
|
+
// We expect this exception.
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
builder.addRepeatedString(null);
|
|
266
|
+
fail("Exception was not thrown");
|
|
267
|
+
} catch (NullPointerException e) {
|
|
268
|
+
// We expect this exception.
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
builder.addRepeatedBytes(null);
|
|
272
|
+
fail("Exception was not thrown");
|
|
273
|
+
} catch (NullPointerException e) {
|
|
274
|
+
// We expect this exception.
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
builder.addRepeatedNestedMessage((TestAllTypes.NestedMessage) null);
|
|
278
|
+
fail("Exception was not thrown");
|
|
279
|
+
} catch (NullPointerException e) {
|
|
280
|
+
// We expect this exception.
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
builder.addRepeatedNestedMessage(
|
|
284
|
+
(TestAllTypes.NestedMessage.Builder) null);
|
|
285
|
+
fail("Exception was not thrown");
|
|
286
|
+
} catch (NullPointerException e) {
|
|
287
|
+
// We expect this exception.
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
builder.addRepeatedNestedEnum(null);
|
|
291
|
+
fail("Exception was not thrown");
|
|
292
|
+
} catch (NullPointerException e) {
|
|
293
|
+
// We expect this exception.
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public void testRepeatedSetters() throws Exception {
|
|
298
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
299
|
+
TestUtil.setAllFields(builder);
|
|
300
|
+
TestUtil.modifyRepeatedFields(builder);
|
|
301
|
+
TestAllTypes message = builder.build();
|
|
302
|
+
TestUtil.assertRepeatedFieldsModified(message);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
public void testRepeatedSettersRejectNull() throws Exception {
|
|
306
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
307
|
+
|
|
308
|
+
builder.addRepeatedString("one");
|
|
309
|
+
builder.addRepeatedString("two");
|
|
310
|
+
try {
|
|
311
|
+
builder.setRepeatedString(1, null);
|
|
312
|
+
fail("Exception was not thrown");
|
|
313
|
+
} catch (NullPointerException e) {
|
|
314
|
+
// We expect this exception.
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
builder.addRepeatedBytes(TestUtil.toBytes("one"));
|
|
318
|
+
builder.addRepeatedBytes(TestUtil.toBytes("two"));
|
|
319
|
+
try {
|
|
320
|
+
builder.setRepeatedBytes(1, null);
|
|
321
|
+
fail("Exception was not thrown");
|
|
322
|
+
} catch (NullPointerException e) {
|
|
323
|
+
// We expect this exception.
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
builder.addRepeatedNestedMessage(
|
|
327
|
+
TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
|
|
328
|
+
builder.addRepeatedNestedMessage(
|
|
329
|
+
TestAllTypes.NestedMessage.newBuilder().setBb(456).build());
|
|
330
|
+
try {
|
|
331
|
+
builder.setRepeatedNestedMessage(1, (TestAllTypes.NestedMessage) null);
|
|
332
|
+
fail("Exception was not thrown");
|
|
333
|
+
} catch (NullPointerException e) {
|
|
334
|
+
// We expect this exception.
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
builder.setRepeatedNestedMessage(
|
|
338
|
+
1, (TestAllTypes.NestedMessage.Builder) null);
|
|
339
|
+
fail("Exception was not thrown");
|
|
340
|
+
} catch (NullPointerException e) {
|
|
341
|
+
// We expect this exception.
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.FOO);
|
|
345
|
+
builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAR);
|
|
346
|
+
try {
|
|
347
|
+
builder.setRepeatedNestedEnum(1, null);
|
|
348
|
+
fail("Exception was not thrown");
|
|
349
|
+
} catch (NullPointerException e) {
|
|
350
|
+
// We expect this exception.
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
public void testRepeatedAppend() throws Exception {
|
|
355
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
356
|
+
|
|
357
|
+
builder.addAllRepeatedInt32(Arrays.asList(1, 2, 3, 4));
|
|
358
|
+
builder.addAllRepeatedForeignEnum(Arrays.asList(ForeignEnum.FOREIGN_BAZ));
|
|
359
|
+
|
|
360
|
+
ForeignMessage foreignMessage =
|
|
361
|
+
ForeignMessage.newBuilder().setC(12).build();
|
|
362
|
+
builder.addAllRepeatedForeignMessage(Arrays.asList(foreignMessage));
|
|
363
|
+
|
|
364
|
+
TestAllTypes message = builder.build();
|
|
365
|
+
assertEquals(message.getRepeatedInt32List(), Arrays.asList(1, 2, 3, 4));
|
|
366
|
+
assertEquals(message.getRepeatedForeignEnumList(),
|
|
367
|
+
Arrays.asList(ForeignEnum.FOREIGN_BAZ));
|
|
368
|
+
assertEquals(1, message.getRepeatedForeignMessageCount());
|
|
369
|
+
assertEquals(12, message.getRepeatedForeignMessage(0).getC());
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
public void testRepeatedAppendRejectsNull() throws Exception {
|
|
373
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
374
|
+
|
|
375
|
+
ForeignMessage foreignMessage =
|
|
376
|
+
ForeignMessage.newBuilder().setC(12).build();
|
|
377
|
+
try {
|
|
378
|
+
builder.addAllRepeatedForeignMessage(
|
|
379
|
+
Arrays.asList(foreignMessage, (ForeignMessage) null));
|
|
380
|
+
fail("Exception was not thrown");
|
|
381
|
+
} catch (NullPointerException e) {
|
|
382
|
+
// We expect this exception.
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
try {
|
|
386
|
+
builder.addAllRepeatedForeignEnum(
|
|
387
|
+
Arrays.asList(ForeignEnum.FOREIGN_BAZ, null));
|
|
388
|
+
fail("Exception was not thrown");
|
|
389
|
+
} catch (NullPointerException e) {
|
|
390
|
+
// We expect this exception.
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
try {
|
|
394
|
+
builder.addAllRepeatedString(Arrays.asList("one", null));
|
|
395
|
+
fail("Exception was not thrown");
|
|
396
|
+
} catch (NullPointerException e) {
|
|
397
|
+
// We expect this exception.
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
try {
|
|
401
|
+
builder.addAllRepeatedBytes(Arrays.asList(TestUtil.toBytes("one"), null));
|
|
402
|
+
fail("Exception was not thrown");
|
|
403
|
+
} catch (NullPointerException e) {
|
|
404
|
+
// We expect this exception.
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
public void testRepeatedAppendIterateOnlyOnce() throws Exception {
|
|
409
|
+
// Create a Iterable that can only be iterated once.
|
|
410
|
+
Iterable<String> stringIterable = new Iterable<String>() {
|
|
411
|
+
private boolean called = false;
|
|
412
|
+
@Override
|
|
413
|
+
public Iterator<String> iterator() {
|
|
414
|
+
if (called) {
|
|
415
|
+
throw new IllegalStateException();
|
|
416
|
+
}
|
|
417
|
+
called = true;
|
|
418
|
+
return Arrays.asList("one", "two", "three").iterator();
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
422
|
+
builder.addAllRepeatedString(stringIterable);
|
|
423
|
+
assertEquals(3, builder.getRepeatedStringCount());
|
|
424
|
+
assertEquals("one", builder.getRepeatedString(0));
|
|
425
|
+
assertEquals("two", builder.getRepeatedString(1));
|
|
426
|
+
assertEquals("three", builder.getRepeatedString(2));
|
|
427
|
+
|
|
428
|
+
try {
|
|
429
|
+
builder.addAllRepeatedString(stringIterable);
|
|
430
|
+
fail("Exception was not thrown");
|
|
431
|
+
} catch (IllegalStateException e) {
|
|
432
|
+
// We expect this exception.
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
public void testMergeFromOtherRejectsNull() throws Exception {
|
|
437
|
+
try {
|
|
438
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
439
|
+
builder.mergeFrom((TestAllTypes) null);
|
|
440
|
+
fail("Exception was not thrown");
|
|
441
|
+
} catch (NullPointerException e) {
|
|
442
|
+
// We expect this exception.
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
public void testSettingForeignMessageUsingBuilder() throws Exception {
|
|
447
|
+
TestAllTypes message = TestAllTypes.newBuilder()
|
|
448
|
+
// Pass builder for foreign message instance.
|
|
449
|
+
.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(123))
|
|
450
|
+
.build();
|
|
451
|
+
TestAllTypes expectedMessage = TestAllTypes.newBuilder()
|
|
452
|
+
// Create expected version passing foreign message instance explicitly.
|
|
453
|
+
.setOptionalForeignMessage(
|
|
454
|
+
ForeignMessage.newBuilder().setC(123).build())
|
|
455
|
+
.build();
|
|
456
|
+
// TODO(ngd): Upgrade to using real #equals method once implemented
|
|
457
|
+
assertEquals(expectedMessage.toString(), message.toString());
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
public void testSettingRepeatedForeignMessageUsingBuilder() throws Exception {
|
|
461
|
+
TestAllTypes message = TestAllTypes.newBuilder()
|
|
462
|
+
// Pass builder for foreign message instance.
|
|
463
|
+
.addRepeatedForeignMessage(ForeignMessage.newBuilder().setC(456))
|
|
464
|
+
.build();
|
|
465
|
+
TestAllTypes expectedMessage = TestAllTypes.newBuilder()
|
|
466
|
+
// Create expected version passing foreign message instance explicitly.
|
|
467
|
+
.addRepeatedForeignMessage(
|
|
468
|
+
ForeignMessage.newBuilder().setC(456).build())
|
|
469
|
+
.build();
|
|
470
|
+
assertEquals(expectedMessage.toString(), message.toString());
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
public void testDefaults() throws Exception {
|
|
474
|
+
TestUtil.assertClear(TestAllTypes.getDefaultInstance());
|
|
475
|
+
TestUtil.assertClear(TestAllTypes.newBuilder().build());
|
|
476
|
+
|
|
477
|
+
TestExtremeDefaultValues message =
|
|
478
|
+
TestExtremeDefaultValues.getDefaultInstance();
|
|
479
|
+
assertEquals("\u1234", message.getUtf8String());
|
|
480
|
+
assertEquals(Double.POSITIVE_INFINITY, message.getInfDouble());
|
|
481
|
+
assertEquals(Double.NEGATIVE_INFINITY, message.getNegInfDouble());
|
|
482
|
+
assertTrue(Double.isNaN(message.getNanDouble()));
|
|
483
|
+
assertEquals(Float.POSITIVE_INFINITY, message.getInfFloat());
|
|
484
|
+
assertEquals(Float.NEGATIVE_INFINITY, message.getNegInfFloat());
|
|
485
|
+
assertTrue(Float.isNaN(message.getNanFloat()));
|
|
486
|
+
assertEquals("? ? ?? ?? ??? ??/ ??-", message.getCppTrigraph());
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
public void testClear() throws Exception {
|
|
490
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
491
|
+
TestUtil.assertClear(builder);
|
|
492
|
+
TestUtil.setAllFields(builder);
|
|
493
|
+
builder.clear();
|
|
494
|
+
TestUtil.assertClear(builder);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
public void testReflectionGetters() throws Exception {
|
|
498
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
499
|
+
TestUtil.setAllFields(builder);
|
|
500
|
+
reflectionTester.assertAllFieldsSetViaReflection(builder);
|
|
501
|
+
|
|
502
|
+
TestAllTypes message = builder.build();
|
|
503
|
+
reflectionTester.assertAllFieldsSetViaReflection(message);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
public void testReflectionSetters() throws Exception {
|
|
507
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
508
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
509
|
+
TestUtil.assertAllFieldsSet(builder);
|
|
510
|
+
|
|
511
|
+
TestAllTypes message = builder.build();
|
|
512
|
+
TestUtil.assertAllFieldsSet(message);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
public void testReflectionSettersRejectNull() throws Exception {
|
|
516
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
517
|
+
reflectionTester.assertReflectionSettersRejectNull(builder);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
public void testReflectionRepeatedSetters() throws Exception {
|
|
521
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
522
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
523
|
+
reflectionTester.modifyRepeatedFieldsViaReflection(builder);
|
|
524
|
+
TestUtil.assertRepeatedFieldsModified(builder);
|
|
525
|
+
|
|
526
|
+
TestAllTypes message = builder.build();
|
|
527
|
+
TestUtil.assertRepeatedFieldsModified(message);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
public void testReflectionRepeatedSettersRejectNull() throws Exception {
|
|
531
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
532
|
+
reflectionTester.assertReflectionRepeatedSettersRejectNull(builder);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
public void testReflectionDefaults() throws Exception {
|
|
536
|
+
reflectionTester.assertClearViaReflection(
|
|
537
|
+
TestAllTypes.getDefaultInstance());
|
|
538
|
+
reflectionTester.assertClearViaReflection(
|
|
539
|
+
TestAllTypes.newBuilder().build());
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
public void testReflectionGetOneof() throws Exception {
|
|
543
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
544
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
545
|
+
Descriptors.OneofDescriptor oneof =
|
|
546
|
+
TestAllTypes.getDescriptor().getOneofs().get(0);
|
|
547
|
+
Descriptors.FieldDescriptor field =
|
|
548
|
+
TestAllTypes.getDescriptor().findFieldByName("oneof_bytes");
|
|
549
|
+
assertSame(field, builder.getOneofFieldDescriptor(oneof));
|
|
550
|
+
|
|
551
|
+
TestAllTypes message = builder.build();
|
|
552
|
+
assertSame(field, message.getOneofFieldDescriptor(oneof));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
public void testReflectionClearOneof() throws Exception {
|
|
556
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
557
|
+
reflectionTester.setAllFieldsViaReflection(builder);
|
|
558
|
+
Descriptors.OneofDescriptor oneof =
|
|
559
|
+
TestAllTypes.getDescriptor().getOneofs().get(0);
|
|
560
|
+
Descriptors.FieldDescriptor field =
|
|
561
|
+
TestAllTypes.getDescriptor().findFieldByName("oneof_bytes");
|
|
562
|
+
|
|
563
|
+
assertTrue(builder.hasOneof(oneof));
|
|
564
|
+
assertTrue(builder.hasField(field));
|
|
565
|
+
builder.clearOneof(oneof);
|
|
566
|
+
assertFalse(builder.hasOneof(oneof));
|
|
567
|
+
assertFalse(builder.hasField(field));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
public void testEnumInterface() throws Exception {
|
|
571
|
+
assertTrue(TestAllTypes.getDefaultInstance().getDefaultNestedEnum()
|
|
572
|
+
instanceof ProtocolMessageEnum);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
public void testEnumMap() throws Exception {
|
|
576
|
+
Internal.EnumLiteMap<ForeignEnum> map = ForeignEnum.internalGetValueMap();
|
|
577
|
+
|
|
578
|
+
for (ForeignEnum value : ForeignEnum.values()) {
|
|
579
|
+
assertEquals(value, map.findValueByNumber(value.getNumber()));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
assertTrue(map.findValueByNumber(12345) == null);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
public void testParsePackedToUnpacked() throws Exception {
|
|
586
|
+
TestUnpackedTypes.Builder builder = TestUnpackedTypes.newBuilder();
|
|
587
|
+
TestUnpackedTypes message =
|
|
588
|
+
builder.mergeFrom(TestUtil.getPackedSet().toByteString()).build();
|
|
589
|
+
TestUtil.assertUnpackedFieldsSet(message);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
public void testParseUnpackedToPacked() throws Exception {
|
|
593
|
+
TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
|
|
594
|
+
TestPackedTypes message =
|
|
595
|
+
builder.mergeFrom(TestUtil.getUnpackedSet().toByteString()).build();
|
|
596
|
+
TestUtil.assertPackedFieldsSet(message);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// =================================================================
|
|
600
|
+
// Extensions.
|
|
601
|
+
|
|
602
|
+
TestUtil.ReflectionTester extensionsReflectionTester =
|
|
603
|
+
new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
|
|
604
|
+
TestUtil.getExtensionRegistry());
|
|
605
|
+
|
|
606
|
+
public void testExtensionMessageOrBuilder() throws Exception {
|
|
607
|
+
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
|
|
608
|
+
TestUtil.setAllExtensions(builder);
|
|
609
|
+
TestAllExtensions message = builder.build();
|
|
610
|
+
TestUtil.assertAllExtensionsSet(message);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
public void testExtensionRepeatedSetters() throws Exception {
|
|
614
|
+
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
|
|
615
|
+
TestUtil.setAllExtensions(builder);
|
|
616
|
+
TestUtil.modifyRepeatedExtensions(builder);
|
|
617
|
+
TestAllExtensions message = builder.build();
|
|
618
|
+
TestUtil.assertRepeatedExtensionsModified(message);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
public void testExtensionDefaults() throws Exception {
|
|
622
|
+
TestUtil.assertExtensionsClear(TestAllExtensions.getDefaultInstance());
|
|
623
|
+
TestUtil.assertExtensionsClear(TestAllExtensions.newBuilder().build());
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
public void testExtensionReflectionGetters() throws Exception {
|
|
627
|
+
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
|
|
628
|
+
TestUtil.setAllExtensions(builder);
|
|
629
|
+
extensionsReflectionTester.assertAllFieldsSetViaReflection(builder);
|
|
630
|
+
|
|
631
|
+
TestAllExtensions message = builder.build();
|
|
632
|
+
extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
public void testExtensionReflectionSetters() throws Exception {
|
|
636
|
+
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
|
|
637
|
+
extensionsReflectionTester.setAllFieldsViaReflection(builder);
|
|
638
|
+
TestUtil.assertAllExtensionsSet(builder);
|
|
639
|
+
|
|
640
|
+
TestAllExtensions message = builder.build();
|
|
641
|
+
TestUtil.assertAllExtensionsSet(message);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
public void testExtensionReflectionSettersRejectNull() throws Exception {
|
|
645
|
+
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
|
|
646
|
+
extensionsReflectionTester.assertReflectionSettersRejectNull(builder);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
public void testExtensionReflectionRepeatedSetters() throws Exception {
|
|
650
|
+
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
|
|
651
|
+
extensionsReflectionTester.setAllFieldsViaReflection(builder);
|
|
652
|
+
extensionsReflectionTester.modifyRepeatedFieldsViaReflection(builder);
|
|
653
|
+
TestUtil.assertRepeatedExtensionsModified(builder);
|
|
654
|
+
|
|
655
|
+
TestAllExtensions message = builder.build();
|
|
656
|
+
TestUtil.assertRepeatedExtensionsModified(message);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
public void testExtensionReflectionRepeatedSettersRejectNull()
|
|
660
|
+
throws Exception {
|
|
661
|
+
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
|
|
662
|
+
extensionsReflectionTester.assertReflectionRepeatedSettersRejectNull(
|
|
663
|
+
builder);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
public void testExtensionReflectionDefaults() throws Exception {
|
|
667
|
+
extensionsReflectionTester.assertClearViaReflection(
|
|
668
|
+
TestAllExtensions.getDefaultInstance());
|
|
669
|
+
extensionsReflectionTester.assertClearViaReflection(
|
|
670
|
+
TestAllExtensions.newBuilder().build());
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
public void testClearExtension() throws Exception {
|
|
674
|
+
// clearExtension() is not actually used in TestUtil, so try it manually.
|
|
675
|
+
assertFalse(
|
|
676
|
+
TestAllExtensions.newBuilder()
|
|
677
|
+
.setExtension(UnittestProto.optionalInt32Extension, 1)
|
|
678
|
+
.clearExtension(UnittestProto.optionalInt32Extension)
|
|
679
|
+
.hasExtension(UnittestProto.optionalInt32Extension));
|
|
680
|
+
assertEquals(0,
|
|
681
|
+
TestAllExtensions.newBuilder()
|
|
682
|
+
.addExtension(UnittestProto.repeatedInt32Extension, 1)
|
|
683
|
+
.clearExtension(UnittestProto.repeatedInt32Extension)
|
|
684
|
+
.getExtensionCount(UnittestProto.repeatedInt32Extension));
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
public void testExtensionCopy() throws Exception {
|
|
688
|
+
TestAllExtensions original = TestUtil.getAllExtensionsSet();
|
|
689
|
+
TestAllExtensions copy = TestAllExtensions.newBuilder(original).build();
|
|
690
|
+
TestUtil.assertAllExtensionsSet(copy);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
public void testExtensionMergeFrom() throws Exception {
|
|
694
|
+
TestAllExtensions original =
|
|
695
|
+
TestAllExtensions.newBuilder()
|
|
696
|
+
.setExtension(UnittestProto.optionalInt32Extension, 1).build();
|
|
697
|
+
TestAllExtensions merged =
|
|
698
|
+
TestAllExtensions.newBuilder().mergeFrom(original).build();
|
|
699
|
+
assertTrue(merged.hasExtension(UnittestProto.optionalInt32Extension));
|
|
700
|
+
assertEquals(
|
|
701
|
+
1, (int) merged.getExtension(UnittestProto.optionalInt32Extension));
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// =================================================================
|
|
705
|
+
// Lite Extensions.
|
|
706
|
+
|
|
707
|
+
// We test lite extensions directly because they have a separate
|
|
708
|
+
// implementation from full extensions. In contrast, we do not test
|
|
709
|
+
// lite fields directly since they are implemented exactly the same as
|
|
710
|
+
// regular fields.
|
|
711
|
+
|
|
712
|
+
public void testLiteExtensionMessageOrBuilder() throws Exception {
|
|
713
|
+
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder();
|
|
714
|
+
TestUtil.setAllExtensions(builder);
|
|
715
|
+
TestUtil.assertAllExtensionsSet(builder);
|
|
716
|
+
|
|
717
|
+
TestAllExtensionsLite message = builder.build();
|
|
718
|
+
TestUtil.assertAllExtensionsSet(message);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
public void testLiteExtensionRepeatedSetters() throws Exception {
|
|
722
|
+
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder();
|
|
723
|
+
TestUtil.setAllExtensions(builder);
|
|
724
|
+
TestUtil.modifyRepeatedExtensions(builder);
|
|
725
|
+
TestUtil.assertRepeatedExtensionsModified(builder);
|
|
726
|
+
|
|
727
|
+
TestAllExtensionsLite message = builder.build();
|
|
728
|
+
TestUtil.assertRepeatedExtensionsModified(message);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
public void testLiteExtensionDefaults() throws Exception {
|
|
732
|
+
TestUtil.assertExtensionsClear(TestAllExtensionsLite.getDefaultInstance());
|
|
733
|
+
TestUtil.assertExtensionsClear(TestAllExtensionsLite.newBuilder().build());
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
public void testClearLiteExtension() throws Exception {
|
|
737
|
+
// clearExtension() is not actually used in TestUtil, so try it manually.
|
|
738
|
+
assertFalse(
|
|
739
|
+
TestAllExtensionsLite.newBuilder()
|
|
740
|
+
.setExtension(UnittestLite.optionalInt32ExtensionLite, 1)
|
|
741
|
+
.clearExtension(UnittestLite.optionalInt32ExtensionLite)
|
|
742
|
+
.hasExtension(UnittestLite.optionalInt32ExtensionLite));
|
|
743
|
+
assertEquals(0,
|
|
744
|
+
TestAllExtensionsLite.newBuilder()
|
|
745
|
+
.addExtension(UnittestLite.repeatedInt32ExtensionLite, 1)
|
|
746
|
+
.clearExtension(UnittestLite.repeatedInt32ExtensionLite)
|
|
747
|
+
.getExtensionCount(UnittestLite.repeatedInt32ExtensionLite));
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
public void testLiteExtensionCopy() throws Exception {
|
|
751
|
+
TestAllExtensionsLite original = TestUtil.getAllLiteExtensionsSet();
|
|
752
|
+
TestAllExtensionsLite copy =
|
|
753
|
+
TestAllExtensionsLite.newBuilder(original).build();
|
|
754
|
+
TestUtil.assertAllExtensionsSet(copy);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
public void testLiteExtensionMergeFrom() throws Exception {
|
|
758
|
+
TestAllExtensionsLite original =
|
|
759
|
+
TestAllExtensionsLite.newBuilder()
|
|
760
|
+
.setExtension(UnittestLite.optionalInt32ExtensionLite, 1).build();
|
|
761
|
+
TestAllExtensionsLite merged =
|
|
762
|
+
TestAllExtensionsLite.newBuilder().mergeFrom(original).build();
|
|
763
|
+
assertTrue(merged.hasExtension(UnittestLite.optionalInt32ExtensionLite));
|
|
764
|
+
assertEquals(
|
|
765
|
+
1, (int) merged.getExtension(UnittestLite.optionalInt32ExtensionLite));
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// =================================================================
|
|
769
|
+
// multiple_files_test
|
|
770
|
+
|
|
771
|
+
// Test that custom options of an file level enum are properly initialized.
|
|
772
|
+
// This test needs to be put before any other access to MultipleFilesTestProto
|
|
773
|
+
// or messages defined in multiple_files_test.proto because the class loading
|
|
774
|
+
// order affects initialization process of custom options.
|
|
775
|
+
public void testEnumValueOptionsInMultipleFilesMode() throws Exception {
|
|
776
|
+
assertEquals(12345, EnumWithNoOuter.FOO.getValueDescriptor().getOptions()
|
|
777
|
+
.getExtension(MultipleFilesTestProto.enumValueOption).intValue());
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
public void testMultipleFilesOption() throws Exception {
|
|
781
|
+
// We mostly just want to check that things compile.
|
|
782
|
+
MessageWithNoOuter message =
|
|
783
|
+
MessageWithNoOuter.newBuilder()
|
|
784
|
+
.setNested(MessageWithNoOuter.NestedMessage.newBuilder().setI(1))
|
|
785
|
+
.addForeign(TestAllTypes.newBuilder().setOptionalInt32(1))
|
|
786
|
+
.setNestedEnum(MessageWithNoOuter.NestedEnum.BAZ)
|
|
787
|
+
.setForeignEnum(EnumWithNoOuter.BAR)
|
|
788
|
+
.build();
|
|
789
|
+
assertEquals(message, MessageWithNoOuter.parseFrom(message.toByteString()));
|
|
790
|
+
|
|
791
|
+
assertEquals(MultipleFilesTestProto.getDescriptor(),
|
|
792
|
+
MessageWithNoOuter.getDescriptor().getFile());
|
|
793
|
+
|
|
794
|
+
Descriptors.FieldDescriptor field =
|
|
795
|
+
MessageWithNoOuter.getDescriptor().findFieldByName("foreign_enum");
|
|
796
|
+
assertEquals(EnumWithNoOuter.BAR.getValueDescriptor(),
|
|
797
|
+
message.getField(field));
|
|
798
|
+
|
|
799
|
+
assertEquals(MultipleFilesTestProto.getDescriptor(),
|
|
800
|
+
ServiceWithNoOuter.getDescriptor().getFile());
|
|
801
|
+
|
|
802
|
+
assertFalse(
|
|
803
|
+
TestAllExtensions.getDefaultInstance().hasExtension(
|
|
804
|
+
MultipleFilesTestProto.extensionWithOuter));
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
public void testOptionalFieldWithRequiredSubfieldsOptimizedForSize()
|
|
808
|
+
throws Exception {
|
|
809
|
+
TestOptionalOptimizedForSize message =
|
|
810
|
+
TestOptionalOptimizedForSize.getDefaultInstance();
|
|
811
|
+
assertTrue(message.isInitialized());
|
|
812
|
+
|
|
813
|
+
message = TestOptionalOptimizedForSize.newBuilder().setO(
|
|
814
|
+
TestRequiredOptimizedForSize.newBuilder().buildPartial()
|
|
815
|
+
).buildPartial();
|
|
816
|
+
assertFalse(message.isInitialized());
|
|
817
|
+
|
|
818
|
+
message = TestOptionalOptimizedForSize.newBuilder().setO(
|
|
819
|
+
TestRequiredOptimizedForSize.newBuilder().setX(5).buildPartial()
|
|
820
|
+
).buildPartial();
|
|
821
|
+
assertTrue(message.isInitialized());
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
public void testUninitializedExtensionInOptimizedForSize()
|
|
825
|
+
throws Exception {
|
|
826
|
+
TestOptimizedForSize.Builder builder = TestOptimizedForSize.newBuilder();
|
|
827
|
+
builder.setExtension(TestOptimizedForSize.testExtension2,
|
|
828
|
+
TestRequiredOptimizedForSize.newBuilder().buildPartial());
|
|
829
|
+
assertFalse(builder.isInitialized());
|
|
830
|
+
assertFalse(builder.buildPartial().isInitialized());
|
|
831
|
+
|
|
832
|
+
builder = TestOptimizedForSize.newBuilder();
|
|
833
|
+
builder.setExtension(TestOptimizedForSize.testExtension2,
|
|
834
|
+
TestRequiredOptimizedForSize.newBuilder().setX(10).buildPartial());
|
|
835
|
+
assertTrue(builder.isInitialized());
|
|
836
|
+
assertTrue(builder.buildPartial().isInitialized());
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
public void testToBuilder() throws Exception {
|
|
840
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
841
|
+
TestUtil.setAllFields(builder);
|
|
842
|
+
TestAllTypes message = builder.build();
|
|
843
|
+
TestUtil.assertAllFieldsSet(message);
|
|
844
|
+
TestUtil.assertAllFieldsSet(message.toBuilder().build());
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
public void testFieldConstantValues() throws Exception {
|
|
848
|
+
assertEquals(TestAllTypes.NestedMessage.BB_FIELD_NUMBER, 1);
|
|
849
|
+
assertEquals(TestAllTypes.OPTIONAL_INT32_FIELD_NUMBER, 1);
|
|
850
|
+
assertEquals(TestAllTypes.OPTIONALGROUP_FIELD_NUMBER, 16);
|
|
851
|
+
assertEquals(TestAllTypes.OPTIONAL_NESTED_MESSAGE_FIELD_NUMBER, 18);
|
|
852
|
+
assertEquals(TestAllTypes.OPTIONAL_NESTED_ENUM_FIELD_NUMBER, 21);
|
|
853
|
+
assertEquals(TestAllTypes.REPEATED_INT32_FIELD_NUMBER, 31);
|
|
854
|
+
assertEquals(TestAllTypes.REPEATEDGROUP_FIELD_NUMBER, 46);
|
|
855
|
+
assertEquals(TestAllTypes.REPEATED_NESTED_MESSAGE_FIELD_NUMBER, 48);
|
|
856
|
+
assertEquals(TestAllTypes.REPEATED_NESTED_ENUM_FIELD_NUMBER, 51);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
public void testExtensionConstantValues() throws Exception {
|
|
860
|
+
assertEquals(UnittestProto.TestRequired.SINGLE_FIELD_NUMBER, 1000);
|
|
861
|
+
assertEquals(UnittestProto.TestRequired.MULTI_FIELD_NUMBER, 1001);
|
|
862
|
+
assertEquals(UnittestProto.OPTIONAL_INT32_EXTENSION_FIELD_NUMBER, 1);
|
|
863
|
+
assertEquals(UnittestProto.OPTIONALGROUP_EXTENSION_FIELD_NUMBER, 16);
|
|
864
|
+
assertEquals(
|
|
865
|
+
UnittestProto.OPTIONAL_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 18);
|
|
866
|
+
assertEquals(UnittestProto.OPTIONAL_NESTED_ENUM_EXTENSION_FIELD_NUMBER, 21);
|
|
867
|
+
assertEquals(UnittestProto.REPEATED_INT32_EXTENSION_FIELD_NUMBER, 31);
|
|
868
|
+
assertEquals(UnittestProto.REPEATEDGROUP_EXTENSION_FIELD_NUMBER, 46);
|
|
869
|
+
assertEquals(
|
|
870
|
+
UnittestProto.REPEATED_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 48);
|
|
871
|
+
assertEquals(UnittestProto.REPEATED_NESTED_ENUM_EXTENSION_FIELD_NUMBER, 51);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
public void testRecursiveMessageDefaultInstance() throws Exception {
|
|
875
|
+
UnittestProto.TestRecursiveMessage message =
|
|
876
|
+
UnittestProto.TestRecursiveMessage.getDefaultInstance();
|
|
877
|
+
assertTrue(message != null);
|
|
878
|
+
assertNotNull(message.getA());
|
|
879
|
+
assertTrue(message.getA() == message);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
public void testSerialize() throws Exception {
|
|
883
|
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
884
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
885
|
+
TestUtil.setAllFields(builder);
|
|
886
|
+
TestAllTypes expected = builder.build();
|
|
887
|
+
ObjectOutputStream out = new ObjectOutputStream(baos);
|
|
888
|
+
try {
|
|
889
|
+
out.writeObject(expected);
|
|
890
|
+
} finally {
|
|
891
|
+
out.close();
|
|
892
|
+
}
|
|
893
|
+
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
894
|
+
ObjectInputStream in = new ObjectInputStream(bais);
|
|
895
|
+
TestAllTypes actual = (TestAllTypes) in.readObject();
|
|
896
|
+
assertEquals(expected, actual);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
public void testSerializePartial() throws Exception {
|
|
900
|
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
901
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
902
|
+
TestAllTypes expected = builder.buildPartial();
|
|
903
|
+
ObjectOutputStream out = new ObjectOutputStream(baos);
|
|
904
|
+
try {
|
|
905
|
+
out.writeObject(expected);
|
|
906
|
+
} finally {
|
|
907
|
+
out.close();
|
|
908
|
+
}
|
|
909
|
+
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
910
|
+
ObjectInputStream in = new ObjectInputStream(bais);
|
|
911
|
+
TestAllTypes actual = (TestAllTypes) in.readObject();
|
|
912
|
+
assertEquals(expected, actual);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
public void testEnumValues() {
|
|
916
|
+
assertEquals(
|
|
917
|
+
TestAllTypes.NestedEnum.BAR.getNumber(),
|
|
918
|
+
TestAllTypes.NestedEnum.BAR_VALUE);
|
|
919
|
+
assertEquals(
|
|
920
|
+
TestAllTypes.NestedEnum.BAZ.getNumber(),
|
|
921
|
+
TestAllTypes.NestedEnum.BAZ_VALUE);
|
|
922
|
+
assertEquals(
|
|
923
|
+
TestAllTypes.NestedEnum.FOO.getNumber(),
|
|
924
|
+
TestAllTypes.NestedEnum.FOO_VALUE);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
public void testNonNestedExtensionInitialization() {
|
|
928
|
+
assertTrue(NonNestedExtension.nonNestedExtension
|
|
929
|
+
.getMessageDefaultInstance() instanceof MyNonNestedExtension);
|
|
930
|
+
assertEquals("nonNestedExtension",
|
|
931
|
+
NonNestedExtension.nonNestedExtension.getDescriptor().getName());
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
public void testNestedExtensionInitialization() {
|
|
935
|
+
assertTrue(MyNestedExtension.recursiveExtension.getMessageDefaultInstance()
|
|
936
|
+
instanceof MessageToBeExtended);
|
|
937
|
+
assertEquals("recursiveExtension",
|
|
938
|
+
MyNestedExtension.recursiveExtension.getDescriptor().getName());
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
public void testNonNestedExtensionLiteInitialization() {
|
|
942
|
+
assertTrue(NonNestedExtensionLite.nonNestedExtensionLite
|
|
943
|
+
.getMessageDefaultInstance() instanceof MyNonNestedExtensionLite);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
public void testNestedExtensionLiteInitialization() {
|
|
947
|
+
assertTrue(MyNestedExtensionLite.recursiveExtensionLite
|
|
948
|
+
.getMessageDefaultInstance() instanceof MessageLiteToBeExtended);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
public void testInvalidations() throws Exception {
|
|
952
|
+
GeneratedMessage.enableAlwaysUseFieldBuildersForTesting();
|
|
953
|
+
TestAllTypes.NestedMessage nestedMessage1 =
|
|
954
|
+
TestAllTypes.NestedMessage.newBuilder().build();
|
|
955
|
+
TestAllTypes.NestedMessage nestedMessage2 =
|
|
956
|
+
TestAllTypes.NestedMessage.newBuilder().build();
|
|
957
|
+
|
|
958
|
+
// Set all three flavors (enum, primitive, message and singular/repeated)
|
|
959
|
+
// and verify no invalidations fired
|
|
960
|
+
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
|
|
961
|
+
|
|
962
|
+
TestAllTypes.Builder builder = (TestAllTypes.Builder)
|
|
963
|
+
((GeneratedMessage) TestAllTypes.getDefaultInstance()).
|
|
964
|
+
newBuilderForType(mockParent);
|
|
965
|
+
builder.setOptionalInt32(1);
|
|
966
|
+
builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR);
|
|
967
|
+
builder.setOptionalNestedMessage(nestedMessage1);
|
|
968
|
+
builder.addRepeatedInt32(1);
|
|
969
|
+
builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAR);
|
|
970
|
+
builder.addRepeatedNestedMessage(nestedMessage1);
|
|
971
|
+
assertEquals(0, mockParent.getInvalidationCount());
|
|
972
|
+
|
|
973
|
+
// Now tell it we want changes and make sure it's only fired once
|
|
974
|
+
// And do this for each flavor
|
|
975
|
+
|
|
976
|
+
// primitive single
|
|
977
|
+
builder.buildPartial();
|
|
978
|
+
builder.setOptionalInt32(2);
|
|
979
|
+
builder.setOptionalInt32(3);
|
|
980
|
+
assertEquals(1, mockParent.getInvalidationCount());
|
|
981
|
+
|
|
982
|
+
// enum single
|
|
983
|
+
builder.buildPartial();
|
|
984
|
+
builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAZ);
|
|
985
|
+
builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR);
|
|
986
|
+
assertEquals(2, mockParent.getInvalidationCount());
|
|
987
|
+
|
|
988
|
+
// message single
|
|
989
|
+
builder.buildPartial();
|
|
990
|
+
builder.setOptionalNestedMessage(nestedMessage2);
|
|
991
|
+
builder.setOptionalNestedMessage(nestedMessage1);
|
|
992
|
+
assertEquals(3, mockParent.getInvalidationCount());
|
|
993
|
+
|
|
994
|
+
// primitive repeated
|
|
995
|
+
builder.buildPartial();
|
|
996
|
+
builder.addRepeatedInt32(2);
|
|
997
|
+
builder.addRepeatedInt32(3);
|
|
998
|
+
assertEquals(4, mockParent.getInvalidationCount());
|
|
999
|
+
|
|
1000
|
+
// enum repeated
|
|
1001
|
+
builder.buildPartial();
|
|
1002
|
+
builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAZ);
|
|
1003
|
+
builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAZ);
|
|
1004
|
+
assertEquals(5, mockParent.getInvalidationCount());
|
|
1005
|
+
|
|
1006
|
+
// message repeated
|
|
1007
|
+
builder.buildPartial();
|
|
1008
|
+
builder.addRepeatedNestedMessage(nestedMessage2);
|
|
1009
|
+
builder.addRepeatedNestedMessage(nestedMessage1);
|
|
1010
|
+
assertEquals(6, mockParent.getInvalidationCount());
|
|
1011
|
+
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
public void testInvalidations_Extensions() throws Exception {
|
|
1015
|
+
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
|
|
1016
|
+
|
|
1017
|
+
TestAllExtensions.Builder builder = (TestAllExtensions.Builder)
|
|
1018
|
+
((GeneratedMessage) TestAllExtensions.getDefaultInstance()).
|
|
1019
|
+
newBuilderForType(mockParent);
|
|
1020
|
+
|
|
1021
|
+
builder.addExtension(UnittestProto.repeatedInt32Extension, 1);
|
|
1022
|
+
builder.setExtension(UnittestProto.repeatedInt32Extension, 0, 2);
|
|
1023
|
+
builder.clearExtension(UnittestProto.repeatedInt32Extension);
|
|
1024
|
+
assertEquals(0, mockParent.getInvalidationCount());
|
|
1025
|
+
|
|
1026
|
+
// Now tell it we want changes and make sure it's only fired once
|
|
1027
|
+
builder.buildPartial();
|
|
1028
|
+
builder.addExtension(UnittestProto.repeatedInt32Extension, 2);
|
|
1029
|
+
builder.addExtension(UnittestProto.repeatedInt32Extension, 3);
|
|
1030
|
+
assertEquals(1, mockParent.getInvalidationCount());
|
|
1031
|
+
|
|
1032
|
+
builder.buildPartial();
|
|
1033
|
+
builder.setExtension(UnittestProto.repeatedInt32Extension, 0, 4);
|
|
1034
|
+
builder.setExtension(UnittestProto.repeatedInt32Extension, 1, 5);
|
|
1035
|
+
assertEquals(2, mockParent.getInvalidationCount());
|
|
1036
|
+
|
|
1037
|
+
builder.buildPartial();
|
|
1038
|
+
builder.clearExtension(UnittestProto.repeatedInt32Extension);
|
|
1039
|
+
builder.clearExtension(UnittestProto.repeatedInt32Extension);
|
|
1040
|
+
assertEquals(3, mockParent.getInvalidationCount());
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
public void testBaseMessageOrBuilder() {
|
|
1044
|
+
// Mostly just makes sure the base interface exists and has some methods.
|
|
1045
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
1046
|
+
TestAllTypes message = builder.buildPartial();
|
|
1047
|
+
TestAllTypesOrBuilder builderAsInterface = (TestAllTypesOrBuilder) builder;
|
|
1048
|
+
TestAllTypesOrBuilder messageAsInterface = (TestAllTypesOrBuilder) message;
|
|
1049
|
+
|
|
1050
|
+
assertEquals(
|
|
1051
|
+
messageAsInterface.getDefaultBool(),
|
|
1052
|
+
messageAsInterface.getDefaultBool());
|
|
1053
|
+
assertEquals(
|
|
1054
|
+
messageAsInterface.getOptionalDouble(),
|
|
1055
|
+
messageAsInterface.getOptionalDouble());
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
public void testMessageOrBuilderGetters() {
|
|
1059
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
1060
|
+
|
|
1061
|
+
// single fields
|
|
1062
|
+
assertSame(ForeignMessage.getDefaultInstance(),
|
|
1063
|
+
builder.getOptionalForeignMessageOrBuilder());
|
|
1064
|
+
ForeignMessage.Builder subBuilder =
|
|
1065
|
+
builder.getOptionalForeignMessageBuilder();
|
|
1066
|
+
assertSame(subBuilder, builder.getOptionalForeignMessageOrBuilder());
|
|
1067
|
+
|
|
1068
|
+
// repeated fields
|
|
1069
|
+
ForeignMessage m0 = ForeignMessage.newBuilder().buildPartial();
|
|
1070
|
+
ForeignMessage m1 = ForeignMessage.newBuilder().buildPartial();
|
|
1071
|
+
ForeignMessage m2 = ForeignMessage.newBuilder().buildPartial();
|
|
1072
|
+
builder.addRepeatedForeignMessage(m0);
|
|
1073
|
+
builder.addRepeatedForeignMessage(m1);
|
|
1074
|
+
builder.addRepeatedForeignMessage(m2);
|
|
1075
|
+
assertSame(m0, builder.getRepeatedForeignMessageOrBuilder(0));
|
|
1076
|
+
assertSame(m1, builder.getRepeatedForeignMessageOrBuilder(1));
|
|
1077
|
+
assertSame(m2, builder.getRepeatedForeignMessageOrBuilder(2));
|
|
1078
|
+
ForeignMessage.Builder b0 = builder.getRepeatedForeignMessageBuilder(0);
|
|
1079
|
+
ForeignMessage.Builder b1 = builder.getRepeatedForeignMessageBuilder(1);
|
|
1080
|
+
assertSame(b0, builder.getRepeatedForeignMessageOrBuilder(0));
|
|
1081
|
+
assertSame(b1, builder.getRepeatedForeignMessageOrBuilder(1));
|
|
1082
|
+
assertSame(m2, builder.getRepeatedForeignMessageOrBuilder(2));
|
|
1083
|
+
|
|
1084
|
+
List<? extends ForeignMessageOrBuilder> messageOrBuilderList =
|
|
1085
|
+
builder.getRepeatedForeignMessageOrBuilderList();
|
|
1086
|
+
assertSame(b0, messageOrBuilderList.get(0));
|
|
1087
|
+
assertSame(b1, messageOrBuilderList.get(1));
|
|
1088
|
+
assertSame(m2, messageOrBuilderList.get(2));
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
public void testGetFieldBuilder() {
|
|
1092
|
+
Descriptor descriptor = TestAllTypes.getDescriptor();
|
|
1093
|
+
|
|
1094
|
+
FieldDescriptor fieldDescriptor =
|
|
1095
|
+
descriptor.findFieldByName("optional_nested_message");
|
|
1096
|
+
FieldDescriptor foreignFieldDescriptor =
|
|
1097
|
+
descriptor.findFieldByName("optional_foreign_message");
|
|
1098
|
+
FieldDescriptor importFieldDescriptor =
|
|
1099
|
+
descriptor.findFieldByName("optional_import_message");
|
|
1100
|
+
|
|
1101
|
+
// Mutate the message with new field builder
|
|
1102
|
+
// Mutate nested message
|
|
1103
|
+
TestAllTypes.Builder builder1 = TestAllTypes.newBuilder();
|
|
1104
|
+
Message.Builder fieldBuilder1 = builder1.newBuilderForField(fieldDescriptor)
|
|
1105
|
+
.mergeFrom((Message) builder1.getField(fieldDescriptor));
|
|
1106
|
+
FieldDescriptor subFieldDescriptor1 =
|
|
1107
|
+
fieldBuilder1.getDescriptorForType().findFieldByName("bb");
|
|
1108
|
+
fieldBuilder1.setField(subFieldDescriptor1, 1);
|
|
1109
|
+
builder1.setField(fieldDescriptor, fieldBuilder1.build());
|
|
1110
|
+
|
|
1111
|
+
// Mutate foreign message
|
|
1112
|
+
Message.Builder foreignFieldBuilder1 = builder1.newBuilderForField(
|
|
1113
|
+
foreignFieldDescriptor)
|
|
1114
|
+
.mergeFrom((Message) builder1.getField(foreignFieldDescriptor));
|
|
1115
|
+
FieldDescriptor subForeignFieldDescriptor1 =
|
|
1116
|
+
foreignFieldBuilder1.getDescriptorForType().findFieldByName("c");
|
|
1117
|
+
foreignFieldBuilder1.setField(subForeignFieldDescriptor1, 2);
|
|
1118
|
+
builder1.setField(foreignFieldDescriptor, foreignFieldBuilder1.build());
|
|
1119
|
+
|
|
1120
|
+
// Mutate import message
|
|
1121
|
+
Message.Builder importFieldBuilder1 = builder1.newBuilderForField(
|
|
1122
|
+
importFieldDescriptor)
|
|
1123
|
+
.mergeFrom((Message) builder1.getField(importFieldDescriptor));
|
|
1124
|
+
FieldDescriptor subImportFieldDescriptor1 =
|
|
1125
|
+
importFieldBuilder1.getDescriptorForType().findFieldByName("d");
|
|
1126
|
+
importFieldBuilder1.setField(subImportFieldDescriptor1, 3);
|
|
1127
|
+
builder1.setField(importFieldDescriptor, importFieldBuilder1.build());
|
|
1128
|
+
|
|
1129
|
+
Message newMessage1 = builder1.build();
|
|
1130
|
+
|
|
1131
|
+
// Mutate the message with existing field builder
|
|
1132
|
+
// Mutate nested message
|
|
1133
|
+
TestAllTypes.Builder builder2 = TestAllTypes.newBuilder();
|
|
1134
|
+
Message.Builder fieldBuilder2 = builder2.getFieldBuilder(fieldDescriptor);
|
|
1135
|
+
FieldDescriptor subFieldDescriptor2 =
|
|
1136
|
+
fieldBuilder2.getDescriptorForType().findFieldByName("bb");
|
|
1137
|
+
fieldBuilder2.setField(subFieldDescriptor2, 1);
|
|
1138
|
+
builder2.setField(fieldDescriptor, fieldBuilder2.build());
|
|
1139
|
+
|
|
1140
|
+
// Mutate foreign message
|
|
1141
|
+
Message.Builder foreignFieldBuilder2 = builder2.newBuilderForField(
|
|
1142
|
+
foreignFieldDescriptor)
|
|
1143
|
+
.mergeFrom((Message) builder2.getField(foreignFieldDescriptor));
|
|
1144
|
+
FieldDescriptor subForeignFieldDescriptor2 =
|
|
1145
|
+
foreignFieldBuilder2.getDescriptorForType().findFieldByName("c");
|
|
1146
|
+
foreignFieldBuilder2.setField(subForeignFieldDescriptor2, 2);
|
|
1147
|
+
builder2.setField(foreignFieldDescriptor, foreignFieldBuilder2.build());
|
|
1148
|
+
|
|
1149
|
+
// Mutate import message
|
|
1150
|
+
Message.Builder importFieldBuilder2 = builder2.newBuilderForField(
|
|
1151
|
+
importFieldDescriptor)
|
|
1152
|
+
.mergeFrom((Message) builder2.getField(importFieldDescriptor));
|
|
1153
|
+
FieldDescriptor subImportFieldDescriptor2 =
|
|
1154
|
+
importFieldBuilder2.getDescriptorForType().findFieldByName("d");
|
|
1155
|
+
importFieldBuilder2.setField(subImportFieldDescriptor2, 3);
|
|
1156
|
+
builder2.setField(importFieldDescriptor, importFieldBuilder2.build());
|
|
1157
|
+
|
|
1158
|
+
Message newMessage2 = builder2.build();
|
|
1159
|
+
|
|
1160
|
+
// These two messages should be equal.
|
|
1161
|
+
assertEquals(newMessage1, newMessage2);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
public void testGetFieldBuilderWithInitializedValue() {
|
|
1165
|
+
Descriptor descriptor = TestAllTypes.getDescriptor();
|
|
1166
|
+
FieldDescriptor fieldDescriptor =
|
|
1167
|
+
descriptor.findFieldByName("optional_nested_message");
|
|
1168
|
+
|
|
1169
|
+
// Before setting field, builder is initialized by default value.
|
|
1170
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
1171
|
+
NestedMessage.Builder fieldBuilder =
|
|
1172
|
+
(NestedMessage.Builder) builder.getFieldBuilder(fieldDescriptor);
|
|
1173
|
+
assertEquals(0, fieldBuilder.getBb());
|
|
1174
|
+
|
|
1175
|
+
// Setting field value with new field builder instance.
|
|
1176
|
+
builder = TestAllTypes.newBuilder();
|
|
1177
|
+
NestedMessage.Builder newFieldBuilder =
|
|
1178
|
+
builder.getOptionalNestedMessageBuilder();
|
|
1179
|
+
newFieldBuilder.setBb(2);
|
|
1180
|
+
// Then get the field builder instance by getFieldBuilder().
|
|
1181
|
+
fieldBuilder =
|
|
1182
|
+
(NestedMessage.Builder) builder.getFieldBuilder(fieldDescriptor);
|
|
1183
|
+
// It should contain new value.
|
|
1184
|
+
assertEquals(2, fieldBuilder.getBb());
|
|
1185
|
+
// These two builder should be equal.
|
|
1186
|
+
assertSame(fieldBuilder, newFieldBuilder);
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
public void testGetFieldBuilderNotSupportedException() {
|
|
1190
|
+
Descriptor descriptor = TestAllTypes.getDescriptor();
|
|
1191
|
+
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
|
1192
|
+
try {
|
|
1193
|
+
builder.getFieldBuilder(descriptor.findFieldByName("optional_int32"));
|
|
1194
|
+
fail("Exception was not thrown");
|
|
1195
|
+
} catch (UnsupportedOperationException e) {
|
|
1196
|
+
// We expect this exception.
|
|
1197
|
+
}
|
|
1198
|
+
try {
|
|
1199
|
+
builder.getFieldBuilder(
|
|
1200
|
+
descriptor.findFieldByName("optional_nested_enum"));
|
|
1201
|
+
fail("Exception was not thrown");
|
|
1202
|
+
} catch (UnsupportedOperationException e) {
|
|
1203
|
+
// We expect this exception.
|
|
1204
|
+
}
|
|
1205
|
+
try {
|
|
1206
|
+
builder.getFieldBuilder(descriptor.findFieldByName("repeated_int32"));
|
|
1207
|
+
fail("Exception was not thrown");
|
|
1208
|
+
} catch (UnsupportedOperationException e) {
|
|
1209
|
+
// We expect this exception.
|
|
1210
|
+
}
|
|
1211
|
+
try {
|
|
1212
|
+
builder.getFieldBuilder(
|
|
1213
|
+
descriptor.findFieldByName("repeated_nested_enum"));
|
|
1214
|
+
fail("Exception was not thrown");
|
|
1215
|
+
} catch (UnsupportedOperationException e) {
|
|
1216
|
+
// We expect this exception.
|
|
1217
|
+
}
|
|
1218
|
+
try {
|
|
1219
|
+
builder.getFieldBuilder(
|
|
1220
|
+
descriptor.findFieldByName("repeated_nested_message"));
|
|
1221
|
+
fail("Exception was not thrown");
|
|
1222
|
+
} catch (UnsupportedOperationException e) {
|
|
1223
|
+
// We expect this exception.
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// Test that when the default outer class name conflicts with another type
|
|
1228
|
+
// defined in the proto the compiler will append a suffix to avoid the
|
|
1229
|
+
// conflict.
|
|
1230
|
+
public void testConflictingOuterClassName() {
|
|
1231
|
+
// We just need to make sure we can refer to the outer class with the
|
|
1232
|
+
// expected name. There is nothing else to test.
|
|
1233
|
+
OuterClassNameTestOuterClass.OuterClassNameTest message =
|
|
1234
|
+
OuterClassNameTestOuterClass.OuterClassNameTest.newBuilder().build();
|
|
1235
|
+
assertTrue(message.getDescriptorForType() ==
|
|
1236
|
+
OuterClassNameTestOuterClass.OuterClassNameTest.getDescriptor());
|
|
1237
|
+
|
|
1238
|
+
OuterClassNameTest2OuterClass.TestMessage2.NestedMessage.OuterClassNameTest2
|
|
1239
|
+
message2 = OuterClassNameTest2OuterClass.TestMessage2.NestedMessage
|
|
1240
|
+
.OuterClassNameTest2.newBuilder().build();
|
|
1241
|
+
assertEquals(0, message2.getSerializedSize());
|
|
1242
|
+
|
|
1243
|
+
OuterClassNameTest3OuterClass.TestMessage3.NestedMessage.OuterClassNameTest3
|
|
1244
|
+
enumValue = OuterClassNameTest3OuterClass.TestMessage3.NestedMessage
|
|
1245
|
+
.OuterClassNameTest3.DUMMY_VALUE;
|
|
1246
|
+
assertEquals(1, enumValue.getNumber());
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// =================================================================
|
|
1250
|
+
// oneof generated code test
|
|
1251
|
+
public void testOneofEnumCase() throws Exception {
|
|
1252
|
+
TestOneof2 message = TestOneof2.newBuilder()
|
|
1253
|
+
.setFooInt(123).setFooString("foo").setFooCord("bar").build();
|
|
1254
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
public void testClearOneof() throws Exception {
|
|
1258
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder().setFooInt(123);
|
|
1259
|
+
assertEquals(TestOneof2.FooCase.FOO_INT, builder.getFooCase());
|
|
1260
|
+
builder.clearFoo();
|
|
1261
|
+
assertEquals(TestOneof2.FooCase.FOO_NOT_SET, builder.getFooCase());
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
public void testSetOneofClearsOthers() throws Exception {
|
|
1265
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1266
|
+
TestOneof2 message =
|
|
1267
|
+
builder.setFooInt(123).setFooString("foo").buildPartial();
|
|
1268
|
+
assertTrue(message.hasFooString());
|
|
1269
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1270
|
+
|
|
1271
|
+
message = builder.setFooCord("bar").buildPartial();
|
|
1272
|
+
assertTrue(message.hasFooCord());
|
|
1273
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1274
|
+
|
|
1275
|
+
message = builder.setFooStringPiece("baz").buildPartial();
|
|
1276
|
+
assertTrue(message.hasFooStringPiece());
|
|
1277
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1278
|
+
|
|
1279
|
+
message = builder.setFooBytes(TestUtil.toBytes("qux")).buildPartial();
|
|
1280
|
+
assertTrue(message.hasFooBytes());
|
|
1281
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1282
|
+
|
|
1283
|
+
message = builder.setFooEnum(TestOneof2.NestedEnum.FOO).buildPartial();
|
|
1284
|
+
assertTrue(message.hasFooEnum());
|
|
1285
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1286
|
+
|
|
1287
|
+
message = builder.setFooMessage(
|
|
1288
|
+
TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build()).buildPartial();
|
|
1289
|
+
assertTrue(message.hasFooMessage());
|
|
1290
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1291
|
+
|
|
1292
|
+
message = builder.setFooInt(123).buildPartial();
|
|
1293
|
+
assertTrue(message.hasFooInt());
|
|
1294
|
+
TestUtil.assertAtMostOneFieldSetOneof(message);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
public void testOneofTypes() throws Exception {
|
|
1298
|
+
// Primitive
|
|
1299
|
+
{
|
|
1300
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1301
|
+
assertEquals(builder.getFooInt(), 0);
|
|
1302
|
+
assertFalse(builder.hasFooInt());
|
|
1303
|
+
assertTrue(builder.setFooInt(123).hasFooInt());
|
|
1304
|
+
assertEquals(builder.getFooInt(), 123);
|
|
1305
|
+
TestOneof2 message = builder.buildPartial();
|
|
1306
|
+
assertTrue(message.hasFooInt());
|
|
1307
|
+
assertEquals(message.getFooInt(), 123);
|
|
1308
|
+
|
|
1309
|
+
assertFalse(builder.clearFooInt().hasFooInt());
|
|
1310
|
+
TestOneof2 message2 = builder.build();
|
|
1311
|
+
assertFalse(message2.hasFooInt());
|
|
1312
|
+
assertEquals(message2.getFooInt(), 0);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
// Enum
|
|
1316
|
+
{
|
|
1317
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1318
|
+
assertEquals(builder.getFooEnum(), TestOneof2.NestedEnum.FOO);
|
|
1319
|
+
assertTrue(builder.setFooEnum(TestOneof2.NestedEnum.BAR).hasFooEnum());
|
|
1320
|
+
assertEquals(builder.getFooEnum(), TestOneof2.NestedEnum.BAR);
|
|
1321
|
+
TestOneof2 message = builder.buildPartial();
|
|
1322
|
+
assertTrue(message.hasFooEnum());
|
|
1323
|
+
assertEquals(message.getFooEnum(), TestOneof2.NestedEnum.BAR);
|
|
1324
|
+
|
|
1325
|
+
assertFalse(builder.clearFooEnum().hasFooEnum());
|
|
1326
|
+
TestOneof2 message2 = builder.build();
|
|
1327
|
+
assertFalse(message2.hasFooEnum());
|
|
1328
|
+
assertEquals(message2.getFooEnum(), TestOneof2.NestedEnum.FOO);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// String
|
|
1332
|
+
{
|
|
1333
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1334
|
+
assertEquals(builder.getFooString(), "");
|
|
1335
|
+
builder.setFooString("foo");
|
|
1336
|
+
assertTrue(builder.hasFooString());
|
|
1337
|
+
assertEquals(builder.getFooString(), "foo");
|
|
1338
|
+
TestOneof2 message = builder.buildPartial();
|
|
1339
|
+
assertTrue(message.hasFooString());
|
|
1340
|
+
assertEquals(message.getFooString(), "foo");
|
|
1341
|
+
assertEquals(message.getFooStringBytes(), TestUtil.toBytes("foo"));
|
|
1342
|
+
|
|
1343
|
+
assertFalse(builder.clearFooString().hasFooString());
|
|
1344
|
+
TestOneof2 message2 = builder.buildPartial();
|
|
1345
|
+
assertFalse(message2.hasFooString());
|
|
1346
|
+
assertEquals(message2.getFooString(), "");
|
|
1347
|
+
assertEquals(message2.getFooStringBytes(), TestUtil.toBytes(""));
|
|
1348
|
+
|
|
1349
|
+
// Get method should not change the oneof value.
|
|
1350
|
+
builder.setFooInt(123);
|
|
1351
|
+
assertEquals(builder.getFooString(), "");
|
|
1352
|
+
assertEquals(builder.getFooStringBytes(), TestUtil.toBytes(""));
|
|
1353
|
+
assertEquals(123, builder.getFooInt());
|
|
1354
|
+
|
|
1355
|
+
message = builder.build();
|
|
1356
|
+
assertEquals(message.getFooString(), "");
|
|
1357
|
+
assertEquals(message.getFooStringBytes(), TestUtil.toBytes(""));
|
|
1358
|
+
assertEquals(123, message.getFooInt());
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
// Cord
|
|
1362
|
+
{
|
|
1363
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1364
|
+
assertEquals(builder.getFooCord(), "");
|
|
1365
|
+
builder.setFooCord("foo");
|
|
1366
|
+
assertTrue(builder.hasFooCord());
|
|
1367
|
+
assertEquals(builder.getFooCord(), "foo");
|
|
1368
|
+
TestOneof2 message = builder.buildPartial();
|
|
1369
|
+
assertTrue(message.hasFooCord());
|
|
1370
|
+
assertEquals(message.getFooCord(), "foo");
|
|
1371
|
+
assertEquals(message.getFooCordBytes(), TestUtil.toBytes("foo"));
|
|
1372
|
+
|
|
1373
|
+
assertFalse(builder.clearFooCord().hasFooCord());
|
|
1374
|
+
TestOneof2 message2 = builder.build();
|
|
1375
|
+
assertFalse(message2.hasFooCord());
|
|
1376
|
+
assertEquals(message2.getFooCord(), "");
|
|
1377
|
+
assertEquals(message2.getFooCordBytes(), TestUtil.toBytes(""));
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// StringPiece
|
|
1381
|
+
{
|
|
1382
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1383
|
+
assertEquals(builder.getFooStringPiece(), "");
|
|
1384
|
+
builder.setFooStringPiece("foo");
|
|
1385
|
+
assertTrue(builder.hasFooStringPiece());
|
|
1386
|
+
assertEquals(builder.getFooStringPiece(), "foo");
|
|
1387
|
+
TestOneof2 message = builder.buildPartial();
|
|
1388
|
+
assertTrue(message.hasFooStringPiece());
|
|
1389
|
+
assertEquals(message.getFooStringPiece(), "foo");
|
|
1390
|
+
assertEquals(message.getFooStringPieceBytes(), TestUtil.toBytes("foo"));
|
|
1391
|
+
|
|
1392
|
+
assertFalse(builder.clearFooStringPiece().hasFooStringPiece());
|
|
1393
|
+
TestOneof2 message2 = builder.build();
|
|
1394
|
+
assertFalse(message2.hasFooStringPiece());
|
|
1395
|
+
assertEquals(message2.getFooStringPiece(), "");
|
|
1396
|
+
assertEquals(message2.getFooStringPieceBytes(), TestUtil.toBytes(""));
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// Message
|
|
1400
|
+
{
|
|
1401
|
+
// set
|
|
1402
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1403
|
+
assertEquals(builder.getFooMessage().getQuxInt(), 0);
|
|
1404
|
+
builder.setFooMessage(
|
|
1405
|
+
TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build());
|
|
1406
|
+
assertTrue(builder.hasFooMessage());
|
|
1407
|
+
assertEquals(builder.getFooMessage().getQuxInt(), 234);
|
|
1408
|
+
TestOneof2 message = builder.buildPartial();
|
|
1409
|
+
assertTrue(message.hasFooMessage());
|
|
1410
|
+
assertEquals(message.getFooMessage().getQuxInt(), 234);
|
|
1411
|
+
|
|
1412
|
+
// clear
|
|
1413
|
+
assertFalse(builder.clearFooMessage().hasFooString());
|
|
1414
|
+
message = builder.build();
|
|
1415
|
+
assertFalse(message.hasFooMessage());
|
|
1416
|
+
assertEquals(message.getFooMessage().getQuxInt(), 0);
|
|
1417
|
+
|
|
1418
|
+
// nested builder
|
|
1419
|
+
builder = TestOneof2.newBuilder();
|
|
1420
|
+
assertSame(builder.getFooMessageOrBuilder(),
|
|
1421
|
+
TestOneof2.NestedMessage.getDefaultInstance());
|
|
1422
|
+
assertFalse(builder.hasFooMessage());
|
|
1423
|
+
builder.getFooMessageBuilder().setQuxInt(123);
|
|
1424
|
+
assertTrue(builder.hasFooMessage());
|
|
1425
|
+
assertEquals(builder.getFooMessage().getQuxInt(), 123);
|
|
1426
|
+
message = builder.build();
|
|
1427
|
+
assertTrue(message.hasFooMessage());
|
|
1428
|
+
assertEquals(message.getFooMessage().getQuxInt(), 123);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
// LazyMessage is tested in LazyMessageLiteTest.java
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
public void testOneofMerge() throws Exception {
|
|
1435
|
+
// Primitive Type
|
|
1436
|
+
{
|
|
1437
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1438
|
+
TestOneof2 message = builder.setFooInt(123).build();
|
|
1439
|
+
TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
|
|
1440
|
+
assertTrue(message2.hasFooInt());
|
|
1441
|
+
assertEquals(message2.getFooInt(), 123);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
// String
|
|
1445
|
+
{
|
|
1446
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1447
|
+
TestOneof2 message = builder.setFooString("foo").build();
|
|
1448
|
+
TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
|
|
1449
|
+
assertTrue(message2.hasFooString());
|
|
1450
|
+
assertEquals(message2.getFooString(), "foo");
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// Enum
|
|
1454
|
+
{
|
|
1455
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1456
|
+
TestOneof2 message = builder.setFooEnum(TestOneof2.NestedEnum.BAR).build();
|
|
1457
|
+
TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
|
|
1458
|
+
assertTrue(message2.hasFooEnum());
|
|
1459
|
+
assertEquals(message2.getFooEnum(), TestOneof2.NestedEnum.BAR);
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// Message
|
|
1463
|
+
{
|
|
1464
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1465
|
+
TestOneof2 message = builder.setFooMessage(
|
|
1466
|
+
TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build()).build();
|
|
1467
|
+
TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
|
|
1468
|
+
assertTrue(message2.hasFooMessage());
|
|
1469
|
+
assertEquals(message2.getFooMessage().getQuxInt(), 234);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
public void testOneofSerialization() throws Exception {
|
|
1474
|
+
// Primitive Type
|
|
1475
|
+
{
|
|
1476
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1477
|
+
TestOneof2 message = builder.setFooInt(123).build();
|
|
1478
|
+
ByteString serialized = message.toByteString();
|
|
1479
|
+
TestOneof2 message2 = TestOneof2.parseFrom(serialized);
|
|
1480
|
+
assertTrue(message2.hasFooInt());
|
|
1481
|
+
assertEquals(message2.getFooInt(), 123);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// String
|
|
1485
|
+
{
|
|
1486
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1487
|
+
TestOneof2 message = builder.setFooString("foo").build();
|
|
1488
|
+
ByteString serialized = message.toByteString();
|
|
1489
|
+
TestOneof2 message2 = TestOneof2.parseFrom(serialized);
|
|
1490
|
+
assertTrue(message2.hasFooString());
|
|
1491
|
+
assertEquals(message2.getFooString(), "foo");
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// Enum
|
|
1495
|
+
{
|
|
1496
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1497
|
+
TestOneof2 message = builder.setFooEnum(TestOneof2.NestedEnum.BAR).build();
|
|
1498
|
+
ByteString serialized = message.toByteString();
|
|
1499
|
+
TestOneof2 message2 = TestOneof2.parseFrom(serialized);
|
|
1500
|
+
assertTrue(message2.hasFooEnum());
|
|
1501
|
+
assertEquals(message2.getFooEnum(), TestOneof2.NestedEnum.BAR);
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
// Message
|
|
1505
|
+
{
|
|
1506
|
+
TestOneof2.Builder builder = TestOneof2.newBuilder();
|
|
1507
|
+
TestOneof2 message = builder.setFooMessage(
|
|
1508
|
+
TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build()).build();
|
|
1509
|
+
ByteString serialized = message.toByteString();
|
|
1510
|
+
TestOneof2 message2 = TestOneof2.parseFrom(serialized);
|
|
1511
|
+
assertTrue(message2.hasFooMessage());
|
|
1512
|
+
assertEquals(message2.getFooMessage().getQuxInt(), 234);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|