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

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

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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_memory_overhead.cc ('k') | base/values.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "base/trace_event/trace_event.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 return true; 253 return true;
254 } 254 }
255 255
256 DictionaryValue* TraceEventTestFixture::FindMatchingTraceEntry( 256 DictionaryValue* TraceEventTestFixture::FindMatchingTraceEntry(
257 const JsonKeyValue* key_values) { 257 const JsonKeyValue* key_values) {
258 // Scan all items 258 // Scan all items
259 size_t trace_parsed_count = trace_parsed_.GetSize(); 259 size_t trace_parsed_count = trace_parsed_.GetSize();
260 for (size_t i = 0; i < trace_parsed_count; i++) { 260 for (size_t i = 0; i < trace_parsed_count; i++) {
261 Value* value = NULL; 261 Value* value = NULL;
262 trace_parsed_.Get(i, &value); 262 trace_parsed_.Get(i, &value);
263 if (!value || value->GetType() != Value::TYPE_DICTIONARY) 263 if (!value || value->GetType() != Value::Type::DICTIONARY)
264 continue; 264 continue;
265 DictionaryValue* dict = static_cast<DictionaryValue*>(value); 265 DictionaryValue* dict = static_cast<DictionaryValue*>(value);
266 266
267 if (IsAllKeyValueInDict(key_values, dict)) 267 if (IsAllKeyValueInDict(key_values, dict))
268 return dict; 268 return dict;
269 } 269 }
270 return NULL; 270 return NULL;
271 } 271 }
272 272
273 void TraceEventTestFixture::DropTracedMetadataRecords() { 273 void TraceEventTestFixture::DropTracedMetadataRecords() {
274 std::unique_ptr<ListValue> old_trace_parsed(trace_parsed_.CreateDeepCopy()); 274 std::unique_ptr<ListValue> old_trace_parsed(trace_parsed_.CreateDeepCopy());
275 size_t old_trace_parsed_size = old_trace_parsed->GetSize(); 275 size_t old_trace_parsed_size = old_trace_parsed->GetSize();
276 trace_parsed_.Clear(); 276 trace_parsed_.Clear();
277 277
278 for (size_t i = 0; i < old_trace_parsed_size; i++) { 278 for (size_t i = 0; i < old_trace_parsed_size; i++) {
279 Value* value = nullptr; 279 Value* value = nullptr;
280 old_trace_parsed->Get(i, &value); 280 old_trace_parsed->Get(i, &value);
281 if (!value || value->GetType() != Value::TYPE_DICTIONARY) { 281 if (!value || value->GetType() != Value::Type::DICTIONARY) {
282 trace_parsed_.Append(value->CreateDeepCopy()); 282 trace_parsed_.Append(value->CreateDeepCopy());
283 continue; 283 continue;
284 } 284 }
285 DictionaryValue* dict = static_cast<DictionaryValue*>(value); 285 DictionaryValue* dict = static_cast<DictionaryValue*>(value);
286 std::string tmp; 286 std::string tmp;
287 if (dict->GetString("ph", &tmp) && tmp == "M") 287 if (dict->GetString("ph", &tmp) && tmp == "M")
288 continue; 288 continue;
289 289
290 trace_parsed_.Append(value->CreateDeepCopy()); 290 trace_parsed_.Append(value->CreateDeepCopy());
291 } 291 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // Scan all items 360 // Scan all items
361 size_t trace_parsed_count = trace_parsed.GetSize(); 361 size_t trace_parsed_count = trace_parsed.GetSize();
362 for (size_t i = 0; i < trace_parsed_count; i++) { 362 for (size_t i = 0; i < trace_parsed_count; i++) {
363 const Value* value = NULL; 363 const Value* value = NULL;
364 trace_parsed.Get(i, &value); 364 trace_parsed.Get(i, &value);
365 if (match_after_this_item) { 365 if (match_after_this_item) {
366 if (value == match_after_this_item) 366 if (value == match_after_this_item)
367 match_after_this_item = NULL; 367 match_after_this_item = NULL;
368 continue; 368 continue;
369 } 369 }
370 if (!value || value->GetType() != Value::TYPE_DICTIONARY) 370 if (!value || value->GetType() != Value::Type::DICTIONARY)
371 continue; 371 continue;
372 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); 372 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
373 373
374 if (IsStringInDict(string_to_match, dict)) 374 if (IsStringInDict(string_to_match, dict))
375 return dict; 375 return dict;
376 } 376 }
377 return NULL; 377 return NULL;
378 } 378 }
379 379
380 std::vector<const DictionaryValue*> FindTraceEntries( 380 std::vector<const DictionaryValue*> FindTraceEntries(
381 const ListValue& trace_parsed, 381 const ListValue& trace_parsed,
382 const char* string_to_match) { 382 const char* string_to_match) {
383 std::vector<const DictionaryValue*> hits; 383 std::vector<const DictionaryValue*> hits;
384 size_t trace_parsed_count = trace_parsed.GetSize(); 384 size_t trace_parsed_count = trace_parsed.GetSize();
385 for (size_t i = 0; i < trace_parsed_count; i++) { 385 for (size_t i = 0; i < trace_parsed_count; i++) {
386 const Value* value = NULL; 386 const Value* value = NULL;
387 trace_parsed.Get(i, &value); 387 trace_parsed.Get(i, &value);
388 if (!value || value->GetType() != Value::TYPE_DICTIONARY) 388 if (!value || value->GetType() != Value::Type::DICTIONARY)
389 continue; 389 continue;
390 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); 390 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
391 391
392 if (IsStringInDict(string_to_match, dict)) 392 if (IsStringInDict(string_to_match, dict))
393 hits.push_back(dict); 393 hits.push_back(dict);
394 } 394 }
395 return hits; 395 return hits;
396 } 396 }
397 397
398 const char kControlCharacters[] = "\001\002\003\n\r"; 398 const char kControlCharacters[] = "\001\002\003\n\r";
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 1107
1108 void ValidateInstantEventPresentOnEveryThread(const ListValue& trace_parsed, 1108 void ValidateInstantEventPresentOnEveryThread(const ListValue& trace_parsed,
1109 int num_threads, 1109 int num_threads,
1110 int num_events) { 1110 int num_events) {
1111 std::map<int, std::map<int, bool> > results; 1111 std::map<int, std::map<int, bool> > results;
1112 1112
1113 size_t trace_parsed_count = trace_parsed.GetSize(); 1113 size_t trace_parsed_count = trace_parsed.GetSize();
1114 for (size_t i = 0; i < trace_parsed_count; i++) { 1114 for (size_t i = 0; i < trace_parsed_count; i++) {
1115 const Value* value = NULL; 1115 const Value* value = NULL;
1116 trace_parsed.Get(i, &value); 1116 trace_parsed.Get(i, &value);
1117 if (!value || value->GetType() != Value::TYPE_DICTIONARY) 1117 if (!value || value->GetType() != Value::Type::DICTIONARY)
1118 continue; 1118 continue;
1119 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); 1119 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
1120 std::string name; 1120 std::string name;
1121 dict->GetString("name", &name); 1121 dict->GetString("name", &name);
1122 if (name != "multi thread event") 1122 if (name != "multi thread event")
1123 continue; 1123 continue;
1124 1124
1125 int thread = 0; 1125 int thread = 0;
1126 int event = 0; 1126 int event = 0;
1127 EXPECT_TRUE(dict->GetInteger("args.thread", &thread)); 1127 EXPECT_TRUE(dict->GetInteger("args.thread", &thread));
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2313 ASSERT_TRUE(args_dict); 2313 ASSERT_TRUE(args_dict);
2314 EXPECT_TRUE(args_dict->GetInteger("int_neg_ten", &int_value)); 2314 EXPECT_TRUE(args_dict->GetInteger("int_neg_ten", &int_value));
2315 EXPECT_EQ(-10, int_value); 2315 EXPECT_EQ(-10, int_value);
2316 2316
2317 // 1f must be serlized to JSON as "1.0" in order to be a double, not an int. 2317 // 1f must be serlized to JSON as "1.0" in order to be a double, not an int.
2318 dict = FindNamePhase("event3", "X"); 2318 dict = FindNamePhase("event3", "X");
2319 ASSERT_TRUE(dict); 2319 ASSERT_TRUE(dict);
2320 dict->GetDictionary("args", &args_dict); 2320 dict->GetDictionary("args", &args_dict);
2321 ASSERT_TRUE(args_dict); 2321 ASSERT_TRUE(args_dict);
2322 EXPECT_TRUE(args_dict->Get("float_one", &value)); 2322 EXPECT_TRUE(args_dict->Get("float_one", &value));
2323 EXPECT_TRUE(value->IsType(Value::TYPE_DOUBLE)); 2323 EXPECT_TRUE(value->IsType(Value::Type::DOUBLE));
2324 EXPECT_TRUE(value->GetAsDouble(&double_value)); 2324 EXPECT_TRUE(value->GetAsDouble(&double_value));
2325 EXPECT_EQ(1, double_value); 2325 EXPECT_EQ(1, double_value);
2326 2326
2327 // .5f must be serlized to JSON as "0.5". 2327 // .5f must be serlized to JSON as "0.5".
2328 dict = FindNamePhase("event4", "X"); 2328 dict = FindNamePhase("event4", "X");
2329 ASSERT_TRUE(dict); 2329 ASSERT_TRUE(dict);
2330 dict->GetDictionary("args", &args_dict); 2330 dict->GetDictionary("args", &args_dict);
2331 ASSERT_TRUE(args_dict); 2331 ASSERT_TRUE(args_dict);
2332 EXPECT_TRUE(args_dict->Get("float_half", &value)); 2332 EXPECT_TRUE(args_dict->Get("float_half", &value));
2333 EXPECT_TRUE(value->IsType(Value::TYPE_DOUBLE)); 2333 EXPECT_TRUE(value->IsType(Value::Type::DOUBLE));
2334 EXPECT_TRUE(value->GetAsDouble(&double_value)); 2334 EXPECT_TRUE(value->GetAsDouble(&double_value));
2335 EXPECT_EQ(0.5, double_value); 2335 EXPECT_EQ(0.5, double_value);
2336 2336
2337 // -.5f must be serlized to JSON as "-0.5". 2337 // -.5f must be serlized to JSON as "-0.5".
2338 dict = FindNamePhase("event5", "X"); 2338 dict = FindNamePhase("event5", "X");
2339 ASSERT_TRUE(dict); 2339 ASSERT_TRUE(dict);
2340 dict->GetDictionary("args", &args_dict); 2340 dict->GetDictionary("args", &args_dict);
2341 ASSERT_TRUE(args_dict); 2341 ASSERT_TRUE(args_dict);
2342 EXPECT_TRUE(args_dict->Get("float_neghalf", &value)); 2342 EXPECT_TRUE(args_dict->Get("float_neghalf", &value));
2343 EXPECT_TRUE(value->IsType(Value::TYPE_DOUBLE)); 2343 EXPECT_TRUE(value->IsType(Value::Type::DOUBLE));
2344 EXPECT_TRUE(value->GetAsDouble(&double_value)); 2344 EXPECT_TRUE(value->GetAsDouble(&double_value));
2345 EXPECT_EQ(-0.5, double_value); 2345 EXPECT_EQ(-0.5, double_value);
2346 2346
2347 // Infinity is serialized to JSON as a string. 2347 // Infinity is serialized to JSON as a string.
2348 dict = FindNamePhase("event6", "X"); 2348 dict = FindNamePhase("event6", "X");
2349 ASSERT_TRUE(dict); 2349 ASSERT_TRUE(dict);
2350 dict->GetDictionary("args", &args_dict); 2350 dict->GetDictionary("args", &args_dict);
2351 ASSERT_TRUE(args_dict); 2351 ASSERT_TRUE(args_dict);
2352 EXPECT_TRUE(args_dict->GetString("float_infinity", &str_value)); 2352 EXPECT_TRUE(args_dict->GetString("float_infinity", &str_value));
2353 EXPECT_STREQ("Infinity", str_value.c_str()); 2353 EXPECT_STREQ("Infinity", str_value.c_str());
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
3203 3203
3204 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { 3204 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) {
3205 BeginSpecificTrace("-*"); 3205 BeginSpecificTrace("-*");
3206 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); 3206 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1);
3207 EndTraceAndFlush(); 3207 EndTraceAndFlush();
3208 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); 3208 EXPECT_TRUE(FindNamePhase("clock_sync", "c"));
3209 } 3209 }
3210 3210
3211 } // namespace trace_event 3211 } // namespace trace_event
3212 } // namespace base 3212 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_memory_overhead.cc ('k') | base/values.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698