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..9d85d21f42d9e677f16ed0c48019d3f1c059c6d4 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"; |
| +const char kFolders[] = "base/trace_event"; |
|
petrcermak
2016/03/29 12:49:05
I'd say kPath would be easier to understand.
ssid
2016/03/29 18:32:45
Done.
|
| +#else |
| +const char kFileNameWin[] = "..\\..\\base\\memory\\memory_win.cc"; |
|
petrcermak
2016/03/29 12:49:05
Why not kFileName as well?
ssid
2016/03/29 18:32:45
Done.
|
| +const char kFolders[] = "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 value gets inserted and the exported value for |type_name| is same |
|
petrcermak
2016/03/29 12:49:05
nit: s/if value/if the value/ and s/is same/is the
ssid
2016/03/29 18:32:45
Done.
|
| +// as |exported_value|. |
| +void InsertAndTestExportedValue(const char* type_name, |
| + const char* exported_value) { |
|
petrcermak
2016/03/29 12:49:05
Don't you mean "expected"?
ssid
2016/03/29 18:32:45
yeah that makes sense.
|
| + 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 |exported_value|. |
| + std::string value; |
| + ASSERT_TRUE(dictionary->GetString("1", &value)); |
| + ASSERT_EQ(exported_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\""); |
| +} |
| - // 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, kFolders); |
| } |
| } // namespace trace_event |