Chromium Code Reviews| Index: base/allocator/type_profiler_map_unittests.cc |
| diff --git a/base/allocator/type_profiler_map_unittests.cc b/base/allocator/type_profiler_map_unittests.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..60eae52cb71df80253bb84db6505bc4e45321e8d |
| --- /dev/null |
| +++ b/base/allocator/type_profiler_map_unittests.cc |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// This is a unittest set for type_profiler_map in third_party/tcmalloc. It is |
| +// independent from other tests and executed manually like allocator_unittests |
| +// since type_profiler_map is a singleton (like TCMalloc's heap-profiler), and |
| +// it requires RTTI and different compiling/linking options from others. |
| + |
| +#include <cstddef> |
|
Ryan Sleevi
2012/09/13 09:13:25
stddef.h
Dai Mikurube (NOT FULLTIME)
2012/09/13 10:45:04
Actually, is has been removed.
|
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/tcmalloc/chromium/src/gperftools/type_profiler_map.h" |
| + |
| +#if defined(TYPE_PROFILING) |
| + |
| +namespace base { |
| +namespace type_profiler { |
| + |
| +static const void* const g_const_null = static_cast<const void*>(NULL); |
| + |
| +TEST(TypeProfilerMapTest, NormalOperation) { |
| + // Allocate an object just to get a valid address. |
| + // This 'new' is not profiled by type_profiler. |
| + scoped_ptr<int> dummy(new int(48)); |
| + const std::type_info* type; |
| + |
| + type = LookupType(dummy.get()); |
| + EXPECT_EQ(type, g_const_null); |
|
Ryan Sleevi
2012/09/13 09:13:25
Please re-order all of the test comparisons to mat
Dai Mikurube (NOT FULLTIME)
2012/09/13 10:45:04
I chose just re-ordering.
|
| + |
| + InsertType(dummy.get(), 12, typeid(int)); |
| + type = LookupType(dummy.get()); |
| + ASSERT_NE(type, g_const_null); |
| + EXPECT_STREQ(type->name(), typeid(int).name()); |
| + |
| + EraseType(dummy.get()); |
| + type = LookupType(dummy.get()); |
| + EXPECT_EQ(type, g_const_null); |
| +} |
| + |
| +TEST(TypeProfilerMapTest, EraseWithoutInsert) { |
| + scoped_ptr<int> dummy(new int(48)); |
| + const std::type_info* type; |
| + |
| + for (int i = 0; i < 10; ++i) { |
| + EraseType(dummy.get()); |
| + type = LookupType(dummy.get()); |
| + EXPECT_EQ(type, g_const_null); |
| + } |
| +} |
| + |
| +TEST(TypeProfilerMapTest, InsertThenMultipleErase) { |
| + scoped_ptr<int> dummy(new int(48)); |
| + const std::type_info* type; |
| + |
| + InsertType(dummy.get(), 12, typeid(int)); |
| + type = LookupType(dummy.get()); |
| + ASSERT_NE(type, g_const_null); |
| + EXPECT_STREQ(type->name(), typeid(int).name()); |
| + |
| + for (int i = 0; i < 10; ++i) { |
| + EraseType(dummy.get()); |
| + type = LookupType(dummy.get()); |
| + EXPECT_EQ(type, g_const_null); |
| + } |
| +} |
| + |
| +TEST(TypeProfilerMapTest, MultipleInsertWithoutErase) { |
| + scoped_ptr<int> dummy(new int(48)); |
| + const std::type_info* type; |
| + |
| + InsertType(dummy.get(), 12, typeid(int)); |
| + type = LookupType(dummy.get()); |
| + ASSERT_NE(type, g_const_null); |
| + EXPECT_STREQ(type->name(), typeid(int).name()); |
| + |
| + InsertType(dummy.get(), 5, typeid(char)); |
| + type = LookupType(dummy.get()); |
| + ASSERT_NE(type, g_const_null); |
| + EXPECT_STREQ(type->name(), typeid(char).name()); |
| + |
| + InsertType(dummy.get(), 129, typeid(long)); |
| + type = LookupType(dummy.get()); |
| + ASSERT_NE(type, g_const_null); |
| + EXPECT_STREQ(type->name(), typeid(long).name()); |
| + |
| + EraseType(dummy.get()); |
| + type = LookupType(dummy.get()); |
| + EXPECT_EQ(type, g_const_null); |
| +} |
| + |
| +} // namespace type_profiler |
| +} // namespace base |
| + |
| +#endif // defined(TYPE_PROFILING) |
| + |
| +int main(int argc, char** argv) { |
| + testing::InitGoogleTest(&argc, argv); |
| + return RUN_ALL_TESTS(); |
| +} |