OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #import "ios/web/alloc_with_zone_interceptor.h" | |
6 | |
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" | |
11 | |
12 // Testable class to test web::AddAllocWithZoneMethod. | |
13 @interface CRBTestAlloc : NSObject | |
14 @end | |
15 @implementation CRBTestAlloc | |
16 @end | |
17 | |
18 namespace web { | |
19 namespace { | |
20 | |
21 // Test fixture for alloc_with_zone_interceptor functions. | |
22 typedef PlatformTest AllocWithZoneInterceptorTest; | |
23 | |
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); | |
34 return kResult; | |
35 }); | |
36 EXPECT_NSEQ(kResult, [CRBTestAlloc allocWithZone:kZone]); | |
37 } | |
38 | |
39 } // namespace | |
40 } // namespace web | |
OLD | NEW |