| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/mac/scoped_objc_class_swizzler.h" | 5 #import "base/mac/scoped_objc_class_swizzler.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | 7 #import "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 ObjCClassSwizzlerTestOne : NSObject | 10 @interface ObjCClassSwizzlerTestOne : NSObject |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 { | 108 { |
| 109 base::mac::ScopedObjCClassSwizzler swizzler( | 109 base::mac::ScopedObjCClassSwizzler swizzler( |
| 110 [ObjCClassSwizzlerTestOne class], | 110 [ObjCClassSwizzlerTestOne class], |
| 111 [ObjCClassSwizzlerTestTwo class], | 111 [ObjCClassSwizzlerTestTwo class], |
| 112 @selector(function)); | 112 @selector(function)); |
| 113 EXPECT_EQ(20, [ObjCClassSwizzlerTestOne function]); | 113 EXPECT_EQ(20, [ObjCClassSwizzlerTestOne function]); |
| 114 EXPECT_EQ(10, [ObjCClassSwizzlerTestTwo function]); | 114 EXPECT_EQ(10, [ObjCClassSwizzlerTestTwo function]); |
| 115 | 115 |
| 116 IMP original = swizzler.GetOriginalImplementation(); | 116 IMP original = swizzler.GetOriginalImplementation(); |
| 117 id expected_result = reinterpret_cast<id>(10); | 117 id expected_result = reinterpret_cast<id>(10); |
| 118 EXPECT_EQ(expected_result, original(nil, @selector(function))); | 118 EXPECT_EQ(expected_result, |
| 119 original([ObjCClassSwizzlerTestOne class], @selector(function))); |
| 119 } | 120 } |
| 120 | 121 |
| 121 EXPECT_EQ(10, [ObjCClassSwizzlerTestOne function]); | 122 EXPECT_EQ(10, [ObjCClassSwizzlerTestOne function]); |
| 122 EXPECT_EQ(20, [ObjCClassSwizzlerTestTwo function]); | 123 EXPECT_EQ(20, [ObjCClassSwizzlerTestTwo function]); |
| 123 } | 124 } |
| 124 | 125 |
| 125 TEST(ObjCClassSwizzlerTest, SwizzleViaCategory) { | 126 TEST(ObjCClassSwizzlerTest, SwizzleViaCategory) { |
| 126 base::scoped_nsobject<ObjCClassSwizzlerTestOne> object_one( | 127 base::scoped_nsobject<ObjCClassSwizzlerTestOne> object_one( |
| 127 [[ObjCClassSwizzlerTestOne alloc] init]); | 128 [[ObjCClassSwizzlerTestOne alloc] init]); |
| 128 EXPECT_EQ(3, [object_one method]); | 129 EXPECT_EQ(3, [object_one method]); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 157 IMP original = swizzler.GetOriginalImplementation(); | 158 IMP original = swizzler.GetOriginalImplementation(); |
| 158 id expected_result = reinterpret_cast<id>(3); | 159 id expected_result = reinterpret_cast<id>(3); |
| 159 EXPECT_EQ(expected_result, original(child, @selector(method))); | 160 EXPECT_EQ(expected_result, original(child, @selector(method))); |
| 160 } | 161 } |
| 161 | 162 |
| 162 EXPECT_EQ(3, [child method]); | 163 EXPECT_EQ(3, [child method]); |
| 163 } | 164 } |
| 164 | 165 |
| 165 } // namespace mac | 166 } // namespace mac |
| 166 } // namespace base | 167 } // namespace base |
| OLD | NEW |