Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yulingtianxia committed Jul 31, 2018
1 parent fc0a144 commit 2275be4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
41 changes: 38 additions & 3 deletions MTDemo/MTDemoTests/MTDemoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,46 @@ - (void)setUp {

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
// [MTEngine.defaultEngine savePersistentRules];
[Stub mt_limitSelector:@selector(foo:) oncePerDuration:0.01].persistent = YES;
[MTEngine.defaultEngine savePersistentRules];
[super tearDown];
}

- (void)testSample {
- (void)testSamplePerformModeFirstly {
[self.stub mt_limitSelector:@selector(foo:) oncePerDuration:0.01 usingMode:MTPerformModeFirstly onMessageQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) alwaysInvokeBlock:nil];
[self.stub foo:[NSDate date]];
for (MTRule *rule in self.stub.mt_allRules) {
[rule discard];
}
}

- (void)testSamplePerformModeLast {
[self.stub mt_limitSelector:@selector(foo:) oncePerDuration:0.01 usingMode:MTPerformModeLast onMessageQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) alwaysInvokeBlock:nil];
[self.stub foo:[NSDate date]];
for (MTRule *rule in self.stub.mt_allRules) {
[rule discard];
}
}

- (void)testSamplePerformModeDebounce {
[self.stub mt_limitSelector:@selector(foo:) oncePerDuration:0.01 usingMode:MTPerformModeDebounce onMessageQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) alwaysInvokeBlock:nil];
[self.stub foo:[NSDate date]];
[self.stub mt_limitSelector:@selector(foo:) oncePerDuration:0 usingMode:MTPerformModeFirstly onMessageQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) alwaysInvokeBlock:nil];
for (MTRule *rule in self.stub.mt_allRules) {
[rule discard];
}
}

- (void)testSampleDurationZero
{
[self.stub mt_limitSelector:@selector(foo:) oncePerDuration:0 usingMode:MTPerformModeDebounce onMessageQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) alwaysInvokeBlock:nil];
[self.stub foo:[NSDate date]];
for (MTRule *rule in self.stub.mt_allRules) {
[rule discard];
}
}

- (void)testSampleAlwaysInvoke
{
[self.stub mt_limitSelector:@selector(foo:) oncePerDuration:0.01 usingMode:MTPerformModeFirstly onMessageQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) alwaysInvokeBlock:^(MTRule *rule, NSDate *date) {
return YES;
}];
Expand Down Expand Up @@ -136,6 +163,14 @@ - (void)testInstanceAndMetaClass {
[rule2 discard];
}

- (void)testSubAndSuperClass {
MTRule *rule1 = [Stub mt_limitSelector:@selector(foo:) oncePerDuration:0.01];
MTRule *rule2 = [SuperStub mt_limitSelector:@selector(foo:) oncePerDuration:0.01];
[self.stub foo:[NSDate date]];
[rule1 discard];
[rule2 discard];
}

- (void)testApplyStubThenDiscardThenApplySuperStub {
MTRule *rule1 = [Stub mt_limitSelector:@selector(foo:) oncePerDuration:0.01];
[rule1 discard];
Expand Down
4 changes: 2 additions & 2 deletions MessageThrottle/MessageThrottle.m
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,10 @@ static BOOL mt_isMsgForwardIMP(IMP impl)

static IMP mt_getMsgForwardIMP(Class cls, SEL selector)
{
Method originMethod = class_getInstanceMethod(cls, selector);
const char *originType = (char *)method_getTypeEncoding(originMethod);
IMP msgForwardIMP = _objc_msgForward;
#if !defined(__arm64__)
Method originMethod = class_getInstanceMethod(cls, selector);
const char *originType = (char *)method_getTypeEncoding(originMethod);
if (originType[0] == _C_STRUCT_B) {
//In some cases that returns struct, we should use the '_stret' API:
//http://sealiesoftware.com/blog/archive/2008/10/30/objc_explain_objc_msgSend_stret.html
Expand Down

0 comments on commit 2275be4

Please sign in to comment.