Index: base/values_unittest.cc |
diff --git a/base/values_unittest.cc b/base/values_unittest.cc |
index ff6f4a50284c41dab6a0e86b151ee4644385f796..513384a8cc9dc5a783f5b6c56db992e57cf8d73f 100644 |
--- a/base/values_unittest.cc |
+++ b/base/values_unittest.cc |
@@ -2,8 +2,10 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <cmath> |
#include <limits> |
+#include "base/basictypes.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/string16.h" |
#include "base/utf_string_conversions.h" |
@@ -59,39 +61,57 @@ TEST(ValuesTest, List) { |
scoped_ptr<ListValue> mixed_list(new ListValue()); |
mixed_list->Set(0, Value::CreateBooleanValue(true)); |
mixed_list->Set(1, Value::CreateIntegerValue(42)); |
- mixed_list->Set(2, Value::CreateDoubleValue(88.8)); |
- mixed_list->Set(3, Value::CreateStringValue("foo")); |
- ASSERT_EQ(4u, mixed_list->GetSize()); |
+ mixed_list->Set(2, Value::CreateInteger64Value(std::pow(2, 42))); |
+ mixed_list->Set(3, Value::CreateDoubleValue(88.8)); |
+ mixed_list->Set(4, Value::CreateStringValue("foo")); |
+ ASSERT_EQ(5u, mixed_list->GetSize()); |
Value *value = NULL; |
bool bool_value = false; |
int int_value = 0; |
+ int64 int64_value = 0; |
double double_value = 0.0; |
std::string string_value; |
- ASSERT_FALSE(mixed_list->Get(4, &value)); |
+ ASSERT_FALSE(mixed_list->Get(5, &value)); |
ASSERT_FALSE(mixed_list->GetInteger(0, &int_value)); |
ASSERT_EQ(0, int_value); |
+ ASSERT_FALSE(mixed_list->GetInteger64(0, &int64_value)); |
+ ASSERT_EQ(0, int64_value); |
ASSERT_FALSE(mixed_list->GetBoolean(1, &bool_value)); |
ASSERT_FALSE(bool_value); |
- ASSERT_FALSE(mixed_list->GetString(2, &string_value)); |
- ASSERT_EQ("", string_value); |
+ ASSERT_FALSE(mixed_list->GetBoolean(2, &bool_value)); |
+ ASSERT_FALSE(bool_value); |
ASSERT_FALSE(mixed_list->GetInteger(2, &int_value)); |
+ ASSERT_FALSE(int_value); |
+ // Implicit conversion from int64 to double is not allowed, even if the |
+ // double can represent the integer. |
+ ASSERT_FALSE(mixed_list->GetDouble(2, &double_value)); |
+ ASSERT_FALSE(double_value); |
+ ASSERT_FALSE(mixed_list->GetString(3, &string_value)); |
+ ASSERT_EQ("", string_value); |
+ ASSERT_FALSE(mixed_list->GetInteger(3, &int_value)); |
ASSERT_EQ(0, int_value); |
- ASSERT_FALSE(mixed_list->GetBoolean(3, &bool_value)); |
+ ASSERT_FALSE(mixed_list->GetInteger64(3, &int64_value)); |
+ ASSERT_EQ(0, int64_value); |
+ ASSERT_FALSE(mixed_list->GetBoolean(4, &bool_value)); |
ASSERT_FALSE(bool_value); |
ASSERT_TRUE(mixed_list->GetBoolean(0, &bool_value)); |
ASSERT_TRUE(bool_value); |
ASSERT_TRUE(mixed_list->GetInteger(1, &int_value)); |
ASSERT_EQ(42, int_value); |
- // implicit conversion from Integer to Double should be possible. |
+ // Implicit conversion from Integer to Double should be possible. |
ASSERT_TRUE(mixed_list->GetDouble(1, &double_value)); |
ASSERT_EQ(42, double_value); |
- ASSERT_TRUE(mixed_list->GetDouble(2, &double_value)); |
+ ASSERT_TRUE(mixed_list->GetInteger64(1, &int64_value)); |
+ ASSERT_EQ(42, int64_value); |
+ ASSERT_TRUE(mixed_list->GetInteger64(2, &int64_value)); |
+ ASSERT_EQ(std::pow(2, 42), int64_value); |
+ ASSERT_TRUE(mixed_list->GetDouble(3, &double_value)); |
ASSERT_EQ(88.8, double_value); |
- ASSERT_TRUE(mixed_list->GetString(3, &string_value)); |
+ ASSERT_TRUE(mixed_list->GetString(4, &string_value)); |
ASSERT_EQ("foo", string_value); |
// Try searching in the mixed list. |
@@ -342,6 +362,9 @@ TEST(ValuesTest, DeepCopy) { |
original_dict.Set("bool", original_bool); |
FundamentalValue* original_int = Value::CreateIntegerValue(42); |
original_dict.Set("int", original_int); |
+ FundamentalValue* original_int64 = |
+ Value::CreateInteger64Value(std::pow(2, 42)); |
+ original_dict.Set("int64", original_int64); |
FundamentalValue* original_double = Value::CreateDoubleValue(3.14); |
original_dict.Set("double", original_double); |
StringValue* original_string = Value::CreateStringValue("hello"); |
@@ -394,6 +417,15 @@ TEST(ValuesTest, DeepCopy) { |
ASSERT_TRUE(copy_int->GetAsInteger(©_int_value)); |
ASSERT_EQ(42, copy_int_value); |
+ Value* copy_int64 = NULL; |
+ ASSERT_TRUE(copy_dict->Get("int64", ©_int64)); |
+ ASSERT_TRUE(copy_int64); |
+ ASSERT_NE(copy_int64, original_int64); |
+ ASSERT_TRUE(copy_int64->IsType(Value::TYPE_INTEGER64)); |
+ int64 copy_int64_value = 0; |
+ ASSERT_TRUE(copy_int64->GetAsInteger64(©_int64_value)); |
+ ASSERT_EQ(std::pow(2, 42), copy_int64_value); |
+ |
Value* copy_double = NULL; |
ASSERT_TRUE(copy_dict->Get("double", ©_double)); |
ASSERT_TRUE(copy_double); |
@@ -490,6 +522,7 @@ TEST(ValuesTest, Equals) { |
DictionaryValue dv; |
dv.SetBoolean("a", false); |
dv.SetInteger("b", 2); |
+ dv.SetInteger64("b64", std::pow(2, 42)); |
dv.SetDouble("c", 2.5); |
dv.SetString("d1", "string"); |
dv.SetString("d2", ASCIIToUTF16("http://google.com")); |
@@ -550,6 +583,9 @@ TEST(ValuesTest, DeepCopyCovariantReturnTypes) { |
original_dict.Set("bool", original_bool); |
FundamentalValue* original_int = Value::CreateIntegerValue(42); |
original_dict.Set("int", original_int); |
+ FundamentalValue* original_int64 = |
+ Value::CreateInteger64Value(std::pow(2, 42)); |
+ original_dict.Set("int64", original_int64); |
FundamentalValue* original_double = Value::CreateDoubleValue(3.14); |
original_dict.Set("double", original_double); |
StringValue* original_string = Value::CreateStringValue("hello"); |
@@ -573,6 +609,7 @@ TEST(ValuesTest, DeepCopyCovariantReturnTypes) { |
Value* original_dict_value = &original_dict; |
Value* original_bool_value = original_bool; |
Value* original_int_value = original_int; |
+ Value* original_int64_value = original_int64; |
Value* original_double_value = original_double; |
Value* original_string_value = original_string; |
Value* original_string16_value = original_string16; |
@@ -582,6 +619,7 @@ TEST(ValuesTest, DeepCopyCovariantReturnTypes) { |
scoped_ptr<Value> copy_dict_value(original_dict_value->DeepCopy()); |
scoped_ptr<Value> copy_bool_value(original_bool_value->DeepCopy()); |
scoped_ptr<Value> copy_int_value(original_int_value->DeepCopy()); |
+ scoped_ptr<Value> copy_int64_value(original_int64_value->DeepCopy()); |
scoped_ptr<Value> copy_double_value(original_double_value->DeepCopy()); |
scoped_ptr<Value> copy_string_value(original_string_value->DeepCopy()); |
scoped_ptr<Value> copy_string16_value(original_string16_value->DeepCopy()); |
@@ -591,6 +629,7 @@ TEST(ValuesTest, DeepCopyCovariantReturnTypes) { |
EXPECT_TRUE(original_dict_value->Equals(copy_dict_value.get())); |
EXPECT_TRUE(original_bool_value->Equals(copy_bool_value.get())); |
EXPECT_TRUE(original_int_value->Equals(copy_int_value.get())); |
+ EXPECT_TRUE(original_int64_value->Equals(copy_int64_value.get())); |
EXPECT_TRUE(original_double_value->Equals(copy_double_value.get())); |
EXPECT_TRUE(original_string_value->Equals(copy_string_value.get())); |
EXPECT_TRUE(original_string16_value->Equals(copy_string16_value.get())); |