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