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 recursively 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 367message TestChildExtension { 368 optional string a = 1; 369 optional string b = 2; 370 optional TestAllExtensions optional_extension = 3; 371} 372 373// We have separate messages for testing required fields because it's 374// annoying to have to fill in required fields in TestProto in order to 375// do anything with it. Note that we don't need to test every type of 376// required filed because the code output is basically identical to 377// optional fields for all types. 378message TestRequired { 379 required int32 a = 1; 380 optional int32 dummy2 = 2; 381 required int32 b = 3; 382 383 extend TestAllExtensions { 384 optional TestRequired single = 1000; 385 repeated TestRequired multi = 1001; 386 } 387 388 // Pad the field count to 32 so that we can test that IsInitialized() 389 // properly checks multiple elements of has_bits_. 390 optional int32 dummy4 = 4; 391 optional int32 dummy5 = 5; 392 optional int32 dummy6 = 6; 393 optional int32 dummy7 = 7; 394 optional int32 dummy8 = 8; 395 optional int32 dummy9 = 9; 396 optional int32 dummy10 = 10; 397 optional int32 dummy11 = 11; 398 optional int32 dummy12 = 12; 399 optional int32 dummy13 = 13; 400 optional int32 dummy14 = 14; 401 optional int32 dummy15 = 15; 402 optional int32 dummy16 = 16; 403 optional int32 dummy17 = 17; 404 optional int32 dummy18 = 18; 405 optional int32 dummy19 = 19; 406 optional int32 dummy20 = 20; 407 optional int32 dummy21 = 21; 408 optional int32 dummy22 = 22; 409 optional int32 dummy23 = 23; 410 optional int32 dummy24 = 24; 411 optional int32 dummy25 = 25; 412 optional int32 dummy26 = 26; 413 optional int32 dummy27 = 27; 414 optional int32 dummy28 = 28; 415 optional int32 dummy29 = 29; 416 optional int32 dummy30 = 30; 417 optional int32 dummy31 = 31; 418 optional int32 dummy32 = 32; 419 420 required int32 c = 33; 421} 422 423message TestRequiredForeign { 424 optional TestRequired optional_message = 1; 425 repeated TestRequired repeated_message = 2; 426 optional int32 dummy = 3; 427} 428 429message TestRequiredMessage { 430 optional TestRequired optional_message = 1; 431 repeated TestRequired repeated_message = 2; 432 required TestRequired required_message = 3; 433} 434 435// Test that we can use NestedMessage from outside TestAllTypes. 436message TestForeignNested { 437 optional TestAllTypes.NestedMessage foreign_nested = 1; 438} 439 440// TestEmptyMessage is used to test unknown field support. 441message TestEmptyMessage { 442} 443 444// Like above, but declare all field numbers as potential extensions. No 445// actual extensions should ever be defined for this type. 446message TestEmptyMessageWithExtensions { 447 extensions 1 to max; 448} 449 450// Needed for a Python test. 451message TestPickleNestedMessage { 452 message NestedMessage { 453 optional int32 bb = 1; 454 message NestedNestedMessage { 455 optional int32 cc = 1; 456 } 457 } 458} 459 460message TestMultipleExtensionRanges { 461 extensions 42; 462 extensions 4143 to 4243; 463 extensions 65536 to max; 464} 465 466// Test that really large tag numbers don't break anything. 467message TestReallyLargeTagNumber { 468 // The largest possible tag number is 2^28 - 1, since the wire format uses 469 // three bits to communicate wire type. 470 optional int32 a = 1; 471 optional int32 bb = 268435455; 472} 473 474message TestRecursiveMessage { 475 optional TestRecursiveMessage a = 1; 476 optional int32 i = 2; 477} 478 479// Test that mutual recursion works. 480message TestMutualRecursionA { 481 message SubMessage { 482 optional TestMutualRecursionB b = 1; 483 } 484 optional TestMutualRecursionB bb = 1; 485 optional group SubGroup = 2 { 486 optional SubMessage sub_message = 3; // Needed because of bug in javatest 487 optional TestAllTypes not_in_this_scc = 4; 488 } 489} 490 491message TestMutualRecursionB { 492 optional TestMutualRecursionA a = 1; 493 optional int32 optional_int32 = 2; 494} 495 496message TestIsInitialized { 497 message SubMessage { 498 optional group SubGroup = 1 { 499 required int32 i = 2; 500 } 501 } 502 optional SubMessage sub_message = 1; 503} 504 505// Test that groups have disjoint field numbers from their siblings and 506// parents. This is NOT possible in proto1; only google.protobuf. When attempting 507// to compile with proto1, this will emit an error; so we only include it 508// in protobuf_unittest_proto. 509message TestDupFieldNumber { // NO_PROTO1 510 optional int32 a = 1; // NO_PROTO1 511 optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 512 optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 513} // NO_PROTO1 514 515// Additional messages for testing lazy fields. 516message TestEagerMessage { 517 optional TestAllTypes sub_message = 1 [lazy=false]; 518} 519message TestLazyMessage { 520 optional TestAllTypes sub_message = 1 [lazy=true]; 521} 522 523// Needed for a Python test. 524message TestNestedMessageHasBits { 525 message NestedMessage { 526 repeated int32 nestedmessage_repeated_int32 = 1; 527 repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2; 528 } 529 optional NestedMessage optional_nested_message = 1; 530} 531 532 533// Test an enum that has multiple values with the same number. 534enum TestEnumWithDupValue { 535 option allow_alias = true; 536 537 FOO1 = 1; 538 BAR1 = 2; 539 BAZ = 3; 540 FOO2 = 1; 541 BAR2 = 2; 542} 543 544// Test an enum with large, unordered values. 545enum TestSparseEnum { 546 SPARSE_A = 123; 547 SPARSE_B = 62374; 548 SPARSE_C = 12589234; 549 SPARSE_D = -15; 550 SPARSE_E = -53452; 551 SPARSE_F = 0; 552 SPARSE_G = 2; 553} 554 555// Test message with CamelCase field names. This violates Protocol Buffer 556// standard style. 557message TestCamelCaseFieldNames { 558 optional int32 PrimitiveField = 1; 559 optional string StringField = 2; 560 optional ForeignEnum EnumField = 3; 561 optional ForeignMessage MessageField = 4; 562 optional string StringPieceField = 5 [ctype=STRING_PIECE]; 563 optional string CordField = 6 [ctype=CORD]; 564 565 repeated int32 RepeatedPrimitiveField = 7; 566 repeated string RepeatedStringField = 8; 567 repeated ForeignEnum RepeatedEnumField = 9; 568 repeated ForeignMessage RepeatedMessageField = 10; 569 repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE]; 570 repeated string RepeatedCordField = 12 [ctype=CORD]; 571} 572 573 574// We list fields out of order, to ensure that we're using field number and not 575// field index to determine serialization order. 576message TestFieldOrderings { 577 optional string my_string = 11; 578 extensions 2 to 10; 579 optional int64 my_int = 1; 580 extensions 12 to 100; 581 optional float my_float = 101; 582 message NestedMessage { 583 optional int64 oo = 2; 584 // The field name "b" fails to compile in proto1 because it conflicts with 585 // a local variable named "b" in one of the generated methods. Doh. 586 // This file needs to compile in proto1 to test backwards-compatibility. 587 optional int32 bb = 1; 588 } 589 590 optional NestedMessage optional_nested_message = 200; 591} 592 593extend TestFieldOrderings { 594 optional string my_extension_string = 50; 595 optional int32 my_extension_int = 5; 596} 597 598message TestExtensionOrderings1 { 599 extend TestFieldOrderings { 600 optional TestExtensionOrderings1 test_ext_orderings1 = 13; 601 } 602 optional string my_string = 1; 603} 604 605message TestExtensionOrderings2 { 606 extend TestFieldOrderings { 607 optional TestExtensionOrderings2 test_ext_orderings2 = 12; 608 } 609 message TestExtensionOrderings3 { 610 extend TestFieldOrderings { 611 optional TestExtensionOrderings3 test_ext_orderings3 = 14; 612 } 613 optional string my_string = 1; 614 } 615 optional string my_string = 1; 616} 617 618message TestExtremeDefaultValues { 619 optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; 620 optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF]; 621 optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF]; 622 optional int32 small_int32 = 4 [default = -0x7FFFFFFF]; 623 optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF]; 624 optional int32 really_small_int32 = 21 [default = -0x80000000]; 625 optional int64 really_small_int64 = 22 [default = -0x8000000000000000]; 626 627 // The default value here is UTF-8 for "\u1234". (We could also just type 628 // the UTF-8 text directly into this text file rather than escape it, but 629 // lots of people use editors that would be confused by this.) 630 optional string utf8_string = 6 [default = "\341\210\264"]; 631 632 // Tests for single-precision floating-point values. 633 optional float zero_float = 7 [default = 0]; 634 optional float one_float = 8 [default = 1]; 635 optional float small_float = 9 [default = 1.5]; 636 optional float negative_one_float = 10 [default = -1]; 637 optional float negative_float = 11 [default = -1.5]; 638 // Using exponents 639 optional float large_float = 12 [default = 2E8]; 640 optional float small_negative_float = 13 [default = -8e-28]; 641 642 // Text for nonfinite floating-point values. 643 optional double inf_double = 14 [default = inf]; 644 optional double neg_inf_double = 15 [default = -inf]; 645 optional double nan_double = 16 [default = nan]; 646 optional float inf_float = 17 [default = inf]; 647 optional float neg_inf_float = 18 [default = -inf]; 648 optional float nan_float = 19 [default = nan]; 649 650 // Tests for C++ trigraphs. 651 // Trigraphs should be escaped in C++ generated files, but they should not be 652 // escaped for other languages. 653 // Note that in .proto file, "\?" is a valid way to escape ? in string 654 // literals. 655 optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"]; 656 657 // String defaults containing the character '\000' 658 optional string string_with_zero = 23 [default = "hel\000lo"]; 659 optional bytes bytes_with_zero = 24 [default = "wor\000ld"]; 660 optional string string_piece_with_zero = 25 [ctype=STRING_PIECE, 661 default="ab\000c"]; 662 optional string cord_with_zero = 26 [ctype=CORD, 663 default="12\0003"]; 664 optional string replacement_string = 27 [default="${unknown}"]; 665} 666 667message SparseEnumMessage { 668 optional TestSparseEnum sparse_enum = 1; 669} 670 671// Test String and Bytes: string is for valid UTF-8 strings 672message OneString { 673 optional string data = 1; 674} 675 676message MoreString { 677 repeated string data = 1; 678} 679 680message OneBytes { 681 optional bytes data = 1; 682} 683 684message MoreBytes { 685 repeated bytes data = 1; 686} 687 688// Test int32, uint32, int64, uint64, and bool are all compatible 689message Int32Message { 690 optional int32 data = 1; 691} 692 693message Uint32Message { 694 optional uint32 data = 1; 695} 696 697message Int64Message { 698 optional int64 data = 1; 699} 700 701message Uint64Message { 702 optional uint64 data = 1; 703} 704 705message BoolMessage { 706 optional bool data = 1; 707} 708 709// Test oneofs. 710message TestOneof { 711 oneof foo { 712 int32 foo_int = 1; 713 string foo_string = 2; 714 TestAllTypes foo_message = 3; 715 group FooGroup = 4 { 716 optional int32 a = 5; 717 optional string b = 6; 718 } 719 } 720} 721 722message TestOneofBackwardsCompatible { 723 optional int32 foo_int = 1; 724 optional string foo_string = 2; 725 optional TestAllTypes foo_message = 3; 726 optional group FooGroup = 4 { 727 optional int32 a = 5; 728 optional string b = 6; 729 } 730} 731 732message TestOneof2 { 733 oneof foo { 734 int32 foo_int = 1; 735 string foo_string = 2; 736 string foo_cord = 3 [ctype=CORD]; 737 string foo_string_piece = 4 [ctype=STRING_PIECE]; 738 bytes foo_bytes = 5; 739 NestedEnum foo_enum = 6; 740 NestedMessage foo_message = 7; 741 group FooGroup = 8 { 742 optional int32 a = 9; 743 optional string b = 10; 744 } 745 NestedMessage foo_lazy_message = 11 [lazy=true]; 746 } 747 748 oneof bar { 749 int32 bar_int = 12 [default = 5]; 750 string bar_string = 13 [default = "STRING"]; 751 string bar_cord = 14 [ctype=CORD, default = "CORD"]; 752 string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"]; 753 bytes bar_bytes = 16 [default = "BYTES"]; 754 NestedEnum bar_enum = 17 [default = BAR]; 755 string bar_string_with_empty_default = 20 [default = ""]; 756 string bar_cord_with_empty_default = 21 [ctype=CORD, default = ""]; 757 string bar_string_piece_with_empty_default = 22 [ctype=STRING_PIECE, default = ""]; 758 bytes bar_bytes_with_empty_default = 23 [default = ""]; 759 } 760 761 optional int32 baz_int = 18; 762 optional string baz_string = 19 [default = "BAZ"]; 763 764 message NestedMessage { 765 optional int64 qux_int = 1; 766 repeated int32 corge_int = 2; 767 } 768 769 enum NestedEnum { 770 FOO = 1; 771 BAR = 2; 772 BAZ = 3; 773 } 774} 775 776message TestRequiredOneof { 777 oneof foo { 778 int32 foo_int = 1; 779 string foo_string = 2; 780 NestedMessage foo_message = 3; 781 } 782 message NestedMessage { 783 required double required_double = 1; 784 } 785} 786 787 788// Test messages for packed fields 789 790message TestPackedTypes { 791 repeated int32 packed_int32 = 90 [packed = true]; 792 repeated int64 packed_int64 = 91 [packed = true]; 793 repeated uint32 packed_uint32 = 92 [packed = true]; 794 repeated uint64 packed_uint64 = 93 [packed = true]; 795 repeated sint32 packed_sint32 = 94 [packed = true]; 796 repeated sint64 packed_sint64 = 95 [packed = true]; 797 repeated fixed32 packed_fixed32 = 96 [packed = true]; 798 repeated fixed64 packed_fixed64 = 97 [packed = true]; 799 repeated sfixed32 packed_sfixed32 = 98 [packed = true]; 800 repeated sfixed64 packed_sfixed64 = 99 [packed = true]; 801 repeated float packed_float = 100 [packed = true]; 802 repeated double packed_double = 101 [packed = true]; 803 repeated bool packed_bool = 102 [packed = true]; 804 repeated ForeignEnum packed_enum = 103 [packed = true]; 805} 806 807// A message with the same fields as TestPackedTypes, but without packing. Used 808// to test packed <-> unpacked wire compatibility. 809message TestUnpackedTypes { 810 repeated int32 unpacked_int32 = 90 [packed = false]; 811 repeated int64 unpacked_int64 = 91 [packed = false]; 812 repeated uint32 unpacked_uint32 = 92 [packed = false]; 813 repeated uint64 unpacked_uint64 = 93 [packed = false]; 814 repeated sint32 unpacked_sint32 = 94 [packed = false]; 815 repeated sint64 unpacked_sint64 = 95 [packed = false]; 816 repeated fixed32 unpacked_fixed32 = 96 [packed = false]; 817 repeated fixed64 unpacked_fixed64 = 97 [packed = false]; 818 repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; 819 repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; 820 repeated float unpacked_float = 100 [packed = false]; 821 repeated double unpacked_double = 101 [packed = false]; 822 repeated bool unpacked_bool = 102 [packed = false]; 823 repeated ForeignEnum unpacked_enum = 103 [packed = false]; 824} 825 826message TestPackedExtensions { 827 extensions 1 to max; 828} 829 830extend TestPackedExtensions { 831 repeated int32 packed_int32_extension = 90 [packed = true]; 832 repeated int64 packed_int64_extension = 91 [packed = true]; 833 repeated uint32 packed_uint32_extension = 92 [packed = true]; 834 repeated uint64 packed_uint64_extension = 93 [packed = true]; 835 repeated sint32 packed_sint32_extension = 94 [packed = true]; 836 repeated sint64 packed_sint64_extension = 95 [packed = true]; 837 repeated fixed32 packed_fixed32_extension = 96 [packed = true]; 838 repeated fixed64 packed_fixed64_extension = 97 [packed = true]; 839 repeated sfixed32 packed_sfixed32_extension = 98 [packed = true]; 840 repeated sfixed64 packed_sfixed64_extension = 99 [packed = true]; 841 repeated float packed_float_extension = 100 [packed = true]; 842 repeated double packed_double_extension = 101 [packed = true]; 843 repeated bool packed_bool_extension = 102 [packed = true]; 844 repeated ForeignEnum packed_enum_extension = 103 [packed = true]; 845} 846 847message TestUnpackedExtensions { 848 extensions 1 to max; 849} 850 851extend TestUnpackedExtensions { 852 repeated int32 unpacked_int32_extension = 90 [packed = false]; 853 repeated int64 unpacked_int64_extension = 91 [packed = false]; 854 repeated uint32 unpacked_uint32_extension = 92 [packed = false]; 855 repeated uint64 unpacked_uint64_extension = 93 [packed = false]; 856 repeated sint32 unpacked_sint32_extension = 94 [packed = false]; 857 repeated sint64 unpacked_sint64_extension = 95 [packed = false]; 858 repeated fixed32 unpacked_fixed32_extension = 96 [packed = false]; 859 repeated fixed64 unpacked_fixed64_extension = 97 [packed = false]; 860 repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false]; 861 repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false]; 862 repeated float unpacked_float_extension = 100 [packed = false]; 863 repeated double unpacked_double_extension = 101 [packed = false]; 864 repeated bool unpacked_bool_extension = 102 [packed = false]; 865 repeated ForeignEnum unpacked_enum_extension = 103 [packed = false]; 866} 867 868// Used by ExtensionSetTest/DynamicExtensions. The test actually builds 869// a set of extensions to TestAllExtensions dynamically, based on the fields 870// of this message type. 871message TestDynamicExtensions { 872 enum DynamicEnumType { 873 DYNAMIC_FOO = 2200; 874 DYNAMIC_BAR = 2201; 875 DYNAMIC_BAZ = 2202; 876 } 877 message DynamicMessageType { 878 optional int32 dynamic_field = 2100; 879 } 880 881 optional fixed32 scalar_extension = 2000; 882 optional ForeignEnum enum_extension = 2001; 883 optional DynamicEnumType dynamic_enum_extension = 2002; 884 885 optional ForeignMessage message_extension = 2003; 886 optional DynamicMessageType dynamic_message_extension = 2004; 887 888 repeated string repeated_extension = 2005; 889 repeated sint32 packed_extension = 2006 [packed = true]; 890} 891 892message TestRepeatedScalarDifferentTagSizes { 893 // Parsing repeated fixed size values used to fail. This message needs to be 894 // used in order to get a tag of the right size; all of the repeated fields 895 // in TestAllTypes didn't trigger the check. 896 repeated fixed32 repeated_fixed32 = 12; 897 // Check for a varint type, just for good measure. 898 repeated int32 repeated_int32 = 13; 899 900 // These have two-byte tags. 901 repeated fixed64 repeated_fixed64 = 2046; 902 repeated int64 repeated_int64 = 2047; 903 904 // Three byte tags. 905 repeated float repeated_float = 262142; 906 repeated uint64 repeated_uint64 = 262143; 907} 908 909// Test that if an optional or required message/group field appears multiple 910// times in the input, they need to be merged. 911message TestParsingMerge { 912 // RepeatedFieldsGenerator defines matching field types as TestParsingMerge, 913 // except that all fields are repeated. In the tests, we will serialize the 914 // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge. 915 // Repeated fields in RepeatedFieldsGenerator are expected to be merged into 916 // the corresponding required/optional fields in TestParsingMerge. 917 message RepeatedFieldsGenerator { 918 repeated TestAllTypes field1 = 1; 919 repeated TestAllTypes field2 = 2; 920 repeated TestAllTypes field3 = 3; 921 repeated group Group1 = 10 { 922 optional TestAllTypes field1 = 11; 923 } 924 repeated group Group2 = 20 { 925 optional TestAllTypes field1 = 21; 926 } 927 repeated TestAllTypes ext1 = 1000; 928 repeated TestAllTypes ext2 = 1001; 929 } 930 required TestAllTypes required_all_types = 1; 931 optional TestAllTypes optional_all_types = 2; 932 repeated TestAllTypes repeated_all_types = 3; 933 optional group OptionalGroup = 10 { 934 optional TestAllTypes optional_group_all_types = 11; 935 } 936 repeated group RepeatedGroup = 20 { 937 optional TestAllTypes repeated_group_all_types = 21; 938 } 939 extensions 1000 to max; 940 extend TestParsingMerge { 941 optional TestAllTypes optional_ext = 1000; 942 repeated TestAllTypes repeated_ext = 1001; 943 } 944} 945 946message TestCommentInjectionMessage { 947 // */ <- This should not close the generated doc comment 948 optional string a = 1 [default="*/ <- Neither should this."]; 949} 950 951 952// Test that RPC services work. 953message FooRequest {} 954message FooResponse {} 955 956message FooClientMessage {} 957message FooServerMessage{} 958 959service TestService { 960 rpc Foo(FooRequest) returns (FooResponse); 961 rpc Bar(BarRequest) returns (BarResponse); 962} 963 964 965message BarRequest {} 966message BarResponse {} 967 968message TestJsonName { 969 optional int32 field_name1 = 1; 970 optional int32 fieldName2 = 2; 971 optional int32 FieldName3 = 3; 972 optional int32 _field_name4 = 4; 973 optional int32 FIELD_NAME5 = 5; 974 optional int32 field_name6 = 6 [json_name = "@type"]; 975} 976 977message TestHugeFieldNumbers { 978 optional int32 optional_int32 = 536870000; 979 optional int32 fixed_32 = 536870001; 980 repeated int32 repeated_int32 = 536870002 [packed = false]; 981 repeated int32 packed_int32 = 536870003 [packed = true]; 982 983 optional ForeignEnum optional_enum = 536870004; 984 optional string optional_string = 536870005; 985 optional bytes optional_bytes = 536870006; 986 optional ForeignMessage optional_message = 536870007; 987 988 optional group OptionalGroup = 536870008 { 989 optional int32 group_a = 536870009; 990 } 991 992 map<string, string> string_string_map = 536870010; 993 994 oneof oneof_field { 995 uint32 oneof_uint32 = 536870011; 996 TestAllTypes oneof_test_all_types = 536870012; 997 string oneof_string = 536870013; 998 bytes oneof_bytes = 536870014; 999 } 1000 1001 extensions 536860000 to 536869999; 1002} 1003 1004extend TestHugeFieldNumbers { 1005 optional TestAllTypes test_all_types = 536860000; 1006} 1007 1008message TestExtensionInsideTable { 1009 optional int32 field1 = 1; 1010 optional int32 field2 = 2; 1011 optional int32 field3 = 3; 1012 optional int32 field4 = 4; 1013 extensions 5 to 5; 1014 optional int32 field6 = 6; 1015 optional int32 field7 = 7; 1016 optional int32 field8 = 8; 1017 optional int32 field9 = 9; 1018 optional int32 field10 = 10; 1019} 1020 1021extend TestExtensionInsideTable { 1022 optional int32 test_extension_inside_table_extension = 5; 1023} 1024 1025enum VeryLargeEnum { 1026 ENUM_LABEL_DEFAULT = 0; 1027 ENUM_LABEL_1 = 1; 1028 ENUM_LABEL_2 = 2; 1029 ENUM_LABEL_3 = 3; 1030 ENUM_LABEL_4 = 4; 1031 ENUM_LABEL_5 = 5; 1032 ENUM_LABEL_6 = 6; 1033 ENUM_LABEL_7 = 7; 1034 ENUM_LABEL_8 = 8; 1035 ENUM_LABEL_9 = 9; 1036 ENUM_LABEL_10 = 10; 1037 ENUM_LABEL_11 = 11; 1038 ENUM_LABEL_12 = 12; 1039 ENUM_LABEL_13 = 13; 1040 ENUM_LABEL_14 = 14; 1041 ENUM_LABEL_15 = 15; 1042 ENUM_LABEL_16 = 16; 1043 ENUM_LABEL_17 = 17; 1044 ENUM_LABEL_18 = 18; 1045 ENUM_LABEL_19 = 19; 1046 ENUM_LABEL_20 = 20; 1047 ENUM_LABEL_21 = 21; 1048 ENUM_LABEL_22 = 22; 1049 ENUM_LABEL_23 = 23; 1050 ENUM_LABEL_24 = 24; 1051 ENUM_LABEL_25 = 25; 1052 ENUM_LABEL_26 = 26; 1053 ENUM_LABEL_27 = 27; 1054 ENUM_LABEL_28 = 28; 1055 ENUM_LABEL_29 = 29; 1056 ENUM_LABEL_30 = 30; 1057 ENUM_LABEL_31 = 31; 1058 ENUM_LABEL_32 = 32; 1059 ENUM_LABEL_33 = 33; 1060 ENUM_LABEL_34 = 34; 1061 ENUM_LABEL_35 = 35; 1062 ENUM_LABEL_36 = 36; 1063 ENUM_LABEL_37 = 37; 1064 ENUM_LABEL_38 = 38; 1065 ENUM_LABEL_39 = 39; 1066 ENUM_LABEL_40 = 40; 1067 ENUM_LABEL_41 = 41; 1068 ENUM_LABEL_42 = 42; 1069 ENUM_LABEL_43 = 43; 1070 ENUM_LABEL_44 = 44; 1071 ENUM_LABEL_45 = 45; 1072 ENUM_LABEL_46 = 46; 1073 ENUM_LABEL_47 = 47; 1074 ENUM_LABEL_48 = 48; 1075 ENUM_LABEL_49 = 49; 1076 ENUM_LABEL_50 = 50; 1077 ENUM_LABEL_51 = 51; 1078 ENUM_LABEL_52 = 52; 1079 ENUM_LABEL_53 = 53; 1080 ENUM_LABEL_54 = 54; 1081 ENUM_LABEL_55 = 55; 1082 ENUM_LABEL_56 = 56; 1083 ENUM_LABEL_57 = 57; 1084 ENUM_LABEL_58 = 58; 1085 ENUM_LABEL_59 = 59; 1086 ENUM_LABEL_60 = 60; 1087 ENUM_LABEL_61 = 61; 1088 ENUM_LABEL_62 = 62; 1089 ENUM_LABEL_63 = 63; 1090 ENUM_LABEL_64 = 64; 1091 ENUM_LABEL_65 = 65; 1092 ENUM_LABEL_66 = 66; 1093 ENUM_LABEL_67 = 67; 1094 ENUM_LABEL_68 = 68; 1095 ENUM_LABEL_69 = 69; 1096 ENUM_LABEL_70 = 70; 1097 ENUM_LABEL_71 = 71; 1098 ENUM_LABEL_72 = 72; 1099 ENUM_LABEL_73 = 73; 1100 ENUM_LABEL_74 = 74; 1101 ENUM_LABEL_75 = 75; 1102 ENUM_LABEL_76 = 76; 1103 ENUM_LABEL_77 = 77; 1104 ENUM_LABEL_78 = 78; 1105 ENUM_LABEL_79 = 79; 1106 ENUM_LABEL_80 = 80; 1107 ENUM_LABEL_81 = 81; 1108 ENUM_LABEL_82 = 82; 1109 ENUM_LABEL_83 = 83; 1110 ENUM_LABEL_84 = 84; 1111 ENUM_LABEL_85 = 85; 1112 ENUM_LABEL_86 = 86; 1113 ENUM_LABEL_87 = 87; 1114 ENUM_LABEL_88 = 88; 1115 ENUM_LABEL_89 = 89; 1116 ENUM_LABEL_90 = 90; 1117 ENUM_LABEL_91 = 91; 1118 ENUM_LABEL_92 = 92; 1119 ENUM_LABEL_93 = 93; 1120 ENUM_LABEL_94 = 94; 1121 ENUM_LABEL_95 = 95; 1122 ENUM_LABEL_96 = 96; 1123 ENUM_LABEL_97 = 97; 1124 ENUM_LABEL_98 = 98; 1125 ENUM_LABEL_99 = 99; 1126 ENUM_LABEL_100 = 100; 1127}; 1128 1129message TestExtensionRangeSerialize { 1130 optional int32 foo_one = 1; 1131 1132 extensions 2 to 2; 1133 extensions 3 to 4; 1134 1135 optional int32 foo_two = 6; 1136 optional int32 foo_three = 7; 1137 1138 extensions 9 to 10; 1139 1140 optional int32 foo_four = 13; 1141 1142 extensions 15 to 15; 1143 extensions 17 to 17; 1144 extensions 19 to 19; 1145 1146 extend TestExtensionRangeSerialize { 1147 optional int32 bar_one = 2; 1148 optional int32 bar_two = 4; 1149 1150 optional int32 bar_three = 10; 1151 1152 optional int32 bar_four = 15; 1153 optional int32 bar_five = 19; 1154 } 1155} 1156 1157 1158