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