unittest_objc.proto 19 KB

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