Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame^] | 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 | // Author: kenton@google.com (Kenton Varda) |
| 32 | // Based on original Protocol Buffers design by |
| 33 | // Sanjay Ghemawat, Jeff Dean, and others. |
| 34 | // |
| 35 | // A proto file we will use for unit testing. |
| 36 | |
| 37 | syntax = "proto3"; |
| 38 | |
| 39 | // Some generic_services option(s) added automatically. |
| 40 | // See: http://go/proto2-generic-services-default |
| 41 | option cc_generic_services = true; // auto-added |
| 42 | option java_generic_services = true; // auto-added |
| 43 | option py_generic_services = true; // auto-added |
| 44 | option cc_enable_arenas = true; |
| 45 | option csharp_namespace = "Google.Protobuf.TestProtos"; |
| 46 | |
| 47 | import "google/protobuf/unittest_import_proto3.proto"; |
| 48 | |
| 49 | // We don't put this in a package within proto2 because we need to make sure |
| 50 | // that the generated code doesn't depend on being in the proto2 namespace. |
| 51 | // In test_util.h we do "using namespace unittest = protobuf_unittest". |
| 52 | package protobuf_unittest; |
| 53 | |
| 54 | // Protos optimized for SPEED use a strict superset of the generated code |
| 55 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our |
| 56 | // tests for speed unless explicitly testing code size optimization. |
| 57 | option optimize_for = SPEED; |
| 58 | |
| 59 | option java_outer_classname = "UnittestProto"; |
| 60 | |
| 61 | // This proto includes every type of field in both singular and repeated |
| 62 | // forms. |
| 63 | message TestAllTypes { |
| 64 | message NestedMessage { |
| 65 | // The field name "b" fails to compile in proto1 because it conflicts with |
| 66 | // a local variable named "b" in one of the generated methods. Doh. |
| 67 | // This file needs to compile in proto1 to test backwards-compatibility. |
| 68 | int32 bb = 1; |
| 69 | } |
| 70 | |
| 71 | enum NestedEnum { |
| 72 | NESTED_ENUM_UNSPECIFIED = 0; |
| 73 | FOO = 1; |
| 74 | BAR = 2; |
| 75 | BAZ = 3; |
| 76 | NEG = -1; // Intentionally negative. |
| 77 | } |
| 78 | |
| 79 | // Singular |
| 80 | int32 single_int32 = 1; |
| 81 | int64 single_int64 = 2; |
| 82 | uint32 single_uint32 = 3; |
| 83 | uint64 single_uint64 = 4; |
| 84 | sint32 single_sint32 = 5; |
| 85 | sint64 single_sint64 = 6; |
| 86 | fixed32 single_fixed32 = 7; |
| 87 | fixed64 single_fixed64 = 8; |
| 88 | sfixed32 single_sfixed32 = 9; |
| 89 | sfixed64 single_sfixed64 = 10; |
| 90 | float single_float = 11; |
| 91 | double single_double = 12; |
| 92 | bool single_bool = 13; |
| 93 | string single_string = 14; |
| 94 | bytes single_bytes = 15; |
| 95 | |
| 96 | NestedMessage single_nested_message = 18; |
| 97 | ForeignMessage single_foreign_message = 19; |
| 98 | protobuf_unittest_import.ImportMessage single_import_message = 20; |
| 99 | |
| 100 | NestedEnum single_nested_enum = 21; |
| 101 | ForeignEnum single_foreign_enum = 22; |
| 102 | protobuf_unittest_import.ImportEnum single_import_enum = 23; |
| 103 | |
| 104 | // Defined in unittest_import_public.proto |
| 105 | protobuf_unittest_import.PublicImportMessage |
| 106 | single_public_import_message = 26; |
| 107 | |
| 108 | // Repeated |
| 109 | repeated int32 repeated_int32 = 31; |
| 110 | repeated int64 repeated_int64 = 32; |
| 111 | repeated uint32 repeated_uint32 = 33; |
| 112 | repeated uint64 repeated_uint64 = 34; |
| 113 | repeated sint32 repeated_sint32 = 35; |
| 114 | repeated sint64 repeated_sint64 = 36; |
| 115 | repeated fixed32 repeated_fixed32 = 37; |
| 116 | repeated fixed64 repeated_fixed64 = 38; |
| 117 | repeated sfixed32 repeated_sfixed32 = 39; |
| 118 | repeated sfixed64 repeated_sfixed64 = 40; |
| 119 | repeated float repeated_float = 41; |
| 120 | repeated double repeated_double = 42; |
| 121 | repeated bool repeated_bool = 43; |
| 122 | repeated string repeated_string = 44; |
| 123 | repeated bytes repeated_bytes = 45; |
| 124 | |
| 125 | repeated NestedMessage repeated_nested_message = 48; |
| 126 | repeated ForeignMessage repeated_foreign_message = 49; |
| 127 | repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; |
| 128 | |
| 129 | repeated NestedEnum repeated_nested_enum = 51; |
| 130 | repeated ForeignEnum repeated_foreign_enum = 52; |
| 131 | repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; |
| 132 | // Defined in unittest_import_public.proto |
| 133 | repeated protobuf_unittest_import.PublicImportMessage |
| 134 | repeated_public_import_message = 54; |
| 135 | |
| 136 | // For oneof test |
| 137 | oneof oneof_field { |
| 138 | uint32 oneof_uint32 = 111; |
| 139 | NestedMessage oneof_nested_message = 112; |
| 140 | string oneof_string = 113; |
| 141 | bytes oneof_bytes = 114; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // This proto includes a recusively nested message. |
| 146 | message NestedTestAllTypes { |
| 147 | NestedTestAllTypes child = 1; |
| 148 | TestAllTypes payload = 2; |
| 149 | repeated NestedTestAllTypes repeated_child = 3; |
| 150 | } |
| 151 | |
| 152 | message TestDeprecatedFields { |
| 153 | int32 deprecated_int32 = 1 [deprecated=true]; |
| 154 | } |
| 155 | |
| 156 | // Define these after TestAllTypes to make sure the compiler can handle |
| 157 | // that. |
| 158 | message ForeignMessage { |
| 159 | int32 c = 1; |
| 160 | } |
| 161 | |
| 162 | enum ForeignEnum { |
| 163 | FOREIGN_UNSPECIFIED = 0; |
| 164 | FOREIGN_FOO = 4; |
| 165 | FOREIGN_BAR = 5; |
| 166 | FOREIGN_BAZ = 6; |
| 167 | } |
| 168 | |
| 169 | message TestReservedFields { |
| 170 | reserved 2, 15, 9 to 11; |
| 171 | reserved "bar", "baz"; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | // Test that we can use NestedMessage from outside TestAllTypes. |
| 176 | message TestForeignNested { |
| 177 | TestAllTypes.NestedMessage foreign_nested = 1; |
| 178 | } |
| 179 | |
| 180 | // Test that really large tag numbers don't break anything. |
| 181 | message TestReallyLargeTagNumber { |
| 182 | // The largest possible tag number is 2^28 - 1, since the wire format uses |
| 183 | // three bits to communicate wire type. |
| 184 | int32 a = 1; |
| 185 | int32 bb = 268435455; |
| 186 | } |
| 187 | |
| 188 | message TestRecursiveMessage { |
| 189 | TestRecursiveMessage a = 1; |
| 190 | int32 i = 2; |
| 191 | } |
| 192 | |
| 193 | // Test that mutual recursion works. |
| 194 | message TestMutualRecursionA { |
| 195 | TestMutualRecursionB bb = 1; |
| 196 | } |
| 197 | |
| 198 | message TestMutualRecursionB { |
| 199 | TestMutualRecursionA a = 1; |
| 200 | int32 optional_int32 = 2; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | // Test an enum that has multiple values with the same number. |
| 205 | enum TestEnumWithDupValue { |
| 206 | TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0; |
| 207 | option allow_alias = true; |
| 208 | |
| 209 | FOO1 = 1; |
| 210 | BAR1 = 2; |
| 211 | BAZ = 3; |
| 212 | FOO2 = 1; |
| 213 | BAR2 = 2; |
| 214 | } |
| 215 | |
| 216 | // Test an enum with large, unordered values. |
| 217 | enum TestSparseEnum { |
| 218 | TEST_SPARSE_ENUM_UNSPECIFIED = 0; |
| 219 | SPARSE_A = 123; |
| 220 | SPARSE_B = 62374; |
| 221 | SPARSE_C = 12589234; |
| 222 | SPARSE_D = -15; |
| 223 | SPARSE_E = -53452; |
| 224 | // In proto3, value 0 must be the first one specified |
| 225 | // SPARSE_F = 0; |
| 226 | SPARSE_G = 2; |
| 227 | } |
| 228 | |
| 229 | // Test message with CamelCase field names. This violates Protocol Buffer |
| 230 | // standard style. |
| 231 | message TestCamelCaseFieldNames { |
| 232 | int32 PrimitiveField = 1; |
| 233 | string StringField = 2; |
| 234 | ForeignEnum EnumField = 3; |
| 235 | ForeignMessage MessageField = 4; |
| 236 | |
| 237 | repeated int32 RepeatedPrimitiveField = 7; |
| 238 | repeated string RepeatedStringField = 8; |
| 239 | repeated ForeignEnum RepeatedEnumField = 9; |
| 240 | repeated ForeignMessage RepeatedMessageField = 10; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | // We list fields out of order, to ensure that we're using field number and not |
| 245 | // field index to determine serialization order. |
| 246 | message TestFieldOrderings { |
| 247 | string my_string = 11; |
| 248 | int64 my_int = 1; |
| 249 | float my_float = 101; |
| 250 | message NestedMessage { |
| 251 | int64 oo = 2; |
| 252 | // The field name "b" fails to compile in proto1 because it conflicts with |
| 253 | // a local variable named "b" in one of the generated methods. Doh. |
| 254 | // This file needs to compile in proto1 to test backwards-compatibility. |
| 255 | int32 bb = 1; |
| 256 | } |
| 257 | |
| 258 | NestedMessage single_nested_message = 200; |
| 259 | } |
| 260 | |
| 261 | message SparseEnumMessage { |
| 262 | TestSparseEnum sparse_enum = 1; |
| 263 | } |
| 264 | |
| 265 | // Test String and Bytes: string is for valid UTF-8 strings |
| 266 | message OneString { |
| 267 | string data = 1; |
| 268 | } |
| 269 | |
| 270 | message MoreString { |
| 271 | repeated string data = 1; |
| 272 | } |
| 273 | |
| 274 | message OneBytes { |
| 275 | bytes data = 1; |
| 276 | } |
| 277 | |
| 278 | message MoreBytes { |
| 279 | bytes data = 1; |
| 280 | } |
| 281 | |
| 282 | // Test int32, uint32, int64, uint64, and bool are all compatible |
| 283 | message Int32Message { |
| 284 | int32 data = 1; |
| 285 | } |
| 286 | |
| 287 | message Uint32Message { |
| 288 | uint32 data = 1; |
| 289 | } |
| 290 | |
| 291 | message Int64Message { |
| 292 | int64 data = 1; |
| 293 | } |
| 294 | |
| 295 | message Uint64Message { |
| 296 | uint64 data = 1; |
| 297 | } |
| 298 | |
| 299 | message BoolMessage { |
| 300 | bool data = 1; |
| 301 | } |
| 302 | |
| 303 | // Test oneofs. |
| 304 | message TestOneof { |
| 305 | oneof foo { |
| 306 | int32 foo_int = 1; |
| 307 | string foo_string = 2; |
| 308 | TestAllTypes foo_message = 3; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | // Test messages for packed fields |
| 313 | |
| 314 | message TestPackedTypes { |
| 315 | repeated int32 packed_int32 = 90 [packed = true]; |
| 316 | repeated int64 packed_int64 = 91 [packed = true]; |
| 317 | repeated uint32 packed_uint32 = 92 [packed = true]; |
| 318 | repeated uint64 packed_uint64 = 93 [packed = true]; |
| 319 | repeated sint32 packed_sint32 = 94 [packed = true]; |
| 320 | repeated sint64 packed_sint64 = 95 [packed = true]; |
| 321 | repeated fixed32 packed_fixed32 = 96 [packed = true]; |
| 322 | repeated fixed64 packed_fixed64 = 97 [packed = true]; |
| 323 | repeated sfixed32 packed_sfixed32 = 98 [packed = true]; |
| 324 | repeated sfixed64 packed_sfixed64 = 99 [packed = true]; |
| 325 | repeated float packed_float = 100 [packed = true]; |
| 326 | repeated double packed_double = 101 [packed = true]; |
| 327 | repeated bool packed_bool = 102 [packed = true]; |
| 328 | repeated ForeignEnum packed_enum = 103 [packed = true]; |
| 329 | } |
| 330 | |
| 331 | // A message with the same fields as TestPackedTypes, but without packing. Used |
| 332 | // to test packed <-> unpacked wire compatibility. |
| 333 | message TestUnpackedTypes { |
| 334 | repeated int32 unpacked_int32 = 90 [packed = false]; |
| 335 | repeated int64 unpacked_int64 = 91 [packed = false]; |
| 336 | repeated uint32 unpacked_uint32 = 92 [packed = false]; |
| 337 | repeated uint64 unpacked_uint64 = 93 [packed = false]; |
| 338 | repeated sint32 unpacked_sint32 = 94 [packed = false]; |
| 339 | repeated sint64 unpacked_sint64 = 95 [packed = false]; |
| 340 | repeated fixed32 unpacked_fixed32 = 96 [packed = false]; |
| 341 | repeated fixed64 unpacked_fixed64 = 97 [packed = false]; |
| 342 | repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; |
| 343 | repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; |
| 344 | repeated float unpacked_float = 100 [packed = false]; |
| 345 | repeated double unpacked_double = 101 [packed = false]; |
| 346 | repeated bool unpacked_bool = 102 [packed = false]; |
| 347 | repeated ForeignEnum unpacked_enum = 103 [packed = false]; |
| 348 | } |
| 349 | |
| 350 | message TestRepeatedScalarDifferentTagSizes { |
| 351 | // Parsing repeated fixed size values used to fail. This message needs to be |
| 352 | // used in order to get a tag of the right size; all of the repeated fields |
| 353 | // in TestAllTypes didn't trigger the check. |
| 354 | repeated fixed32 repeated_fixed32 = 12; |
| 355 | // Check for a varint type, just for good measure. |
| 356 | repeated int32 repeated_int32 = 13; |
| 357 | |
| 358 | // These have two-byte tags. |
| 359 | repeated fixed64 repeated_fixed64 = 2046; |
| 360 | repeated int64 repeated_int64 = 2047; |
| 361 | |
| 362 | // Three byte tags. |
| 363 | repeated float repeated_float = 262142; |
| 364 | repeated uint64 repeated_uint64 = 262143; |
| 365 | } |
| 366 | |
| 367 | message TestCommentInjectionMessage { |
| 368 | // */ <- This should not close the generated doc comment |
| 369 | string a = 1; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | // Test that RPC services work. |
| 374 | message FooRequest {} |
| 375 | message FooResponse {} |
| 376 | |
| 377 | message FooClientMessage {} |
| 378 | message FooServerMessage{} |
| 379 | |
| 380 | service TestService { |
| 381 | rpc Foo(FooRequest) returns (FooResponse); |
| 382 | rpc Bar(BarRequest) returns (BarResponse); |
| 383 | } |
| 384 | |
| 385 | |
| 386 | message BarRequest {} |
| 387 | message BarResponse {} |
| 388 | |