unittest.proto 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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. //
  36. // LINT: ALLOW_GROUPS, LEGACY_NAMES
  37. syntax = "proto2";
  38. // Some generic_services option(s) added automatically.
  39. // See: http://go/proto2-generic-services-default
  40. option cc_generic_services = true; // auto-added
  41. option java_generic_services = true; // auto-added
  42. option py_generic_services = true; // auto-added
  43. option cc_enable_arenas = true;
  44. import "unittest_import.proto";
  45. // We don't put this in a package within proto2 because we need to make sure
  46. // that the generated code doesn't depend on being in the proto2 namespace.
  47. // In test_util.h we do "using namespace unittest = protobuf_unittest".
  48. package protobuf_unittest_proto2;
  49. // Protos optimized for SPEED use a strict superset of the generated code
  50. // of equivalent ones optimized for CODE_SIZE, so we should optimize all our
  51. // tests for speed unless explicitly testing code size optimization.
  52. option optimize_for = SPEED;
  53. option csharp_namespace = "Google.Protobuf.TestProtos.Proto2";
  54. // This proto includes every type of field in both singular and repeated
  55. // forms.
  56. message TestAllTypes {
  57. message NestedMessage {
  58. // The field name "b" fails to compile in proto1 because it conflicts with
  59. // a local variable named "b" in one of the generated methods. Doh.
  60. // This file needs to compile in proto1 to test backwards-compatibility.
  61. optional int32 bb = 1;
  62. }
  63. enum NestedEnum {
  64. FOO = 1;
  65. BAR = 2;
  66. BAZ = 3;
  67. NEG = -1; // Intentionally negative.
  68. }
  69. // Singular
  70. optional int32 optional_int32 = 1;
  71. optional int64 optional_int64 = 2;
  72. optional uint32 optional_uint32 = 3;
  73. optional uint64 optional_uint64 = 4;
  74. optional sint32 optional_sint32 = 5;
  75. optional sint64 optional_sint64 = 6;
  76. optional fixed32 optional_fixed32 = 7;
  77. optional fixed64 optional_fixed64 = 8;
  78. optional sfixed32 optional_sfixed32 = 9;
  79. optional sfixed64 optional_sfixed64 = 10;
  80. optional float optional_float = 11;
  81. optional double optional_double = 12;
  82. optional bool optional_bool = 13;
  83. optional string optional_string = 14;
  84. optional bytes optional_bytes = 15;
  85. optional group OptionalGroup = 16 {
  86. optional int32 a = 17;
  87. }
  88. optional NestedMessage optional_nested_message = 18;
  89. optional ForeignMessage optional_foreign_message = 19;
  90. optional protobuf_unittest_import_proto2.ImportMessage optional_import_message = 20;
  91. optional NestedEnum optional_nested_enum = 21;
  92. optional ForeignEnum optional_foreign_enum = 22;
  93. optional protobuf_unittest_import_proto2.ImportEnum optional_import_enum = 23;
  94. optional string optional_string_piece = 24 [ctype=STRING_PIECE];
  95. optional string optional_cord = 25 [ctype=CORD];
  96. // Defined in unittest_import_public.proto
  97. optional protobuf_unittest_import_proto2.PublicImportMessage
  98. optional_public_import_message = 26;
  99. optional NestedMessage optional_lazy_message = 27 [lazy=true];
  100. // Repeated
  101. repeated int32 repeated_int32 = 31;
  102. repeated int64 repeated_int64 = 32;
  103. repeated uint32 repeated_uint32 = 33;
  104. repeated uint64 repeated_uint64 = 34;
  105. repeated sint32 repeated_sint32 = 35;
  106. repeated sint64 repeated_sint64 = 36;
  107. repeated fixed32 repeated_fixed32 = 37;
  108. repeated fixed64 repeated_fixed64 = 38;
  109. repeated sfixed32 repeated_sfixed32 = 39;
  110. repeated sfixed64 repeated_sfixed64 = 40;
  111. repeated float repeated_float = 41;
  112. repeated double repeated_double = 42;
  113. repeated bool repeated_bool = 43;
  114. repeated string repeated_string = 44;
  115. repeated bytes repeated_bytes = 45;
  116. repeated group RepeatedGroup = 46 {
  117. optional int32 a = 47;
  118. }
  119. repeated NestedMessage repeated_nested_message = 48;
  120. repeated ForeignMessage repeated_foreign_message = 49;
  121. repeated protobuf_unittest_import_proto2.ImportMessage repeated_import_message = 50;
  122. repeated NestedEnum repeated_nested_enum = 51;
  123. repeated ForeignEnum repeated_foreign_enum = 52;
  124. repeated protobuf_unittest_import_proto2.ImportEnum repeated_import_enum = 53;
  125. repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
  126. repeated string repeated_cord = 55 [ctype=CORD];
  127. repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
  128. // Singular with defaults
  129. optional int32 default_int32 = 61 [default = 41 ];
  130. optional int64 default_int64 = 62 [default = 42 ];
  131. optional uint32 default_uint32 = 63 [default = 43 ];
  132. optional uint64 default_uint64 = 64 [default = 44 ];
  133. optional sint32 default_sint32 = 65 [default = -45 ];
  134. optional sint64 default_sint64 = 66 [default = 46 ];
  135. optional fixed32 default_fixed32 = 67 [default = 47 ];
  136. optional fixed64 default_fixed64 = 68 [default = 48 ];
  137. optional sfixed32 default_sfixed32 = 69 [default = 49 ];
  138. optional sfixed64 default_sfixed64 = 70 [default = -50 ];
  139. optional float default_float = 71 [default = 51.5 ];
  140. optional double default_double = 72 [default = 52e3 ];
  141. optional bool default_bool = 73 [default = true ];
  142. optional string default_string = 74 [default = "hello"];
  143. optional bytes default_bytes = 75 [default = "world"];
  144. optional NestedEnum default_nested_enum = 81 [default = BAR ];
  145. optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
  146. optional protobuf_unittest_import_proto2.ImportEnum
  147. default_import_enum = 83 [default = IMPORT_BAR];
  148. optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
  149. optional string default_cord = 85 [ctype=CORD,default="123"];
  150. // For oneof test
  151. oneof oneof_field {
  152. uint32 oneof_uint32 = 111;
  153. NestedMessage oneof_nested_message = 112;
  154. string oneof_string = 113;
  155. bytes oneof_bytes = 114;
  156. }
  157. }
  158. // This proto includes a recursively nested message.
  159. message NestedTestAllTypes {
  160. optional NestedTestAllTypes child = 1;
  161. optional TestAllTypes payload = 2;
  162. repeated NestedTestAllTypes repeated_child = 3;
  163. }
  164. message TestDeprecatedFields {
  165. optional int32 deprecated_int32 = 1 [deprecated=true];
  166. oneof oneof_fields {
  167. int32 deprecated_int32_in_oneof = 2 [deprecated=true];
  168. }
  169. }
  170. message TestDeprecatedMessage {
  171. option deprecated = true;
  172. }
  173. // Define these after TestAllTypes to make sure the compiler can handle
  174. // that.
  175. message ForeignMessage {
  176. optional int32 c = 1;
  177. optional int32 d = 2;
  178. }
  179. enum ForeignEnum {
  180. FOREIGN_FOO = 4;
  181. FOREIGN_BAR = 5;
  182. FOREIGN_BAZ = 6;
  183. }
  184. message TestReservedFields {
  185. reserved 2, 15, 9 to 11;
  186. reserved "bar", "baz";
  187. }
  188. message TestAllExtensions {
  189. extensions 1 to max;
  190. }
  191. extend TestAllExtensions {
  192. // Singular
  193. optional int32 optional_int32_extension = 1;
  194. optional int64 optional_int64_extension = 2;
  195. optional uint32 optional_uint32_extension = 3;
  196. optional uint64 optional_uint64_extension = 4;
  197. optional sint32 optional_sint32_extension = 5;
  198. optional sint64 optional_sint64_extension = 6;
  199. optional fixed32 optional_fixed32_extension = 7;
  200. optional fixed64 optional_fixed64_extension = 8;
  201. optional sfixed32 optional_sfixed32_extension = 9;
  202. optional sfixed64 optional_sfixed64_extension = 10;
  203. optional float optional_float_extension = 11;
  204. optional double optional_double_extension = 12;
  205. optional bool optional_bool_extension = 13;
  206. optional string optional_string_extension = 14;
  207. optional bytes optional_bytes_extension = 15;
  208. optional group OptionalGroup_extension = 16 {
  209. optional int32 a = 17;
  210. }
  211. optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
  212. optional ForeignMessage optional_foreign_message_extension = 19;
  213. optional protobuf_unittest_import_proto2.ImportMessage
  214. optional_import_message_extension = 20;
  215. optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
  216. optional ForeignEnum optional_foreign_enum_extension = 22;
  217. optional protobuf_unittest_import_proto2.ImportEnum
  218. optional_import_enum_extension = 23;
  219. optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
  220. optional string optional_cord_extension = 25 [ctype=CORD];
  221. optional protobuf_unittest_import_proto2.PublicImportMessage
  222. optional_public_import_message_extension = 26;
  223. optional TestAllTypes.NestedMessage
  224. optional_lazy_message_extension = 27 [lazy=true];
  225. // Repeated
  226. repeated int32 repeated_int32_extension = 31;
  227. repeated int64 repeated_int64_extension = 32;
  228. repeated uint32 repeated_uint32_extension = 33;
  229. repeated uint64 repeated_uint64_extension = 34;
  230. repeated sint32 repeated_sint32_extension = 35;
  231. repeated sint64 repeated_sint64_extension = 36;
  232. repeated fixed32 repeated_fixed32_extension = 37;
  233. repeated fixed64 repeated_fixed64_extension = 38;
  234. repeated sfixed32 repeated_sfixed32_extension = 39;
  235. repeated sfixed64 repeated_sfixed64_extension = 40;
  236. repeated float repeated_float_extension = 41;
  237. repeated double repeated_double_extension = 42;
  238. repeated bool repeated_bool_extension = 43;
  239. repeated string repeated_string_extension = 44;
  240. repeated bytes repeated_bytes_extension = 45;
  241. repeated group RepeatedGroup_extension = 46 {
  242. optional int32 a = 47;
  243. }
  244. repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
  245. repeated ForeignMessage repeated_foreign_message_extension = 49;
  246. repeated protobuf_unittest_import_proto2.ImportMessage
  247. repeated_import_message_extension = 50;
  248. repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
  249. repeated ForeignEnum repeated_foreign_enum_extension = 52;
  250. repeated protobuf_unittest_import_proto2.ImportEnum
  251. repeated_import_enum_extension = 53;
  252. repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
  253. repeated string repeated_cord_extension = 55 [ctype=CORD];
  254. repeated TestAllTypes.NestedMessage
  255. repeated_lazy_message_extension = 57 [lazy=true];
  256. // Singular with defaults
  257. optional int32 default_int32_extension = 61 [default = 41 ];
  258. optional int64 default_int64_extension = 62 [default = 42 ];
  259. optional uint32 default_uint32_extension = 63 [default = 43 ];
  260. optional uint64 default_uint64_extension = 64 [default = 44 ];
  261. optional sint32 default_sint32_extension = 65 [default = -45 ];
  262. optional sint64 default_sint64_extension = 66 [default = 46 ];
  263. optional fixed32 default_fixed32_extension = 67 [default = 47 ];
  264. optional fixed64 default_fixed64_extension = 68 [default = 48 ];
  265. optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];
  266. optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];
  267. optional float default_float_extension = 71 [default = 51.5 ];
  268. optional double default_double_extension = 72 [default = 52e3 ];
  269. optional bool default_bool_extension = 73 [default = true ];
  270. optional string default_string_extension = 74 [default = "hello"];
  271. optional bytes default_bytes_extension = 75 [default = "world"];
  272. optional TestAllTypes.NestedEnum
  273. default_nested_enum_extension = 81 [default = BAR];
  274. optional ForeignEnum
  275. default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
  276. optional protobuf_unittest_import_proto2.ImportEnum
  277. default_import_enum_extension = 83 [default = IMPORT_BAR];
  278. optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
  279. default="abc"];
  280. optional string default_cord_extension = 85 [ctype=CORD, default="123"];
  281. // For oneof test
  282. optional uint32 oneof_uint32_extension = 111;
  283. optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112;
  284. optional string oneof_string_extension = 113;
  285. optional bytes oneof_bytes_extension = 114;
  286. }
  287. message TestGroup {
  288. optional group OptionalGroup = 16 {
  289. optional int32 a = 17;
  290. }
  291. optional ForeignEnum optional_foreign_enum = 22;
  292. }
  293. message TestGroupExtension {
  294. extensions 1 to max;
  295. }
  296. message TestNestedExtension {
  297. extend TestAllExtensions {
  298. // Check for bug where string extensions declared in tested scope did not
  299. // compile.
  300. optional string test = 1002 [default="test"];
  301. // Used to test if generated extension name is correct when there are
  302. // underscores.
  303. optional string nested_string_extension = 1003;
  304. }
  305. extend TestGroupExtension {
  306. optional group OptionalGroup_extension = 16 {
  307. optional int32 a = 17;
  308. }
  309. optional ForeignEnum optional_foreign_enum_extension = 22;
  310. }
  311. }
  312. // We have separate messages for testing required fields because it's
  313. // annoying to have to fill in required fields in TestProto in order to
  314. // do anything with it. Note that we don't need to test every type of
  315. // required filed because the code output is basically identical to
  316. // optional fields for all types.
  317. message TestRequired {
  318. required int32 a = 1;
  319. optional int32 dummy2 = 2;
  320. required int32 b = 3;
  321. extend TestAllExtensions {
  322. optional TestRequired single = 1000;
  323. repeated TestRequired multi = 1001;
  324. }
  325. // Pad the field count to 32 so that we can test that IsInitialized()
  326. // properly checks multiple elements of has_bits_.
  327. optional int32 dummy4 = 4;
  328. optional int32 dummy5 = 5;
  329. optional int32 dummy6 = 6;
  330. optional int32 dummy7 = 7;
  331. optional int32 dummy8 = 8;
  332. optional int32 dummy9 = 9;
  333. optional int32 dummy10 = 10;
  334. optional int32 dummy11 = 11;
  335. optional int32 dummy12 = 12;
  336. optional int32 dummy13 = 13;
  337. optional int32 dummy14 = 14;
  338. optional int32 dummy15 = 15;
  339. optional int32 dummy16 = 16;
  340. optional int32 dummy17 = 17;
  341. optional int32 dummy18 = 18;
  342. optional int32 dummy19 = 19;
  343. optional int32 dummy20 = 20;
  344. optional int32 dummy21 = 21;
  345. optional int32 dummy22 = 22;
  346. optional int32 dummy23 = 23;
  347. optional int32 dummy24 = 24;
  348. optional int32 dummy25 = 25;
  349. optional int32 dummy26 = 26;
  350. optional int32 dummy27 = 27;
  351. optional int32 dummy28 = 28;
  352. optional int32 dummy29 = 29;
  353. optional int32 dummy30 = 30;
  354. optional int32 dummy31 = 31;
  355. optional int32 dummy32 = 32;
  356. required int32 c = 33;
  357. }
  358. message TestRequiredForeign {
  359. optional TestRequired optional_message = 1;
  360. repeated TestRequired repeated_message = 2;
  361. optional int32 dummy = 3;
  362. }
  363. message TestRequiredMessage {
  364. optional TestRequired optional_message = 1;
  365. repeated TestRequired repeated_message = 2;
  366. required TestRequired required_message = 3;
  367. }
  368. // Test that we can use NestedMessage from outside TestAllTypes.
  369. message TestForeignNested {
  370. optional TestAllTypes.NestedMessage foreign_nested = 1;
  371. }
  372. // TestEmptyMessage is used to test unknown field support.
  373. message TestEmptyMessage {
  374. }
  375. // Like above, but declare all field numbers as potential extensions. No
  376. // actual extensions should ever be defined for this type.
  377. message TestEmptyMessageWithExtensions {
  378. extensions 1 to max;
  379. }
  380. message TestMultipleExtensionRanges {
  381. extensions 42;
  382. extensions 4143 to 4243;
  383. extensions 65536 to max;
  384. }
  385. // Test that really large tag numbers don't break anything.
  386. message TestReallyLargeTagNumber {
  387. // The largest possible tag number is 2^28 - 1, since the wire format uses
  388. // three bits to communicate wire type.
  389. optional int32 a = 1;
  390. optional int32 bb = 268435455;
  391. }
  392. message TestRecursiveMessage {
  393. optional TestRecursiveMessage a = 1;
  394. optional int32 i = 2;
  395. }
  396. // Test that mutual recursion works.
  397. message TestMutualRecursionA {
  398. message SubMessage {
  399. optional TestMutualRecursionB b = 1;
  400. }
  401. optional TestMutualRecursionB bb = 1;
  402. optional group SubGroup = 2 {
  403. optional SubMessage sub_message = 3; // Needed because of bug in javatest
  404. optional TestAllTypes not_in_this_scc = 4;
  405. }
  406. }
  407. message TestMutualRecursionB {
  408. optional TestMutualRecursionA a = 1;
  409. optional int32 optional_int32 = 2;
  410. }
  411. message TestIsInitialized {
  412. message SubMessage {
  413. optional group SubGroup = 1 {
  414. required int32 i = 2;
  415. }
  416. }
  417. optional SubMessage sub_message = 1;
  418. }
  419. // Test that groups have disjoint field numbers from their siblings and
  420. // parents. This is NOT possible in proto1; only google.protobuf. When attempting
  421. // to compile with proto1, this will emit an error; so we only include it
  422. // in protobuf_unittest_proto.
  423. message TestDupFieldNumber { // NO_PROTO1
  424. optional int32 a = 1; // NO_PROTO1
  425. optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1
  426. optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1
  427. } // NO_PROTO1
  428. // Additional messages for testing lazy fields.
  429. message TestEagerMessage {
  430. optional TestAllTypes sub_message = 1 [lazy=false];
  431. }
  432. message TestLazyMessage {
  433. optional TestAllTypes sub_message = 1 [lazy=true];
  434. }
  435. // Needed for a Python test.
  436. message TestNestedMessageHasBits {
  437. message NestedMessage {
  438. repeated int32 nestedmessage_repeated_int32 = 1;
  439. repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
  440. }
  441. optional NestedMessage optional_nested_message = 1;
  442. }
  443. // Test an enum that has multiple values with the same number.
  444. enum TestEnumWithDupValue {
  445. option allow_alias = true;
  446. FOO1 = 1;
  447. BAR1 = 2;
  448. BAZ = 3;
  449. FOO2 = 1;
  450. BAR2 = 2;
  451. }
  452. // Test an enum with large, unordered values.
  453. enum TestSparseEnum {
  454. SPARSE_A = 123;
  455. SPARSE_B = 62374;
  456. SPARSE_C = 12589234;
  457. SPARSE_D = -15;
  458. SPARSE_E = -53452;
  459. SPARSE_F = 0;
  460. SPARSE_G = 2;
  461. }
  462. // Test message with CamelCase field names. This violates Protocol Buffer
  463. // standard style.
  464. message TestCamelCaseFieldNames {
  465. optional int32 PrimitiveField = 1;
  466. optional string StringField = 2;
  467. optional ForeignEnum EnumField = 3;
  468. optional ForeignMessage MessageField = 4;
  469. optional string StringPieceField = 5 [ctype=STRING_PIECE];
  470. optional string CordField = 6 [ctype=CORD];
  471. repeated int32 RepeatedPrimitiveField = 7;
  472. repeated string RepeatedStringField = 8;
  473. repeated ForeignEnum RepeatedEnumField = 9;
  474. repeated ForeignMessage RepeatedMessageField = 10;
  475. repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
  476. repeated string RepeatedCordField = 12 [ctype=CORD];
  477. }
  478. // We list fields out of order, to ensure that we're using field number and not
  479. // field index to determine serialization order.
  480. message TestFieldOrderings {
  481. optional string my_string = 11;
  482. extensions 2 to 10;
  483. optional int64 my_int = 1;
  484. extensions 12 to 100;
  485. optional float my_float = 101;
  486. message NestedMessage {
  487. optional int64 oo = 2;
  488. // The field name "b" fails to compile in proto1 because it conflicts with
  489. // a local variable named "b" in one of the generated methods. Doh.
  490. // This file needs to compile in proto1 to test backwards-compatibility.
  491. optional int32 bb = 1;
  492. }
  493. optional NestedMessage optional_nested_message = 200;
  494. }
  495. extend TestFieldOrderings {
  496. optional string my_extension_string = 50;
  497. optional int32 my_extension_int = 5;
  498. }
  499. message TestExtensionOrderings1 {
  500. extend TestFieldOrderings {
  501. optional TestExtensionOrderings1 test_ext_orderings1 = 13;
  502. }
  503. optional string my_string = 1;
  504. }
  505. message TestExtensionOrderings2 {
  506. extend TestFieldOrderings {
  507. optional TestExtensionOrderings2 test_ext_orderings2 = 12;
  508. }
  509. message TestExtensionOrderings3 {
  510. extend TestFieldOrderings {
  511. optional TestExtensionOrderings3 test_ext_orderings3 = 14;
  512. }
  513. optional string my_string = 1;
  514. }
  515. optional string my_string = 1;
  516. }
  517. message TestExtremeDefaultValues {
  518. optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
  519. optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
  520. optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
  521. optional int32 small_int32 = 4 [default = -0x7FFFFFFF];
  522. optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];
  523. optional int32 really_small_int32 = 21 [default = -0x80000000];
  524. optional int64 really_small_int64 = 22 [default = -0x8000000000000000];
  525. // The default value here is UTF-8 for "\u1234". (We could also just type
  526. // the UTF-8 text directly into this text file rather than escape it, but
  527. // lots of people use editors that would be confused by this.)
  528. optional string utf8_string = 6 [default = "\341\210\264"];
  529. // Tests for single-precision floating-point values.
  530. optional float zero_float = 7 [default = 0];
  531. optional float one_float = 8 [default = 1];
  532. optional float small_float = 9 [default = 1.5];
  533. optional float negative_one_float = 10 [default = -1];
  534. optional float negative_float = 11 [default = -1.5];
  535. // Using exponents
  536. optional float large_float = 12 [default = 2E8];
  537. optional float small_negative_float = 13 [default = -8e-28];
  538. // Text for nonfinite floating-point values.
  539. optional double inf_double = 14 [default = inf];
  540. optional double neg_inf_double = 15 [default = -inf];
  541. optional double nan_double = 16 [default = nan];
  542. optional float inf_float = 17 [default = inf];
  543. optional float neg_inf_float = 18 [default = -inf];
  544. optional float nan_float = 19 [default = nan];
  545. // Tests for C++ trigraphs.
  546. // Trigraphs should be escaped in C++ generated files, but they should not be
  547. // escaped for other languages.
  548. // Note that in .proto file, "\?" is a valid way to escape ? in string
  549. // literals.
  550. optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
  551. // String defaults containing the character '\000'
  552. optional string string_with_zero = 23 [default = "hel\000lo"];
  553. optional bytes bytes_with_zero = 24 [default = "wor\000ld"];
  554. optional string string_piece_with_zero = 25 [ctype=STRING_PIECE,
  555. default="ab\000c"];
  556. optional string cord_with_zero = 26 [ctype=CORD,
  557. default="12\0003"];
  558. optional string replacement_string = 27 [default="${unknown}"];
  559. }
  560. message SparseEnumMessage {
  561. optional TestSparseEnum sparse_enum = 1;
  562. }
  563. // Test String and Bytes: string is for valid UTF-8 strings
  564. message OneString {
  565. optional string data = 1;
  566. }
  567. message MoreString {
  568. repeated string data = 1;
  569. }
  570. message OneBytes {
  571. optional bytes data = 1;
  572. }
  573. message MoreBytes {
  574. repeated bytes data = 1;
  575. }
  576. // Test int32, uint32, int64, uint64, and bool are all compatible
  577. message Int32Message {
  578. optional int32 data = 1;
  579. }
  580. message Uint32Message {
  581. optional uint32 data = 1;
  582. }
  583. message Int64Message {
  584. optional int64 data = 1;
  585. }
  586. message Uint64Message {
  587. optional uint64 data = 1;
  588. }
  589. message BoolMessage {
  590. optional bool data = 1;
  591. }
  592. // Test oneofs.
  593. message TestOneof {
  594. oneof foo {
  595. int32 foo_int = 1;
  596. string foo_string = 2;
  597. TestAllTypes foo_message = 3;
  598. group FooGroup = 4 {
  599. optional int32 a = 5;
  600. optional string b = 6;
  601. }
  602. }
  603. }
  604. message TestOneofBackwardsCompatible {
  605. optional int32 foo_int = 1;
  606. optional string foo_string = 2;
  607. optional TestAllTypes foo_message = 3;
  608. optional group FooGroup = 4 {
  609. optional int32 a = 5;
  610. optional string b = 6;
  611. }
  612. }
  613. message TestOneof2 {
  614. oneof foo {
  615. int32 foo_int = 1;
  616. string foo_string = 2;
  617. string foo_cord = 3 [ctype=CORD];
  618. string foo_string_piece = 4 [ctype=STRING_PIECE];
  619. bytes foo_bytes = 5;
  620. NestedEnum foo_enum = 6;
  621. NestedMessage foo_message = 7;
  622. group FooGroup = 8 {
  623. optional int32 a = 9;
  624. optional string b = 10;
  625. }
  626. NestedMessage foo_lazy_message = 11 [lazy=true];
  627. }
  628. oneof bar {
  629. int32 bar_int = 12 [default = 5];
  630. string bar_string = 13 [default = "STRING"];
  631. string bar_cord = 14 [ctype=CORD, default = "CORD"];
  632. string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"];
  633. bytes bar_bytes = 16 [default = "BYTES"];
  634. NestedEnum bar_enum = 17 [default = BAR];
  635. }
  636. optional int32 baz_int = 18;
  637. optional string baz_string = 19 [default = "BAZ"];
  638. message NestedMessage {
  639. optional int64 qux_int = 1;
  640. repeated int32 corge_int = 2;
  641. }
  642. enum NestedEnum {
  643. FOO = 1;
  644. BAR = 2;
  645. BAZ = 3;
  646. }
  647. }
  648. message TestRequiredOneof {
  649. oneof foo {
  650. int32 foo_int = 1;
  651. string foo_string = 2;
  652. NestedMessage foo_message = 3;
  653. }
  654. message NestedMessage {
  655. required double required_double = 1;
  656. }
  657. }
  658. message TestRequiredMap {
  659. map<int32, NestedMessage> foo = 1;
  660. message NestedMessage {
  661. required int32 required_int32 = 1;
  662. }
  663. }
  664. // Test messages for packed fields
  665. message TestPackedTypes {
  666. repeated int32 packed_int32 = 90 [packed = true];
  667. repeated int64 packed_int64 = 91 [packed = true];
  668. repeated uint32 packed_uint32 = 92 [packed = true];
  669. repeated uint64 packed_uint64 = 93 [packed = true];
  670. repeated sint32 packed_sint32 = 94 [packed = true];
  671. repeated sint64 packed_sint64 = 95 [packed = true];
  672. repeated fixed32 packed_fixed32 = 96 [packed = true];
  673. repeated fixed64 packed_fixed64 = 97 [packed = true];
  674. repeated sfixed32 packed_sfixed32 = 98 [packed = true];
  675. repeated sfixed64 packed_sfixed64 = 99 [packed = true];
  676. repeated float packed_float = 100 [packed = true];
  677. repeated double packed_double = 101 [packed = true];
  678. repeated bool packed_bool = 102 [packed = true];
  679. repeated ForeignEnum packed_enum = 103 [packed = true];
  680. }
  681. // A message with the same fields as TestPackedTypes, but without packing. Used
  682. // to test packed <-> unpacked wire compatibility.
  683. message TestUnpackedTypes {
  684. repeated int32 unpacked_int32 = 90 [packed = false];
  685. repeated int64 unpacked_int64 = 91 [packed = false];
  686. repeated uint32 unpacked_uint32 = 92 [packed = false];
  687. repeated uint64 unpacked_uint64 = 93 [packed = false];
  688. repeated sint32 unpacked_sint32 = 94 [packed = false];
  689. repeated sint64 unpacked_sint64 = 95 [packed = false];
  690. repeated fixed32 unpacked_fixed32 = 96 [packed = false];
  691. repeated fixed64 unpacked_fixed64 = 97 [packed = false];
  692. repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
  693. repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
  694. repeated float unpacked_float = 100 [packed = false];
  695. repeated double unpacked_double = 101 [packed = false];
  696. repeated bool unpacked_bool = 102 [packed = false];
  697. repeated ForeignEnum unpacked_enum = 103 [packed = false];
  698. }
  699. message TestPackedExtensions {
  700. extensions 1 to max;
  701. }
  702. extend TestPackedExtensions {
  703. repeated int32 packed_int32_extension = 90 [packed = true];
  704. repeated int64 packed_int64_extension = 91 [packed = true];
  705. repeated uint32 packed_uint32_extension = 92 [packed = true];
  706. repeated uint64 packed_uint64_extension = 93 [packed = true];
  707. repeated sint32 packed_sint32_extension = 94 [packed = true];
  708. repeated sint64 packed_sint64_extension = 95 [packed = true];
  709. repeated fixed32 packed_fixed32_extension = 96 [packed = true];
  710. repeated fixed64 packed_fixed64_extension = 97 [packed = true];
  711. repeated sfixed32 packed_sfixed32_extension = 98 [packed = true];
  712. repeated sfixed64 packed_sfixed64_extension = 99 [packed = true];
  713. repeated float packed_float_extension = 100 [packed = true];
  714. repeated double packed_double_extension = 101 [packed = true];
  715. repeated bool packed_bool_extension = 102 [packed = true];
  716. repeated ForeignEnum packed_enum_extension = 103 [packed = true];
  717. }
  718. message TestUnpackedExtensions {
  719. extensions 1 to max;
  720. }
  721. extend TestUnpackedExtensions {
  722. repeated int32 unpacked_int32_extension = 90 [packed = false];
  723. repeated int64 unpacked_int64_extension = 91 [packed = false];
  724. repeated uint32 unpacked_uint32_extension = 92 [packed = false];
  725. repeated uint64 unpacked_uint64_extension = 93 [packed = false];
  726. repeated sint32 unpacked_sint32_extension = 94 [packed = false];
  727. repeated sint64 unpacked_sint64_extension = 95 [packed = false];
  728. repeated fixed32 unpacked_fixed32_extension = 96 [packed = false];
  729. repeated fixed64 unpacked_fixed64_extension = 97 [packed = false];
  730. repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false];
  731. repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false];
  732. repeated float unpacked_float_extension = 100 [packed = false];
  733. repeated double unpacked_double_extension = 101 [packed = false];
  734. repeated bool unpacked_bool_extension = 102 [packed = false];
  735. repeated ForeignEnum unpacked_enum_extension = 103 [packed = false];
  736. }
  737. // Used by ExtensionSetTest/DynamicExtensions. The test actually builds
  738. // a set of extensions to TestAllExtensions dynamically, based on the fields
  739. // of this message type.
  740. message TestDynamicExtensions {
  741. enum DynamicEnumType {
  742. DYNAMIC_FOO = 2200;
  743. DYNAMIC_BAR = 2201;
  744. DYNAMIC_BAZ = 2202;
  745. }
  746. message DynamicMessageType {
  747. optional int32 dynamic_field = 2100;
  748. }
  749. optional fixed32 scalar_extension = 2000;
  750. optional ForeignEnum enum_extension = 2001;
  751. optional DynamicEnumType dynamic_enum_extension = 2002;
  752. optional ForeignMessage message_extension = 2003;
  753. optional DynamicMessageType dynamic_message_extension = 2004;
  754. repeated string repeated_extension = 2005;
  755. repeated sint32 packed_extension = 2006 [packed = true];
  756. }
  757. message TestRepeatedScalarDifferentTagSizes {
  758. // Parsing repeated fixed size values used to fail. This message needs to be
  759. // used in order to get a tag of the right size; all of the repeated fields
  760. // in TestAllTypes didn't trigger the check.
  761. repeated fixed32 repeated_fixed32 = 12;
  762. // Check for a varint type, just for good measure.
  763. repeated int32 repeated_int32 = 13;
  764. // These have two-byte tags.
  765. repeated fixed64 repeated_fixed64 = 2046;
  766. repeated int64 repeated_int64 = 2047;
  767. // Three byte tags.
  768. repeated float repeated_float = 262142;
  769. repeated uint64 repeated_uint64 = 262143;
  770. }
  771. // Test that if an optional or required message/group field appears multiple
  772. // times in the input, they need to be merged.
  773. message TestParsingMerge {
  774. // RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
  775. // except that all fields are repeated. In the tests, we will serialize the
  776. // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
  777. // Repeated fields in RepeatedFieldsGenerator are expected to be merged into
  778. // the corresponding required/optional fields in TestParsingMerge.
  779. message RepeatedFieldsGenerator {
  780. repeated TestAllTypes field1 = 1;
  781. repeated TestAllTypes field2 = 2;
  782. repeated TestAllTypes field3 = 3;
  783. repeated group Group1 = 10 {
  784. optional TestAllTypes field1 = 11;
  785. }
  786. repeated group Group2 = 20 {
  787. optional TestAllTypes field1 = 21;
  788. }
  789. repeated TestAllTypes ext1 = 1000;
  790. repeated TestAllTypes ext2 = 1001;
  791. }
  792. required TestAllTypes required_all_types = 1;
  793. optional TestAllTypes optional_all_types = 2;
  794. repeated TestAllTypes repeated_all_types = 3;
  795. optional group OptionalGroup = 10 {
  796. optional TestAllTypes optional_group_all_types = 11;
  797. }
  798. repeated group RepeatedGroup = 20 {
  799. optional TestAllTypes repeated_group_all_types = 21;
  800. }
  801. extensions 1000 to max;
  802. extend TestParsingMerge {
  803. optional TestAllTypes optional_ext = 1000;
  804. repeated TestAllTypes repeated_ext = 1001;
  805. }
  806. }
  807. message TestCommentInjectionMessage {
  808. // */ <- This should not close the generated doc comment
  809. optional string a = 1 [default="*/ <- Neither should this."];
  810. }
  811. // Test that RPC services work.
  812. message FooRequest {}
  813. message FooResponse {}
  814. message FooClientMessage {}
  815. message FooServerMessage{}
  816. service TestService {
  817. rpc Foo(FooRequest) returns (FooResponse);
  818. rpc Bar(BarRequest) returns (BarResponse);
  819. }
  820. message BarRequest {}
  821. message BarResponse {}
  822. message TestJsonName {
  823. optional int32 field_name1 = 1;
  824. optional int32 fieldName2 = 2;
  825. optional int32 FieldName3 = 3;
  826. optional int32 _field_name4 = 4;
  827. optional int32 FIELD_NAME5 = 5;
  828. optional int32 field_name6 = 6 [json_name = "@type"];
  829. }
  830. message TestHugeFieldNumbers {
  831. optional int32 optional_int32 = 536870000;
  832. optional int32 fixed_32 = 536870001;
  833. repeated int32 repeated_int32 = 536870002 [packed = false];
  834. repeated int32 packed_int32 = 536870003 [packed = true];
  835. optional ForeignEnum optional_enum = 536870004;
  836. optional string optional_string = 536870005;
  837. optional bytes optional_bytes = 536870006;
  838. optional ForeignMessage optional_message = 536870007;
  839. optional group OptionalGroup = 536870008 {
  840. optional int32 group_a = 536870009;
  841. }
  842. map<string, string> string_string_map = 536870010;
  843. oneof oneof_field {
  844. uint32 oneof_uint32 = 536870011;
  845. TestAllTypes oneof_test_all_types = 536870012;
  846. string oneof_string = 536870013;
  847. bytes oneof_bytes = 536870014;
  848. }
  849. extensions 536860000 to 536869999;
  850. }
  851. extend TestHugeFieldNumbers {
  852. optional TestAllTypes test_all_types = 536860000;
  853. }
  854. message TestExtensionInsideTable {
  855. optional int32 field1 = 1;
  856. optional int32 field2 = 2;
  857. optional int32 field3 = 3;
  858. optional int32 field4 = 4;
  859. extensions 5 to 5;
  860. optional int32 field6 = 6;
  861. optional int32 field7 = 7;
  862. optional int32 field8 = 8;
  863. optional int32 field9 = 9;
  864. optional int32 field10 = 10;
  865. }
  866. extend TestExtensionInsideTable {
  867. optional int32 test_extension_inside_table_extension = 5;
  868. }
  869. enum VeryLargeEnum {
  870. ENUM_LABEL_DEFAULT = 0;
  871. ENUM_LABEL_1 = 1;
  872. ENUM_LABEL_2 = 2;
  873. ENUM_LABEL_3 = 3;
  874. ENUM_LABEL_4 = 4;
  875. ENUM_LABEL_5 = 5;
  876. ENUM_LABEL_6 = 6;
  877. ENUM_LABEL_7 = 7;
  878. ENUM_LABEL_8 = 8;
  879. ENUM_LABEL_9 = 9;
  880. ENUM_LABEL_10 = 10;
  881. ENUM_LABEL_11 = 11;
  882. ENUM_LABEL_12 = 12;
  883. ENUM_LABEL_13 = 13;
  884. ENUM_LABEL_14 = 14;
  885. ENUM_LABEL_15 = 15;
  886. ENUM_LABEL_16 = 16;
  887. ENUM_LABEL_17 = 17;
  888. ENUM_LABEL_18 = 18;
  889. ENUM_LABEL_19 = 19;
  890. ENUM_LABEL_20 = 20;
  891. ENUM_LABEL_21 = 21;
  892. ENUM_LABEL_22 = 22;
  893. ENUM_LABEL_23 = 23;
  894. ENUM_LABEL_24 = 24;
  895. ENUM_LABEL_25 = 25;
  896. ENUM_LABEL_26 = 26;
  897. ENUM_LABEL_27 = 27;
  898. ENUM_LABEL_28 = 28;
  899. ENUM_LABEL_29 = 29;
  900. ENUM_LABEL_30 = 30;
  901. ENUM_LABEL_31 = 31;
  902. ENUM_LABEL_32 = 32;
  903. ENUM_LABEL_33 = 33;
  904. ENUM_LABEL_34 = 34;
  905. ENUM_LABEL_35 = 35;
  906. ENUM_LABEL_36 = 36;
  907. ENUM_LABEL_37 = 37;
  908. ENUM_LABEL_38 = 38;
  909. ENUM_LABEL_39 = 39;
  910. ENUM_LABEL_40 = 40;
  911. ENUM_LABEL_41 = 41;
  912. ENUM_LABEL_42 = 42;
  913. ENUM_LABEL_43 = 43;
  914. ENUM_LABEL_44 = 44;
  915. ENUM_LABEL_45 = 45;
  916. ENUM_LABEL_46 = 46;
  917. ENUM_LABEL_47 = 47;
  918. ENUM_LABEL_48 = 48;
  919. ENUM_LABEL_49 = 49;
  920. ENUM_LABEL_50 = 50;
  921. ENUM_LABEL_51 = 51;
  922. ENUM_LABEL_52 = 52;
  923. ENUM_LABEL_53 = 53;
  924. ENUM_LABEL_54 = 54;
  925. ENUM_LABEL_55 = 55;
  926. ENUM_LABEL_56 = 56;
  927. ENUM_LABEL_57 = 57;
  928. ENUM_LABEL_58 = 58;
  929. ENUM_LABEL_59 = 59;
  930. ENUM_LABEL_60 = 60;
  931. ENUM_LABEL_61 = 61;
  932. ENUM_LABEL_62 = 62;
  933. ENUM_LABEL_63 = 63;
  934. ENUM_LABEL_64 = 64;
  935. ENUM_LABEL_65 = 65;
  936. ENUM_LABEL_66 = 66;
  937. ENUM_LABEL_67 = 67;
  938. ENUM_LABEL_68 = 68;
  939. ENUM_LABEL_69 = 69;
  940. ENUM_LABEL_70 = 70;
  941. ENUM_LABEL_71 = 71;
  942. ENUM_LABEL_72 = 72;
  943. ENUM_LABEL_73 = 73;
  944. ENUM_LABEL_74 = 74;
  945. ENUM_LABEL_75 = 75;
  946. ENUM_LABEL_76 = 76;
  947. ENUM_LABEL_77 = 77;
  948. ENUM_LABEL_78 = 78;
  949. ENUM_LABEL_79 = 79;
  950. ENUM_LABEL_80 = 80;
  951. ENUM_LABEL_81 = 81;
  952. ENUM_LABEL_82 = 82;
  953. ENUM_LABEL_83 = 83;
  954. ENUM_LABEL_84 = 84;
  955. ENUM_LABEL_85 = 85;
  956. ENUM_LABEL_86 = 86;
  957. ENUM_LABEL_87 = 87;
  958. ENUM_LABEL_88 = 88;
  959. ENUM_LABEL_89 = 89;
  960. ENUM_LABEL_90 = 90;
  961. ENUM_LABEL_91 = 91;
  962. ENUM_LABEL_92 = 92;
  963. ENUM_LABEL_93 = 93;
  964. ENUM_LABEL_94 = 94;
  965. ENUM_LABEL_95 = 95;
  966. ENUM_LABEL_96 = 96;
  967. ENUM_LABEL_97 = 97;
  968. ENUM_LABEL_98 = 98;
  969. ENUM_LABEL_99 = 99;
  970. ENUM_LABEL_100 = 100;
  971. };