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

Side by Side Diff: base/values_unittest.cc

Issue 18200: Flesh out ListValue class. (Closed)
Patch Set: Created 11 years, 11 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
« no previous file with comments | « base/values.cc ('k') | 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) 2006-2008 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 "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 class ValuesTest: public testing::Test { 11 class ValuesTest: public testing::Test {
11 }; 12 };
12 13
13 TEST(ValuesTest, Basic) { 14 TEST(ValuesTest, Basic) {
14 // Test basic dictionary getting/setting 15 // Test basic dictionary getting/setting
15 DictionaryValue settings; 16 DictionaryValue settings;
16 std::wstring homepage = L"http://google.com"; 17 std::wstring homepage = L"http://google.com";
17 ASSERT_FALSE( 18 ASSERT_FALSE(
(...skipping 30 matching lines...) Expand all
48 ASSERT_EQ(1U, bookmark_list->GetSize()); 49 ASSERT_EQ(1U, bookmark_list->GetSize());
49 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); 50 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark));
50 std::wstring bookmark_name = L"Unnamed"; 51 std::wstring bookmark_name = L"Unnamed";
51 ASSERT_TRUE(bookmark->GetString(L"name", &bookmark_name)); 52 ASSERT_TRUE(bookmark->GetString(L"name", &bookmark_name));
52 ASSERT_EQ(std::wstring(L"Froogle"), bookmark_name); 53 ASSERT_EQ(std::wstring(L"Froogle"), bookmark_name);
53 std::wstring bookmark_url; 54 std::wstring bookmark_url;
54 ASSERT_TRUE(bookmark->GetString(L"url", &bookmark_url)); 55 ASSERT_TRUE(bookmark->GetString(L"url", &bookmark_url));
55 ASSERT_EQ(std::wstring(L"http://froogle.com"), bookmark_url); 56 ASSERT_EQ(std::wstring(L"http://froogle.com"), bookmark_url);
56 } 57 }
57 58
59 TEST(ValuesTest, List) {
60 scoped_ptr<ListValue> mixed_list(new ListValue());
61 mixed_list->Set(0, Value::CreateBooleanValue(true));
62 mixed_list->Set(1, Value::CreateIntegerValue(42));
63 mixed_list->Set(2, Value::CreateRealValue(88.8));
64 mixed_list->Set(3, Value::CreateStringValue("foo"));
65 ASSERT_EQ(4u, mixed_list->GetSize());
66
67 Value *value = NULL;
68 bool bool_value = false;
69 int int_value = 0;
70 double double_value = 0.0;
71 std::string string_value;
72
73 ASSERT_FALSE(mixed_list->Get(4, &value));
74
75 ASSERT_FALSE(mixed_list->GetInteger(0, &int_value));
76 ASSERT_EQ(0, int_value);
77 ASSERT_FALSE(mixed_list->GetReal(1, &double_value));
78 ASSERT_EQ(0.0, double_value);
79 ASSERT_FALSE(mixed_list->GetString(2, &string_value));
80 ASSERT_EQ("", string_value);
81 ASSERT_FALSE(mixed_list->GetBoolean(3, &bool_value));
82 ASSERT_EQ(false, bool_value);
83
84 ASSERT_TRUE(mixed_list->GetBoolean(0, &bool_value));
85 ASSERT_EQ(true, bool_value);
86 ASSERT_TRUE(mixed_list->GetInteger(1, &int_value));
87 ASSERT_EQ(42, int_value);
88 ASSERT_TRUE(mixed_list->GetReal(2, &double_value));
89 ASSERT_EQ(88.8, double_value);
90 ASSERT_TRUE(mixed_list->GetString(3, &string_value));
91 ASSERT_EQ("foo", string_value);
92 }
93
58 TEST(ValuesTest, BinaryValue) { 94 TEST(ValuesTest, BinaryValue) {
59 char* buffer = NULL; 95 char* buffer = NULL;
60 // Passing a null buffer pointer doesn't yield a BinaryValue 96 // Passing a null buffer pointer doesn't yield a BinaryValue
61 BinaryValue* binary = BinaryValue::Create(buffer, 0); 97 BinaryValue* binary = BinaryValue::Create(buffer, 0);
62 ASSERT_FALSE(binary); 98 ASSERT_FALSE(binary);
63 99
64 // If you want to represent an empty binary value, use a zero-length buffer. 100 // If you want to represent an empty binary value, use a zero-length buffer.
65 buffer = new char[1]; 101 buffer = new char[1];
66 ASSERT_TRUE(buffer); 102 ASSERT_TRUE(buffer);
67 binary = BinaryValue::Create(buffer, 0); 103 binary = BinaryValue::Create(buffer, 0);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 449
414 EXPECT_FALSE(dv.Equals(copy)); 450 EXPECT_FALSE(dv.Equals(copy));
415 copy->Set(L"f", list->DeepCopy()); 451 copy->Set(L"f", list->DeepCopy());
416 EXPECT_TRUE(dv.Equals(copy)); 452 EXPECT_TRUE(dv.Equals(copy));
417 453
418 list->Append(Value::CreateBooleanValue(true)); 454 list->Append(Value::CreateBooleanValue(true));
419 EXPECT_FALSE(dv.Equals(copy)); 455 EXPECT_FALSE(dv.Equals(copy));
420 delete copy; 456 delete copy;
421 } 457 }
422 458
OLDNEW
« no previous file with comments | « base/values.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698