1c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)// found in the LICENSE file.
4c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
5c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "config.h"
6c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
7c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "platform/TracedValue.h"
8c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
9c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include <gtest/gtest.h>
10c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
11c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)using namespace blink;
12c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
13c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace {
14c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
15c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)TEST(TracedValueTest, FlatDictionary)
16c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){
17c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    RefPtr<TracedValue> value = TracedValue::create();
18c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setInteger("int", 2014);
19c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setDouble("double", 0.0);
20c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setBoolean("bool", true);
21c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setString("string", "string");
22c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    String json = value->asTraceFormat();
23c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    EXPECT_EQ("{\"int\":2014,\"double\":0,\"bool\":true,\"string\":\"string\"}", json);
24c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}
25c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
26c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)TEST(TracedValueTest, Hierarchy)
27c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){
28c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    RefPtr<TracedValue> value = TracedValue::create();
29c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setInteger("i0", 2014);
30c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->beginDictionary("dict1");
31c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setInteger("i1", 2014);
32c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->beginDictionary("dict2");
33c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setBoolean("b2", false);
34c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->endDictionary();
35c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setString("s1", "foo");
36c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->endDictionary();
37c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setDouble("d0", 0.0);
38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setBoolean("b0", true);
39c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->beginArray("a1");
40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->pushInteger(1);
41c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->pushBoolean(true);
42c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->beginDictionary();
43c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setInteger("i2", 3);
44c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->endDictionary();
45c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->endArray();
46c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    value->setString("s0", "foo");
47c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    String json = value->asTraceFormat();
48c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    EXPECT_EQ("{\"i0\":2014,\"dict1\":{\"i1\":2014,\"dict2\":{\"b2\":false},\"s1\":\"foo\"},\"d0\":0,\"b0\":true,\"a1\":[1,true,{\"i2\":3}],\"s0\":\"foo\"}", json);
49c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}
50c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
51c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}
52