summaryrefslogtreecommitdiffstats
path: root/base/values_unittest.cc
diff options
context:
space:
mode:
authorpatrick@chromium.org <patrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-24 23:37:14 +0000
committerpatrick@chromium.org <patrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-24 23:37:14 +0000
commit0a9a0fc0b5a219c5370c481f28797fe94418c564 (patch)
tree9dbd7f710171f963c90c4fccdacac5d0011cce45 /base/values_unittest.cc
parent1810e13962cca160e222d1ba9119fff4e7e7e033 (diff)
downloadchromium_src-0a9a0fc0b5a219c5370c481f28797fe94418c564.zip
chromium_src-0a9a0fc0b5a219c5370c481f28797fe94418c564.tar.gz
chromium_src-0a9a0fc0b5a219c5370c481f28797fe94418c564.tar.bz2
Use scoped_ptr to prevent memory leaks on test failures.
Review URL: http://codereview.chromium.org/50027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values_unittest.cc')
-rw-r--r--base/values_unittest.cc31
1 files changed, 12 insertions, 19 deletions
diff --git a/base/values_unittest.cc b/base/values_unittest.cc
index 90e2c65a..2931dd7 100644
--- a/base/values_unittest.cc
+++ b/base/values_unittest.cc
@@ -94,48 +94,43 @@ TEST(ValuesTest, List) {
TEST(ValuesTest, BinaryValue) {
char* buffer = NULL;
// Passing a null buffer pointer doesn't yield a BinaryValue
- BinaryValue* binary = BinaryValue::Create(buffer, 0);
- ASSERT_FALSE(binary);
+ scoped_ptr<BinaryValue> binary(BinaryValue::Create(buffer, 0));
+ ASSERT_FALSE(binary.get());
// If you want to represent an empty binary value, use a zero-length buffer.
buffer = new char[1];
ASSERT_TRUE(buffer);
- binary = BinaryValue::Create(buffer, 0);
- ASSERT_TRUE(binary);
+ binary.reset(BinaryValue::Create(buffer, 0));
+ ASSERT_TRUE(binary.get());
ASSERT_TRUE(binary->GetBuffer());
ASSERT_EQ(buffer, binary->GetBuffer());
ASSERT_EQ(0U, binary->GetSize());
- delete binary;
- binary = NULL;
// Test the common case of a non-empty buffer
buffer = new char[15];
- binary = BinaryValue::Create(buffer, 15);
- ASSERT_TRUE(binary);
+ binary.reset(BinaryValue::Create(buffer, 15));
+ ASSERT_TRUE(binary.get());
ASSERT_TRUE(binary->GetBuffer());
ASSERT_EQ(buffer, binary->GetBuffer());
ASSERT_EQ(15U, binary->GetSize());
- delete binary;
- binary = NULL;
char stack_buffer[42];
memset(stack_buffer, '!', 42);
- binary = BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42);
- ASSERT_TRUE(binary);
+ binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42));
+ ASSERT_TRUE(binary.get());
ASSERT_TRUE(binary->GetBuffer());
ASSERT_NE(stack_buffer, binary->GetBuffer());
ASSERT_EQ(42U, binary->GetSize());
ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize()));
- delete binary;
}
TEST(ValuesTest, StringValue) {
// Test overloaded CreateStringValue.
- Value* narrow_value = Value::CreateStringValue("narrow");
- ASSERT_TRUE(narrow_value);
+ scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow"));
+ ASSERT_TRUE(narrow_value.get());
ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
- Value* wide_value = Value::CreateStringValue(L"wide");
- ASSERT_TRUE(wide_value);
+ scoped_ptr<Value> wide_value(Value::CreateStringValue(L"wide"));
+ ASSERT_TRUE(wide_value.get());
ASSERT_TRUE(wide_value->IsType(Value::TYPE_STRING));
// Test overloaded GetString.
@@ -149,8 +144,6 @@ TEST(ValuesTest, StringValue) {
ASSERT_TRUE(wide_value->GetAsString(&wide));
ASSERT_EQ(std::string("wide"), narrow);
ASSERT_EQ(std::wstring(L"wide"), wide);
- delete narrow_value;
- delete wide_value;
}
// This is a Value object that allows us to tell if it's been