unittest_proto3.proto 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. option csharp_namespace = "Google.Protobuf.TestProtos";
  37. // Only present so we can test that we can read it (as an example
  38. // of a non-C# option)
  39. option java_outer_classname = "UnittestProto";
  40. import "unittest_import_proto3.proto";
  41. package protobuf_unittest3;
  42. // This proto includes every type of field in both singular and repeated
  43. // forms.
  44. message TestAllTypes {
  45. message NestedMessage {
  46. // The field name "b" fails to compile in proto1 because it conflicts with
  47. // a local variable named "b" in one of the generated methods. Doh.
  48. // This file needs to compile in proto1 to test backwards-compatibility.
  49. int32 bb = 1;
  50. }
  51. enum NestedEnum {
  52. NESTED_ENUM_UNSPECIFIED = 0;
  53. FOO = 1;
  54. BAR = 2;
  55. BAZ = 3;
  56. NEG = -1; // Intentionally negative.
  57. }
  58. // Singular
  59. int32 single_int32 = 1;
  60. int64 single_int64 = 2;
  61. uint32 single_uint32 = 3;
  62. uint64 single_uint64 = 4;
  63. sint32 single_sint32 = 5;
  64. sint64 single_sint64 = 6;
  65. fixed32 single_fixed32 = 7;
  66. fixed64 single_fixed64 = 8;
  67. sfixed32 single_sfixed32 = 9;
  68. sfixed64 single_sfixed64 = 10;
  69. float single_float = 11;
  70. double single_double = 12;
  71. bool single_bool = 13;
  72. string single_string = 14;
  73. bytes single_bytes = 15;
  74. NestedMessage single_nested_message = 18;
  75. ForeignMessage single_foreign_message = 19;
  76. protobuf_unittest_import.ImportMessage single_import_message = 20;
  77. NestedEnum single_nested_enum = 21;
  78. ForeignEnum single_foreign_enum = 22;
  79. protobuf_unittest_import.ImportEnum single_import_enum = 23;
  80. // Defined in unittest_import_public.proto
  81. protobuf_unittest_import.PublicImportMessage
  82. single_public_import_message = 26;
  83. // Repeated
  84. repeated int32 repeated_int32 = 31;
  85. repeated int64 repeated_int64 = 32;
  86. repeated uint32 repeated_uint32 = 33;
  87. repeated uint64 repeated_uint64 = 34;
  88. repeated sint32 repeated_sint32 = 35;
  89. repeated sint64 repeated_sint64 = 36;
  90. repeated fixed32 repeated_fixed32 = 37;
  91. repeated fixed64 repeated_fixed64 = 38;
  92. repeated sfixed32 repeated_sfixed32 = 39;
  93. repeated sfixed64 repeated_sfixed64 = 40;
  94. repeated float repeated_float = 41;
  95. repeated double repeated_double = 42;
  96. repeated bool repeated_bool = 43;
  97. repeated string repeated_string = 44;
  98. repeated bytes repeated_bytes = 45;
  99. repeated NestedMessage repeated_nested_message = 48;
  100. repeated ForeignMessage repeated_foreign_message = 49;
  101. repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
  102. repeated NestedEnum repeated_nested_enum = 51;
  103. repeated ForeignEnum repeated_foreign_enum = 52;
  104. repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
  105. // Defined in unittest_import_public.proto
  106. repeated protobuf_unittest_import.PublicImportMessage
  107. repeated_public_import_message = 54;
  108. // For oneof test
  109. oneof oneof_field {
  110. uint32 oneof_uint32 = 111;
  111. NestedMessage oneof_nested_message = 112;
  112. string oneof_string = 113;
  113. bytes oneof_bytes = 114;
  114. }
  115. }
  116. // This proto includes a recursively nested message.
  117. message NestedTestAllTypes {
  118. NestedTestAllTypes child = 1;
  119. TestAllTypes payload = 2;
  120. repeated NestedTestAllTypes repeated_child = 3;
  121. }
  122. message TestDeprecatedFields {
  123. int32 deprecated_int32 = 1 [deprecated=true];
  124. }
  125. // Define these after TestAllTypes to make sure the compiler can handle
  126. // that.
  127. message ForeignMessage {
  128. int32 c = 1;
  129. }
  130. enum ForeignEnum {
  131. FOREIGN_UNSPECIFIED = 0;
  132. FOREIGN_FOO = 4;
  133. FOREIGN_BAR = 5;
  134. FOREIGN_BAZ = 6;
  135. }
  136. message TestReservedFields {
  137. reserved 2, 15, 9 to 11;
  138. reserved "bar", "baz";
  139. }
  140. // Test that we can use NestedMessage from outside TestAllTypes.
  141. message TestForeignNested {
  142. TestAllTypes.NestedMessage foreign_nested = 1;
  143. }
  144. // Test that really large tag numbers don't break anything.
  145. message TestReallyLargeTagNumber {
  146. // The largest possible tag number is 2^28 - 1, since the wire format uses
  147. // three bits to communicate wire type.
  148. int32 a = 1;
  149. int32 bb = 268435455;
  150. }
  151. message TestRecursiveMessage {
  152. TestRecursiveMessage a = 1;
  153. int32 i = 2;
  154. }
  155. // Test that mutual recursion works.
  156. message TestMutualRecursionA {
  157. TestMutualRecursionB bb = 1;
  158. }
  159. message TestMutualRecursionB {
  160. TestMutualRecursionA a = 1;
  161. int32 optional_int32 = 2;
  162. }
  163. message TestEnumAllowAlias {
  164. TestEnumWithDupValue value = 1;
  165. }
  166. // Test an enum that has multiple values with the same number.
  167. enum TestEnumWithDupValue {
  168. TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0;
  169. option allow_alias = true;
  170. FOO1 = 1;
  171. BAR1 = 2;
  172. BAZ = 3;
  173. FOO2 = 1;
  174. BAR2 = 2;
  175. }
  176. // Test an enum with large, unordered values.
  177. enum TestSparseEnum {
  178. TEST_SPARSE_ENUM_UNSPECIFIED = 0;
  179. SPARSE_A = 123;
  180. SPARSE_B = 62374;
  181. SPARSE_C = 12589234;
  182. SPARSE_D = -15;
  183. SPARSE_E = -53452;
  184. // In proto3, value 0 must be the first one specified
  185. // SPARSE_F = 0;
  186. SPARSE_G = 2;
  187. }
  188. // Test message with CamelCase field names. This violates Protocol Buffer
  189. // standard style.
  190. message TestCamelCaseFieldNames {
  191. int32 PrimitiveField = 1;
  192. string StringField = 2;
  193. ForeignEnum EnumField = 3;
  194. ForeignMessage MessageField = 4;
  195. repeated int32 RepeatedPrimitiveField = 7;
  196. repeated string RepeatedStringField = 8;
  197. repeated ForeignEnum RepeatedEnumField = 9;
  198. repeated ForeignMessage RepeatedMessageField = 10;
  199. }
  200. // We list fields out of order, to ensure that we're using field number and not
  201. // field index to determine serialization order.
  202. message TestFieldOrderings {
  203. string my_string = 11;
  204. int64 my_int = 1;
  205. float my_float = 101;
  206. message NestedMessage {
  207. int64 oo = 2;
  208. // The field name "b" fails to compile in proto1 because it conflicts with
  209. // a local variable named "b" in one of the generated methods. Doh.
  210. // This file needs to compile in proto1 to test backwards-compatibility.
  211. int32 bb = 1;
  212. }
  213. NestedMessage single_nested_message = 200;
  214. }
  215. message SparseEnumMessage {
  216. TestSparseEnum sparse_enum = 1;
  217. }
  218. // Test String and Bytes: string is for valid UTF-8 strings
  219. message OneString {
  220. string data = 1;
  221. }
  222. message MoreString {
  223. repeated string data = 1;
  224. }
  225. message OneBytes {
  226. bytes data = 1;
  227. }
  228. message MoreBytes {
  229. bytes data = 1;
  230. }
  231. // Test int32, uint32, int64, uint64, and bool are all compatible
  232. message Int32Message {
  233. int32 data = 1;
  234. }
  235. message Uint32Message {
  236. uint32 data = 1;
  237. }
  238. message Int64Message {
  239. int64 data = 1;
  240. }
  241. message Uint64Message {
  242. uint64 data = 1;
  243. }
  244. message BoolMessage {
  245. bool data = 1;
  246. }
  247. // Test oneofs.
  248. message TestOneof {
  249. oneof foo {
  250. int32 foo_int = 1;
  251. string foo_string = 2;
  252. TestAllTypes foo_message = 3;
  253. }
  254. }
  255. // Test messages for packed fields
  256. message TestPackedTypes {
  257. repeated int32 packed_int32 = 90 [packed = true];
  258. repeated int64 packed_int64 = 91 [packed = true];
  259. repeated uint32 packed_uint32 = 92 [packed = true];
  260. repeated uint64 packed_uint64 = 93 [packed = true];
  261. repeated sint32 packed_sint32 = 94 [packed = true];
  262. repeated sint64 packed_sint64 = 95 [packed = true];
  263. repeated fixed32 packed_fixed32 = 96 [packed = true];
  264. repeated fixed64 packed_fixed64 = 97 [packed = true];
  265. repeated sfixed32 packed_sfixed32 = 98 [packed = true];
  266. repeated sfixed64 packed_sfixed64 = 99 [packed = true];
  267. repeated float packed_float = 100 [packed = true];
  268. repeated double packed_double = 101 [packed = true];
  269. repeated bool packed_bool = 102 [packed = true];
  270. repeated ForeignEnum packed_enum = 103 [packed = true];
  271. }
  272. // A message with the same fields as TestPackedTypes, but without packing. Used
  273. // to test packed <-> unpacked wire compatibility.
  274. message TestUnpackedTypes {
  275. repeated int32 unpacked_int32 = 90 [packed = false];
  276. repeated int64 unpacked_int64 = 91 [packed = false];
  277. repeated uint32 unpacked_uint32 = 92 [packed = false];
  278. repeated uint64 unpacked_uint64 = 93 [packed = false];
  279. repeated sint32 unpacked_sint32 = 94 [packed = false];
  280. repeated sint64 unpacked_sint64 = 95 [packed = false];
  281. repeated fixed32 unpacked_fixed32 = 96 [packed = false];
  282. repeated fixed64 unpacked_fixed64 = 97 [packed = false];
  283. repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
  284. repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
  285. repeated float unpacked_float = 100 [packed = false];
  286. repeated double unpacked_double = 101 [packed = false];
  287. repeated bool unpacked_bool = 102 [packed = false];
  288. repeated ForeignEnum unpacked_enum = 103 [packed = false];
  289. }
  290. message TestRepeatedScalarDifferentTagSizes {
  291. // Parsing repeated fixed size values used to fail. This message needs to be
  292. // used in order to get a tag of the right size; all of the repeated fields
  293. // in TestAllTypes didn't trigger the check.
  294. repeated fixed32 repeated_fixed32 = 12;
  295. // Check for a varint type, just for good measure.
  296. repeated int32 repeated_int32 = 13;
  297. // These have two-byte tags.
  298. repeated fixed64 repeated_fixed64 = 2046;
  299. repeated int64 repeated_int64 = 2047;
  300. // Three byte tags.
  301. repeated float repeated_float = 262142;
  302. repeated uint64 repeated_uint64 = 262143;
  303. }
  304. message TestCommentInjectionMessage {
  305. // */ <- This should not close the generated doc comment
  306. string a = 1;
  307. }
  308. // Test that RPC services work.
  309. message FooRequest {}
  310. message FooResponse {}
  311. message FooClientMessage {}
  312. message FooServerMessage{}
  313. // This is a test service
  314. service TestService {
  315. // This is a test method
  316. rpc Foo(FooRequest) returns (FooResponse);
  317. rpc Bar(BarRequest) returns (BarResponse);
  318. }
  319. message BarRequest {}
  320. message BarResponse {}
  321. message TestEmptyMessage {}
  322. // This is leading detached comment 1
  323. // This is leading detached comment 2
  324. // This is a leading comment
  325. message CommentMessage {
  326. // Leading nested message comment
  327. message NestedCommentMessage {
  328. // Leading nested message field comment
  329. string nested_text = 1;
  330. }
  331. // Leading nested enum comment
  332. enum NestedCommentEnum {
  333. // Zero value comment
  334. ZERO_VALUE = 0;
  335. }
  336. // Leading field comment
  337. string text = 1; // Trailing field comment
  338. }
  339. // Leading enum comment
  340. enum CommentEnum {
  341. // Zero value comment
  342. ZERO_VALUE = 0;
  343. }