This repository has been archived by the owner on Jun 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
JEFRecordingTests.m
60 lines (47 loc) · 1.79 KB
/
JEFRecordingTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// JEFRecordingTests.m
// JeffTests
//
// Created by Brandon on 2/21/2014.
// Copyright (c) 2014 Brandon Evans. All rights reserved.
//
#import <XCTest/XCTest.h>
#import <Dropbox/Dropbox.h>
#import <objc/runtime.h>
#import "JEFRecording.h"
@implementation DBFileInfo (Mock)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
[self swizzleMethods:class originalSelector:@selector(path) swizzledSelector:@selector(mock_path)];
});
}
+ (void)swizzleMethods:(Class)class originalSelector:(SEL)originalSelector swizzledSelector:(SEL)swizzledSelector {
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
static NSInteger pathCount = 0;
- (DBPath *)mock_path {
pathCount += 1;
return [[DBPath alloc] initWithString:[NSString stringWithFormat:@"/blah%ld.png", (long)pathCount]];
}
@end
@interface JEFRecordingTests : XCTestCase
@end
@implementation JEFRecordingTests
- (void)testIsEqual {
JEFRecording *recording = [JEFRecording recordingWithNewFile:nil];
JEFRecording *recording2 = [JEFRecording recordingWithNewFile:nil];
XCTAssertFalse([recording isEqual:nil]);
XCTAssertFalse([recording isEqual:@5]);
XCTAssertFalse([recording isEqual:recording2]);
XCTAssertTrue([recording isEqual:recording]);
}
@end