blob: 8d4c36925a714dc9991d4d20c069e10382bb29d9 [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);
24 base::DictionaryValue* dict;
25 value->GetAsDictionary(&dict);
26 return std::unique_ptr<base::DictionaryValue>(dict);
27}
28
29std::string ValueToString(const base::Value* value) {
30 std::string json;
31 base::JSONWriter::Write(value, &json);
32 std::replace(json.begin(), json.end(), '"', '\'');
33 return json;
34}
35
36} // namespace unittests
37} // namespace buffet