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
3 // found in the LICENSE file.
5 #include "tools/json_schema_compiler/test/test_util.h"
9 #include "base/json/json_reader.h"
10 #include "base/logging.h"
12 namespace json_schema_compiler
{
15 scoped_ptr
<base::Value
> ReadJson(const base::StringPiece
& json
) {
17 std::string error_msg
;
18 scoped_ptr
<base::Value
> result(base::JSONReader::ReadAndReturnError(
20 base::JSON_ALLOW_TRAILING_COMMAS
,
23 // CHECK not ASSERT since passing invalid |json| is a test error.
24 CHECK(result
) << error_msg
;
28 scoped_ptr
<base::ListValue
> List(base::Value
* a
) {
29 scoped_ptr
<base::ListValue
> list(new base::ListValue());
33 scoped_ptr
<base::ListValue
> List(base::Value
* a
, base::Value
* b
) {
34 scoped_ptr
<base::ListValue
> list
= List(a
);
38 scoped_ptr
<base::ListValue
> List(base::Value
* a
,
41 scoped_ptr
<base::ListValue
> list
= List(a
, b
);
46 scoped_ptr
<base::DictionaryValue
> Dictionary(
47 const std::string
& ak
, base::Value
* av
) {
48 scoped_ptr
<base::DictionaryValue
> dict(new base::DictionaryValue());
49 dict
->SetWithoutPathExpansion(ak
, av
);
52 scoped_ptr
<base::DictionaryValue
> Dictionary(
53 const std::string
& ak
, base::Value
* av
,
54 const std::string
& bk
, base::Value
* bv
) {
55 scoped_ptr
<base::DictionaryValue
> dict
= Dictionary(ak
, av
);
56 dict
->SetWithoutPathExpansion(bk
, bv
);
59 scoped_ptr
<base::DictionaryValue
> Dictionary(
60 const std::string
& ak
, base::Value
* av
,
61 const std::string
& bk
, base::Value
* bv
,
62 const std::string
& ck
, base::Value
* cv
) {
63 scoped_ptr
<base::DictionaryValue
> dict
= Dictionary(ak
, av
, bk
, bv
);
64 dict
->SetWithoutPathExpansion(ck
, cv
);
68 } // namespace test_util
69 } // namespace json_schema_compiler