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