Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: base/trace_event/trace_event_argument_unittest.cc

Issue 2975033002: [tracing] Optimize TracedValue::AppendAsTraceFormat(). (Closed)
Patch Set: Fix GraphicsMemoryDumpProviderTest Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/trace_event_argument.cc ('k') | cc/base/filter_operations_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace base { 15 namespace base {
16 namespace trace_event { 16 namespace trace_event {
17 17
18 TEST(TraceEventArgumentTest, FlatDictionary) { 18 TEST(TraceEventArgumentTest, FlatDictionary) {
19 std::unique_ptr<TracedValue> value(new TracedValue()); 19 std::unique_ptr<TracedValue> value(new TracedValue());
20 value->SetBoolean("bool", true);
21 value->SetDouble("double", 0.0);
20 value->SetInteger("int", 2014); 22 value->SetInteger("int", 2014);
21 value->SetDouble("double", 0.0);
22 value->SetBoolean("bool", true);
23 value->SetString("string", "string"); 23 value->SetString("string", "string");
24 std::string json = "PREFIX"; 24 std::string json = "PREFIX";
25 value->AppendAsTraceFormat(&json); 25 value->AppendAsTraceFormat(&json);
26 EXPECT_EQ( 26 EXPECT_EQ(
27 "PREFIX{\"bool\":true,\"double\":0.0,\"int\":2014,\"string\":\"string\"}", 27 "PREFIX{\"bool\":true,\"double\":0.0,\"int\":2014,\"string\":\"string\"}",
28 json); 28 json);
29 } 29 }
30 30
31 TEST(TraceEventArgumentTest, NoDotPathExpansion) { 31 TEST(TraceEventArgumentTest, NoDotPathExpansion) {
32 std::unique_ptr<TracedValue> value(new TracedValue()); 32 std::unique_ptr<TracedValue> value(new TracedValue());
33 value->SetBoolean("bo.ol", true);
34 value->SetDouble("doub.le", 0.0);
33 value->SetInteger("in.t", 2014); 35 value->SetInteger("in.t", 2014);
34 value->SetDouble("doub.le", 0.0);
35 value->SetBoolean("bo.ol", true);
36 value->SetString("str.ing", "str.ing"); 36 value->SetString("str.ing", "str.ing");
37 std::string json; 37 std::string json;
38 value->AppendAsTraceFormat(&json); 38 value->AppendAsTraceFormat(&json);
39 EXPECT_EQ( 39 EXPECT_EQ(
40 "{\"bo.ol\":true,\"doub.le\":0.0,\"in.t\":2014,\"str.ing\":\"str.ing\"}", 40 "{\"bo.ol\":true,\"doub.le\":0.0,\"in.t\":2014,\"str.ing\":\"str.ing\"}",
41 json); 41 json);
42 } 42 }
43 43
44 TEST(TraceEventArgumentTest, Hierarchy) { 44 TEST(TraceEventArgumentTest, Hierarchy) {
45 std::unique_ptr<TracedValue> value(new TracedValue()); 45 std::unique_ptr<TracedValue> value(new TracedValue());
46 value->SetInteger("i0", 2014);
47 value->BeginDictionary("dict1");
48 value->SetInteger("i1", 2014);
49 value->BeginDictionary("dict2");
50 value->SetBoolean("b2", false);
51 value->EndDictionary();
52 value->SetString("s1", "foo");
53 value->EndDictionary();
54 value->SetDouble("d0", 0.0);
55 value->SetBoolean("b0", true);
56 value->BeginArray("a1"); 46 value->BeginArray("a1");
57 value->AppendInteger(1); 47 value->AppendInteger(1);
58 value->AppendBoolean(true); 48 value->AppendBoolean(true);
59 value->BeginDictionary(); 49 value->BeginDictionary();
60 value->SetInteger("i2", 3); 50 value->SetInteger("i2", 3);
61 value->EndDictionary(); 51 value->EndDictionary();
62 value->EndArray(); 52 value->EndArray();
53 value->SetBoolean("b0", true);
54 value->SetDouble("d0", 0.0);
55 value->BeginDictionary("dict1");
56 value->BeginDictionary("dict2");
57 value->SetBoolean("b2", false);
58 value->EndDictionary();
59 value->SetInteger("i1", 2014);
60 value->SetString("s1", "foo");
61 value->EndDictionary();
62 value->SetInteger("i0", 2014);
63 value->SetString("s0", "foo"); 63 value->SetString("s0", "foo");
64 std::string json; 64 std::string json;
65 value->AppendAsTraceFormat(&json); 65 value->AppendAsTraceFormat(&json);
66 EXPECT_EQ( 66 EXPECT_EQ(
67 "{\"a1\":[1,true,{\"i2\":3}],\"b0\":true,\"d0\":0.0,\"dict1\":{\"dict2\":" 67 "{\"a1\":[1,true,{\"i2\":3}],\"b0\":true,\"d0\":0.0,\"dict1\":{\"dict2\":"
68 "{\"b2\":false},\"i1\":2014,\"s1\":\"foo\"},\"i0\":2014,\"s0\":" 68 "{\"b2\":false},\"i1\":2014,\"s1\":\"foo\"},\"i0\":2014,\"s0\":"
69 "\"foo\"}", 69 "\"foo\"}",
70 json); 70 json);
71 } 71 }
72 72
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 nested_dict_value->SetInteger("f", 3); 156 nested_dict_value->SetInteger("f", 3);
157 nested_dict_value->BeginDictionary("g"); 157 nested_dict_value->BeginDictionary("g");
158 nested_dict_value->EndDictionary(); 158 nested_dict_value->EndDictionary();
159 json = ""; 159 json = "";
160 nested_dict_value->AppendAsTraceFormat(&json); 160 nested_dict_value->AppendAsTraceFormat(&json);
161 EXPECT_EQ("{\"b\":2,\"c\":[\"foo\"],\"f\":3,\"g\":{}}", json); 161 EXPECT_EQ("{\"b\":2,\"c\":[\"foo\"],\"f\":3,\"g\":{}}", json);
162 } 162 }
163 163
164 } // namespace trace_event 164 } // namespace trace_event
165 } // namespace base 165 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_argument.cc ('k') | cc/base/filter_operations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698