unittest_objc.proto 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. // 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. syntax = "proto2";
  30. import "google/protobuf/any.proto";
  31. import "google/protobuf/unittest.proto";
  32. package protobuf_unittest;
  33. // Used to check that Headerdocs and appledoc work correctly. If these comments
  34. // are not handled correctly, Xcode will fail to build the tests.
  35. message TestGeneratedComments {
  36. // This is a string that could contain stuff like
  37. // mime types as image/* or */plain. Maybe twitter usernames
  38. // like @protobuf, @google or @something.
  39. optional string string_field = 1;
  40. }
  41. // Using the messages in unittest.proto, setup for recursive cases for testing
  42. // extensions at various depths.
  43. extend TestAllExtensions {
  44. optional TestAllExtensions recursive_extension = 86;
  45. }
  46. // Recursive message to for testing autocreators at different depths.
  47. message TestRecursiveMessageWithRepeatedField {
  48. optional TestRecursiveMessageWithRepeatedField a = 1;
  49. repeated int32 i = 2;
  50. repeated string str = 3;
  51. map<int32, int32> i_to_i = 4;
  52. map<string, string> str_to_str = 5;
  53. }
  54. // Recursive message and extension to for testing autocreators at different
  55. // depths.
  56. message TestRecursiveExtension {
  57. optional TestRecursiveExtension recursive_sub_message = 1;
  58. repeated int32 repeated_value = 2;
  59. extensions 1000 to max;
  60. }
  61. extend TestRecursiveExtension {
  62. optional TestRecursiveExtension recursive_message_extension = 1000;
  63. }
  64. message self {
  65. message super {
  66. optional int32 description = 1;
  67. }
  68. enum autorelease {
  69. retain = 1;
  70. release = 2;
  71. retainCount = 3;
  72. }
  73. // Singular
  74. optional bool id = 1;
  75. optional bool _cmd = 2;
  76. optional bool in = 3;
  77. optional bool out = 4;
  78. optional bool inout = 5;
  79. optional bool bycopy = 6;
  80. optional bool byref = 7;
  81. optional bool oneway = 8;
  82. optional bool dealloc = 9;
  83. optional bool zone = 10;
  84. optional bool isProxy = 11;
  85. optional bool copy = 12;
  86. optional bool readonly = 13;
  87. optional bool default = 14;
  88. optional bool assign = 15;
  89. optional bool getter = 16;
  90. optional bool setter = 17;
  91. optional bool weak = 18;
  92. optional bool public = 19;
  93. optional bool case = 20;
  94. optional autorelease SubEnum = 25;
  95. optional group New = 50 {
  96. optional string copy = 51;
  97. }
  98. optional group MutableCopy = 60 {
  99. optional int32 extensionRegistry = 61;
  100. }
  101. extensions 90 to 94;
  102. }
  103. enum retain {
  104. count = 4;
  105. initialized = 5;
  106. serializedSize = 6;
  107. }
  108. message ObjCPropertyNaming {
  109. // Test that the properties properly get things all caps.
  110. optional string url = 1;
  111. optional string thumbnail_url = 2;
  112. optional string url_foo = 3;
  113. optional string some_url_blah = 4;
  114. optional string http = 5;
  115. optional string https = 6;
  116. // This one doesn't.
  117. repeated string urls = 7;
  118. }
  119. // EnumValueShortName: The short names shouldn't get suffixes/prefixes.
  120. enum Foo {
  121. SERIALIZED_SIZE = 1;
  122. SIZE = 2;
  123. OTHER = 3;
  124. }
  125. // EnumValueShortName: The enum name gets a prefix.
  126. enum Category {
  127. RED = 1;
  128. BLUE = 2;
  129. }
  130. // EnumValueShortName: Twist case, full name gets PB, but the short names
  131. // should still end up correct.
  132. enum Time {
  133. BASE = 1;
  134. RECORD = 2;
  135. SOMETHING_ELSE = 3;
  136. }
  137. extend self {
  138. repeated int32 debugDescription = 90 [packed = true];
  139. repeated int64 finalize = 91 [packed = true];
  140. repeated uint32 hash = 92 [packed = true];
  141. repeated uint64 classForCoder = 93 [packed = true];
  142. repeated sint32 byref = 94 [packed = true];
  143. }
  144. // Test handing of fields that start with init* since Xcode 5's ARC support
  145. // doesn't like messages that look like initializers but aren't.
  146. message ObjCInitFoo {
  147. optional string init_val = 11;
  148. optional int32 init_size = 12;
  149. optional self init_self = 13;
  150. repeated string init_vals = 21;
  151. repeated int32 init_sizes = 22;
  152. repeated self init_selfs = 23;
  153. }
  154. // Test handling of fields that start with retained names.
  155. message ObjCRetainedFoo {
  156. optional string new_val_lower_complex = 11;
  157. optional string new_Val_upper_complex = 12;
  158. optional string newvalue_lower_no_underscore_complex = 13;
  159. optional string newValue_upper_no_underscore_complex = 14;
  160. optional int32 new_val_lower_primitive = 15;
  161. optional int32 new_Val_upper_primitive = 16;
  162. optional int32 newvalue_lower_no_underscore_primitive = 17;
  163. optional int32 newValue_upper_no_underscore_primitive = 18;
  164. optional self new_val_lower_message = 19;
  165. optional self new_Val_upper_message = 20;
  166. optional self newvalue_lower_no_underscore_message = 21;
  167. optional self newValue_upper_no_underscore_message = 22;
  168. optional Foo new_val_lower_enum = 23;
  169. optional Foo new_Val_upper_enum = 24;
  170. optional Foo newvalue_lower_no_underscore_enum = 25;
  171. optional Foo newValue_upper_no_underscore_enum = 26;
  172. repeated string new_val_lower_complex_repeated = 111;
  173. repeated string new_Val_upper_complex_repeated = 112;
  174. repeated string newvalue_lower_no_underscore_complex_repeated = 113;
  175. repeated string newValue_upper_no_underscore_complex_repeated = 114;
  176. repeated int32 new_val_lower_primitive_repeated = 115;
  177. repeated int32 new_Val_upper_primitive_repeated = 116;
  178. repeated int32 newvalue_lower_no_underscore_primitive_repeated = 117;
  179. repeated int32 newValue_upper_no_underscore_primitive_repeated = 118;
  180. repeated self new_val_lower_message_repeated = 119;
  181. repeated self new_Val_upper_message_repeated = 120;
  182. repeated self newvalue_lower_no_underscore_message_repeated = 121;
  183. repeated self newValue_upper_no_underscore_message_repeated = 122;
  184. repeated Foo new_val_lower_enum_repeated = 123;
  185. repeated Foo new_Val_upper_enum_repeated = 124;
  186. repeated Foo newvalue_lower_no_underscore_enum_repeated = 125;
  187. repeated Foo newValue_upper_no_underscore_enum_repeated = 126;
  188. optional string alloc_val_lower_complex = 211;
  189. optional string alloc_Val_upper_complex = 212;
  190. optional string allocvalue_lower_no_underscore_complex = 213;
  191. optional string allocValue_upper_no_underscore_complex = 214;
  192. optional int32 alloc_val_lower_primitive = 215;
  193. optional int32 alloc_Val_upper_primitive = 216;
  194. optional int32 allocvalue_lower_no_underscore_primitive = 217;
  195. optional int32 allocValue_upper_no_underscore_primitive = 218;
  196. optional self alloc_val_lower_message = 219;
  197. optional self alloc_Val_upper_message = 220;
  198. optional self allocvalue_lower_no_underscore_message = 221;
  199. optional self allocValue_upper_no_underscore_message = 222;
  200. optional Foo alloc_val_lower_enum = 223;
  201. optional Foo alloc_Val_upper_enum = 224;
  202. optional Foo allocvalue_lower_no_underscore_enum = 225;
  203. optional Foo allocValue_upper_no_underscore_enum = 226;
  204. repeated string alloc_val_lower_complex_repeated = 311;
  205. repeated string alloc_Val_upper_complex_repeated = 312;
  206. repeated string allocvalue_lower_no_underscore_complex_repeated = 313;
  207. repeated string allocValue_upper_no_underscore_complex_repeated = 314;
  208. repeated int32 alloc_val_lower_primitive_repeated = 315;
  209. repeated int32 alloc_Val_upper_primitive_repeated = 316;
  210. repeated int32 allocvalue_lower_no_underscore_primitive_repeated = 317;
  211. repeated int32 allocValue_upper_no_underscore_primitive_repeated = 318;
  212. repeated self alloc_val_lower_message_repeated = 319;
  213. repeated self alloc_Val_upper_message_repeated = 320;
  214. repeated self allocvalue_lower_no_underscore_message_repeated = 321;
  215. repeated self allocValue_upper_no_underscore_message_repeated = 322;
  216. repeated Foo alloc_val_lower_enum_repeated = 323;
  217. repeated Foo alloc_Val_upper_enum_repeated = 324;
  218. repeated Foo allocvalue_lower_no_underscore_enum_repeated = 325;
  219. repeated Foo allocValue_upper_no_underscore_enum_repeated = 326;
  220. optional string copy_val_lower_complex = 411;
  221. optional string copy_Val_upper_complex = 412;
  222. optional string copyvalue_lower_no_underscore_complex = 413;
  223. optional string copyValue_upper_no_underscore_complex = 414;
  224. optional int32 copy_val_lower_primitive = 415;
  225. optional int32 copy_Val_upper_primitive = 416;
  226. optional int32 copyvalue_lower_no_underscore_primitive = 417;
  227. optional int32 copyValue_upper_no_underscore_primitive = 418;
  228. optional self copy_val_lower_message = 419;
  229. optional self copy_Val_upper_message = 420;
  230. optional self copyvalue_lower_no_underscore_message = 421;
  231. optional self copyValue_upper_no_underscore_message = 422;
  232. optional Foo copy_val_lower_enum = 423;
  233. optional Foo copy_Val_upper_enum = 424;
  234. optional Foo copyvalue_lower_no_underscore_enum = 425;
  235. optional Foo copyValue_upper_no_underscore_enum = 426;
  236. repeated string copy_val_lower_complex_repeated = 511;
  237. repeated string copy_Val_upper_complex_repeated = 512;
  238. repeated string copyvalue_lower_no_underscore_complex_repeated = 513;
  239. repeated string copyValue_upper_no_underscore_complex_repeated = 514;
  240. repeated int32 copy_val_lower_primitive_repeated = 515;
  241. repeated int32 copy_Val_upper_primitive_repeated = 516;
  242. repeated int32 copyvalue_lower_no_underscore_primitive_repeated = 517;
  243. repeated int32 copyValue_upper_no_underscore_primitive_repeated = 518;
  244. repeated self copy_val_lower_message_repeated = 519;
  245. repeated self copy_Val_upper_message_repeated = 520;
  246. repeated self copyvalue_lower_no_underscore_message_repeated = 521;
  247. repeated self copyValue_upper_no_underscore_message_repeated = 522;
  248. repeated Foo copy_val_lower_enum_repeated = 523;
  249. repeated Foo copy_Val_upper_enum_repeated = 524;
  250. repeated Foo copyvalue_lower_no_underscore_enum_repeated = 525;
  251. repeated Foo copyValue_upper_no_underscore_enum_repeated = 526;
  252. optional string mutableCopy_val_lower_complex = 611;
  253. optional string mutableCopy_Val_upper_complex = 612;
  254. optional string mutableCopyvalue_lower_no_underscore_complex = 613;
  255. optional string mutableCopyValue_upper_no_underscore_complex = 614;
  256. optional int32 mutableCopy_val_lower_primitive = 615;
  257. optional int32 mutableCopy_Val_upper_primitive = 616;
  258. optional int32 mutableCopyvalue_lower_no_underscore_primitive = 617;
  259. optional int32 mutableCopyValue_upper_no_underscore_primitive = 618;
  260. optional self mutableCopy_val_lower_message = 619;
  261. optional self mutableCopy_Val_upper_message = 620;
  262. optional self mutableCopyvalue_lower_no_underscore_message = 621;
  263. optional self mutableCopyValue_upper_no_underscore_message = 622;
  264. optional Foo mutableCopy_val_lower_enum = 623;
  265. optional Foo mutableCopy_Val_upper_enum = 624;
  266. optional Foo mutableCopyvalue_lower_no_underscore_enum = 625;
  267. optional Foo mutableCopyValue_upper_no_underscore_enum = 626;
  268. repeated string mutableCopy_val_lower_complex_repeated = 711;
  269. repeated string mutableCopy_Val_upper_complex_repeated = 712;
  270. repeated string mutableCopyvalue_lower_no_underscore_complex_repeated = 713;
  271. repeated string mutableCopyValue_upper_no_underscore_complex_repeated = 714;
  272. repeated int32 mutableCopy_val_lower_primitive_repeated = 715;
  273. repeated int32 mutableCopy_Val_upper_primitive_repeated = 716;
  274. repeated int32 mutableCopyvalue_lower_no_underscore_primitive_repeated = 717;
  275. repeated int32 mutableCopyValue_upper_no_underscore_primitive_repeated = 718;
  276. repeated self mutableCopy_val_lower_message_repeated = 719;
  277. repeated self mutableCopy_Val_upper_message_repeated = 720;
  278. repeated self mutableCopyvalue_lower_no_underscore_message_repeated = 721;
  279. repeated self mutableCopyValue_upper_no_underscore_message_repeated = 722;
  280. repeated Foo mutableCopy_val_lower_enum_repeated = 723;
  281. repeated Foo mutableCopy_Val_upper_enum_repeated = 724;
  282. repeated Foo mutableCopyvalue_lower_no_underscore_enum_repeated = 725;
  283. repeated Foo mutableCopyValue_upper_no_underscore_enum_repeated = 726;
  284. }
  285. // Test handling of fields that are the retained names.
  286. message ObjCRetainedComplex {
  287. optional string new = 1;
  288. optional string alloc = 2;
  289. optional string copy = 3;
  290. optional string mutableCopy = 4;
  291. }
  292. message ObjCRetainedComplexRepeated {
  293. repeated string new = 1;
  294. repeated string alloc = 2;
  295. repeated string copy = 3;
  296. repeated string mutableCopy = 4;
  297. }
  298. message ObjCRetainedPrimitive {
  299. optional int32 new = 1;
  300. optional int32 alloc = 2;
  301. optional int32 copy = 3;
  302. optional int32 mutableCopy = 4;
  303. }
  304. message ObjCRetainedPrimitiveRepeated {
  305. repeated int32 new = 1;
  306. repeated int32 alloc = 2;
  307. repeated int32 copy = 3;
  308. repeated int32 mutableCopy = 4;
  309. }
  310. message ObjCRetainedMessage {
  311. optional self new = 1;
  312. optional self alloc = 2;
  313. optional self copy = 3;
  314. optional self mutableCopy = 4;
  315. }
  316. message ObjCRetainedMessageRepeated {
  317. repeated self new = 1;
  318. repeated self alloc = 2;
  319. repeated self copy = 3;
  320. repeated self mutableCopy = 4;
  321. }
  322. // Test Handling some MacTypes
  323. message Point {
  324. message Rect {
  325. optional int32 TimeValue = 1;
  326. }
  327. }
  328. // Test some weird defaults that we see in protos.
  329. message ObjcWeirdDefaults {
  330. // Set default values that match the protocol buffer defined defaults to
  331. // confirm hasDefault and the default values are set correctly.
  332. optional string foo = 1 [default = ""];
  333. optional bytes bar = 2 [default = ""];
  334. }
  335. // Used to confirm negative enum values work as expected.
  336. message EnumTestMsg {
  337. enum MyEnum {
  338. ZERO = 0;
  339. ONE = 1;
  340. TWO = 2;
  341. NEG_ONE = -1;
  342. NEG_TWO = -2;
  343. }
  344. optional MyEnum foo = 1;
  345. optional MyEnum bar = 2 [default = ONE];
  346. optional MyEnum baz = 3 [default = NEG_ONE];
  347. repeated MyEnum mumble = 4;
  348. }
  349. // Test case for https://github.com/google/protobuf/issues/1453
  350. // Message with no explicit defaults, but a non zero default for an enum.
  351. message MessageWithOneBasedEnum {
  352. enum OneBasedEnum {
  353. ONE = 1;
  354. TWO = 2;
  355. }
  356. optional OneBasedEnum enum_field = 1;
  357. }
  358. // Message with all bools for testing things related to bool storage.
  359. message BoolOnlyMessage {
  360. optional bool bool_field_1 = 1;
  361. optional bool bool_field_2 = 2;
  362. optional bool bool_field_3 = 3;
  363. optional bool bool_field_4 = 4;
  364. optional bool bool_field_5 = 5;
  365. optional bool bool_field_6 = 6;
  366. optional bool bool_field_7 = 7;
  367. optional bool bool_field_8 = 8;
  368. optional bool bool_field_9 = 9;
  369. optional bool bool_field_10 = 10;
  370. optional bool bool_field_11 = 11;
  371. optional bool bool_field_12 = 12;
  372. optional bool bool_field_13 = 13;
  373. optional bool bool_field_14 = 14;
  374. optional bool bool_field_15 = 15;
  375. optional bool bool_field_16 = 16;
  376. optional bool bool_field_17 = 17;
  377. optional bool bool_field_18 = 18;
  378. optional bool bool_field_19 = 19;
  379. optional bool bool_field_20 = 20;
  380. optional bool bool_field_21 = 21;
  381. optional bool bool_field_22 = 22;
  382. optional bool bool_field_23 = 23;
  383. optional bool bool_field_24 = 24;
  384. optional bool bool_field_25 = 25;
  385. optional bool bool_field_26 = 26;
  386. optional bool bool_field_27 = 27;
  387. optional bool bool_field_28 = 28;
  388. optional bool bool_field_29 = 29;
  389. optional bool bool_field_30 = 30;
  390. optional bool bool_field_31 = 31;
  391. optional bool bool_field_32 = 32;
  392. }
  393. // Reference to a WKT to test (via generated code inspection), the handling
  394. // of #imports. Within the WKTs, references to each other are just path
  395. // based imports, but when reference from another proto file, they should be
  396. // conditional to support the framework import style.
  397. message WKTRefereceMessage {
  398. optional google.protobuf.Any an_any = 1;
  399. }