1// Copyright 2014 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. 4 5#include "config.h" 6 7#include "platform/TracedValue.h" 8 9#include <gtest/gtest.h> 10 11using namespace blink; 12 13namespace { 14 15TEST(TracedValueTest, FlatDictionary) 16{ 17 RefPtr<TracedValue> value = TracedValue::create(); 18 value->setInteger("int", 2014); 19 value->setDouble("double", 0.0); 20 value->setBoolean("bool", true); 21 value->setString("string", "string"); 22 String json = value->asTraceFormat(); 23 EXPECT_EQ("{\"int\":2014,\"double\":0,\"bool\":true,\"string\":\"string\"}", json); 24} 25 26TEST(TracedValueTest, Hierarchy) 27{ 28 RefPtr<TracedValue> value = TracedValue::create(); 29 value->setInteger("i0", 2014); 30 value->beginDictionary("dict1"); 31 value->setInteger("i1", 2014); 32 value->beginDictionary("dict2"); 33 value->setBoolean("b2", false); 34 value->endDictionary(); 35 value->setString("s1", "foo"); 36 value->endDictionary(); 37 value->setDouble("d0", 0.0); 38 value->setBoolean("b0", true); 39 value->beginArray("a1"); 40 value->pushInteger(1); 41 value->pushBoolean(true); 42 value->beginDictionary(); 43 value->setInteger("i2", 3); 44 value->endDictionary(); 45 value->endArray(); 46 value->setString("s0", "foo"); 47 String json = value->asTraceFormat(); 48 EXPECT_EQ("{\"i0\":2014,\"dict1\":{\"i1\":2014,\"dict2\":{\"b2\":false},\"s1\":\"foo\"},\"d0\":0,\"b0\":true,\"a1\":[1,true,{\"i2\":3}],\"s0\":\"foo\"}", json); 49} 50 51} 52