12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829 |
- // Protocol Buffers - Google's data interchange format
- // Copyright 2008 Google Inc. All rights reserved.
- // https://developers.google.com/protocol-buffers/
- //
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are
- // met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following disclaimer
- // in the documentation and/or other materials provided with the
- // distribution.
- // * Neither the name of Google Inc. nor the names of its
- // contributors may be used to endorse or promote products derived from
- // this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- #include <google/protobuf/map_test_util.h>
- #include <google/protobuf/map_test_util_impl.h>
- #include <google/protobuf/descriptor.h>
- #include <google/protobuf/message.h>
- namespace google {
- namespace protobuf {
- void MapTestUtil::SetMapFields(unittest::TestMap* message) {
- MapTestUtilImpl::SetMapFields<unittest::MapEnum, unittest::MAP_ENUM_BAR,
- unittest::MAP_ENUM_BAZ>(message);
- }
- void MapTestUtil::SetArenaMapFields(unittest::TestArenaMap* message) {
- MapTestUtilImpl::SetArenaMapFields<unittest::MapEnum, unittest::MAP_ENUM_BAR,
- unittest::MAP_ENUM_BAZ>(message);
- }
- void MapTestUtil::SetMapFieldsInitialized(unittest::TestMap* message) {
- MapTestUtilImpl::SetMapFieldsInitialized(message);
- }
- void MapTestUtil::ModifyMapFields(unittest::TestMap* message) {
- MapTestUtilImpl::ModifyMapFields<unittest::MapEnum, unittest::MAP_ENUM_FOO>(
- message);
- }
- void MapTestUtil::ExpectClear(const unittest::TestMap& message) {
- MapTestUtilImpl::ExpectClear(message);
- }
- void MapTestUtil::ExpectMapFieldsSet(const unittest::TestMap& message) {
- MapTestUtilImpl::ExpectMapFieldsSet<unittest::MapEnum, unittest::MAP_ENUM_BAR,
- unittest::MAP_ENUM_BAZ>(message);
- }
- void MapTestUtil::ExpectArenaMapFieldsSet(
- const unittest::TestArenaMap& message) {
- MapTestUtilImpl::ExpectArenaMapFieldsSet<
- unittest::MapEnum, unittest::MAP_ENUM_BAR, unittest::MAP_ENUM_BAZ>(
- message);
- }
- void MapTestUtil::ExpectMapFieldsSetInitialized(
- const unittest::TestMap& message) {
- MapTestUtilImpl::ExpectMapFieldsSetInitialized<unittest::MapEnum,
- unittest::MAP_ENUM_FOO>(
- message);
- }
- void MapTestUtil::ExpectMapFieldsModified(
- const unittest::TestMap& message) {
- MapTestUtilImpl::ExpectMapFieldsModified<
- unittest::MapEnum, unittest::MAP_ENUM_BAR, unittest::MAP_ENUM_FOO>(
- message);
- }
- void MapTestUtil::ExpectMapsSize(
- const unittest::TestMap& message, int size) {
- const Descriptor* descriptor = message.GetDescriptor();
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_int32_int32")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_int64_int64")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_uint32_uint32")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_uint64_uint64")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_sint32_sint32")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_sint64_sint64")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_fixed32_fixed32")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_fixed64_fixed64")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_sfixed32_sfixed32")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_sfixed64_sfixed64")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_int32_float")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_int32_double")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_bool_bool")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_string_string")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_int32_bytes")));
- EXPECT_EQ(size, message.GetReflection()->FieldSize(
- message, descriptor->FindFieldByName("map_int32_foreign_message")));
- }
- std::vector<const Message*> MapTestUtil::GetMapEntries(
- const unittest::TestMap& message, int index) {
- const Descriptor* descriptor = message.GetDescriptor();
- std::vector<const Message*> result;
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_int32_int32"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_int64_int64"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_uint32_uint32"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_uint64_uint64"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_sint32_sint32"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_sint64_sint64"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_fixed32_fixed32"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_fixed64_fixed64"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_sfixed32_sfixed32"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_sfixed64_sfixed64"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_int32_float"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_int32_double"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_bool_bool"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_string_string"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_int32_bytes"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_int32_enum"), index));
- result.push_back(&message.GetReflection()->GetRepeatedMessage(
- message, descriptor->FindFieldByName("map_int32_foreign_message"), index));
- return result;
- }
- std::vector<const Message*> MapTestUtil::GetMapEntriesFromRelease(
- unittest::TestMap* message) {
- const Descriptor* descriptor = message->GetDescriptor();
- std::vector<const Message*> result;
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_int32_int32")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_int64_int64")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_uint32_uint32")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_uint64_uint64")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_sint32_sint32")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_sint64_sint64")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_fixed32_fixed32")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_fixed64_fixed64")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_sfixed32_sfixed32")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_sfixed64_sfixed64")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_int32_float")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_int32_double")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_bool_bool")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_string_string")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_int32_bytes")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_int32_enum")));
- result.push_back(message->GetReflection()->ReleaseLast(
- message, descriptor->FindFieldByName("map_int32_foreign_message")));
- return result;
- }
- MapReflectionTester::MapReflectionTester(
- const Descriptor* base_descriptor)
- : base_descriptor_(base_descriptor) {
- const DescriptorPool* pool = base_descriptor->file()->pool();
- map_enum_foo_ = pool->FindEnumValueByName("protobuf_unittest.MAP_ENUM_FOO");
- map_enum_bar_ = pool->FindEnumValueByName("protobuf_unittest.MAP_ENUM_BAR");
- map_enum_baz_ = pool->FindEnumValueByName("protobuf_unittest.MAP_ENUM_BAZ");
- foreign_c_ = pool->FindFieldByName(
- "protobuf_unittest.ForeignMessage.c");
- map_int32_int32_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32Int32Entry.key");
- map_int32_int32_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32Int32Entry.value");
- map_int64_int64_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt64Int64Entry.key");
- map_int64_int64_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt64Int64Entry.value");
- map_uint32_uint32_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapUint32Uint32Entry.key");
- map_uint32_uint32_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapUint32Uint32Entry.value");
- map_uint64_uint64_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapUint64Uint64Entry.key");
- map_uint64_uint64_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapUint64Uint64Entry.value");
- map_sint32_sint32_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSint32Sint32Entry.key");
- map_sint32_sint32_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSint32Sint32Entry.value");
- map_sint64_sint64_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSint64Sint64Entry.key");
- map_sint64_sint64_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSint64Sint64Entry.value");
- map_fixed32_fixed32_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapFixed32Fixed32Entry.key");
- map_fixed32_fixed32_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapFixed32Fixed32Entry.value");
- map_fixed64_fixed64_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapFixed64Fixed64Entry.key");
- map_fixed64_fixed64_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapFixed64Fixed64Entry.value");
- map_sfixed32_sfixed32_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSfixed32Sfixed32Entry.key");
- map_sfixed32_sfixed32_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSfixed32Sfixed32Entry.value");
- map_sfixed64_sfixed64_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSfixed64Sfixed64Entry.key");
- map_sfixed64_sfixed64_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapSfixed64Sfixed64Entry.value");
- map_int32_float_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32FloatEntry.key");
- map_int32_float_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32FloatEntry.value");
- map_int32_double_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32DoubleEntry.key");
- map_int32_double_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32DoubleEntry.value");
- map_bool_bool_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapBoolBoolEntry.key");
- map_bool_bool_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapBoolBoolEntry.value");
- map_string_string_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapStringStringEntry.key");
- map_string_string_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapStringStringEntry.value");
- map_int32_bytes_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32BytesEntry.key");
- map_int32_bytes_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32BytesEntry.value");
- map_int32_enum_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32EnumEntry.key");
- map_int32_enum_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32EnumEntry.value");
- map_int32_foreign_message_key_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32ForeignMessageEntry.key");
- map_int32_foreign_message_val_ = pool->FindFieldByName(
- "protobuf_unittest.TestMap.MapInt32ForeignMessageEntry.value");
- EXPECT_FALSE(map_enum_foo_ == NULL);
- EXPECT_FALSE(map_enum_bar_ == NULL);
- EXPECT_FALSE(map_enum_baz_ == NULL);
- EXPECT_FALSE(map_int32_int32_key_ == NULL);
- EXPECT_FALSE(map_int32_int32_val_ == NULL);
- EXPECT_FALSE(map_int64_int64_key_ == NULL);
- EXPECT_FALSE(map_int64_int64_val_ == NULL);
- EXPECT_FALSE(map_uint32_uint32_key_ == NULL);
- EXPECT_FALSE(map_uint32_uint32_val_ == NULL);
- EXPECT_FALSE(map_uint64_uint64_key_ == NULL);
- EXPECT_FALSE(map_uint64_uint64_val_ == NULL);
- EXPECT_FALSE(map_sint32_sint32_key_ == NULL);
- EXPECT_FALSE(map_sint32_sint32_val_ == NULL);
- EXPECT_FALSE(map_sint64_sint64_key_ == NULL);
- EXPECT_FALSE(map_sint64_sint64_val_ == NULL);
- EXPECT_FALSE(map_fixed32_fixed32_key_ == NULL);
- EXPECT_FALSE(map_fixed32_fixed32_val_ == NULL);
- EXPECT_FALSE(map_fixed64_fixed64_key_ == NULL);
- EXPECT_FALSE(map_fixed64_fixed64_val_ == NULL);
- EXPECT_FALSE(map_sfixed32_sfixed32_key_ == NULL);
- EXPECT_FALSE(map_sfixed32_sfixed32_val_ == NULL);
- EXPECT_FALSE(map_sfixed64_sfixed64_key_ == NULL);
- EXPECT_FALSE(map_sfixed64_sfixed64_val_ == NULL);
- EXPECT_FALSE(map_int32_float_key_ == NULL);
- EXPECT_FALSE(map_int32_float_val_ == NULL);
- EXPECT_FALSE(map_int32_double_key_ == NULL);
- EXPECT_FALSE(map_int32_double_val_ == NULL);
- EXPECT_FALSE(map_bool_bool_key_ == NULL);
- EXPECT_FALSE(map_bool_bool_val_ == NULL);
- EXPECT_FALSE(map_string_string_key_ == NULL);
- EXPECT_FALSE(map_string_string_val_ == NULL);
- EXPECT_FALSE(map_int32_bytes_key_ == NULL);
- EXPECT_FALSE(map_int32_bytes_val_ == NULL);
- EXPECT_FALSE(map_int32_enum_key_ == NULL);
- EXPECT_FALSE(map_int32_enum_val_ == NULL);
- EXPECT_FALSE(map_int32_foreign_message_key_ == NULL);
- EXPECT_FALSE(map_int32_foreign_message_val_ == NULL);
- }
- // Shorthand to get a FieldDescriptor for a field of unittest::TestMap.
- const FieldDescriptor* MapReflectionTester::F(const string& name) {
- const FieldDescriptor* result = NULL;
- result = base_descriptor_->FindFieldByName(name);
- GOOGLE_CHECK(result != NULL);
- return result;
- }
- void MapReflectionTester::SetMapFieldsViaReflection(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- Message* sub_message = NULL;
- Message* sub_foreign_message = NULL;
- // Add first element.
- sub_message = reflection->AddMessage(message, F("map_int32_int32"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_int32_key_, 0);
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_int32_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_int64_int64"));
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_int64_int64_key_, 0);
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_int64_int64_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_uint32_uint32_key_, 0);
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_uint32_uint32_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_uint64_uint64_key_, 0);
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_uint64_uint64_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sint32_sint32_key_, 0);
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sint32_sint32_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sint64_sint64_key_, 0);
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sint64_sint64_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_fixed32_fixed32_key_, 0);
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_fixed32_fixed32_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_fixed64_fixed64_key_, 0);
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_fixed64_fixed64_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sfixed32_sfixed32_key_, 0);
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sfixed32_sfixed32_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sfixed64_sfixed64_key_, 0);
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sfixed64_sfixed64_val_, 0);
- sub_message = reflection->AddMessage(message, F("map_int32_float"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_float_key_, 0);
- sub_message->GetReflection()
- ->SetFloat(sub_message, map_int32_float_val_, 0.0);
- sub_message = reflection->AddMessage(message, F("map_int32_double"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_double_key_, 0);
- sub_message->GetReflection()
- ->SetDouble(sub_message, map_int32_double_val_, 0.0);
- sub_message = reflection->AddMessage(message, F("map_bool_bool"));
- sub_message->GetReflection()
- ->SetBool(sub_message, map_bool_bool_key_, false);
- sub_message->GetReflection()
- ->SetBool(sub_message, map_bool_bool_val_, false);
- sub_message = reflection->AddMessage(message, F("map_string_string"));
- sub_message->GetReflection()
- ->SetString(sub_message, map_string_string_key_, "0");
- sub_message->GetReflection()
- ->SetString(sub_message, map_string_string_val_, "0");
- sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_bytes_key_, 0);
- sub_message->GetReflection()
- ->SetString(sub_message, map_int32_bytes_val_, "0");
- sub_message = reflection->AddMessage(message, F("map_int32_enum"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_enum_key_, 0);
- sub_message->GetReflection()
- ->SetEnum(sub_message, map_int32_enum_val_, map_enum_bar_);
- sub_message = reflection
- ->AddMessage(message, F("map_int32_foreign_message"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_foreign_message_key_, 0);
- sub_foreign_message = sub_message->GetReflection()->
- MutableMessage(sub_message, map_int32_foreign_message_val_, NULL);
- sub_foreign_message->GetReflection()->
- SetInt32(sub_foreign_message, foreign_c_, 0);
- // Add second element
- sub_message = reflection->AddMessage(message, F("map_int32_int32"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_int32_key_, 1);
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_int32_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_int64_int64"));
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_int64_int64_key_, 1);
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_int64_int64_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_uint32_uint32_key_, 1);
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_uint32_uint32_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_uint64_uint64_key_, 1);
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_uint64_uint64_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sint32_sint32_key_, 1);
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sint32_sint32_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sint64_sint64_key_, 1);
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sint64_sint64_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_fixed32_fixed32_key_, 1);
- sub_message->GetReflection()
- ->SetUInt32(sub_message, map_fixed32_fixed32_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_fixed64_fixed64_key_, 1);
- sub_message->GetReflection()
- ->SetUInt64(sub_message, map_fixed64_fixed64_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sfixed32_sfixed32_key_, 1);
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_sfixed32_sfixed32_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sfixed64_sfixed64_key_, 1);
- sub_message->GetReflection()
- ->SetInt64(sub_message, map_sfixed64_sfixed64_val_, 1);
- sub_message = reflection->AddMessage(message, F("map_int32_float"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_float_key_, 1);
- sub_message->GetReflection()
- ->SetFloat(sub_message, map_int32_float_val_, 1.0);
- sub_message = reflection->AddMessage(message, F("map_int32_double"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_double_key_, 1);
- sub_message->GetReflection()
- ->SetDouble(sub_message, map_int32_double_val_, 1.0);
- sub_message = reflection->AddMessage(message, F("map_bool_bool"));
- sub_message->GetReflection()
- ->SetBool(sub_message, map_bool_bool_key_, true);
- sub_message->GetReflection()
- ->SetBool(sub_message, map_bool_bool_val_, true);
- sub_message = reflection->AddMessage(message, F("map_string_string"));
- sub_message->GetReflection()
- ->SetString(sub_message, map_string_string_key_, "1");
- sub_message->GetReflection()
- ->SetString(sub_message, map_string_string_val_, "1");
- sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_bytes_key_, 1);
- sub_message->GetReflection()
- ->SetString(sub_message, map_int32_bytes_val_, "1");
- sub_message = reflection->AddMessage(message, F("map_int32_enum"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_enum_key_, 1);
- sub_message->GetReflection()
- ->SetEnum(sub_message, map_int32_enum_val_, map_enum_baz_);
- sub_message = reflection
- ->AddMessage(message, F("map_int32_foreign_message"));
- sub_message->GetReflection()
- ->SetInt32(sub_message, map_int32_foreign_message_key_, 1);
- sub_foreign_message = sub_message->GetReflection()->
- MutableMessage(sub_message, map_int32_foreign_message_val_, NULL);
- sub_foreign_message->GetReflection()->
- SetInt32(sub_foreign_message, foreign_c_, 1);
- }
- void MapReflectionTester::SetMapFieldsViaMapReflection(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- Message* sub_foreign_message = NULL;
- MapValueRef map_val;
- // Add first element.
- MapKey map_key;
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_int32"), map_key, &map_val));
- map_val.SetInt32Value(0);
- map_key.SetInt64Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int64_int64"), map_key, &map_val));
- map_val.SetInt64Value(0);
- map_key.SetUInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_uint32_uint32"), map_key, &map_val));
- map_val.SetUInt32Value(0);
- map_key.SetUInt64Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_uint64_uint64"), map_key, &map_val));
- map_val.SetUInt64Value(0);
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_sint32_sint32"), map_key, &map_val));
- map_val.SetInt32Value(0);
- map_key.SetInt64Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_sint64_sint64"), map_key, &map_val));
- map_val.SetInt64Value(0);
- map_key.SetUInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_fixed32_fixed32"), map_key, &map_val));
- map_val.SetUInt32Value(0);
- map_key.SetUInt64Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_fixed64_fixed64"), map_key, &map_val));
- map_val.SetUInt64Value(0);
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_sfixed32_sfixed32"), map_key, &map_val));
- map_val.SetInt32Value(0);
- map_key.SetInt64Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_sfixed64_sfixed64"), map_key, &map_val));
- map_val.SetInt64Value(0);
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_float"), map_key, &map_val));
- map_val.SetFloatValue(0.0);
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_double"), map_key, &map_val));
- map_val.SetDoubleValue(0.0);
- map_key.SetBoolValue(false);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_bool_bool"), map_key, &map_val));
- map_val.SetBoolValue(false);
- map_key.SetStringValue("0");
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_string_string"), map_key, &map_val));
- map_val.SetStringValue("0");
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_bytes"), map_key, &map_val));
- map_val.SetStringValue("0");
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_enum"), map_key, &map_val));
- map_val.SetEnumValue(map_enum_bar_->number());
- map_key.SetInt32Value(0);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_foreign_message"), map_key, &map_val));
- sub_foreign_message = map_val.MutableMessageValue();
- sub_foreign_message->GetReflection()->SetInt32(
- sub_foreign_message, foreign_c_, 0);
- // Add second element
- map_key.SetInt32Value(1);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_int32"), map_key, &map_val));
- map_val.SetInt32Value(1);
- EXPECT_FALSE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_int32"), map_key, &map_val));
- map_key.SetInt64Value(1);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int64_int64"), map_key, &map_val));
- map_val.SetInt64Value(1);
- EXPECT_FALSE(reflection->InsertOrLookupMapValue(
- message, F("map_int64_int64"), map_key, &map_val));
- map_key.SetUInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_uint32_uint32"), map_key, &map_val);
- map_val.SetUInt32Value(1);
- map_key.SetUInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_uint64_uint64"), map_key, &map_val);
- map_val.SetUInt64Value(1);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sint32_sint32"), map_key, &map_val);
- map_val.SetInt32Value(1);
- map_key.SetInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sint64_sint64"), map_key, &map_val);
- map_val.SetInt64Value(1);
- map_key.SetUInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_fixed32_fixed32"), map_key, &map_val);
- map_val.SetUInt32Value(1);
- map_key.SetUInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_fixed64_fixed64"), map_key, &map_val);
- map_val.SetUInt64Value(1);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sfixed32_sfixed32"), map_key, &map_val);
- map_val.SetInt32Value(1);
- map_key.SetInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sfixed64_sfixed64"), map_key, &map_val);
- map_val.SetInt64Value(1);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_float"), map_key, &map_val);
- map_val.SetFloatValue(1.0);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_double"), map_key, &map_val);
- map_val.SetDoubleValue(1.0);
- map_key.SetBoolValue(true);
- reflection->InsertOrLookupMapValue(
- message, F("map_bool_bool"), map_key, &map_val);
- map_val.SetBoolValue(true);
- map_key.SetStringValue("1");
- reflection->InsertOrLookupMapValue(
- message, F("map_string_string"), map_key, &map_val);
- map_val.SetStringValue("1");
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_bytes"), map_key, &map_val);
- map_val.SetStringValue("1");
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_enum"), map_key, &map_val);
- map_val.SetEnumValue(map_enum_baz_->number());
- map_key.SetInt32Value(1);
- EXPECT_TRUE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_foreign_message"), map_key, &map_val));
- sub_foreign_message = map_val.MutableMessageValue();
- sub_foreign_message->GetReflection()->SetInt32(
- sub_foreign_message, foreign_c_, 1);
- }
- void MapReflectionTester::GetMapValueViaMapReflection(Message* message,
- const string& field_name,
- const MapKey& map_key,
- MapValueRef* map_val) {
- const Reflection* reflection = message->GetReflection();
- EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F(field_name),
- map_key, map_val));
- }
- Message* MapReflectionTester::GetMapEntryViaReflection(Message* message,
- const string& field_name,
- int index) {
- const Reflection* reflection = message->GetReflection();
- return reflection->MutableRepeatedMessage(message, F(field_name), index);
- }
- MapIterator MapReflectionTester::MapBegin(Message* message,
- const string& field_name) {
- const Reflection* reflection = message->GetReflection();
- return reflection->MapBegin(message, F(field_name));
- }
- MapIterator MapReflectionTester::MapEnd(Message* message,
- const string& field_name) {
- const Reflection* reflection = message->GetReflection();
- return reflection->MapEnd(message, F(field_name));
- }
- void MapReflectionTester::ClearMapFieldsViaReflection(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- reflection->ClearField(message, F("map_int32_int32"));
- reflection->ClearField(message, F("map_int64_int64"));
- reflection->ClearField(message, F("map_uint32_uint32"));
- reflection->ClearField(message, F("map_uint64_uint64"));
- reflection->ClearField(message, F("map_sint32_sint32"));
- reflection->ClearField(message, F("map_sint64_sint64"));
- reflection->ClearField(message, F("map_fixed32_fixed32"));
- reflection->ClearField(message, F("map_fixed64_fixed64"));
- reflection->ClearField(message, F("map_sfixed32_sfixed32"));
- reflection->ClearField(message, F("map_sfixed64_sfixed64"));
- reflection->ClearField(message, F("map_int32_float"));
- reflection->ClearField(message, F("map_int32_double"));
- reflection->ClearField(message, F("map_bool_bool"));
- reflection->ClearField(message, F("map_string_string"));
- reflection->ClearField(message, F("map_int32_bytes"));
- reflection->ClearField(message, F("map_int32_enum"));
- reflection->ClearField(message, F("map_int32_foreign_message"));
- }
- void MapReflectionTester::ModifyMapFieldsViaReflection(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- MapValueRef map_val;
- Message* sub_foreign_message;
- // Modify the second element
- MapKey map_key;
- map_key.SetInt32Value(1);
- EXPECT_FALSE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_int32"), map_key, &map_val));
- map_val.SetInt32Value(2);
- map_key.SetInt64Value(1);
- EXPECT_FALSE(reflection->InsertOrLookupMapValue(
- message, F("map_int64_int64"), map_key, &map_val));
- map_val.SetInt64Value(2);
- map_key.SetUInt32Value(1);
- EXPECT_FALSE(reflection->InsertOrLookupMapValue(
- message, F("map_uint32_uint32"), map_key, &map_val));
- map_val.SetUInt32Value(2);
- map_key.SetUInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_uint64_uint64"), map_key, &map_val);
- map_val.SetUInt64Value(2);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sint32_sint32"), map_key, &map_val);
- map_val.SetInt32Value(2);
- map_key.SetInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sint64_sint64"), map_key, &map_val);
- map_val.SetInt64Value(2);
- map_key.SetUInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_fixed32_fixed32"), map_key, &map_val);
- map_val.SetUInt32Value(2);
- map_key.SetUInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_fixed64_fixed64"), map_key, &map_val);
- map_val.SetUInt64Value(2);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sfixed32_sfixed32"), map_key, &map_val);
- map_val.SetInt32Value(2);
- map_key.SetInt64Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_sfixed64_sfixed64"), map_key, &map_val);
- map_val.SetInt64Value(2);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_float"), map_key, &map_val);
- map_val.SetFloatValue(2.0);
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_double"), map_key, &map_val);
- map_val.SetDoubleValue(2.0);
- map_key.SetBoolValue(true);
- reflection->InsertOrLookupMapValue(
- message, F("map_bool_bool"), map_key, &map_val);
- map_val.SetBoolValue(false);
- map_key.SetStringValue("1");
- reflection->InsertOrLookupMapValue(
- message, F("map_string_string"), map_key, &map_val);
- map_val.SetStringValue("2");
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_bytes"), map_key, &map_val);
- map_val.SetStringValue("2");
- map_key.SetInt32Value(1);
- reflection->InsertOrLookupMapValue(
- message, F("map_int32_enum"), map_key, &map_val);
- map_val.SetEnumValue(map_enum_foo_->number());
- map_key.SetInt32Value(1);
- EXPECT_FALSE(reflection->InsertOrLookupMapValue(
- message, F("map_int32_foreign_message"), map_key, &map_val));
- sub_foreign_message = map_val.MutableMessageValue();
- sub_foreign_message->GetReflection()->SetInt32(
- sub_foreign_message, foreign_c_, 2);
- }
- void MapReflectionTester::RemoveLastMapsViaReflection(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- std::vector<const FieldDescriptor*> output;
- reflection->ListFields(*message, &output);
- for (int i = 0; i < output.size(); ++i) {
- const FieldDescriptor* field = output[i];
- if (!field->is_repeated()) continue;
- reflection->RemoveLast(message, field);
- }
- }
- void MapReflectionTester::ReleaseLastMapsViaReflection(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- std::vector<const FieldDescriptor*> output;
- reflection->ListFields(*message, &output);
- for (int i = 0; i < output.size(); ++i) {
- const FieldDescriptor* field = output[i];
- if (!field->is_repeated()) continue;
- if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue;
- Message* released = reflection->ReleaseLast(message, field);
- ASSERT_TRUE(released != NULL) << "ReleaseLast returned NULL for: "
- << field->name();
- delete released;
- }
- }
- void MapReflectionTester::SwapMapsViaReflection(Message* message) {
- const Reflection* reflection = message->GetReflection();
- std::vector<const FieldDescriptor*> output;
- reflection->ListFields(*message, &output);
- for (int i = 0; i < output.size(); ++i) {
- const FieldDescriptor* field = output[i];
- if (!field->is_repeated()) continue;
- reflection->SwapElements(message, field, 0, 1);
- }
- }
- void MapReflectionTester::
- MutableUnknownFieldsOfMapFieldsViaReflection(Message* message) {
- const Reflection* reflection = message->GetReflection();
- Message* sub_message = NULL;
- sub_message = reflection->AddMessage(message, F("map_int32_int32"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_int64_int64"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_int32_float"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_int32_double"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_bool_bool"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_string_string"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_int32_enum"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- sub_message = reflection->AddMessage(message, F("map_int32_foreign_message"));
- EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
- NULL);
- }
- void MapReflectionTester::ExpectMapFieldsSetViaReflection(
- const Message& message) {
- string scratch;
- const Reflection* reflection = message.GetReflection();
- const Message* sub_message;
- MapKey map_key;
- // -----------------------------------------------------------------
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_int32")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_int64_int64")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_uint32_uint32")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_uint64_uint64")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_sint32_sint32")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_sint64_sint64")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_fixed32_fixed32")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_fixed64_fixed64")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_sfixed32_sfixed32")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_sfixed64_sfixed64")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_float")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_double")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_bool_bool")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_string_string")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_bytes")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_enum")));
- ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_foreign_message")));
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- // Check with RepeatedField Reflection
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_int32_int32"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_int32_int32_key_);
- int32 val = sub_message->GetReflection()->GetInt32(
- *sub_message, map_int32_int32_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_TRUE(reflection->ContainsMapKey(
- message, F("map_int32_int32"), map_key));
- }
- }
- {
- std::map<int64, int64> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- // Check with RepeatedField Reflection
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_int64_int64"), i);
- int64 key = sub_message->GetReflection()->GetInt64(
- *sub_message, map_int64_int64_key_);
- int64 val = sub_message->GetReflection()->GetInt64(
- *sub_message, map_int64_int64_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt64Value(key);
- EXPECT_TRUE(reflection->ContainsMapKey(
- message, F("map_int64_int64"), map_key));
- }
- }
- {
- std::map<uint32, uint32> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- // Check with RepeatedField Reflection
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_uint32_uint32"), i);
- uint32 key = sub_message->GetReflection()->GetUInt32(
- *sub_message, map_uint32_uint32_key_);
- uint32 val = sub_message->GetReflection()->GetUInt32(
- *sub_message, map_uint32_uint32_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetUInt32Value(key);
- EXPECT_TRUE(reflection->ContainsMapKey(
- message, F("map_uint32_uint32"), map_key));
- }
- }
- {
- std::map<uint64, uint64> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_uint64_uint64"), i);
- uint64 key = sub_message->GetReflection()->GetUInt64(
- *sub_message, map_uint64_uint64_key_);
- uint64 val = sub_message->GetReflection()->GetUInt64(
- *sub_message, map_uint64_uint64_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetUInt64Value(key);
- EXPECT_TRUE(reflection->ContainsMapKey(
- message, F("map_uint64_uint64"), map_key));
- }
- }
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_sint32_sint32"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_sint32_sint32_key_);
- int32 val = sub_message->GetReflection()->GetInt32(
- *sub_message, map_sint32_sint32_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_sint32_sint32"), map_key));
- }
- }
- {
- std::map<int64, int64> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_sint64_sint64"), i);
- int64 key = sub_message->GetReflection()->GetInt64(
- *sub_message, map_sint64_sint64_key_);
- int64 val = sub_message->GetReflection()->GetInt64(
- *sub_message, map_sint64_sint64_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt64Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_sint64_sint64"), map_key));
- }
- }
- {
- std::map<uint32, uint32> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_fixed32_fixed32"), i);
- uint32 key = sub_message->GetReflection()->GetUInt32(
- *sub_message, map_fixed32_fixed32_key_);
- uint32 val = sub_message->GetReflection()->GetUInt32(
- *sub_message, map_fixed32_fixed32_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetUInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_fixed32_fixed32"), map_key));
- }
- }
- {
- std::map<uint64, uint64> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_fixed64_fixed64"), i);
- uint64 key = sub_message->GetReflection()->GetUInt64(
- *sub_message, map_fixed64_fixed64_key_);
- uint64 val = sub_message->GetReflection()->GetUInt64(
- *sub_message, map_fixed64_fixed64_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetUInt64Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_fixed64_fixed64"), map_key));
- }
- }
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message = &reflection->GetRepeatedMessage(
- message, F("map_sfixed32_sfixed32"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_sfixed32_sfixed32_key_);
- int32 val = sub_message->GetReflection()->GetInt32(
- *sub_message, map_sfixed32_sfixed32_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_sfixed32_sfixed32"), map_key));
- }
- }
- {
- std::map<int64, int64> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message = &reflection->GetRepeatedMessage(
- message, F("map_sfixed64_sfixed64"), i);
- int64 key = sub_message->GetReflection()->GetInt64(
- *sub_message, map_sfixed64_sfixed64_key_);
- int64 val = sub_message->GetReflection()->GetInt64(
- *sub_message, map_sfixed64_sfixed64_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt64Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_sfixed64_sfixed64"), map_key));
- }
- }
- {
- std::map<int32, float> map;
- map[0] = 0.0;
- map[1] = 1.0;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_int32_float"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_int32_float_key_);
- float val = sub_message->GetReflection()->GetFloat(
- *sub_message, map_int32_float_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_int32_float"), map_key));
- }
- }
- {
- std::map<int32, double> map;
- map[0] = 0.0;
- map[1] = 1.0;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_int32_double"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_int32_double_key_);
- double val = sub_message->GetReflection()->GetDouble(
- *sub_message, map_int32_double_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_int32_double"), map_key));
- }
- }
- {
- std::map<bool, bool> map;
- map[false] = false;
- map[true] = true;
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_bool_bool"), i);
- bool key = sub_message->GetReflection()->GetBool(
- *sub_message, map_bool_bool_key_);
- bool val = sub_message->GetReflection()->GetBool(
- *sub_message, map_bool_bool_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetBoolValue(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_bool_bool"), map_key));
- }
- }
- {
- std::map<string, string> map;
- map["0"] = "0";
- map["1"] = "1";
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_string_string"), i);
- string key = sub_message->GetReflection()->GetString(
- *sub_message, map_string_string_key_);
- string val = sub_message->GetReflection()->GetString(
- *sub_message, map_string_string_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetStringValue(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_string_string"), map_key));
- }
- }
- {
- std::map<int32, string> map;
- map[0] = "0";
- map[1] = "1";
- for (int i = 0; i < 2; i++) {
- sub_message =
- &reflection->GetRepeatedMessage(message, F("map_int32_bytes"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_int32_bytes_key_);
- string val = sub_message->GetReflection()->GetString(
- *sub_message, map_int32_bytes_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_int32_bytes"), map_key));
- }
- }
- {
- std::map<int32, const EnumValueDescriptor*> map;
- map[0] = map_enum_bar_;
- map[1] = map_enum_baz_;
- for (int i = 0; i < 2; i++) {
- sub_message = &reflection->GetRepeatedMessage(
- message, F("map_int32_enum"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_int32_enum_key_);
- const EnumValueDescriptor* val = sub_message->GetReflection()->GetEnum(
- *sub_message, map_int32_enum_val_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_int32_enum"), map_key));
- }
- }
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- for (int i = 0; i < 2; i++) {
- sub_message = &reflection->GetRepeatedMessage(
- message, F("map_int32_foreign_message"), i);
- int32 key = sub_message->GetReflection()->GetInt32(
- *sub_message, map_int32_foreign_message_key_);
- const Message& foreign_message = sub_message->GetReflection()->GetMessage(
- *sub_message, map_int32_foreign_message_val_);
- int32 val = foreign_message.GetReflection()->GetInt32(
- foreign_message, foreign_c_);
- EXPECT_EQ(map[key], val);
- // Check with Map Reflection
- map_key.SetInt32Value(key);
- EXPECT_EQ(true, reflection->ContainsMapKey(
- message, F("map_int32_foreign_message"), map_key));
- }
- }
- }
- void MapReflectionTester::ExpectMapFieldsSetViaReflectionIterator(
- Message* message) {
- string scratch;
- string serialized;
- const Reflection* reflection = message->GetReflection();
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_int32")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int64_int64")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_uint32_uint32")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_uint64_uint64")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sint32_sint32")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sint64_sint64")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_fixed32_fixed32")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_fixed64_fixed64")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sfixed32_sfixed32")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sfixed64_sfixed64")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_float")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_double")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_bool_bool")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_string_string")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_bytes")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_enum")));
- ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_foreign_message")));
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- int size = 0;
- for (MapIterator iter = reflection->MapBegin(message, F("map_int32_int32"));
- iter != reflection->MapEnd(message, F("map_int32_int32"));
- ++iter, ++size) {
- // Check const methods do not invalidate map.
- message->DebugString();
- message->ShortDebugString();
- message->SerializeToString(&serialized);
- message->SpaceUsed();
- message->ByteSize();
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
- iter.GetValueRef().GetInt32Value());
- }
- EXPECT_EQ(size, 2);
- }
- {
- std::map<int64, int64> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(message, F("map_int64_int64"));
- iter != reflection->MapEnd(message, F("map_int64_int64")); ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt64Value()],
- iter.GetValueRef().GetInt64Value());
- }
- }
- {
- std::map<uint32, uint32> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_uint32_uint32"));
- iter != reflection->MapEnd(message, F("map_uint32_uint32"));
- ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetUInt32Value()],
- iter.GetValueRef().GetUInt32Value());
- }
- }
- {
- std::map<uint64, uint64> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_uint64_uint64"));
- iter != reflection->MapEnd(message, F("map_uint64_uint64"));
- ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetUInt64Value()],
- iter.GetValueRef().GetUInt64Value());
- }
- }
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_sint32_sint32"));
- iter != reflection->MapEnd(message, F("map_sint32_sint32"));
- ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
- iter.GetValueRef().GetInt32Value());
- }
- }
- {
- std::map<int64, int64> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_sint64_sint64"));
- iter != reflection->MapEnd(message, F("map_sint64_sint64")); ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt64Value()],
- iter.GetValueRef().GetInt64Value());
- }
- }
- {
- std::map<uint32, uint32> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_fixed32_fixed32"));
- iter != reflection->MapEnd(message, F("map_fixed32_fixed32"));
- ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetUInt32Value()],
- iter.GetValueRef().GetUInt32Value());
- }
- }
- {
- std::map<uint64, uint64> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_fixed64_fixed64"));
- iter != reflection->MapEnd(message, F("map_fixed64_fixed64"));
- ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetUInt64Value()],
- iter.GetValueRef().GetUInt64Value());
- }
- }
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_sfixed32_sfixed32"));
- iter != reflection->MapEnd(message, F("map_sfixed32_sfixed32"));
- ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
- iter.GetValueRef().GetInt32Value());
- }
- }
- {
- std::map<int32, float> map;
- map[0] = 0.0;
- map[1] = 1.0;
- for (MapIterator iter = reflection->MapBegin(message, F("map_int32_float"));
- iter != reflection->MapEnd(message, F("map_int32_float")); ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
- iter.GetValueRef().GetFloatValue());
- }
- }
- {
- std::map<int32, double> map;
- map[0] = 0.0;
- map[1] = 1.0;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_int32_double"));
- iter != reflection->MapEnd(message, F("map_int32_double")); ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
- iter.GetValueRef().GetDoubleValue());
- }
- }
- {
- std::map<bool, bool> map;
- map[false] = false;
- map[true] = true;
- for (MapIterator iter = reflection->MapBegin(message, F("map_bool_bool"));
- iter != reflection->MapEnd(message, F("map_bool_bool")); ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetBoolValue()],
- iter.GetValueRef().GetBoolValue());
- }
- }
- {
- std::map<string, string> map;
- map["0"] = "0";
- map["1"] = "1";
- int size = 0;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_string_string"));
- iter != reflection->MapEnd(message, F("map_string_string"));
- ++iter, ++size) {
- // Check const methods do not invalidate map.
- message->DebugString();
- message->ShortDebugString();
- message->SerializeToString(&serialized);
- message->SpaceUsed();
- message->ByteSize();
- EXPECT_EQ(map[iter.GetKey().GetStringValue()],
- iter.GetValueRef().GetStringValue());
- }
- EXPECT_EQ(size, 2);
- }
- {
- std::map<int32, string> map;
- map[0] = "0";
- map[1] = "1";
- for (MapIterator iter = reflection->MapBegin(message, F("map_int32_bytes"));
- iter != reflection->MapEnd(message, F("map_int32_bytes")); ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
- iter.GetValueRef().GetStringValue());
- }
- }
- {
- std::map<int32, const EnumValueDescriptor*> map;
- map[0] = map_enum_bar_;
- map[1] = map_enum_baz_;
- for (MapIterator iter = reflection->MapBegin(message, F("map_int32_enum"));
- iter != reflection->MapEnd(message, F("map_int32_enum")); ++iter) {
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()]->number(),
- iter.GetValueRef().GetEnumValue());
- }
- }
- {
- std::map<int32, int32> map;
- map[0] = 0;
- map[1] = 1;
- int size = 0;
- for (MapIterator iter = reflection->MapBegin(
- message, F("map_int32_foreign_message"));
- iter != reflection->MapEnd(message, F("map_int32_foreign_message"));
- ++iter, ++size) {
- // Check const methods do not invalidate map.
- message->DebugString();
- message->ShortDebugString();
- message->SerializeToString(&serialized);
- message->SpaceUsed();
- message->ByteSize();
- const Message& sub_message = iter.GetValueRef().GetMessageValue();
- EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
- sub_message.GetReflection()->GetInt32(sub_message, foreign_c_));
- }
- EXPECT_EQ(size, 2);
- }
- }
- void MapReflectionTester::ExpectClearViaReflection(
- const Message& message) {
- const Reflection* reflection = message.GetReflection();
- // Map fields are empty.
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_int32")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_int64_int64")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_uint32_uint32")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_uint64_uint64")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_sint32_sint32")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_sint64_sint64")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_fixed32_fixed32")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_fixed64_fixed64")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_sfixed32_sfixed32")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_sfixed64_sfixed64")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_float")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_double")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_bool_bool")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_string_string")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_bytes")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_enum")));
- EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_foreign_message")));
- }
- void MapReflectionTester::ExpectClearViaReflectionIterator(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_int32")) ==
- reflection->MapEnd(message, F("map_int32_int32")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_int64_int64")) ==
- reflection->MapEnd(message, F("map_int64_int64")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_uint32_uint32")) ==
- reflection->MapEnd(message, F("map_uint32_uint32")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_uint64_uint64")) ==
- reflection->MapEnd(message, F("map_uint64_uint64")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_sint32_sint32")) ==
- reflection->MapEnd(message, F("map_sint32_sint32")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_sint64_sint64")) ==
- reflection->MapEnd(message, F("map_sint64_sint64")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_fixed32_fixed32")) ==
- reflection->MapEnd(message, F("map_fixed32_fixed32")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_fixed64_fixed64")) ==
- reflection->MapEnd(message, F("map_fixed64_fixed64")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_sfixed32_sfixed32")) ==
- reflection->MapEnd(message, F("map_sfixed32_sfixed32")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_sfixed64_sfixed64")) ==
- reflection->MapEnd(message, F("map_sfixed64_sfixed64")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_float")) ==
- reflection->MapEnd(message, F("map_int32_float")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_double")) ==
- reflection->MapEnd(message, F("map_int32_double")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_bool_bool")) ==
- reflection->MapEnd(message, F("map_bool_bool")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_string_string")) ==
- reflection->MapEnd(message, F("map_string_string")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_bytes")) ==
- reflection->MapEnd(message, F("map_int32_bytes")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_enum")) ==
- reflection->MapEnd(message, F("map_int32_enum")));
- EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_foreign_message")) ==
- reflection->MapEnd(message, F("map_int32_foreign_message")));
- }
- void MapReflectionTester::ExpectMapEntryClearViaReflection(
- Message* message) {
- const Reflection* reflection = message->GetReflection();
- const Message* sub_message;
- {
- const FieldDescriptor* descriptor = F("map_int32_int32");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_int32_int32"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_int64_int64");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_int64_int64"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt64(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt64(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_uint32_uint32");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt32(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_uint64_uint64");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt64(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt64(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_sint32_sint32");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_sint64_sint64");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt64(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt64(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_fixed32_fixed32");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt32(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_fixed64_fixed64");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt64(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetUInt64(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_sfixed32_sfixed32");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_sfixed64_sfixed64");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt64(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt64(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_int32_float");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_int32_float"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetFloat(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_int32_double");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_int32_double"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()->GetDouble(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_bool_bool");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_bool_bool"));
- EXPECT_EQ(false, sub_message->GetReflection()->GetBool(*sub_message,
- key_descriptor));
- EXPECT_EQ(false, sub_message->GetReflection()->GetBool(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_string_string");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_string_string"));
- EXPECT_EQ("", sub_message->GetReflection()->GetString(*sub_message,
- key_descriptor));
- EXPECT_EQ("", sub_message->GetReflection()->GetString(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_int32_bytes");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ("", sub_message->GetReflection()->GetString(*sub_message,
- value_descriptor));
- }
- {
- const FieldDescriptor* descriptor = F("map_int32_enum");
- const FieldDescriptor* key_descriptor =
- descriptor->message_type()->FindFieldByName("key");
- const FieldDescriptor* value_descriptor =
- descriptor->message_type()->FindFieldByName("value");
- sub_message = reflection->AddMessage(message, F("map_int32_enum"));
- EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message,
- key_descriptor));
- EXPECT_EQ(0, sub_message->GetReflection()
- ->GetEnum(*sub_message, value_descriptor)
- ->number());
- }
- // Map using message as value has been tested in other place. Thus, we don't
- // test it here.
- }
- } // namespace protobuf
- } // namespace google
|