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