temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 2 | // Copyright 2008 Google Inc. All rights reserved. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 3 | // http://code.google.com/p/protobuf/ |
| 4 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 8 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 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. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 18 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 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. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 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 | |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 38 | // Some generic_services option(s) added automatically. |
| 39 | // See: http://go/proto2-generic-services-default |
| 40 | option cc_generic_services = true; // auto-added |
| 41 | option java_generic_services = true; // auto-added |
| 42 | option py_generic_services = true; // auto-added |
| 43 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 44 | import "google/protobuf/unittest_import.proto"; |
| 45 | |
| 46 | // We don't put this in a package within proto2 because we need to make sure |
| 47 | // that the generated code doesn't depend on being in the proto2 namespace. |
| 48 | // In test_util.h we do "using namespace unittest = protobuf_unittest". |
| 49 | package protobuf_unittest; |
| 50 | |
| 51 | // Protos optimized for SPEED use a strict superset of the generated code |
| 52 | // of equivalent ones optimized for CODE_SIZE, so we should optimize all our |
| 53 | // tests for speed unless explicitly testing code size optimization. |
| 54 | option optimize_for = SPEED; |
| 55 | |
| 56 | option java_outer_classname = "UnittestProto"; |
| 57 | |
| 58 | // This proto includes every type of field in both singular and repeated |
| 59 | // forms. |
| 60 | message TestAllTypes { |
| 61 | message NestedMessage { |
| 62 | // The field name "b" fails to compile in proto1 because it conflicts with |
| 63 | // a local variable named "b" in one of the generated methods. Doh. |
| 64 | // This file needs to compile in proto1 to test backwards-compatibility. |
| 65 | optional int32 bb = 1; |
| 66 | } |
| 67 | |
| 68 | enum NestedEnum { |
| 69 | FOO = 1; |
| 70 | BAR = 2; |
| 71 | BAZ = 3; |
| 72 | } |
| 73 | |
| 74 | // Singular |
| 75 | optional int32 optional_int32 = 1; |
| 76 | optional int64 optional_int64 = 2; |
| 77 | optional uint32 optional_uint32 = 3; |
| 78 | optional uint64 optional_uint64 = 4; |
| 79 | optional sint32 optional_sint32 = 5; |
| 80 | optional sint64 optional_sint64 = 6; |
| 81 | optional fixed32 optional_fixed32 = 7; |
| 82 | optional fixed64 optional_fixed64 = 8; |
| 83 | optional sfixed32 optional_sfixed32 = 9; |
| 84 | optional sfixed64 optional_sfixed64 = 10; |
| 85 | optional float optional_float = 11; |
| 86 | optional double optional_double = 12; |
| 87 | optional bool optional_bool = 13; |
| 88 | optional string optional_string = 14; |
| 89 | optional bytes optional_bytes = 15; |
| 90 | |
| 91 | optional group OptionalGroup = 16 { |
| 92 | optional int32 a = 17; |
| 93 | } |
| 94 | |
| 95 | optional NestedMessage optional_nested_message = 18; |
| 96 | optional ForeignMessage optional_foreign_message = 19; |
| 97 | optional protobuf_unittest_import.ImportMessage optional_import_message = 20; |
| 98 | |
| 99 | optional NestedEnum optional_nested_enum = 21; |
| 100 | optional ForeignEnum optional_foreign_enum = 22; |
| 101 | optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; |
| 102 | |
| 103 | optional string optional_string_piece = 24 [ctype=STRING_PIECE]; |
| 104 | optional string optional_cord = 25 [ctype=CORD]; |
| 105 | |
| 106 | // Repeated |
| 107 | repeated int32 repeated_int32 = 31; |
| 108 | repeated int64 repeated_int64 = 32; |
| 109 | repeated uint32 repeated_uint32 = 33; |
| 110 | repeated uint64 repeated_uint64 = 34; |
| 111 | repeated sint32 repeated_sint32 = 35; |
| 112 | repeated sint64 repeated_sint64 = 36; |
| 113 | repeated fixed32 repeated_fixed32 = 37; |
| 114 | repeated fixed64 repeated_fixed64 = 38; |
| 115 | repeated sfixed32 repeated_sfixed32 = 39; |
| 116 | repeated sfixed64 repeated_sfixed64 = 40; |
| 117 | repeated float repeated_float = 41; |
| 118 | repeated double repeated_double = 42; |
| 119 | repeated bool repeated_bool = 43; |
| 120 | repeated string repeated_string = 44; |
| 121 | repeated bytes repeated_bytes = 45; |
| 122 | |
| 123 | repeated group RepeatedGroup = 46 { |
| 124 | optional int32 a = 47; |
| 125 | } |
| 126 | |
| 127 | repeated NestedMessage repeated_nested_message = 48; |
| 128 | repeated ForeignMessage repeated_foreign_message = 49; |
| 129 | repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; |
| 130 | |
| 131 | repeated NestedEnum repeated_nested_enum = 51; |
| 132 | repeated ForeignEnum repeated_foreign_enum = 52; |
| 133 | repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; |
| 134 | |
| 135 | repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; |
| 136 | repeated string repeated_cord = 55 [ctype=CORD]; |
| 137 | |
| 138 | // Singular with defaults |
| 139 | optional int32 default_int32 = 61 [default = 41 ]; |
| 140 | optional int64 default_int64 = 62 [default = 42 ]; |
| 141 | optional uint32 default_uint32 = 63 [default = 43 ]; |
| 142 | optional uint64 default_uint64 = 64 [default = 44 ]; |
| 143 | optional sint32 default_sint32 = 65 [default = -45 ]; |
| 144 | optional sint64 default_sint64 = 66 [default = 46 ]; |
| 145 | optional fixed32 default_fixed32 = 67 [default = 47 ]; |
| 146 | optional fixed64 default_fixed64 = 68 [default = 48 ]; |
| 147 | optional sfixed32 default_sfixed32 = 69 [default = 49 ]; |
| 148 | optional sfixed64 default_sfixed64 = 70 [default = -50 ]; |
| 149 | optional float default_float = 71 [default = 51.5 ]; |
| 150 | optional double default_double = 72 [default = 52e3 ]; |
| 151 | optional bool default_bool = 73 [default = true ]; |
| 152 | optional string default_string = 74 [default = "hello"]; |
| 153 | optional bytes default_bytes = 75 [default = "world"]; |
| 154 | |
| 155 | optional NestedEnum default_nested_enum = 81 [default = BAR ]; |
| 156 | optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; |
| 157 | optional protobuf_unittest_import.ImportEnum |
| 158 | default_import_enum = 83 [default = IMPORT_BAR]; |
| 159 | |
| 160 | optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; |
| 161 | optional string default_cord = 85 [ctype=CORD,default="123"]; |
| 162 | } |
| 163 | |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 164 | message TestDeprecatedFields { |
| 165 | optional int32 deprecated_int32 = 1 [deprecated=true]; |
| 166 | } |
| 167 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 168 | // Define these after TestAllTypes to make sure the compiler can handle |
| 169 | // that. |
| 170 | message ForeignMessage { |
| 171 | optional int32 c = 1; |
| 172 | } |
| 173 | |
| 174 | enum ForeignEnum { |
| 175 | FOREIGN_FOO = 4; |
| 176 | FOREIGN_BAR = 5; |
| 177 | FOREIGN_BAZ = 6; |
| 178 | } |
| 179 | |
| 180 | message TestAllExtensions { |
| 181 | extensions 1 to max; |
| 182 | } |
| 183 | |
| 184 | extend TestAllExtensions { |
| 185 | // Singular |
| 186 | optional int32 optional_int32_extension = 1; |
| 187 | optional int64 optional_int64_extension = 2; |
| 188 | optional uint32 optional_uint32_extension = 3; |
| 189 | optional uint64 optional_uint64_extension = 4; |
| 190 | optional sint32 optional_sint32_extension = 5; |
| 191 | optional sint64 optional_sint64_extension = 6; |
| 192 | optional fixed32 optional_fixed32_extension = 7; |
| 193 | optional fixed64 optional_fixed64_extension = 8; |
| 194 | optional sfixed32 optional_sfixed32_extension = 9; |
| 195 | optional sfixed64 optional_sfixed64_extension = 10; |
| 196 | optional float optional_float_extension = 11; |
| 197 | optional double optional_double_extension = 12; |
| 198 | optional bool optional_bool_extension = 13; |
| 199 | optional string optional_string_extension = 14; |
| 200 | optional bytes optional_bytes_extension = 15; |
| 201 | |
| 202 | optional group OptionalGroup_extension = 16 { |
| 203 | optional int32 a = 17; |
| 204 | } |
| 205 | |
| 206 | optional TestAllTypes.NestedMessage optional_nested_message_extension = 18; |
| 207 | optional ForeignMessage optional_foreign_message_extension = 19; |
| 208 | optional protobuf_unittest_import.ImportMessage |
| 209 | optional_import_message_extension = 20; |
| 210 | |
| 211 | optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21; |
| 212 | optional ForeignEnum optional_foreign_enum_extension = 22; |
| 213 | optional protobuf_unittest_import.ImportEnum |
| 214 | optional_import_enum_extension = 23; |
| 215 | |
| 216 | optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE]; |
| 217 | optional string optional_cord_extension = 25 [ctype=CORD]; |
| 218 | |
| 219 | // Repeated |
| 220 | repeated int32 repeated_int32_extension = 31; |
| 221 | repeated int64 repeated_int64_extension = 32; |
| 222 | repeated uint32 repeated_uint32_extension = 33; |
| 223 | repeated uint64 repeated_uint64_extension = 34; |
| 224 | repeated sint32 repeated_sint32_extension = 35; |
| 225 | repeated sint64 repeated_sint64_extension = 36; |
| 226 | repeated fixed32 repeated_fixed32_extension = 37; |
| 227 | repeated fixed64 repeated_fixed64_extension = 38; |
| 228 | repeated sfixed32 repeated_sfixed32_extension = 39; |
| 229 | repeated sfixed64 repeated_sfixed64_extension = 40; |
| 230 | repeated float repeated_float_extension = 41; |
| 231 | repeated double repeated_double_extension = 42; |
| 232 | repeated bool repeated_bool_extension = 43; |
| 233 | repeated string repeated_string_extension = 44; |
| 234 | repeated bytes repeated_bytes_extension = 45; |
| 235 | |
| 236 | repeated group RepeatedGroup_extension = 46 { |
| 237 | optional int32 a = 47; |
| 238 | } |
| 239 | |
| 240 | repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48; |
| 241 | repeated ForeignMessage repeated_foreign_message_extension = 49; |
| 242 | repeated protobuf_unittest_import.ImportMessage |
| 243 | repeated_import_message_extension = 50; |
| 244 | |
| 245 | repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51; |
| 246 | repeated ForeignEnum repeated_foreign_enum_extension = 52; |
| 247 | repeated protobuf_unittest_import.ImportEnum |
| 248 | repeated_import_enum_extension = 53; |
| 249 | |
| 250 | repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE]; |
| 251 | repeated string repeated_cord_extension = 55 [ctype=CORD]; |
| 252 | |
| 253 | // Singular with defaults |
| 254 | optional int32 default_int32_extension = 61 [default = 41 ]; |
| 255 | optional int64 default_int64_extension = 62 [default = 42 ]; |
| 256 | optional uint32 default_uint32_extension = 63 [default = 43 ]; |
| 257 | optional uint64 default_uint64_extension = 64 [default = 44 ]; |
| 258 | optional sint32 default_sint32_extension = 65 [default = -45 ]; |
| 259 | optional sint64 default_sint64_extension = 66 [default = 46 ]; |
| 260 | optional fixed32 default_fixed32_extension = 67 [default = 47 ]; |
| 261 | optional fixed64 default_fixed64_extension = 68 [default = 48 ]; |
| 262 | optional sfixed32 default_sfixed32_extension = 69 [default = 49 ]; |
| 263 | optional sfixed64 default_sfixed64_extension = 70 [default = -50 ]; |
| 264 | optional float default_float_extension = 71 [default = 51.5 ]; |
| 265 | optional double default_double_extension = 72 [default = 52e3 ]; |
| 266 | optional bool default_bool_extension = 73 [default = true ]; |
| 267 | optional string default_string_extension = 74 [default = "hello"]; |
| 268 | optional bytes default_bytes_extension = 75 [default = "world"]; |
| 269 | |
| 270 | optional TestAllTypes.NestedEnum |
| 271 | default_nested_enum_extension = 81 [default = BAR]; |
| 272 | optional ForeignEnum |
| 273 | default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; |
| 274 | optional protobuf_unittest_import.ImportEnum |
| 275 | default_import_enum_extension = 83 [default = IMPORT_BAR]; |
| 276 | |
| 277 | optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, |
| 278 | default="abc"]; |
| 279 | optional string default_cord_extension = 85 [ctype=CORD, default="123"]; |
| 280 | } |
| 281 | |
kenton@google.com | d37d46d | 2009-04-25 02:53:47 +0000 | [diff] [blame] | 282 | message TestNestedExtension { |
| 283 | extend TestAllExtensions { |
| 284 | // Check for bug where string extensions declared in tested scope did not |
| 285 | // compile. |
| 286 | optional string test = 1002 [default="test"]; |
| 287 | } |
| 288 | } |
| 289 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 290 | // We have separate messages for testing required fields because it's |
| 291 | // annoying to have to fill in required fields in TestProto in order to |
| 292 | // do anything with it. Note that we don't need to test every type of |
| 293 | // required filed because the code output is basically identical to |
| 294 | // optional fields for all types. |
| 295 | message TestRequired { |
| 296 | required int32 a = 1; |
| 297 | optional int32 dummy2 = 2; |
| 298 | required int32 b = 3; |
| 299 | |
| 300 | extend TestAllExtensions { |
| 301 | optional TestRequired single = 1000; |
| 302 | repeated TestRequired multi = 1001; |
| 303 | } |
| 304 | |
| 305 | // Pad the field count to 32 so that we can test that IsInitialized() |
| 306 | // properly checks multiple elements of has_bits_. |
| 307 | optional int32 dummy4 = 4; |
| 308 | optional int32 dummy5 = 5; |
| 309 | optional int32 dummy6 = 6; |
| 310 | optional int32 dummy7 = 7; |
| 311 | optional int32 dummy8 = 8; |
| 312 | optional int32 dummy9 = 9; |
| 313 | optional int32 dummy10 = 10; |
| 314 | optional int32 dummy11 = 11; |
| 315 | optional int32 dummy12 = 12; |
| 316 | optional int32 dummy13 = 13; |
| 317 | optional int32 dummy14 = 14; |
| 318 | optional int32 dummy15 = 15; |
| 319 | optional int32 dummy16 = 16; |
| 320 | optional int32 dummy17 = 17; |
| 321 | optional int32 dummy18 = 18; |
| 322 | optional int32 dummy19 = 19; |
| 323 | optional int32 dummy20 = 20; |
| 324 | optional int32 dummy21 = 21; |
| 325 | optional int32 dummy22 = 22; |
| 326 | optional int32 dummy23 = 23; |
| 327 | optional int32 dummy24 = 24; |
| 328 | optional int32 dummy25 = 25; |
| 329 | optional int32 dummy26 = 26; |
| 330 | optional int32 dummy27 = 27; |
| 331 | optional int32 dummy28 = 28; |
| 332 | optional int32 dummy29 = 29; |
| 333 | optional int32 dummy30 = 30; |
| 334 | optional int32 dummy31 = 31; |
| 335 | optional int32 dummy32 = 32; |
| 336 | |
| 337 | required int32 c = 33; |
| 338 | } |
| 339 | |
| 340 | message TestRequiredForeign { |
| 341 | optional TestRequired optional_message = 1; |
| 342 | repeated TestRequired repeated_message = 2; |
| 343 | optional int32 dummy = 3; |
| 344 | } |
| 345 | |
| 346 | // Test that we can use NestedMessage from outside TestAllTypes. |
| 347 | message TestForeignNested { |
| 348 | optional TestAllTypes.NestedMessage foreign_nested = 1; |
| 349 | } |
| 350 | |
| 351 | // TestEmptyMessage is used to test unknown field support. |
| 352 | message TestEmptyMessage { |
| 353 | } |
| 354 | |
| 355 | // Like above, but declare all field numbers as potential extensions. No |
| 356 | // actual extensions should ever be defined for this type. |
| 357 | message TestEmptyMessageWithExtensions { |
| 358 | extensions 1 to max; |
| 359 | } |
| 360 | |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 361 | message TestMultipleExtensionRanges { |
| 362 | extensions 42; |
| 363 | extensions 4143 to 4243; |
| 364 | extensions 65536 to max; |
| 365 | } |
| 366 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 367 | // Test that really large tag numbers don't break anything. |
| 368 | message TestReallyLargeTagNumber { |
| 369 | // The largest possible tag number is 2^28 - 1, since the wire format uses |
| 370 | // three bits to communicate wire type. |
| 371 | optional int32 a = 1; |
| 372 | optional int32 bb = 268435455; |
| 373 | } |
| 374 | |
| 375 | message TestRecursiveMessage { |
| 376 | optional TestRecursiveMessage a = 1; |
| 377 | optional int32 i = 2; |
| 378 | } |
| 379 | |
| 380 | // Test that mutual recursion works. |
| 381 | message TestMutualRecursionA { |
| 382 | optional TestMutualRecursionB bb = 1; |
| 383 | } |
| 384 | |
| 385 | message TestMutualRecursionB { |
| 386 | optional TestMutualRecursionA a = 1; |
| 387 | optional int32 optional_int32 = 2; |
| 388 | } |
| 389 | |
| 390 | // Test that groups have disjoint field numbers from their siblings and |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 391 | // parents. This is NOT possible in proto1; only proto2. When attempting |
| 392 | // to compile with proto1, this will emit an error; so we only include it |
| 393 | // in protobuf_unittest_proto. |
| 394 | message TestDupFieldNumber { // NO_PROTO1 |
| 395 | optional int32 a = 1; // NO_PROTO1 |
| 396 | optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 |
| 397 | optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 |
| 398 | } // NO_PROTO1 |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 399 | |
| 400 | |
| 401 | // Needed for a Python test. |
| 402 | message TestNestedMessageHasBits { |
| 403 | message NestedMessage { |
| 404 | repeated int32 nestedmessage_repeated_int32 = 1; |
| 405 | repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2; |
| 406 | } |
| 407 | optional NestedMessage optional_nested_message = 1; |
| 408 | } |
| 409 | |
| 410 | |
| 411 | // Test an enum that has multiple values with the same number. |
| 412 | enum TestEnumWithDupValue { |
| 413 | FOO1 = 1; |
| 414 | BAR1 = 2; |
| 415 | BAZ = 3; |
| 416 | FOO2 = 1; |
| 417 | BAR2 = 2; |
| 418 | } |
| 419 | |
| 420 | // Test an enum with large, unordered values. |
| 421 | enum TestSparseEnum { |
| 422 | SPARSE_A = 123; |
| 423 | SPARSE_B = 62374; |
| 424 | SPARSE_C = 12589234; |
| 425 | SPARSE_D = -15; |
| 426 | SPARSE_E = -53452; |
| 427 | SPARSE_F = 0; |
| 428 | SPARSE_G = 2; |
| 429 | } |
| 430 | |
| 431 | // Test message with CamelCase field names. This violates Protocol Buffer |
| 432 | // standard style. |
| 433 | message TestCamelCaseFieldNames { |
| 434 | optional int32 PrimitiveField = 1; |
| 435 | optional string StringField = 2; |
| 436 | optional ForeignEnum EnumField = 3; |
| 437 | optional ForeignMessage MessageField = 4; |
| 438 | optional string StringPieceField = 5 [ctype=STRING_PIECE]; |
| 439 | optional string CordField = 6 [ctype=CORD]; |
| 440 | |
| 441 | repeated int32 RepeatedPrimitiveField = 7; |
| 442 | repeated string RepeatedStringField = 8; |
| 443 | repeated ForeignEnum RepeatedEnumField = 9; |
| 444 | repeated ForeignMessage RepeatedMessageField = 10; |
| 445 | repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE]; |
| 446 | repeated string RepeatedCordField = 12 [ctype=CORD]; |
| 447 | } |
| 448 | |
| 449 | |
| 450 | // We list fields out of order, to ensure that we're using field number and not |
| 451 | // field index to determine serialization order. |
| 452 | message TestFieldOrderings { |
| 453 | optional string my_string = 11; |
| 454 | extensions 2 to 10; |
| 455 | optional int64 my_int = 1; |
| 456 | extensions 12 to 100; |
| 457 | optional float my_float = 101; |
| 458 | } |
| 459 | |
| 460 | |
| 461 | extend TestFieldOrderings { |
| 462 | optional string my_extension_string = 50; |
| 463 | optional int32 my_extension_int = 5; |
| 464 | } |
| 465 | |
| 466 | |
| 467 | message TestExtremeDefaultValues { |
| 468 | optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; |
| 469 | optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF]; |
| 470 | optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF]; |
| 471 | optional int32 small_int32 = 4 [default = -0x7FFFFFFF]; |
| 472 | optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF]; |
| 473 | |
| 474 | // The default value here is UTF-8 for "\u1234". (We could also just type |
| 475 | // the UTF-8 text directly into this text file rather than escape it, but |
| 476 | // lots of people use editors that would be confused by this.) |
| 477 | optional string utf8_string = 6 [default = "\341\210\264"]; |
kenton@google.com | d2fd063 | 2009-07-24 01:00:35 +0000 | [diff] [blame] | 478 | |
| 479 | // Tests for single-precision floating-point values. |
| 480 | optional float zero_float = 7 [default = 0]; |
| 481 | optional float one_float = 8 [default = 1]; |
| 482 | optional float small_float = 9 [default = 1.5]; |
| 483 | optional float negative_one_float = 10 [default = -1]; |
| 484 | optional float negative_float = 11 [default = -1.5]; |
| 485 | // Using exponents |
| 486 | optional float large_float = 12 [default = 2E8]; |
| 487 | optional float small_negative_float = 13 [default = -8e-28]; |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 488 | |
| 489 | // Text for nonfinite floating-point values. |
| 490 | optional double inf_double = 14 [default = inf]; |
| 491 | optional double neg_inf_double = 15 [default = -inf]; |
| 492 | optional double nan_double = 16 [default = nan]; |
| 493 | optional float inf_float = 17 [default = inf]; |
| 494 | optional float neg_inf_float = 18 [default = -inf]; |
| 495 | optional float nan_float = 19 [default = nan]; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 496 | } |
| 497 | |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 498 | message SparseEnumMessage { |
| 499 | optional TestSparseEnum sparse_enum = 1; |
| 500 | } |
| 501 | |
kenton@google.com | 26bd9ee | 2008-11-21 00:06:27 +0000 | [diff] [blame] | 502 | // Test String and Bytes: string is for valid UTF-8 strings |
| 503 | message OneString { |
| 504 | optional string data = 1; |
| 505 | } |
| 506 | |
| 507 | message OneBytes { |
| 508 | optional bytes data = 1; |
| 509 | } |
| 510 | |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 511 | // Test messages for packed fields |
| 512 | |
| 513 | message TestPackedTypes { |
| 514 | repeated int32 packed_int32 = 90 [packed = true]; |
| 515 | repeated int64 packed_int64 = 91 [packed = true]; |
| 516 | repeated uint32 packed_uint32 = 92 [packed = true]; |
| 517 | repeated uint64 packed_uint64 = 93 [packed = true]; |
| 518 | repeated sint32 packed_sint32 = 94 [packed = true]; |
| 519 | repeated sint64 packed_sint64 = 95 [packed = true]; |
| 520 | repeated fixed32 packed_fixed32 = 96 [packed = true]; |
| 521 | repeated fixed64 packed_fixed64 = 97 [packed = true]; |
| 522 | repeated sfixed32 packed_sfixed32 = 98 [packed = true]; |
| 523 | repeated sfixed64 packed_sfixed64 = 99 [packed = true]; |
| 524 | repeated float packed_float = 100 [packed = true]; |
| 525 | repeated double packed_double = 101 [packed = true]; |
| 526 | repeated bool packed_bool = 102 [packed = true]; |
| 527 | repeated ForeignEnum packed_enum = 103 [packed = true]; |
| 528 | } |
| 529 | |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 530 | // A message with the same fields as TestPackedTypes, but without packing. Used |
| 531 | // to test packed <-> unpacked wire compatibility. |
| 532 | message TestUnpackedTypes { |
| 533 | repeated int32 unpacked_int32 = 90 [packed = false]; |
| 534 | repeated int64 unpacked_int64 = 91 [packed = false]; |
| 535 | repeated uint32 unpacked_uint32 = 92 [packed = false]; |
| 536 | repeated uint64 unpacked_uint64 = 93 [packed = false]; |
| 537 | repeated sint32 unpacked_sint32 = 94 [packed = false]; |
| 538 | repeated sint64 unpacked_sint64 = 95 [packed = false]; |
| 539 | repeated fixed32 unpacked_fixed32 = 96 [packed = false]; |
| 540 | repeated fixed64 unpacked_fixed64 = 97 [packed = false]; |
| 541 | repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; |
| 542 | repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; |
| 543 | repeated float unpacked_float = 100 [packed = false]; |
| 544 | repeated double unpacked_double = 101 [packed = false]; |
| 545 | repeated bool unpacked_bool = 102 [packed = false]; |
| 546 | repeated ForeignEnum unpacked_enum = 103 [packed = false]; |
| 547 | } |
| 548 | |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 549 | message TestPackedExtensions { |
| 550 | extensions 1 to max; |
| 551 | } |
| 552 | |
| 553 | extend TestPackedExtensions { |
| 554 | repeated int32 packed_int32_extension = 90 [packed = true]; |
| 555 | repeated int64 packed_int64_extension = 91 [packed = true]; |
| 556 | repeated uint32 packed_uint32_extension = 92 [packed = true]; |
| 557 | repeated uint64 packed_uint64_extension = 93 [packed = true]; |
| 558 | repeated sint32 packed_sint32_extension = 94 [packed = true]; |
| 559 | repeated sint64 packed_sint64_extension = 95 [packed = true]; |
| 560 | repeated fixed32 packed_fixed32_extension = 96 [packed = true]; |
| 561 | repeated fixed64 packed_fixed64_extension = 97 [packed = true]; |
| 562 | repeated sfixed32 packed_sfixed32_extension = 98 [packed = true]; |
| 563 | repeated sfixed64 packed_sfixed64_extension = 99 [packed = true]; |
| 564 | repeated float packed_float_extension = 100 [packed = true]; |
| 565 | repeated double packed_double_extension = 101 [packed = true]; |
| 566 | repeated bool packed_bool_extension = 102 [packed = true]; |
| 567 | repeated ForeignEnum packed_enum_extension = 103 [packed = true]; |
| 568 | } |
| 569 | |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 570 | // Used by ExtensionSetTest/DynamicExtensions. The test actually builds |
| 571 | // a set of extensions to TestAllExtensions dynamically, based on the fields |
| 572 | // of this message type. |
| 573 | message TestDynamicExtensions { |
| 574 | enum DynamicEnumType { |
| 575 | DYNAMIC_FOO = 2200; |
| 576 | DYNAMIC_BAR = 2201; |
| 577 | DYNAMIC_BAZ = 2202; |
| 578 | } |
| 579 | message DynamicMessageType { |
| 580 | optional int32 dynamic_field = 2100; |
| 581 | } |
| 582 | |
| 583 | optional fixed32 scalar_extension = 2000; |
| 584 | optional ForeignEnum enum_extension = 2001; |
| 585 | optional DynamicEnumType dynamic_enum_extension = 2002; |
| 586 | |
| 587 | optional ForeignMessage message_extension = 2003; |
| 588 | optional DynamicMessageType dynamic_message_extension = 2004; |
| 589 | |
| 590 | repeated string repeated_extension = 2005; |
| 591 | repeated sint32 packed_extension = 2006 [packed = true]; |
| 592 | } |
| 593 | |
| 594 | message TestRepeatedScalarDifferentTagSizes { |
| 595 | // Parsing repeated fixed size values used to fail. This message needs to be |
| 596 | // used in order to get a tag of the right size; all of the repeated fields |
| 597 | // in TestAllTypes didn't trigger the check. |
| 598 | repeated fixed32 repeated_fixed32 = 12; |
| 599 | // Check for a varint type, just for good measure. |
| 600 | repeated int32 repeated_int32 = 13; |
| 601 | |
| 602 | // These have two-byte tags. |
| 603 | repeated fixed64 repeated_fixed64 = 2046; |
| 604 | repeated int64 repeated_int64 = 2047; |
| 605 | |
| 606 | // Three byte tags. |
| 607 | repeated float repeated_float = 262142; |
| 608 | repeated uint64 repeated_uint64 = 262143; |
| 609 | } |
| 610 | |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 611 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 612 | // Test that RPC services work. |
| 613 | message FooRequest {} |
| 614 | message FooResponse {} |
| 615 | |
| 616 | service TestService { |
| 617 | rpc Foo(FooRequest) returns (FooResponse); |
| 618 | rpc Bar(BarRequest) returns (BarResponse); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | message BarRequest {} |
| 623 | message BarResponse {} |