test_util.inc 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // This file needs to be included as .inc as it depends on the namespaces
  35. // (unittest and unittest_import) being set up properly. It is also included
  36. // within an enclosing namespace and requires header files to be included
  37. // out of this file.
  38. #include <google/protobuf/stubs/logging.h>
  39. #include <google/protobuf/stubs/common.h>
  40. #include <google/protobuf/descriptor.h>
  41. #include <google/protobuf/message.h>
  42. #include <google/protobuf/testing/googletest.h>
  43. #include <gtest/gtest.h>
  44. namespace google {
  45. namespace protobuf {
  46. namespace TestUtil {
  47. // Set every field in the message to a unique value.
  48. inline void SetAllFields(UNITTEST::TestAllTypes* message);
  49. inline void SetOptionalFields(UNITTEST::TestAllTypes* message);
  50. inline void AddRepeatedFields1(UNITTEST::TestAllTypes* message);
  51. inline void AddRepeatedFields2(UNITTEST::TestAllTypes* message);
  52. inline void SetDefaultFields(UNITTEST::TestAllTypes* message);
  53. inline void SetOneofFields(UNITTEST::TestAllTypes* message);
  54. inline void SetAllExtensions(UNITTEST::TestAllExtensions* message);
  55. inline void SetOneofFields(UNITTEST::TestAllExtensions* message);
  56. inline void SetAllFieldsAndExtensions(UNITTEST::TestFieldOrderings* message);
  57. inline void SetPackedFields(UNITTEST::TestPackedTypes* message);
  58. inline void SetPackedExtensions(UNITTEST::TestPackedExtensions* message);
  59. inline void SetUnpackedFields(UNITTEST::TestUnpackedTypes* message);
  60. inline void SetOneof1(UNITTEST::TestOneof2* message);
  61. inline void SetOneof2(UNITTEST::TestOneof2* message);
  62. // Use the repeated versions of the set_*() accessors to modify all the
  63. // repeated fields of the message (which should already have been
  64. // initialized with Set*Fields()). Set*Fields() itself only tests
  65. // the add_*() accessors.
  66. inline void ModifyRepeatedFields(UNITTEST::TestAllTypes* message);
  67. inline void ModifyRepeatedExtensions(UNITTEST::TestAllExtensions* message);
  68. inline void ModifyPackedFields(UNITTEST::TestPackedTypes* message);
  69. inline void ModifyPackedExtensions(UNITTEST::TestPackedExtensions* message);
  70. // Check that all fields have the values that they should have after
  71. // Set*Fields() is called.
  72. inline void ExpectAllFieldsSet(const UNITTEST::TestAllTypes& message);
  73. inline void ExpectAllExtensionsSet(const UNITTEST::TestAllExtensions& message);
  74. inline void ExpectPackedFieldsSet(const UNITTEST::TestPackedTypes& message);
  75. inline void ExpectPackedExtensionsSet(
  76. const UNITTEST::TestPackedExtensions& message);
  77. inline void ExpectUnpackedFieldsSet(const UNITTEST::TestUnpackedTypes& message);
  78. inline void ExpectUnpackedExtensionsSet(
  79. const UNITTEST::TestUnpackedExtensions& message);
  80. inline void ExpectOneofSet1(const UNITTEST::TestOneof2& message);
  81. inline void ExpectOneofSet2(const UNITTEST::TestOneof2& message);
  82. // Expect that the message is modified as would be expected from
  83. // Modify*Fields().
  84. inline void ExpectRepeatedFieldsModified(const UNITTEST::TestAllTypes& message);
  85. inline void ExpectRepeatedExtensionsModified(
  86. const UNITTEST::TestAllExtensions& message);
  87. inline void ExpectPackedFieldsModified(
  88. const UNITTEST::TestPackedTypes& message);
  89. inline void ExpectPackedExtensionsModified(
  90. const UNITTEST::TestPackedExtensions& message);
  91. // Check that all fields have their default values.
  92. inline void ExpectClear(const UNITTEST::TestAllTypes& message);
  93. inline void ExpectExtensionsClear(const UNITTEST::TestAllExtensions& message);
  94. inline void ExpectPackedClear(const UNITTEST::TestPackedTypes& message);
  95. inline void ExpectPackedExtensionsClear(
  96. const UNITTEST::TestPackedExtensions& message);
  97. inline void ExpectOneofClear(const UNITTEST::TestOneof2& message);
  98. // Check that all repeated fields have had their last elements removed.
  99. inline void ExpectLastRepeatedsRemoved(const UNITTEST::TestAllTypes& message);
  100. inline void ExpectLastRepeatedExtensionsRemoved(
  101. const UNITTEST::TestAllExtensions& message);
  102. inline void ExpectLastRepeatedsReleased(const UNITTEST::TestAllTypes& message);
  103. inline void ExpectLastRepeatedExtensionsReleased(
  104. const UNITTEST::TestAllExtensions& message);
  105. // Check that all repeated fields have had their first and last elements
  106. // swapped.
  107. inline void ExpectRepeatedsSwapped(const UNITTEST::TestAllTypes& message);
  108. inline void ExpectRepeatedExtensionsSwapped(
  109. const UNITTEST::TestAllExtensions& message);
  110. inline void ExpectAtMostOneFieldSetInOneof(const UNITTEST::TestOneof2& message);
  111. } // namespace TestUtil
  112. inline void TestUtil::SetAllFields(UNITTEST::TestAllTypes* message) {
  113. SetOptionalFields(message);
  114. AddRepeatedFields1(message);
  115. AddRepeatedFields2(message);
  116. SetDefaultFields(message);
  117. SetOneofFields(message);
  118. }
  119. inline void TestUtil::SetOptionalFields(UNITTEST::TestAllTypes* message) {
  120. message->set_optional_int32(101);
  121. message->set_optional_int64(102);
  122. message->set_optional_uint32(103);
  123. message->set_optional_uint64(104);
  124. message->set_optional_sint32(105);
  125. message->set_optional_sint64(106);
  126. message->set_optional_fixed32(107);
  127. message->set_optional_fixed64(108);
  128. message->set_optional_sfixed32(109);
  129. message->set_optional_sfixed64(110);
  130. message->set_optional_float(111);
  131. message->set_optional_double(112);
  132. message->set_optional_bool(true);
  133. message->set_optional_string("115");
  134. message->set_optional_bytes("116");
  135. message->mutable_optionalgroup()->set_a(117);
  136. message->mutable_optional_nested_message()->set_bb(118);
  137. message->mutable_optional_foreign_message()->set_c(119);
  138. message->mutable_optional_import_message()->set_d(120);
  139. message->mutable_optional_public_import_message()->set_e(126);
  140. message->mutable_optional_lazy_message()->set_bb(127);
  141. message->set_optional_nested_enum(UNITTEST::TestAllTypes::BAZ);
  142. message->set_optional_foreign_enum(UNITTEST::FOREIGN_BAZ);
  143. message->set_optional_import_enum(UNITTEST_IMPORT::IMPORT_BAZ);
  144. // StringPiece and Cord fields are only accessible via reflection in the
  145. // open source release; see comments in compiler/cpp/string_field.cc.
  146. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  147. message->GetReflection()->SetString(
  148. message,
  149. message->GetDescriptor()->FindFieldByName("optional_string_piece"),
  150. "124");
  151. message->GetReflection()->SetString(
  152. message, message->GetDescriptor()->FindFieldByName("optional_cord"),
  153. "125");
  154. #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
  155. }
  156. // -------------------------------------------------------------------
  157. inline void TestUtil::AddRepeatedFields1(UNITTEST::TestAllTypes* message) {
  158. message->add_repeated_int32(201);
  159. message->add_repeated_int64(202);
  160. message->add_repeated_uint32(203);
  161. message->add_repeated_uint64(204);
  162. message->add_repeated_sint32(205);
  163. message->add_repeated_sint64(206);
  164. message->add_repeated_fixed32(207);
  165. message->add_repeated_fixed64(208);
  166. message->add_repeated_sfixed32(209);
  167. message->add_repeated_sfixed64(210);
  168. message->add_repeated_float(211);
  169. message->add_repeated_double(212);
  170. message->add_repeated_bool(true);
  171. message->add_repeated_string("215");
  172. message->add_repeated_bytes("216");
  173. message->add_repeatedgroup()->set_a(217);
  174. message->add_repeated_nested_message()->set_bb(218);
  175. message->add_repeated_foreign_message()->set_c(219);
  176. message->add_repeated_import_message()->set_d(220);
  177. message->add_repeated_lazy_message()->set_bb(227);
  178. message->add_repeated_nested_enum(UNITTEST::TestAllTypes::BAR);
  179. message->add_repeated_foreign_enum(UNITTEST::FOREIGN_BAR);
  180. message->add_repeated_import_enum(UNITTEST_IMPORT::IMPORT_BAR);
  181. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  182. message->GetReflection()->AddString(
  183. message,
  184. message->GetDescriptor()->FindFieldByName("repeated_string_piece"),
  185. "224");
  186. message->GetReflection()->AddString(
  187. message, message->GetDescriptor()->FindFieldByName("repeated_cord"),
  188. "225");
  189. #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
  190. }
  191. inline void TestUtil::AddRepeatedFields2(UNITTEST::TestAllTypes* message) {
  192. // Add a second one of each field.
  193. message->add_repeated_int32(301);
  194. message->add_repeated_int64(302);
  195. message->add_repeated_uint32(303);
  196. message->add_repeated_uint64(304);
  197. message->add_repeated_sint32(305);
  198. message->add_repeated_sint64(306);
  199. message->add_repeated_fixed32(307);
  200. message->add_repeated_fixed64(308);
  201. message->add_repeated_sfixed32(309);
  202. message->add_repeated_sfixed64(310);
  203. message->add_repeated_float(311);
  204. message->add_repeated_double(312);
  205. message->add_repeated_bool(false);
  206. message->add_repeated_string("315");
  207. message->add_repeated_bytes("316");
  208. message->add_repeatedgroup()->set_a(317);
  209. message->add_repeated_nested_message()->set_bb(318);
  210. message->add_repeated_foreign_message()->set_c(319);
  211. message->add_repeated_import_message()->set_d(320);
  212. message->add_repeated_lazy_message()->set_bb(327);
  213. message->add_repeated_nested_enum(UNITTEST::TestAllTypes::BAZ);
  214. message->add_repeated_foreign_enum(UNITTEST::FOREIGN_BAZ);
  215. message->add_repeated_import_enum(UNITTEST_IMPORT::IMPORT_BAZ);
  216. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  217. message->GetReflection()->AddString(
  218. message,
  219. message->GetDescriptor()->FindFieldByName("repeated_string_piece"),
  220. "324");
  221. message->GetReflection()->AddString(
  222. message, message->GetDescriptor()->FindFieldByName("repeated_cord"),
  223. "325");
  224. #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
  225. }
  226. // -------------------------------------------------------------------
  227. inline void TestUtil::SetDefaultFields(UNITTEST::TestAllTypes* message) {
  228. message->set_default_int32(401);
  229. message->set_default_int64(402);
  230. message->set_default_uint32(403);
  231. message->set_default_uint64(404);
  232. message->set_default_sint32(405);
  233. message->set_default_sint64(406);
  234. message->set_default_fixed32(407);
  235. message->set_default_fixed64(408);
  236. message->set_default_sfixed32(409);
  237. message->set_default_sfixed64(410);
  238. message->set_default_float(411);
  239. message->set_default_double(412);
  240. message->set_default_bool(false);
  241. message->set_default_string("415");
  242. message->set_default_bytes("416");
  243. message->set_default_nested_enum(UNITTEST::TestAllTypes::FOO);
  244. message->set_default_foreign_enum(UNITTEST::FOREIGN_FOO);
  245. message->set_default_import_enum(UNITTEST_IMPORT::IMPORT_FOO);
  246. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  247. message->GetReflection()->SetString(
  248. message,
  249. message->GetDescriptor()->FindFieldByName("default_string_piece"), "424");
  250. message->GetReflection()->SetString(
  251. message, message->GetDescriptor()->FindFieldByName("default_cord"),
  252. "425");
  253. #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
  254. }
  255. // -------------------------------------------------------------------
  256. inline void TestUtil::ModifyRepeatedFields(UNITTEST::TestAllTypes* message) {
  257. message->set_repeated_int32(1, 501);
  258. message->set_repeated_int64(1, 502);
  259. message->set_repeated_uint32(1, 503);
  260. message->set_repeated_uint64(1, 504);
  261. message->set_repeated_sint32(1, 505);
  262. message->set_repeated_sint64(1, 506);
  263. message->set_repeated_fixed32(1, 507);
  264. message->set_repeated_fixed64(1, 508);
  265. message->set_repeated_sfixed32(1, 509);
  266. message->set_repeated_sfixed64(1, 510);
  267. message->set_repeated_float(1, 511);
  268. message->set_repeated_double(1, 512);
  269. message->set_repeated_bool(1, true);
  270. message->set_repeated_string(1, "515");
  271. message->set_repeated_bytes(1, "516");
  272. message->mutable_repeatedgroup(1)->set_a(517);
  273. message->mutable_repeated_nested_message(1)->set_bb(518);
  274. message->mutable_repeated_foreign_message(1)->set_c(519);
  275. message->mutable_repeated_import_message(1)->set_d(520);
  276. message->mutable_repeated_lazy_message(1)->set_bb(527);
  277. message->set_repeated_nested_enum(1, UNITTEST::TestAllTypes::FOO);
  278. message->set_repeated_foreign_enum(1, UNITTEST::FOREIGN_FOO);
  279. message->set_repeated_import_enum(1, UNITTEST_IMPORT::IMPORT_FOO);
  280. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  281. message->GetReflection()->SetRepeatedString(
  282. message,
  283. message->GetDescriptor()->FindFieldByName("repeated_string_piece"), 1,
  284. "524");
  285. message->GetReflection()->SetRepeatedString(
  286. message, message->GetDescriptor()->FindFieldByName("repeated_cord"), 1,
  287. "525");
  288. #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
  289. }
  290. // ------------------------------------------------------------------
  291. inline void TestUtil::SetOneofFields(UNITTEST::TestAllTypes* message) {
  292. message->set_oneof_uint32(601);
  293. message->mutable_oneof_nested_message()->set_bb(602);
  294. message->set_oneof_string("603");
  295. message->set_oneof_bytes("604");
  296. }
  297. // -------------------------------------------------------------------
  298. inline void TestUtil::ExpectAllFieldsSet(
  299. const UNITTEST::TestAllTypes& message) {
  300. EXPECT_TRUE(message.has_optional_int32());
  301. EXPECT_TRUE(message.has_optional_int64());
  302. EXPECT_TRUE(message.has_optional_uint32());
  303. EXPECT_TRUE(message.has_optional_uint64());
  304. EXPECT_TRUE(message.has_optional_sint32());
  305. EXPECT_TRUE(message.has_optional_sint64());
  306. EXPECT_TRUE(message.has_optional_fixed32());
  307. EXPECT_TRUE(message.has_optional_fixed64());
  308. EXPECT_TRUE(message.has_optional_sfixed32());
  309. EXPECT_TRUE(message.has_optional_sfixed64());
  310. EXPECT_TRUE(message.has_optional_float());
  311. EXPECT_TRUE(message.has_optional_double());
  312. EXPECT_TRUE(message.has_optional_bool());
  313. EXPECT_TRUE(message.has_optional_string());
  314. EXPECT_TRUE(message.has_optional_bytes());
  315. EXPECT_TRUE(message.has_optionalgroup());
  316. EXPECT_TRUE(message.has_optional_nested_message());
  317. EXPECT_TRUE(message.has_optional_foreign_message());
  318. EXPECT_TRUE(message.has_optional_import_message());
  319. EXPECT_TRUE(message.has_optional_public_import_message());
  320. EXPECT_TRUE(message.has_optional_lazy_message());
  321. EXPECT_TRUE(message.optionalgroup().has_a());
  322. EXPECT_TRUE(message.optional_nested_message().has_bb());
  323. EXPECT_TRUE(message.optional_foreign_message().has_c());
  324. EXPECT_TRUE(message.optional_import_message().has_d());
  325. EXPECT_TRUE(message.optional_public_import_message().has_e());
  326. EXPECT_TRUE(message.optional_lazy_message().has_bb());
  327. EXPECT_TRUE(message.has_optional_nested_enum());
  328. EXPECT_TRUE(message.has_optional_foreign_enum());
  329. EXPECT_TRUE(message.has_optional_import_enum());
  330. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  331. EXPECT_TRUE(message.has_optional_string_piece());
  332. EXPECT_TRUE(message.has_optional_cord());
  333. #endif
  334. EXPECT_EQ(101, message.optional_int32());
  335. EXPECT_EQ(102, message.optional_int64());
  336. EXPECT_EQ(103, message.optional_uint32());
  337. EXPECT_EQ(104, message.optional_uint64());
  338. EXPECT_EQ(105, message.optional_sint32());
  339. EXPECT_EQ(106, message.optional_sint64());
  340. EXPECT_EQ(107, message.optional_fixed32());
  341. EXPECT_EQ(108, message.optional_fixed64());
  342. EXPECT_EQ(109, message.optional_sfixed32());
  343. EXPECT_EQ(110, message.optional_sfixed64());
  344. EXPECT_EQ(111, message.optional_float());
  345. EXPECT_EQ(112, message.optional_double());
  346. EXPECT_TRUE(message.optional_bool());
  347. EXPECT_EQ("115", message.optional_string());
  348. EXPECT_EQ("116", message.optional_bytes());
  349. EXPECT_EQ(117, message.optionalgroup().a());
  350. EXPECT_EQ(118, message.optional_nested_message().bb());
  351. EXPECT_EQ(119, message.optional_foreign_message().c());
  352. EXPECT_EQ(120, message.optional_import_message().d());
  353. EXPECT_EQ(126, message.optional_public_import_message().e());
  354. EXPECT_EQ(127, message.optional_lazy_message().bb());
  355. EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, message.optional_nested_enum());
  356. EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.optional_foreign_enum());
  357. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, message.optional_import_enum());
  358. // -----------------------------------------------------------------
  359. ASSERT_EQ(2, message.repeated_int32_size());
  360. ASSERT_EQ(2, message.repeated_int64_size());
  361. ASSERT_EQ(2, message.repeated_uint32_size());
  362. ASSERT_EQ(2, message.repeated_uint64_size());
  363. ASSERT_EQ(2, message.repeated_sint32_size());
  364. ASSERT_EQ(2, message.repeated_sint64_size());
  365. ASSERT_EQ(2, message.repeated_fixed32_size());
  366. ASSERT_EQ(2, message.repeated_fixed64_size());
  367. ASSERT_EQ(2, message.repeated_sfixed32_size());
  368. ASSERT_EQ(2, message.repeated_sfixed64_size());
  369. ASSERT_EQ(2, message.repeated_float_size());
  370. ASSERT_EQ(2, message.repeated_double_size());
  371. ASSERT_EQ(2, message.repeated_bool_size());
  372. ASSERT_EQ(2, message.repeated_string_size());
  373. ASSERT_EQ(2, message.repeated_bytes_size());
  374. ASSERT_EQ(2, message.repeatedgroup_size());
  375. ASSERT_EQ(2, message.repeated_nested_message_size());
  376. ASSERT_EQ(2, message.repeated_foreign_message_size());
  377. ASSERT_EQ(2, message.repeated_import_message_size());
  378. ASSERT_EQ(2, message.repeated_lazy_message_size());
  379. ASSERT_EQ(2, message.repeated_nested_enum_size());
  380. ASSERT_EQ(2, message.repeated_foreign_enum_size());
  381. ASSERT_EQ(2, message.repeated_import_enum_size());
  382. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  383. ASSERT_EQ(2, message.repeated_string_piece_size());
  384. ASSERT_EQ(2, message.repeated_cord_size());
  385. #endif
  386. EXPECT_EQ(201, message.repeated_int32(0));
  387. EXPECT_EQ(202, message.repeated_int64(0));
  388. EXPECT_EQ(203, message.repeated_uint32(0));
  389. EXPECT_EQ(204, message.repeated_uint64(0));
  390. EXPECT_EQ(205, message.repeated_sint32(0));
  391. EXPECT_EQ(206, message.repeated_sint64(0));
  392. EXPECT_EQ(207, message.repeated_fixed32(0));
  393. EXPECT_EQ(208, message.repeated_fixed64(0));
  394. EXPECT_EQ(209, message.repeated_sfixed32(0));
  395. EXPECT_EQ(210, message.repeated_sfixed64(0));
  396. EXPECT_EQ(211, message.repeated_float(0));
  397. EXPECT_EQ(212, message.repeated_double(0));
  398. EXPECT_TRUE(message.repeated_bool(0));
  399. EXPECT_EQ("215", message.repeated_string(0));
  400. EXPECT_EQ("216", message.repeated_bytes(0));
  401. EXPECT_EQ(217, message.repeatedgroup(0).a());
  402. EXPECT_EQ(218, message.repeated_nested_message(0).bb());
  403. EXPECT_EQ(219, message.repeated_foreign_message(0).c());
  404. EXPECT_EQ(220, message.repeated_import_message(0).d());
  405. EXPECT_EQ(227, message.repeated_lazy_message(0).bb());
  406. EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(0));
  407. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(0));
  408. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(0));
  409. EXPECT_EQ(301, message.repeated_int32(1));
  410. EXPECT_EQ(302, message.repeated_int64(1));
  411. EXPECT_EQ(303, message.repeated_uint32(1));
  412. EXPECT_EQ(304, message.repeated_uint64(1));
  413. EXPECT_EQ(305, message.repeated_sint32(1));
  414. EXPECT_EQ(306, message.repeated_sint64(1));
  415. EXPECT_EQ(307, message.repeated_fixed32(1));
  416. EXPECT_EQ(308, message.repeated_fixed64(1));
  417. EXPECT_EQ(309, message.repeated_sfixed32(1));
  418. EXPECT_EQ(310, message.repeated_sfixed64(1));
  419. EXPECT_EQ(311, message.repeated_float(1));
  420. EXPECT_EQ(312, message.repeated_double(1));
  421. EXPECT_FALSE(message.repeated_bool(1));
  422. EXPECT_EQ("315", message.repeated_string(1));
  423. EXPECT_EQ("316", message.repeated_bytes(1));
  424. EXPECT_EQ(317, message.repeatedgroup(1).a());
  425. EXPECT_EQ(318, message.repeated_nested_message(1).bb());
  426. EXPECT_EQ(319, message.repeated_foreign_message(1).c());
  427. EXPECT_EQ(320, message.repeated_import_message(1).d());
  428. EXPECT_EQ(327, message.repeated_lazy_message(1).bb());
  429. EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, message.repeated_nested_enum(1));
  430. EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.repeated_foreign_enum(1));
  431. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, message.repeated_import_enum(1));
  432. // -----------------------------------------------------------------
  433. EXPECT_TRUE(message.has_default_int32());
  434. EXPECT_TRUE(message.has_default_int64());
  435. EXPECT_TRUE(message.has_default_uint32());
  436. EXPECT_TRUE(message.has_default_uint64());
  437. EXPECT_TRUE(message.has_default_sint32());
  438. EXPECT_TRUE(message.has_default_sint64());
  439. EXPECT_TRUE(message.has_default_fixed32());
  440. EXPECT_TRUE(message.has_default_fixed64());
  441. EXPECT_TRUE(message.has_default_sfixed32());
  442. EXPECT_TRUE(message.has_default_sfixed64());
  443. EXPECT_TRUE(message.has_default_float());
  444. EXPECT_TRUE(message.has_default_double());
  445. EXPECT_TRUE(message.has_default_bool());
  446. EXPECT_TRUE(message.has_default_string());
  447. EXPECT_TRUE(message.has_default_bytes());
  448. EXPECT_TRUE(message.has_default_nested_enum());
  449. EXPECT_TRUE(message.has_default_foreign_enum());
  450. EXPECT_TRUE(message.has_default_import_enum());
  451. EXPECT_EQ(401, message.default_int32());
  452. EXPECT_EQ(402, message.default_int64());
  453. EXPECT_EQ(403, message.default_uint32());
  454. EXPECT_EQ(404, message.default_uint64());
  455. EXPECT_EQ(405, message.default_sint32());
  456. EXPECT_EQ(406, message.default_sint64());
  457. EXPECT_EQ(407, message.default_fixed32());
  458. EXPECT_EQ(408, message.default_fixed64());
  459. EXPECT_EQ(409, message.default_sfixed32());
  460. EXPECT_EQ(410, message.default_sfixed64());
  461. EXPECT_EQ(411, message.default_float());
  462. EXPECT_EQ(412, message.default_double());
  463. EXPECT_FALSE(message.default_bool());
  464. EXPECT_EQ("415", message.default_string());
  465. EXPECT_EQ("416", message.default_bytes());
  466. EXPECT_EQ(UNITTEST::TestAllTypes::FOO, message.default_nested_enum());
  467. EXPECT_EQ(UNITTEST::FOREIGN_FOO, message.default_foreign_enum());
  468. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, message.default_import_enum());
  469. EXPECT_FALSE(message.has_oneof_uint32());
  470. EXPECT_FALSE(message.has_oneof_nested_message());
  471. EXPECT_FALSE(message.has_oneof_string());
  472. EXPECT_TRUE(message.has_oneof_bytes());
  473. EXPECT_EQ("604", message.oneof_bytes());
  474. }
  475. // -------------------------------------------------------------------
  476. inline void TestUtil::ExpectClear(const UNITTEST::TestAllTypes& message) {
  477. // has_blah() should initially be false for all optional fields.
  478. EXPECT_FALSE(message.has_optional_int32());
  479. EXPECT_FALSE(message.has_optional_int64());
  480. EXPECT_FALSE(message.has_optional_uint32());
  481. EXPECT_FALSE(message.has_optional_uint64());
  482. EXPECT_FALSE(message.has_optional_sint32());
  483. EXPECT_FALSE(message.has_optional_sint64());
  484. EXPECT_FALSE(message.has_optional_fixed32());
  485. EXPECT_FALSE(message.has_optional_fixed64());
  486. EXPECT_FALSE(message.has_optional_sfixed32());
  487. EXPECT_FALSE(message.has_optional_sfixed64());
  488. EXPECT_FALSE(message.has_optional_float());
  489. EXPECT_FALSE(message.has_optional_double());
  490. EXPECT_FALSE(message.has_optional_bool());
  491. EXPECT_FALSE(message.has_optional_string());
  492. EXPECT_FALSE(message.has_optional_bytes());
  493. EXPECT_FALSE(message.has_optionalgroup());
  494. EXPECT_FALSE(message.has_optional_nested_message());
  495. EXPECT_FALSE(message.has_optional_foreign_message());
  496. EXPECT_FALSE(message.has_optional_import_message());
  497. EXPECT_FALSE(message.has_optional_public_import_message());
  498. EXPECT_FALSE(message.has_optional_lazy_message());
  499. EXPECT_FALSE(message.has_optional_nested_enum());
  500. EXPECT_FALSE(message.has_optional_foreign_enum());
  501. EXPECT_FALSE(message.has_optional_import_enum());
  502. EXPECT_FALSE(message.has_optional_string_piece());
  503. EXPECT_FALSE(message.has_optional_cord());
  504. // Optional fields without defaults are set to zero or something like it.
  505. EXPECT_EQ(0, message.optional_int32());
  506. EXPECT_EQ(0, message.optional_int64());
  507. EXPECT_EQ(0, message.optional_uint32());
  508. EXPECT_EQ(0, message.optional_uint64());
  509. EXPECT_EQ(0, message.optional_sint32());
  510. EXPECT_EQ(0, message.optional_sint64());
  511. EXPECT_EQ(0, message.optional_fixed32());
  512. EXPECT_EQ(0, message.optional_fixed64());
  513. EXPECT_EQ(0, message.optional_sfixed32());
  514. EXPECT_EQ(0, message.optional_sfixed64());
  515. EXPECT_EQ(0, message.optional_float());
  516. EXPECT_EQ(0, message.optional_double());
  517. EXPECT_FALSE(message.optional_bool());
  518. EXPECT_EQ("", message.optional_string());
  519. EXPECT_EQ("", message.optional_bytes());
  520. // Embedded messages should also be clear.
  521. EXPECT_FALSE(message.optionalgroup().has_a());
  522. EXPECT_FALSE(message.optional_nested_message().has_bb());
  523. EXPECT_FALSE(message.optional_foreign_message().has_c());
  524. EXPECT_FALSE(message.optional_import_message().has_d());
  525. EXPECT_FALSE(message.optional_public_import_message().has_e());
  526. EXPECT_FALSE(message.optional_lazy_message().has_bb());
  527. EXPECT_EQ(0, message.optionalgroup().a());
  528. EXPECT_EQ(0, message.optional_nested_message().bb());
  529. EXPECT_EQ(0, message.optional_foreign_message().c());
  530. EXPECT_EQ(0, message.optional_import_message().d());
  531. EXPECT_EQ(0, message.optional_public_import_message().e());
  532. EXPECT_EQ(0, message.optional_lazy_message().bb());
  533. // Enums without defaults are set to the first value in the enum.
  534. EXPECT_EQ(UNITTEST::TestAllTypes::FOO, message.optional_nested_enum());
  535. EXPECT_EQ(UNITTEST::FOREIGN_FOO, message.optional_foreign_enum());
  536. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, message.optional_import_enum());
  537. // Repeated fields are empty.
  538. EXPECT_EQ(0, message.repeated_int32_size());
  539. EXPECT_EQ(0, message.repeated_int64_size());
  540. EXPECT_EQ(0, message.repeated_uint32_size());
  541. EXPECT_EQ(0, message.repeated_uint64_size());
  542. EXPECT_EQ(0, message.repeated_sint32_size());
  543. EXPECT_EQ(0, message.repeated_sint64_size());
  544. EXPECT_EQ(0, message.repeated_fixed32_size());
  545. EXPECT_EQ(0, message.repeated_fixed64_size());
  546. EXPECT_EQ(0, message.repeated_sfixed32_size());
  547. EXPECT_EQ(0, message.repeated_sfixed64_size());
  548. EXPECT_EQ(0, message.repeated_float_size());
  549. EXPECT_EQ(0, message.repeated_double_size());
  550. EXPECT_EQ(0, message.repeated_bool_size());
  551. EXPECT_EQ(0, message.repeated_string_size());
  552. EXPECT_EQ(0, message.repeated_bytes_size());
  553. EXPECT_EQ(0, message.repeatedgroup_size());
  554. EXPECT_EQ(0, message.repeated_nested_message_size());
  555. EXPECT_EQ(0, message.repeated_foreign_message_size());
  556. EXPECT_EQ(0, message.repeated_import_message_size());
  557. EXPECT_EQ(0, message.repeated_lazy_message_size());
  558. EXPECT_EQ(0, message.repeated_nested_enum_size());
  559. EXPECT_EQ(0, message.repeated_foreign_enum_size());
  560. EXPECT_EQ(0, message.repeated_import_enum_size());
  561. EXPECT_EQ(0, message.repeated_string_piece_size());
  562. EXPECT_EQ(0, message.repeated_cord_size());
  563. // has_blah() should also be false for all default fields.
  564. EXPECT_FALSE(message.has_default_int32());
  565. EXPECT_FALSE(message.has_default_int64());
  566. EXPECT_FALSE(message.has_default_uint32());
  567. EXPECT_FALSE(message.has_default_uint64());
  568. EXPECT_FALSE(message.has_default_sint32());
  569. EXPECT_FALSE(message.has_default_sint64());
  570. EXPECT_FALSE(message.has_default_fixed32());
  571. EXPECT_FALSE(message.has_default_fixed64());
  572. EXPECT_FALSE(message.has_default_sfixed32());
  573. EXPECT_FALSE(message.has_default_sfixed64());
  574. EXPECT_FALSE(message.has_default_float());
  575. EXPECT_FALSE(message.has_default_double());
  576. EXPECT_FALSE(message.has_default_bool());
  577. EXPECT_FALSE(message.has_default_string());
  578. EXPECT_FALSE(message.has_default_bytes());
  579. EXPECT_FALSE(message.has_default_nested_enum());
  580. EXPECT_FALSE(message.has_default_foreign_enum());
  581. EXPECT_FALSE(message.has_default_import_enum());
  582. // Fields with defaults have their default values (duh).
  583. EXPECT_EQ(41, message.default_int32());
  584. EXPECT_EQ(42, message.default_int64());
  585. EXPECT_EQ(43, message.default_uint32());
  586. EXPECT_EQ(44, message.default_uint64());
  587. EXPECT_EQ(-45, message.default_sint32());
  588. EXPECT_EQ(46, message.default_sint64());
  589. EXPECT_EQ(47, message.default_fixed32());
  590. EXPECT_EQ(48, message.default_fixed64());
  591. EXPECT_EQ(49, message.default_sfixed32());
  592. EXPECT_EQ(-50, message.default_sfixed64());
  593. EXPECT_EQ(51.5, message.default_float());
  594. EXPECT_EQ(52e3, message.default_double());
  595. EXPECT_TRUE(message.default_bool());
  596. EXPECT_EQ("hello", message.default_string());
  597. EXPECT_EQ("world", message.default_bytes());
  598. EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.default_nested_enum());
  599. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.default_foreign_enum());
  600. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.default_import_enum());
  601. EXPECT_FALSE(message.has_oneof_uint32());
  602. EXPECT_FALSE(message.has_oneof_nested_message());
  603. EXPECT_FALSE(message.has_oneof_string());
  604. EXPECT_FALSE(message.has_oneof_bytes());
  605. }
  606. // -------------------------------------------------------------------
  607. inline void TestUtil::ExpectRepeatedFieldsModified(
  608. const UNITTEST::TestAllTypes& message) {
  609. // ModifyRepeatedFields only sets the second repeated element of each
  610. // field. In addition to verifying this, we also verify that the first
  611. // element and size were *not* modified.
  612. ASSERT_EQ(2, message.repeated_int32_size());
  613. ASSERT_EQ(2, message.repeated_int64_size());
  614. ASSERT_EQ(2, message.repeated_uint32_size());
  615. ASSERT_EQ(2, message.repeated_uint64_size());
  616. ASSERT_EQ(2, message.repeated_sint32_size());
  617. ASSERT_EQ(2, message.repeated_sint64_size());
  618. ASSERT_EQ(2, message.repeated_fixed32_size());
  619. ASSERT_EQ(2, message.repeated_fixed64_size());
  620. ASSERT_EQ(2, message.repeated_sfixed32_size());
  621. ASSERT_EQ(2, message.repeated_sfixed64_size());
  622. ASSERT_EQ(2, message.repeated_float_size());
  623. ASSERT_EQ(2, message.repeated_double_size());
  624. ASSERT_EQ(2, message.repeated_bool_size());
  625. ASSERT_EQ(2, message.repeated_string_size());
  626. ASSERT_EQ(2, message.repeated_bytes_size());
  627. ASSERT_EQ(2, message.repeatedgroup_size());
  628. ASSERT_EQ(2, message.repeated_nested_message_size());
  629. ASSERT_EQ(2, message.repeated_foreign_message_size());
  630. ASSERT_EQ(2, message.repeated_import_message_size());
  631. ASSERT_EQ(2, message.repeated_lazy_message_size());
  632. ASSERT_EQ(2, message.repeated_nested_enum_size());
  633. ASSERT_EQ(2, message.repeated_foreign_enum_size());
  634. ASSERT_EQ(2, message.repeated_import_enum_size());
  635. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  636. ASSERT_EQ(2, message.repeated_string_piece_size());
  637. ASSERT_EQ(2, message.repeated_cord_size());
  638. #endif
  639. EXPECT_EQ(201, message.repeated_int32(0));
  640. EXPECT_EQ(202, message.repeated_int64(0));
  641. EXPECT_EQ(203, message.repeated_uint32(0));
  642. EXPECT_EQ(204, message.repeated_uint64(0));
  643. EXPECT_EQ(205, message.repeated_sint32(0));
  644. EXPECT_EQ(206, message.repeated_sint64(0));
  645. EXPECT_EQ(207, message.repeated_fixed32(0));
  646. EXPECT_EQ(208, message.repeated_fixed64(0));
  647. EXPECT_EQ(209, message.repeated_sfixed32(0));
  648. EXPECT_EQ(210, message.repeated_sfixed64(0));
  649. EXPECT_EQ(211, message.repeated_float(0));
  650. EXPECT_EQ(212, message.repeated_double(0));
  651. EXPECT_TRUE(message.repeated_bool(0));
  652. EXPECT_EQ("215", message.repeated_string(0));
  653. EXPECT_EQ("216", message.repeated_bytes(0));
  654. EXPECT_EQ(217, message.repeatedgroup(0).a());
  655. EXPECT_EQ(218, message.repeated_nested_message(0).bb());
  656. EXPECT_EQ(219, message.repeated_foreign_message(0).c());
  657. EXPECT_EQ(220, message.repeated_import_message(0).d());
  658. EXPECT_EQ(227, message.repeated_lazy_message(0).bb());
  659. EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(0));
  660. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(0));
  661. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(0));
  662. // Actually verify the second (modified) elements now.
  663. EXPECT_EQ(501, message.repeated_int32(1));
  664. EXPECT_EQ(502, message.repeated_int64(1));
  665. EXPECT_EQ(503, message.repeated_uint32(1));
  666. EXPECT_EQ(504, message.repeated_uint64(1));
  667. EXPECT_EQ(505, message.repeated_sint32(1));
  668. EXPECT_EQ(506, message.repeated_sint64(1));
  669. EXPECT_EQ(507, message.repeated_fixed32(1));
  670. EXPECT_EQ(508, message.repeated_fixed64(1));
  671. EXPECT_EQ(509, message.repeated_sfixed32(1));
  672. EXPECT_EQ(510, message.repeated_sfixed64(1));
  673. EXPECT_EQ(511, message.repeated_float(1));
  674. EXPECT_EQ(512, message.repeated_double(1));
  675. EXPECT_TRUE(message.repeated_bool(1));
  676. EXPECT_EQ("515", message.repeated_string(1));
  677. EXPECT_EQ("516", message.repeated_bytes(1));
  678. EXPECT_EQ(517, message.repeatedgroup(1).a());
  679. EXPECT_EQ(518, message.repeated_nested_message(1).bb());
  680. EXPECT_EQ(519, message.repeated_foreign_message(1).c());
  681. EXPECT_EQ(520, message.repeated_import_message(1).d());
  682. EXPECT_EQ(527, message.repeated_lazy_message(1).bb());
  683. EXPECT_EQ(UNITTEST::TestAllTypes::FOO, message.repeated_nested_enum(1));
  684. EXPECT_EQ(UNITTEST::FOREIGN_FOO, message.repeated_foreign_enum(1));
  685. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, message.repeated_import_enum(1));
  686. }
  687. // -------------------------------------------------------------------
  688. inline void TestUtil::SetPackedFields(UNITTEST::TestPackedTypes* message) {
  689. message->add_packed_int32(601);
  690. message->add_packed_int64(602);
  691. message->add_packed_uint32(603);
  692. message->add_packed_uint64(604);
  693. message->add_packed_sint32(605);
  694. message->add_packed_sint64(606);
  695. message->add_packed_fixed32(607);
  696. message->add_packed_fixed64(608);
  697. message->add_packed_sfixed32(609);
  698. message->add_packed_sfixed64(610);
  699. message->add_packed_float(611);
  700. message->add_packed_double(612);
  701. message->add_packed_bool(true);
  702. message->add_packed_enum(UNITTEST::FOREIGN_BAR);
  703. // add a second one of each field
  704. message->add_packed_int32(701);
  705. message->add_packed_int64(702);
  706. message->add_packed_uint32(703);
  707. message->add_packed_uint64(704);
  708. message->add_packed_sint32(705);
  709. message->add_packed_sint64(706);
  710. message->add_packed_fixed32(707);
  711. message->add_packed_fixed64(708);
  712. message->add_packed_sfixed32(709);
  713. message->add_packed_sfixed64(710);
  714. message->add_packed_float(711);
  715. message->add_packed_double(712);
  716. message->add_packed_bool(false);
  717. message->add_packed_enum(UNITTEST::FOREIGN_BAZ);
  718. }
  719. inline void TestUtil::SetUnpackedFields(UNITTEST::TestUnpackedTypes* message) {
  720. // The values applied here must match those of SetPackedFields.
  721. message->add_unpacked_int32(601);
  722. message->add_unpacked_int64(602);
  723. message->add_unpacked_uint32(603);
  724. message->add_unpacked_uint64(604);
  725. message->add_unpacked_sint32(605);
  726. message->add_unpacked_sint64(606);
  727. message->add_unpacked_fixed32(607);
  728. message->add_unpacked_fixed64(608);
  729. message->add_unpacked_sfixed32(609);
  730. message->add_unpacked_sfixed64(610);
  731. message->add_unpacked_float(611);
  732. message->add_unpacked_double(612);
  733. message->add_unpacked_bool(true);
  734. message->add_unpacked_enum(UNITTEST::FOREIGN_BAR);
  735. // add a second one of each field
  736. message->add_unpacked_int32(701);
  737. message->add_unpacked_int64(702);
  738. message->add_unpacked_uint32(703);
  739. message->add_unpacked_uint64(704);
  740. message->add_unpacked_sint32(705);
  741. message->add_unpacked_sint64(706);
  742. message->add_unpacked_fixed32(707);
  743. message->add_unpacked_fixed64(708);
  744. message->add_unpacked_sfixed32(709);
  745. message->add_unpacked_sfixed64(710);
  746. message->add_unpacked_float(711);
  747. message->add_unpacked_double(712);
  748. message->add_unpacked_bool(false);
  749. message->add_unpacked_enum(UNITTEST::FOREIGN_BAZ);
  750. }
  751. // -------------------------------------------------------------------
  752. inline void TestUtil::ModifyPackedFields(UNITTEST::TestPackedTypes* message) {
  753. message->set_packed_int32(1, 801);
  754. message->set_packed_int64(1, 802);
  755. message->set_packed_uint32(1, 803);
  756. message->set_packed_uint64(1, 804);
  757. message->set_packed_sint32(1, 805);
  758. message->set_packed_sint64(1, 806);
  759. message->set_packed_fixed32(1, 807);
  760. message->set_packed_fixed64(1, 808);
  761. message->set_packed_sfixed32(1, 809);
  762. message->set_packed_sfixed64(1, 810);
  763. message->set_packed_float(1, 811);
  764. message->set_packed_double(1, 812);
  765. message->set_packed_bool(1, true);
  766. message->set_packed_enum(1, UNITTEST::FOREIGN_FOO);
  767. }
  768. // -------------------------------------------------------------------
  769. inline void TestUtil::ExpectPackedFieldsSet(
  770. const UNITTEST::TestPackedTypes& message) {
  771. ASSERT_EQ(2, message.packed_int32_size());
  772. ASSERT_EQ(2, message.packed_int64_size());
  773. ASSERT_EQ(2, message.packed_uint32_size());
  774. ASSERT_EQ(2, message.packed_uint64_size());
  775. ASSERT_EQ(2, message.packed_sint32_size());
  776. ASSERT_EQ(2, message.packed_sint64_size());
  777. ASSERT_EQ(2, message.packed_fixed32_size());
  778. ASSERT_EQ(2, message.packed_fixed64_size());
  779. ASSERT_EQ(2, message.packed_sfixed32_size());
  780. ASSERT_EQ(2, message.packed_sfixed64_size());
  781. ASSERT_EQ(2, message.packed_float_size());
  782. ASSERT_EQ(2, message.packed_double_size());
  783. ASSERT_EQ(2, message.packed_bool_size());
  784. ASSERT_EQ(2, message.packed_enum_size());
  785. EXPECT_EQ(601, message.packed_int32(0));
  786. EXPECT_EQ(602, message.packed_int64(0));
  787. EXPECT_EQ(603, message.packed_uint32(0));
  788. EXPECT_EQ(604, message.packed_uint64(0));
  789. EXPECT_EQ(605, message.packed_sint32(0));
  790. EXPECT_EQ(606, message.packed_sint64(0));
  791. EXPECT_EQ(607, message.packed_fixed32(0));
  792. EXPECT_EQ(608, message.packed_fixed64(0));
  793. EXPECT_EQ(609, message.packed_sfixed32(0));
  794. EXPECT_EQ(610, message.packed_sfixed64(0));
  795. EXPECT_EQ(611, message.packed_float(0));
  796. EXPECT_EQ(612, message.packed_double(0));
  797. EXPECT_TRUE(message.packed_bool(0));
  798. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.packed_enum(0));
  799. EXPECT_EQ(701, message.packed_int32(1));
  800. EXPECT_EQ(702, message.packed_int64(1));
  801. EXPECT_EQ(703, message.packed_uint32(1));
  802. EXPECT_EQ(704, message.packed_uint64(1));
  803. EXPECT_EQ(705, message.packed_sint32(1));
  804. EXPECT_EQ(706, message.packed_sint64(1));
  805. EXPECT_EQ(707, message.packed_fixed32(1));
  806. EXPECT_EQ(708, message.packed_fixed64(1));
  807. EXPECT_EQ(709, message.packed_sfixed32(1));
  808. EXPECT_EQ(710, message.packed_sfixed64(1));
  809. EXPECT_EQ(711, message.packed_float(1));
  810. EXPECT_EQ(712, message.packed_double(1));
  811. EXPECT_FALSE(message.packed_bool(1));
  812. EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.packed_enum(1));
  813. }
  814. inline void TestUtil::ExpectUnpackedFieldsSet(
  815. const UNITTEST::TestUnpackedTypes& message) {
  816. // The values expected here must match those of ExpectPackedFieldsSet.
  817. ASSERT_EQ(2, message.unpacked_int32_size());
  818. ASSERT_EQ(2, message.unpacked_int64_size());
  819. ASSERT_EQ(2, message.unpacked_uint32_size());
  820. ASSERT_EQ(2, message.unpacked_uint64_size());
  821. ASSERT_EQ(2, message.unpacked_sint32_size());
  822. ASSERT_EQ(2, message.unpacked_sint64_size());
  823. ASSERT_EQ(2, message.unpacked_fixed32_size());
  824. ASSERT_EQ(2, message.unpacked_fixed64_size());
  825. ASSERT_EQ(2, message.unpacked_sfixed32_size());
  826. ASSERT_EQ(2, message.unpacked_sfixed64_size());
  827. ASSERT_EQ(2, message.unpacked_float_size());
  828. ASSERT_EQ(2, message.unpacked_double_size());
  829. ASSERT_EQ(2, message.unpacked_bool_size());
  830. ASSERT_EQ(2, message.unpacked_enum_size());
  831. EXPECT_EQ(601, message.unpacked_int32(0));
  832. EXPECT_EQ(602, message.unpacked_int64(0));
  833. EXPECT_EQ(603, message.unpacked_uint32(0));
  834. EXPECT_EQ(604, message.unpacked_uint64(0));
  835. EXPECT_EQ(605, message.unpacked_sint32(0));
  836. EXPECT_EQ(606, message.unpacked_sint64(0));
  837. EXPECT_EQ(607, message.unpacked_fixed32(0));
  838. EXPECT_EQ(608, message.unpacked_fixed64(0));
  839. EXPECT_EQ(609, message.unpacked_sfixed32(0));
  840. EXPECT_EQ(610, message.unpacked_sfixed64(0));
  841. EXPECT_EQ(611, message.unpacked_float(0));
  842. EXPECT_EQ(612, message.unpacked_double(0));
  843. EXPECT_TRUE(message.unpacked_bool(0));
  844. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.unpacked_enum(0));
  845. EXPECT_EQ(701, message.unpacked_int32(1));
  846. EXPECT_EQ(702, message.unpacked_int64(1));
  847. EXPECT_EQ(703, message.unpacked_uint32(1));
  848. EXPECT_EQ(704, message.unpacked_uint64(1));
  849. EXPECT_EQ(705, message.unpacked_sint32(1));
  850. EXPECT_EQ(706, message.unpacked_sint64(1));
  851. EXPECT_EQ(707, message.unpacked_fixed32(1));
  852. EXPECT_EQ(708, message.unpacked_fixed64(1));
  853. EXPECT_EQ(709, message.unpacked_sfixed32(1));
  854. EXPECT_EQ(710, message.unpacked_sfixed64(1));
  855. EXPECT_EQ(711, message.unpacked_float(1));
  856. EXPECT_EQ(712, message.unpacked_double(1));
  857. EXPECT_FALSE(message.unpacked_bool(1));
  858. EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.unpacked_enum(1));
  859. }
  860. // -------------------------------------------------------------------
  861. inline void TestUtil::ExpectPackedClear(
  862. const UNITTEST::TestPackedTypes& message) {
  863. // Packed repeated fields are empty.
  864. EXPECT_EQ(0, message.packed_int32_size());
  865. EXPECT_EQ(0, message.packed_int64_size());
  866. EXPECT_EQ(0, message.packed_uint32_size());
  867. EXPECT_EQ(0, message.packed_uint64_size());
  868. EXPECT_EQ(0, message.packed_sint32_size());
  869. EXPECT_EQ(0, message.packed_sint64_size());
  870. EXPECT_EQ(0, message.packed_fixed32_size());
  871. EXPECT_EQ(0, message.packed_fixed64_size());
  872. EXPECT_EQ(0, message.packed_sfixed32_size());
  873. EXPECT_EQ(0, message.packed_sfixed64_size());
  874. EXPECT_EQ(0, message.packed_float_size());
  875. EXPECT_EQ(0, message.packed_double_size());
  876. EXPECT_EQ(0, message.packed_bool_size());
  877. EXPECT_EQ(0, message.packed_enum_size());
  878. }
  879. // -------------------------------------------------------------------
  880. inline void TestUtil::ExpectPackedFieldsModified(
  881. const UNITTEST::TestPackedTypes& message) {
  882. // Do the same for packed repeated fields.
  883. ASSERT_EQ(2, message.packed_int32_size());
  884. ASSERT_EQ(2, message.packed_int64_size());
  885. ASSERT_EQ(2, message.packed_uint32_size());
  886. ASSERT_EQ(2, message.packed_uint64_size());
  887. ASSERT_EQ(2, message.packed_sint32_size());
  888. ASSERT_EQ(2, message.packed_sint64_size());
  889. ASSERT_EQ(2, message.packed_fixed32_size());
  890. ASSERT_EQ(2, message.packed_fixed64_size());
  891. ASSERT_EQ(2, message.packed_sfixed32_size());
  892. ASSERT_EQ(2, message.packed_sfixed64_size());
  893. ASSERT_EQ(2, message.packed_float_size());
  894. ASSERT_EQ(2, message.packed_double_size());
  895. ASSERT_EQ(2, message.packed_bool_size());
  896. ASSERT_EQ(2, message.packed_enum_size());
  897. EXPECT_EQ(601, message.packed_int32(0));
  898. EXPECT_EQ(602, message.packed_int64(0));
  899. EXPECT_EQ(603, message.packed_uint32(0));
  900. EXPECT_EQ(604, message.packed_uint64(0));
  901. EXPECT_EQ(605, message.packed_sint32(0));
  902. EXPECT_EQ(606, message.packed_sint64(0));
  903. EXPECT_EQ(607, message.packed_fixed32(0));
  904. EXPECT_EQ(608, message.packed_fixed64(0));
  905. EXPECT_EQ(609, message.packed_sfixed32(0));
  906. EXPECT_EQ(610, message.packed_sfixed64(0));
  907. EXPECT_EQ(611, message.packed_float(0));
  908. EXPECT_EQ(612, message.packed_double(0));
  909. EXPECT_TRUE(message.packed_bool(0));
  910. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.packed_enum(0));
  911. // Actually verify the second (modified) elements now.
  912. EXPECT_EQ(801, message.packed_int32(1));
  913. EXPECT_EQ(802, message.packed_int64(1));
  914. EXPECT_EQ(803, message.packed_uint32(1));
  915. EXPECT_EQ(804, message.packed_uint64(1));
  916. EXPECT_EQ(805, message.packed_sint32(1));
  917. EXPECT_EQ(806, message.packed_sint64(1));
  918. EXPECT_EQ(807, message.packed_fixed32(1));
  919. EXPECT_EQ(808, message.packed_fixed64(1));
  920. EXPECT_EQ(809, message.packed_sfixed32(1));
  921. EXPECT_EQ(810, message.packed_sfixed64(1));
  922. EXPECT_EQ(811, message.packed_float(1));
  923. EXPECT_EQ(812, message.packed_double(1));
  924. EXPECT_TRUE(message.packed_bool(1));
  925. EXPECT_EQ(UNITTEST::FOREIGN_FOO, message.packed_enum(1));
  926. }
  927. // ===================================================================
  928. // Extensions
  929. //
  930. // All this code is exactly equivalent to the above code except that it's
  931. // manipulating extension fields instead of normal ones.
  932. inline void TestUtil::SetAllExtensions(UNITTEST::TestAllExtensions* message) {
  933. message->SetExtension(UNITTEST::optional_int32_extension, 101);
  934. message->SetExtension(UNITTEST::optional_int64_extension, 102);
  935. message->SetExtension(UNITTEST::optional_uint32_extension, 103);
  936. message->SetExtension(UNITTEST::optional_uint64_extension, 104);
  937. message->SetExtension(UNITTEST::optional_sint32_extension, 105);
  938. message->SetExtension(UNITTEST::optional_sint64_extension, 106);
  939. message->SetExtension(UNITTEST::optional_fixed32_extension, 107);
  940. message->SetExtension(UNITTEST::optional_fixed64_extension, 108);
  941. message->SetExtension(UNITTEST::optional_sfixed32_extension, 109);
  942. message->SetExtension(UNITTEST::optional_sfixed64_extension, 110);
  943. message->SetExtension(UNITTEST::optional_float_extension, 111);
  944. message->SetExtension(UNITTEST::optional_double_extension, 112);
  945. message->SetExtension(UNITTEST::optional_bool_extension, true);
  946. message->SetExtension(UNITTEST::optional_string_extension, "115");
  947. message->SetExtension(UNITTEST::optional_bytes_extension, "116");
  948. message->MutableExtension(UNITTEST::optionalgroup_extension)->set_a(117);
  949. message->MutableExtension(UNITTEST::optional_nested_message_extension)
  950. ->set_bb(118);
  951. message->MutableExtension(UNITTEST::optional_foreign_message_extension)
  952. ->set_c(119);
  953. message->MutableExtension(UNITTEST::optional_import_message_extension)
  954. ->set_d(120);
  955. message->SetExtension(UNITTEST::optional_nested_enum_extension,
  956. UNITTEST::TestAllTypes::BAZ);
  957. message->SetExtension(UNITTEST::optional_foreign_enum_extension,
  958. UNITTEST::FOREIGN_BAZ);
  959. message->SetExtension(UNITTEST::optional_import_enum_extension,
  960. UNITTEST_IMPORT::IMPORT_BAZ);
  961. message->SetExtension(UNITTEST::optional_string_piece_extension, "124");
  962. message->SetExtension(UNITTEST::optional_cord_extension, "125");
  963. message->MutableExtension(UNITTEST::optional_public_import_message_extension)
  964. ->set_e(126);
  965. message->MutableExtension(UNITTEST::optional_lazy_message_extension)
  966. ->set_bb(127);
  967. // -----------------------------------------------------------------
  968. message->AddExtension(UNITTEST::repeated_int32_extension, 201);
  969. message->AddExtension(UNITTEST::repeated_int64_extension, 202);
  970. message->AddExtension(UNITTEST::repeated_uint32_extension, 203);
  971. message->AddExtension(UNITTEST::repeated_uint64_extension, 204);
  972. message->AddExtension(UNITTEST::repeated_sint32_extension, 205);
  973. message->AddExtension(UNITTEST::repeated_sint64_extension, 206);
  974. message->AddExtension(UNITTEST::repeated_fixed32_extension, 207);
  975. message->AddExtension(UNITTEST::repeated_fixed64_extension, 208);
  976. message->AddExtension(UNITTEST::repeated_sfixed32_extension, 209);
  977. message->AddExtension(UNITTEST::repeated_sfixed64_extension, 210);
  978. message->AddExtension(UNITTEST::repeated_float_extension, 211);
  979. message->AddExtension(UNITTEST::repeated_double_extension, 212);
  980. message->AddExtension(UNITTEST::repeated_bool_extension, true);
  981. message->AddExtension(UNITTEST::repeated_string_extension, "215");
  982. message->AddExtension(UNITTEST::repeated_bytes_extension, "216");
  983. message->AddExtension(UNITTEST::repeatedgroup_extension)->set_a(217);
  984. message->AddExtension(UNITTEST::repeated_nested_message_extension)
  985. ->set_bb(218);
  986. message->AddExtension(UNITTEST::repeated_foreign_message_extension)
  987. ->set_c(219);
  988. message->AddExtension(UNITTEST::repeated_import_message_extension)
  989. ->set_d(220);
  990. message->AddExtension(UNITTEST::repeated_lazy_message_extension)->set_bb(227);
  991. message->AddExtension(UNITTEST::repeated_nested_enum_extension,
  992. UNITTEST::TestAllTypes::BAR);
  993. message->AddExtension(UNITTEST::repeated_foreign_enum_extension,
  994. UNITTEST::FOREIGN_BAR);
  995. message->AddExtension(UNITTEST::repeated_import_enum_extension,
  996. UNITTEST_IMPORT::IMPORT_BAR);
  997. message->AddExtension(UNITTEST::repeated_string_piece_extension, "224");
  998. message->AddExtension(UNITTEST::repeated_cord_extension, "225");
  999. // Add a second one of each field.
  1000. message->AddExtension(UNITTEST::repeated_int32_extension, 301);
  1001. message->AddExtension(UNITTEST::repeated_int64_extension, 302);
  1002. message->AddExtension(UNITTEST::repeated_uint32_extension, 303);
  1003. message->AddExtension(UNITTEST::repeated_uint64_extension, 304);
  1004. message->AddExtension(UNITTEST::repeated_sint32_extension, 305);
  1005. message->AddExtension(UNITTEST::repeated_sint64_extension, 306);
  1006. message->AddExtension(UNITTEST::repeated_fixed32_extension, 307);
  1007. message->AddExtension(UNITTEST::repeated_fixed64_extension, 308);
  1008. message->AddExtension(UNITTEST::repeated_sfixed32_extension, 309);
  1009. message->AddExtension(UNITTEST::repeated_sfixed64_extension, 310);
  1010. message->AddExtension(UNITTEST::repeated_float_extension, 311);
  1011. message->AddExtension(UNITTEST::repeated_double_extension, 312);
  1012. message->AddExtension(UNITTEST::repeated_bool_extension, false);
  1013. message->AddExtension(UNITTEST::repeated_string_extension, "315");
  1014. message->AddExtension(UNITTEST::repeated_bytes_extension, "316");
  1015. message->AddExtension(UNITTEST::repeatedgroup_extension)->set_a(317);
  1016. message->AddExtension(UNITTEST::repeated_nested_message_extension)
  1017. ->set_bb(318);
  1018. message->AddExtension(UNITTEST::repeated_foreign_message_extension)
  1019. ->set_c(319);
  1020. message->AddExtension(UNITTEST::repeated_import_message_extension)
  1021. ->set_d(320);
  1022. message->AddExtension(UNITTEST::repeated_lazy_message_extension)->set_bb(327);
  1023. message->AddExtension(UNITTEST::repeated_nested_enum_extension,
  1024. UNITTEST::TestAllTypes::BAZ);
  1025. message->AddExtension(UNITTEST::repeated_foreign_enum_extension,
  1026. UNITTEST::FOREIGN_BAZ);
  1027. message->AddExtension(UNITTEST::repeated_import_enum_extension,
  1028. UNITTEST_IMPORT::IMPORT_BAZ);
  1029. message->AddExtension(UNITTEST::repeated_string_piece_extension, "324");
  1030. message->AddExtension(UNITTEST::repeated_cord_extension, "325");
  1031. // -----------------------------------------------------------------
  1032. message->SetExtension(UNITTEST::default_int32_extension, 401);
  1033. message->SetExtension(UNITTEST::default_int64_extension, 402);
  1034. message->SetExtension(UNITTEST::default_uint32_extension, 403);
  1035. message->SetExtension(UNITTEST::default_uint64_extension, 404);
  1036. message->SetExtension(UNITTEST::default_sint32_extension, 405);
  1037. message->SetExtension(UNITTEST::default_sint64_extension, 406);
  1038. message->SetExtension(UNITTEST::default_fixed32_extension, 407);
  1039. message->SetExtension(UNITTEST::default_fixed64_extension, 408);
  1040. message->SetExtension(UNITTEST::default_sfixed32_extension, 409);
  1041. message->SetExtension(UNITTEST::default_sfixed64_extension, 410);
  1042. message->SetExtension(UNITTEST::default_float_extension, 411);
  1043. message->SetExtension(UNITTEST::default_double_extension, 412);
  1044. message->SetExtension(UNITTEST::default_bool_extension, false);
  1045. message->SetExtension(UNITTEST::default_string_extension, "415");
  1046. message->SetExtension(UNITTEST::default_bytes_extension, "416");
  1047. message->SetExtension(UNITTEST::default_nested_enum_extension,
  1048. UNITTEST::TestAllTypes::FOO);
  1049. message->SetExtension(UNITTEST::default_foreign_enum_extension,
  1050. UNITTEST::FOREIGN_FOO);
  1051. message->SetExtension(UNITTEST::default_import_enum_extension,
  1052. UNITTEST_IMPORT::IMPORT_FOO);
  1053. message->SetExtension(UNITTEST::default_string_piece_extension, "424");
  1054. message->SetExtension(UNITTEST::default_cord_extension, "425");
  1055. SetOneofFields(message);
  1056. }
  1057. inline void TestUtil::SetOneofFields(UNITTEST::TestAllExtensions* message) {
  1058. message->SetExtension(UNITTEST::oneof_uint32_extension, 601);
  1059. message->MutableExtension(UNITTEST::oneof_nested_message_extension)
  1060. ->set_bb(602);
  1061. message->SetExtension(UNITTEST::oneof_string_extension, "603");
  1062. message->SetExtension(UNITTEST::oneof_bytes_extension, "604");
  1063. }
  1064. // -------------------------------------------------------------------
  1065. inline void TestUtil::SetAllFieldsAndExtensions(
  1066. UNITTEST::TestFieldOrderings* message) {
  1067. GOOGLE_CHECK(message);
  1068. message->set_my_int(1);
  1069. message->set_my_string("foo");
  1070. message->set_my_float(1.0);
  1071. message->SetExtension(UNITTEST::my_extension_int, 23);
  1072. message->SetExtension(UNITTEST::my_extension_string, "bar");
  1073. }
  1074. // -------------------------------------------------------------------
  1075. inline void TestUtil::ModifyRepeatedExtensions(
  1076. UNITTEST::TestAllExtensions* message) {
  1077. message->SetExtension(UNITTEST::repeated_int32_extension, 1, 501);
  1078. message->SetExtension(UNITTEST::repeated_int64_extension, 1, 502);
  1079. message->SetExtension(UNITTEST::repeated_uint32_extension, 1, 503);
  1080. message->SetExtension(UNITTEST::repeated_uint64_extension, 1, 504);
  1081. message->SetExtension(UNITTEST::repeated_sint32_extension, 1, 505);
  1082. message->SetExtension(UNITTEST::repeated_sint64_extension, 1, 506);
  1083. message->SetExtension(UNITTEST::repeated_fixed32_extension, 1, 507);
  1084. message->SetExtension(UNITTEST::repeated_fixed64_extension, 1, 508);
  1085. message->SetExtension(UNITTEST::repeated_sfixed32_extension, 1, 509);
  1086. message->SetExtension(UNITTEST::repeated_sfixed64_extension, 1, 510);
  1087. message->SetExtension(UNITTEST::repeated_float_extension, 1, 511);
  1088. message->SetExtension(UNITTEST::repeated_double_extension, 1, 512);
  1089. message->SetExtension(UNITTEST::repeated_bool_extension, 1, true);
  1090. message->SetExtension(UNITTEST::repeated_string_extension, 1, "515");
  1091. message->SetExtension(UNITTEST::repeated_bytes_extension, 1, "516");
  1092. message->MutableExtension(UNITTEST::repeatedgroup_extension, 1)->set_a(517);
  1093. message->MutableExtension(UNITTEST::repeated_nested_message_extension, 1)
  1094. ->set_bb(518);
  1095. message->MutableExtension(UNITTEST::repeated_foreign_message_extension, 1)
  1096. ->set_c(519);
  1097. message->MutableExtension(UNITTEST::repeated_import_message_extension, 1)
  1098. ->set_d(520);
  1099. message->MutableExtension(UNITTEST::repeated_lazy_message_extension, 1)
  1100. ->set_bb(527);
  1101. message->SetExtension(UNITTEST::repeated_nested_enum_extension, 1,
  1102. UNITTEST::TestAllTypes::FOO);
  1103. message->SetExtension(UNITTEST::repeated_foreign_enum_extension, 1,
  1104. UNITTEST::FOREIGN_FOO);
  1105. message->SetExtension(UNITTEST::repeated_import_enum_extension, 1,
  1106. UNITTEST_IMPORT::IMPORT_FOO);
  1107. message->SetExtension(UNITTEST::repeated_string_piece_extension, 1, "524");
  1108. message->SetExtension(UNITTEST::repeated_cord_extension, 1, "525");
  1109. }
  1110. // -------------------------------------------------------------------
  1111. inline void TestUtil::ExpectAllExtensionsSet(
  1112. const UNITTEST::TestAllExtensions& message) {
  1113. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_int32_extension));
  1114. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_int64_extension));
  1115. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_uint32_extension));
  1116. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_uint64_extension));
  1117. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sint32_extension));
  1118. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sint64_extension));
  1119. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_fixed32_extension));
  1120. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_fixed64_extension));
  1121. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sfixed32_extension));
  1122. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sfixed64_extension));
  1123. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_float_extension));
  1124. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_double_extension));
  1125. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_bool_extension));
  1126. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_string_extension));
  1127. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_bytes_extension));
  1128. EXPECT_TRUE(message.HasExtension(UNITTEST::optionalgroup_extension));
  1129. EXPECT_TRUE(
  1130. message.HasExtension(UNITTEST::optional_nested_message_extension));
  1131. EXPECT_TRUE(
  1132. message.HasExtension(UNITTEST::optional_foreign_message_extension));
  1133. EXPECT_TRUE(
  1134. message.HasExtension(UNITTEST::optional_import_message_extension));
  1135. EXPECT_TRUE(
  1136. message.HasExtension(UNITTEST::optional_public_import_message_extension));
  1137. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_lazy_message_extension));
  1138. EXPECT_TRUE(message.GetExtension(UNITTEST::optionalgroup_extension).has_a());
  1139. EXPECT_TRUE(message.GetExtension(UNITTEST::optional_nested_message_extension)
  1140. .has_bb());
  1141. EXPECT_TRUE(message.GetExtension(UNITTEST::optional_foreign_message_extension)
  1142. .has_c());
  1143. EXPECT_TRUE(message.GetExtension(UNITTEST::optional_import_message_extension)
  1144. .has_d());
  1145. EXPECT_TRUE(
  1146. message.GetExtension(UNITTEST::optional_public_import_message_extension)
  1147. .has_e());
  1148. EXPECT_TRUE(
  1149. message.GetExtension(UNITTEST::optional_lazy_message_extension).has_bb());
  1150. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_nested_enum_extension));
  1151. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_foreign_enum_extension));
  1152. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_import_enum_extension));
  1153. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_string_piece_extension));
  1154. EXPECT_TRUE(message.HasExtension(UNITTEST::optional_cord_extension));
  1155. EXPECT_EQ(101, message.GetExtension(UNITTEST::optional_int32_extension));
  1156. EXPECT_EQ(102, message.GetExtension(UNITTEST::optional_int64_extension));
  1157. EXPECT_EQ(103, message.GetExtension(UNITTEST::optional_uint32_extension));
  1158. EXPECT_EQ(104, message.GetExtension(UNITTEST::optional_uint64_extension));
  1159. EXPECT_EQ(105, message.GetExtension(UNITTEST::optional_sint32_extension));
  1160. EXPECT_EQ(106, message.GetExtension(UNITTEST::optional_sint64_extension));
  1161. EXPECT_EQ(107, message.GetExtension(UNITTEST::optional_fixed32_extension));
  1162. EXPECT_EQ(108, message.GetExtension(UNITTEST::optional_fixed64_extension));
  1163. EXPECT_EQ(109, message.GetExtension(UNITTEST::optional_sfixed32_extension));
  1164. EXPECT_EQ(110, message.GetExtension(UNITTEST::optional_sfixed64_extension));
  1165. EXPECT_EQ(111, message.GetExtension(UNITTEST::optional_float_extension));
  1166. EXPECT_EQ(112, message.GetExtension(UNITTEST::optional_double_extension));
  1167. EXPECT_TRUE(message.GetExtension(UNITTEST::optional_bool_extension));
  1168. EXPECT_EQ("115", message.GetExtension(UNITTEST::optional_string_extension));
  1169. EXPECT_EQ("116", message.GetExtension(UNITTEST::optional_bytes_extension));
  1170. EXPECT_EQ(117, message.GetExtension(UNITTEST::optionalgroup_extension).a());
  1171. EXPECT_EQ(
  1172. 118,
  1173. message.GetExtension(UNITTEST::optional_nested_message_extension).bb());
  1174. EXPECT_EQ(
  1175. 119,
  1176. message.GetExtension(UNITTEST::optional_foreign_message_extension).c());
  1177. EXPECT_EQ(
  1178. 120,
  1179. message.GetExtension(UNITTEST::optional_import_message_extension).d());
  1180. EXPECT_EQ(UNITTEST::TestAllTypes::BAZ,
  1181. message.GetExtension(UNITTEST::optional_nested_enum_extension));
  1182. EXPECT_EQ(UNITTEST::FOREIGN_BAZ,
  1183. message.GetExtension(UNITTEST::optional_foreign_enum_extension));
  1184. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ,
  1185. message.GetExtension(UNITTEST::optional_import_enum_extension));
  1186. EXPECT_EQ("124",
  1187. message.GetExtension(UNITTEST::optional_string_piece_extension));
  1188. EXPECT_EQ("125", message.GetExtension(UNITTEST::optional_cord_extension));
  1189. EXPECT_EQ(
  1190. 126,
  1191. message.GetExtension(UNITTEST::optional_public_import_message_extension)
  1192. .e());
  1193. EXPECT_EQ(
  1194. 127,
  1195. message.GetExtension(UNITTEST::optional_lazy_message_extension).bb());
  1196. // -----------------------------------------------------------------
  1197. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int32_extension));
  1198. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int64_extension));
  1199. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint32_extension));
  1200. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint64_extension));
  1201. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint32_extension));
  1202. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint64_extension));
  1203. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed32_extension));
  1204. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed64_extension));
  1205. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension));
  1206. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension));
  1207. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_float_extension));
  1208. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_double_extension));
  1209. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bool_extension));
  1210. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_string_extension));
  1211. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bytes_extension));
  1212. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeatedgroup_extension));
  1213. ASSERT_EQ(2,
  1214. message.ExtensionSize(UNITTEST::repeated_nested_message_extension));
  1215. ASSERT_EQ(
  1216. 2, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension));
  1217. ASSERT_EQ(2,
  1218. message.ExtensionSize(UNITTEST::repeated_import_message_extension));
  1219. ASSERT_EQ(2,
  1220. message.ExtensionSize(UNITTEST::repeated_lazy_message_extension));
  1221. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension));
  1222. ASSERT_EQ(2,
  1223. message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension));
  1224. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_import_enum_extension));
  1225. ASSERT_EQ(2,
  1226. message.ExtensionSize(UNITTEST::repeated_string_piece_extension));
  1227. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_cord_extension));
  1228. EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 0));
  1229. EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 0));
  1230. EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 0));
  1231. EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 0));
  1232. EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 0));
  1233. EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 0));
  1234. EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0));
  1235. EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0));
  1236. EXPECT_EQ(209,
  1237. message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0));
  1238. EXPECT_EQ(210,
  1239. message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0));
  1240. EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 0));
  1241. EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 0));
  1242. EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 0));
  1243. EXPECT_EQ("215",
  1244. message.GetExtension(UNITTEST::repeated_string_extension, 0));
  1245. EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 0));
  1246. EXPECT_EQ(217,
  1247. message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a());
  1248. EXPECT_EQ(218,
  1249. message.GetExtension(UNITTEST::repeated_nested_message_extension, 0)
  1250. .bb());
  1251. EXPECT_EQ(
  1252. 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0)
  1253. .c());
  1254. EXPECT_EQ(
  1255. 220,
  1256. message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d());
  1257. EXPECT_EQ(
  1258. 227,
  1259. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb());
  1260. EXPECT_EQ(UNITTEST::TestAllTypes::BAR,
  1261. message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0));
  1262. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  1263. message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0));
  1264. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR,
  1265. message.GetExtension(UNITTEST::repeated_import_enum_extension, 0));
  1266. EXPECT_EQ("224",
  1267. message.GetExtension(UNITTEST::repeated_string_piece_extension, 0));
  1268. EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 0));
  1269. EXPECT_EQ(301, message.GetExtension(UNITTEST::repeated_int32_extension, 1));
  1270. EXPECT_EQ(302, message.GetExtension(UNITTEST::repeated_int64_extension, 1));
  1271. EXPECT_EQ(303, message.GetExtension(UNITTEST::repeated_uint32_extension, 1));
  1272. EXPECT_EQ(304, message.GetExtension(UNITTEST::repeated_uint64_extension, 1));
  1273. EXPECT_EQ(305, message.GetExtension(UNITTEST::repeated_sint32_extension, 1));
  1274. EXPECT_EQ(306, message.GetExtension(UNITTEST::repeated_sint64_extension, 1));
  1275. EXPECT_EQ(307, message.GetExtension(UNITTEST::repeated_fixed32_extension, 1));
  1276. EXPECT_EQ(308, message.GetExtension(UNITTEST::repeated_fixed64_extension, 1));
  1277. EXPECT_EQ(309,
  1278. message.GetExtension(UNITTEST::repeated_sfixed32_extension, 1));
  1279. EXPECT_EQ(310,
  1280. message.GetExtension(UNITTEST::repeated_sfixed64_extension, 1));
  1281. EXPECT_EQ(311, message.GetExtension(UNITTEST::repeated_float_extension, 1));
  1282. EXPECT_EQ(312, message.GetExtension(UNITTEST::repeated_double_extension, 1));
  1283. EXPECT_FALSE(message.GetExtension(UNITTEST::repeated_bool_extension, 1));
  1284. EXPECT_EQ("315",
  1285. message.GetExtension(UNITTEST::repeated_string_extension, 1));
  1286. EXPECT_EQ("316", message.GetExtension(UNITTEST::repeated_bytes_extension, 1));
  1287. EXPECT_EQ(317,
  1288. message.GetExtension(UNITTEST::repeatedgroup_extension, 1).a());
  1289. EXPECT_EQ(318,
  1290. message.GetExtension(UNITTEST::repeated_nested_message_extension, 1)
  1291. .bb());
  1292. EXPECT_EQ(
  1293. 319, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 1)
  1294. .c());
  1295. EXPECT_EQ(
  1296. 320,
  1297. message.GetExtension(UNITTEST::repeated_import_message_extension, 1).d());
  1298. EXPECT_EQ(
  1299. 327,
  1300. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 1).bb());
  1301. EXPECT_EQ(UNITTEST::TestAllTypes::BAZ,
  1302. message.GetExtension(UNITTEST::repeated_nested_enum_extension, 1));
  1303. EXPECT_EQ(UNITTEST::FOREIGN_BAZ,
  1304. message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 1));
  1305. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ,
  1306. message.GetExtension(UNITTEST::repeated_import_enum_extension, 1));
  1307. EXPECT_EQ("324",
  1308. message.GetExtension(UNITTEST::repeated_string_piece_extension, 1));
  1309. EXPECT_EQ("325", message.GetExtension(UNITTEST::repeated_cord_extension, 1));
  1310. // -----------------------------------------------------------------
  1311. EXPECT_TRUE(message.HasExtension(UNITTEST::default_int32_extension));
  1312. EXPECT_TRUE(message.HasExtension(UNITTEST::default_int64_extension));
  1313. EXPECT_TRUE(message.HasExtension(UNITTEST::default_uint32_extension));
  1314. EXPECT_TRUE(message.HasExtension(UNITTEST::default_uint64_extension));
  1315. EXPECT_TRUE(message.HasExtension(UNITTEST::default_sint32_extension));
  1316. EXPECT_TRUE(message.HasExtension(UNITTEST::default_sint64_extension));
  1317. EXPECT_TRUE(message.HasExtension(UNITTEST::default_fixed32_extension));
  1318. EXPECT_TRUE(message.HasExtension(UNITTEST::default_fixed64_extension));
  1319. EXPECT_TRUE(message.HasExtension(UNITTEST::default_sfixed32_extension));
  1320. EXPECT_TRUE(message.HasExtension(UNITTEST::default_sfixed64_extension));
  1321. EXPECT_TRUE(message.HasExtension(UNITTEST::default_float_extension));
  1322. EXPECT_TRUE(message.HasExtension(UNITTEST::default_double_extension));
  1323. EXPECT_TRUE(message.HasExtension(UNITTEST::default_bool_extension));
  1324. EXPECT_TRUE(message.HasExtension(UNITTEST::default_string_extension));
  1325. EXPECT_TRUE(message.HasExtension(UNITTEST::default_bytes_extension));
  1326. EXPECT_TRUE(message.HasExtension(UNITTEST::default_nested_enum_extension));
  1327. EXPECT_TRUE(message.HasExtension(UNITTEST::default_foreign_enum_extension));
  1328. EXPECT_TRUE(message.HasExtension(UNITTEST::default_import_enum_extension));
  1329. EXPECT_TRUE(message.HasExtension(UNITTEST::default_string_piece_extension));
  1330. EXPECT_TRUE(message.HasExtension(UNITTEST::default_cord_extension));
  1331. EXPECT_EQ(401, message.GetExtension(UNITTEST::default_int32_extension));
  1332. EXPECT_EQ(402, message.GetExtension(UNITTEST::default_int64_extension));
  1333. EXPECT_EQ(403, message.GetExtension(UNITTEST::default_uint32_extension));
  1334. EXPECT_EQ(404, message.GetExtension(UNITTEST::default_uint64_extension));
  1335. EXPECT_EQ(405, message.GetExtension(UNITTEST::default_sint32_extension));
  1336. EXPECT_EQ(406, message.GetExtension(UNITTEST::default_sint64_extension));
  1337. EXPECT_EQ(407, message.GetExtension(UNITTEST::default_fixed32_extension));
  1338. EXPECT_EQ(408, message.GetExtension(UNITTEST::default_fixed64_extension));
  1339. EXPECT_EQ(409, message.GetExtension(UNITTEST::default_sfixed32_extension));
  1340. EXPECT_EQ(410, message.GetExtension(UNITTEST::default_sfixed64_extension));
  1341. EXPECT_EQ(411, message.GetExtension(UNITTEST::default_float_extension));
  1342. EXPECT_EQ(412, message.GetExtension(UNITTEST::default_double_extension));
  1343. EXPECT_FALSE(message.GetExtension(UNITTEST::default_bool_extension));
  1344. EXPECT_EQ("415", message.GetExtension(UNITTEST::default_string_extension));
  1345. EXPECT_EQ("416", message.GetExtension(UNITTEST::default_bytes_extension));
  1346. EXPECT_EQ(UNITTEST::TestAllTypes::FOO,
  1347. message.GetExtension(UNITTEST::default_nested_enum_extension));
  1348. EXPECT_EQ(UNITTEST::FOREIGN_FOO,
  1349. message.GetExtension(UNITTEST::default_foreign_enum_extension));
  1350. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO,
  1351. message.GetExtension(UNITTEST::default_import_enum_extension));
  1352. EXPECT_EQ("424",
  1353. message.GetExtension(UNITTEST::default_string_piece_extension));
  1354. EXPECT_EQ("425", message.GetExtension(UNITTEST::default_cord_extension));
  1355. EXPECT_TRUE(message.HasExtension(UNITTEST::oneof_uint32_extension));
  1356. EXPECT_TRUE(
  1357. message.GetExtension(UNITTEST::oneof_nested_message_extension).has_bb());
  1358. EXPECT_TRUE(message.HasExtension(UNITTEST::oneof_string_extension));
  1359. EXPECT_TRUE(message.HasExtension(UNITTEST::oneof_bytes_extension));
  1360. EXPECT_EQ(601, message.GetExtension(UNITTEST::oneof_uint32_extension));
  1361. EXPECT_EQ(
  1362. 602, message.GetExtension(UNITTEST::oneof_nested_message_extension).bb());
  1363. EXPECT_EQ("603", message.GetExtension(UNITTEST::oneof_string_extension));
  1364. EXPECT_EQ("604", message.GetExtension(UNITTEST::oneof_bytes_extension));
  1365. }
  1366. // -------------------------------------------------------------------
  1367. inline void TestUtil::ExpectExtensionsClear(
  1368. const UNITTEST::TestAllExtensions& message) {
  1369. string serialized;
  1370. ASSERT_TRUE(message.SerializeToString(&serialized));
  1371. EXPECT_EQ("", serialized);
  1372. EXPECT_EQ(0, message.ByteSizeLong());
  1373. // has_blah() should initially be false for all optional fields.
  1374. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_int32_extension));
  1375. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_int64_extension));
  1376. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_uint32_extension));
  1377. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_uint64_extension));
  1378. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sint32_extension));
  1379. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sint64_extension));
  1380. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_fixed32_extension));
  1381. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_fixed64_extension));
  1382. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sfixed32_extension));
  1383. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sfixed64_extension));
  1384. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_float_extension));
  1385. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_double_extension));
  1386. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_bool_extension));
  1387. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_string_extension));
  1388. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_bytes_extension));
  1389. EXPECT_FALSE(message.HasExtension(UNITTEST::optionalgroup_extension));
  1390. EXPECT_FALSE(
  1391. message.HasExtension(UNITTEST::optional_nested_message_extension));
  1392. EXPECT_FALSE(
  1393. message.HasExtension(UNITTEST::optional_foreign_message_extension));
  1394. EXPECT_FALSE(
  1395. message.HasExtension(UNITTEST::optional_import_message_extension));
  1396. EXPECT_FALSE(
  1397. message.HasExtension(UNITTEST::optional_public_import_message_extension));
  1398. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_lazy_message_extension));
  1399. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_nested_enum_extension));
  1400. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_foreign_enum_extension));
  1401. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_import_enum_extension));
  1402. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_string_piece_extension));
  1403. EXPECT_FALSE(message.HasExtension(UNITTEST::optional_cord_extension));
  1404. // Optional fields without defaults are set to zero or something like it.
  1405. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_int32_extension));
  1406. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_int64_extension));
  1407. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_uint32_extension));
  1408. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_uint64_extension));
  1409. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sint32_extension));
  1410. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sint64_extension));
  1411. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_fixed32_extension));
  1412. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_fixed64_extension));
  1413. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sfixed32_extension));
  1414. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sfixed64_extension));
  1415. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_float_extension));
  1416. EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_double_extension));
  1417. EXPECT_FALSE(message.GetExtension(UNITTEST::optional_bool_extension));
  1418. EXPECT_EQ("", message.GetExtension(UNITTEST::optional_string_extension));
  1419. EXPECT_EQ("", message.GetExtension(UNITTEST::optional_bytes_extension));
  1420. // Embedded messages should also be clear.
  1421. EXPECT_FALSE(message.GetExtension(UNITTEST::optionalgroup_extension).has_a());
  1422. EXPECT_FALSE(message.GetExtension(UNITTEST::optional_nested_message_extension)
  1423. .has_bb());
  1424. EXPECT_FALSE(
  1425. message.GetExtension(UNITTEST::optional_foreign_message_extension)
  1426. .has_c());
  1427. EXPECT_FALSE(message.GetExtension(UNITTEST::optional_import_message_extension)
  1428. .has_d());
  1429. EXPECT_FALSE(
  1430. message.GetExtension(UNITTEST::optional_public_import_message_extension)
  1431. .has_e());
  1432. EXPECT_FALSE(
  1433. message.GetExtension(UNITTEST::optional_lazy_message_extension).has_bb());
  1434. EXPECT_EQ(0, message.GetExtension(UNITTEST::optionalgroup_extension).a());
  1435. EXPECT_EQ(
  1436. 0,
  1437. message.GetExtension(UNITTEST::optional_nested_message_extension).bb());
  1438. EXPECT_EQ(
  1439. 0,
  1440. message.GetExtension(UNITTEST::optional_foreign_message_extension).c());
  1441. EXPECT_EQ(
  1442. 0, message.GetExtension(UNITTEST::optional_import_message_extension).d());
  1443. EXPECT_EQ(
  1444. 0,
  1445. message.GetExtension(UNITTEST::optional_public_import_message_extension)
  1446. .e());
  1447. EXPECT_EQ(
  1448. 0, message.GetExtension(UNITTEST::optional_lazy_message_extension).bb());
  1449. // Enums without defaults are set to the first value in the enum.
  1450. EXPECT_EQ(UNITTEST::TestAllTypes::FOO,
  1451. message.GetExtension(UNITTEST::optional_nested_enum_extension));
  1452. EXPECT_EQ(UNITTEST::FOREIGN_FOO,
  1453. message.GetExtension(UNITTEST::optional_foreign_enum_extension));
  1454. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO,
  1455. message.GetExtension(UNITTEST::optional_import_enum_extension));
  1456. EXPECT_EQ("",
  1457. message.GetExtension(UNITTEST::optional_string_piece_extension));
  1458. EXPECT_EQ("", message.GetExtension(UNITTEST::optional_cord_extension));
  1459. // Repeated fields are empty.
  1460. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_int32_extension));
  1461. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_int64_extension));
  1462. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_uint32_extension));
  1463. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_uint64_extension));
  1464. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sint32_extension));
  1465. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sint64_extension));
  1466. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_fixed32_extension));
  1467. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_fixed64_extension));
  1468. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension));
  1469. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension));
  1470. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_float_extension));
  1471. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_double_extension));
  1472. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_bool_extension));
  1473. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_string_extension));
  1474. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_bytes_extension));
  1475. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeatedgroup_extension));
  1476. EXPECT_EQ(0,
  1477. message.ExtensionSize(UNITTEST::repeated_nested_message_extension));
  1478. EXPECT_EQ(
  1479. 0, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension));
  1480. EXPECT_EQ(0,
  1481. message.ExtensionSize(UNITTEST::repeated_import_message_extension));
  1482. EXPECT_EQ(0,
  1483. message.ExtensionSize(UNITTEST::repeated_lazy_message_extension));
  1484. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension));
  1485. EXPECT_EQ(0,
  1486. message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension));
  1487. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_import_enum_extension));
  1488. EXPECT_EQ(0,
  1489. message.ExtensionSize(UNITTEST::repeated_string_piece_extension));
  1490. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_cord_extension));
  1491. // has_blah() should also be false for all default fields.
  1492. EXPECT_FALSE(message.HasExtension(UNITTEST::default_int32_extension));
  1493. EXPECT_FALSE(message.HasExtension(UNITTEST::default_int64_extension));
  1494. EXPECT_FALSE(message.HasExtension(UNITTEST::default_uint32_extension));
  1495. EXPECT_FALSE(message.HasExtension(UNITTEST::default_uint64_extension));
  1496. EXPECT_FALSE(message.HasExtension(UNITTEST::default_sint32_extension));
  1497. EXPECT_FALSE(message.HasExtension(UNITTEST::default_sint64_extension));
  1498. EXPECT_FALSE(message.HasExtension(UNITTEST::default_fixed32_extension));
  1499. EXPECT_FALSE(message.HasExtension(UNITTEST::default_fixed64_extension));
  1500. EXPECT_FALSE(message.HasExtension(UNITTEST::default_sfixed32_extension));
  1501. EXPECT_FALSE(message.HasExtension(UNITTEST::default_sfixed64_extension));
  1502. EXPECT_FALSE(message.HasExtension(UNITTEST::default_float_extension));
  1503. EXPECT_FALSE(message.HasExtension(UNITTEST::default_double_extension));
  1504. EXPECT_FALSE(message.HasExtension(UNITTEST::default_bool_extension));
  1505. EXPECT_FALSE(message.HasExtension(UNITTEST::default_string_extension));
  1506. EXPECT_FALSE(message.HasExtension(UNITTEST::default_bytes_extension));
  1507. EXPECT_FALSE(message.HasExtension(UNITTEST::default_nested_enum_extension));
  1508. EXPECT_FALSE(message.HasExtension(UNITTEST::default_foreign_enum_extension));
  1509. EXPECT_FALSE(message.HasExtension(UNITTEST::default_import_enum_extension));
  1510. EXPECT_FALSE(message.HasExtension(UNITTEST::default_string_piece_extension));
  1511. EXPECT_FALSE(message.HasExtension(UNITTEST::default_cord_extension));
  1512. // Fields with defaults have their default values (duh).
  1513. EXPECT_EQ(41, message.GetExtension(UNITTEST::default_int32_extension));
  1514. EXPECT_EQ(42, message.GetExtension(UNITTEST::default_int64_extension));
  1515. EXPECT_EQ(43, message.GetExtension(UNITTEST::default_uint32_extension));
  1516. EXPECT_EQ(44, message.GetExtension(UNITTEST::default_uint64_extension));
  1517. EXPECT_EQ(-45, message.GetExtension(UNITTEST::default_sint32_extension));
  1518. EXPECT_EQ(46, message.GetExtension(UNITTEST::default_sint64_extension));
  1519. EXPECT_EQ(47, message.GetExtension(UNITTEST::default_fixed32_extension));
  1520. EXPECT_EQ(48, message.GetExtension(UNITTEST::default_fixed64_extension));
  1521. EXPECT_EQ(49, message.GetExtension(UNITTEST::default_sfixed32_extension));
  1522. EXPECT_EQ(-50, message.GetExtension(UNITTEST::default_sfixed64_extension));
  1523. EXPECT_EQ(51.5, message.GetExtension(UNITTEST::default_float_extension));
  1524. EXPECT_EQ(52e3, message.GetExtension(UNITTEST::default_double_extension));
  1525. EXPECT_TRUE(message.GetExtension(UNITTEST::default_bool_extension));
  1526. EXPECT_EQ("hello", message.GetExtension(UNITTEST::default_string_extension));
  1527. EXPECT_EQ("world", message.GetExtension(UNITTEST::default_bytes_extension));
  1528. EXPECT_EQ(UNITTEST::TestAllTypes::BAR,
  1529. message.GetExtension(UNITTEST::default_nested_enum_extension));
  1530. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  1531. message.GetExtension(UNITTEST::default_foreign_enum_extension));
  1532. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR,
  1533. message.GetExtension(UNITTEST::default_import_enum_extension));
  1534. EXPECT_EQ("abc",
  1535. message.GetExtension(UNITTEST::default_string_piece_extension));
  1536. EXPECT_EQ("123", message.GetExtension(UNITTEST::default_cord_extension));
  1537. EXPECT_FALSE(message.HasExtension(UNITTEST::oneof_uint32_extension));
  1538. EXPECT_FALSE(
  1539. message.GetExtension(UNITTEST::oneof_nested_message_extension).has_bb());
  1540. EXPECT_FALSE(message.HasExtension(UNITTEST::oneof_string_extension));
  1541. EXPECT_FALSE(message.HasExtension(UNITTEST::oneof_bytes_extension));
  1542. }
  1543. // -------------------------------------------------------------------
  1544. inline void TestUtil::ExpectRepeatedExtensionsModified(
  1545. const UNITTEST::TestAllExtensions& message) {
  1546. // ModifyRepeatedFields only sets the second repeated element of each
  1547. // field. In addition to verifying this, we also verify that the first
  1548. // element and size were *not* modified.
  1549. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int32_extension));
  1550. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int64_extension));
  1551. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint32_extension));
  1552. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint64_extension));
  1553. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint32_extension));
  1554. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint64_extension));
  1555. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed32_extension));
  1556. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed64_extension));
  1557. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension));
  1558. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension));
  1559. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_float_extension));
  1560. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_double_extension));
  1561. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bool_extension));
  1562. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_string_extension));
  1563. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bytes_extension));
  1564. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeatedgroup_extension));
  1565. ASSERT_EQ(2,
  1566. message.ExtensionSize(UNITTEST::repeated_nested_message_extension));
  1567. ASSERT_EQ(
  1568. 2, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension));
  1569. ASSERT_EQ(2,
  1570. message.ExtensionSize(UNITTEST::repeated_import_message_extension));
  1571. ASSERT_EQ(2,
  1572. message.ExtensionSize(UNITTEST::repeated_lazy_message_extension));
  1573. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension));
  1574. ASSERT_EQ(2,
  1575. message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension));
  1576. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_import_enum_extension));
  1577. ASSERT_EQ(2,
  1578. message.ExtensionSize(UNITTEST::repeated_string_piece_extension));
  1579. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_cord_extension));
  1580. EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 0));
  1581. EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 0));
  1582. EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 0));
  1583. EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 0));
  1584. EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 0));
  1585. EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 0));
  1586. EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0));
  1587. EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0));
  1588. EXPECT_EQ(209,
  1589. message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0));
  1590. EXPECT_EQ(210,
  1591. message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0));
  1592. EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 0));
  1593. EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 0));
  1594. EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 0));
  1595. EXPECT_EQ("215",
  1596. message.GetExtension(UNITTEST::repeated_string_extension, 0));
  1597. EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 0));
  1598. EXPECT_EQ(217,
  1599. message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a());
  1600. EXPECT_EQ(218,
  1601. message.GetExtension(UNITTEST::repeated_nested_message_extension, 0)
  1602. .bb());
  1603. EXPECT_EQ(
  1604. 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0)
  1605. .c());
  1606. EXPECT_EQ(
  1607. 220,
  1608. message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d());
  1609. EXPECT_EQ(
  1610. 227,
  1611. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb());
  1612. EXPECT_EQ(UNITTEST::TestAllTypes::BAR,
  1613. message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0));
  1614. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  1615. message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0));
  1616. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR,
  1617. message.GetExtension(UNITTEST::repeated_import_enum_extension, 0));
  1618. EXPECT_EQ("224",
  1619. message.GetExtension(UNITTEST::repeated_string_piece_extension, 0));
  1620. EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 0));
  1621. // Actually verify the second (modified) elements now.
  1622. EXPECT_EQ(501, message.GetExtension(UNITTEST::repeated_int32_extension, 1));
  1623. EXPECT_EQ(502, message.GetExtension(UNITTEST::repeated_int64_extension, 1));
  1624. EXPECT_EQ(503, message.GetExtension(UNITTEST::repeated_uint32_extension, 1));
  1625. EXPECT_EQ(504, message.GetExtension(UNITTEST::repeated_uint64_extension, 1));
  1626. EXPECT_EQ(505, message.GetExtension(UNITTEST::repeated_sint32_extension, 1));
  1627. EXPECT_EQ(506, message.GetExtension(UNITTEST::repeated_sint64_extension, 1));
  1628. EXPECT_EQ(507, message.GetExtension(UNITTEST::repeated_fixed32_extension, 1));
  1629. EXPECT_EQ(508, message.GetExtension(UNITTEST::repeated_fixed64_extension, 1));
  1630. EXPECT_EQ(509,
  1631. message.GetExtension(UNITTEST::repeated_sfixed32_extension, 1));
  1632. EXPECT_EQ(510,
  1633. message.GetExtension(UNITTEST::repeated_sfixed64_extension, 1));
  1634. EXPECT_EQ(511, message.GetExtension(UNITTEST::repeated_float_extension, 1));
  1635. EXPECT_EQ(512, message.GetExtension(UNITTEST::repeated_double_extension, 1));
  1636. EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 1));
  1637. EXPECT_EQ("515",
  1638. message.GetExtension(UNITTEST::repeated_string_extension, 1));
  1639. EXPECT_EQ("516", message.GetExtension(UNITTEST::repeated_bytes_extension, 1));
  1640. EXPECT_EQ(517,
  1641. message.GetExtension(UNITTEST::repeatedgroup_extension, 1).a());
  1642. EXPECT_EQ(518,
  1643. message.GetExtension(UNITTEST::repeated_nested_message_extension, 1)
  1644. .bb());
  1645. EXPECT_EQ(
  1646. 519, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 1)
  1647. .c());
  1648. EXPECT_EQ(
  1649. 520,
  1650. message.GetExtension(UNITTEST::repeated_import_message_extension, 1).d());
  1651. EXPECT_EQ(
  1652. 527,
  1653. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 1).bb());
  1654. EXPECT_EQ(UNITTEST::TestAllTypes::FOO,
  1655. message.GetExtension(UNITTEST::repeated_nested_enum_extension, 1));
  1656. EXPECT_EQ(UNITTEST::FOREIGN_FOO,
  1657. message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 1));
  1658. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO,
  1659. message.GetExtension(UNITTEST::repeated_import_enum_extension, 1));
  1660. EXPECT_EQ("524",
  1661. message.GetExtension(UNITTEST::repeated_string_piece_extension, 1));
  1662. EXPECT_EQ("525", message.GetExtension(UNITTEST::repeated_cord_extension, 1));
  1663. }
  1664. // -------------------------------------------------------------------
  1665. inline void TestUtil::SetPackedExtensions(
  1666. UNITTEST::TestPackedExtensions* message) {
  1667. message->AddExtension(UNITTEST::packed_int32_extension, 601);
  1668. message->AddExtension(UNITTEST::packed_int64_extension, 602);
  1669. message->AddExtension(UNITTEST::packed_uint32_extension, 603);
  1670. message->AddExtension(UNITTEST::packed_uint64_extension, 604);
  1671. message->AddExtension(UNITTEST::packed_sint32_extension, 605);
  1672. message->AddExtension(UNITTEST::packed_sint64_extension, 606);
  1673. message->AddExtension(UNITTEST::packed_fixed32_extension, 607);
  1674. message->AddExtension(UNITTEST::packed_fixed64_extension, 608);
  1675. message->AddExtension(UNITTEST::packed_sfixed32_extension, 609);
  1676. message->AddExtension(UNITTEST::packed_sfixed64_extension, 610);
  1677. message->AddExtension(UNITTEST::packed_float_extension, 611);
  1678. message->AddExtension(UNITTEST::packed_double_extension, 612);
  1679. message->AddExtension(UNITTEST::packed_bool_extension, true);
  1680. message->AddExtension(UNITTEST::packed_enum_extension, UNITTEST::FOREIGN_BAR);
  1681. // add a second one of each field
  1682. message->AddExtension(UNITTEST::packed_int32_extension, 701);
  1683. message->AddExtension(UNITTEST::packed_int64_extension, 702);
  1684. message->AddExtension(UNITTEST::packed_uint32_extension, 703);
  1685. message->AddExtension(UNITTEST::packed_uint64_extension, 704);
  1686. message->AddExtension(UNITTEST::packed_sint32_extension, 705);
  1687. message->AddExtension(UNITTEST::packed_sint64_extension, 706);
  1688. message->AddExtension(UNITTEST::packed_fixed32_extension, 707);
  1689. message->AddExtension(UNITTEST::packed_fixed64_extension, 708);
  1690. message->AddExtension(UNITTEST::packed_sfixed32_extension, 709);
  1691. message->AddExtension(UNITTEST::packed_sfixed64_extension, 710);
  1692. message->AddExtension(UNITTEST::packed_float_extension, 711);
  1693. message->AddExtension(UNITTEST::packed_double_extension, 712);
  1694. message->AddExtension(UNITTEST::packed_bool_extension, false);
  1695. message->AddExtension(UNITTEST::packed_enum_extension, UNITTEST::FOREIGN_BAZ);
  1696. }
  1697. // -------------------------------------------------------------------
  1698. inline void TestUtil::ModifyPackedExtensions(
  1699. UNITTEST::TestPackedExtensions* message) {
  1700. message->SetExtension(UNITTEST::packed_int32_extension, 1, 801);
  1701. message->SetExtension(UNITTEST::packed_int64_extension, 1, 802);
  1702. message->SetExtension(UNITTEST::packed_uint32_extension, 1, 803);
  1703. message->SetExtension(UNITTEST::packed_uint64_extension, 1, 804);
  1704. message->SetExtension(UNITTEST::packed_sint32_extension, 1, 805);
  1705. message->SetExtension(UNITTEST::packed_sint64_extension, 1, 806);
  1706. message->SetExtension(UNITTEST::packed_fixed32_extension, 1, 807);
  1707. message->SetExtension(UNITTEST::packed_fixed64_extension, 1, 808);
  1708. message->SetExtension(UNITTEST::packed_sfixed32_extension, 1, 809);
  1709. message->SetExtension(UNITTEST::packed_sfixed64_extension, 1, 810);
  1710. message->SetExtension(UNITTEST::packed_float_extension, 1, 811);
  1711. message->SetExtension(UNITTEST::packed_double_extension, 1, 812);
  1712. message->SetExtension(UNITTEST::packed_bool_extension, 1, true);
  1713. message->SetExtension(UNITTEST::packed_enum_extension, 1,
  1714. UNITTEST::FOREIGN_FOO);
  1715. }
  1716. // -------------------------------------------------------------------
  1717. inline void TestUtil::ExpectPackedExtensionsSet(
  1718. const UNITTEST::TestPackedExtensions& message) {
  1719. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_int32_extension));
  1720. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_int64_extension));
  1721. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_uint32_extension));
  1722. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_uint64_extension));
  1723. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sint32_extension));
  1724. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sint64_extension));
  1725. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_fixed32_extension));
  1726. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_fixed64_extension));
  1727. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sfixed32_extension));
  1728. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sfixed64_extension));
  1729. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_float_extension));
  1730. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_double_extension));
  1731. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_bool_extension));
  1732. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_enum_extension));
  1733. EXPECT_EQ(601, message.GetExtension(UNITTEST::packed_int32_extension, 0));
  1734. EXPECT_EQ(602, message.GetExtension(UNITTEST::packed_int64_extension, 0));
  1735. EXPECT_EQ(603, message.GetExtension(UNITTEST::packed_uint32_extension, 0));
  1736. EXPECT_EQ(604, message.GetExtension(UNITTEST::packed_uint64_extension, 0));
  1737. EXPECT_EQ(605, message.GetExtension(UNITTEST::packed_sint32_extension, 0));
  1738. EXPECT_EQ(606, message.GetExtension(UNITTEST::packed_sint64_extension, 0));
  1739. EXPECT_EQ(607, message.GetExtension(UNITTEST::packed_fixed32_extension, 0));
  1740. EXPECT_EQ(608, message.GetExtension(UNITTEST::packed_fixed64_extension, 0));
  1741. EXPECT_EQ(609, message.GetExtension(UNITTEST::packed_sfixed32_extension, 0));
  1742. EXPECT_EQ(610, message.GetExtension(UNITTEST::packed_sfixed64_extension, 0));
  1743. EXPECT_EQ(611, message.GetExtension(UNITTEST::packed_float_extension, 0));
  1744. EXPECT_EQ(612, message.GetExtension(UNITTEST::packed_double_extension, 0));
  1745. EXPECT_TRUE(message.GetExtension(UNITTEST::packed_bool_extension, 0));
  1746. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  1747. message.GetExtension(UNITTEST::packed_enum_extension, 0));
  1748. EXPECT_EQ(701, message.GetExtension(UNITTEST::packed_int32_extension, 1));
  1749. EXPECT_EQ(702, message.GetExtension(UNITTEST::packed_int64_extension, 1));
  1750. EXPECT_EQ(703, message.GetExtension(UNITTEST::packed_uint32_extension, 1));
  1751. EXPECT_EQ(704, message.GetExtension(UNITTEST::packed_uint64_extension, 1));
  1752. EXPECT_EQ(705, message.GetExtension(UNITTEST::packed_sint32_extension, 1));
  1753. EXPECT_EQ(706, message.GetExtension(UNITTEST::packed_sint64_extension, 1));
  1754. EXPECT_EQ(707, message.GetExtension(UNITTEST::packed_fixed32_extension, 1));
  1755. EXPECT_EQ(708, message.GetExtension(UNITTEST::packed_fixed64_extension, 1));
  1756. EXPECT_EQ(709, message.GetExtension(UNITTEST::packed_sfixed32_extension, 1));
  1757. EXPECT_EQ(710, message.GetExtension(UNITTEST::packed_sfixed64_extension, 1));
  1758. EXPECT_EQ(711, message.GetExtension(UNITTEST::packed_float_extension, 1));
  1759. EXPECT_EQ(712, message.GetExtension(UNITTEST::packed_double_extension, 1));
  1760. EXPECT_FALSE(message.GetExtension(UNITTEST::packed_bool_extension, 1));
  1761. EXPECT_EQ(UNITTEST::FOREIGN_BAZ,
  1762. message.GetExtension(UNITTEST::packed_enum_extension, 1));
  1763. }
  1764. // -------------------------------------------------------------------
  1765. inline void TestUtil::ExpectPackedExtensionsClear(
  1766. const UNITTEST::TestPackedExtensions& message) {
  1767. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_int32_extension));
  1768. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_int64_extension));
  1769. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_uint32_extension));
  1770. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_uint64_extension));
  1771. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_sint32_extension));
  1772. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_sint64_extension));
  1773. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_fixed32_extension));
  1774. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_fixed64_extension));
  1775. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_sfixed32_extension));
  1776. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_sfixed64_extension));
  1777. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_float_extension));
  1778. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_double_extension));
  1779. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_bool_extension));
  1780. EXPECT_EQ(0, message.ExtensionSize(UNITTEST::packed_enum_extension));
  1781. }
  1782. // -------------------------------------------------------------------
  1783. inline void TestUtil::ExpectPackedExtensionsModified(
  1784. const UNITTEST::TestPackedExtensions& message) {
  1785. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_int32_extension));
  1786. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_int64_extension));
  1787. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_uint32_extension));
  1788. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_uint64_extension));
  1789. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sint32_extension));
  1790. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sint64_extension));
  1791. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_fixed32_extension));
  1792. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_fixed64_extension));
  1793. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sfixed32_extension));
  1794. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sfixed64_extension));
  1795. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_float_extension));
  1796. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_double_extension));
  1797. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_bool_extension));
  1798. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_enum_extension));
  1799. EXPECT_EQ(601, message.GetExtension(UNITTEST::packed_int32_extension, 0));
  1800. EXPECT_EQ(602, message.GetExtension(UNITTEST::packed_int64_extension, 0));
  1801. EXPECT_EQ(603, message.GetExtension(UNITTEST::packed_uint32_extension, 0));
  1802. EXPECT_EQ(604, message.GetExtension(UNITTEST::packed_uint64_extension, 0));
  1803. EXPECT_EQ(605, message.GetExtension(UNITTEST::packed_sint32_extension, 0));
  1804. EXPECT_EQ(606, message.GetExtension(UNITTEST::packed_sint64_extension, 0));
  1805. EXPECT_EQ(607, message.GetExtension(UNITTEST::packed_fixed32_extension, 0));
  1806. EXPECT_EQ(608, message.GetExtension(UNITTEST::packed_fixed64_extension, 0));
  1807. EXPECT_EQ(609, message.GetExtension(UNITTEST::packed_sfixed32_extension, 0));
  1808. EXPECT_EQ(610, message.GetExtension(UNITTEST::packed_sfixed64_extension, 0));
  1809. EXPECT_EQ(611, message.GetExtension(UNITTEST::packed_float_extension, 0));
  1810. EXPECT_EQ(612, message.GetExtension(UNITTEST::packed_double_extension, 0));
  1811. EXPECT_TRUE(message.GetExtension(UNITTEST::packed_bool_extension, 0));
  1812. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  1813. message.GetExtension(UNITTEST::packed_enum_extension, 0));
  1814. // Actually verify the second (modified) elements now.
  1815. EXPECT_EQ(801, message.GetExtension(UNITTEST::packed_int32_extension, 1));
  1816. EXPECT_EQ(802, message.GetExtension(UNITTEST::packed_int64_extension, 1));
  1817. EXPECT_EQ(803, message.GetExtension(UNITTEST::packed_uint32_extension, 1));
  1818. EXPECT_EQ(804, message.GetExtension(UNITTEST::packed_uint64_extension, 1));
  1819. EXPECT_EQ(805, message.GetExtension(UNITTEST::packed_sint32_extension, 1));
  1820. EXPECT_EQ(806, message.GetExtension(UNITTEST::packed_sint64_extension, 1));
  1821. EXPECT_EQ(807, message.GetExtension(UNITTEST::packed_fixed32_extension, 1));
  1822. EXPECT_EQ(808, message.GetExtension(UNITTEST::packed_fixed64_extension, 1));
  1823. EXPECT_EQ(809, message.GetExtension(UNITTEST::packed_sfixed32_extension, 1));
  1824. EXPECT_EQ(810, message.GetExtension(UNITTEST::packed_sfixed64_extension, 1));
  1825. EXPECT_EQ(811, message.GetExtension(UNITTEST::packed_float_extension, 1));
  1826. EXPECT_EQ(812, message.GetExtension(UNITTEST::packed_double_extension, 1));
  1827. EXPECT_TRUE(message.GetExtension(UNITTEST::packed_bool_extension, 1));
  1828. EXPECT_EQ(UNITTEST::FOREIGN_FOO,
  1829. message.GetExtension(UNITTEST::packed_enum_extension, 1));
  1830. }
  1831. // -------------------------------------------------------------------
  1832. inline void TestUtil::ExpectUnpackedExtensionsSet(
  1833. const UNITTEST::TestUnpackedExtensions& message) {
  1834. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_int32_extension));
  1835. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_int64_extension));
  1836. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_uint32_extension));
  1837. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_uint64_extension));
  1838. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sint32_extension));
  1839. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sint64_extension));
  1840. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_fixed32_extension));
  1841. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_fixed64_extension));
  1842. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sfixed32_extension));
  1843. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sfixed64_extension));
  1844. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_float_extension));
  1845. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_double_extension));
  1846. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_bool_extension));
  1847. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_enum_extension));
  1848. EXPECT_EQ(601, message.GetExtension(UNITTEST::unpacked_int32_extension, 0));
  1849. EXPECT_EQ(602, message.GetExtension(UNITTEST::unpacked_int64_extension, 0));
  1850. EXPECT_EQ(603, message.GetExtension(UNITTEST::unpacked_uint32_extension, 0));
  1851. EXPECT_EQ(604, message.GetExtension(UNITTEST::unpacked_uint64_extension, 0));
  1852. EXPECT_EQ(605, message.GetExtension(UNITTEST::unpacked_sint32_extension, 0));
  1853. EXPECT_EQ(606, message.GetExtension(UNITTEST::unpacked_sint64_extension, 0));
  1854. EXPECT_EQ(607, message.GetExtension(UNITTEST::unpacked_fixed32_extension, 0));
  1855. EXPECT_EQ(608, message.GetExtension(UNITTEST::unpacked_fixed64_extension, 0));
  1856. EXPECT_EQ(609,
  1857. message.GetExtension(UNITTEST::unpacked_sfixed32_extension, 0));
  1858. EXPECT_EQ(610,
  1859. message.GetExtension(UNITTEST::unpacked_sfixed64_extension, 0));
  1860. EXPECT_EQ(611, message.GetExtension(UNITTEST::unpacked_float_extension, 0));
  1861. EXPECT_EQ(612, message.GetExtension(UNITTEST::unpacked_double_extension, 0));
  1862. EXPECT_EQ(true, message.GetExtension(UNITTEST::unpacked_bool_extension, 0));
  1863. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  1864. message.GetExtension(UNITTEST::unpacked_enum_extension, 0));
  1865. EXPECT_EQ(701, message.GetExtension(UNITTEST::unpacked_int32_extension, 1));
  1866. EXPECT_EQ(702, message.GetExtension(UNITTEST::unpacked_int64_extension, 1));
  1867. EXPECT_EQ(703, message.GetExtension(UNITTEST::unpacked_uint32_extension, 1));
  1868. EXPECT_EQ(704, message.GetExtension(UNITTEST::unpacked_uint64_extension, 1));
  1869. EXPECT_EQ(705, message.GetExtension(UNITTEST::unpacked_sint32_extension, 1));
  1870. EXPECT_EQ(706, message.GetExtension(UNITTEST::unpacked_sint64_extension, 1));
  1871. EXPECT_EQ(707, message.GetExtension(UNITTEST::unpacked_fixed32_extension, 1));
  1872. EXPECT_EQ(708, message.GetExtension(UNITTEST::unpacked_fixed64_extension, 1));
  1873. EXPECT_EQ(709,
  1874. message.GetExtension(UNITTEST::unpacked_sfixed32_extension, 1));
  1875. EXPECT_EQ(710,
  1876. message.GetExtension(UNITTEST::unpacked_sfixed64_extension, 1));
  1877. EXPECT_EQ(711, message.GetExtension(UNITTEST::unpacked_float_extension, 1));
  1878. EXPECT_EQ(712, message.GetExtension(UNITTEST::unpacked_double_extension, 1));
  1879. EXPECT_EQ(false, message.GetExtension(UNITTEST::unpacked_bool_extension, 1));
  1880. EXPECT_EQ(UNITTEST::FOREIGN_BAZ,
  1881. message.GetExtension(UNITTEST::unpacked_enum_extension, 1));
  1882. }
  1883. // -------------------------------------------------------------------
  1884. inline void TestUtil::ExpectLastRepeatedsRemoved(
  1885. const UNITTEST::TestAllTypes& message) {
  1886. ASSERT_EQ(1, message.repeated_int32_size());
  1887. ASSERT_EQ(1, message.repeated_int64_size());
  1888. ASSERT_EQ(1, message.repeated_uint32_size());
  1889. ASSERT_EQ(1, message.repeated_uint64_size());
  1890. ASSERT_EQ(1, message.repeated_sint32_size());
  1891. ASSERT_EQ(1, message.repeated_sint64_size());
  1892. ASSERT_EQ(1, message.repeated_fixed32_size());
  1893. ASSERT_EQ(1, message.repeated_fixed64_size());
  1894. ASSERT_EQ(1, message.repeated_sfixed32_size());
  1895. ASSERT_EQ(1, message.repeated_sfixed64_size());
  1896. ASSERT_EQ(1, message.repeated_float_size());
  1897. ASSERT_EQ(1, message.repeated_double_size());
  1898. ASSERT_EQ(1, message.repeated_bool_size());
  1899. ASSERT_EQ(1, message.repeated_string_size());
  1900. ASSERT_EQ(1, message.repeated_bytes_size());
  1901. ASSERT_EQ(1, message.repeatedgroup_size());
  1902. ASSERT_EQ(1, message.repeated_nested_message_size());
  1903. ASSERT_EQ(1, message.repeated_foreign_message_size());
  1904. ASSERT_EQ(1, message.repeated_import_message_size());
  1905. ASSERT_EQ(1, message.repeated_import_message_size());
  1906. ASSERT_EQ(1, message.repeated_nested_enum_size());
  1907. ASSERT_EQ(1, message.repeated_foreign_enum_size());
  1908. ASSERT_EQ(1, message.repeated_import_enum_size());
  1909. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  1910. ASSERT_EQ(1, message.repeated_string_piece_size());
  1911. ASSERT_EQ(1, message.repeated_cord_size());
  1912. #endif
  1913. // Test that the remaining element is the correct one.
  1914. EXPECT_EQ(201, message.repeated_int32(0));
  1915. EXPECT_EQ(202, message.repeated_int64(0));
  1916. EXPECT_EQ(203, message.repeated_uint32(0));
  1917. EXPECT_EQ(204, message.repeated_uint64(0));
  1918. EXPECT_EQ(205, message.repeated_sint32(0));
  1919. EXPECT_EQ(206, message.repeated_sint64(0));
  1920. EXPECT_EQ(207, message.repeated_fixed32(0));
  1921. EXPECT_EQ(208, message.repeated_fixed64(0));
  1922. EXPECT_EQ(209, message.repeated_sfixed32(0));
  1923. EXPECT_EQ(210, message.repeated_sfixed64(0));
  1924. EXPECT_EQ(211, message.repeated_float(0));
  1925. EXPECT_EQ(212, message.repeated_double(0));
  1926. EXPECT_TRUE(message.repeated_bool(0));
  1927. EXPECT_EQ("215", message.repeated_string(0));
  1928. EXPECT_EQ("216", message.repeated_bytes(0));
  1929. EXPECT_EQ(217, message.repeatedgroup(0).a());
  1930. EXPECT_EQ(218, message.repeated_nested_message(0).bb());
  1931. EXPECT_EQ(219, message.repeated_foreign_message(0).c());
  1932. EXPECT_EQ(220, message.repeated_import_message(0).d());
  1933. EXPECT_EQ(220, message.repeated_import_message(0).d());
  1934. EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(0));
  1935. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(0));
  1936. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(0));
  1937. }
  1938. inline void TestUtil::ExpectLastRepeatedExtensionsRemoved(
  1939. const UNITTEST::TestAllExtensions& message) {
  1940. // Test that one element was removed.
  1941. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_int32_extension));
  1942. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_int64_extension));
  1943. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_uint32_extension));
  1944. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_uint64_extension));
  1945. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sint32_extension));
  1946. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sint64_extension));
  1947. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_fixed32_extension));
  1948. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_fixed64_extension));
  1949. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension));
  1950. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension));
  1951. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_float_extension));
  1952. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_double_extension));
  1953. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_bool_extension));
  1954. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_string_extension));
  1955. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_bytes_extension));
  1956. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeatedgroup_extension));
  1957. ASSERT_EQ(1,
  1958. message.ExtensionSize(UNITTEST::repeated_nested_message_extension));
  1959. ASSERT_EQ(
  1960. 1, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension));
  1961. ASSERT_EQ(1,
  1962. message.ExtensionSize(UNITTEST::repeated_import_message_extension));
  1963. ASSERT_EQ(1,
  1964. message.ExtensionSize(UNITTEST::repeated_lazy_message_extension));
  1965. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension));
  1966. ASSERT_EQ(1,
  1967. message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension));
  1968. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_import_enum_extension));
  1969. ASSERT_EQ(1,
  1970. message.ExtensionSize(UNITTEST::repeated_string_piece_extension));
  1971. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_cord_extension));
  1972. // Test that the remaining element is the correct one.
  1973. EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 0));
  1974. EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 0));
  1975. EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 0));
  1976. EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 0));
  1977. EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 0));
  1978. EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 0));
  1979. EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0));
  1980. EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0));
  1981. EXPECT_EQ(209,
  1982. message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0));
  1983. EXPECT_EQ(210,
  1984. message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0));
  1985. EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 0));
  1986. EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 0));
  1987. EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 0));
  1988. EXPECT_EQ("215",
  1989. message.GetExtension(UNITTEST::repeated_string_extension, 0));
  1990. EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 0));
  1991. EXPECT_EQ(217,
  1992. message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a());
  1993. EXPECT_EQ(218,
  1994. message.GetExtension(UNITTEST::repeated_nested_message_extension, 0)
  1995. .bb());
  1996. EXPECT_EQ(
  1997. 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0)
  1998. .c());
  1999. EXPECT_EQ(
  2000. 220,
  2001. message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d());
  2002. EXPECT_EQ(
  2003. 227,
  2004. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb());
  2005. EXPECT_EQ(UNITTEST::TestAllTypes::BAR,
  2006. message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0));
  2007. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  2008. message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0));
  2009. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR,
  2010. message.GetExtension(UNITTEST::repeated_import_enum_extension, 0));
  2011. EXPECT_EQ("224",
  2012. message.GetExtension(UNITTEST::repeated_string_piece_extension, 0));
  2013. EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 0));
  2014. }
  2015. inline void TestUtil::ExpectLastRepeatedsReleased(
  2016. const UNITTEST::TestAllTypes& message) {
  2017. ASSERT_EQ(1, message.repeatedgroup_size());
  2018. ASSERT_EQ(1, message.repeated_nested_message_size());
  2019. ASSERT_EQ(1, message.repeated_foreign_message_size());
  2020. ASSERT_EQ(1, message.repeated_import_message_size());
  2021. ASSERT_EQ(1, message.repeated_import_message_size());
  2022. EXPECT_EQ(217, message.repeatedgroup(0).a());
  2023. EXPECT_EQ(218, message.repeated_nested_message(0).bb());
  2024. EXPECT_EQ(219, message.repeated_foreign_message(0).c());
  2025. EXPECT_EQ(220, message.repeated_import_message(0).d());
  2026. EXPECT_EQ(220, message.repeated_import_message(0).d());
  2027. }
  2028. inline void TestUtil::ExpectLastRepeatedExtensionsReleased(
  2029. const UNITTEST::TestAllExtensions& message) {
  2030. ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeatedgroup_extension));
  2031. ASSERT_EQ(1,
  2032. message.ExtensionSize(UNITTEST::repeated_nested_message_extension));
  2033. ASSERT_EQ(
  2034. 1, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension));
  2035. ASSERT_EQ(1,
  2036. message.ExtensionSize(UNITTEST::repeated_import_message_extension));
  2037. ASSERT_EQ(1,
  2038. message.ExtensionSize(UNITTEST::repeated_lazy_message_extension));
  2039. EXPECT_EQ(217,
  2040. message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a());
  2041. EXPECT_EQ(218,
  2042. message.GetExtension(UNITTEST::repeated_nested_message_extension, 0)
  2043. .bb());
  2044. EXPECT_EQ(
  2045. 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0)
  2046. .c());
  2047. EXPECT_EQ(
  2048. 220,
  2049. message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d());
  2050. EXPECT_EQ(
  2051. 227,
  2052. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb());
  2053. }
  2054. inline void TestUtil::ExpectRepeatedsSwapped(
  2055. const UNITTEST::TestAllTypes& message) {
  2056. ASSERT_EQ(2, message.repeated_int32_size());
  2057. ASSERT_EQ(2, message.repeated_int64_size());
  2058. ASSERT_EQ(2, message.repeated_uint32_size());
  2059. ASSERT_EQ(2, message.repeated_uint64_size());
  2060. ASSERT_EQ(2, message.repeated_sint32_size());
  2061. ASSERT_EQ(2, message.repeated_sint64_size());
  2062. ASSERT_EQ(2, message.repeated_fixed32_size());
  2063. ASSERT_EQ(2, message.repeated_fixed64_size());
  2064. ASSERT_EQ(2, message.repeated_sfixed32_size());
  2065. ASSERT_EQ(2, message.repeated_sfixed64_size());
  2066. ASSERT_EQ(2, message.repeated_float_size());
  2067. ASSERT_EQ(2, message.repeated_double_size());
  2068. ASSERT_EQ(2, message.repeated_bool_size());
  2069. ASSERT_EQ(2, message.repeated_string_size());
  2070. ASSERT_EQ(2, message.repeated_bytes_size());
  2071. ASSERT_EQ(2, message.repeatedgroup_size());
  2072. ASSERT_EQ(2, message.repeated_nested_message_size());
  2073. ASSERT_EQ(2, message.repeated_foreign_message_size());
  2074. ASSERT_EQ(2, message.repeated_import_message_size());
  2075. ASSERT_EQ(2, message.repeated_import_message_size());
  2076. ASSERT_EQ(2, message.repeated_nested_enum_size());
  2077. ASSERT_EQ(2, message.repeated_foreign_enum_size());
  2078. ASSERT_EQ(2, message.repeated_import_enum_size());
  2079. #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
  2080. ASSERT_EQ(2, message.repeated_string_piece_size());
  2081. ASSERT_EQ(2, message.repeated_cord_size());
  2082. #endif
  2083. // Test that the first element and second element are flipped.
  2084. EXPECT_EQ(201, message.repeated_int32(1));
  2085. EXPECT_EQ(202, message.repeated_int64(1));
  2086. EXPECT_EQ(203, message.repeated_uint32(1));
  2087. EXPECT_EQ(204, message.repeated_uint64(1));
  2088. EXPECT_EQ(205, message.repeated_sint32(1));
  2089. EXPECT_EQ(206, message.repeated_sint64(1));
  2090. EXPECT_EQ(207, message.repeated_fixed32(1));
  2091. EXPECT_EQ(208, message.repeated_fixed64(1));
  2092. EXPECT_EQ(209, message.repeated_sfixed32(1));
  2093. EXPECT_EQ(210, message.repeated_sfixed64(1));
  2094. EXPECT_EQ(211, message.repeated_float(1));
  2095. EXPECT_EQ(212, message.repeated_double(1));
  2096. EXPECT_TRUE(message.repeated_bool(1));
  2097. EXPECT_EQ("215", message.repeated_string(1));
  2098. EXPECT_EQ("216", message.repeated_bytes(1));
  2099. EXPECT_EQ(217, message.repeatedgroup(1).a());
  2100. EXPECT_EQ(218, message.repeated_nested_message(1).bb());
  2101. EXPECT_EQ(219, message.repeated_foreign_message(1).c());
  2102. EXPECT_EQ(220, message.repeated_import_message(1).d());
  2103. EXPECT_EQ(220, message.repeated_import_message(1).d());
  2104. EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(1));
  2105. EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(1));
  2106. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(1));
  2107. EXPECT_EQ(301, message.repeated_int32(0));
  2108. EXPECT_EQ(302, message.repeated_int64(0));
  2109. EXPECT_EQ(303, message.repeated_uint32(0));
  2110. EXPECT_EQ(304, message.repeated_uint64(0));
  2111. EXPECT_EQ(305, message.repeated_sint32(0));
  2112. EXPECT_EQ(306, message.repeated_sint64(0));
  2113. EXPECT_EQ(307, message.repeated_fixed32(0));
  2114. EXPECT_EQ(308, message.repeated_fixed64(0));
  2115. EXPECT_EQ(309, message.repeated_sfixed32(0));
  2116. EXPECT_EQ(310, message.repeated_sfixed64(0));
  2117. EXPECT_EQ(311, message.repeated_float(0));
  2118. EXPECT_EQ(312, message.repeated_double(0));
  2119. EXPECT_FALSE(message.repeated_bool(0));
  2120. EXPECT_EQ("315", message.repeated_string(0));
  2121. EXPECT_EQ("316", message.repeated_bytes(0));
  2122. EXPECT_EQ(317, message.repeatedgroup(0).a());
  2123. EXPECT_EQ(318, message.repeated_nested_message(0).bb());
  2124. EXPECT_EQ(319, message.repeated_foreign_message(0).c());
  2125. EXPECT_EQ(320, message.repeated_import_message(0).d());
  2126. EXPECT_EQ(320, message.repeated_import_message(0).d());
  2127. EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, message.repeated_nested_enum(0));
  2128. EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.repeated_foreign_enum(0));
  2129. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, message.repeated_import_enum(0));
  2130. }
  2131. inline void TestUtil::ExpectRepeatedExtensionsSwapped(
  2132. const UNITTEST::TestAllExtensions& message) {
  2133. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int32_extension));
  2134. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int64_extension));
  2135. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint32_extension));
  2136. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint64_extension));
  2137. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint32_extension));
  2138. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint64_extension));
  2139. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed32_extension));
  2140. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed64_extension));
  2141. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension));
  2142. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension));
  2143. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_float_extension));
  2144. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_double_extension));
  2145. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bool_extension));
  2146. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_string_extension));
  2147. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bytes_extension));
  2148. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeatedgroup_extension));
  2149. ASSERT_EQ(2,
  2150. message.ExtensionSize(UNITTEST::repeated_nested_message_extension));
  2151. ASSERT_EQ(
  2152. 2, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension));
  2153. ASSERT_EQ(2,
  2154. message.ExtensionSize(UNITTEST::repeated_import_message_extension));
  2155. ASSERT_EQ(2,
  2156. message.ExtensionSize(UNITTEST::repeated_lazy_message_extension));
  2157. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension));
  2158. ASSERT_EQ(2,
  2159. message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension));
  2160. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_import_enum_extension));
  2161. ASSERT_EQ(2,
  2162. message.ExtensionSize(UNITTEST::repeated_string_piece_extension));
  2163. ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_cord_extension));
  2164. EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 1));
  2165. EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 1));
  2166. EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 1));
  2167. EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 1));
  2168. EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 1));
  2169. EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 1));
  2170. EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 1));
  2171. EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 1));
  2172. EXPECT_EQ(209,
  2173. message.GetExtension(UNITTEST::repeated_sfixed32_extension, 1));
  2174. EXPECT_EQ(210,
  2175. message.GetExtension(UNITTEST::repeated_sfixed64_extension, 1));
  2176. EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 1));
  2177. EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 1));
  2178. EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 1));
  2179. EXPECT_EQ("215",
  2180. message.GetExtension(UNITTEST::repeated_string_extension, 1));
  2181. EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 1));
  2182. EXPECT_EQ(217,
  2183. message.GetExtension(UNITTEST::repeatedgroup_extension, 1).a());
  2184. EXPECT_EQ(218,
  2185. message.GetExtension(UNITTEST::repeated_nested_message_extension, 1)
  2186. .bb());
  2187. EXPECT_EQ(
  2188. 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 1)
  2189. .c());
  2190. EXPECT_EQ(
  2191. 220,
  2192. message.GetExtension(UNITTEST::repeated_import_message_extension, 1).d());
  2193. EXPECT_EQ(
  2194. 227,
  2195. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 1).bb());
  2196. EXPECT_EQ(UNITTEST::TestAllTypes::BAR,
  2197. message.GetExtension(UNITTEST::repeated_nested_enum_extension, 1));
  2198. EXPECT_EQ(UNITTEST::FOREIGN_BAR,
  2199. message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 1));
  2200. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR,
  2201. message.GetExtension(UNITTEST::repeated_import_enum_extension, 1));
  2202. EXPECT_EQ("224",
  2203. message.GetExtension(UNITTEST::repeated_string_piece_extension, 1));
  2204. EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 1));
  2205. EXPECT_EQ(301, message.GetExtension(UNITTEST::repeated_int32_extension, 0));
  2206. EXPECT_EQ(302, message.GetExtension(UNITTEST::repeated_int64_extension, 0));
  2207. EXPECT_EQ(303, message.GetExtension(UNITTEST::repeated_uint32_extension, 0));
  2208. EXPECT_EQ(304, message.GetExtension(UNITTEST::repeated_uint64_extension, 0));
  2209. EXPECT_EQ(305, message.GetExtension(UNITTEST::repeated_sint32_extension, 0));
  2210. EXPECT_EQ(306, message.GetExtension(UNITTEST::repeated_sint64_extension, 0));
  2211. EXPECT_EQ(307, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0));
  2212. EXPECT_EQ(308, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0));
  2213. EXPECT_EQ(309,
  2214. message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0));
  2215. EXPECT_EQ(310,
  2216. message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0));
  2217. EXPECT_EQ(311, message.GetExtension(UNITTEST::repeated_float_extension, 0));
  2218. EXPECT_EQ(312, message.GetExtension(UNITTEST::repeated_double_extension, 0));
  2219. EXPECT_FALSE(message.GetExtension(UNITTEST::repeated_bool_extension, 0));
  2220. EXPECT_EQ("315",
  2221. message.GetExtension(UNITTEST::repeated_string_extension, 0));
  2222. EXPECT_EQ("316", message.GetExtension(UNITTEST::repeated_bytes_extension, 0));
  2223. EXPECT_EQ(317,
  2224. message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a());
  2225. EXPECT_EQ(318,
  2226. message.GetExtension(UNITTEST::repeated_nested_message_extension, 0)
  2227. .bb());
  2228. EXPECT_EQ(
  2229. 319, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0)
  2230. .c());
  2231. EXPECT_EQ(
  2232. 320,
  2233. message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d());
  2234. EXPECT_EQ(
  2235. 327,
  2236. message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb());
  2237. EXPECT_EQ(UNITTEST::TestAllTypes::BAZ,
  2238. message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0));
  2239. EXPECT_EQ(UNITTEST::FOREIGN_BAZ,
  2240. message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0));
  2241. EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ,
  2242. message.GetExtension(UNITTEST::repeated_import_enum_extension, 0));
  2243. EXPECT_EQ("324",
  2244. message.GetExtension(UNITTEST::repeated_string_piece_extension, 0));
  2245. EXPECT_EQ("325", message.GetExtension(UNITTEST::repeated_cord_extension, 0));
  2246. }
  2247. inline void TestUtil::SetOneof1(UNITTEST::TestOneof2* message) {
  2248. message->mutable_foo_lazy_message()->set_qux_int(100);
  2249. message->set_bar_string("101");
  2250. message->set_baz_int(102);
  2251. message->set_baz_string("103");
  2252. }
  2253. inline void TestUtil::SetOneof2(UNITTEST::TestOneof2* message) {
  2254. message->set_foo_int(200);
  2255. message->set_bar_enum(UNITTEST::TestOneof2::BAZ);
  2256. message->set_baz_int(202);
  2257. message->set_baz_string("203");
  2258. }
  2259. inline void TestUtil::ExpectOneofSet1(const UNITTEST::TestOneof2& message) {
  2260. ExpectAtMostOneFieldSetInOneof(message);
  2261. EXPECT_TRUE(message.has_foo_lazy_message());
  2262. EXPECT_TRUE(message.foo_lazy_message().has_qux_int());
  2263. EXPECT_TRUE(message.has_bar_string());
  2264. EXPECT_TRUE(message.has_baz_int());
  2265. EXPECT_TRUE(message.has_baz_string());
  2266. ASSERT_EQ(0, message.foo_lazy_message().corge_int_size());
  2267. EXPECT_EQ(100, message.foo_lazy_message().qux_int());
  2268. EXPECT_EQ("101", message.bar_string());
  2269. EXPECT_EQ(102, message.baz_int());
  2270. EXPECT_EQ("103", message.baz_string());
  2271. }
  2272. inline void TestUtil::ExpectOneofSet2(const UNITTEST::TestOneof2& message) {
  2273. ExpectAtMostOneFieldSetInOneof(message);
  2274. EXPECT_TRUE(message.has_foo_int());
  2275. EXPECT_TRUE(message.has_bar_enum());
  2276. EXPECT_TRUE(message.has_baz_int());
  2277. EXPECT_TRUE(message.has_baz_string());
  2278. EXPECT_EQ(200, message.foo_int());
  2279. EXPECT_EQ(UNITTEST::TestOneof2::BAZ, message.bar_enum());
  2280. EXPECT_EQ(202, message.baz_int());
  2281. EXPECT_EQ("203", message.baz_string());
  2282. }
  2283. inline void TestUtil::ExpectOneofClear(const UNITTEST::TestOneof2& message) {
  2284. EXPECT_FALSE(message.has_foo_int());
  2285. EXPECT_FALSE(message.has_foo_string());
  2286. EXPECT_FALSE(message.has_foo_bytes());
  2287. EXPECT_FALSE(message.has_foo_enum());
  2288. EXPECT_FALSE(message.has_foo_message());
  2289. EXPECT_FALSE(message.has_foogroup());
  2290. EXPECT_FALSE(message.has_foo_lazy_message());
  2291. EXPECT_FALSE(message.has_bar_int());
  2292. EXPECT_FALSE(message.has_bar_string());
  2293. EXPECT_FALSE(message.has_bar_bytes());
  2294. EXPECT_FALSE(message.has_bar_enum());
  2295. EXPECT_FALSE(message.has_baz_int());
  2296. EXPECT_FALSE(message.has_baz_string());
  2297. EXPECT_EQ(UNITTEST::TestOneof2::FOO_NOT_SET, message.foo_case());
  2298. EXPECT_EQ(UNITTEST::TestOneof2::BAR_NOT_SET, message.bar_case());
  2299. }
  2300. inline void TestUtil::ExpectAtMostOneFieldSetInOneof(
  2301. const UNITTEST::TestOneof2& message) {
  2302. int count = 0;
  2303. if (message.has_foo_int()) count++;
  2304. if (message.has_foo_string()) count++;
  2305. if (message.has_foo_bytes()) count++;
  2306. if (message.has_foo_enum()) count++;
  2307. if (message.has_foo_message()) count++;
  2308. if (message.has_foogroup()) count++;
  2309. if (message.has_foo_lazy_message()) count++;
  2310. EXPECT_LE(count, 1);
  2311. count = 0;
  2312. if (message.has_bar_int()) count++;
  2313. if (message.has_bar_string()) count++;
  2314. if (message.has_bar_bytes()) count++;
  2315. if (message.has_bar_enum()) count++;
  2316. EXPECT_TRUE(count == 0 || count == 1);
  2317. }
  2318. // ===================================================================
  2319. } // namespace protobuf
  2320. } // namespace google