aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/map_field_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/map_field_test.cc')
-rw-r--r--src/google/protobuf/map_field_test.cc51
1 files changed, 21 insertions, 30 deletions
diff --git a/src/google/protobuf/map_field_test.cc b/src/google/protobuf/map_field_test.cc
index dd5061c4..8617a366 100644
--- a/src/google/protobuf/map_field_test.cc
+++ b/src/google/protobuf/map_field_test.cc
@@ -101,8 +101,10 @@ class MapFieldBaseStub : public MapFieldBase {
class MapFieldBasePrimitiveTest : public ::testing::Test {
protected:
- typedef MapField<int32, int32, WireFormatLite::TYPE_INT32,
- WireFormatLite::TYPE_INT32, false> MapFieldType;
+ typedef unittest::TestMap::TestMap_MapInt32Int32Entry EntryType;
+ typedef MapField<EntryType, int32, int32, WireFormatLite::TYPE_INT32,
+ WireFormatLite::TYPE_INT32, false>
+ MapFieldType;
MapFieldBasePrimitiveTest() {
// Get descriptors
@@ -113,9 +115,7 @@ class MapFieldBasePrimitiveTest : public ::testing::Test {
value_descriptor_ = map_descriptor_->FindFieldByName("value");
// Build map field
- default_entry_ =
- MessageFactory::generated_factory()->GetPrototype(map_descriptor_);
- map_field_.reset(new MapFieldType(default_entry_));
+ map_field_.reset(new MapFieldType);
map_field_base_ = map_field_.get();
map_ = map_field_->MutableMap();
initial_value_map_[0] = 100;
@@ -130,7 +130,6 @@ class MapFieldBasePrimitiveTest : public ::testing::Test {
const Descriptor* map_descriptor_;
const FieldDescriptor* key_descriptor_;
const FieldDescriptor* value_descriptor_;
- const Message* default_entry_;
std::map<int32, int32> initial_value_map_; // copy of initial values inserted
};
@@ -177,8 +176,7 @@ TEST_F(MapFieldBasePrimitiveTest, Arena) {
// repeated fields are allocated from arenas.
// NoHeapChecker no_heap;
- MapFieldType* map_field =
- Arena::CreateMessage<MapFieldType>(&arena, default_entry_);
+ MapFieldType* map_field = Arena::CreateMessage<MapFieldType>(&arena);
// Set content in map
(*map_field->MutableMap())[100] = 101;
@@ -208,19 +206,13 @@ class MapFieldStateTest
: public testing::TestWithParam<State> {
public:
protected:
- typedef MapField<int32, int32, WireFormatLite::TYPE_INT32,
- WireFormatLite::TYPE_INT32, false> MapFieldType;
- typedef MapFieldLite<int32, int32, WireFormatLite::TYPE_INT32,
- WireFormatLite::TYPE_INT32, false> MapFieldLiteType;
+ typedef unittest::TestMap::TestMap_MapInt32Int32Entry EntryType;
+ typedef MapField<EntryType, int32, int32, WireFormatLite::TYPE_INT32,
+ WireFormatLite::TYPE_INT32, false>
+ MapFieldType;
MapFieldStateTest() : state_(GetParam()) {
// Build map field
- const Descriptor* map_descriptor =
- unittest::TestMap::descriptor()
- ->FindFieldByName("map_int32_int32")
- ->message_type();
- default_entry_ =
- MessageFactory::generated_factory()->GetPrototype(map_descriptor);
- map_field_.reset(new MapFieldType(default_entry_));
+ map_field_.reset(new MapFieldType());
map_field_base_ = map_field_.get();
Expect(map_field_.get(), MAP_DIRTY, 0, 0, true);
@@ -257,8 +249,8 @@ class MapFieldStateTest
MakeMapDirty(map_field);
MapFieldBase* map_field_base = map_field;
map_field_base->MutableRepeatedField();
- Map<int32, int32>* map = implicit_cast<MapFieldLiteType*>(map_field)
- ->MapFieldLiteType::MutableMap();
+ // We use MutableMap on impl_ because we don't want to disturb the syncing
+ Map<int32, int32>* map = map_field->impl_.MutableMap();
map->clear();
Expect(map_field, REPEATED_DIRTY, 0, 1, false);
@@ -270,8 +262,8 @@ class MapFieldStateTest
MapFieldBaseStub* stub =
reinterpret_cast<MapFieldBaseStub*>(map_field_base);
- Map<int32, int32>* map = implicit_cast<MapFieldLiteType*>(map_field)
- ->MapFieldLiteType::MutableMap();
+ // We use MutableMap on impl_ because we don't want to disturb the syncing
+ Map<int32, int32>* map = map_field->impl_.MutableMap();
RepeatedPtrField<Message>* repeated_field = stub->InternalRepeatedField();
switch (state) {
@@ -302,7 +294,6 @@ class MapFieldStateTest
google::protobuf::scoped_ptr<MapFieldType> map_field_;
MapFieldBase* map_field_base_;
State state_;
- const Message* default_entry_;
};
INSTANTIATE_TEST_CASE_P(MapFieldStateTestInstance, MapFieldStateTest,
@@ -327,7 +318,7 @@ TEST_P(MapFieldStateTest, MutableMap) {
}
TEST_P(MapFieldStateTest, MergeFromClean) {
- MapFieldType other(default_entry_);
+ MapFieldType other;
AddOneStillClean(&other);
map_field_->MergeFrom(other);
@@ -342,7 +333,7 @@ TEST_P(MapFieldStateTest, MergeFromClean) {
}
TEST_P(MapFieldStateTest, MergeFromMapDirty) {
- MapFieldType other(default_entry_);
+ MapFieldType other;
MakeMapDirty(&other);
map_field_->MergeFrom(other);
@@ -357,7 +348,7 @@ TEST_P(MapFieldStateTest, MergeFromMapDirty) {
}
TEST_P(MapFieldStateTest, MergeFromRepeatedDirty) {
- MapFieldType other(default_entry_);
+ MapFieldType other;
MakeRepeatedDirty(&other);
map_field_->MergeFrom(other);
@@ -372,7 +363,7 @@ TEST_P(MapFieldStateTest, MergeFromRepeatedDirty) {
}
TEST_P(MapFieldStateTest, SwapClean) {
- MapFieldType other(default_entry_);
+ MapFieldType other;
AddOneStillClean(&other);
map_field_->Swap(&other);
@@ -395,7 +386,7 @@ TEST_P(MapFieldStateTest, SwapClean) {
}
TEST_P(MapFieldStateTest, SwapMapDirty) {
- MapFieldType other(default_entry_);
+ MapFieldType other;
MakeMapDirty(&other);
map_field_->Swap(&other);
@@ -418,7 +409,7 @@ TEST_P(MapFieldStateTest, SwapMapDirty) {
}
TEST_P(MapFieldStateTest, SwapRepeatedDirty) {
- MapFieldType other(default_entry_);
+ MapFieldType other;
MakeRepeatedDirty(&other);
map_field_->Swap(&other);