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 = "proto2"; |
| 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 | |
| 46 | import "google/protobuf/unittest_import.proto"; |
| 47 | |
| 48 | // We don't put this in a package within proto2 because we need to make sure |
| 49 | // that the generated code doesn't depend on being in the proto2 namespace. |
| 50 | // In test_util.h we do "using namespace unittest = protobuf_unittest". |
| 51 | package protobuf_unittest; |
| 52 | |
| 53 | // Protos optimized for SPEED use a strict superset of the generated code |
| 54 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our |
| 55 | // tests for speed unless explicitly testing code size optimization. |
| 56 | option optimize_for = SPEED; |
| 57 | |
| 58 | option java_outer_classname = "UnittestProto"; |
| 59 | |
| 60 | // This proto includes every type of field in both singular and repeated |
| 61 | // forms. |
| 62 | message TestAllTypes { |
| 63 | message NestedMessage { |
| 64 | // The field name "b" fails to compile in proto1 because it conflicts with |
| 65 | // a local variable named "b" in one of the generated methods. Doh. |
| 66 | // This file needs to compile in proto1 to test backwards-compatibility. |
| 67 | optional int32 bb = 1; |
| 68 | } |
| 69 | |
| 70 | enum NestedEnum { |
| 71 | FOO = 1; |
| 72 | BAR = 2; |
| 73 | BAZ = 3; |
| 74 | NEG = -1; // Intentionally negative. |
| 75 | } |
| 76 | |
| 77 | // Singular |
| 78 | optional int32 optional_int32 = 1; |
| 79 | optional int64 optional_int64 = 2; |
| 80 | optional uint32 optional_uint32 = 3; |
| 81 | optional uint64 optional_uint64 = 4; |
| 82 | optional sint32 optional_sint32 = 5; |
| 83 | optional sint64 optional_sint64 = 6; |
| 84 | optional fixed32 optional_fixed32 = 7; |
| 85 | optional fixed64 optional_fixed64 = 8; |
| 86 | optional sfixed32 optional_sfixed32 = 9; |
| 87 | optional sfixed64 optional_sfixed64 = 10; |
| 88 | optional float optional_float = 11; |
| 89 | optional double optional_double = 12; |
| 90 | optional bool optional_bool = 13; |
| 91 | optional string optional_string = 14; |
| 92 | optional bytes optional_bytes = 15; |
| 93 | |
| 94 | optional group OptionalGroup = 16 { |
| 95 | optional int32 a = 17; |
| 96 | } |
| 97 | |
| 98 | optional NestedMessage optional_nested_message = 18; |
| 99 | optional ForeignMessage optional_foreign_message = 19; |
| 100 | optional protobuf_unittest_import.ImportMessage optional_import_message = 20; |
| 101 | |
| 102 | optional NestedEnum optional_nested_enum = 21; |
| 103 | optional ForeignEnum optional_foreign_enum = 22; |
| 104 | optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; |
| 105 | |
| 106 | optional string optional_string_piece = 24 [ctype=STRING_PIECE]; |
| 107 | optional string optional_cord = 25 [ctype=CORD]; |
| 108 | |
| 109 | // Defined in unittest_import_public.proto |
| 110 | optional protobuf_unittest_import.PublicImportMessage |
| 111 | optional_public_import_message = 26; |
| 112 | |
| 113 | optional NestedMessage optional_lazy_message = 27 [lazy=true]; |
| 114 | |
| 115 | // Repeated |
| 116 | repeated int32 repeated_int32 = 31; |
| 117 | repeated int64 repeated_int64 = 32; |
| 118 | repeated uint32 repeated_uint32 = 33; |
| 119 | repeated uint64 repeated_uint64 = 34; |
| 120 | repeated sint32 repeated_sint32 = 35; |
| 121 | repeated sint64 repeated_sint64 = 36; |
| 122 | repeated fixed32 repeated_fixed32 = 37; |
| 123 | repeated fixed64 repeated_fixed64 = 38; |
| 124 | repeated sfixed32 repeated_sfixed32 = 39; |
| 125 | repeated sfixed64 repeated_sfixed64 = 40; |
| 126 | repeated float repeated_float = 41; |
| 127 | repeated double repeated_double = 42; |
| 128 | repeated bool repeated_bool = 43; |
| 129 | repeated string repeated_string = 44; |
| 130 | repeated bytes repeated_bytes = 45; |
| 131 | |
| 132 | repeated group RepeatedGroup = 46 { |
| 133 | optional int32 a = 47; |
| 134 | } |
| 135 | |
| 136 | repeated NestedMessage repeated_nested_message = 48; |
| 137 | repeated ForeignMessage repeated_foreign_message = 49; |
| 138 | repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; |
| 139 | |
| 140 | repeated NestedEnum repeated_nested_enum = 51; |
| 141 | repeated ForeignEnum repeated_foreign_enum = 52; |
| 142 | repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; |
| 143 | |
| 144 | repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; |
| 145 | repeated string repeated_cord = 55 [ctype=CORD]; |
| 146 | |
| 147 | repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; |
| 148 | |
| 149 | // Singular with defaults |
| 150 | optional int32 default_int32 = 61 [default = 41 ]; |
| 151 | optional int64 default_int64 = 62 [default = 42 ]; |
| 152 | optional uint32 default_uint32 = 63 [default = 43 ]; |
| 153 | optional uint64 default_uint64 = 64 [default = 44 ]; |
| 154 | optional sint32 default_sint32 = 65 [default = -45 ]; |
| 155 | optional sint64 default_sint64 = 66 [default = 46 ]; |
| 156 | optional fixed32 default_fixed32 = 67 [default = 47 ]; |
| 157 | optional fixed64 default_fixed64 = 68 [default = 48 ]; |
| 158 | optional sfixed32 default_sfixed32 = 69 [default = 49 ]; |
| 159 | optional sfixed64 default_sfixed64 = 70 [default = -50 ]; |
| 160 | optional float default_float = 71 [default = 51.5 ]; |
| 161 | optional double default_double = 72 [default = 52e3 ]; |
| 162 | optional bool default_bool = 73 [default = true ]; |
| 163 | optional string default_string = 74 [default = "hello"]; |
| 164 | optional bytes default_bytes = 75 [default = "world"]; |
| 165 | |
| 166 | optional NestedEnum default_nested_enum = 81 [default = BAR ]; |
| 167 | optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; |
| 168 | optional protobuf_unittest_import.ImportEnum |
| 169 | default_import_enum = 83 [default = IMPORT_BAR]; |
| 170 | |
| 171 | optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; |
| 172 | optional string default_cord = 85 [ctype=CORD,default="123"]; |
| 173 | |
| 174 | // For oneof test |
| 175 | oneof oneof_field { |
| 176 | uint32 oneof_uint32 = 111; |
| 177 | NestedMessage oneof_nested_message = 112; |
| 178 | string oneof_string = 113; |
| 179 | bytes oneof_bytes = 114; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // This proto includes a recusively nested message. |
| 184 | message NestedTestAllTypes { |
| 185 | optional NestedTestAllTypes child = 1; |
| 186 | optional TestAllTypes payload = 2; |
| 187 | repeated NestedTestAllTypes repeated_child = 3; |
| 188 | } |
| 189 | |
| 190 | message TestDeprecatedFields { |
| 191 | optional int32 deprecated_int32 = 1 [deprecated=true]; |
| 192 | } |
| 193 | |
| 194 | // Define these after TestAllTypes to make sure the compiler can handle |
| 195 | // that. |
| 196 | message ForeignMessage { |
| 197 | optional int32 c = 1; |
| 198 | } |
| 199 | |
| 200 | enum ForeignEnum { |
| 201 | FOREIGN_FOO = 4; |
| 202 | FOREIGN_BAR = 5; |
| 203 | FOREIGN_BAZ = 6; |
| 204 | } |
| 205 | |
| 206 | message TestReservedFields { |
| 207 | reserved 2, 15, 9 to 11; |
| 208 | reserved "bar", "baz"; |
| 209 | } |
| 210 | |
| 211 | message TestAllExtensions { |
| 212 | extensions 1 to max; |
| 213 | } |
| 214 | |
| 215 | extend TestAllExtensions { |
| 216 | // Singular |
| 217 | optional int32 optional_int32_extension = 1; |
| 218 | optional int64 optional_int64_extension = 2; |
| 219 | optional uint32 optional_uint32_extension = 3; |
| 220 | optional uint64 optional_uint64_extension = 4; |
| 221 | optional sint32 optional_sint32_extension = 5; |
| 222 | optional sint64 optional_sint64_extension = 6; |
| 223 | optional fixed32 optional_fixed32_extension = 7; |
| 224 | optional fixed64 optional_fixed64_extension = 8; |
| 225 | optional sfixed32 optional_sfixed32_extension = 9; |
| 226 | optional sfixed64 optional_sfixed64_extension = 10; |
| 227 | optional float optional_float_extension = 11; |
| 228 | optional double optional_double_extension = 12; |
| 229 | optional bool optional_bool_extension = 13; |
| 230 | optional string optional_string_extension = 14; |
| 231 | optional bytes optional_bytes_extension = 15; |
| 232 | |
| 233 | optional group OptionalGroup_extension = 16 { |
| 234 | optional int32 a = 17; |
| 235 | } |
| 236 | |
| 237 | optional TestAllTypes.NestedMessage optional_nested_message_extension = 18; |
| 238 | optional ForeignMessage optional_foreign_message_extension = 19; |
| 239 | optional protobuf_unittest_import.ImportMessage |
| 240 | optional_import_message_extension = 20; |
| 241 | |
| 242 | optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21; |
| 243 | optional ForeignEnum optional_foreign_enum_extension = 22; |
| 244 | optional protobuf_unittest_import.ImportEnum |
| 245 | optional_import_enum_extension = 23; |
| 246 | |
| 247 | optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE]; |
| 248 | optional string optional_cord_extension = 25 [ctype=CORD]; |
| 249 | |
| 250 | optional protobuf_unittest_import.PublicImportMessage |
| 251 | optional_public_import_message_extension = 26; |
| 252 | |
| 253 | optional TestAllTypes.NestedMessage |
| 254 | optional_lazy_message_extension = 27 [lazy=true]; |
| 255 | |
| 256 | // Repeated |
| 257 | repeated int32 repeated_int32_extension = 31; |
| 258 | repeated int64 repeated_int64_extension = 32; |
| 259 | repeated uint32 repeated_uint32_extension = 33; |
| 260 | repeated uint64 repeated_uint64_extension = 34; |
| 261 | repeated sint32 repeated_sint32_extension = 35; |
| 262 | repeated sint64 repeated_sint64_extension = 36; |
| 263 | repeated fixed32 repeated_fixed32_extension = 37; |
| 264 | repeated fixed64 repeated_fixed64_extension = 38; |
| 265 | repeated sfixed32 repeated_sfixed32_extension = 39; |
| 266 | repeated sfixed64 repeated_sfixed64_extension = 40; |
| 267 | repeated float repeated_float_extension = 41; |
| 268 | repeated double repeated_double_extension = 42; |
| 269 | repeated bool repeated_bool_extension = 43; |
| 270 | repeated string repeated_string_extension = 44; |
| 271 | repeated bytes repeated_bytes_extension = 45; |
| 272 | |
| 273 | repeated group RepeatedGroup_extension = 46 { |
| 274 | optional int32 a = 47; |
| 275 | } |
| 276 | |
| 277 | repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48; |
| 278 | repeated ForeignMessage repeated_foreign_message_extension = 49; |
| 279 | repeated protobuf_unittest_import.ImportMessage |
| 280 | repeated_import_message_extension = 50; |
| 281 | |
| 282 | repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51; |
| 283 | repeated ForeignEnum repeated_foreign_enum_extension = 52; |
| 284 | repeated protobuf_unittest_import.ImportEnum |
| 285 | repeated_import_enum_extension = 53; |
| 286 | |
| 287 | repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE]; |
| 288 | repeated string repeated_cord_extension = 55 [ctype=CORD]; |
| 289 | |
| 290 | repeated TestAllTypes.NestedMessage |
| 291 | repeated_lazy_message_extension = 57 [lazy=true]; |
| 292 | |
| 293 | // Singular with defaults |
| 294 | optional int32 default_int32_extension = 61 [default = 41 ]; |
| 295 | optional int64 default_int64_extension = 62 [default = 42 ]; |
| 296 | optional uint32 default_uint32_extension = 63 [default = 43 ]; |
| 297 | optional uint64 default_uint64_extension = 64 [default = 44 ]; |
| 298 | optional sint32 default_sint32_extension = 65 [default = -45 ]; |
| 299 | optional sint64 default_sint64_extension = 66 [default = 46 ]; |
| 300 | optional fixed32 default_fixed32_extension = 67 [default = 47 ]; |
| 301 | optional fixed64 default_fixed64_extension = 68 [default = 48 ]; |
| 302 | optional sfixed32 default_sfixed32_extension = 69 [default = 49 ]; |
| 303 | optional sfixed64 default_sfixed64_extension = 70 [default = -50 ]; |
| 304 | optional float default_float_extension = 71 [default = 51.5 ]; |
| 305 | optional double default_double_extension = 72 [default = 52e3 ]; |
| 306 | optional bool default_bool_extension = 73 [default = true ]; |
| 307 | optional string default_string_extension = 74 [default = "hello"]; |
| 308 | optional bytes default_bytes_extension = 75 [default = "world"]; |
| 309 | |
| 310 | optional TestAllTypes.NestedEnum |
| 311 | default_nested_enum_extension = 81 [default = BAR]; |
| 312 | optional ForeignEnum |
| 313 | default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; |
| 314 | optional protobuf_unittest_import.ImportEnum |
| 315 | default_import_enum_extension = 83 [default = IMPORT_BAR]; |
| 316 | |
| 317 | optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, |
| 318 | default="abc"]; |
| 319 | optional string default_cord_extension = 85 [ctype=CORD, default="123"]; |
| 320 | |
| 321 | // For oneof test |
| 322 | optional uint32 oneof_uint32_extension = 111; |
| 323 | optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112; |
| 324 | optional string oneof_string_extension = 113; |
| 325 | optional bytes oneof_bytes_extension = 114; |
| 326 | } |
| 327 | |
| 328 | message TestNestedExtension { |
| 329 | extend TestAllExtensions { |
| 330 | // Check for bug where string extensions declared in tested scope did not |
| 331 | // compile. |
| 332 | optional string test = 1002 [default="test"]; |
| 333 | // Used to test if generated extension name is correct when there are |
| 334 | // underscores. |
| 335 | optional string nested_string_extension = 1003; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // We have separate messages for testing required fields because it's |
| 340 | // annoying to have to fill in required fields in TestProto in order to |
| 341 | // do anything with it. Note that we don't need to test every type of |
| 342 | // required filed because the code output is basically identical to |
| 343 | // optional fields for all types. |
| 344 | message TestRequired { |
| 345 | required int32 a = 1; |
| 346 | optional int32 dummy2 = 2; |
| 347 | required int32 b = 3; |
| 348 | |
| 349 | extend TestAllExtensions { |
| 350 | optional TestRequired single = 1000; |
| 351 | repeated TestRequired multi = 1001; |
| 352 | } |
| 353 | |
| 354 | // Pad the field count to 32 so that we can test that IsInitialized() |
| 355 | // properly checks multiple elements of has_bits_. |
| 356 | optional int32 dummy4 = 4; |
| 357 | optional int32 dummy5 = 5; |
| 358 | optional int32 dummy6 = 6; |
| 359 | optional int32 dummy7 = 7; |
| 360 | optional int32 dummy8 = 8; |
| 361 | optional int32 dummy9 = 9; |
| 362 | optional int32 dummy10 = 10; |
| 363 | optional int32 dummy11 = 11; |
| 364 | optional int32 dummy12 = 12; |
| 365 | optional int32 dummy13 = 13; |
| 366 | optional int32 dummy14 = 14; |
| 367 | optional int32 dummy15 = 15; |
| 368 | optional int32 dummy16 = 16; |
| 369 | optional int32 dummy17 = 17; |
| 370 | optional int32 dummy18 = 18; |
| 371 | optional int32 dummy19 = 19; |
| 372 | optional int32 dummy20 = 20; |
| 373 | optional int32 dummy21 = 21; |
| 374 | optional int32 dummy22 = 22; |
| 375 | optional int32 dummy23 = 23; |
| 376 | optional int32 dummy24 = 24; |
| 377 | optional int32 dummy25 = 25; |
| 378 | optional int32 dummy26 = 26; |
| 379 | optional int32 dummy27 = 27; |
| 380 | optional int32 dummy28 = 28; |
| 381 | optional int32 dummy29 = 29; |
| 382 | optional int32 dummy30 = 30; |
| 383 | optional int32 dummy31 = 31; |
| 384 | optional int32 dummy32 = 32; |
| 385 | |
| 386 | required int32 c = 33; |
| 387 | } |
| 388 | |
| 389 | message TestRequiredForeign { |
| 390 | optional TestRequired optional_message = 1; |
| 391 | repeated TestRequired repeated_message = 2; |
| 392 | optional int32 dummy = 3; |
| 393 | } |
| 394 | |
| 395 | // Test that we can use NestedMessage from outside TestAllTypes. |
| 396 | message TestForeignNested { |
| 397 | optional TestAllTypes.NestedMessage foreign_nested = 1; |
| 398 | } |
| 399 | |
| 400 | // TestEmptyMessage is used to test unknown field support. |
| 401 | message TestEmptyMessage { |
| 402 | } |
| 403 | |
| 404 | // Like above, but declare all field numbers as potential extensions. No |
| 405 | // actual extensions should ever be defined for this type. |
| 406 | message TestEmptyMessageWithExtensions { |
| 407 | extensions 1 to max; |
| 408 | } |
| 409 | |
| 410 | message TestMultipleExtensionRanges { |
| 411 | extensions 42; |
| 412 | extensions 4143 to 4243; |
| 413 | extensions 65536 to max; |
| 414 | } |
| 415 | |
| 416 | // Test that really large tag numbers don't break anything. |
| 417 | message TestReallyLargeTagNumber { |
| 418 | // The largest possible tag number is 2^28 - 1, since the wire format uses |
| 419 | // three bits to communicate wire type. |
| 420 | optional int32 a = 1; |
| 421 | optional int32 bb = 268435455; |
| 422 | } |
| 423 | |
| 424 | message TestRecursiveMessage { |
| 425 | optional TestRecursiveMessage a = 1; |
| 426 | optional int32 i = 2; |
| 427 | } |
| 428 | |
| 429 | // Test that mutual recursion works. |
| 430 | message TestMutualRecursionA { |
| 431 | optional TestMutualRecursionB bb = 1; |
| 432 | } |
| 433 | |
| 434 | message TestMutualRecursionB { |
| 435 | optional TestMutualRecursionA a = 1; |
| 436 | optional int32 optional_int32 = 2; |
| 437 | } |
| 438 | |
| 439 | // Test that groups have disjoint field numbers from their siblings and |
| 440 | // parents. This is NOT possible in proto1; only google.protobuf. When attempting |
| 441 | // to compile with proto1, this will emit an error; so we only include it |
| 442 | // in protobuf_unittest_proto. |
| 443 | message TestDupFieldNumber { // NO_PROTO1 |
| 444 | optional int32 a = 1; // NO_PROTO1 |
| 445 | optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 |
| 446 | optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 |
| 447 | } // NO_PROTO1 |
| 448 | |
| 449 | // Additional messages for testing lazy fields. |
| 450 | message TestEagerMessage { |
| 451 | optional TestAllTypes sub_message = 1 [lazy=false]; |
| 452 | } |
| 453 | message TestLazyMessage { |
| 454 | optional TestAllTypes sub_message = 1 [lazy=true]; |
| 455 | } |
| 456 | |
| 457 | // Needed for a Python test. |
| 458 | message TestNestedMessageHasBits { |
| 459 | message NestedMessage { |
| 460 | repeated int32 nestedmessage_repeated_int32 = 1; |
| 461 | repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2; |
| 462 | } |
| 463 | optional NestedMessage optional_nested_message = 1; |
| 464 | } |
| 465 | |
| 466 | |
| 467 | // Test an enum that has multiple values with the same number. |
| 468 | enum TestEnumWithDupValue { |
| 469 | option allow_alias = true; |
| 470 | |
| 471 | FOO1 = 1; |
| 472 | BAR1 = 2; |
| 473 | BAZ = 3; |
| 474 | FOO2 = 1; |
| 475 | BAR2 = 2; |
| 476 | } |
| 477 | |
| 478 | // Test an enum with large, unordered values. |
| 479 | enum TestSparseEnum { |
| 480 | SPARSE_A = 123; |
| 481 | SPARSE_B = 62374; |
| 482 | SPARSE_C = 12589234; |
| 483 | SPARSE_D = -15; |
| 484 | SPARSE_E = -53452; |
| 485 | SPARSE_F = 0; |
| 486 | SPARSE_G = 2; |
| 487 | } |
| 488 | |
| 489 | // Test message with CamelCase field names. This violates Protocol Buffer |
| 490 | // standard style. |
| 491 | message TestCamelCaseFieldNames { |
| 492 | optional int32 PrimitiveField = 1; |
| 493 | optional string StringField = 2; |
| 494 | optional ForeignEnum EnumField = 3; |
| 495 | optional ForeignMessage MessageField = 4; |
| 496 | optional string StringPieceField = 5 [ctype=STRING_PIECE]; |
| 497 | optional string CordField = 6 [ctype=CORD]; |
| 498 | |
| 499 | repeated int32 RepeatedPrimitiveField = 7; |
| 500 | repeated string RepeatedStringField = 8; |
| 501 | repeated ForeignEnum RepeatedEnumField = 9; |
| 502 | repeated ForeignMessage RepeatedMessageField = 10; |
| 503 | repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE]; |
| 504 | repeated string RepeatedCordField = 12 [ctype=CORD]; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | // We list fields out of order, to ensure that we're using field number and not |
| 509 | // field index to determine serialization order. |
| 510 | message TestFieldOrderings { |
| 511 | optional string my_string = 11; |
| 512 | extensions 2 to 10; |
| 513 | optional int64 my_int = 1; |
| 514 | extensions 12 to 100; |
| 515 | optional float my_float = 101; |
| 516 | message NestedMessage { |
| 517 | optional int64 oo = 2; |
| 518 | // The field name "b" fails to compile in proto1 because it conflicts with |
| 519 | // a local variable named "b" in one of the generated methods. Doh. |
| 520 | // This file needs to compile in proto1 to test backwards-compatibility. |
| 521 | optional int32 bb = 1; |
| 522 | } |
| 523 | |
| 524 | optional NestedMessage optional_nested_message = 200; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | extend TestFieldOrderings { |
| 529 | optional string my_extension_string = 50; |
| 530 | optional int32 my_extension_int = 5; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | message TestExtremeDefaultValues { |
| 535 | optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; |
| 536 | optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF]; |
| 537 | optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF]; |
| 538 | optional int32 small_int32 = 4 [default = -0x7FFFFFFF]; |
| 539 | optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF]; |
| 540 | optional int32 really_small_int32 = 21 [default = -0x80000000]; |
| 541 | optional int64 really_small_int64 = 22 [default = -0x8000000000000000]; |
| 542 | |
| 543 | // The default value here is UTF-8 for "\u1234". (We could also just type |
| 544 | // the UTF-8 text directly into this text file rather than escape it, but |
| 545 | // lots of people use editors that would be confused by this.) |
| 546 | optional string utf8_string = 6 [default = "\341\210\264"]; |
| 547 | |
| 548 | // Tests for single-precision floating-point values. |
| 549 | optional float zero_float = 7 [default = 0]; |
| 550 | optional float one_float = 8 [default = 1]; |
| 551 | optional float small_float = 9 [default = 1.5]; |
| 552 | optional float negative_one_float = 10 [default = -1]; |
| 553 | optional float negative_float = 11 [default = -1.5]; |
| 554 | // Using exponents |
| 555 | optional float large_float = 12 [default = 2E8]; |
| 556 | optional float small_negative_float = 13 [default = -8e-28]; |
| 557 | |
| 558 | // Text for nonfinite floating-point values. |
| 559 | optional double inf_double = 14 [default = inf]; |
| 560 | optional double neg_inf_double = 15 [default = -inf]; |
| 561 | optional double nan_double = 16 [default = nan]; |
| 562 | optional float inf_float = 17 [default = inf]; |
| 563 | optional float neg_inf_float = 18 [default = -inf]; |
| 564 | optional float nan_float = 19 [default = nan]; |
| 565 | |
| 566 | // Tests for C++ trigraphs. |
| 567 | // Trigraphs should be escaped in C++ generated files, but they should not be |
| 568 | // escaped for other languages. |
| 569 | // Note that in .proto file, "\?" is a valid way to escape ? in string |
| 570 | // literals. |
| 571 | optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"]; |
| 572 | |
| 573 | // String defaults containing the character '\000' |
| 574 | optional string string_with_zero = 23 [default = "hel\000lo"]; |
| 575 | optional bytes bytes_with_zero = 24 [default = "wor\000ld"]; |
| 576 | optional string string_piece_with_zero = 25 [ctype=STRING_PIECE, |
| 577 | default="ab\000c"]; |
| 578 | optional string cord_with_zero = 26 [ctype=CORD, |
| 579 | default="12\0003"]; |
| 580 | optional string replacement_string = 27 [default="${unknown}"]; |
| 581 | } |
| 582 | |
| 583 | message SparseEnumMessage { |
| 584 | optional TestSparseEnum sparse_enum = 1; |
| 585 | } |
| 586 | |
| 587 | // Test String and Bytes: string is for valid UTF-8 strings |
| 588 | message OneString { |
| 589 | optional string data = 1; |
| 590 | } |
| 591 | |
| 592 | message MoreString { |
| 593 | repeated string data = 1; |
| 594 | } |
| 595 | |
| 596 | message OneBytes { |
| 597 | optional bytes data = 1; |
| 598 | } |
| 599 | |
| 600 | message MoreBytes { |
| 601 | repeated bytes data = 1; |
| 602 | } |
| 603 | |
| 604 | // Test int32, uint32, int64, uint64, and bool are all compatible |
| 605 | message Int32Message { |
| 606 | optional int32 data = 1; |
| 607 | } |
| 608 | |
| 609 | message Uint32Message { |
| 610 | optional uint32 data = 1; |
| 611 | } |
| 612 | |
| 613 | message Int64Message { |
| 614 | optional int64 data = 1; |
| 615 | } |
| 616 | |
| 617 | message Uint64Message { |
| 618 | optional uint64 data = 1; |
| 619 | } |
| 620 | |
| 621 | message BoolMessage { |
| 622 | optional bool data = 1; |
| 623 | } |
| 624 | |
| 625 | // Test oneofs. |
| 626 | message TestOneof { |
| 627 | oneof foo { |
| 628 | int32 foo_int = 1; |
| 629 | string foo_string = 2; |
| 630 | TestAllTypes foo_message = 3; |
| 631 | group FooGroup = 4 { |
| 632 | optional int32 a = 5; |
| 633 | optional string b = 6; |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | message TestOneofBackwardsCompatible { |
| 639 | optional int32 foo_int = 1; |
| 640 | optional string foo_string = 2; |
| 641 | optional TestAllTypes foo_message = 3; |
| 642 | optional group FooGroup = 4 { |
| 643 | optional int32 a = 5; |
| 644 | optional string b = 6; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | message TestOneof2 { |
| 649 | oneof foo { |
| 650 | int32 foo_int = 1; |
| 651 | string foo_string = 2; |
| 652 | string foo_cord = 3 [ctype=CORD]; |
| 653 | string foo_string_piece = 4 [ctype=STRING_PIECE]; |
| 654 | bytes foo_bytes = 5; |
| 655 | NestedEnum foo_enum = 6; |
| 656 | NestedMessage foo_message = 7; |
| 657 | group FooGroup = 8 { |
| 658 | optional int32 a = 9; |
| 659 | optional string b = 10; |
| 660 | } |
| 661 | NestedMessage foo_lazy_message = 11 [lazy=true]; |
| 662 | } |
| 663 | |
| 664 | oneof bar { |
| 665 | int32 bar_int = 12 [default = 5]; |
| 666 | string bar_string = 13 [default = "STRING"]; |
| 667 | string bar_cord = 14 [ctype=CORD, default = "CORD"]; |
| 668 | string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"]; |
| 669 | bytes bar_bytes = 16 [default = "BYTES"]; |
| 670 | NestedEnum bar_enum = 17 [default = BAR]; |
| 671 | } |
| 672 | |
| 673 | optional int32 baz_int = 18; |
| 674 | optional string baz_string = 19 [default = "BAZ"]; |
| 675 | |
| 676 | message NestedMessage { |
| 677 | optional int64 qux_int = 1; |
| 678 | repeated int32 corge_int = 2; |
| 679 | } |
| 680 | |
| 681 | enum NestedEnum { |
| 682 | FOO = 1; |
| 683 | BAR = 2; |
| 684 | BAZ = 3; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | message TestRequiredOneof { |
| 689 | oneof foo { |
| 690 | int32 foo_int = 1; |
| 691 | string foo_string = 2; |
| 692 | NestedMessage foo_message = 3; |
| 693 | } |
| 694 | message NestedMessage { |
| 695 | required double required_double = 1; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | // Test messages for packed fields |
| 700 | |
| 701 | message TestPackedTypes { |
| 702 | repeated int32 packed_int32 = 90 [packed = true]; |
| 703 | repeated int64 packed_int64 = 91 [packed = true]; |
| 704 | repeated uint32 packed_uint32 = 92 [packed = true]; |
| 705 | repeated uint64 packed_uint64 = 93 [packed = true]; |
| 706 | repeated sint32 packed_sint32 = 94 [packed = true]; |
| 707 | repeated sint64 packed_sint64 = 95 [packed = true]; |
| 708 | repeated fixed32 packed_fixed32 = 96 [packed = true]; |
| 709 | repeated fixed64 packed_fixed64 = 97 [packed = true]; |
| 710 | repeated sfixed32 packed_sfixed32 = 98 [packed = true]; |
| 711 | repeated sfixed64 packed_sfixed64 = 99 [packed = true]; |
| 712 | repeated float packed_float = 100 [packed = true]; |
| 713 | repeated double packed_double = 101 [packed = true]; |
| 714 | repeated bool packed_bool = 102 [packed = true]; |
| 715 | repeated ForeignEnum packed_enum = 103 [packed = true]; |
| 716 | } |
| 717 | |
| 718 | // A message with the same fields as TestPackedTypes, but without packing. Used |
| 719 | // to test packed <-> unpacked wire compatibility. |
| 720 | message TestUnpackedTypes { |
| 721 | repeated int32 unpacked_int32 = 90 [packed = false]; |
| 722 | repeated int64 unpacked_int64 = 91 [packed = false]; |
| 723 | repeated uint32 unpacked_uint32 = 92 [packed = false]; |
| 724 | repeated uint64 unpacked_uint64 = 93 [packed = false]; |
| 725 | repeated sint32 unpacked_sint32 = 94 [packed = false]; |
| 726 | repeated sint64 unpacked_sint64 = 95 [packed = false]; |
| 727 | repeated fixed32 unpacked_fixed32 = 96 [packed = false]; |
| 728 | repeated fixed64 unpacked_fixed64 = 97 [packed = false]; |
| 729 | repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; |
| 730 | repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; |
| 731 | repeated float unpacked_float = 100 [packed = false]; |
| 732 | repeated double unpacked_double = 101 [packed = false]; |
| 733 | repeated bool unpacked_bool = 102 [packed = false]; |
| 734 | repeated ForeignEnum unpacked_enum = 103 [packed = false]; |
| 735 | } |
| 736 | |
| 737 | message TestPackedExtensions { |
| 738 | extensions 1 to max; |
| 739 | } |
| 740 | |
| 741 | extend TestPackedExtensions { |
| 742 | repeated int32 packed_int32_extension = 90 [packed = true]; |
| 743 | repeated int64 packed_int64_extension = 91 [packed = true]; |
| 744 | repeated uint32 packed_uint32_extension = 92 [packed = true]; |
| 745 | repeated uint64 packed_uint64_extension = 93 [packed = true]; |
| 746 | repeated sint32 packed_sint32_extension = 94 [packed = true]; |
| 747 | repeated sint64 packed_sint64_extension = 95 [packed = true]; |
| 748 | repeated fixed32 packed_fixed32_extension = 96 [packed = true]; |
| 749 | repeated fixed64 packed_fixed64_extension = 97 [packed = true]; |
| 750 | repeated sfixed32 packed_sfixed32_extension = 98 [packed = true]; |
| 751 | repeated sfixed64 packed_sfixed64_extension = 99 [packed = true]; |
| 752 | repeated float packed_float_extension = 100 [packed = true]; |
| 753 | repeated double packed_double_extension = 101 [packed = true]; |
| 754 | repeated bool packed_bool_extension = 102 [packed = true]; |
| 755 | repeated ForeignEnum packed_enum_extension = 103 [packed = true]; |
| 756 | } |
| 757 | |
| 758 | message TestUnpackedExtensions { |
| 759 | extensions 1 to max; |
| 760 | } |
| 761 | |
| 762 | extend TestUnpackedExtensions { |
| 763 | repeated int32 unpacked_int32_extension = 90 [packed = false]; |
| 764 | repeated int64 unpacked_int64_extension = 91 [packed = false]; |
| 765 | repeated uint32 unpacked_uint32_extension = 92 [packed = false]; |
| 766 | repeated uint64 unpacked_uint64_extension = 93 [packed = false]; |
| 767 | repeated sint32 unpacked_sint32_extension = 94 [packed = false]; |
| 768 | repeated sint64 unpacked_sint64_extension = 95 [packed = false]; |
| 769 | repeated fixed32 unpacked_fixed32_extension = 96 [packed = false]; |
| 770 | repeated fixed64 unpacked_fixed64_extension = 97 [packed = false]; |
| 771 | repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false]; |
| 772 | repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false]; |
| 773 | repeated float unpacked_float_extension = 100 [packed = false]; |
| 774 | repeated double unpacked_double_extension = 101 [packed = false]; |
| 775 | repeated bool unpacked_bool_extension = 102 [packed = false]; |
| 776 | repeated ForeignEnum unpacked_enum_extension = 103 [packed = false]; |
| 777 | } |
| 778 | |
| 779 | // Used by ExtensionSetTest/DynamicExtensions. The test actually builds |
| 780 | // a set of extensions to TestAllExtensions dynamically, based on the fields |
| 781 | // of this message type. |
| 782 | message TestDynamicExtensions { |
| 783 | enum DynamicEnumType { |
| 784 | DYNAMIC_FOO = 2200; |
| 785 | DYNAMIC_BAR = 2201; |
| 786 | DYNAMIC_BAZ = 2202; |
| 787 | } |
| 788 | message DynamicMessageType { |
| 789 | optional int32 dynamic_field = 2100; |
| 790 | } |
| 791 | |
| 792 | optional fixed32 scalar_extension = 2000; |
| 793 | optional ForeignEnum enum_extension = 2001; |
| 794 | optional DynamicEnumType dynamic_enum_extension = 2002; |
| 795 | |
| 796 | optional ForeignMessage message_extension = 2003; |
| 797 | optional DynamicMessageType dynamic_message_extension = 2004; |
| 798 | |
| 799 | repeated string repeated_extension = 2005; |
| 800 | repeated sint32 packed_extension = 2006 [packed = true]; |
| 801 | } |
| 802 | |
| 803 | message TestRepeatedScalarDifferentTagSizes { |
| 804 | // Parsing repeated fixed size values used to fail. This message needs to be |
| 805 | // used in order to get a tag of the right size; all of the repeated fields |
| 806 | // in TestAllTypes didn't trigger the check. |
| 807 | repeated fixed32 repeated_fixed32 = 12; |
| 808 | // Check for a varint type, just for good measure. |
| 809 | repeated int32 repeated_int32 = 13; |
| 810 | |
| 811 | // These have two-byte tags. |
| 812 | repeated fixed64 repeated_fixed64 = 2046; |
| 813 | repeated int64 repeated_int64 = 2047; |
| 814 | |
| 815 | // Three byte tags. |
| 816 | repeated float repeated_float = 262142; |
| 817 | repeated uint64 repeated_uint64 = 262143; |
| 818 | } |
| 819 | |
| 820 | // Test that if an optional or required message/group field appears multiple |
| 821 | // times in the input, they need to be merged. |
| 822 | message TestParsingMerge { |
| 823 | // RepeatedFieldsGenerator defines matching field types as TestParsingMerge, |
| 824 | // except that all fields are repeated. In the tests, we will serialize the |
| 825 | // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge. |
| 826 | // Repeated fields in RepeatedFieldsGenerator are expected to be merged into |
| 827 | // the corresponding required/optional fields in TestParsingMerge. |
| 828 | message RepeatedFieldsGenerator { |
| 829 | repeated TestAllTypes field1 = 1; |
| 830 | repeated TestAllTypes field2 = 2; |
| 831 | repeated TestAllTypes field3 = 3; |
| 832 | repeated group Group1 = 10 { |
| 833 | optional TestAllTypes field1 = 11; |
| 834 | } |
| 835 | repeated group Group2 = 20 { |
| 836 | optional TestAllTypes field1 = 21; |
| 837 | } |
| 838 | repeated TestAllTypes ext1 = 1000; |
| 839 | repeated TestAllTypes ext2 = 1001; |
| 840 | } |
| 841 | required TestAllTypes required_all_types = 1; |
| 842 | optional TestAllTypes optional_all_types = 2; |
| 843 | repeated TestAllTypes repeated_all_types = 3; |
| 844 | optional group OptionalGroup = 10 { |
| 845 | optional TestAllTypes optional_group_all_types = 11; |
| 846 | } |
| 847 | repeated group RepeatedGroup = 20 { |
| 848 | optional TestAllTypes repeated_group_all_types = 21; |
| 849 | } |
| 850 | extensions 1000 to max; |
| 851 | extend TestParsingMerge { |
| 852 | optional TestAllTypes optional_ext = 1000; |
| 853 | repeated TestAllTypes repeated_ext = 1001; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | message TestCommentInjectionMessage { |
| 858 | // */ <- This should not close the generated doc comment |
| 859 | optional string a = 1 [default="*/ <- Neither should this."]; |
| 860 | } |
| 861 | |
| 862 | |
| 863 | // Test that RPC services work. |
| 864 | message FooRequest {} |
| 865 | message FooResponse {} |
| 866 | |
| 867 | message FooClientMessage {} |
| 868 | message FooServerMessage{} |
| 869 | |
| 870 | service TestService { |
| 871 | rpc Foo(FooRequest) returns (FooResponse); |
| 872 | rpc Bar(BarRequest) returns (BarResponse); |
| 873 | } |
| 874 | |
| 875 | |
| 876 | message BarRequest {} |
| 877 | message BarResponse {} |
| 878 | |