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

Unified Diff: base/trace_event/heap_profiler_type_name_deduplicator_unittest.cc

Issue 1784133002: [tracing] Adding task information to heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit. Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/heap_profiler_type_name_deduplicator.cc ('k') | base/trace_event/trace_event.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/heap_profiler_type_name_deduplicator_unittest.cc
diff --git a/base/trace_event/heap_profiler_type_name_deduplicator_unittest.cc b/base/trace_event/heap_profiler_type_name_deduplicator_unittest.cc
index 92ffcf83599ca9e579a0a61170ea890fbb069712..8ab3f3719aaa82245c95b2fa87a5d60b461e4223 100644
--- a/base/trace_event/heap_profiler_type_name_deduplicator_unittest.cc
+++ b/base/trace_event/heap_profiler_type_name_deduplicator_unittest.cc
@@ -13,6 +13,8 @@
namespace base {
namespace trace_event {
+namespace {
+
// Define all strings once, because the deduplicator requires pointer equality,
// and string interning is unreliable.
const char kInt[] = "int";
@@ -20,12 +22,43 @@ const char kBool[] = "bool";
const char kString[] = "string";
const char kNeedsEscape[] = "\"quotes\"";
+#if defined(OS_POSIX)
+const char kTaskFileName[] = "../../base/trace_event/trace_log.cc";
+const char kTaskPath[] = "base/trace_event";
+#else
+const char kTaskFileName[] = "..\\..\\base\\memory\\memory_win.cc";
+const char kTaskPath[] = "base\\memory";
+#endif
+
scoped_ptr<Value> DumpAndReadBack(const TypeNameDeduplicator& deduplicator) {
std::string json;
deduplicator.AppendAsTraceFormat(&json);
return JSONReader::Read(json);
}
+// Inserts a single type name into a new TypeNameDeduplicator instance and
+// checks if the value gets inserted and the exported value for |type_name| is
+// the same as |expected_value|.
+void TestInsertTypeAndReadback(const char* type_name,
+ const char* expected_value) {
+ scoped_ptr<TypeNameDeduplicator> dedup(new TypeNameDeduplicator);
+ ASSERT_EQ(1, dedup->Insert(type_name));
+
+ scoped_ptr<Value> type_names = DumpAndReadBack(*dedup);
+ ASSERT_NE(nullptr, type_names);
+
+ const DictionaryValue* dictionary;
+ ASSERT_TRUE(type_names->GetAsDictionary(&dictionary));
+
+ // When the type name was inserted, it got ID 1. The exported key "1"
+ // should be equal to |expected_value|.
+ std::string value;
+ ASSERT_TRUE(dictionary->GetString("1", &value));
+ ASSERT_EQ(expected_value, value);
+}
+
+} // namespace
+
TEST(TypeNameDeduplicatorTest, Deduplication) {
// The type IDs should be like this:
// 0: [unknown]
@@ -48,22 +81,14 @@ TEST(TypeNameDeduplicatorTest, Deduplication) {
}
TEST(TypeNameDeduplicatorTest, EscapeTypeName) {
- scoped_ptr<TypeNameDeduplicator> dedup(new TypeNameDeduplicator);
- ASSERT_EQ(1, dedup->Insert(kNeedsEscape));
-
// Reading json should not fail, because the type name should have been
- // escaped properly.
- scoped_ptr<Value> type_names = DumpAndReadBack(*dedup);
- ASSERT_NE(nullptr, type_names);
-
- const DictionaryValue* dictionary;
- ASSERT_TRUE(type_names->GetAsDictionary(&dictionary));
+ // escaped properly and exported value should contain quotes.
+ TestInsertTypeAndReadback(kNeedsEscape, kNeedsEscape);
+}
- // When the type name was inserted, it got ID 1. The exported key "1"
- // should contain the name, with quotes.
- std::string type_name;
- ASSERT_TRUE(dictionary->GetString("1", &type_name));
- ASSERT_EQ("\"quotes\"", type_name);
+TEST(TypeNameDeduplicatorTest, TestExtractFileName) {
+ // The exported value for passed file name should be the folders in the path.
+ TestInsertTypeAndReadback(kTaskFileName, kTaskPath);
}
} // namespace trace_event
« no previous file with comments | « base/trace_event/heap_profiler_type_name_deduplicator.cc ('k') | base/trace_event/trace_event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698