unittest_proto3.proto 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file or at
  6. // https://developers.google.com/open-source/licenses/bsd
  7. syntax = "proto3";
  8. package proto3_unittest;
  9. import "google/protobuf/unittest_import.proto";
  10. option optimize_for = SPEED;
  11. // This proto includes every type of field in both singular and repeated
  12. // forms.
  13. message TestAllTypes {
  14. message NestedMessage {
  15. // The field name "b" fails to compile in proto1 because it conflicts with
  16. // a local variable named "b" in one of the generated methods. Doh.
  17. // This file needs to compile in proto1 to test backwards-compatibility.
  18. int32 bb = 1;
  19. }
  20. enum NestedEnum {
  21. ZERO = 0;
  22. FOO = 1;
  23. BAR = 2;
  24. BAZ = 3;
  25. NEG = -1; // Intentionally negative.
  26. }
  27. // Singular
  28. int32 optional_int32 = 1;
  29. int64 optional_int64 = 2;
  30. uint32 optional_uint32 = 3;
  31. uint64 optional_uint64 = 4;
  32. sint32 optional_sint32 = 5;
  33. sint64 optional_sint64 = 6;
  34. fixed32 optional_fixed32 = 7;
  35. fixed64 optional_fixed64 = 8;
  36. sfixed32 optional_sfixed32 = 9;
  37. sfixed64 optional_sfixed64 = 10;
  38. float optional_float = 11;
  39. double optional_double = 12;
  40. bool optional_bool = 13;
  41. string optional_string = 14;
  42. bytes optional_bytes = 15;
  43. // Groups are not allowed in proto3.
  44. // optional group OptionalGroup = 16 {
  45. // optional int32 a = 17;
  46. // }
  47. optional NestedMessage optional_nested_message = 18;
  48. ForeignMessage optional_foreign_message = 19;
  49. protobuf_unittest_import.ImportMessage optional_import_message = 20;
  50. NestedEnum optional_nested_enum = 21;
  51. ForeignEnum optional_foreign_enum = 22;
  52. // Omitted (compared to unittest.proto) because proto2 enums are not allowed
  53. // inside proto2 messages.
  54. //
  55. // optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;
  56. string optional_string_piece = 24 [ctype = STRING_PIECE];
  57. string optional_cord = 25 [ctype = CORD];
  58. // Defined in unittest_import_public.proto
  59. protobuf_unittest_import.PublicImportMessage optional_public_import_message =
  60. 26;
  61. NestedMessage optional_lazy_message = 27 [lazy = true];
  62. NestedMessage optional_unverified_lazy_message = 28 [unverified_lazy = true];
  63. protobuf_unittest_import.ImportMessage optional_lazy_import_message = 115
  64. [lazy = true];
  65. // Repeated
  66. repeated int32 repeated_int32 = 31;
  67. repeated int64 repeated_int64 = 32;
  68. repeated uint32 repeated_uint32 = 33;
  69. repeated uint64 repeated_uint64 = 34;
  70. repeated sint32 repeated_sint32 = 35;
  71. repeated sint64 repeated_sint64 = 36;
  72. repeated fixed32 repeated_fixed32 = 37;
  73. repeated fixed64 repeated_fixed64 = 38;
  74. repeated sfixed32 repeated_sfixed32 = 39;
  75. repeated sfixed64 repeated_sfixed64 = 40;
  76. repeated float repeated_float = 41;
  77. repeated double repeated_double = 42;
  78. repeated bool repeated_bool = 43;
  79. repeated string repeated_string = 44;
  80. repeated bytes repeated_bytes = 45;
  81. // Groups are not allowed in proto3.
  82. // repeated group RepeatedGroup = 46 {
  83. // optional int32 a = 47;
  84. // }
  85. repeated NestedMessage repeated_nested_message = 48;
  86. repeated ForeignMessage repeated_foreign_message = 49;
  87. repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
  88. repeated NestedEnum repeated_nested_enum = 51;
  89. repeated ForeignEnum repeated_foreign_enum = 52;
  90. // Omitted (compared to unittest.proto) because proto2 enums are not allowed
  91. // inside proto2 messages.
  92. //
  93. // repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
  94. repeated string repeated_string_piece = 54 [ctype = STRING_PIECE];
  95. repeated string repeated_cord = 55 [ctype = CORD];
  96. repeated NestedMessage repeated_lazy_message = 57;
  97. oneof oneof_field {
  98. uint32 oneof_uint32 = 111;
  99. NestedMessage oneof_nested_message = 112;
  100. string oneof_string = 113;
  101. bytes oneof_bytes = 114;
  102. }
  103. }
  104. // Test messages for packed fields
  105. message TestPackedTypes {
  106. repeated int32 packed_int32 = 90 [packed = true];
  107. repeated int64 packed_int64 = 91 [packed = true];
  108. repeated uint32 packed_uint32 = 92 [packed = true];
  109. repeated uint64 packed_uint64 = 93 [packed = true];
  110. repeated sint32 packed_sint32 = 94 [packed = true];
  111. repeated sint64 packed_sint64 = 95 [packed = true];
  112. repeated fixed32 packed_fixed32 = 96 [packed = true];
  113. repeated fixed64 packed_fixed64 = 97 [packed = true];
  114. repeated sfixed32 packed_sfixed32 = 98 [packed = true];
  115. repeated sfixed64 packed_sfixed64 = 99 [packed = true];
  116. repeated float packed_float = 100 [packed = true];
  117. repeated double packed_double = 101 [packed = true];
  118. repeated bool packed_bool = 102 [packed = true];
  119. repeated ForeignEnum packed_enum = 103 [packed = true];
  120. }
  121. // Explicitly set packed to false
  122. message TestUnpackedTypes {
  123. repeated int32 repeated_int32 = 1 [packed = false];
  124. repeated int64 repeated_int64 = 2 [packed = false];
  125. repeated uint32 repeated_uint32 = 3 [packed = false];
  126. repeated uint64 repeated_uint64 = 4 [packed = false];
  127. repeated sint32 repeated_sint32 = 5 [packed = false];
  128. repeated sint64 repeated_sint64 = 6 [packed = false];
  129. repeated fixed32 repeated_fixed32 = 7 [packed = false];
  130. repeated fixed64 repeated_fixed64 = 8 [packed = false];
  131. repeated sfixed32 repeated_sfixed32 = 9 [packed = false];
  132. repeated sfixed64 repeated_sfixed64 = 10 [packed = false];
  133. repeated float repeated_float = 11 [packed = false];
  134. repeated double repeated_double = 12 [packed = false];
  135. repeated bool repeated_bool = 13 [packed = false];
  136. repeated TestAllTypes.NestedEnum repeated_nested_enum = 14 [packed = false];
  137. }
  138. // This proto includes a recursively nested message.
  139. message NestedTestAllTypes {
  140. NestedTestAllTypes child = 1;
  141. TestAllTypes payload = 2;
  142. }
  143. // Define these after TestAllTypes to make sure the compiler can handle
  144. // that.
  145. message ForeignMessage {
  146. int32 c = 1;
  147. }
  148. enum ForeignEnum {
  149. FOREIGN_ZERO = 0;
  150. FOREIGN_FOO = 4;
  151. FOREIGN_BAR = 5;
  152. FOREIGN_BAZ = 6;
  153. FOREIGN_LARGE = 123456; // Large enough to escape the Boxed Integer cache.
  154. }
  155. // TestEmptyMessage is used to test behavior of unknown fields.
  156. message TestEmptyMessage {}
  157. // TestMessageWithDummy is also used to test behavior of unknown fields.
  158. message TestMessageWithDummy {
  159. // This field is only here for triggering copy-on-write; it's not intended to
  160. // be serialized.
  161. bool dummy = 536870911;
  162. }
  163. // Same layout as TestOneof2 in unittest.proto to test unknown enum value
  164. // parsing behavior in oneof.
  165. message TestOneof2 {
  166. oneof foo {
  167. NestedEnum foo_enum = 6;
  168. }
  169. enum NestedEnum {
  170. UNKNOWN = 0;
  171. FOO = 1;
  172. BAR = 2;
  173. BAZ = 3;
  174. }
  175. }
  176. // If bool fields are incorrectly assumed to have hasbits, InternalSwap would
  177. // result in swapping N more 32bit hasbits incorrectly. Considering padding, we
  178. // need many bool fields to stress this.
  179. message TestHasbits {
  180. bool b1 = 1;
  181. bool b2 = 2;
  182. bool b3 = 3;
  183. bool b4 = 4;
  184. bool b5 = 5;
  185. bool b6 = 6;
  186. bool b7 = 7;
  187. bool b8 = 8;
  188. bool b9 = 9;
  189. bool b10 = 10;
  190. bool b11 = 11;
  191. bool b12 = 12;
  192. bool b13 = 13;
  193. bool b14 = 14;
  194. bool b15 = 15;
  195. bool b16 = 16;
  196. bool b17 = 17;
  197. bool b18 = 18;
  198. bool b19 = 19;
  199. bool b20 = 20;
  200. bool b21 = 21;
  201. bool b22 = 22;
  202. bool b23 = 23;
  203. bool b24 = 24;
  204. bool b25 = 25;
  205. bool b26 = 26;
  206. bool b27 = 27;
  207. bool b28 = 28;
  208. bool b29 = 29;
  209. bool b30 = 30;
  210. bool b31 = 31;
  211. bool b32 = 32;
  212. bool b33 = 33;
  213. bool b34 = 34;
  214. bool b35 = 35;
  215. bool b36 = 36;
  216. bool b37 = 37;
  217. bool b38 = 38;
  218. bool b39 = 39;
  219. bool b40 = 40;
  220. bool b41 = 41;
  221. bool b42 = 42;
  222. bool b43 = 43;
  223. bool b44 = 44;
  224. bool b45 = 45;
  225. bool b46 = 46;
  226. bool b47 = 47;
  227. bool b48 = 48;
  228. bool b49 = 49;
  229. bool b50 = 50;
  230. bool b51 = 51;
  231. bool b52 = 52;
  232. bool b53 = 53;
  233. bool b54 = 54;
  234. bool b55 = 55;
  235. bool b56 = 56;
  236. bool b57 = 57;
  237. bool b58 = 58;
  238. bool b59 = 59;
  239. bool b60 = 60;
  240. bool b61 = 61;
  241. bool b62 = 62;
  242. bool b63 = 63;
  243. bool b64 = 64;
  244. bool b65 = 65;
  245. bool b66 = 66;
  246. bool b67 = 67;
  247. bool b68 = 68;
  248. bool b69 = 69;
  249. TestAllTypes child = 100;
  250. }