Debian Codegraph @

activemq-protobuf-test/src/main/proto/unittest.proto

raw
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.
3 // http://code.google.com/p/protobuf/
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 // Author: [email protected] (Kenton Varda)
18 // Based on original Protocol Buffers design by
19 // Sanjay Ghemawat, Jeff Dean, and others.
20 //
21 // A proto file we will use for unit testing.
22
23
24 import "unittest_import.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".
29 package 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.
34 option optimize_for = SPEED;
35
36 option java_outer_classname = "UnittestProto";
37
38 // This proto includes every type of field in both singular and repeated
39 // forms.
40 message 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 optional int32 bb = 1;
46 }
47
48 enum NestedEnum {
49 FOO = 1;
50 BAR = 2;
51 BAZ = 3;
52 }
53
54 // Singular
55 optional int32 optional_int32 = 1;
56 optional int64 optional_int64 = 2;
57 optional uint32 optional_uint32 = 3;
58 optional uint64 optional_uint64 = 4;
59 optional sint32 optional_sint32 = 5;
60 optional sint64 optional_sint64 = 6;
61 optional fixed32 optional_fixed32 = 7;
62 optional fixed64 optional_fixed64 = 8;
63 optional sfixed32 optional_sfixed32 = 9;
64 optional sfixed64 optional_sfixed64 = 10;
65 optional float optional_float = 11;
66 optional double optional_double = 12;
67 optional bool optional_bool = 13;
68 optional string optional_string = 14;
69 optional bytes optional_bytes = 15;
70
71 optional group OptionalGroup = 16 {
72 optional int32 a = 17;
73 }
74
75 optional NestedMessage optional_nested_message = 18;
76 optional ForeignMessage optional_foreign_message = 19;
77 optional protobuf_unittest_import.ImportMessage optional_import_message = 20;
78
79 optional NestedEnum optional_nested_enum = 21;
80 optional ForeignEnum optional_foreign_enum = 22;
81 optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;
82
83 optional string optional_string_piece = 24 [ctype=STRING_PIECE];
84 optional string optional_cord = 25 [ctype=CORD];
85
86 // Repeated
87 repeated int32 repeated_int32 = 31;
88 repeated int64 repeated_int64 = 32;
89 repeated uint32 repeated_uint32 = 33;
90 repeated uint64 repeated_uint64 = 34;
91 repeated sint32 repeated_sint32 = 35;
92 repeated sint64 repeated_sint64 = 36;
93 repeated fixed32 repeated_fixed32 = 37;
94 repeated fixed64 repeated_fixed64 = 38;
95 repeated sfixed32 repeated_sfixed32 = 39;
96 repeated sfixed64 repeated_sfixed64 = 40;
97 repeated float repeated_float = 41;
98 repeated double repeated_double = 42;
99 repeated bool repeated_bool = 43;
100 repeated string repeated_string = 44;
101 repeated bytes repeated_bytes = 45;
102
103 repeated group RepeatedGroup = 46 {
104 optional int32 a = 47;
105 }
106
107 repeated NestedMessage repeated_nested_message = 48;
108 repeated ForeignMessage repeated_foreign_message = 49;
109 repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
110
111 repeated NestedEnum repeated_nested_enum = 51;
112 repeated ForeignEnum repeated_foreign_enum = 52;
113 repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
114
115 repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
116 repeated string repeated_cord = 55 [ctype=CORD];
117
118 // Singular with defaults
119 optional int32 default_int32 = 61 [default = 41 ];
120 optional int64 default_int64 = 62 [default = 42 ];
121 optional uint32 default_uint32 = 63 [default = 43 ];
122 optional uint64 default_uint64 = 64 [default = 44 ];
123 optional sint32 default_sint32 = 65 [default = -45 ];
124 optional sint64 default_sint64 = 66 [default = 46 ];
125 optional fixed32 default_fixed32 = 67 [default = 47 ];
126 optional fixed64 default_fixed64 = 68 [default = 48 ];
127 optional sfixed32 default_sfixed32 = 69 [default = 49 ];
128 optional sfixed64 default_sfixed64 = 70 [default = -50 ];
129 optional float default_float = 71 [default = 51.5 ];
130 optional double default_double = 72 [default = 52e3 ];
131 optional bool default_bool = 73 [default = true ];
132 optional string default_string = 74 [default = "hello"];
133 optional bytes default_bytes = 75 [default = "world"];
134
135 optional NestedEnum default_nested_enum = 81 [default = BAR ];
136 optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
137 optional protobuf_unittest_import.ImportEnum
138 default_import_enum = 83 [default = IMPORT_BAR];
139
140 optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
141 optional string default_cord = 85 [ctype=CORD,default="123"];
142 }
143
144 // Define these after TestAllTypes to make sure the compiler can handle
145 // that.
146 message ForeignMessage {
147 optional int32 c = 1;
148 }
149
150 enum ForeignEnum {
151 FOREIGN_FOO = 4;
152 FOREIGN_BAR = 5;
153 FOREIGN_BAZ = 6;
154 }
155
156 message TestAllExtensions {
157 extensions 1 to max;
158 }
159
160 extend TestAllExtensions {
161 // Singular
162 optional int32 optional_int32_extension = 1;
163 optional int64 optional_int64_extension = 2;
164 optional uint32 optional_uint32_extension = 3;
165 optional uint64 optional_uint64_extension = 4;
166 optional sint32 optional_sint32_extension = 5;
167 optional sint64 optional_sint64_extension = 6;
168 optional fixed32 optional_fixed32_extension = 7;
169 optional fixed64 optional_fixed64_extension = 8;
170 optional sfixed32 optional_sfixed32_extension = 9;
171 optional sfixed64 optional_sfixed64_extension = 10;
172 optional float optional_float_extension = 11;
173 optional double optional_double_extension = 12;
174 optional bool optional_bool_extension = 13;
175 optional string optional_string_extension = 14;
176 optional bytes optional_bytes_extension = 15;
177
178 optional group OptionalGroup_extension = 16 {
179 optional int32 a = 17;
180 }
181
182 optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
183 optional ForeignMessage optional_foreign_message_extension = 19;
184 optional protobuf_unittest_import.ImportMessage
185 optional_import_message_extension = 20;
186
187 optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
188 optional ForeignEnum optional_foreign_enum_extension = 22;
189 optional protobuf_unittest_import.ImportEnum
190 optional_import_enum_extension = 23;
191
192 optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
193 optional string optional_cord_extension = 25 [ctype=CORD];
194
195 // Repeated
196 repeated int32 repeated_int32_extension = 31;
197 repeated int64 repeated_int64_extension = 32;
198 repeated uint32 repeated_uint32_extension = 33;
199 repeated uint64 repeated_uint64_extension = 34;
200 repeated sint32 repeated_sint32_extension = 35;
201 repeated sint64 repeated_sint64_extension = 36;
202 repeated fixed32 repeated_fixed32_extension = 37;
203 repeated fixed64 repeated_fixed64_extension = 38;
204 repeated sfixed32 repeated_sfixed32_extension = 39;
205 repeated sfixed64 repeated_sfixed64_extension = 40;
206 repeated float repeated_float_extension = 41;
207 repeated double repeated_double_extension = 42;
208 repeated bool repeated_bool_extension = 43;
209 repeated string repeated_string_extension = 44;
210 repeated bytes repeated_bytes_extension = 45;
211
212 repeated group RepeatedGroup_extension = 46 {
213 optional int32 a = 47;
214 }
215
216 repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
217 repeated ForeignMessage repeated_foreign_message_extension = 49;
218 repeated protobuf_unittest_import.ImportMessage
219 repeated_import_message_extension = 50;
220
221 repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
222 repeated ForeignEnum repeated_foreign_enum_extension = 52;
223 repeated protobuf_unittest_import.ImportEnum
224 repeated_import_enum_extension = 53;
225
226 repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
227 repeated string repeated_cord_extension = 55 [ctype=CORD];
228
229 // Singular with defaults
230 optional int32 default_int32_extension = 61 [default = 41 ];
231 optional int64 default_int64_extension = 62 [default = 42 ];
232 optional uint32 default_uint32_extension = 63 [default = 43 ];
233 optional uint64 default_uint64_extension = 64 [default = 44 ];
234 optional sint32 default_sint32_extension = 65 [default = -45 ];
235 optional sint64 default_sint64_extension = 66 [default = 46 ];
236 optional fixed32 default_fixed32_extension = 67 [default = 47 ];
237 optional fixed64 default_fixed64_extension = 68 [default = 48 ];
238 optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];
239 optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];
240 optional float default_float_extension = 71 [default = 51.5 ];
241 optional double default_double_extension = 72 [default = 52e3 ];
242 optional bool default_bool_extension = 73 [default = true ];
243 optional string default_string_extension = 74 [default = "hello"];
244 optional bytes default_bytes_extension = 75 [default = "world"];
245
246 optional TestAllTypes.NestedEnum
247 default_nested_enum_extension = 81 [default = BAR];
248 optional ForeignEnum
249 default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
250 optional protobuf_unittest_import.ImportEnum
251 default_import_enum_extension = 83 [default = IMPORT_BAR];
252
253 optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
254 default="abc"];
255 optional string default_cord_extension = 85 [ctype=CORD, default="123"];
256 }
257
258 // We have separate messages for testing required fields because it's
259 // annoying to have to fill in required fields in TestProto in order to
260 // do anything with it. Note that we don't need to test every type of
261 // required filed because the code output is basically identical to
262 // optional fields for all types.
263 message TestRequired {
264 required int32 a = 1;
265 optional int32 dummy2 = 2;
266 required int32 b = 3;
267
268 extend TestAllExtensions {
269 optional TestRequired single = 1000;
270 repeated TestRequired multi = 1001;
271 }
272
273 // Pad the field count to 32 so that we can test that IsInitialized()
274 // properly checks multiple elements of has_bits_.
275 optional int32 dummy4 = 4;
276 optional int32 dummy5 = 5;
277 optional int32 dummy6 = 6;
278 optional int32 dummy7 = 7;
279 optional int32 dummy8 = 8;
280 optional int32 dummy9 = 9;
281 optional int32 dummy10 = 10;
282 optional int32 dummy11 = 11;
283 optional int32 dummy12 = 12;
284 optional int32 dummy13 = 13;
285 optional int32 dummy14 = 14;
286 optional int32 dummy15 = 15;
287 optional int32 dummy16 = 16;
288 optional int32 dummy17 = 17;
289 optional int32 dummy18 = 18;
290 optional int32 dummy19 = 19;
291 optional int32 dummy20 = 20;
292 optional int32 dummy21 = 21;
293 optional int32 dummy22 = 22;
294 optional int32 dummy23 = 23;
295 optional int32 dummy24 = 24;
296 optional int32 dummy25 = 25;
297 optional int32 dummy26 = 26;
298 optional int32 dummy27 = 27;
299 optional int32 dummy28 = 28;
300 optional int32 dummy29 = 29;
301 optional int32 dummy30 = 30;
302 optional int32 dummy31 = 31;
303 optional int32 dummy32 = 32;
304
305 required int32 c = 33;
306 }
307
308 message TestRequiredForeign {
309 optional TestRequired optional_message = 1;
310 repeated TestRequired repeated_message = 2;
311 optional int32 dummy = 3;
312 }
313
314 // Test that we can use NestedMessage from outside TestAllTypes.
315 message TestForeignNested {
316 optional TestAllTypes.NestedMessage foreign_nested = 1;
317 }
318
319 // TestEmptyMessage is used to test unknown field support.
320 message TestEmptyMessage {
321 }
322
323 // Like above, but declare all field numbers as potential extensions. No
324 // actual extensions should ever be defined for this type.
325 message TestEmptyMessageWithExtensions {
326 extensions 1 to max;
327 }
328
329 // Test that really large tag numbers don't break anything.
330 message TestReallyLargeTagNumber {
331 // The largest possible tag number is 2^28 - 1, since the wire format uses
332 // three bits to communicate wire type.
333 optional int32 a = 1;
334 optional int32 bb = 268435455;
335 }
336
337 message TestRecursiveMessage {
338 optional TestRecursiveMessage a = 1;
339 optional int32 i = 2;
340 }
341
342 // Test that mutual recursion works.
343 message TestMutualRecursionA {
344 optional TestMutualRecursionB bb = 1;
345 }
346
347 message TestMutualRecursionB {
348 optional TestMutualRecursionA a = 1;
349 optional int32 optional_int32 = 2;
350 }
351
352 // Test that groups have disjoint field numbers from their siblings and
353 // parents. This is NOT possible in proto1; only proto2. When outputting
354 // proto1, the dup fields should be dropped.
355 message TestDupFieldNumber {
356 optional int32 a = 1;
357 optional group Foo = 2 { optional int32 a = 1; }
358 optional group Bar = 3 { optional int32 a = 1; }
359 }
360
361
362 // Needed for a Python test.
363 message TestNestedMessageHasBits {
364 message NestedMessage {
365 repeated int32 nestedmessage_repeated_int32 = 1;
366 repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
367 }
368 optional NestedMessage optional_nested_message = 1;
369 }
370
371
372 // Test an enum that has multiple values with the same number.
373 enum TestEnumWithDupValue {
374 FOO1 = 1;
375 BAR1 = 2;
376 BAZ = 3;
377 FOO2 = 1;
378 BAR2 = 2;
379 }
380
381 // Test an enum with large, unordered values.
382 enum TestSparseEnum {
383 SPARSE_A = 123;
384 SPARSE_B = 62374;
385 SPARSE_C = 12589234;
386 SPARSE_D = -15;
387 SPARSE_E = -53452;
388 SPARSE_F = 0;
389 SPARSE_G = 2;
390 }
391
392 // Test message with CamelCase field names. This violates Protocol Buffer
393 // standard style.
394 message TestCamelCaseFieldNames {
395 optional int32 PrimitiveField = 1;
396 optional string StringField = 2;
397 optional ForeignEnum EnumField = 3;
398 optional ForeignMessage MessageField = 4;
399 optional string StringPieceField = 5 [ctype=STRING_PIECE];
400 optional string CordField = 6 [ctype=CORD];
401
402 repeated int32 RepeatedPrimitiveField = 7;
403 repeated string RepeatedStringField = 8;
404 repeated ForeignEnum RepeatedEnumField = 9;
405 repeated ForeignMessage RepeatedMessageField = 10;
406 repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
407 repeated string RepeatedCordField = 12 [ctype=CORD];
408 }
409
410
411 // We list fields out of order, to ensure that we're using field number and not
412 // field index to determine serialization order.
413 message TestFieldOrderings {
414 optional string my_string = 11;
415 extensions 2 to 10;
416 optional int64 my_int = 1;
417 extensions 12 to 100;
418 optional float my_float = 101;
419 }
420
421
422 extend TestFieldOrderings {
423 optional string my_extension_string = 50;
424 optional int32 my_extension_int = 5;
425 }
426
427
428 message TestExtremeDefaultValues {
429 optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
430 optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
431 optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
432 optional int32 small_int32 = 4 [default = -0x7FFFFFFF];
433 optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];
434
435 // The default value here is UTF-8 for "\u1234". (We could also just type
436 // the UTF-8 text directly into this text file rather than escape it, but
437 // lots of people use editors that would be confused by this.)
438 optional string utf8_string = 6 [default = "\341\210\264"];
439 }
440
441 // Test that RPC services work.
442 message FooRequest {}
443 message FooResponse {}
444
445 service TestService {
446 rpc Foo(FooRequest) returns (FooResponse);
447 rpc Bar(BarRequest) returns (BarResponse);
448 }
449
450
451 message BarRequest {}
452 message BarResponse {}