OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/trace_event/trace_event_argument.h" | 5 #include "base/trace_event/trace_event_argument.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 namespace trace_event { | 10 namespace trace_event { |
11 | 11 |
12 TEST(TraceEventArgumentTest, FlatDictionary) { | 12 TEST(TraceEventArgumentTest, FlatDictionary) { |
13 scoped_refptr<TracedValue> value = new TracedValue(); | 13 scoped_refptr<TracedValue> value = new TracedValue(); |
14 value->SetInteger("int", 2014); | 14 value->SetInteger("int", 2014); |
15 value->SetDouble("double", 0.0); | 15 value->SetDouble("double", 0.0); |
16 value->SetBoolean("bool", true); | 16 value->SetBoolean("bool", true); |
17 value->SetString("string", "string"); | 17 value->SetString("string", "string"); |
18 std::string json = "PREFIX"; | 18 std::string json = "PREFIX"; |
19 value->AppendAsTraceFormat(&json); | 19 value->AppendAsTraceFormat(&json); |
20 EXPECT_EQ( | 20 EXPECT_EQ( |
21 "PREFIX{\"bool\":true,\"double\":0.0,\"int\":2014,\"string\":\"string\"}", | 21 "PREFIX{\"bool\":true,\"double\":0.0,\"int\":2014,\"string\":\"string\"}", |
22 json); | 22 json); |
23 } | 23 } |
24 | 24 |
| 25 TEST(TraceEventArgumentTest, NoDotPathExpansion) { |
| 26 scoped_refptr<TracedValue> value = new TracedValue(); |
| 27 value->SetInteger("in.t", 2014); |
| 28 value->SetDouble("doub.le", 0.0); |
| 29 value->SetBoolean("bo.ol", true); |
| 30 value->SetString("str.ing", "str.ing"); |
| 31 std::string json; |
| 32 value->AppendAsTraceFormat(&json); |
| 33 EXPECT_EQ( |
| 34 "{\"bo.ol\":true,\"doub.le\":0.0,\"in.t\":2014,\"str.ing\":\"str.ing\"}", |
| 35 json); |
| 36 } |
| 37 |
25 TEST(TraceEventArgumentTest, Hierarchy) { | 38 TEST(TraceEventArgumentTest, Hierarchy) { |
26 scoped_refptr<TracedValue> value = new TracedValue(); | 39 scoped_refptr<TracedValue> value = new TracedValue(); |
27 value->SetInteger("i0", 2014); | 40 value->SetInteger("i0", 2014); |
28 value->BeginDictionary("dict1"); | 41 value->BeginDictionary("dict1"); |
29 value->SetInteger("i1", 2014); | 42 value->SetInteger("i1", 2014); |
30 value->BeginDictionary("dict2"); | 43 value->BeginDictionary("dict2"); |
31 value->SetBoolean("b2", false); | 44 value->SetBoolean("b2", false); |
32 value->EndDictionary(); | 45 value->EndDictionary(); |
33 value->SetString("s1", "foo"); | 46 value->SetString("s1", "foo"); |
34 value->EndDictionary(); | 47 value->EndDictionary(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 nested_dict_value->SetInteger("f", 3); | 150 nested_dict_value->SetInteger("f", 3); |
138 nested_dict_value->BeginDictionary("g"); | 151 nested_dict_value->BeginDictionary("g"); |
139 nested_dict_value->EndDictionary(); | 152 nested_dict_value->EndDictionary(); |
140 json = ""; | 153 json = ""; |
141 nested_dict_value->AppendAsTraceFormat(&json); | 154 nested_dict_value->AppendAsTraceFormat(&json); |
142 EXPECT_EQ("{\"b\":2,\"c\":[\"foo\"],\"f\":3,\"g\":{}}", json); | 155 EXPECT_EQ("{\"b\":2,\"c\":[\"foo\"],\"f\":3,\"g\":{}}", json); |
143 } | 156 } |
144 | 157 |
145 } // namespace trace_event | 158 } // namespace trace_event |
146 } // namespace base | 159 } // namespace base |
OLD | NEW |