OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/common/mac/objc_method_swizzle.h" | 5 #import "chrome/common/mac/objc_method_swizzle.h" |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 @interface ObjcMethodSwizzleTest : NSObject | 10 @interface ObjcMethodSwizzleTest : NSObject |
11 - (id)self; | 11 - (id)self; |
12 | 12 |
13 - (NSInteger)one; | 13 - (NSInteger)one; |
14 - (NSInteger)two; | 14 - (NSInteger)two; |
15 @end | 15 @end |
16 | 16 |
17 @implementation ObjcMethodSwizzleTest : NSObject | 17 @implementation ObjcMethodSwizzleTest : NSObject |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 EXPECT_EQ(class_getInstanceMethod(testClass, @selector(self)), | 51 EXPECT_EQ(class_getInstanceMethod(testClass, @selector(self)), |
52 GetImplementedInstanceMethod(testClass, @selector(self))); | 52 GetImplementedInstanceMethod(testClass, @selector(self))); |
53 EXPECT_NE(class_getInstanceMethod([NSObject class], @selector(self)), | 53 EXPECT_NE(class_getInstanceMethod([NSObject class], @selector(self)), |
54 class_getInstanceMethod(testClass, @selector(self))); | 54 class_getInstanceMethod(testClass, @selector(self))); |
55 | 55 |
56 EXPECT_TRUE(class_getInstanceMethod(testClass, @selector(dealloc))); | 56 EXPECT_TRUE(class_getInstanceMethod(testClass, @selector(dealloc))); |
57 EXPECT_FALSE(GetImplementedInstanceMethod(testClass, @selector(dealloc))); | 57 EXPECT_FALSE(GetImplementedInstanceMethod(testClass, @selector(dealloc))); |
58 } | 58 } |
59 | 59 |
60 TEST(ObjcMethodSwizzleTest, SwizzleImplementedInstanceMethods) { | 60 TEST(ObjcMethodSwizzleTest, SwizzleImplementedInstanceMethods) { |
61 scoped_nsobject<ObjcMethodSwizzleTest> object( | 61 base::scoped_nsobject<ObjcMethodSwizzleTest> object( |
62 [[ObjcMethodSwizzleTest alloc] init]); | 62 [[ObjcMethodSwizzleTest alloc] init]); |
63 EXPECT_EQ([object one], 1); | 63 EXPECT_EQ([object one], 1); |
64 EXPECT_EQ([object two], 2); | 64 EXPECT_EQ([object two], 2); |
65 | 65 |
66 Class testClass = [object class]; | 66 Class testClass = [object class]; |
67 SwizzleImplementedInstanceMethods(testClass, @selector(one), @selector(two)); | 67 SwizzleImplementedInstanceMethods(testClass, @selector(one), @selector(two)); |
68 EXPECT_EQ([object one], 2); | 68 EXPECT_EQ([object one], 2); |
69 EXPECT_EQ([object two], 1); | 69 EXPECT_EQ([object two], 1); |
70 | 70 |
71 SwizzleImplementedInstanceMethods(testClass, @selector(one), @selector(two)); | 71 SwizzleImplementedInstanceMethods(testClass, @selector(one), @selector(two)); |
72 EXPECT_EQ([object one], 1); | 72 EXPECT_EQ([object one], 1); |
73 EXPECT_EQ([object two], 2); | 73 EXPECT_EQ([object two], 2); |
74 } | 74 } |
75 | 75 |
76 } // namespace ObjcEvilDoers | 76 } // namespace ObjcEvilDoers |
OLD | NEW |