Skip to content

Commit

Permalink
Merge pull request #1518 from smartdevicelink/bugfix/issue-1517-OCMoc…
Browse files Browse the repository at this point in the history
…k-test-failures

Fix issues shown by OCMock 3.5
  • Loading branch information
joeljfischer committed Jan 8, 2020
2 parents 1ea33cb + a1dd7d8 commit 2ff8972
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 29 deletions.
8 changes: 1 addition & 7 deletions SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m
Expand Up @@ -222,8 +222,7 @@ @interface SDLChoiceSetManager()

beforeEach(^{
pendingPreloadOp = [[SDLPreloadChoicesOperation alloc] init];
OCMPartialMock(pendingPreloadOp);
OCMStub([pendingPreloadOp removeChoicesFromUpload:[OCMArg any]]);

[testManager.transactionQueue addOperation:pendingPreloadOp];

testManager.pendingMutablePreloadChoices = [NSMutableSet setWithObject:testCell1];
Expand All @@ -232,11 +231,6 @@ @interface SDLChoiceSetManager()
});

it(@"should properly start the deletion", ^{
OCMStub([pendingPreloadOp removeChoicesFromUpload:[OCMArg checkWithBlock:^BOOL(id obj) {
NSArray<SDLChoiceCell *> *choices = (NSArray<SDLChoiceCell *> *)obj;
return (choices.count == 1) && ([choices.firstObject isEqual:testCell1]);
}]]);

expect(testManager.pendingPreloadChoices).to(beEmpty());
expect(testManager.transactionQueue.operationCount).to(equal(1)); // No delete operation
});
Expand Down
104 changes: 82 additions & 22 deletions SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m
Expand Up @@ -51,7 +51,7 @@ @interface SDLFocusableItemLocator ()
__block SDLFocusableItemLocator *hapticManager;
__block SDLSendHapticData* sentHapticRequest;

__block id sdlLifecycleManager = OCMClassMock([SDLLifecycleManager class]);
__block id<SDLConnectionManagerType> sdlLifecycleManager = nil;
__block SDLStreamingVideoScaleManager *sdlStreamingVideoScaleManager = nil;
__block CGRect viewRect1;
__block CGRect viewRect2;
Expand All @@ -61,17 +61,11 @@ @interface SDLFocusableItemLocator ()
uiViewController = [[UIViewController alloc] init];
uiWindow.rootViewController = uiViewController;

sdlLifecycleManager = OCMProtocolMock(@protocol(SDLConnectionManagerType));

hapticManager = nil;
sentHapticRequest = nil;
sdlStreamingVideoScaleManager = [[SDLStreamingVideoScaleManager alloc] initWithScale:1.0 displayViewportResolution:uiViewController.view.frame.size];

OCMExpect([[sdlLifecycleManager stub] sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);
});

context(@"when disabled", ^{
Expand All @@ -86,7 +80,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have no views", ^{
OCMVerify(sdlLifecycleManager);
OCMReject([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

expect(sentHapticRequest).to(beNil());
});
Expand All @@ -99,7 +99,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have no focusable view", ^{
OCMVerify(sdlLifecycleManager);
OCMReject([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);
expect(sentHapticRequest.hapticRectData.count).to(equal(0));
});
});
Expand All @@ -116,7 +122,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have one view", ^{
OCMVerify(sdlLifecycleManager);
OCMVerify([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

int expectedCount = 1;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));
Expand All @@ -143,7 +155,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have one view", ^{
OCMVerify(sdlLifecycleManager);
OCMVerify([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

int expectedCount = 1;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));
Expand Down Expand Up @@ -176,7 +194,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have two views", ^{
OCMVerify(sdlLifecycleManager);
OCMVerify([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

int expectedCount = 2;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));
Expand Down Expand Up @@ -214,7 +238,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have only leaf views added", ^{
OCMVerify(sdlLifecycleManager);
OCMVerify([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

int expectedCount = 2;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));
Expand Down Expand Up @@ -252,7 +282,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have only leaf views added", ^{
OCMVerify(sdlLifecycleManager);
OCMVerify([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

int expectedCount = 2;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));
Expand All @@ -273,6 +309,14 @@ @interface SDLFocusableItemLocator ()

context(@"when initialized with two views and then updated with one view removed", ^{
beforeEach(^{
OCMStub([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

viewRect1 = CGRectMake(101, 101, 50, 50);
UITextField *textField1 = [[UITextField alloc] initWithFrame:viewRect1];
[uiViewController.view addSubview:textField1];
Expand All @@ -291,8 +335,6 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have one view", ^{
OCMVerify(sdlLifecycleManager);

int expectedCount = 1;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));

Expand All @@ -308,6 +350,14 @@ @interface SDLFocusableItemLocator ()

context(@"when initialized with one view and notified after adding one more view", ^{
beforeEach(^{
OCMStub([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

viewRect1 = CGRectMake(101, 101, 50, 50);
UITextField *textField1 = [[UITextField alloc] initWithFrame:viewRect1];
[uiViewController.view addSubview:textField1];
Expand All @@ -324,8 +374,6 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have two views", ^{
OCMVerify(sdlLifecycleManager);

int expectedCount = 2;
expect(sentHapticRequest.hapticRectData.count).toEventually(equal(expectedCount));

Expand Down Expand Up @@ -422,7 +470,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have sent one view that has been scaled", ^{
OCMVerify(sdlLifecycleManager);
OCMVerify([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

int expectedCount = 1;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));
Expand All @@ -445,7 +499,13 @@ @interface SDLFocusableItemLocator ()
});

it(@"should have sent one view that has not been scaled", ^{
OCMVerify(sdlLifecycleManager);
OCMVerify([sdlLifecycleManager sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){
BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]];
if(isFirstArg) {
sentHapticRequest = value;
}
return YES;
}] withResponseHandler:[OCMArg any]]);

int expectedCount = 1;
expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount));
Expand Down

0 comments on commit 2ff8972

Please sign in to comment.