unittest_objc.proto 17 KB

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