|
|
|
@ -1387,6 +1387,45 @@ TEST_P(MapTestWithParams, SwapMapsFieldsViaReflection) { |
|
|
|
|
reflection_tester.ExpectMapFieldsSetViaReflectionIterator(rhs); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class MapTestCodegenOrDynamic : public testing::TestWithParam<bool> {}; |
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(MapTestCodegenOrDynamicSuite, MapTestCodegenOrDynamic, |
|
|
|
|
testing::Bool()); |
|
|
|
|
|
|
|
|
|
TEST_P(MapTestCodegenOrDynamic, LookupMapValueSyncsRepeatedFieldRep) { |
|
|
|
|
auto* descriptor = UNITTEST::TestMap::descriptor(); |
|
|
|
|
bool use_dynamic = GetParam(); |
|
|
|
|
|
|
|
|
|
DynamicMessageFactory factory; |
|
|
|
|
std::unique_ptr<Message> dyn_message( |
|
|
|
|
factory.GetPrototype(descriptor)->New()); |
|
|
|
|
TestMap gen_message; |
|
|
|
|
Message* msg = use_dynamic ? dyn_message.get() : &gen_message; |
|
|
|
|
|
|
|
|
|
const auto* reflection = msg->GetReflection(); |
|
|
|
|
const auto* field = msg->GetDescriptor()->FindFieldByName("map_int32_int32"); |
|
|
|
|
|
|
|
|
|
MapKey map_key; |
|
|
|
|
map_key.SetInt32Value(10); |
|
|
|
|
auto res = |
|
|
|
|
MapReflectionTester::LookupMapValue(*reflection, *msg, *field, map_key); |
|
|
|
|
// Check that we don't have it yet. |
|
|
|
|
ASSERT_FALSE(res.has_value()); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
auto* sub = reflection->AddMessage(msg, field); |
|
|
|
|
sub->GetReflection()->SetInt32(sub, sub->GetDescriptor()->map_key(), 10); |
|
|
|
|
sub->GetReflection()->SetInt32(sub, sub->GetDescriptor()->map_value(), 100); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = MapReflectionTester::LookupMapValue(*reflection, *msg, *field, map_key); |
|
|
|
|
// If this fails, LookupMapValue might have failed to sync from the repeated |
|
|
|
|
// field. |
|
|
|
|
ASSERT_TRUE(res.has_value()); |
|
|
|
|
EXPECT_EQ(res->GetInt32Value(), 100); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(MapImplTest, SpaceUsed) { |
|
|
|
|
constexpr size_t kMinCap = 16 / sizeof(void*); |
|
|
|
|
|
|
|
|
|