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