Skip to content

Commit

Permalink
Added shutdown tests
Browse files Browse the repository at this point in the history
Signed-off-by: NicoleYarroch <[email protected]>
  • Loading branch information
NicoleYarroch committed Jun 4, 2021
1 parent ae58436 commit 6ba82a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion SmartDeviceLink/private/SDLChoiceSetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}];
}
Expand Down
18 changes: 18 additions & 0 deletions SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,24 @@ - (void)sdl_addUniqueNamesToCells:(NSMutableSet<SDLChoiceCell *> *)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) {
Expand Down

0 comments on commit 6ba82a8

Please sign in to comment.