OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/allocator/allocator_interception_mac.h" |
| 6 #include "base/allocator/malloc_zone_functions_mac.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/apple_apsl/malloc.h" |
| 9 |
| 10 namespace base { |
| 11 namespace allocator { |
| 12 |
| 13 namespace { |
| 14 void* TestMalloc(struct _malloc_zone_t* zone, size_t size) { |
| 15 return reinterpret_cast<void*>(0x123); |
| 16 } |
| 17 } // namespace |
| 18 |
| 19 class AllocatorInterceptionMacTest : public testing::Test { |
| 20 protected: |
| 21 void TearDown() override { UninterceptMallocZonesForTesting(); } |
| 22 }; |
| 23 |
| 24 TEST_F(AllocatorInterceptionMacTest, InterceptNewlyRegisteredZone) { |
| 25 ChromeMallocZone* default_zone = |
| 26 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); |
| 27 MallocZoneFunctions default_zone_functions; |
| 28 StoreZoneFunctions(default_zone, &default_zone_functions); |
| 29 default_zone_functions.malloc = &TestMalloc; |
| 30 InterceptNewlyRegisteredMallocZones(&default_zone_functions); |
| 31 |
| 32 struct _malloc_zone_t* test_malloc_zone = malloc_create_zone(0, 0); |
| 33 ChromeMallocZone* test_zone = |
| 34 reinterpret_cast<ChromeMallocZone*>(test_malloc_zone); |
| 35 EXPECT_EQ(test_zone->malloc, &TestMalloc); |
| 36 |
| 37 void* result = malloc_zone_malloc(test_malloc_zone, 13); |
| 38 EXPECT_EQ(reinterpret_cast<void*>(0x123), result); |
| 39 |
| 40 malloc_destroy_zone(test_malloc_zone); |
| 41 } |
| 42 |
| 43 } // namespace allocator |
| 44 } // namespace base |
OLD | NEW |