OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "tools/json_schema_compiler/test/test_util.h" | 5 #include "tools/json_schema_compiler/test/test_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 | 11 |
12 namespace json_schema_compiler { | 12 namespace json_schema_compiler { |
13 namespace test_util { | 13 namespace test_util { |
14 | 14 |
15 scoped_ptr<base::Value> ReadJson(const base::StringPiece& json) { | 15 std::unique_ptr<base::Value> ReadJson(const base::StringPiece& json) { |
16 int error_code; | 16 int error_code; |
17 std::string error_msg; | 17 std::string error_msg; |
18 scoped_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( | 18 std::unique_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( |
19 json, | 19 json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error_msg)); |
20 base::JSON_ALLOW_TRAILING_COMMAS, | |
21 &error_code, | |
22 &error_msg)); | |
23 // CHECK not ASSERT since passing invalid |json| is a test error. | 20 // CHECK not ASSERT since passing invalid |json| is a test error. |
24 CHECK(result) << error_msg; | 21 CHECK(result) << error_msg; |
25 return result; | 22 return result; |
26 } | 23 } |
27 | 24 |
28 scoped_ptr<base::ListValue> List(base::Value* a) { | 25 std::unique_ptr<base::ListValue> List(base::Value* a) { |
29 scoped_ptr<base::ListValue> list(new base::ListValue()); | 26 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
30 list->Append(a); | 27 list->Append(a); |
31 return list; | 28 return list; |
32 } | 29 } |
33 scoped_ptr<base::ListValue> List(base::Value* a, base::Value* b) { | 30 std::unique_ptr<base::ListValue> List(base::Value* a, base::Value* b) { |
34 scoped_ptr<base::ListValue> list = List(a); | 31 std::unique_ptr<base::ListValue> list = List(a); |
35 list->Append(b); | 32 list->Append(b); |
36 return list; | 33 return list; |
37 } | 34 } |
38 scoped_ptr<base::ListValue> List(base::Value* a, | 35 std::unique_ptr<base::ListValue> List(base::Value* a, |
39 base::Value* b, | 36 base::Value* b, |
40 base::Value* c) { | 37 base::Value* c) { |
41 scoped_ptr<base::ListValue> list = List(a, b); | 38 std::unique_ptr<base::ListValue> list = List(a, b); |
42 list->Append(c); | 39 list->Append(c); |
43 return list; | 40 return list; |
44 } | 41 } |
45 | 42 |
46 scoped_ptr<base::DictionaryValue> Dictionary( | 43 std::unique_ptr<base::DictionaryValue> Dictionary(const std::string& ak, |
47 const std::string& ak, base::Value* av) { | 44 base::Value* av) { |
48 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 45 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
49 dict->SetWithoutPathExpansion(ak, av); | 46 dict->SetWithoutPathExpansion(ak, av); |
50 return dict; | 47 return dict; |
51 } | 48 } |
52 scoped_ptr<base::DictionaryValue> Dictionary( | 49 std::unique_ptr<base::DictionaryValue> Dictionary(const std::string& ak, |
53 const std::string& ak, base::Value* av, | 50 base::Value* av, |
54 const std::string& bk, base::Value* bv) { | 51 const std::string& bk, |
55 scoped_ptr<base::DictionaryValue> dict = Dictionary(ak, av); | 52 base::Value* bv) { |
| 53 std::unique_ptr<base::DictionaryValue> dict = Dictionary(ak, av); |
56 dict->SetWithoutPathExpansion(bk, bv); | 54 dict->SetWithoutPathExpansion(bk, bv); |
57 return dict; | 55 return dict; |
58 } | 56 } |
59 scoped_ptr<base::DictionaryValue> Dictionary( | 57 std::unique_ptr<base::DictionaryValue> Dictionary(const std::string& ak, |
60 const std::string& ak, base::Value* av, | 58 base::Value* av, |
61 const std::string& bk, base::Value* bv, | 59 const std::string& bk, |
62 const std::string& ck, base::Value* cv) { | 60 base::Value* bv, |
63 scoped_ptr<base::DictionaryValue> dict = Dictionary(ak, av, bk, bv); | 61 const std::string& ck, |
| 62 base::Value* cv) { |
| 63 std::unique_ptr<base::DictionaryValue> dict = Dictionary(ak, av, bk, bv); |
64 dict->SetWithoutPathExpansion(ck, cv); | 64 dict->SetWithoutPathExpansion(ck, cv); |
65 return dict; | 65 return dict; |
66 } | 66 } |
67 | 67 |
68 } // namespace test_util | 68 } // namespace test_util |
69 } // namespace json_schema_compiler | 69 } // namespace json_schema_compiler |
OLD | NEW |