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 scoped_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 scoped_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( |
19 json, | 19 json, |
20 base::JSON_ALLOW_TRAILING_COMMAS, | 20 base::JSON_ALLOW_TRAILING_COMMAS, |
21 &error_code, | 21 &error_code, |
22 &error_msg)); | 22 &error_msg)); |
23 // CHECK not ASSERT since passing invalid |json| is a test error. | 23 // CHECK not ASSERT since passing invalid |json| is a test error. |
24 CHECK(result) << error_msg; | 24 CHECK(result) << error_msg; |
25 return result.Pass(); | 25 return result; |
26 } | 26 } |
27 | 27 |
28 scoped_ptr<base::ListValue> List(base::Value* a) { | 28 scoped_ptr<base::ListValue> List(base::Value* a) { |
29 scoped_ptr<base::ListValue> list(new base::ListValue()); | 29 scoped_ptr<base::ListValue> list(new base::ListValue()); |
30 list->Append(a); | 30 list->Append(a); |
31 return list.Pass(); | 31 return list; |
32 } | 32 } |
33 scoped_ptr<base::ListValue> List(base::Value* a, base::Value* b) { | 33 scoped_ptr<base::ListValue> List(base::Value* a, base::Value* b) { |
34 scoped_ptr<base::ListValue> list = List(a); | 34 scoped_ptr<base::ListValue> list = List(a); |
35 list->Append(b); | 35 list->Append(b); |
36 return list.Pass(); | 36 return list; |
37 } | 37 } |
38 scoped_ptr<base::ListValue> List(base::Value* a, | 38 scoped_ptr<base::ListValue> List(base::Value* a, |
39 base::Value* b, | 39 base::Value* b, |
40 base::Value* c) { | 40 base::Value* c) { |
41 scoped_ptr<base::ListValue> list = List(a, b); | 41 scoped_ptr<base::ListValue> list = List(a, b); |
42 list->Append(c); | 42 list->Append(c); |
43 return list.Pass(); | 43 return list; |
44 } | 44 } |
45 | 45 |
46 scoped_ptr<base::DictionaryValue> Dictionary( | 46 scoped_ptr<base::DictionaryValue> Dictionary( |
47 const std::string& ak, base::Value* av) { | 47 const std::string& ak, base::Value* av) { |
48 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 48 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
49 dict->SetWithoutPathExpansion(ak, av); | 49 dict->SetWithoutPathExpansion(ak, av); |
50 return dict.Pass(); | 50 return dict; |
51 } | 51 } |
52 scoped_ptr<base::DictionaryValue> Dictionary( | 52 scoped_ptr<base::DictionaryValue> Dictionary( |
53 const std::string& ak, base::Value* av, | 53 const std::string& ak, base::Value* av, |
54 const std::string& bk, base::Value* bv) { | 54 const std::string& bk, base::Value* bv) { |
55 scoped_ptr<base::DictionaryValue> dict = Dictionary(ak, av); | 55 scoped_ptr<base::DictionaryValue> dict = Dictionary(ak, av); |
56 dict->SetWithoutPathExpansion(bk, bv); | 56 dict->SetWithoutPathExpansion(bk, bv); |
57 return dict.Pass(); | 57 return dict; |
58 } | 58 } |
59 scoped_ptr<base::DictionaryValue> Dictionary( | 59 scoped_ptr<base::DictionaryValue> Dictionary( |
60 const std::string& ak, base::Value* av, | 60 const std::string& ak, base::Value* av, |
61 const std::string& bk, base::Value* bv, | 61 const std::string& bk, base::Value* bv, |
62 const std::string& ck, base::Value* cv) { | 62 const std::string& ck, base::Value* cv) { |
63 scoped_ptr<base::DictionaryValue> dict = Dictionary(ak, av, bk, bv); | 63 scoped_ptr<base::DictionaryValue> dict = Dictionary(ak, av, bk, bv); |
64 dict->SetWithoutPathExpansion(ck, cv); | 64 dict->SetWithoutPathExpansion(ck, cv); |
65 return dict.Pass(); | 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 |