summaryrefslogtreecommitdiffstats
path: root/base/json_reader_unittest.cc
diff options
context:
space:
mode:
authormmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-07 17:15:41 +0000
committermmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-07 17:15:41 +0000
commitd9023abb77c05d411835658b1091bdbb592b45c2 (patch)
tree0fb92b1786b59c2c1a42a0d29d58df697e1b7ec0 /base/json_reader_unittest.cc
parent9f16de03664224cc286851ca03369cf699dd7c3c (diff)
downloadchromium_src-d9023abb77c05d411835658b1091bdbb592b45c2.zip
chromium_src-d9023abb77c05d411835658b1091bdbb592b45c2.tar.gz
chromium_src-d9023abb77c05d411835658b1091bdbb592b45c2.tar.bz2
Cross-platform portability fixes for JSONReader. Adds generic string-to-double parsing and tests in string_util.
There is one behavior change here: numbers which "look" like integers by virtue of being free of '.', 'e', and 'E' are no longer rejected if they're not within the [INT_MIN .. INT_MAX] range. Instead, they'll be parsed and stored internally as doubles. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/json_reader_unittest.cc')
-rw-r--r--base/json_reader_unittest.cc23
1 files changed, 12 insertions, 11 deletions
diff --git a/base/json_reader_unittest.cc b/base/json_reader_unittest.cc
index 130c8e8..1a81425 100644
--- a/base/json_reader_unittest.cc
+++ b/base/json_reader_unittest.cc
@@ -83,13 +83,14 @@ TEST(JSONReaderTest, Reading) {
ASSERT_EQ(0, int_val);
delete root;
- // Numbers that overflow ints should fail
+ // Numbers that overflow ints should succeed, being internally promoted to
+ // storage as doubles
root = NULL;
- ASSERT_FALSE(JSONReader::JsonToValue("2147483648", &root, false, false));
- ASSERT_FALSE(root);
+ ASSERT_TRUE(JSONReader::JsonToValue("2147483648", &root, false, false));
+ ASSERT_TRUE(root);
root = NULL;
- ASSERT_FALSE(JSONReader::JsonToValue("-2147483649", &root, false, false));
- ASSERT_FALSE(root);
+ ASSERT_TRUE(JSONReader::JsonToValue("-2147483649", &root, false, false));
+ ASSERT_TRUE(root);
// Parse a double
root = NULL;
@@ -264,7 +265,7 @@ TEST(JSONReaderTest, Reading) {
ASSERT_TRUE(root);
ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
ListValue* list = static_cast<ListValue*>(root);
- ASSERT_EQ(3, list->GetSize());
+ ASSERT_EQ(static_cast<size_t>(3), list->GetSize());
// Test with trailing comma. Should be parsed the same as above.
Value* root2 = NULL;
@@ -279,7 +280,7 @@ TEST(JSONReaderTest, Reading) {
ASSERT_TRUE(root);
ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
list = static_cast<ListValue*>(root);
- ASSERT_EQ(0, list->GetSize());
+ ASSERT_EQ(static_cast<size_t>(0), list->GetSize());
delete root;
// Nested arrays
@@ -289,7 +290,7 @@ TEST(JSONReaderTest, Reading) {
ASSERT_TRUE(root);
ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
list = static_cast<ListValue*>(root);
- ASSERT_EQ(4, list->GetSize());
+ ASSERT_EQ(static_cast<size_t>(4), list->GetSize());
// Lots of trailing commas.
root2 = NULL;
@@ -327,7 +328,7 @@ TEST(JSONReaderTest, Reading) {
ASSERT_TRUE(root);
ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
list = static_cast<ListValue*>(root);
- EXPECT_EQ(1, list->GetSize());
+ EXPECT_EQ(static_cast<size_t>(1), list->GetSize());
Value* tmp_value = NULL;
ASSERT_TRUE(list->Get(0, &tmp_value));
EXPECT_TRUE(tmp_value->IsType(Value::TYPE_BOOLEAN));
@@ -391,7 +392,7 @@ TEST(JSONReaderTest, Reading) {
ASSERT_TRUE(dict_val->GetDictionary(L"inner", &inner_dict));
ListValue* inner_array = NULL;
ASSERT_TRUE(inner_dict->GetList(L"array", &inner_array));
- ASSERT_EQ(1, inner_array->GetSize());
+ ASSERT_EQ(static_cast<size_t>(1), inner_array->GetSize());
bool_value = true;
ASSERT_TRUE(dict_val->GetBoolean(L"false", &bool_value));
ASSERT_FALSE(bool_value);
@@ -465,7 +466,7 @@ TEST(JSONReaderTest, Reading) {
ASSERT_TRUE(root);
ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
list = static_cast<ListValue*>(root);
- ASSERT_EQ(5001, list->GetSize());
+ ASSERT_EQ(static_cast<size_t>(5001), list->GetSize());
delete root;
// Test utf8 encoded input