Chromium Code Reviews| 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..4cfda18a006ad64cc46dc4e8674cbf5e78be8b02 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 kFileName[] = "../../base/trace_event/trace_log.cc"; |
|
Primiano Tucci (use gerrit)
2016/03/31 15:37:16
maybe kTaskFileName and kTaskPath will make it eas
ssid
2016/04/01 04:34:54
Done.
|
| +const char kPath[] = "base/trace_event"; |
| +#else |
| +const char kFileName[] = "..\\..\\base\\memory\\memory_win.cc"; |
| +const char kPath[] = "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 InsertAndTestExportedValue(const char* type_name, |
|
Primiano Tucci (use gerrit)
2016/03/31 15:37:16
maybe TestInsertTypeAndReadback?
ssid
2016/04/01 04:34:54
Done.
|
| + 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. |
| + InsertAndTestExportedValue(kNeedsEscape, "\"quotes\""); |
|
Primiano Tucci (use gerrit)
2016/03/31 15:37:16
I guess this can be
InsertAndTestExportedValue(kN
ssid
2016/04/01 04:34:54
I thought u wanted to make it explicit. fixed.
|
| +} |
| - // 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. |
| + InsertAndTestExportedValue(kFileName, kPath); |
| } |
| } // namespace trace_event |