From f6b53b76b9a4eb3a50bb3853b2a7cdd9f60ac17b Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Wed, 8 Jan 2020 13:58:13 -0500 Subject: [PATCH 1/2] Fix issues shown by OCMock 3.5 --- .../DevAPISpecs/SDLChoiceSetManagerSpec.m | 8 +- .../ProxySpecs/SDLHapticManagerSpec.m | 106 ++++++++++++++---- 2 files changed, 84 insertions(+), 30 deletions(-) diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m index 71d74c5bc..1d72c106f 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m @@ -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]; @@ -232,11 +231,6 @@ @interface SDLChoiceSetManager() }); it(@"should properly start the deletion", ^{ - OCMStub([pendingPreloadOp removeChoicesFromUpload:[OCMArg checkWithBlock:^BOOL(id obj) { - NSArray *choices = (NSArray *)obj; - return (choices.count == 1) && ([choices.firstObject isEqual:testCell1]); - }]]); - expect(testManager.pendingPreloadChoices).to(beEmpty()); expect(testManager.transactionQueue.operationCount).to(equal(1)); // No delete operation }); diff --git a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m index efa067b5c..fb7d456a0 100644 --- a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m +++ b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m @@ -44,14 +44,14 @@ @interface SDLFocusableItemLocator () QuickSpecBegin(SDLHapticManagerSpec) -describe(@"the haptic manager", ^{ +fdescribe(@"the haptic manager", ^{ __block UIWindow *uiWindow; __block UIViewController *uiViewController; __block SDLFocusableItemLocator *hapticManager; __block SDLSendHapticData* sentHapticRequest; - __block id sdlLifecycleManager = OCMClassMock([SDLLifecycleManager class]); + __block id sdlLifecycleManager = nil; __block SDLStreamingVideoScaleManager *sdlStreamingVideoScaleManager = nil; __block CGRect viewRect1; __block CGRect viewRect2; @@ -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", ^{ @@ -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()); }); @@ -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)); }); }); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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]; @@ -291,8 +335,6 @@ @interface SDLFocusableItemLocator () }); it(@"should have one view", ^{ - OCMVerify(sdlLifecycleManager); - int expectedCount = 1; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); @@ -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]; @@ -324,8 +374,6 @@ @interface SDLFocusableItemLocator () }); it(@"should have two views", ^{ - OCMVerify(sdlLifecycleManager); - int expectedCount = 2; expect(sentHapticRequest.hapticRectData.count).toEventually(equal(expectedCount)); @@ -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)); @@ -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)); From a1dd7d8548b854e102844b6d94e317c891021e2a Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Wed, 8 Jan 2020 14:55:05 -0500 Subject: [PATCH 2/2] Remove focus from test --- SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m index fb7d456a0..77a658a86 100644 --- a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m +++ b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m @@ -44,7 +44,7 @@ @interface SDLFocusableItemLocator () QuickSpecBegin(SDLHapticManagerSpec) -fdescribe(@"the haptic manager", ^{ +describe(@"the haptic manager", ^{ __block UIWindow *uiWindow; __block UIViewController *uiViewController;