test_util_lite.cc 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  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. #include <google/protobuf/test_util_lite.h>
  34. #include <google/protobuf/stubs/logging.h>
  35. #include <google/protobuf/stubs/common.h>
  36. #include <gtest/gtest.h>
  37. namespace google {
  38. namespace protobuf {
  39. void TestUtilLite::SetAllFields(unittest::TestAllTypesLite* message) {
  40. message->set_optional_int32 (101);
  41. message->set_optional_int64 (102);
  42. message->set_optional_uint32 (103);
  43. message->set_optional_uint64 (104);
  44. message->set_optional_sint32 (105);
  45. message->set_optional_sint64 (106);
  46. message->set_optional_fixed32 (107);
  47. message->set_optional_fixed64 (108);
  48. message->set_optional_sfixed32(109);
  49. message->set_optional_sfixed64(110);
  50. message->set_optional_float (111);
  51. message->set_optional_double (112);
  52. message->set_optional_bool (true);
  53. message->set_optional_string ("115");
  54. message->set_optional_bytes ("116");
  55. message->mutable_optionalgroup ()->set_a(117);
  56. message->mutable_optional_nested_message ()->set_bb(118);
  57. message->mutable_optional_foreign_message ()->set_c(119);
  58. message->mutable_optional_import_message ()->set_d(120);
  59. message->mutable_optional_public_import_message()->set_e(126);
  60. message->mutable_optional_lazy_message ()->set_bb(127);
  61. message->set_optional_nested_enum (unittest::TestAllTypesLite::BAZ );
  62. message->set_optional_foreign_enum(unittest::FOREIGN_LITE_BAZ );
  63. message->set_optional_import_enum (unittest_import::IMPORT_LITE_BAZ);
  64. // -----------------------------------------------------------------
  65. message->add_repeated_int32 (201);
  66. message->add_repeated_int64 (202);
  67. message->add_repeated_uint32 (203);
  68. message->add_repeated_uint64 (204);
  69. message->add_repeated_sint32 (205);
  70. message->add_repeated_sint64 (206);
  71. message->add_repeated_fixed32 (207);
  72. message->add_repeated_fixed64 (208);
  73. message->add_repeated_sfixed32(209);
  74. message->add_repeated_sfixed64(210);
  75. message->add_repeated_float (211);
  76. message->add_repeated_double (212);
  77. message->add_repeated_bool (true);
  78. message->add_repeated_string ("215");
  79. message->add_repeated_bytes ("216");
  80. message->add_repeatedgroup ()->set_a(217);
  81. message->add_repeated_nested_message ()->set_bb(218);
  82. message->add_repeated_foreign_message()->set_c(219);
  83. message->add_repeated_import_message ()->set_d(220);
  84. message->add_repeated_lazy_message ()->set_bb(227);
  85. message->add_repeated_nested_enum (unittest::TestAllTypesLite::BAR );
  86. message->add_repeated_foreign_enum(unittest::FOREIGN_LITE_BAR );
  87. message->add_repeated_import_enum (unittest_import::IMPORT_LITE_BAR);
  88. // Add a second one of each field.
  89. message->add_repeated_int32 (301);
  90. message->add_repeated_int64 (302);
  91. message->add_repeated_uint32 (303);
  92. message->add_repeated_uint64 (304);
  93. message->add_repeated_sint32 (305);
  94. message->add_repeated_sint64 (306);
  95. message->add_repeated_fixed32 (307);
  96. message->add_repeated_fixed64 (308);
  97. message->add_repeated_sfixed32(309);
  98. message->add_repeated_sfixed64(310);
  99. message->add_repeated_float (311);
  100. message->add_repeated_double (312);
  101. message->add_repeated_bool (false);
  102. message->add_repeated_string ("315");
  103. message->add_repeated_bytes ("316");
  104. message->add_repeatedgroup ()->set_a(317);
  105. message->add_repeated_nested_message ()->set_bb(318);
  106. message->add_repeated_foreign_message()->set_c(319);
  107. message->add_repeated_import_message ()->set_d(320);
  108. message->add_repeated_lazy_message ()->set_bb(327);
  109. message->add_repeated_nested_enum (unittest::TestAllTypesLite::BAZ );
  110. message->add_repeated_foreign_enum(unittest::FOREIGN_LITE_BAZ );
  111. message->add_repeated_import_enum (unittest_import::IMPORT_LITE_BAZ);
  112. // -----------------------------------------------------------------
  113. message->set_default_int32 (401);
  114. message->set_default_int64 (402);
  115. message->set_default_uint32 (403);
  116. message->set_default_uint64 (404);
  117. message->set_default_sint32 (405);
  118. message->set_default_sint64 (406);
  119. message->set_default_fixed32 (407);
  120. message->set_default_fixed64 (408);
  121. message->set_default_sfixed32(409);
  122. message->set_default_sfixed64(410);
  123. message->set_default_float (411);
  124. message->set_default_double (412);
  125. message->set_default_bool (false);
  126. message->set_default_string ("415");
  127. message->set_default_bytes ("416");
  128. message->set_default_nested_enum (unittest::TestAllTypesLite::FOO );
  129. message->set_default_foreign_enum(unittest::FOREIGN_LITE_FOO );
  130. message->set_default_import_enum (unittest_import::IMPORT_LITE_FOO);
  131. message->set_oneof_uint32(601);
  132. message->mutable_oneof_nested_message()->set_bb(602);
  133. message->set_oneof_string("603");
  134. message->set_oneof_bytes("604");
  135. }
  136. // -------------------------------------------------------------------
  137. void TestUtilLite::ModifyRepeatedFields(unittest::TestAllTypesLite* message) {
  138. message->set_repeated_int32 (1, 501);
  139. message->set_repeated_int64 (1, 502);
  140. message->set_repeated_uint32 (1, 503);
  141. message->set_repeated_uint64 (1, 504);
  142. message->set_repeated_sint32 (1, 505);
  143. message->set_repeated_sint64 (1, 506);
  144. message->set_repeated_fixed32 (1, 507);
  145. message->set_repeated_fixed64 (1, 508);
  146. message->set_repeated_sfixed32(1, 509);
  147. message->set_repeated_sfixed64(1, 510);
  148. message->set_repeated_float (1, 511);
  149. message->set_repeated_double (1, 512);
  150. message->set_repeated_bool (1, true);
  151. message->set_repeated_string (1, "515");
  152. message->set_repeated_bytes (1, "516");
  153. message->mutable_repeatedgroup (1)->set_a(517);
  154. message->mutable_repeated_nested_message (1)->set_bb(518);
  155. message->mutable_repeated_foreign_message(1)->set_c(519);
  156. message->mutable_repeated_import_message (1)->set_d(520);
  157. message->mutable_repeated_lazy_message (1)->set_bb(527);
  158. message->set_repeated_nested_enum (1, unittest::TestAllTypesLite::FOO );
  159. message->set_repeated_foreign_enum(1, unittest::FOREIGN_LITE_FOO );
  160. message->set_repeated_import_enum (1, unittest_import::IMPORT_LITE_FOO);
  161. }
  162. // -------------------------------------------------------------------
  163. void TestUtilLite::ExpectAllFieldsSet(
  164. const unittest::TestAllTypesLite& message) {
  165. EXPECT_TRUE(message.has_optional_int32 ());
  166. EXPECT_TRUE(message.has_optional_int64 ());
  167. EXPECT_TRUE(message.has_optional_uint32 ());
  168. EXPECT_TRUE(message.has_optional_uint64 ());
  169. EXPECT_TRUE(message.has_optional_sint32 ());
  170. EXPECT_TRUE(message.has_optional_sint64 ());
  171. EXPECT_TRUE(message.has_optional_fixed32 ());
  172. EXPECT_TRUE(message.has_optional_fixed64 ());
  173. EXPECT_TRUE(message.has_optional_sfixed32());
  174. EXPECT_TRUE(message.has_optional_sfixed64());
  175. EXPECT_TRUE(message.has_optional_float ());
  176. EXPECT_TRUE(message.has_optional_double ());
  177. EXPECT_TRUE(message.has_optional_bool ());
  178. EXPECT_TRUE(message.has_optional_string ());
  179. EXPECT_TRUE(message.has_optional_bytes ());
  180. EXPECT_TRUE(message.has_optionalgroup ());
  181. EXPECT_TRUE(message.has_optional_nested_message ());
  182. EXPECT_TRUE(message.has_optional_foreign_message ());
  183. EXPECT_TRUE(message.has_optional_import_message ());
  184. EXPECT_TRUE(message.has_optional_public_import_message());
  185. EXPECT_TRUE(message.has_optional_lazy_message ());
  186. EXPECT_TRUE(message.optionalgroup ().has_a());
  187. EXPECT_TRUE(message.optional_nested_message ().has_bb());
  188. EXPECT_TRUE(message.optional_foreign_message ().has_c());
  189. EXPECT_TRUE(message.optional_import_message ().has_d());
  190. EXPECT_TRUE(message.optional_public_import_message().has_e());
  191. EXPECT_TRUE(message.optional_lazy_message ().has_bb());
  192. EXPECT_TRUE(message.has_optional_nested_enum ());
  193. EXPECT_TRUE(message.has_optional_foreign_enum());
  194. EXPECT_TRUE(message.has_optional_import_enum ());
  195. EXPECT_EQ(101 , message.optional_int32 ());
  196. EXPECT_EQ(102 , message.optional_int64 ());
  197. EXPECT_EQ(103 , message.optional_uint32 ());
  198. EXPECT_EQ(104 , message.optional_uint64 ());
  199. EXPECT_EQ(105 , message.optional_sint32 ());
  200. EXPECT_EQ(106 , message.optional_sint64 ());
  201. EXPECT_EQ(107 , message.optional_fixed32 ());
  202. EXPECT_EQ(108 , message.optional_fixed64 ());
  203. EXPECT_EQ(109 , message.optional_sfixed32());
  204. EXPECT_EQ(110 , message.optional_sfixed64());
  205. EXPECT_EQ(111 , message.optional_float ());
  206. EXPECT_EQ(112 , message.optional_double ());
  207. EXPECT_EQ(true , message.optional_bool ());
  208. EXPECT_EQ("115", message.optional_string ());
  209. EXPECT_EQ("116", message.optional_bytes ());
  210. EXPECT_EQ(117, message.optionalgroup ().a());
  211. EXPECT_EQ(118, message.optional_nested_message ().bb());
  212. EXPECT_EQ(119, message.optional_foreign_message ().c());
  213. EXPECT_EQ(120, message.optional_import_message ().d());
  214. EXPECT_EQ(126, message.optional_public_import_message().e());
  215. EXPECT_EQ(127, message.optional_lazy_message ().bb());
  216. EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.optional_nested_enum ());
  217. EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.optional_foreign_enum());
  218. EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.optional_import_enum ());
  219. // -----------------------------------------------------------------
  220. ASSERT_EQ(2, message.repeated_int32_size ());
  221. ASSERT_EQ(2, message.repeated_int64_size ());
  222. ASSERT_EQ(2, message.repeated_uint32_size ());
  223. ASSERT_EQ(2, message.repeated_uint64_size ());
  224. ASSERT_EQ(2, message.repeated_sint32_size ());
  225. ASSERT_EQ(2, message.repeated_sint64_size ());
  226. ASSERT_EQ(2, message.repeated_fixed32_size ());
  227. ASSERT_EQ(2, message.repeated_fixed64_size ());
  228. ASSERT_EQ(2, message.repeated_sfixed32_size());
  229. ASSERT_EQ(2, message.repeated_sfixed64_size());
  230. ASSERT_EQ(2, message.repeated_float_size ());
  231. ASSERT_EQ(2, message.repeated_double_size ());
  232. ASSERT_EQ(2, message.repeated_bool_size ());
  233. ASSERT_EQ(2, message.repeated_string_size ());
  234. ASSERT_EQ(2, message.repeated_bytes_size ());
  235. ASSERT_EQ(2, message.repeatedgroup_size ());
  236. ASSERT_EQ(2, message.repeated_nested_message_size ());
  237. ASSERT_EQ(2, message.repeated_foreign_message_size());
  238. ASSERT_EQ(2, message.repeated_import_message_size ());
  239. ASSERT_EQ(2, message.repeated_lazy_message_size ());
  240. ASSERT_EQ(2, message.repeated_nested_enum_size ());
  241. ASSERT_EQ(2, message.repeated_foreign_enum_size ());
  242. ASSERT_EQ(2, message.repeated_import_enum_size ());
  243. EXPECT_EQ(201 , message.repeated_int32 (0));
  244. EXPECT_EQ(202 , message.repeated_int64 (0));
  245. EXPECT_EQ(203 , message.repeated_uint32 (0));
  246. EXPECT_EQ(204 , message.repeated_uint64 (0));
  247. EXPECT_EQ(205 , message.repeated_sint32 (0));
  248. EXPECT_EQ(206 , message.repeated_sint64 (0));
  249. EXPECT_EQ(207 , message.repeated_fixed32 (0));
  250. EXPECT_EQ(208 , message.repeated_fixed64 (0));
  251. EXPECT_EQ(209 , message.repeated_sfixed32(0));
  252. EXPECT_EQ(210 , message.repeated_sfixed64(0));
  253. EXPECT_EQ(211 , message.repeated_float (0));
  254. EXPECT_EQ(212 , message.repeated_double (0));
  255. EXPECT_EQ(true , message.repeated_bool (0));
  256. EXPECT_EQ("215", message.repeated_string (0));
  257. EXPECT_EQ("216", message.repeated_bytes (0));
  258. EXPECT_EQ(217, message.repeatedgroup (0).a());
  259. EXPECT_EQ(218, message.repeated_nested_message (0).bb());
  260. EXPECT_EQ(219, message.repeated_foreign_message(0).c());
  261. EXPECT_EQ(220, message.repeated_import_message (0).d());
  262. EXPECT_EQ(227, message.repeated_lazy_message (0).bb());
  263. EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.repeated_nested_enum (0));
  264. EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.repeated_foreign_enum(0));
  265. EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.repeated_import_enum (0));
  266. EXPECT_EQ(301 , message.repeated_int32 (1));
  267. EXPECT_EQ(302 , message.repeated_int64 (1));
  268. EXPECT_EQ(303 , message.repeated_uint32 (1));
  269. EXPECT_EQ(304 , message.repeated_uint64 (1));
  270. EXPECT_EQ(305 , message.repeated_sint32 (1));
  271. EXPECT_EQ(306 , message.repeated_sint64 (1));
  272. EXPECT_EQ(307 , message.repeated_fixed32 (1));
  273. EXPECT_EQ(308 , message.repeated_fixed64 (1));
  274. EXPECT_EQ(309 , message.repeated_sfixed32(1));
  275. EXPECT_EQ(310 , message.repeated_sfixed64(1));
  276. EXPECT_EQ(311 , message.repeated_float (1));
  277. EXPECT_EQ(312 , message.repeated_double (1));
  278. EXPECT_EQ(false, message.repeated_bool (1));
  279. EXPECT_EQ("315", message.repeated_string (1));
  280. EXPECT_EQ("316", message.repeated_bytes (1));
  281. EXPECT_EQ(317, message.repeatedgroup (1).a());
  282. EXPECT_EQ(318, message.repeated_nested_message (1).bb());
  283. EXPECT_EQ(319, message.repeated_foreign_message(1).c());
  284. EXPECT_EQ(320, message.repeated_import_message (1).d());
  285. EXPECT_EQ(327, message.repeated_lazy_message (1).bb());
  286. EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.repeated_nested_enum (1));
  287. EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.repeated_foreign_enum(1));
  288. EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.repeated_import_enum (1));
  289. // -----------------------------------------------------------------
  290. EXPECT_TRUE(message.has_default_int32 ());
  291. EXPECT_TRUE(message.has_default_int64 ());
  292. EXPECT_TRUE(message.has_default_uint32 ());
  293. EXPECT_TRUE(message.has_default_uint64 ());
  294. EXPECT_TRUE(message.has_default_sint32 ());
  295. EXPECT_TRUE(message.has_default_sint64 ());
  296. EXPECT_TRUE(message.has_default_fixed32 ());
  297. EXPECT_TRUE(message.has_default_fixed64 ());
  298. EXPECT_TRUE(message.has_default_sfixed32());
  299. EXPECT_TRUE(message.has_default_sfixed64());
  300. EXPECT_TRUE(message.has_default_float ());
  301. EXPECT_TRUE(message.has_default_double ());
  302. EXPECT_TRUE(message.has_default_bool ());
  303. EXPECT_TRUE(message.has_default_string ());
  304. EXPECT_TRUE(message.has_default_bytes ());
  305. EXPECT_TRUE(message.has_default_nested_enum ());
  306. EXPECT_TRUE(message.has_default_foreign_enum());
  307. EXPECT_TRUE(message.has_default_import_enum ());
  308. EXPECT_EQ(401 , message.default_int32 ());
  309. EXPECT_EQ(402 , message.default_int64 ());
  310. EXPECT_EQ(403 , message.default_uint32 ());
  311. EXPECT_EQ(404 , message.default_uint64 ());
  312. EXPECT_EQ(405 , message.default_sint32 ());
  313. EXPECT_EQ(406 , message.default_sint64 ());
  314. EXPECT_EQ(407 , message.default_fixed32 ());
  315. EXPECT_EQ(408 , message.default_fixed64 ());
  316. EXPECT_EQ(409 , message.default_sfixed32());
  317. EXPECT_EQ(410 , message.default_sfixed64());
  318. EXPECT_EQ(411 , message.default_float ());
  319. EXPECT_EQ(412 , message.default_double ());
  320. EXPECT_EQ(false, message.default_bool ());
  321. EXPECT_EQ("415", message.default_string ());
  322. EXPECT_EQ("416", message.default_bytes ());
  323. EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.default_nested_enum ());
  324. EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.default_foreign_enum());
  325. EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.default_import_enum ());
  326. EXPECT_FALSE(message.has_oneof_uint32 ());
  327. EXPECT_FALSE(message.has_oneof_nested_message());
  328. EXPECT_FALSE(message.has_oneof_string ());
  329. EXPECT_TRUE(message.has_oneof_bytes ());
  330. EXPECT_EQ("604", message.oneof_bytes());
  331. }
  332. // -------------------------------------------------------------------
  333. void TestUtilLite::ExpectClear(const unittest::TestAllTypesLite& message) {
  334. // has_blah() should initially be false for all optional fields.
  335. EXPECT_FALSE(message.has_optional_int32 ());
  336. EXPECT_FALSE(message.has_optional_int64 ());
  337. EXPECT_FALSE(message.has_optional_uint32 ());
  338. EXPECT_FALSE(message.has_optional_uint64 ());
  339. EXPECT_FALSE(message.has_optional_sint32 ());
  340. EXPECT_FALSE(message.has_optional_sint64 ());
  341. EXPECT_FALSE(message.has_optional_fixed32 ());
  342. EXPECT_FALSE(message.has_optional_fixed64 ());
  343. EXPECT_FALSE(message.has_optional_sfixed32());
  344. EXPECT_FALSE(message.has_optional_sfixed64());
  345. EXPECT_FALSE(message.has_optional_float ());
  346. EXPECT_FALSE(message.has_optional_double ());
  347. EXPECT_FALSE(message.has_optional_bool ());
  348. EXPECT_FALSE(message.has_optional_string ());
  349. EXPECT_FALSE(message.has_optional_bytes ());
  350. EXPECT_FALSE(message.has_optionalgroup ());
  351. EXPECT_FALSE(message.has_optional_nested_message ());
  352. EXPECT_FALSE(message.has_optional_foreign_message ());
  353. EXPECT_FALSE(message.has_optional_import_message ());
  354. EXPECT_FALSE(message.has_optional_public_import_message());
  355. EXPECT_FALSE(message.has_optional_lazy_message ());
  356. EXPECT_FALSE(message.has_optional_nested_enum ());
  357. EXPECT_FALSE(message.has_optional_foreign_enum());
  358. EXPECT_FALSE(message.has_optional_import_enum ());
  359. // Optional fields without defaults are set to zero or something like it.
  360. EXPECT_EQ(0 , message.optional_int32 ());
  361. EXPECT_EQ(0 , message.optional_int64 ());
  362. EXPECT_EQ(0 , message.optional_uint32 ());
  363. EXPECT_EQ(0 , message.optional_uint64 ());
  364. EXPECT_EQ(0 , message.optional_sint32 ());
  365. EXPECT_EQ(0 , message.optional_sint64 ());
  366. EXPECT_EQ(0 , message.optional_fixed32 ());
  367. EXPECT_EQ(0 , message.optional_fixed64 ());
  368. EXPECT_EQ(0 , message.optional_sfixed32());
  369. EXPECT_EQ(0 , message.optional_sfixed64());
  370. EXPECT_EQ(0 , message.optional_float ());
  371. EXPECT_EQ(0 , message.optional_double ());
  372. EXPECT_EQ(false, message.optional_bool ());
  373. EXPECT_EQ("" , message.optional_string ());
  374. EXPECT_EQ("" , message.optional_bytes ());
  375. // Embedded messages should also be clear.
  376. EXPECT_FALSE(message.optionalgroup ().has_a());
  377. EXPECT_FALSE(message.optional_nested_message ().has_bb());
  378. EXPECT_FALSE(message.optional_foreign_message ().has_c());
  379. EXPECT_FALSE(message.optional_import_message ().has_d());
  380. EXPECT_FALSE(message.optional_public_import_message().has_e());
  381. EXPECT_FALSE(message.optional_lazy_message ().has_bb());
  382. EXPECT_EQ(0, message.optionalgroup ().a());
  383. EXPECT_EQ(0, message.optional_nested_message ().bb());
  384. EXPECT_EQ(0, message.optional_foreign_message().c());
  385. EXPECT_EQ(0, message.optional_import_message ().d());
  386. // Enums without defaults are set to the first value in the enum.
  387. EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.optional_nested_enum ());
  388. EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.optional_foreign_enum());
  389. EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.optional_import_enum ());
  390. // Repeated fields are empty.
  391. EXPECT_EQ(0, message.repeated_int32_size ());
  392. EXPECT_EQ(0, message.repeated_int64_size ());
  393. EXPECT_EQ(0, message.repeated_uint32_size ());
  394. EXPECT_EQ(0, message.repeated_uint64_size ());
  395. EXPECT_EQ(0, message.repeated_sint32_size ());
  396. EXPECT_EQ(0, message.repeated_sint64_size ());
  397. EXPECT_EQ(0, message.repeated_fixed32_size ());
  398. EXPECT_EQ(0, message.repeated_fixed64_size ());
  399. EXPECT_EQ(0, message.repeated_sfixed32_size());
  400. EXPECT_EQ(0, message.repeated_sfixed64_size());
  401. EXPECT_EQ(0, message.repeated_float_size ());
  402. EXPECT_EQ(0, message.repeated_double_size ());
  403. EXPECT_EQ(0, message.repeated_bool_size ());
  404. EXPECT_EQ(0, message.repeated_string_size ());
  405. EXPECT_EQ(0, message.repeated_bytes_size ());
  406. EXPECT_EQ(0, message.repeatedgroup_size ());
  407. EXPECT_EQ(0, message.repeated_nested_message_size ());
  408. EXPECT_EQ(0, message.repeated_foreign_message_size());
  409. EXPECT_EQ(0, message.repeated_import_message_size ());
  410. EXPECT_EQ(0, message.repeated_lazy_message_size ());
  411. EXPECT_EQ(0, message.repeated_nested_enum_size ());
  412. EXPECT_EQ(0, message.repeated_foreign_enum_size ());
  413. EXPECT_EQ(0, message.repeated_import_enum_size ());
  414. // has_blah() should also be false for all default fields.
  415. EXPECT_FALSE(message.has_default_int32 ());
  416. EXPECT_FALSE(message.has_default_int64 ());
  417. EXPECT_FALSE(message.has_default_uint32 ());
  418. EXPECT_FALSE(message.has_default_uint64 ());
  419. EXPECT_FALSE(message.has_default_sint32 ());
  420. EXPECT_FALSE(message.has_default_sint64 ());
  421. EXPECT_FALSE(message.has_default_fixed32 ());
  422. EXPECT_FALSE(message.has_default_fixed64 ());
  423. EXPECT_FALSE(message.has_default_sfixed32());
  424. EXPECT_FALSE(message.has_default_sfixed64());
  425. EXPECT_FALSE(message.has_default_float ());
  426. EXPECT_FALSE(message.has_default_double ());
  427. EXPECT_FALSE(message.has_default_bool ());
  428. EXPECT_FALSE(message.has_default_string ());
  429. EXPECT_FALSE(message.has_default_bytes ());
  430. EXPECT_FALSE(message.has_default_nested_enum ());
  431. EXPECT_FALSE(message.has_default_foreign_enum());
  432. EXPECT_FALSE(message.has_default_import_enum ());
  433. // Fields with defaults have their default values (duh).
  434. EXPECT_EQ( 41 , message.default_int32 ());
  435. EXPECT_EQ( 42 , message.default_int64 ());
  436. EXPECT_EQ( 43 , message.default_uint32 ());
  437. EXPECT_EQ( 44 , message.default_uint64 ());
  438. EXPECT_EQ(-45 , message.default_sint32 ());
  439. EXPECT_EQ( 46 , message.default_sint64 ());
  440. EXPECT_EQ( 47 , message.default_fixed32 ());
  441. EXPECT_EQ( 48 , message.default_fixed64 ());
  442. EXPECT_EQ( 49 , message.default_sfixed32());
  443. EXPECT_EQ(-50 , message.default_sfixed64());
  444. EXPECT_EQ( 51.5 , message.default_float ());
  445. EXPECT_EQ( 52e3 , message.default_double ());
  446. EXPECT_EQ(true , message.default_bool ());
  447. EXPECT_EQ("hello", message.default_string ());
  448. EXPECT_EQ("world", message.default_bytes ());
  449. EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.default_nested_enum ());
  450. EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.default_foreign_enum());
  451. EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.default_import_enum ());
  452. EXPECT_FALSE(message.has_oneof_uint32 ());
  453. EXPECT_FALSE(message.has_oneof_nested_message());
  454. EXPECT_FALSE(message.has_oneof_string ());
  455. EXPECT_FALSE(message.has_oneof_bytes ());
  456. }
  457. // -------------------------------------------------------------------
  458. void TestUtilLite::ExpectRepeatedFieldsModified(
  459. const unittest::TestAllTypesLite& message) {
  460. // ModifyRepeatedFields only sets the second repeated element of each
  461. // field. In addition to verifying this, we also verify that the first
  462. // element and size were *not* modified.
  463. ASSERT_EQ(2, message.repeated_int32_size ());
  464. ASSERT_EQ(2, message.repeated_int64_size ());
  465. ASSERT_EQ(2, message.repeated_uint32_size ());
  466. ASSERT_EQ(2, message.repeated_uint64_size ());
  467. ASSERT_EQ(2, message.repeated_sint32_size ());
  468. ASSERT_EQ(2, message.repeated_sint64_size ());
  469. ASSERT_EQ(2, message.repeated_fixed32_size ());
  470. ASSERT_EQ(2, message.repeated_fixed64_size ());
  471. ASSERT_EQ(2, message.repeated_sfixed32_size());
  472. ASSERT_EQ(2, message.repeated_sfixed64_size());
  473. ASSERT_EQ(2, message.repeated_float_size ());
  474. ASSERT_EQ(2, message.repeated_double_size ());
  475. ASSERT_EQ(2, message.repeated_bool_size ());
  476. ASSERT_EQ(2, message.repeated_string_size ());
  477. ASSERT_EQ(2, message.repeated_bytes_size ());
  478. ASSERT_EQ(2, message.repeatedgroup_size ());
  479. ASSERT_EQ(2, message.repeated_nested_message_size ());
  480. ASSERT_EQ(2, message.repeated_foreign_message_size());
  481. ASSERT_EQ(2, message.repeated_import_message_size ());
  482. ASSERT_EQ(2, message.repeated_lazy_message_size ());
  483. ASSERT_EQ(2, message.repeated_nested_enum_size ());
  484. ASSERT_EQ(2, message.repeated_foreign_enum_size ());
  485. ASSERT_EQ(2, message.repeated_import_enum_size ());
  486. EXPECT_EQ(201 , message.repeated_int32 (0));
  487. EXPECT_EQ(202 , message.repeated_int64 (0));
  488. EXPECT_EQ(203 , message.repeated_uint32 (0));
  489. EXPECT_EQ(204 , message.repeated_uint64 (0));
  490. EXPECT_EQ(205 , message.repeated_sint32 (0));
  491. EXPECT_EQ(206 , message.repeated_sint64 (0));
  492. EXPECT_EQ(207 , message.repeated_fixed32 (0));
  493. EXPECT_EQ(208 , message.repeated_fixed64 (0));
  494. EXPECT_EQ(209 , message.repeated_sfixed32(0));
  495. EXPECT_EQ(210 , message.repeated_sfixed64(0));
  496. EXPECT_EQ(211 , message.repeated_float (0));
  497. EXPECT_EQ(212 , message.repeated_double (0));
  498. EXPECT_EQ(true , message.repeated_bool (0));
  499. EXPECT_EQ("215", message.repeated_string (0));
  500. EXPECT_EQ("216", message.repeated_bytes (0));
  501. EXPECT_EQ(217, message.repeatedgroup (0).a());
  502. EXPECT_EQ(218, message.repeated_nested_message (0).bb());
  503. EXPECT_EQ(219, message.repeated_foreign_message(0).c());
  504. EXPECT_EQ(220, message.repeated_import_message (0).d());
  505. EXPECT_EQ(227, message.repeated_lazy_message (0).bb());
  506. EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.repeated_nested_enum (0));
  507. EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.repeated_foreign_enum(0));
  508. EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.repeated_import_enum (0));
  509. // Actually verify the second (modified) elements now.
  510. EXPECT_EQ(501 , message.repeated_int32 (1));
  511. EXPECT_EQ(502 , message.repeated_int64 (1));
  512. EXPECT_EQ(503 , message.repeated_uint32 (1));
  513. EXPECT_EQ(504 , message.repeated_uint64 (1));
  514. EXPECT_EQ(505 , message.repeated_sint32 (1));
  515. EXPECT_EQ(506 , message.repeated_sint64 (1));
  516. EXPECT_EQ(507 , message.repeated_fixed32 (1));
  517. EXPECT_EQ(508 , message.repeated_fixed64 (1));
  518. EXPECT_EQ(509 , message.repeated_sfixed32(1));
  519. EXPECT_EQ(510 , message.repeated_sfixed64(1));
  520. EXPECT_EQ(511 , message.repeated_float (1));
  521. EXPECT_EQ(512 , message.repeated_double (1));
  522. EXPECT_EQ(true , message.repeated_bool (1));
  523. EXPECT_EQ("515", message.repeated_string (1));
  524. EXPECT_EQ("516", message.repeated_bytes (1));
  525. EXPECT_EQ(517, message.repeatedgroup (1).a());
  526. EXPECT_EQ(518, message.repeated_nested_message (1).bb());
  527. EXPECT_EQ(519, message.repeated_foreign_message(1).c());
  528. EXPECT_EQ(520, message.repeated_import_message (1).d());
  529. EXPECT_EQ(527, message.repeated_lazy_message (1).bb());
  530. EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.repeated_nested_enum (1));
  531. EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.repeated_foreign_enum(1));
  532. EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.repeated_import_enum (1));
  533. }
  534. // -------------------------------------------------------------------
  535. void TestUtilLite::SetPackedFields(unittest::TestPackedTypesLite* message) {
  536. message->add_packed_int32 (601);
  537. message->add_packed_int64 (602);
  538. message->add_packed_uint32 (603);
  539. message->add_packed_uint64 (604);
  540. message->add_packed_sint32 (605);
  541. message->add_packed_sint64 (606);
  542. message->add_packed_fixed32 (607);
  543. message->add_packed_fixed64 (608);
  544. message->add_packed_sfixed32(609);
  545. message->add_packed_sfixed64(610);
  546. message->add_packed_float (611);
  547. message->add_packed_double (612);
  548. message->add_packed_bool (true);
  549. message->add_packed_enum (unittest::FOREIGN_LITE_BAR);
  550. // add a second one of each field
  551. message->add_packed_int32 (701);
  552. message->add_packed_int64 (702);
  553. message->add_packed_uint32 (703);
  554. message->add_packed_uint64 (704);
  555. message->add_packed_sint32 (705);
  556. message->add_packed_sint64 (706);
  557. message->add_packed_fixed32 (707);
  558. message->add_packed_fixed64 (708);
  559. message->add_packed_sfixed32(709);
  560. message->add_packed_sfixed64(710);
  561. message->add_packed_float (711);
  562. message->add_packed_double (712);
  563. message->add_packed_bool (false);
  564. message->add_packed_enum (unittest::FOREIGN_LITE_BAZ);
  565. }
  566. // -------------------------------------------------------------------
  567. void TestUtilLite::ModifyPackedFields(unittest::TestPackedTypesLite* message) {
  568. message->set_packed_int32 (1, 801);
  569. message->set_packed_int64 (1, 802);
  570. message->set_packed_uint32 (1, 803);
  571. message->set_packed_uint64 (1, 804);
  572. message->set_packed_sint32 (1, 805);
  573. message->set_packed_sint64 (1, 806);
  574. message->set_packed_fixed32 (1, 807);
  575. message->set_packed_fixed64 (1, 808);
  576. message->set_packed_sfixed32(1, 809);
  577. message->set_packed_sfixed64(1, 810);
  578. message->set_packed_float (1, 811);
  579. message->set_packed_double (1, 812);
  580. message->set_packed_bool (1, true);
  581. message->set_packed_enum (1, unittest::FOREIGN_LITE_FOO);
  582. }
  583. // -------------------------------------------------------------------
  584. void TestUtilLite::ExpectPackedFieldsSet(
  585. const unittest::TestPackedTypesLite& message) {
  586. ASSERT_EQ(2, message.packed_int32_size ());
  587. ASSERT_EQ(2, message.packed_int64_size ());
  588. ASSERT_EQ(2, message.packed_uint32_size ());
  589. ASSERT_EQ(2, message.packed_uint64_size ());
  590. ASSERT_EQ(2, message.packed_sint32_size ());
  591. ASSERT_EQ(2, message.packed_sint64_size ());
  592. ASSERT_EQ(2, message.packed_fixed32_size ());
  593. ASSERT_EQ(2, message.packed_fixed64_size ());
  594. ASSERT_EQ(2, message.packed_sfixed32_size());
  595. ASSERT_EQ(2, message.packed_sfixed64_size());
  596. ASSERT_EQ(2, message.packed_float_size ());
  597. ASSERT_EQ(2, message.packed_double_size ());
  598. ASSERT_EQ(2, message.packed_bool_size ());
  599. ASSERT_EQ(2, message.packed_enum_size ());
  600. EXPECT_EQ(601 , message.packed_int32 (0));
  601. EXPECT_EQ(602 , message.packed_int64 (0));
  602. EXPECT_EQ(603 , message.packed_uint32 (0));
  603. EXPECT_EQ(604 , message.packed_uint64 (0));
  604. EXPECT_EQ(605 , message.packed_sint32 (0));
  605. EXPECT_EQ(606 , message.packed_sint64 (0));
  606. EXPECT_EQ(607 , message.packed_fixed32 (0));
  607. EXPECT_EQ(608 , message.packed_fixed64 (0));
  608. EXPECT_EQ(609 , message.packed_sfixed32(0));
  609. EXPECT_EQ(610 , message.packed_sfixed64(0));
  610. EXPECT_EQ(611 , message.packed_float (0));
  611. EXPECT_EQ(612 , message.packed_double (0));
  612. EXPECT_EQ(true , message.packed_bool (0));
  613. EXPECT_EQ(unittest::FOREIGN_LITE_BAR, message.packed_enum(0));
  614. EXPECT_EQ(701 , message.packed_int32 (1));
  615. EXPECT_EQ(702 , message.packed_int64 (1));
  616. EXPECT_EQ(703 , message.packed_uint32 (1));
  617. EXPECT_EQ(704 , message.packed_uint64 (1));
  618. EXPECT_EQ(705 , message.packed_sint32 (1));
  619. EXPECT_EQ(706 , message.packed_sint64 (1));
  620. EXPECT_EQ(707 , message.packed_fixed32 (1));
  621. EXPECT_EQ(708 , message.packed_fixed64 (1));
  622. EXPECT_EQ(709 , message.packed_sfixed32(1));
  623. EXPECT_EQ(710 , message.packed_sfixed64(1));
  624. EXPECT_EQ(711 , message.packed_float (1));
  625. EXPECT_EQ(712 , message.packed_double (1));
  626. EXPECT_EQ(false, message.packed_bool (1));
  627. EXPECT_EQ(unittest::FOREIGN_LITE_BAZ, message.packed_enum(1));
  628. }
  629. // -------------------------------------------------------------------
  630. void TestUtilLite::ExpectPackedClear(
  631. const unittest::TestPackedTypesLite& message) {
  632. // Packed repeated fields are empty.
  633. EXPECT_EQ(0, message.packed_int32_size ());
  634. EXPECT_EQ(0, message.packed_int64_size ());
  635. EXPECT_EQ(0, message.packed_uint32_size ());
  636. EXPECT_EQ(0, message.packed_uint64_size ());
  637. EXPECT_EQ(0, message.packed_sint32_size ());
  638. EXPECT_EQ(0, message.packed_sint64_size ());
  639. EXPECT_EQ(0, message.packed_fixed32_size ());
  640. EXPECT_EQ(0, message.packed_fixed64_size ());
  641. EXPECT_EQ(0, message.packed_sfixed32_size());
  642. EXPECT_EQ(0, message.packed_sfixed64_size());
  643. EXPECT_EQ(0, message.packed_float_size ());
  644. EXPECT_EQ(0, message.packed_double_size ());
  645. EXPECT_EQ(0, message.packed_bool_size ());
  646. EXPECT_EQ(0, message.packed_enum_size ());
  647. }
  648. // -------------------------------------------------------------------
  649. void TestUtilLite::ExpectPackedFieldsModified(
  650. const unittest::TestPackedTypesLite& message) {
  651. // Do the same for packed repeated fields.
  652. ASSERT_EQ(2, message.packed_int32_size ());
  653. ASSERT_EQ(2, message.packed_int64_size ());
  654. ASSERT_EQ(2, message.packed_uint32_size ());
  655. ASSERT_EQ(2, message.packed_uint64_size ());
  656. ASSERT_EQ(2, message.packed_sint32_size ());
  657. ASSERT_EQ(2, message.packed_sint64_size ());
  658. ASSERT_EQ(2, message.packed_fixed32_size ());
  659. ASSERT_EQ(2, message.packed_fixed64_size ());
  660. ASSERT_EQ(2, message.packed_sfixed32_size());
  661. ASSERT_EQ(2, message.packed_sfixed64_size());
  662. ASSERT_EQ(2, message.packed_float_size ());
  663. ASSERT_EQ(2, message.packed_double_size ());
  664. ASSERT_EQ(2, message.packed_bool_size ());
  665. ASSERT_EQ(2, message.packed_enum_size ());
  666. EXPECT_EQ(601 , message.packed_int32 (0));
  667. EXPECT_EQ(602 , message.packed_int64 (0));
  668. EXPECT_EQ(603 , message.packed_uint32 (0));
  669. EXPECT_EQ(604 , message.packed_uint64 (0));
  670. EXPECT_EQ(605 , message.packed_sint32 (0));
  671. EXPECT_EQ(606 , message.packed_sint64 (0));
  672. EXPECT_EQ(607 , message.packed_fixed32 (0));
  673. EXPECT_EQ(608 , message.packed_fixed64 (0));
  674. EXPECT_EQ(609 , message.packed_sfixed32(0));
  675. EXPECT_EQ(610 , message.packed_sfixed64(0));
  676. EXPECT_EQ(611 , message.packed_float (0));
  677. EXPECT_EQ(612 , message.packed_double (0));
  678. EXPECT_EQ(true , message.packed_bool (0));
  679. EXPECT_EQ(unittest::FOREIGN_LITE_BAR, message.packed_enum(0));
  680. // Actually verify the second (modified) elements now.
  681. EXPECT_EQ(801 , message.packed_int32 (1));
  682. EXPECT_EQ(802 , message.packed_int64 (1));
  683. EXPECT_EQ(803 , message.packed_uint32 (1));
  684. EXPECT_EQ(804 , message.packed_uint64 (1));
  685. EXPECT_EQ(805 , message.packed_sint32 (1));
  686. EXPECT_EQ(806 , message.packed_sint64 (1));
  687. EXPECT_EQ(807 , message.packed_fixed32 (1));
  688. EXPECT_EQ(808 , message.packed_fixed64 (1));
  689. EXPECT_EQ(809 , message.packed_sfixed32(1));
  690. EXPECT_EQ(810 , message.packed_sfixed64(1));
  691. EXPECT_EQ(811 , message.packed_float (1));
  692. EXPECT_EQ(812 , message.packed_double (1));
  693. EXPECT_EQ(true , message.packed_bool (1));
  694. EXPECT_EQ(unittest::FOREIGN_LITE_FOO, message.packed_enum(1));
  695. }
  696. // ===================================================================
  697. // Extensions
  698. //
  699. // All this code is exactly equivalent to the above code except that it's
  700. // manipulating extension fields instead of normal ones.
  701. //
  702. // I gave up on the 80-char limit here. Sorry.
  703. void TestUtilLite::SetAllExtensions(unittest::TestAllExtensionsLite* message) {
  704. message->SetExtension(unittest::optional_int32_extension_lite , 101);
  705. message->SetExtension(unittest::optional_int64_extension_lite , 102);
  706. message->SetExtension(unittest::optional_uint32_extension_lite , 103);
  707. message->SetExtension(unittest::optional_uint64_extension_lite , 104);
  708. message->SetExtension(unittest::optional_sint32_extension_lite , 105);
  709. message->SetExtension(unittest::optional_sint64_extension_lite , 106);
  710. message->SetExtension(unittest::optional_fixed32_extension_lite , 107);
  711. message->SetExtension(unittest::optional_fixed64_extension_lite , 108);
  712. message->SetExtension(unittest::optional_sfixed32_extension_lite, 109);
  713. message->SetExtension(unittest::optional_sfixed64_extension_lite, 110);
  714. message->SetExtension(unittest::optional_float_extension_lite , 111);
  715. message->SetExtension(unittest::optional_double_extension_lite , 112);
  716. message->SetExtension(unittest::optional_bool_extension_lite , true);
  717. message->SetExtension(unittest::optional_string_extension_lite , "115");
  718. message->SetExtension(unittest::optional_bytes_extension_lite , "116");
  719. message->MutableExtension(unittest::optionalgroup_extension_lite )->set_a(117);
  720. message->MutableExtension(unittest::optional_nested_message_extension_lite )->set_bb(118);
  721. message->MutableExtension(unittest::optional_foreign_message_extension_lite )->set_c(119);
  722. message->MutableExtension(unittest::optional_import_message_extension_lite )->set_d(120);
  723. message->MutableExtension(unittest::optional_public_import_message_extension_lite)->set_e(126);
  724. message->MutableExtension(unittest::optional_lazy_message_extension_lite )->set_bb(127);
  725. message->SetExtension(unittest::optional_nested_enum_extension_lite , unittest::TestAllTypesLite::BAZ );
  726. message->SetExtension(unittest::optional_foreign_enum_extension_lite, unittest::FOREIGN_LITE_BAZ );
  727. message->SetExtension(unittest::optional_import_enum_extension_lite , unittest_import::IMPORT_LITE_BAZ);
  728. // -----------------------------------------------------------------
  729. message->AddExtension(unittest::repeated_int32_extension_lite , 201);
  730. message->AddExtension(unittest::repeated_int64_extension_lite , 202);
  731. message->AddExtension(unittest::repeated_uint32_extension_lite , 203);
  732. message->AddExtension(unittest::repeated_uint64_extension_lite , 204);
  733. message->AddExtension(unittest::repeated_sint32_extension_lite , 205);
  734. message->AddExtension(unittest::repeated_sint64_extension_lite , 206);
  735. message->AddExtension(unittest::repeated_fixed32_extension_lite , 207);
  736. message->AddExtension(unittest::repeated_fixed64_extension_lite , 208);
  737. message->AddExtension(unittest::repeated_sfixed32_extension_lite, 209);
  738. message->AddExtension(unittest::repeated_sfixed64_extension_lite, 210);
  739. message->AddExtension(unittest::repeated_float_extension_lite , 211);
  740. message->AddExtension(unittest::repeated_double_extension_lite , 212);
  741. message->AddExtension(unittest::repeated_bool_extension_lite , true);
  742. message->AddExtension(unittest::repeated_string_extension_lite , "215");
  743. message->AddExtension(unittest::repeated_bytes_extension_lite , "216");
  744. message->AddExtension(unittest::repeatedgroup_extension_lite )->set_a(217);
  745. message->AddExtension(unittest::repeated_nested_message_extension_lite )->set_bb(218);
  746. message->AddExtension(unittest::repeated_foreign_message_extension_lite)->set_c(219);
  747. message->AddExtension(unittest::repeated_import_message_extension_lite )->set_d(220);
  748. message->AddExtension(unittest::repeated_lazy_message_extension_lite )->set_bb(227);
  749. message->AddExtension(unittest::repeated_nested_enum_extension_lite , unittest::TestAllTypesLite::BAR );
  750. message->AddExtension(unittest::repeated_foreign_enum_extension_lite, unittest::FOREIGN_LITE_BAR );
  751. message->AddExtension(unittest::repeated_import_enum_extension_lite , unittest_import::IMPORT_LITE_BAR);
  752. // Add a second one of each field.
  753. message->AddExtension(unittest::repeated_int32_extension_lite , 301);
  754. message->AddExtension(unittest::repeated_int64_extension_lite , 302);
  755. message->AddExtension(unittest::repeated_uint32_extension_lite , 303);
  756. message->AddExtension(unittest::repeated_uint64_extension_lite , 304);
  757. message->AddExtension(unittest::repeated_sint32_extension_lite , 305);
  758. message->AddExtension(unittest::repeated_sint64_extension_lite , 306);
  759. message->AddExtension(unittest::repeated_fixed32_extension_lite , 307);
  760. message->AddExtension(unittest::repeated_fixed64_extension_lite , 308);
  761. message->AddExtension(unittest::repeated_sfixed32_extension_lite, 309);
  762. message->AddExtension(unittest::repeated_sfixed64_extension_lite, 310);
  763. message->AddExtension(unittest::repeated_float_extension_lite , 311);
  764. message->AddExtension(unittest::repeated_double_extension_lite , 312);
  765. message->AddExtension(unittest::repeated_bool_extension_lite , false);
  766. message->AddExtension(unittest::repeated_string_extension_lite , "315");
  767. message->AddExtension(unittest::repeated_bytes_extension_lite , "316");
  768. message->AddExtension(unittest::repeatedgroup_extension_lite )->set_a(317);
  769. message->AddExtension(unittest::repeated_nested_message_extension_lite )->set_bb(318);
  770. message->AddExtension(unittest::repeated_foreign_message_extension_lite)->set_c(319);
  771. message->AddExtension(unittest::repeated_import_message_extension_lite )->set_d(320);
  772. message->AddExtension(unittest::repeated_lazy_message_extension_lite )->set_bb(327);
  773. message->AddExtension(unittest::repeated_nested_enum_extension_lite , unittest::TestAllTypesLite::BAZ );
  774. message->AddExtension(unittest::repeated_foreign_enum_extension_lite, unittest::FOREIGN_LITE_BAZ );
  775. message->AddExtension(unittest::repeated_import_enum_extension_lite , unittest_import::IMPORT_LITE_BAZ);
  776. // -----------------------------------------------------------------
  777. message->SetExtension(unittest::default_int32_extension_lite , 401);
  778. message->SetExtension(unittest::default_int64_extension_lite , 402);
  779. message->SetExtension(unittest::default_uint32_extension_lite , 403);
  780. message->SetExtension(unittest::default_uint64_extension_lite , 404);
  781. message->SetExtension(unittest::default_sint32_extension_lite , 405);
  782. message->SetExtension(unittest::default_sint64_extension_lite , 406);
  783. message->SetExtension(unittest::default_fixed32_extension_lite , 407);
  784. message->SetExtension(unittest::default_fixed64_extension_lite , 408);
  785. message->SetExtension(unittest::default_sfixed32_extension_lite, 409);
  786. message->SetExtension(unittest::default_sfixed64_extension_lite, 410);
  787. message->SetExtension(unittest::default_float_extension_lite , 411);
  788. message->SetExtension(unittest::default_double_extension_lite , 412);
  789. message->SetExtension(unittest::default_bool_extension_lite , false);
  790. message->SetExtension(unittest::default_string_extension_lite , "415");
  791. message->SetExtension(unittest::default_bytes_extension_lite , "416");
  792. message->SetExtension(unittest::default_nested_enum_extension_lite , unittest::TestAllTypesLite::FOO );
  793. message->SetExtension(unittest::default_foreign_enum_extension_lite, unittest::FOREIGN_LITE_FOO );
  794. message->SetExtension(unittest::default_import_enum_extension_lite , unittest_import::IMPORT_LITE_FOO);
  795. message->SetExtension(unittest::oneof_uint32_extension_lite, 601);
  796. message->MutableExtension(unittest::oneof_nested_message_extension_lite)->set_bb(602);;
  797. message->SetExtension(unittest::oneof_string_extension_lite, "603");
  798. message->SetExtension(unittest::oneof_bytes_extension_lite, "604");
  799. }
  800. // -------------------------------------------------------------------
  801. void TestUtilLite::ModifyRepeatedExtensions(
  802. unittest::TestAllExtensionsLite* message) {
  803. message->SetExtension(unittest::repeated_int32_extension_lite , 1, 501);
  804. message->SetExtension(unittest::repeated_int64_extension_lite , 1, 502);
  805. message->SetExtension(unittest::repeated_uint32_extension_lite , 1, 503);
  806. message->SetExtension(unittest::repeated_uint64_extension_lite , 1, 504);
  807. message->SetExtension(unittest::repeated_sint32_extension_lite , 1, 505);
  808. message->SetExtension(unittest::repeated_sint64_extension_lite , 1, 506);
  809. message->SetExtension(unittest::repeated_fixed32_extension_lite , 1, 507);
  810. message->SetExtension(unittest::repeated_fixed64_extension_lite , 1, 508);
  811. message->SetExtension(unittest::repeated_sfixed32_extension_lite, 1, 509);
  812. message->SetExtension(unittest::repeated_sfixed64_extension_lite, 1, 510);
  813. message->SetExtension(unittest::repeated_float_extension_lite , 1, 511);
  814. message->SetExtension(unittest::repeated_double_extension_lite , 1, 512);
  815. message->SetExtension(unittest::repeated_bool_extension_lite , 1, true);
  816. message->SetExtension(unittest::repeated_string_extension_lite , 1, "515");
  817. message->SetExtension(unittest::repeated_bytes_extension_lite , 1, "516");
  818. message->MutableExtension(unittest::repeatedgroup_extension_lite , 1)->set_a(517);
  819. message->MutableExtension(unittest::repeated_nested_message_extension_lite , 1)->set_bb(518);
  820. message->MutableExtension(unittest::repeated_foreign_message_extension_lite, 1)->set_c(519);
  821. message->MutableExtension(unittest::repeated_import_message_extension_lite , 1)->set_d(520);
  822. message->MutableExtension(unittest::repeated_lazy_message_extension_lite , 1)->set_bb(527);
  823. message->SetExtension(unittest::repeated_nested_enum_extension_lite , 1, unittest::TestAllTypesLite::FOO );
  824. message->SetExtension(unittest::repeated_foreign_enum_extension_lite, 1, unittest::FOREIGN_LITE_FOO );
  825. message->SetExtension(unittest::repeated_import_enum_extension_lite , 1, unittest_import::IMPORT_LITE_FOO);
  826. }
  827. // -------------------------------------------------------------------
  828. void TestUtilLite::ExpectAllExtensionsSet(
  829. const unittest::TestAllExtensionsLite& message) {
  830. EXPECT_TRUE(message.HasExtension(unittest::optional_int32_extension_lite ));
  831. EXPECT_TRUE(message.HasExtension(unittest::optional_int64_extension_lite ));
  832. EXPECT_TRUE(message.HasExtension(unittest::optional_uint32_extension_lite ));
  833. EXPECT_TRUE(message.HasExtension(unittest::optional_uint64_extension_lite ));
  834. EXPECT_TRUE(message.HasExtension(unittest::optional_sint32_extension_lite ));
  835. EXPECT_TRUE(message.HasExtension(unittest::optional_sint64_extension_lite ));
  836. EXPECT_TRUE(message.HasExtension(unittest::optional_fixed32_extension_lite ));
  837. EXPECT_TRUE(message.HasExtension(unittest::optional_fixed64_extension_lite ));
  838. EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed32_extension_lite));
  839. EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed64_extension_lite));
  840. EXPECT_TRUE(message.HasExtension(unittest::optional_float_extension_lite ));
  841. EXPECT_TRUE(message.HasExtension(unittest::optional_double_extension_lite ));
  842. EXPECT_TRUE(message.HasExtension(unittest::optional_bool_extension_lite ));
  843. EXPECT_TRUE(message.HasExtension(unittest::optional_string_extension_lite ));
  844. EXPECT_TRUE(message.HasExtension(unittest::optional_bytes_extension_lite ));
  845. EXPECT_TRUE(message.HasExtension(unittest::optionalgroup_extension_lite ));
  846. EXPECT_TRUE(message.HasExtension(unittest::optional_nested_message_extension_lite ));
  847. EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_message_extension_lite ));
  848. EXPECT_TRUE(message.HasExtension(unittest::optional_import_message_extension_lite ));
  849. EXPECT_TRUE(message.HasExtension(unittest::optional_public_import_message_extension_lite));
  850. EXPECT_TRUE(message.HasExtension(unittest::optional_lazy_message_extension_lite ));
  851. EXPECT_TRUE(message.GetExtension(unittest::optionalgroup_extension_lite ).has_a());
  852. EXPECT_TRUE(message.GetExtension(unittest::optional_nested_message_extension_lite ).has_bb());
  853. EXPECT_TRUE(message.GetExtension(unittest::optional_foreign_message_extension_lite ).has_c());
  854. EXPECT_TRUE(message.GetExtension(unittest::optional_import_message_extension_lite ).has_d());
  855. EXPECT_TRUE(message.GetExtension(unittest::optional_public_import_message_extension_lite).has_e());
  856. EXPECT_TRUE(message.GetExtension(unittest::optional_lazy_message_extension_lite ).has_bb());
  857. EXPECT_TRUE(message.HasExtension(unittest::optional_nested_enum_extension_lite ));
  858. EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_enum_extension_lite));
  859. EXPECT_TRUE(message.HasExtension(unittest::optional_import_enum_extension_lite ));
  860. EXPECT_EQ(101 , message.GetExtension(unittest::optional_int32_extension_lite ));
  861. EXPECT_EQ(102 , message.GetExtension(unittest::optional_int64_extension_lite ));
  862. EXPECT_EQ(103 , message.GetExtension(unittest::optional_uint32_extension_lite ));
  863. EXPECT_EQ(104 , message.GetExtension(unittest::optional_uint64_extension_lite ));
  864. EXPECT_EQ(105 , message.GetExtension(unittest::optional_sint32_extension_lite ));
  865. EXPECT_EQ(106 , message.GetExtension(unittest::optional_sint64_extension_lite ));
  866. EXPECT_EQ(107 , message.GetExtension(unittest::optional_fixed32_extension_lite ));
  867. EXPECT_EQ(108 , message.GetExtension(unittest::optional_fixed64_extension_lite ));
  868. EXPECT_EQ(109 , message.GetExtension(unittest::optional_sfixed32_extension_lite));
  869. EXPECT_EQ(110 , message.GetExtension(unittest::optional_sfixed64_extension_lite));
  870. EXPECT_EQ(111 , message.GetExtension(unittest::optional_float_extension_lite ));
  871. EXPECT_EQ(112 , message.GetExtension(unittest::optional_double_extension_lite ));
  872. EXPECT_EQ(true , message.GetExtension(unittest::optional_bool_extension_lite ));
  873. EXPECT_EQ("115", message.GetExtension(unittest::optional_string_extension_lite ));
  874. EXPECT_EQ("116", message.GetExtension(unittest::optional_bytes_extension_lite ));
  875. EXPECT_EQ(117, message.GetExtension(unittest::optionalgroup_extension_lite ).a());
  876. EXPECT_EQ(118, message.GetExtension(unittest::optional_nested_message_extension_lite ).bb());
  877. EXPECT_EQ(119, message.GetExtension(unittest::optional_foreign_message_extension_lite ).c());
  878. EXPECT_EQ(120, message.GetExtension(unittest::optional_import_message_extension_lite ).d());
  879. EXPECT_EQ(126, message.GetExtension(unittest::optional_public_import_message_extension_lite).e());
  880. EXPECT_EQ(127, message.GetExtension(unittest::optional_lazy_message_extension_lite ).bb());
  881. EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.GetExtension(unittest::optional_nested_enum_extension_lite ));
  882. EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.GetExtension(unittest::optional_foreign_enum_extension_lite));
  883. EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.GetExtension(unittest::optional_import_enum_extension_lite ));
  884. // -----------------------------------------------------------------
  885. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension_lite ));
  886. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension_lite ));
  887. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension_lite ));
  888. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension_lite ));
  889. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension_lite ));
  890. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension_lite ));
  891. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension_lite ));
  892. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension_lite ));
  893. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension_lite));
  894. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension_lite));
  895. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension_lite ));
  896. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension_lite ));
  897. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension_lite ));
  898. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension_lite ));
  899. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension_lite ));
  900. ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension_lite ));
  901. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension_lite ));
  902. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension_lite));
  903. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension_lite ));
  904. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_lazy_message_extension_lite ));
  905. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension_lite ));
  906. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension_lite ));
  907. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension_lite ));
  908. EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension_lite , 0));
  909. EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension_lite , 0));
  910. EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension_lite , 0));
  911. EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension_lite , 0));
  912. EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension_lite , 0));
  913. EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension_lite , 0));
  914. EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 0));
  915. EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 0));
  916. EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 0));
  917. EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 0));
  918. EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension_lite , 0));
  919. EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension_lite , 0));
  920. EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension_lite , 0));
  921. EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension_lite , 0));
  922. EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension_lite , 0));
  923. EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension_lite , 0).a());
  924. EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension_lite , 0).bb());
  925. EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 0).c());
  926. EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension_lite , 0).d());
  927. EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 0).bb());
  928. EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 0));
  929. EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 0));
  930. EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.GetExtension(unittest::repeated_import_enum_extension_lite , 0));
  931. EXPECT_EQ(301 , message.GetExtension(unittest::repeated_int32_extension_lite , 1));
  932. EXPECT_EQ(302 , message.GetExtension(unittest::repeated_int64_extension_lite , 1));
  933. EXPECT_EQ(303 , message.GetExtension(unittest::repeated_uint32_extension_lite , 1));
  934. EXPECT_EQ(304 , message.GetExtension(unittest::repeated_uint64_extension_lite , 1));
  935. EXPECT_EQ(305 , message.GetExtension(unittest::repeated_sint32_extension_lite , 1));
  936. EXPECT_EQ(306 , message.GetExtension(unittest::repeated_sint64_extension_lite , 1));
  937. EXPECT_EQ(307 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 1));
  938. EXPECT_EQ(308 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 1));
  939. EXPECT_EQ(309 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 1));
  940. EXPECT_EQ(310 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 1));
  941. EXPECT_EQ(311 , message.GetExtension(unittest::repeated_float_extension_lite , 1));
  942. EXPECT_EQ(312 , message.GetExtension(unittest::repeated_double_extension_lite , 1));
  943. EXPECT_EQ(false, message.GetExtension(unittest::repeated_bool_extension_lite , 1));
  944. EXPECT_EQ("315", message.GetExtension(unittest::repeated_string_extension_lite , 1));
  945. EXPECT_EQ("316", message.GetExtension(unittest::repeated_bytes_extension_lite , 1));
  946. EXPECT_EQ(317, message.GetExtension(unittest::repeatedgroup_extension_lite , 1).a());
  947. EXPECT_EQ(318, message.GetExtension(unittest::repeated_nested_message_extension_lite , 1).bb());
  948. EXPECT_EQ(319, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 1).c());
  949. EXPECT_EQ(320, message.GetExtension(unittest::repeated_import_message_extension_lite , 1).d());
  950. EXPECT_EQ(327, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 1).bb());
  951. EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 1));
  952. EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 1));
  953. EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.GetExtension(unittest::repeated_import_enum_extension_lite , 1));
  954. // -----------------------------------------------------------------
  955. EXPECT_TRUE(message.HasExtension(unittest::default_int32_extension_lite ));
  956. EXPECT_TRUE(message.HasExtension(unittest::default_int64_extension_lite ));
  957. EXPECT_TRUE(message.HasExtension(unittest::default_uint32_extension_lite ));
  958. EXPECT_TRUE(message.HasExtension(unittest::default_uint64_extension_lite ));
  959. EXPECT_TRUE(message.HasExtension(unittest::default_sint32_extension_lite ));
  960. EXPECT_TRUE(message.HasExtension(unittest::default_sint64_extension_lite ));
  961. EXPECT_TRUE(message.HasExtension(unittest::default_fixed32_extension_lite ));
  962. EXPECT_TRUE(message.HasExtension(unittest::default_fixed64_extension_lite ));
  963. EXPECT_TRUE(message.HasExtension(unittest::default_sfixed32_extension_lite));
  964. EXPECT_TRUE(message.HasExtension(unittest::default_sfixed64_extension_lite));
  965. EXPECT_TRUE(message.HasExtension(unittest::default_float_extension_lite ));
  966. EXPECT_TRUE(message.HasExtension(unittest::default_double_extension_lite ));
  967. EXPECT_TRUE(message.HasExtension(unittest::default_bool_extension_lite ));
  968. EXPECT_TRUE(message.HasExtension(unittest::default_string_extension_lite ));
  969. EXPECT_TRUE(message.HasExtension(unittest::default_bytes_extension_lite ));
  970. EXPECT_TRUE(message.HasExtension(unittest::default_nested_enum_extension_lite ));
  971. EXPECT_TRUE(message.HasExtension(unittest::default_foreign_enum_extension_lite));
  972. EXPECT_TRUE(message.HasExtension(unittest::default_import_enum_extension_lite ));
  973. EXPECT_EQ(401 , message.GetExtension(unittest::default_int32_extension_lite ));
  974. EXPECT_EQ(402 , message.GetExtension(unittest::default_int64_extension_lite ));
  975. EXPECT_EQ(403 , message.GetExtension(unittest::default_uint32_extension_lite ));
  976. EXPECT_EQ(404 , message.GetExtension(unittest::default_uint64_extension_lite ));
  977. EXPECT_EQ(405 , message.GetExtension(unittest::default_sint32_extension_lite ));
  978. EXPECT_EQ(406 , message.GetExtension(unittest::default_sint64_extension_lite ));
  979. EXPECT_EQ(407 , message.GetExtension(unittest::default_fixed32_extension_lite ));
  980. EXPECT_EQ(408 , message.GetExtension(unittest::default_fixed64_extension_lite ));
  981. EXPECT_EQ(409 , message.GetExtension(unittest::default_sfixed32_extension_lite));
  982. EXPECT_EQ(410 , message.GetExtension(unittest::default_sfixed64_extension_lite));
  983. EXPECT_EQ(411 , message.GetExtension(unittest::default_float_extension_lite ));
  984. EXPECT_EQ(412 , message.GetExtension(unittest::default_double_extension_lite ));
  985. EXPECT_EQ(false, message.GetExtension(unittest::default_bool_extension_lite ));
  986. EXPECT_EQ("415", message.GetExtension(unittest::default_string_extension_lite ));
  987. EXPECT_EQ("416", message.GetExtension(unittest::default_bytes_extension_lite ));
  988. EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.GetExtension(unittest::default_nested_enum_extension_lite ));
  989. EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.GetExtension(unittest::default_foreign_enum_extension_lite));
  990. EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.GetExtension(unittest::default_import_enum_extension_lite ));
  991. EXPECT_TRUE(message.HasExtension(unittest::oneof_uint32_extension_lite));
  992. EXPECT_TRUE(message.GetExtension(unittest::oneof_nested_message_extension_lite).has_bb());
  993. EXPECT_TRUE(message.HasExtension(unittest::oneof_string_extension_lite));
  994. EXPECT_TRUE(message.HasExtension(unittest::oneof_bytes_extension_lite));
  995. EXPECT_EQ(601, message.GetExtension(unittest::oneof_uint32_extension_lite));
  996. EXPECT_EQ(602, message.GetExtension(unittest::oneof_nested_message_extension_lite).bb());
  997. EXPECT_EQ("603", message.GetExtension(unittest::oneof_string_extension_lite));
  998. EXPECT_EQ("604", message.GetExtension(unittest::oneof_bytes_extension_lite));
  999. }
  1000. // -------------------------------------------------------------------
  1001. void TestUtilLite::ExpectExtensionsClear(
  1002. const unittest::TestAllExtensionsLite& message) {
  1003. string serialized;
  1004. ASSERT_TRUE(message.SerializeToString(&serialized));
  1005. EXPECT_EQ("", serialized);
  1006. EXPECT_EQ(0, message.ByteSize());
  1007. // has_blah() should initially be false for all optional fields.
  1008. EXPECT_FALSE(message.HasExtension(unittest::optional_int32_extension_lite ));
  1009. EXPECT_FALSE(message.HasExtension(unittest::optional_int64_extension_lite ));
  1010. EXPECT_FALSE(message.HasExtension(unittest::optional_uint32_extension_lite ));
  1011. EXPECT_FALSE(message.HasExtension(unittest::optional_uint64_extension_lite ));
  1012. EXPECT_FALSE(message.HasExtension(unittest::optional_sint32_extension_lite ));
  1013. EXPECT_FALSE(message.HasExtension(unittest::optional_sint64_extension_lite ));
  1014. EXPECT_FALSE(message.HasExtension(unittest::optional_fixed32_extension_lite ));
  1015. EXPECT_FALSE(message.HasExtension(unittest::optional_fixed64_extension_lite ));
  1016. EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed32_extension_lite));
  1017. EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed64_extension_lite));
  1018. EXPECT_FALSE(message.HasExtension(unittest::optional_float_extension_lite ));
  1019. EXPECT_FALSE(message.HasExtension(unittest::optional_double_extension_lite ));
  1020. EXPECT_FALSE(message.HasExtension(unittest::optional_bool_extension_lite ));
  1021. EXPECT_FALSE(message.HasExtension(unittest::optional_string_extension_lite ));
  1022. EXPECT_FALSE(message.HasExtension(unittest::optional_bytes_extension_lite ));
  1023. EXPECT_FALSE(message.HasExtension(unittest::optionalgroup_extension_lite ));
  1024. EXPECT_FALSE(message.HasExtension(unittest::optional_nested_message_extension_lite ));
  1025. EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_message_extension_lite ));
  1026. EXPECT_FALSE(message.HasExtension(unittest::optional_import_message_extension_lite ));
  1027. EXPECT_FALSE(message.HasExtension(unittest::optional_public_import_message_extension_lite));
  1028. EXPECT_FALSE(message.HasExtension(unittest::optional_lazy_message_extension_lite ));
  1029. EXPECT_FALSE(message.HasExtension(unittest::optional_nested_enum_extension_lite ));
  1030. EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_enum_extension_lite));
  1031. EXPECT_FALSE(message.HasExtension(unittest::optional_import_enum_extension_lite ));
  1032. // Optional fields without defaults are set to zero or something like it.
  1033. EXPECT_EQ(0 , message.GetExtension(unittest::optional_int32_extension_lite ));
  1034. EXPECT_EQ(0 , message.GetExtension(unittest::optional_int64_extension_lite ));
  1035. EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint32_extension_lite ));
  1036. EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint64_extension_lite ));
  1037. EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint32_extension_lite ));
  1038. EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint64_extension_lite ));
  1039. EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed32_extension_lite ));
  1040. EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed64_extension_lite ));
  1041. EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed32_extension_lite));
  1042. EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed64_extension_lite));
  1043. EXPECT_EQ(0 , message.GetExtension(unittest::optional_float_extension_lite ));
  1044. EXPECT_EQ(0 , message.GetExtension(unittest::optional_double_extension_lite ));
  1045. EXPECT_EQ(false, message.GetExtension(unittest::optional_bool_extension_lite ));
  1046. EXPECT_EQ("" , message.GetExtension(unittest::optional_string_extension_lite ));
  1047. EXPECT_EQ("" , message.GetExtension(unittest::optional_bytes_extension_lite ));
  1048. // Embedded messages should also be clear.
  1049. EXPECT_FALSE(message.GetExtension(unittest::optionalgroup_extension_lite ).has_a());
  1050. EXPECT_FALSE(message.GetExtension(unittest::optional_nested_message_extension_lite ).has_bb());
  1051. EXPECT_FALSE(message.GetExtension(unittest::optional_foreign_message_extension_lite ).has_c());
  1052. EXPECT_FALSE(message.GetExtension(unittest::optional_import_message_extension_lite ).has_d());
  1053. EXPECT_FALSE(message.GetExtension(unittest::optional_public_import_message_extension_lite).has_e());
  1054. EXPECT_FALSE(message.GetExtension(unittest::optional_lazy_message_extension_lite ).has_bb());
  1055. EXPECT_EQ(0, message.GetExtension(unittest::optionalgroup_extension_lite ).a());
  1056. EXPECT_EQ(0, message.GetExtension(unittest::optional_nested_message_extension_lite ).bb());
  1057. EXPECT_EQ(0, message.GetExtension(unittest::optional_foreign_message_extension_lite ).c());
  1058. EXPECT_EQ(0, message.GetExtension(unittest::optional_import_message_extension_lite ).d());
  1059. EXPECT_EQ(0, message.GetExtension(unittest::optional_public_import_message_extension_lite).e());
  1060. EXPECT_EQ(0, message.GetExtension(unittest::optional_lazy_message_extension_lite ).bb());
  1061. // Enums without defaults are set to the first value in the enum.
  1062. EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.GetExtension(unittest::optional_nested_enum_extension_lite ));
  1063. EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.GetExtension(unittest::optional_foreign_enum_extension_lite));
  1064. EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.GetExtension(unittest::optional_import_enum_extension_lite ));
  1065. // Repeated fields are empty.
  1066. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int32_extension_lite ));
  1067. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int64_extension_lite ));
  1068. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint32_extension_lite ));
  1069. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint64_extension_lite ));
  1070. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint32_extension_lite ));
  1071. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint64_extension_lite ));
  1072. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed32_extension_lite ));
  1073. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed64_extension_lite ));
  1074. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed32_extension_lite));
  1075. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed64_extension_lite));
  1076. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_float_extension_lite ));
  1077. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_double_extension_lite ));
  1078. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bool_extension_lite ));
  1079. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_string_extension_lite ));
  1080. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bytes_extension_lite ));
  1081. EXPECT_EQ(0, message.ExtensionSize(unittest::repeatedgroup_extension_lite ));
  1082. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_message_extension_lite ));
  1083. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_message_extension_lite));
  1084. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_message_extension_lite ));
  1085. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_lazy_message_extension_lite ));
  1086. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_enum_extension_lite ));
  1087. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_enum_extension_lite ));
  1088. EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_enum_extension_lite ));
  1089. // has_blah() should also be false for all default fields.
  1090. EXPECT_FALSE(message.HasExtension(unittest::default_int32_extension_lite ));
  1091. EXPECT_FALSE(message.HasExtension(unittest::default_int64_extension_lite ));
  1092. EXPECT_FALSE(message.HasExtension(unittest::default_uint32_extension_lite ));
  1093. EXPECT_FALSE(message.HasExtension(unittest::default_uint64_extension_lite ));
  1094. EXPECT_FALSE(message.HasExtension(unittest::default_sint32_extension_lite ));
  1095. EXPECT_FALSE(message.HasExtension(unittest::default_sint64_extension_lite ));
  1096. EXPECT_FALSE(message.HasExtension(unittest::default_fixed32_extension_lite ));
  1097. EXPECT_FALSE(message.HasExtension(unittest::default_fixed64_extension_lite ));
  1098. EXPECT_FALSE(message.HasExtension(unittest::default_sfixed32_extension_lite));
  1099. EXPECT_FALSE(message.HasExtension(unittest::default_sfixed64_extension_lite));
  1100. EXPECT_FALSE(message.HasExtension(unittest::default_float_extension_lite ));
  1101. EXPECT_FALSE(message.HasExtension(unittest::default_double_extension_lite ));
  1102. EXPECT_FALSE(message.HasExtension(unittest::default_bool_extension_lite ));
  1103. EXPECT_FALSE(message.HasExtension(unittest::default_string_extension_lite ));
  1104. EXPECT_FALSE(message.HasExtension(unittest::default_bytes_extension_lite ));
  1105. EXPECT_FALSE(message.HasExtension(unittest::default_nested_enum_extension_lite ));
  1106. EXPECT_FALSE(message.HasExtension(unittest::default_foreign_enum_extension_lite));
  1107. EXPECT_FALSE(message.HasExtension(unittest::default_import_enum_extension_lite ));
  1108. // Fields with defaults have their default values (duh).
  1109. EXPECT_EQ( 41 , message.GetExtension(unittest::default_int32_extension_lite ));
  1110. EXPECT_EQ( 42 , message.GetExtension(unittest::default_int64_extension_lite ));
  1111. EXPECT_EQ( 43 , message.GetExtension(unittest::default_uint32_extension_lite ));
  1112. EXPECT_EQ( 44 , message.GetExtension(unittest::default_uint64_extension_lite ));
  1113. EXPECT_EQ(-45 , message.GetExtension(unittest::default_sint32_extension_lite ));
  1114. EXPECT_EQ( 46 , message.GetExtension(unittest::default_sint64_extension_lite ));
  1115. EXPECT_EQ( 47 , message.GetExtension(unittest::default_fixed32_extension_lite ));
  1116. EXPECT_EQ( 48 , message.GetExtension(unittest::default_fixed64_extension_lite ));
  1117. EXPECT_EQ( 49 , message.GetExtension(unittest::default_sfixed32_extension_lite));
  1118. EXPECT_EQ(-50 , message.GetExtension(unittest::default_sfixed64_extension_lite));
  1119. EXPECT_EQ( 51.5 , message.GetExtension(unittest::default_float_extension_lite ));
  1120. EXPECT_EQ( 52e3 , message.GetExtension(unittest::default_double_extension_lite ));
  1121. EXPECT_EQ(true , message.GetExtension(unittest::default_bool_extension_lite ));
  1122. EXPECT_EQ("hello", message.GetExtension(unittest::default_string_extension_lite ));
  1123. EXPECT_EQ("world", message.GetExtension(unittest::default_bytes_extension_lite ));
  1124. EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.GetExtension(unittest::default_nested_enum_extension_lite ));
  1125. EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.GetExtension(unittest::default_foreign_enum_extension_lite));
  1126. EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.GetExtension(unittest::default_import_enum_extension_lite ));
  1127. EXPECT_FALSE(message.HasExtension(unittest::oneof_uint32_extension_lite));
  1128. EXPECT_FALSE(message.GetExtension(unittest::oneof_nested_message_extension_lite).has_bb());
  1129. EXPECT_FALSE(message.HasExtension(unittest::oneof_string_extension_lite));
  1130. EXPECT_FALSE(message.HasExtension(unittest::oneof_bytes_extension_lite));
  1131. }
  1132. // -------------------------------------------------------------------
  1133. void TestUtilLite::ExpectRepeatedExtensionsModified(
  1134. const unittest::TestAllExtensionsLite& message) {
  1135. // ModifyRepeatedFields only sets the second repeated element of each
  1136. // field. In addition to verifying this, we also verify that the first
  1137. // element and size were *not* modified.
  1138. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension_lite ));
  1139. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension_lite ));
  1140. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension_lite ));
  1141. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension_lite ));
  1142. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension_lite ));
  1143. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension_lite ));
  1144. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension_lite ));
  1145. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension_lite ));
  1146. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension_lite));
  1147. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension_lite));
  1148. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension_lite ));
  1149. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension_lite ));
  1150. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension_lite ));
  1151. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension_lite ));
  1152. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension_lite ));
  1153. ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension_lite ));
  1154. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension_lite ));
  1155. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension_lite));
  1156. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension_lite ));
  1157. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_lazy_message_extension_lite ));
  1158. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension_lite ));
  1159. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension_lite ));
  1160. ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension_lite ));
  1161. EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension_lite , 0));
  1162. EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension_lite , 0));
  1163. EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension_lite , 0));
  1164. EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension_lite , 0));
  1165. EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension_lite , 0));
  1166. EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension_lite , 0));
  1167. EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 0));
  1168. EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 0));
  1169. EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 0));
  1170. EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 0));
  1171. EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension_lite , 0));
  1172. EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension_lite , 0));
  1173. EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension_lite , 0));
  1174. EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension_lite , 0));
  1175. EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension_lite , 0));
  1176. EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension_lite , 0).a());
  1177. EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension_lite , 0).bb());
  1178. EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 0).c());
  1179. EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension_lite , 0).d());
  1180. EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 0).bb());
  1181. EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 0));
  1182. EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 0));
  1183. EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.GetExtension(unittest::repeated_import_enum_extension_lite , 0));
  1184. // Actually verify the second (modified) elements now.
  1185. EXPECT_EQ(501 , message.GetExtension(unittest::repeated_int32_extension_lite , 1));
  1186. EXPECT_EQ(502 , message.GetExtension(unittest::repeated_int64_extension_lite , 1));
  1187. EXPECT_EQ(503 , message.GetExtension(unittest::repeated_uint32_extension_lite , 1));
  1188. EXPECT_EQ(504 , message.GetExtension(unittest::repeated_uint64_extension_lite , 1));
  1189. EXPECT_EQ(505 , message.GetExtension(unittest::repeated_sint32_extension_lite , 1));
  1190. EXPECT_EQ(506 , message.GetExtension(unittest::repeated_sint64_extension_lite , 1));
  1191. EXPECT_EQ(507 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 1));
  1192. EXPECT_EQ(508 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 1));
  1193. EXPECT_EQ(509 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 1));
  1194. EXPECT_EQ(510 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 1));
  1195. EXPECT_EQ(511 , message.GetExtension(unittest::repeated_float_extension_lite , 1));
  1196. EXPECT_EQ(512 , message.GetExtension(unittest::repeated_double_extension_lite , 1));
  1197. EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension_lite , 1));
  1198. EXPECT_EQ("515", message.GetExtension(unittest::repeated_string_extension_lite , 1));
  1199. EXPECT_EQ("516", message.GetExtension(unittest::repeated_bytes_extension_lite , 1));
  1200. EXPECT_EQ(517, message.GetExtension(unittest::repeatedgroup_extension_lite , 1).a());
  1201. EXPECT_EQ(518, message.GetExtension(unittest::repeated_nested_message_extension_lite , 1).bb());
  1202. EXPECT_EQ(519, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 1).c());
  1203. EXPECT_EQ(520, message.GetExtension(unittest::repeated_import_message_extension_lite , 1).d());
  1204. EXPECT_EQ(527, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 1).bb());
  1205. EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 1));
  1206. EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 1));
  1207. EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.GetExtension(unittest::repeated_import_enum_extension_lite , 1));
  1208. }
  1209. // -------------------------------------------------------------------
  1210. void TestUtilLite::SetPackedExtensions(
  1211. unittest::TestPackedExtensionsLite* message) {
  1212. message->AddExtension(unittest::packed_int32_extension_lite , 601);
  1213. message->AddExtension(unittest::packed_int64_extension_lite , 602);
  1214. message->AddExtension(unittest::packed_uint32_extension_lite , 603);
  1215. message->AddExtension(unittest::packed_uint64_extension_lite , 604);
  1216. message->AddExtension(unittest::packed_sint32_extension_lite , 605);
  1217. message->AddExtension(unittest::packed_sint64_extension_lite , 606);
  1218. message->AddExtension(unittest::packed_fixed32_extension_lite , 607);
  1219. message->AddExtension(unittest::packed_fixed64_extension_lite , 608);
  1220. message->AddExtension(unittest::packed_sfixed32_extension_lite, 609);
  1221. message->AddExtension(unittest::packed_sfixed64_extension_lite, 610);
  1222. message->AddExtension(unittest::packed_float_extension_lite , 611);
  1223. message->AddExtension(unittest::packed_double_extension_lite , 612);
  1224. message->AddExtension(unittest::packed_bool_extension_lite , true);
  1225. message->AddExtension(unittest::packed_enum_extension_lite, unittest::FOREIGN_LITE_BAR);
  1226. // add a second one of each field
  1227. message->AddExtension(unittest::packed_int32_extension_lite , 701);
  1228. message->AddExtension(unittest::packed_int64_extension_lite , 702);
  1229. message->AddExtension(unittest::packed_uint32_extension_lite , 703);
  1230. message->AddExtension(unittest::packed_uint64_extension_lite , 704);
  1231. message->AddExtension(unittest::packed_sint32_extension_lite , 705);
  1232. message->AddExtension(unittest::packed_sint64_extension_lite , 706);
  1233. message->AddExtension(unittest::packed_fixed32_extension_lite , 707);
  1234. message->AddExtension(unittest::packed_fixed64_extension_lite , 708);
  1235. message->AddExtension(unittest::packed_sfixed32_extension_lite, 709);
  1236. message->AddExtension(unittest::packed_sfixed64_extension_lite, 710);
  1237. message->AddExtension(unittest::packed_float_extension_lite , 711);
  1238. message->AddExtension(unittest::packed_double_extension_lite , 712);
  1239. message->AddExtension(unittest::packed_bool_extension_lite , false);
  1240. message->AddExtension(unittest::packed_enum_extension_lite, unittest::FOREIGN_LITE_BAZ);
  1241. }
  1242. // -------------------------------------------------------------------
  1243. void TestUtilLite::ModifyPackedExtensions(
  1244. unittest::TestPackedExtensionsLite* message) {
  1245. message->SetExtension(unittest::packed_int32_extension_lite , 1, 801);
  1246. message->SetExtension(unittest::packed_int64_extension_lite , 1, 802);
  1247. message->SetExtension(unittest::packed_uint32_extension_lite , 1, 803);
  1248. message->SetExtension(unittest::packed_uint64_extension_lite , 1, 804);
  1249. message->SetExtension(unittest::packed_sint32_extension_lite , 1, 805);
  1250. message->SetExtension(unittest::packed_sint64_extension_lite , 1, 806);
  1251. message->SetExtension(unittest::packed_fixed32_extension_lite , 1, 807);
  1252. message->SetExtension(unittest::packed_fixed64_extension_lite , 1, 808);
  1253. message->SetExtension(unittest::packed_sfixed32_extension_lite, 1, 809);
  1254. message->SetExtension(unittest::packed_sfixed64_extension_lite, 1, 810);
  1255. message->SetExtension(unittest::packed_float_extension_lite , 1, 811);
  1256. message->SetExtension(unittest::packed_double_extension_lite , 1, 812);
  1257. message->SetExtension(unittest::packed_bool_extension_lite , 1, true);
  1258. message->SetExtension(unittest::packed_enum_extension_lite , 1,
  1259. unittest::FOREIGN_LITE_FOO);
  1260. }
  1261. // -------------------------------------------------------------------
  1262. void TestUtilLite::ExpectPackedExtensionsSet(
  1263. const unittest::TestPackedExtensionsLite& message) {
  1264. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension_lite ));
  1265. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension_lite ));
  1266. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension_lite ));
  1267. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension_lite ));
  1268. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension_lite ));
  1269. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension_lite ));
  1270. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension_lite ));
  1271. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension_lite ));
  1272. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension_lite));
  1273. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension_lite));
  1274. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension_lite ));
  1275. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension_lite ));
  1276. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension_lite ));
  1277. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension_lite ));
  1278. EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension_lite , 0));
  1279. EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension_lite , 0));
  1280. EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension_lite , 0));
  1281. EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension_lite , 0));
  1282. EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension_lite , 0));
  1283. EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension_lite , 0));
  1284. EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension_lite , 0));
  1285. EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension_lite , 0));
  1286. EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 0));
  1287. EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 0));
  1288. EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension_lite , 0));
  1289. EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension_lite , 0));
  1290. EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension_lite , 0));
  1291. EXPECT_EQ(unittest::FOREIGN_LITE_BAR,
  1292. message.GetExtension(unittest::packed_enum_extension_lite, 0));
  1293. EXPECT_EQ(701 , message.GetExtension(unittest::packed_int32_extension_lite , 1));
  1294. EXPECT_EQ(702 , message.GetExtension(unittest::packed_int64_extension_lite , 1));
  1295. EXPECT_EQ(703 , message.GetExtension(unittest::packed_uint32_extension_lite , 1));
  1296. EXPECT_EQ(704 , message.GetExtension(unittest::packed_uint64_extension_lite , 1));
  1297. EXPECT_EQ(705 , message.GetExtension(unittest::packed_sint32_extension_lite , 1));
  1298. EXPECT_EQ(706 , message.GetExtension(unittest::packed_sint64_extension_lite , 1));
  1299. EXPECT_EQ(707 , message.GetExtension(unittest::packed_fixed32_extension_lite , 1));
  1300. EXPECT_EQ(708 , message.GetExtension(unittest::packed_fixed64_extension_lite , 1));
  1301. EXPECT_EQ(709 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 1));
  1302. EXPECT_EQ(710 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 1));
  1303. EXPECT_EQ(711 , message.GetExtension(unittest::packed_float_extension_lite , 1));
  1304. EXPECT_EQ(712 , message.GetExtension(unittest::packed_double_extension_lite , 1));
  1305. EXPECT_EQ(false, message.GetExtension(unittest::packed_bool_extension_lite , 1));
  1306. EXPECT_EQ(unittest::FOREIGN_LITE_BAZ,
  1307. message.GetExtension(unittest::packed_enum_extension_lite, 1));
  1308. }
  1309. // -------------------------------------------------------------------
  1310. void TestUtilLite::ExpectPackedExtensionsClear(
  1311. const unittest::TestPackedExtensionsLite& message) {
  1312. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int32_extension_lite ));
  1313. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int64_extension_lite ));
  1314. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint32_extension_lite ));
  1315. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint64_extension_lite ));
  1316. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint32_extension_lite ));
  1317. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint64_extension_lite ));
  1318. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed32_extension_lite ));
  1319. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed64_extension_lite ));
  1320. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed32_extension_lite));
  1321. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed64_extension_lite));
  1322. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_float_extension_lite ));
  1323. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_double_extension_lite ));
  1324. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_bool_extension_lite ));
  1325. EXPECT_EQ(0, message.ExtensionSize(unittest::packed_enum_extension_lite ));
  1326. }
  1327. // -------------------------------------------------------------------
  1328. void TestUtilLite::ExpectPackedExtensionsModified(
  1329. const unittest::TestPackedExtensionsLite& message) {
  1330. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension_lite ));
  1331. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension_lite ));
  1332. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension_lite ));
  1333. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension_lite ));
  1334. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension_lite ));
  1335. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension_lite ));
  1336. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension_lite ));
  1337. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension_lite ));
  1338. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension_lite));
  1339. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension_lite));
  1340. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension_lite ));
  1341. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension_lite ));
  1342. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension_lite ));
  1343. ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension_lite ));
  1344. EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension_lite , 0));
  1345. EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension_lite , 0));
  1346. EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension_lite , 0));
  1347. EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension_lite , 0));
  1348. EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension_lite , 0));
  1349. EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension_lite , 0));
  1350. EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension_lite , 0));
  1351. EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension_lite , 0));
  1352. EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 0));
  1353. EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 0));
  1354. EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension_lite , 0));
  1355. EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension_lite , 0));
  1356. EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension_lite , 0));
  1357. EXPECT_EQ(unittest::FOREIGN_LITE_BAR,
  1358. message.GetExtension(unittest::packed_enum_extension_lite, 0));
  1359. // Actually verify the second (modified) elements now.
  1360. EXPECT_EQ(801 , message.GetExtension(unittest::packed_int32_extension_lite , 1));
  1361. EXPECT_EQ(802 , message.GetExtension(unittest::packed_int64_extension_lite , 1));
  1362. EXPECT_EQ(803 , message.GetExtension(unittest::packed_uint32_extension_lite , 1));
  1363. EXPECT_EQ(804 , message.GetExtension(unittest::packed_uint64_extension_lite , 1));
  1364. EXPECT_EQ(805 , message.GetExtension(unittest::packed_sint32_extension_lite , 1));
  1365. EXPECT_EQ(806 , message.GetExtension(unittest::packed_sint64_extension_lite , 1));
  1366. EXPECT_EQ(807 , message.GetExtension(unittest::packed_fixed32_extension_lite , 1));
  1367. EXPECT_EQ(808 , message.GetExtension(unittest::packed_fixed64_extension_lite , 1));
  1368. EXPECT_EQ(809 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 1));
  1369. EXPECT_EQ(810 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 1));
  1370. EXPECT_EQ(811 , message.GetExtension(unittest::packed_float_extension_lite , 1));
  1371. EXPECT_EQ(812 , message.GetExtension(unittest::packed_double_extension_lite , 1));
  1372. EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension_lite , 1));
  1373. EXPECT_EQ(unittest::FOREIGN_LITE_FOO,
  1374. message.GetExtension(unittest::packed_enum_extension_lite, 1));
  1375. }
  1376. } // namespace protobuf
  1377. } // namespace google