blob: db8aa4a26e0554ea2e4c999771873860f0907be9 [file] [log] [blame]
Alex Vakulenko6201d2d2014-07-16 14:46:48 -07001// Copyright 2014 The Chromium OS 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.
4
5#include "buffet/commands/unittest_utils.h"
6
7#include <base/json/json_reader.h>
8#include <base/json/json_writer.h>
9
10namespace buffet {
11namespace unittests {
12
13std::unique_ptr<base::Value> CreateValue(const char* json) {
14 std::string json2(json);
15 // Convert apostrophes to double-quotes so JSONReader can parse the string.
16 std::replace(json2.begin(), json2.end(), '\'', '"');
17 return std::unique_ptr<base::Value>(base::JSONReader::Read(json2));
18}
19
20std::unique_ptr<base::DictionaryValue> CreateDictionaryValue(const char* json) {
21 std::string json2(json);
22 std::replace(json2.begin(), json2.end(), '\'', '"');
23 base::Value* value = base::JSONReader::Read(json2);
Alex Vakulenko2a17a532015-02-24 14:51:13 -080024 CHECK(value) << "Failed to load JSON: " << json2;
25 base::DictionaryValue* dict = nullptr;
Alex Vakulenko6201d2d2014-07-16 14:46:48 -070026 value->GetAsDictionary(&dict);
27 return std::unique_ptr<base::DictionaryValue>(dict);
28}
29
30std::string ValueToString(const base::Value* value) {
31 std::string json;
32 base::JSONWriter::Write(value, &json);
33 std::replace(json.begin(), json.end(), '"', '\'');
34 return json;
35}
36
37} // namespace unittests
38} // namespace buffet