From 6ba82a8aa964a64818e728adeba042e493734b09 Mon Sep 17 00:00:00 2001 From: NicoleYarroch Date: Fri, 4 Jun 2021 08:09:48 -0400 Subject: [PATCH] Added shutdown tests Signed-off-by: NicoleYarroch --- SmartDeviceLink/private/SDLChoiceSetManager.m | 4 +++- .../DevAPISpecs/SDLChoiceSetManagerSpec.m | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/SmartDeviceLink/private/SDLChoiceSetManager.m b/SmartDeviceLink/private/SDLChoiceSetManager.m index b9ad3132d..110a594f2 100644 --- a/SmartDeviceLink/private/SDLChoiceSetManager.m +++ b/SmartDeviceLink/private/SDLChoiceSetManager.m @@ -406,10 +406,12 @@ - (void)presentChoiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode if ([strongSelf.currentState isEqualToString:SDLChoiceManagerStateShutdown]) { SDLLogD(@"Cancelling presenting choices because the manager has shut down"); + strongSelf.pendingPresentOperation = nil; + strongSelf.pendingPresentationSet = nil; return; } - // The cells necessary for this presentation are now preloaded, so we will enqueue a presentation + // The cells necessary for this presentation are now preloaded, so we will enqueue a presentation [strongSelf sdl_presentChoiceSetWithMode:mode keyboardDelegate:delegate]; }]; } diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m index 7359653dc..100a82b0a 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m @@ -749,6 +749,24 @@ - (void)sdl_addUniqueNamesToCells:(NSMutableSet *)choices; expect(testManager.pendingMutablePreloadChoices).to(beEmpty()); }); + it(@"should not present choices if the manager shuts down after the choices are uploaded but before presentation", ^{ + OCMExpect([strickMockOperationQueue addOperation:[OCMArg checkWithBlock:^BOOL(id value) { + SDLPreloadChoicesOperation *preloadChoicesOperation = (SDLPreloadChoicesOperation *)value; + expect(testManager.pendingPresentationSet).to(equal(testChoiceSet)); + [preloadChoicesOperation finishOperation]; + [testManager.stateMachine setToState:SDLChoiceManagerStateShutdown fromOldState:nil callEnterTransition:NO]; + return [value isKindOfClass:[SDLPreloadChoicesOperation class]]; + }]]); + OCMReject([strickMockOperationQueue addOperation:[OCMArg isKindOfClass:SDLPresentChoiceSetOperation.class]]); + + [testManager presentChoiceSet:testChoiceSet mode:testMode withKeyboardDelegate:nil]; + + OCMVerifyAllWithDelay(strickMockOperationQueue, 0.5); + + expect(testManager.pendingPresentOperation).to(beNil()); + expect(testManager.pendingPresentationSet).to(beNil()); + }); + context(@"non-searchable", ^{ it(@"should notify the choice delegate when a choice item is selected", ^{ OCMExpect([strickMockOperationQueue addOperation:[OCMArg checkWithBlock:^BOOL(id value) {