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