OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/test/values_test_util.h" | |
6 | |
7 #include "base/json/json_reader.h" | |
5 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
6 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
7 #include "base/test/values_test_util.h" | |
8 #include "base/values.h" | 10 #include "base/values.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 | 12 |
11 namespace base { | 13 namespace base { |
12 | 14 |
13 void ExpectDictBooleanValue(bool expected_value, | 15 void ExpectDictBooleanValue(bool expected_value, |
14 const DictionaryValue& value, | 16 const DictionaryValue& value, |
15 const std::string& key) { | 17 const std::string& key) { |
16 bool boolean_value = false; | 18 bool boolean_value = false; |
17 EXPECT_TRUE(value.GetBoolean(key, &boolean_value)) << key; | 19 EXPECT_TRUE(value.GetBoolean(key, &boolean_value)) << key; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 } | 53 } |
52 | 54 |
53 void ExpectStringValue(const std::string& expected_str, | 55 void ExpectStringValue(const std::string& expected_str, |
54 StringValue* actual) { | 56 StringValue* actual) { |
55 scoped_ptr<StringValue> scoped_actual(actual); | 57 scoped_ptr<StringValue> scoped_actual(actual); |
56 std::string actual_str; | 58 std::string actual_str; |
57 EXPECT_TRUE(scoped_actual->GetAsString(&actual_str)); | 59 EXPECT_TRUE(scoped_actual->GetAsString(&actual_str)); |
58 EXPECT_EQ(expected_str, actual_str); | 60 EXPECT_EQ(expected_str, actual_str); |
59 } | 61 } |
60 | 62 |
63 scoped_ptr<Value> ParseJson(base::StringPiece json) { | |
Jeffrey Yasskin
2012/12/13 23:20:29
It might make sense to put this into a base::test
willchan no longer on Chromium
2012/12/14 20:35:04
It would make sense if I foresaw someone taking th
Jeffrey Yasskin
2012/12/14 23:12:41
I've moved it into base::test so that tests that w
| |
64 std::string error_msg; | |
65 scoped_ptr<Value> result(base::JSONReader::ReadAndReturnError( | |
66 json, base::JSON_ALLOW_TRAILING_COMMAS, | |
67 NULL, &error_msg)); | |
68 if (!result) { | |
69 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg; | |
70 result.reset(Value::CreateNullValue()); | |
71 } | |
72 return result.Pass(); | |
73 } | |
74 | |
61 } // namespace base | 75 } // namespace base |
OLD | NEW |