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