| 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 |
| 7 #include <utility> |
| 8 |
| 6 #include "base/values.h" | 9 #include "base/values.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 11 |
| 9 namespace base { | 12 namespace base { |
| 10 namespace trace_event { | 13 namespace trace_event { |
| 11 | 14 |
| 12 TEST(TraceEventArgumentTest, FlatDictionary) { | 15 TEST(TraceEventArgumentTest, FlatDictionary) { |
| 13 scoped_refptr<TracedValue> value = new TracedValue(); | 16 scoped_refptr<TracedValue> value = new TracedValue(); |
| 14 value->SetInteger("int", 2014); | 17 value->SetInteger("int", 2014); |
| 15 value->SetDouble("double", 0.0); | 18 value->SetDouble("double", 0.0); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 dict_value->SetBoolean("bool", true); | 102 dict_value->SetBoolean("bool", true); |
| 100 dict_value->SetInteger("int", 42); | 103 dict_value->SetInteger("int", 42); |
| 101 dict_value->SetDouble("double", 42.0f); | 104 dict_value->SetDouble("double", 42.0f); |
| 102 dict_value->SetString("string", std::string("a") + "b"); | 105 dict_value->SetString("string", std::string("a") + "b"); |
| 103 dict_value->SetString("string", std::string("a") + "b"); | 106 dict_value->SetString("string", std::string("a") + "b"); |
| 104 | 107 |
| 105 auto list_value = make_scoped_ptr(new ListValue); | 108 auto list_value = make_scoped_ptr(new ListValue); |
| 106 list_value->AppendBoolean(false); | 109 list_value->AppendBoolean(false); |
| 107 list_value->AppendInteger(1); | 110 list_value->AppendInteger(1); |
| 108 list_value->AppendString("in_list"); | 111 list_value->AppendString("in_list"); |
| 109 list_value->Append(dict_value.Pass()); | 112 list_value->Append(std::move(dict_value)); |
| 110 | 113 |
| 111 scoped_refptr<TracedValue> value = new TracedValue(); | 114 scoped_refptr<TracedValue> value = new TracedValue(); |
| 112 value->BeginDictionary("outer_dict"); | 115 value->BeginDictionary("outer_dict"); |
| 113 value->SetValue("inner_list", list_value.Pass()); | 116 value->SetValue("inner_list", std::move(list_value)); |
| 114 value->EndDictionary(); | 117 value->EndDictionary(); |
| 115 | 118 |
| 116 dict_value.reset(); | 119 dict_value.reset(); |
| 117 list_value.reset(); | 120 list_value.reset(); |
| 118 | 121 |
| 119 std::string json; | 122 std::string json; |
| 120 value->AppendAsTraceFormat(&json); | 123 value->AppendAsTraceFormat(&json); |
| 121 EXPECT_EQ( | 124 EXPECT_EQ( |
| 122 "{\"outer_dict\":{\"inner_list\":[false,1,\"in_list\",{\"bool\":true," | 125 "{\"outer_dict\":{\"inner_list\":[false,1,\"in_list\",{\"bool\":true," |
| 123 "\"double\":42.0,\"int\":42,\"string\":\"ab\"}]}}", | 126 "\"double\":42.0,\"int\":42,\"string\":\"ab\"}]}}", |
| (...skipping 26 matching lines...) Expand all Loading... |
| 150 nested_dict_value->SetInteger("f", 3); | 153 nested_dict_value->SetInteger("f", 3); |
| 151 nested_dict_value->BeginDictionary("g"); | 154 nested_dict_value->BeginDictionary("g"); |
| 152 nested_dict_value->EndDictionary(); | 155 nested_dict_value->EndDictionary(); |
| 153 json = ""; | 156 json = ""; |
| 154 nested_dict_value->AppendAsTraceFormat(&json); | 157 nested_dict_value->AppendAsTraceFormat(&json); |
| 155 EXPECT_EQ("{\"b\":2,\"c\":[\"foo\"],\"f\":3,\"g\":{}}", json); | 158 EXPECT_EQ("{\"b\":2,\"c\":[\"foo\"],\"f\":3,\"g\":{}}", json); |
| 156 } | 159 } |
| 157 | 160 |
| 158 } // namespace trace_event | 161 } // namespace trace_event |
| 159 } // namespace base | 162 } // namespace base |
| OLD | NEW |