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

Side by Side Diff: chrome/common/mac/objc_method_swizzle_unittest.mm

Issue 345243007: Add ScopedObjCClassSwizzler in base/mac, absorbs objc_method_swizzle and ScopedClassSwizzler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Inlude in shiny new gn base_unittests target Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/mac/objc_method_swizzle.mm ('k') | chrome/common/mac/objc_zombie.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/common/mac/objc_method_swizzle.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 @interface ObjcMethodSwizzleTest : NSObject
11 - (id)self;
12
13 - (NSInteger)one;
14 - (NSInteger)two;
15 @end
16
17 @implementation ObjcMethodSwizzleTest : NSObject
18 - (id)self {
19 return [super self];
20 }
21
22 - (NSInteger)one {
23 return 1;
24 }
25 - (NSInteger)two {
26 return 2;
27 }
28 @end
29
30 @interface ObjcMethodSwizzleTest (ObjcMethodSwizzleTestCategory)
31 - (NSUInteger)hash;
32 @end
33
34 @implementation ObjcMethodSwizzleTest (ObjcMethodSwizzleTestCategory)
35 - (NSUInteger)hash {
36 return [super hash];
37 }
38 @end
39
40 namespace ObjcEvilDoers {
41
42 TEST(ObjcMethodSwizzleTest, GetImplementedInstanceMethod) {
43 EXPECT_EQ(class_getInstanceMethod([NSObject class], @selector(dealloc)),
44 GetImplementedInstanceMethod([NSObject class], @selector(dealloc)));
45 EXPECT_EQ(class_getInstanceMethod([NSObject class], @selector(self)),
46 GetImplementedInstanceMethod([NSObject class], @selector(self)));
47 EXPECT_EQ(class_getInstanceMethod([NSObject class], @selector(hash)),
48 GetImplementedInstanceMethod([NSObject class], @selector(hash)));
49
50 Class testClass = [ObjcMethodSwizzleTest class];
51 EXPECT_EQ(class_getInstanceMethod(testClass, @selector(self)),
52 GetImplementedInstanceMethod(testClass, @selector(self)));
53 EXPECT_NE(class_getInstanceMethod([NSObject class], @selector(self)),
54 class_getInstanceMethod(testClass, @selector(self)));
55
56 EXPECT_TRUE(class_getInstanceMethod(testClass, @selector(dealloc)));
57 EXPECT_FALSE(GetImplementedInstanceMethod(testClass, @selector(dealloc)));
58 }
59
60 TEST(ObjcMethodSwizzleTest, SwizzleImplementedInstanceMethods) {
61 base::scoped_nsobject<ObjcMethodSwizzleTest> object(
62 [[ObjcMethodSwizzleTest alloc] init]);
63 EXPECT_EQ([object one], 1);
64 EXPECT_EQ([object two], 2);
65
66 Class testClass = [object class];
67 SwizzleImplementedInstanceMethods(testClass, @selector(one), @selector(two));
68 EXPECT_EQ([object one], 2);
69 EXPECT_EQ([object two], 1);
70
71 SwizzleImplementedInstanceMethods(testClass, @selector(one), @selector(two));
72 EXPECT_EQ([object one], 1);
73 EXPECT_EQ([object two], 2);
74 }
75
76 } // namespace ObjcEvilDoers
OLDNEW
« no previous file with comments | « chrome/common/mac/objc_method_swizzle.mm ('k') | chrome/common/mac/objc_zombie.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698