Index: base/allocator/malloc_zone_aggregator_mac_unittest.cc |
diff --git a/base/allocator/malloc_zone_aggregator_mac_unittest.cc b/base/allocator/malloc_zone_aggregator_mac_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c9b3f32bbc89d0e3f6a91a15ad3ae0abc694bc38 |
--- /dev/null |
+++ b/base/allocator/malloc_zone_aggregator_mac_unittest.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2017 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. |
+ |
+#include "base/allocator/malloc_zone_aggregator_mac.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace base { |
+namespace allocator { |
+ |
+TEST(MallocZoneAggregatorTest, TestDefaultZoneMallocFree) { |
+ MallocZoneAggregator aggregator; |
+ ChromeMallocZone* malloc_zone = |
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); |
+ aggregator.StoreZone(malloc_zone); |
+ int* test = |
+ reinterpret_cast<int*>(aggregator.DispatchMallocToZone(malloc_zone, 33)); |
+ test[0] = 1; |
+ test[1] = 2; |
+ aggregator.DispatchFreeToZone(malloc_zone, test); |
+} |
+ |
+TEST(MallocZoneAggregatorTest, IsZoneAlreadyStored) { |
+ MallocZoneAggregator aggregator; |
+ ChromeMallocZone* malloc_zone = |
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); |
+ EXPECT_FALSE(aggregator.IsZoneAlreadyStored(malloc_zone)); |
+ aggregator.StoreZone(malloc_zone); |
+ EXPECT_TRUE(aggregator.IsZoneAlreadyStored(malloc_zone)); |
+} |
+ |
+TEST(MallocZoneAggregatorTest, CannotDoubleStoreZone) { |
+ MallocZoneAggregator aggregator; |
+ ChromeMallocZone* malloc_zone = |
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); |
+ aggregator.StoreZone(malloc_zone); |
+ aggregator.StoreZone(malloc_zone); |
+ EXPECT_EQ(1, aggregator.GetZoneCount()); |
+} |
+ |
+TEST(MallocZoneAggregatorTest, CannotStoreMoreThanMaxZones) { |
+ MallocZoneAggregator aggregator; |
+ |
+ std::vector<ChromeMallocZone> zones; |
+ zones.resize(MallocZoneAggregator::kMaxZoneCount * 2); |
+ for (int i = 0; i < MallocZoneAggregator::kMaxZoneCount * 2; ++i) { |
+ ChromeMallocZone& zone = zones[i]; |
+ memcpy(&zone, malloc_default_zone(), sizeof(ChromeMallocZone)); |
+ aggregator.StoreZone(&zone); |
+ } |
+ |
+ int max_zone_count = MallocZoneAggregator::kMaxZoneCount; |
+ EXPECT_EQ(max_zone_count, aggregator.GetZoneCount()); |
+} |
+ |
+} // namespace allocator |
+} // namespace base |