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