From d36c0c538a545fac5d9db6ba65c525246d4efa95 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 29 Mar 2017 14:32:48 -0700 Subject: Down-integrate from google3. --- .../protobuf/repeated_field_reflection_unittest.cc | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src/google/protobuf/repeated_field_reflection_unittest.cc') diff --git a/src/google/protobuf/repeated_field_reflection_unittest.cc b/src/google/protobuf/repeated_field_reflection_unittest.cc index fcebe5ce..fd466565 100644 --- a/src/google/protobuf/repeated_field_reflection_unittest.cc +++ b/src/google/protobuf/repeated_field_reflection_unittest.cc @@ -189,8 +189,8 @@ TEST(RepeatedFieldReflectionTest, ExtensionFields) { } } -template -void TestRepeatedFieldRefIterator( +template +void TestRepeatedFieldRefIteratorForPrimitive( const Ref& handle, const MessageType& message, ValueType (MessageType::*GetFunc)(int) const) { int index = 0; @@ -202,6 +202,21 @@ void TestRepeatedFieldRefIterator( EXPECT_EQ(handle.size(), index); } +template +void TestRepeatedFieldRefIteratorForString( + const RepeatedFieldRef& handle, const MessageType& message, + ValueType (MessageType::*GetFunc)(int) const) { + int index = 0; + for (typename RepeatedFieldRef::const_iterator it = handle.begin(); + it != handle.end(); ++it) { + // Test both operator* and operator-> + EXPECT_EQ((message.*GetFunc)(index), *it); + EXPECT_EQ((message.*GetFunc)(index).size(), it->size()); + ++index; + } + EXPECT_EQ(handle.size(), index); +} + TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) { TestAllTypes message; const Reflection* refl = message.GetReflection(); @@ -312,12 +327,12 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) { } // Test iterators. - TestRepeatedFieldRefIterator(rf_int32, message, - &TestAllTypes::repeated_int32); - TestRepeatedFieldRefIterator(rf_double, message, - &TestAllTypes::repeated_double); - TestRepeatedFieldRefIterator(rf_string, message, - &TestAllTypes::repeated_string); + TestRepeatedFieldRefIteratorForPrimitive(rf_int32, message, + &TestAllTypes::repeated_int32); + TestRepeatedFieldRefIteratorForPrimitive(rf_double, message, + &TestAllTypes::repeated_double); + TestRepeatedFieldRefIteratorForString(rf_string, message, + &TestAllTypes::repeated_string); // Test iterators for message fields. typedef RepeatedFieldRef::iterator MessageIterator; @@ -474,10 +489,10 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForEnums) { EXPECT_EQ(TestAllTypes::BAZ, message.repeated_nested_enum(i)); } - TestRepeatedFieldRefIterator(enum_ref, message, - &TestAllTypes::repeated_nested_enum); - TestRepeatedFieldRefIterator(int32_ref, message, - &TestAllTypes::repeated_nested_enum); + TestRepeatedFieldRefIteratorForPrimitive(enum_ref, message, + &TestAllTypes::repeated_nested_enum); + TestRepeatedFieldRefIteratorForPrimitive(int32_ref, message, + &TestAllTypes::repeated_nested_enum); // Test Add() mutable_enum_ref.Add(TestAllTypes::FOO); -- cgit v1.2.3