1 // Copyright 2015 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.
5 #import "ios/web/alloc_with_zone_interceptor.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/gtest_mac.h"
10 #include "testing/platform_test.h"
12 // Testable class to test web::AddAllocWithZoneMethod.
13 @interface CRBTestAlloc : NSObject
15 @implementation CRBTestAlloc
21 // Test fixture for alloc_with_zone_interceptor functions.
22 typedef PlatformTest AllocWithZoneInterceptorTest;
24 // Tests that AddAllocWithZoneMethod delegates allocation to the caller.
25 TEST_F(AllocWithZoneInterceptorTest, AddAllocWithZoneMethod) {
26 NSZone* const kZone = NSDefaultMallocZone();
27 base::scoped_nsobject<CRBTestAlloc> original_result(
28 [CRBTestAlloc allocWithZone:kZone]);
29 ASSERT_TRUE([original_result isMemberOfClass:[CRBTestAlloc class]]);
30 NSString* const kResult = @"test-result";
31 AddAllocWithZoneMethod([CRBTestAlloc class], ^id(Class klass, NSZone* zone) {
32 EXPECT_EQ([CRBTestAlloc class], klass);
33 EXPECT_EQ(kZone, zone);
36 EXPECT_NSEQ(kResult, [CRBTestAlloc allocWithZone:kZone]);