Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: base/allocator/malloc_zone_functions_mac_unittest.cc

Issue 2703803004: macOS: Shim all malloc zones. (Closed)
Patch Set: more base export. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/malloc_zone_functions_mac.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace base {
9 namespace allocator {
10
11 class MallocZoneFunctionsTest : public testing::Test {
12 protected:
13 void SetUp() override { ClearAllMallocZonesForTesting(); }
14 };
15
16 TEST_F(MallocZoneFunctionsTest, TestDefaultZoneMallocFree) {
17 ChromeMallocZone* malloc_zone =
18 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
19 StoreMallocZone(malloc_zone);
20 int* test = reinterpret_cast<int*>(
21 g_malloc_zones[0].malloc(malloc_default_zone(), 33));
22 test[0] = 1;
23 test[1] = 2;
24 g_malloc_zones[0].free(malloc_default_zone(), test);
25 }
26
27 TEST_F(MallocZoneFunctionsTest, IsZoneAlreadyStored) {
28 ChromeMallocZone* malloc_zone =
29 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
30 EXPECT_FALSE(IsMallocZoneAlreadyStored(malloc_zone));
31 StoreMallocZone(malloc_zone);
32 EXPECT_TRUE(IsMallocZoneAlreadyStored(malloc_zone));
33 }
34
35 TEST_F(MallocZoneFunctionsTest, CannotDoubleStoreZone) {
36 ChromeMallocZone* malloc_zone =
37 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
38 StoreMallocZone(malloc_zone);
39 StoreMallocZone(malloc_zone);
40 EXPECT_EQ(1, GetMallocZoneCountForTesting());
41 }
42
43 TEST_F(MallocZoneFunctionsTest, CannotStoreMoreThanMaxZones) {
44 std::vector<ChromeMallocZone> zones;
45 zones.resize(kMaxZoneCount * 2);
46 for (int i = 0; i < kMaxZoneCount * 2; ++i) {
47 ChromeMallocZone& zone = zones[i];
48 memcpy(&zone, malloc_default_zone(), sizeof(ChromeMallocZone));
49 StoreMallocZone(&zone);
50 }
51
52 int max_zone_count = kMaxZoneCount;
53 EXPECT_EQ(max_zone_count, GetMallocZoneCountForTesting());
54 }
55
56 } // namespace allocator
57 } // namespace base
OLDNEW
« base/allocator/malloc_zone_functions_mac.cc ('K') | « base/allocator/malloc_zone_functions_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698