unittest_proto3.proto 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // A proto file we will use for unit testing.
  35. syntax = "proto3";
  36. // Some generic_services option(s) added automatically.
  37. // See: http://go/proto2-generic-services-default
  38. option cc_generic_services = true; // auto-added
  39. option java_generic_services = true; // auto-added
  40. option py_generic_services = true; // auto-added
  41. option cc_enable_arenas = true;
  42. option csharp_namespace = "Google.Protobuf.TestProtos";
  43. import "unittest_import_proto3.proto";
  44. // We don't put this in a package within proto2 because we need to make sure
  45. // that the generated code doesn't depend on being in the proto2 namespace.
  46. // In test_util.h we do "using namespace unittest = protobuf_unittest".
  47. package protobuf_unittest3;
  48. // Protos optimized for SPEED use a strict superset of the generated code
  49. // of equivalent ones optimized for CODE_SIZE, so we should optimize all our
  50. // tests for speed unless explicitly testing code size optimization.
  51. option optimize_for = SPEED;
  52. option java_outer_classname = "UnittestProto";
  53. // This proto includes every type of field in both singular and repeated
  54. // forms.
  55. message TestAllTypes {
  56. message NestedMessage {
  57. // The field name "b" fails to compile in proto1 because it conflicts with
  58. // a local variable named "b" in one of the generated methods. Doh.
  59. // This file needs to compile in proto1 to test backwards-compatibility.
  60. int32 bb = 1;
  61. }
  62. enum NestedEnum {
  63. NESTED_ENUM_UNSPECIFIED = 0;
  64. FOO = 1;
  65. BAR = 2;
  66. BAZ = 3;
  67. NEG = -1; // Intentionally negative.
  68. }
  69. // Singular
  70. int32 single_int32 = 1;
  71. int64 single_int64 = 2;
  72. uint32 single_uint32 = 3;
  73. uint64 single_uint64 = 4;
  74. sint32 single_sint32 = 5;
  75. sint64 single_sint64 = 6;
  76. fixed32 single_fixed32 = 7;
  77. fixed64 single_fixed64 = 8;
  78. sfixed32 single_sfixed32 = 9;
  79. sfixed64 single_sfixed64 = 10;
  80. float single_float = 11;
  81. double single_double = 12;
  82. bool single_bool = 13;
  83. string single_string = 14;
  84. bytes single_bytes = 15;
  85. NestedMessage single_nested_message = 18;
  86. ForeignMessage single_foreign_message = 19;
  87. protobuf_unittest_import.ImportMessage single_import_message = 20;
  88. NestedEnum single_nested_enum = 21;
  89. ForeignEnum single_foreign_enum = 22;
  90. protobuf_unittest_import.ImportEnum single_import_enum = 23;
  91. // Defined in unittest_import_public.proto
  92. protobuf_unittest_import.PublicImportMessage
  93. single_public_import_message = 26;
  94. // Repeated
  95. repeated int32 repeated_int32 = 31;
  96. repeated int64 repeated_int64 = 32;
  97. repeated uint32 repeated_uint32 = 33;
  98. repeated uint64 repeated_uint64 = 34;
  99. repeated sint32 repeated_sint32 = 35;
  100. repeated sint64 repeated_sint64 = 36;
  101. repeated fixed32 repeated_fixed32 = 37;
  102. repeated fixed64 repeated_fixed64 = 38;
  103. repeated sfixed32 repeated_sfixed32 = 39;
  104. repeated sfixed64 repeated_sfixed64 = 40;
  105. repeated float repeated_float = 41;
  106. repeated double repeated_double = 42;
  107. repeated bool repeated_bool = 43;
  108. repeated string repeated_string = 44;
  109. repeated bytes repeated_bytes = 45;
  110. repeated NestedMessage repeated_nested_message = 48;
  111. repeated ForeignMessage repeated_foreign_message = 49;
  112. repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
  113. repeated NestedEnum repeated_nested_enum = 51;
  114. repeated ForeignEnum repeated_foreign_enum = 52;
  115. repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
  116. // Defined in unittest_import_public.proto
  117. repeated protobuf_unittest_import.PublicImportMessage
  118. repeated_public_import_message = 54;
  119. // For oneof test
  120. oneof oneof_field {
  121. uint32 oneof_uint32 = 111;
  122. NestedMessage oneof_nested_message = 112;
  123. string oneof_string = 113;
  124. bytes oneof_bytes = 114;
  125. }
  126. }
  127. // This proto includes a recusively nested message.
  128. message NestedTestAllTypes {
  129. NestedTestAllTypes child = 1;
  130. TestAllTypes payload = 2;
  131. repeated NestedTestAllTypes repeated_child = 3;
  132. }
  133. message TestDeprecatedFields {
  134. int32 deprecated_int32 = 1 [deprecated=true];
  135. }
  136. // Define these after TestAllTypes to make sure the compiler can handle
  137. // that.
  138. message ForeignMessage {
  139. int32 c = 1;
  140. }
  141. enum ForeignEnum {
  142. FOREIGN_UNSPECIFIED = 0;
  143. FOREIGN_FOO = 4;
  144. FOREIGN_BAR = 5;
  145. FOREIGN_BAZ = 6;
  146. }
  147. message TestReservedFields {
  148. reserved 2, 15, 9 to 11;
  149. reserved "bar", "baz";
  150. }
  151. // Test that we can use NestedMessage from outside TestAllTypes.
  152. message TestForeignNested {
  153. TestAllTypes.NestedMessage foreign_nested = 1;
  154. }
  155. // Test that really large tag numbers don't break anything.
  156. message TestReallyLargeTagNumber {
  157. // The largest possible tag number is 2^28 - 1, since the wire format uses
  158. // three bits to communicate wire type.
  159. int32 a = 1;
  160. int32 bb = 268435455;
  161. }
  162. message TestRecursiveMessage {
  163. TestRecursiveMessage a = 1;
  164. int32 i = 2;
  165. }
  166. // Test that mutual recursion works.
  167. message TestMutualRecursionA {
  168. TestMutualRecursionB bb = 1;
  169. }
  170. message TestMutualRecursionB {
  171. TestMutualRecursionA a = 1;
  172. int32 optional_int32 = 2;
  173. }
  174. message TestEnumAllowAlias {
  175. TestEnumWithDupValue value = 1;
  176. }
  177. // Test an enum that has multiple values with the same number.
  178. enum TestEnumWithDupValue {
  179. TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0;
  180. option allow_alias = true;
  181. FOO1 = 1;
  182. BAR1 = 2;
  183. BAZ = 3;
  184. FOO2 = 1;
  185. BAR2 = 2;
  186. }
  187. // Test an enum with large, unordered values.
  188. enum TestSparseEnum {
  189. TEST_SPARSE_ENUM_UNSPECIFIED = 0;
  190. SPARSE_A = 123;
  191. SPARSE_B = 62374;
  192. SPARSE_C = 12589234;
  193. SPARSE_D = -15;
  194. SPARSE_E = -53452;
  195. // In proto3, value 0 must be the first one specified
  196. // SPARSE_F = 0;
  197. SPARSE_G = 2;
  198. }
  199. // Test message with CamelCase field names. This violates Protocol Buffer
  200. // standard style.
  201. message TestCamelCaseFieldNames {
  202. int32 PrimitiveField = 1;
  203. string StringField = 2;
  204. ForeignEnum EnumField = 3;
  205. ForeignMessage MessageField = 4;
  206. repeated int32 RepeatedPrimitiveField = 7;
  207. repeated string RepeatedStringField = 8;
  208. repeated ForeignEnum RepeatedEnumField = 9;
  209. repeated ForeignMessage RepeatedMessageField = 10;
  210. }
  211. // We list fields out of order, to ensure that we're using field number and not
  212. // field index to determine serialization order.
  213. message TestFieldOrderings {
  214. string my_string = 11;
  215. int64 my_int = 1;
  216. float my_float = 101;
  217. message NestedMessage {
  218. int64 oo = 2;
  219. // The field name "b" fails to compile in proto1 because it conflicts with
  220. // a local variable named "b" in one of the generated methods. Doh.
  221. // This file needs to compile in proto1 to test backwards-compatibility.
  222. int32 bb = 1;
  223. }
  224. NestedMessage single_nested_message = 200;
  225. }
  226. message SparseEnumMessage {
  227. TestSparseEnum sparse_enum = 1;
  228. }
  229. // Test String and Bytes: string is for valid UTF-8 strings
  230. message OneString {
  231. string data = 1;
  232. }
  233. message MoreString {
  234. repeated string data = 1;
  235. }
  236. message OneBytes {
  237. bytes data = 1;
  238. }
  239. message MoreBytes {
  240. bytes data = 1;
  241. }
  242. // Test int32, uint32, int64, uint64, and bool are all compatible
  243. message Int32Message {
  244. int32 data = 1;
  245. }
  246. message Uint32Message {
  247. uint32 data = 1;
  248. }
  249. message Int64Message {
  250. int64 data = 1;
  251. }
  252. message Uint64Message {
  253. uint64 data = 1;
  254. }
  255. message BoolMessage {
  256. bool data = 1;
  257. }
  258. // Test oneofs.
  259. message TestOneof {
  260. oneof foo {
  261. int32 foo_int = 1;
  262. string foo_string = 2;
  263. TestAllTypes foo_message = 3;
  264. }
  265. }
  266. // Test messages for packed fields
  267. message TestPackedTypes {
  268. repeated int32 packed_int32 = 90 [packed = true];
  269. repeated int64 packed_int64 = 91 [packed = true];
  270. repeated uint32 packed_uint32 = 92 [packed = true];
  271. repeated uint64 packed_uint64 = 93 [packed = true];
  272. repeated sint32 packed_sint32 = 94 [packed = true];
  273. repeated sint64 packed_sint64 = 95 [packed = true];
  274. repeated fixed32 packed_fixed32 = 96 [packed = true];
  275. repeated fixed64 packed_fixed64 = 97 [packed = true];
  276. repeated sfixed32 packed_sfixed32 = 98 [packed = true];
  277. repeated sfixed64 packed_sfixed64 = 99 [packed = true];
  278. repeated float packed_float = 100 [packed = true];
  279. repeated double packed_double = 101 [packed = true];
  280. repeated bool packed_bool = 102 [packed = true];
  281. repeated ForeignEnum packed_enum = 103 [packed = true];
  282. }
  283. // A message with the same fields as TestPackedTypes, but without packing. Used
  284. // to test packed <-> unpacked wire compatibility.
  285. message TestUnpackedTypes {
  286. repeated int32 unpacked_int32 = 90 [packed = false];
  287. repeated int64 unpacked_int64 = 91 [packed = false];
  288. repeated uint32 unpacked_uint32 = 92 [packed = false];
  289. repeated uint64 unpacked_uint64 = 93 [packed = false];
  290. repeated sint32 unpacked_sint32 = 94 [packed = false];
  291. repeated sint64 unpacked_sint64 = 95 [packed = false];
  292. repeated fixed32 unpacked_fixed32 = 96 [packed = false];
  293. repeated fixed64 unpacked_fixed64 = 97 [packed = false];
  294. repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
  295. repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
  296. repeated float unpacked_float = 100 [packed = false];
  297. repeated double unpacked_double = 101 [packed = false];
  298. repeated bool unpacked_bool = 102 [packed = false];
  299. repeated ForeignEnum unpacked_enum = 103 [packed = false];
  300. }
  301. message TestRepeatedScalarDifferentTagSizes {
  302. // Parsing repeated fixed size values used to fail. This message needs to be
  303. // used in order to get a tag of the right size; all of the repeated fields
  304. // in TestAllTypes didn't trigger the check.
  305. repeated fixed32 repeated_fixed32 = 12;
  306. // Check for a varint type, just for good measure.
  307. repeated int32 repeated_int32 = 13;
  308. // These have two-byte tags.
  309. repeated fixed64 repeated_fixed64 = 2046;
  310. repeated int64 repeated_int64 = 2047;
  311. // Three byte tags.
  312. repeated float repeated_float = 262142;
  313. repeated uint64 repeated_uint64 = 262143;
  314. }
  315. message TestCommentInjectionMessage {
  316. // */ <- This should not close the generated doc comment
  317. string a = 1;
  318. }
  319. // Test that RPC services work.
  320. message FooRequest {}
  321. message FooResponse {}
  322. message FooClientMessage {}
  323. message FooServerMessage{}
  324. service TestService {
  325. rpc Foo(FooRequest) returns (FooResponse);
  326. rpc Bar(BarRequest) returns (BarResponse);
  327. }
  328. message BarRequest {}
  329. message BarResponse {}