blob: b0eb47237ef5ccfbe485cfa680b6bdab1622f4d0 [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001// Protocol Buffers - Google's data interchange format
2// Copyright 2011 Google Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30syntax = "proto2";
31
Austin Schuh40c16522018-10-28 20:27:54 -070032import "google/protobuf/any.proto";
Brian Silverman9c614bc2016-02-15 20:20:02 -050033import "google/protobuf/unittest.proto";
34
35package protobuf_unittest;
36
Austin Schuh40c16522018-10-28 20:27:54 -070037// Used to check that Headerdocs and appledoc work correctly. If these comments
38// are not handled correctly, Xcode will fail to build the tests.
39message TestGeneratedComments {
40 // This is a string that could contain stuff like
41 // mime types as image/* or */plain. Maybe twitter usernames
42 // like @protobuf, @google or @something.
43 optional string string_field = 1;
44}
45
Brian Silverman9c614bc2016-02-15 20:20:02 -050046// Using the messages in unittest.proto, setup for recursive cases for testing
47// extensions at various depths.
48extend TestAllExtensions {
49 optional TestAllExtensions recursive_extension = 86;
50}
51
52// Recursive message to for testing autocreators at different depths.
53message TestRecursiveMessageWithRepeatedField {
54 optional TestRecursiveMessageWithRepeatedField a = 1;
55 repeated int32 i = 2;
56 repeated string str = 3;
57 map<int32, int32> i_to_i = 4;
58 map<string, string> str_to_str = 5;
59}
60
Austin Schuh40c16522018-10-28 20:27:54 -070061// Message with a few types of maps to cover the different custom flows
62// in the runtime.
63message TestMessageOfMaps {
64 map<string, string> str_to_str = 1;
65
66 map<string, int32> str_to_int = 2;
67 map<int32, string> int_to_str = 3;
68 map<int32, int32> int_to_int = 4;
69
70 map<string, bool> str_to_bool = 5;
71 map<bool, string> bool_to_str = 6;
72 map<bool, bool> bool_to_bool = 7;
73
74 map<int32, bool> int_to_bool = 8;
75 map<bool, int32> bool_to_int = 9;
76
77 map<string, TestAllTypes> str_to_msg = 10;
78 map<int32, TestAllTypes> int_to_msg = 11;
79 map<bool, TestAllTypes> bool_to_msg = 12;
80}
81
Brian Silverman9c614bc2016-02-15 20:20:02 -050082// Recursive message and extension to for testing autocreators at different
83// depths.
84message TestRecursiveExtension {
85 optional TestRecursiveExtension recursive_sub_message = 1;
86 repeated int32 repeated_value = 2;
87 extensions 1000 to max;
88}
89
90extend TestRecursiveExtension {
91 optional TestRecursiveExtension recursive_message_extension = 1000;
92}
93
94message self {
95 message super {
96 optional int32 description = 1;
97 }
98
99 enum autorelease {
100 retain = 1;
101 release = 2;
102 retainCount = 3;
103 }
104
105 // Singular
106 optional bool id = 1;
107 optional bool _cmd = 2;
108 optional bool in = 3;
109 optional bool out = 4;
110 optional bool inout = 5;
111 optional bool bycopy = 6;
112 optional bool byref = 7;
113 optional bool oneway = 8;
114 optional bool dealloc = 9;
115 optional bool zone = 10;
116 optional bool isProxy = 11;
117 optional bool copy = 12;
118 optional bool readonly = 13;
119 optional bool default = 14;
120 optional bool assign = 15;
121 optional bool getter = 16;
122 optional bool setter = 17;
123 optional bool weak = 18;
124 optional bool public = 19;
125 optional bool case = 20;
126
127 optional autorelease SubEnum = 25;
128
129 optional group New = 50 {
130 optional string copy = 51;
131 }
132 optional group MutableCopy = 60 {
133 optional int32 extensionRegistry = 61;
134 }
135
136 extensions 90 to 94;
137
138}
139
140enum retain {
141 count = 4;
142 initialized = 5;
143 serializedSize = 6;
144}
145
Austin Schuh40c16522018-10-28 20:27:54 -0700146message ObjCPropertyNaming {
147 // Test that the properties properly get things all caps.
148 optional string url = 1;
149 optional string thumbnail_url = 2;
150 optional string url_foo = 3;
151 optional string some_url_blah = 4;
152 optional string http = 5;
153 optional string https = 6;
154 // This one doesn't.
155 repeated string urls = 7;
156}
157
Brian Silverman9c614bc2016-02-15 20:20:02 -0500158// EnumValueShortName: The short names shouldn't get suffixes/prefixes.
159enum Foo {
160 SERIALIZED_SIZE = 1;
161 SIZE = 2;
162 OTHER = 3;
163}
164
165// EnumValueShortName: The enum name gets a prefix.
166enum Category {
167 RED = 1;
168 BLUE = 2;
169}
170
171// EnumValueShortName: Twist case, full name gets PB, but the short names
172// should still end up correct.
173enum Time {
174 BASE = 1;
175 RECORD = 2;
176 SOMETHING_ELSE = 3;
177}
178
179extend self {
180 repeated int32 debugDescription = 90 [packed = true];
181 repeated int64 finalize = 91 [packed = true];
182 repeated uint32 hash = 92 [packed = true];
183 repeated uint64 classForCoder = 93 [packed = true];
184 repeated sint32 byref = 94 [packed = true];
185}
186
187// Test handing of fields that start with init* since Xcode 5's ARC support
188// doesn't like messages that look like initializers but aren't.
189message ObjCInitFoo {
190 optional string init_val = 11;
191 optional int32 init_size = 12;
192 optional self init_self = 13;
193
194 repeated string init_vals = 21;
195 repeated int32 init_sizes = 22;
196 repeated self init_selfs = 23;
197}
198
199// Test handling of fields that start with retained names.
200message ObjCRetainedFoo {
201 optional string new_val_lower_complex = 11;
202 optional string new_Val_upper_complex = 12;
203 optional string newvalue_lower_no_underscore_complex = 13;
204 optional string newValue_upper_no_underscore_complex = 14;
205
206 optional int32 new_val_lower_primitive = 15;
207 optional int32 new_Val_upper_primitive = 16;
208 optional int32 newvalue_lower_no_underscore_primitive = 17;
209 optional int32 newValue_upper_no_underscore_primitive = 18;
210
211 optional self new_val_lower_message = 19;
212 optional self new_Val_upper_message = 20;
213 optional self newvalue_lower_no_underscore_message = 21;
214 optional self newValue_upper_no_underscore_message = 22;
215
216 optional Foo new_val_lower_enum = 23;
217 optional Foo new_Val_upper_enum = 24;
218 optional Foo newvalue_lower_no_underscore_enum = 25;
219 optional Foo newValue_upper_no_underscore_enum = 26;
220
221 repeated string new_val_lower_complex_repeated = 111;
222 repeated string new_Val_upper_complex_repeated = 112;
223 repeated string newvalue_lower_no_underscore_complex_repeated = 113;
224 repeated string newValue_upper_no_underscore_complex_repeated = 114;
225
226 repeated int32 new_val_lower_primitive_repeated = 115;
227 repeated int32 new_Val_upper_primitive_repeated = 116;
228 repeated int32 newvalue_lower_no_underscore_primitive_repeated = 117;
229 repeated int32 newValue_upper_no_underscore_primitive_repeated = 118;
230
231 repeated self new_val_lower_message_repeated = 119;
232 repeated self new_Val_upper_message_repeated = 120;
233 repeated self newvalue_lower_no_underscore_message_repeated = 121;
234 repeated self newValue_upper_no_underscore_message_repeated = 122;
235
236 repeated Foo new_val_lower_enum_repeated = 123;
237 repeated Foo new_Val_upper_enum_repeated = 124;
238 repeated Foo newvalue_lower_no_underscore_enum_repeated = 125;
239 repeated Foo newValue_upper_no_underscore_enum_repeated = 126;
240
241 optional string alloc_val_lower_complex = 211;
242 optional string alloc_Val_upper_complex = 212;
243 optional string allocvalue_lower_no_underscore_complex = 213;
244 optional string allocValue_upper_no_underscore_complex = 214;
245
246 optional int32 alloc_val_lower_primitive = 215;
247 optional int32 alloc_Val_upper_primitive = 216;
248 optional int32 allocvalue_lower_no_underscore_primitive = 217;
249 optional int32 allocValue_upper_no_underscore_primitive = 218;
250
251 optional self alloc_val_lower_message = 219;
252 optional self alloc_Val_upper_message = 220;
253 optional self allocvalue_lower_no_underscore_message = 221;
254 optional self allocValue_upper_no_underscore_message = 222;
255
256 optional Foo alloc_val_lower_enum = 223;
257 optional Foo alloc_Val_upper_enum = 224;
258 optional Foo allocvalue_lower_no_underscore_enum = 225;
259 optional Foo allocValue_upper_no_underscore_enum = 226;
260
261 repeated string alloc_val_lower_complex_repeated = 311;
262 repeated string alloc_Val_upper_complex_repeated = 312;
263 repeated string allocvalue_lower_no_underscore_complex_repeated = 313;
264 repeated string allocValue_upper_no_underscore_complex_repeated = 314;
265
266 repeated int32 alloc_val_lower_primitive_repeated = 315;
267 repeated int32 alloc_Val_upper_primitive_repeated = 316;
268 repeated int32 allocvalue_lower_no_underscore_primitive_repeated = 317;
269 repeated int32 allocValue_upper_no_underscore_primitive_repeated = 318;
270
271 repeated self alloc_val_lower_message_repeated = 319;
272 repeated self alloc_Val_upper_message_repeated = 320;
273 repeated self allocvalue_lower_no_underscore_message_repeated = 321;
274 repeated self allocValue_upper_no_underscore_message_repeated = 322;
275
276 repeated Foo alloc_val_lower_enum_repeated = 323;
277 repeated Foo alloc_Val_upper_enum_repeated = 324;
278 repeated Foo allocvalue_lower_no_underscore_enum_repeated = 325;
279 repeated Foo allocValue_upper_no_underscore_enum_repeated = 326;
280
281 optional string copy_val_lower_complex = 411;
282 optional string copy_Val_upper_complex = 412;
283 optional string copyvalue_lower_no_underscore_complex = 413;
284 optional string copyValue_upper_no_underscore_complex = 414;
285
286 optional int32 copy_val_lower_primitive = 415;
287 optional int32 copy_Val_upper_primitive = 416;
288 optional int32 copyvalue_lower_no_underscore_primitive = 417;
289 optional int32 copyValue_upper_no_underscore_primitive = 418;
290
291 optional self copy_val_lower_message = 419;
292 optional self copy_Val_upper_message = 420;
293 optional self copyvalue_lower_no_underscore_message = 421;
294 optional self copyValue_upper_no_underscore_message = 422;
295
296 optional Foo copy_val_lower_enum = 423;
297 optional Foo copy_Val_upper_enum = 424;
298 optional Foo copyvalue_lower_no_underscore_enum = 425;
299 optional Foo copyValue_upper_no_underscore_enum = 426;
300
301 repeated string copy_val_lower_complex_repeated = 511;
302 repeated string copy_Val_upper_complex_repeated = 512;
303 repeated string copyvalue_lower_no_underscore_complex_repeated = 513;
304 repeated string copyValue_upper_no_underscore_complex_repeated = 514;
305
306 repeated int32 copy_val_lower_primitive_repeated = 515;
307 repeated int32 copy_Val_upper_primitive_repeated = 516;
308 repeated int32 copyvalue_lower_no_underscore_primitive_repeated = 517;
309 repeated int32 copyValue_upper_no_underscore_primitive_repeated = 518;
310
311 repeated self copy_val_lower_message_repeated = 519;
312 repeated self copy_Val_upper_message_repeated = 520;
313 repeated self copyvalue_lower_no_underscore_message_repeated = 521;
314 repeated self copyValue_upper_no_underscore_message_repeated = 522;
315
316 repeated Foo copy_val_lower_enum_repeated = 523;
317 repeated Foo copy_Val_upper_enum_repeated = 524;
318 repeated Foo copyvalue_lower_no_underscore_enum_repeated = 525;
319 repeated Foo copyValue_upper_no_underscore_enum_repeated = 526;
320
321 optional string mutableCopy_val_lower_complex = 611;
322 optional string mutableCopy_Val_upper_complex = 612;
323 optional string mutableCopyvalue_lower_no_underscore_complex = 613;
324 optional string mutableCopyValue_upper_no_underscore_complex = 614;
325
326 optional int32 mutableCopy_val_lower_primitive = 615;
327 optional int32 mutableCopy_Val_upper_primitive = 616;
328 optional int32 mutableCopyvalue_lower_no_underscore_primitive = 617;
329 optional int32 mutableCopyValue_upper_no_underscore_primitive = 618;
330
331 optional self mutableCopy_val_lower_message = 619;
332 optional self mutableCopy_Val_upper_message = 620;
333 optional self mutableCopyvalue_lower_no_underscore_message = 621;
334 optional self mutableCopyValue_upper_no_underscore_message = 622;
335
336 optional Foo mutableCopy_val_lower_enum = 623;
337 optional Foo mutableCopy_Val_upper_enum = 624;
338 optional Foo mutableCopyvalue_lower_no_underscore_enum = 625;
339 optional Foo mutableCopyValue_upper_no_underscore_enum = 626;
340
341 repeated string mutableCopy_val_lower_complex_repeated = 711;
342 repeated string mutableCopy_Val_upper_complex_repeated = 712;
343 repeated string mutableCopyvalue_lower_no_underscore_complex_repeated = 713;
344 repeated string mutableCopyValue_upper_no_underscore_complex_repeated = 714;
345
346 repeated int32 mutableCopy_val_lower_primitive_repeated = 715;
347 repeated int32 mutableCopy_Val_upper_primitive_repeated = 716;
348 repeated int32 mutableCopyvalue_lower_no_underscore_primitive_repeated = 717;
349 repeated int32 mutableCopyValue_upper_no_underscore_primitive_repeated = 718;
350
351 repeated self mutableCopy_val_lower_message_repeated = 719;
352 repeated self mutableCopy_Val_upper_message_repeated = 720;
353 repeated self mutableCopyvalue_lower_no_underscore_message_repeated = 721;
354 repeated self mutableCopyValue_upper_no_underscore_message_repeated = 722;
355
356 repeated Foo mutableCopy_val_lower_enum_repeated = 723;
357 repeated Foo mutableCopy_Val_upper_enum_repeated = 724;
358 repeated Foo mutableCopyvalue_lower_no_underscore_enum_repeated = 725;
359 repeated Foo mutableCopyValue_upper_no_underscore_enum_repeated = 726;
360}
361
362// Test handling of fields that are the retained names.
363message ObjCRetainedComplex {
364 optional string new = 1;
365 optional string alloc = 2;
366 optional string copy = 3;
367 optional string mutableCopy = 4;
368}
369
370message ObjCRetainedComplexRepeated {
371 repeated string new = 1;
372 repeated string alloc = 2;
373 repeated string copy = 3;
374 repeated string mutableCopy = 4;
375}
376
377message ObjCRetainedPrimitive {
378 optional int32 new = 1;
379 optional int32 alloc = 2;
380 optional int32 copy = 3;
381 optional int32 mutableCopy = 4;
382}
383
384message ObjCRetainedPrimitiveRepeated {
385 repeated int32 new = 1;
386 repeated int32 alloc = 2;
387 repeated int32 copy = 3;
388 repeated int32 mutableCopy = 4;
389}
390
391message ObjCRetainedMessage {
392 optional self new = 1;
393 optional self alloc = 2;
394 optional self copy = 3;
395 optional self mutableCopy = 4;
396}
397
398message ObjCRetainedMessageRepeated {
399 repeated self new = 1;
400 repeated self alloc = 2;
401 repeated self copy = 3;
402 repeated self mutableCopy = 4;
403}
404
405// Test Handling some MacTypes
406message Point {
407 message Rect {
408 optional int32 TimeValue = 1;
409 }
410}
411
412// Test some weird defaults that we see in protos.
413message ObjcWeirdDefaults {
414 // Set default values that match the protocol buffer defined defaults to
415 // confirm hasDefault and the default values are set correctly.
416 optional string foo = 1 [default = ""];
417 optional bytes bar = 2 [default = ""];
418}
419
420// Used to confirm negative enum values work as expected.
421message EnumTestMsg {
422 enum MyEnum {
423 ZERO = 0;
424 ONE = 1;
425 TWO = 2;
426 NEG_ONE = -1;
427 NEG_TWO = -2;
428 }
429 optional MyEnum foo = 1;
430 optional MyEnum bar = 2 [default = ONE];
431 optional MyEnum baz = 3 [default = NEG_ONE];
432
433 repeated MyEnum mumble = 4;
434}
Austin Schuh40c16522018-10-28 20:27:54 -0700435
436// Test case for https://github.com/google/protobuf/issues/1453
437// Message with no explicit defaults, but a non zero default for an enum.
438message MessageWithOneBasedEnum {
439 enum OneBasedEnum {
440 ONE = 1;
441 TWO = 2;
442 }
443 optional OneBasedEnum enum_field = 1;
444}
445
446// Message with all bools for testing things related to bool storage.
447message BoolOnlyMessage {
448 optional bool bool_field_1 = 1;
449 optional bool bool_field_2 = 2;
450 optional bool bool_field_3 = 3;
451 optional bool bool_field_4 = 4;
452 optional bool bool_field_5 = 5;
453 optional bool bool_field_6 = 6;
454 optional bool bool_field_7 = 7;
455 optional bool bool_field_8 = 8;
456 optional bool bool_field_9 = 9;
457 optional bool bool_field_10 = 10;
458 optional bool bool_field_11 = 11;
459 optional bool bool_field_12 = 12;
460 optional bool bool_field_13 = 13;
461 optional bool bool_field_14 = 14;
462 optional bool bool_field_15 = 15;
463 optional bool bool_field_16 = 16;
464 optional bool bool_field_17 = 17;
465 optional bool bool_field_18 = 18;
466 optional bool bool_field_19 = 19;
467 optional bool bool_field_20 = 20;
468 optional bool bool_field_21 = 21;
469 optional bool bool_field_22 = 22;
470 optional bool bool_field_23 = 23;
471 optional bool bool_field_24 = 24;
472 optional bool bool_field_25 = 25;
473 optional bool bool_field_26 = 26;
474 optional bool bool_field_27 = 27;
475 optional bool bool_field_28 = 28;
476 optional bool bool_field_29 = 29;
477 optional bool bool_field_30 = 30;
478 optional bool bool_field_31 = 31;
479 optional bool bool_field_32 = 32;
480}
481
482// Reference to a WKT to test (via generated code inspection), the handling
483// of #imports. Within the WKTs, references to each other are just path
484// based imports, but when reference from another proto file, they should be
485// conditional to support the framework import style.
486message WKTRefereceMessage {
487 optional google.protobuf.Any an_any = 1;
488}