OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 "base/debug/trace_event_argument.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 namespace base { |
| 9 namespace debug { |
| 10 |
| 11 class TraceEventArgumentTest : public testing::Test {}; |
| 12 |
| 13 TEST_F(TraceEventArgumentTest, FlatDictionary) { |
| 14 TracedValue value; |
| 15 value.SetInteger("int", 2014) |
| 16 .SetDouble("double", 0.0) |
| 17 .SetBoolean("bool", true) |
| 18 .SetString("string", "string"); |
| 19 scoped_refptr<base::debug::ConvertableToTraceFormat> convertable_value( |
| 20 value.finish()); |
| 21 std::string json; |
| 22 convertable_value->AppendAsTraceFormat(&json); |
| 23 EXPECT_EQ("{\"bool\":true,\"double\":0.0,\"int\":2014,\"string\":\"string\"}", |
| 24 json); |
| 25 } |
| 26 |
| 27 TEST_F(TraceEventArgumentTest, Hierarchy) { |
| 28 TracedValue value; |
| 29 value.SetInteger("i0", 2014) |
| 30 .BeginDictionary("dict1") |
| 31 .SetInteger("i1", 2014) |
| 32 .BeginDictionary("dict2") |
| 33 .SetBoolean("b2", false) |
| 34 .EndDictionary() |
| 35 .SetString("s1", "foo") |
| 36 .EndDictionary() |
| 37 .SetDouble("d0", 0.0) |
| 38 .SetBoolean("b0", true) |
| 39 .BeginArray("a1") |
| 40 .PushInteger(1) |
| 41 .PushBoolean(true) |
| 42 .BeginDictionary() |
| 43 .SetInteger("i2", 3) |
| 44 .EndDictionary() |
| 45 .EndArray() |
| 46 .SetString("s0", "foo"); |
| 47 scoped_refptr<base::debug::ConvertableToTraceFormat> convertable_value( |
| 48 value.finish()); |
| 49 std::string json; |
| 50 convertable_value->AppendAsTraceFormat(&json); |
| 51 EXPECT_EQ( |
| 52 "{\"a1\":[1,true,{\"i2\":3}],\"b0\":true,\"d0\":0.0,\"dict1\":{\"dict2\":" |
| 53 "{\"b2\":false},\"i1\":2014,\"s1\":\"foo\"},\"i0\":2014,\"s0\":" |
| 54 "\"foo\"}", |
| 55 json); |
| 56 } |
| 57 |
| 58 } // namespace debug |
| 59 } // namespace base |
OLD | NEW |