Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: base/values_unittest.cc

Issue 149153: Minor Coverity nit: Unit test leaking data if failure occurs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 class ValuesTest: public testing::Test { 11 class ValuesTest: public testing::Test {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ASSERT_EQ(std::wstring(L"narrow"), wide); 142 ASSERT_EQ(std::wstring(L"narrow"), wide);
143 ASSERT_TRUE(wide_value->GetAsString(&narrow)); 143 ASSERT_TRUE(wide_value->GetAsString(&narrow));
144 ASSERT_TRUE(wide_value->GetAsString(&wide)); 144 ASSERT_TRUE(wide_value->GetAsString(&wide));
145 ASSERT_EQ(std::string("wide"), narrow); 145 ASSERT_EQ(std::string("wide"), narrow);
146 ASSERT_EQ(std::wstring(L"wide"), wide); 146 ASSERT_EQ(std::wstring(L"wide"), wide);
147 } 147 }
148 148
149 // This is a Value object that allows us to tell if it's been 149 // This is a Value object that allows us to tell if it's been
150 // properly deleted by modifying the value of external flag on destruction. 150 // properly deleted by modifying the value of external flag on destruction.
151 class DeletionTestValue : public Value { 151 class DeletionTestValue : public Value {
152 public: 152 public:
153 DeletionTestValue(bool* deletion_flag) : Value(TYPE_NULL) { 153 DeletionTestValue(bool* deletion_flag) : Value(TYPE_NULL) {
154 Init(deletion_flag); // Separate function so that we can use ASSERT_* 154 Init(deletion_flag); // Separate function so that we can use ASSERT_*
155 } 155 }
156 156
157 void Init(bool* deletion_flag) { 157 void Init(bool* deletion_flag) {
158 ASSERT_TRUE(deletion_flag); 158 ASSERT_TRUE(deletion_flag);
159 deletion_flag_ = deletion_flag; 159 deletion_flag_ = deletion_flag;
160 *deletion_flag_ = false; 160 *deletion_flag_ = false;
161 } 161 }
162 162
163 ~DeletionTestValue() { 163 ~DeletionTestValue() {
164 *deletion_flag_ = true; 164 *deletion_flag_ = true;
165 } 165 }
166 166
167 private: 167 private:
168 bool* deletion_flag_; 168 bool* deletion_flag_;
169 }; 169 };
170 170
171 TEST(ValuesTest, ListDeletion) { 171 TEST(ValuesTest, ListDeletion) {
172 bool deletion_flag = true; 172 bool deletion_flag = true;
173 173
174 { 174 {
175 ListValue list; 175 ListValue list;
176 list.Append(new DeletionTestValue(&deletion_flag)); 176 list.Append(new DeletionTestValue(&deletion_flag));
177 EXPECT_FALSE(deletion_flag); 177 EXPECT_FALSE(deletion_flag);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 BinaryValue* original_binary = Value::CreateBinaryValue(original_buffer, 42); 305 BinaryValue* original_binary = Value::CreateBinaryValue(original_buffer, 42);
306 original_dict.Set(L"binary", original_binary); 306 original_dict.Set(L"binary", original_binary);
307 307
308 ListValue* original_list = new ListValue(); 308 ListValue* original_list = new ListValue();
309 Value* original_list_element_0 = Value::CreateIntegerValue(0); 309 Value* original_list_element_0 = Value::CreateIntegerValue(0);
310 original_list->Append(original_list_element_0); 310 original_list->Append(original_list_element_0);
311 Value* original_list_element_1 = Value::CreateIntegerValue(1); 311 Value* original_list_element_1 = Value::CreateIntegerValue(1);
312 original_list->Append(original_list_element_1); 312 original_list->Append(original_list_element_1);
313 original_dict.Set(L"list", original_list); 313 original_dict.Set(L"list", original_list);
314 314
315 DictionaryValue* copy_dict = 315 scoped_ptr<DictionaryValue> copy_dict(
316 static_cast<DictionaryValue*>(original_dict.DeepCopy()); 316 static_cast<DictionaryValue*>(original_dict.DeepCopy()));
317 ASSERT_TRUE(copy_dict); 317 ASSERT_TRUE(copy_dict.get());
318 ASSERT_NE(copy_dict, &original_dict); 318 ASSERT_NE(copy_dict.get(), &original_dict);
319 319
320 Value* copy_null = NULL; 320 Value* copy_null = NULL;
321 ASSERT_TRUE(copy_dict->Get(L"null", &copy_null)); 321 ASSERT_TRUE(copy_dict->Get(L"null", &copy_null));
322 ASSERT_TRUE(copy_null); 322 ASSERT_TRUE(copy_null);
323 ASSERT_NE(copy_null, original_null); 323 ASSERT_NE(copy_null, original_null);
324 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL)); 324 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL));
325 325
326 Value* copy_bool = NULL; 326 Value* copy_bool = NULL;
327 ASSERT_TRUE(copy_dict->Get(L"bool", &copy_bool)); 327 ASSERT_TRUE(copy_dict->Get(L"bool", &copy_bool));
328 ASSERT_TRUE(copy_bool); 328 ASSERT_TRUE(copy_bool);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 ASSERT_TRUE(copy_list_element_0->GetAsInteger(&copy_list_element_0_value)); 401 ASSERT_TRUE(copy_list_element_0->GetAsInteger(&copy_list_element_0_value));
402 ASSERT_EQ(0, copy_list_element_0_value); 402 ASSERT_EQ(0, copy_list_element_0_value);
403 403
404 Value* copy_list_element_1; 404 Value* copy_list_element_1;
405 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1)); 405 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1));
406 ASSERT_TRUE(copy_list_element_1); 406 ASSERT_TRUE(copy_list_element_1);
407 ASSERT_NE(copy_list_element_1, original_list_element_1); 407 ASSERT_NE(copy_list_element_1, original_list_element_1);
408 int copy_list_element_1_value; 408 int copy_list_element_1_value;
409 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value)); 409 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value));
410 ASSERT_EQ(1, copy_list_element_1_value); 410 ASSERT_EQ(1, copy_list_element_1_value);
411
412 delete copy_dict;
413 } 411 }
414 412
415 TEST(ValuesTest, Equals) { 413 TEST(ValuesTest, Equals) {
416 Value* null1 = Value::CreateNullValue(); 414 Value* null1 = Value::CreateNullValue();
417 Value* null2 = Value::CreateNullValue(); 415 Value* null2 = Value::CreateNullValue();
418 EXPECT_NE(null1, null2); 416 EXPECT_NE(null1, null2);
419 EXPECT_TRUE(null1->Equals(null2)); 417 EXPECT_TRUE(null1->Equals(null2));
420 418
421 Value* boolean = Value::CreateBooleanValue(false); 419 Value* boolean = Value::CreateBooleanValue(false);
422 EXPECT_FALSE(null1->Equals(boolean)); 420 EXPECT_FALSE(null1->Equals(boolean));
(...skipping 18 matching lines...) Expand all
441 dv.Set(L"f", list); 439 dv.Set(L"f", list);
442 440
443 EXPECT_FALSE(dv.Equals(copy)); 441 EXPECT_FALSE(dv.Equals(copy));
444 copy->Set(L"f", list->DeepCopy()); 442 copy->Set(L"f", list->DeepCopy());
445 EXPECT_TRUE(dv.Equals(copy)); 443 EXPECT_TRUE(dv.Equals(copy));
446 444
447 list->Append(Value::CreateBooleanValue(true)); 445 list->Append(Value::CreateBooleanValue(true));
448 EXPECT_FALSE(dv.Equals(copy)); 446 EXPECT_FALSE(dv.Equals(copy));
449 delete copy; 447 delete copy;
450 } 448 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698