| Index: base/allocator/allocator_interception_mac_unittest.cc
|
| diff --git a/base/allocator/allocator_interception_mac_unittest.cc b/base/allocator/allocator_interception_mac_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..95e026bd1c5ef0863bf9e4abe6ce36ab0f013f6e
|
| --- /dev/null
|
| +++ b/base/allocator/allocator_interception_mac_unittest.cc
|
| @@ -0,0 +1,44 @@
|
| +// 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/allocator_interception_mac.h"
|
| +#include "base/allocator/malloc_zone_functions_mac.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/apple_apsl/malloc.h"
|
| +
|
| +namespace base {
|
| +namespace allocator {
|
| +
|
| +namespace {
|
| +void* TestMalloc(struct _malloc_zone_t* zone, size_t size) {
|
| + return reinterpret_cast<void*>(0x123);
|
| +}
|
| +} // namespace
|
| +
|
| +class AllocatorInterceptionMacTest : public testing::Test {
|
| + protected:
|
| + void TearDown() override { UninterceptMallocZonesForTesting(); }
|
| +};
|
| +
|
| +TEST_F(AllocatorInterceptionMacTest, InterceptNewlyRegisteredZone) {
|
| + ChromeMallocZone* default_zone =
|
| + reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
|
| + MallocZoneFunctions default_zone_functions;
|
| + StoreZoneFunctions(default_zone, &default_zone_functions);
|
| + default_zone_functions.malloc = &TestMalloc;
|
| + InterceptNewlyRegisteredMallocZones(&default_zone_functions);
|
| +
|
| + struct _malloc_zone_t* test_malloc_zone = malloc_create_zone(0, 0);
|
| + ChromeMallocZone* test_zone =
|
| + reinterpret_cast<ChromeMallocZone*>(test_malloc_zone);
|
| + EXPECT_EQ(test_zone->malloc, &TestMalloc);
|
| +
|
| + void* result = malloc_zone_malloc(test_malloc_zone, 13);
|
| + EXPECT_EQ(reinterpret_cast<void*>(0x123), result);
|
| +
|
| + malloc_destroy_zone(test_malloc_zone);
|
| +}
|
| +
|
| +} // namespace allocator
|
| +} // namespace base
|
|
|