aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/repeated_field_unittest.cc
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@google.com>2015-05-21 14:28:59 -0700
committerGravatar Bo Yang <teboring@google.com>2015-05-21 19:32:02 -0700
commit5db217305f37a79eeccd70f000088a06ec82fcec (patch)
treebe53dcf0c0b47ef9178ab8a6fa5c1946ee84a28f /src/google/protobuf/repeated_field_unittest.cc
parent56095026ccc2f755a6fdb296e30c3ddec8f556a2 (diff)
down-integrate internal changes
Diffstat (limited to 'src/google/protobuf/repeated_field_unittest.cc')
-rw-r--r--src/google/protobuf/repeated_field_unittest.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc
index 66e74523..af397932 100644
--- a/src/google/protobuf/repeated_field_unittest.cc
+++ b/src/google/protobuf/repeated_field_unittest.cc
@@ -456,6 +456,28 @@ TEST(RepeatedField, ExtractSubrange) {
}
}
+TEST(RepeatedField, ClearThenReserveMore) {
+ // Test that Reserve properly destroys the old internal array when it's forced
+ // to allocate a new one, even when cleared-but-not-deleted objects are
+ // present. Use a 'string' and > 16 bytes length so that the elements are
+ // non-POD and allocate -- the leak checker will catch any skipped destructor
+ // calls here.
+ RepeatedField<string> field;
+ for (int i = 0; i < 32; i++) {
+ field.Add(string("abcdefghijklmnopqrstuvwxyz0123456789"));
+ }
+ EXPECT_EQ(32, field.size());
+ field.Clear();
+ EXPECT_EQ(0, field.size());
+ EXPECT_EQ(32, field.Capacity());
+
+ field.Reserve(1024);
+ EXPECT_EQ(0, field.size());
+ EXPECT_EQ(1024, field.Capacity());
+ // Finish test -- |field| should destroy the cleared-but-not-yet-destroyed
+ // strings.
+}
+
// ===================================================================
// RepeatedPtrField tests. These pretty much just mirror the RepeatedField
// tests above.