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

Side by Side Diff: base/json_reader_unittest.cc

Issue 159104: Silence a false coverity warning by changing the code a bit. (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 | « base/json_reader.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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "base/json_reader.h" 6 #include "base/json_reader.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
11 TEST(JSONReaderTest, Reading) { 11 TEST(JSONReaderTest, Reading) {
12 // some whitespace checking 12 // some whitespace checking
13 scoped_ptr<Value> root; 13 scoped_ptr<Value> root;
14 root.reset(JSONReader().JsonToValue(" null ", false, false)); 14 root.reset(JSONReader().JsonToValue(" null ", false, false));
15 ASSERT_TRUE(root.get()); 15 ASSERT_TRUE(root.get());
16 ASSERT_TRUE(root->IsType(Value::TYPE_NULL)); 16 ASSERT_TRUE(root->IsType(Value::TYPE_NULL));
17 17
18 // Invalid JSON string 18 // Invalid JSON string
19 root.reset(JSONReader().JsonToValue("nu", false, false)); 19 root.reset(JSONReader().JsonToValue("nu", false, false));
20 ASSERT_FALSE(root.get()); 20 ASSERT_FALSE(root.get());
21 21
22 // Simple bool 22 // Simple bool
23 root.reset(JSONReader().JsonToValue("true ", false, false)); 23 root.reset(JSONReader().JsonToValue("true ", false, false));
24 ASSERT_TRUE(root.get()); 24 ASSERT_TRUE(root.get());
25 ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN)); 25 ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN));
26 26
27 // Embedded comment
28 root.reset(JSONReader().JsonToValue("/* comment */null", false, false));
29 ASSERT_TRUE(root.get());
30 ASSERT_TRUE(root->IsType(Value::TYPE_NULL));
31 root.reset(JSONReader().JsonToValue("40 /* comment */", false, false));
32 ASSERT_TRUE(root.get());
33 ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER));
34 root.reset(JSONReader().JsonToValue("true // comment", false, false));
35 ASSERT_TRUE(root.get());
36 ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN));
37 root.reset(JSONReader().JsonToValue("/* comment */\"sample string\"",
38 false, false));
39 ASSERT_TRUE(root.get());
40 ASSERT_TRUE(root->IsType(Value::TYPE_STRING));
41 std::string value;
42 ASSERT_TRUE(root->GetAsString(&value));
43 ASSERT_EQ("sample string", value);
44
27 // Test number formats 45 // Test number formats
28 root.reset(JSONReader().JsonToValue("43", false, false)); 46 root.reset(JSONReader().JsonToValue("43", false, false));
29 ASSERT_TRUE(root.get()); 47 ASSERT_TRUE(root.get());
30 ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER)); 48 ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER));
31 int int_val = 0; 49 int int_val = 0;
32 ASSERT_TRUE(root->GetAsInteger(&int_val)); 50 ASSERT_TRUE(root->GetAsInteger(&int_val));
33 ASSERT_EQ(43, int_val); 51 ASSERT_EQ(43, int_val);
34 52
35 // According to RFC4627, oct, hex, and leading zeros are invalid JSON. 53 // According to RFC4627, oct, hex, and leading zeros are invalid JSON.
36 root.reset(JSONReader().JsonToValue("043", false, false)); 54 root.reset(JSONReader().JsonToValue("043", false, false));
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), 521 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape),
504 error_message); 522 error_message);
505 523
506 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false, 524 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false,
507 &error_message)); 525 &error_message));
508 EXPECT_FALSE(root.get()); 526 EXPECT_FALSE(root.get());
509 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), 527 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape),
510 error_message); 528 error_message);
511 529
512 } 530 }
OLDNEW
« no previous file with comments | « base/json_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698