// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "tools/json_schema_compiler/test/test_util.h" #include #include "base/json/json_reader.h" #include "base/logging.h" namespace json_schema_compiler { namespace test_util { scoped_ptr ReadJson(const base::StringPiece& json) { int error_code; std::string error_msg; scoped_ptr result(base::JSONReader::ReadAndReturnError( json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error_msg)); // CHECK not ASSERT since passing invalid |json| is a test error. CHECK(result) << error_msg; return result.Pass(); } scoped_ptr List(base::Value* a) { scoped_ptr list(new base::ListValue()); list->Append(a); return list.Pass(); } scoped_ptr List(base::Value* a, base::Value* b) { scoped_ptr list = List(a); list->Append(b); return list.Pass(); } scoped_ptr List(base::Value* a, base::Value* b, base::Value* c) { scoped_ptr list = List(a, b); list->Append(c); return list.Pass(); } scoped_ptr Dictionary( const std::string& ak, base::Value* av) { scoped_ptr dict(new base::DictionaryValue()); dict->SetWithoutPathExpansion(ak, av); return dict.Pass(); } scoped_ptr Dictionary( const std::string& ak, base::Value* av, const std::string& bk, base::Value* bv) { scoped_ptr dict = Dictionary(ak, av); dict->SetWithoutPathExpansion(bk, bv); return dict.Pass(); } scoped_ptr Dictionary( const std::string& ak, base::Value* av, const std::string& bk, base::Value* bv, const std::string& ck, base::Value* cv) { scoped_ptr dict = Dictionary(ak, av, bk, bv); dict->SetWithoutPathExpansion(ck, cv); return dict.Pass(); } } // namespace test_util } // namespace json_schema_compiler