summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Elias <francois.elias@livio.io>2020-12-18 15:50:29 -0500
committerFrank Elias <francois.elias@livio.io>2020-12-18 15:50:29 -0500
commit651d4f7b071b919fdc54747e144c3ecccea20f25 (patch)
tree8a1444de58617c50d47f17a5c021bdc2eafd2893
parentad572b0bd5e18474a8177a772e54f220a1650062 (diff)
downloadsdl_ios-651d4f7b071b919fdc54747e144c3ecccea20f25.tar.gz
Fixes in the ChoiceSetManager
-rw-r--r--SmartDeviceLink/private/SDLChoiceSetManager.m33
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m14
2 files changed, 31 insertions, 16 deletions
diff --git a/SmartDeviceLink/private/SDLChoiceSetManager.m b/SmartDeviceLink/private/SDLChoiceSetManager.m
index 5923b988b..e0a03b11a 100644
--- a/SmartDeviceLink/private/SDLChoiceSetManager.m
+++ b/SmartDeviceLink/private/SDLChoiceSetManager.m
@@ -453,30 +453,30 @@ UInt16 const ChoiceCellCancelIdMin = 1;
/// @param choices The choices to be uploaded
/// @return The choices that have not yet been uploaded to the module
- (NSArray<SDLChoiceCell *> *)sdl_choicesToBeUploadedWithArray:(NSArray<SDLChoiceCell *> *)choices {
- NSMutableArray<SDLChoiceCell *> *choicesSet = [NSMutableSet setWithArray:choices];
- [choicesSet removeObjectsInArray:self.preloadedChoices];
+ NSMutableArray<SDLChoiceCell *> *choicesArray = [choices mutableCopy];
+ [choicesArray removeObjectsInArray:self.preloadedChoices];
- return [choicesSet copy];
+ return [choicesArray copy];
}
/// Checks the passed list of choices to be deleted and returns the items that have been uploaded to the module.
/// @param choices The choices to be deleted
/// @return The choices that have been uploaded to the module
- (NSArray<SDLChoiceCell *> *)sdl_choicesToBeDeletedWithArray:(NSArray<SDLChoiceCell *> *)choices {
- NSMutableSet<SDLChoiceCell *> *choicesSet = [NSMutableSet setWithArray:choices];
- [choicesSet intersectSet:self.preloadedChoices];
+ NSMutableArray<SDLChoiceCell *> *choicesArray;
+ choicesArray = [self intersectArray:choices secondArray:self.preloadedChoices];
- return [choicesSet copy];
+ return [choicesArray copy];
}
/// Checks the passed list of choices to be deleted and returns the items that are waiting to be uploaded to the module.
/// @param choices The choices to be deleted
/// @return The choices that are waiting to be uploaded to the module
- (NSArray<SDLChoiceCell *> *)sdl_choicesToBeRemovedFromPendingWithArray:(NSArray<SDLChoiceCell *> *)choices {
- NSMutableArray<SDLChoiceCell *> *choicesSet = [choices mutableCopy];
- [choicesSet addObjectsFromArray:self.pendingPreloadChoices];
+ NSMutableArray<SDLChoiceCell *> *choicesArray;
+ choicesArray = [self intersectArray:choices secondArray:self.pendingPreloadChoices];
- return [choicesSet copy];
+ return [choicesArray copy];
}
/// Assigns a unique id to each choice item.
@@ -508,6 +508,21 @@ UInt16 const ChoiceCellCancelIdMin = 1;
}
}
+/// Replaces intersectSet function found in NSMutableSet after refactoring from NSSet/NSMutableSet to NSArray/NSMutableArray
+- (nullable NSMutableArray<SDLChoiceCell *> *)intersectArray:(NSArray<SDLChoiceCell *> *)firstArray secondArray:(NSArray<SDLChoiceCell *> *)secondArray {
+ NSMutableArray <SDLChoiceCell *> *intersectedArray;
+ NSMutableDictionary<NSString *, SDLChoiceCell *> *dict;
+ for (SDLChoiceCell *cell in firstArray) {
+ [dict setObject:cell forKey:[NSString stringWithFormat:@"%d",cell.choiceId]];
+ }
+ for (SDLChoiceCell *cell in secondArray) {
+ if ([dict objectForKey:[NSString stringWithFormat:@"%d",cell.choiceId]]) {
+ [intersectedArray addObject:cell];
+ }
+ }
+ return intersectedArray;
+}
+
#pragma mark - Keyboard Configuration
- (void)setKeyboardConfiguration:(nullable SDLKeyboardProperties *)keyboardConfiguration {
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m
index 321a2dde6..3e4bac2ef 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetManagerSpec.m
@@ -53,9 +53,9 @@
@property (copy, nonatomic, nullable) SDLSystemContext currentSystemContext;
@property (copy, nonatomic, nullable) SDLWindowCapability *currentWindowCapability;
-@property (strong, nonatomic) NSMutableSet<SDLChoiceCell *> *preloadedMutableChoices;
-@property (strong, nonatomic, readonly) NSSet<SDLChoiceCell *> *pendingPreloadChoices;
-@property (strong, nonatomic) NSMutableSet<SDLChoiceCell *> *pendingMutablePreloadChoices;
+@property (strong, nonatomic) NSMutableArray<SDLChoiceCell *> *preloadedMutableChoices;
+@property (strong, nonatomic, readonly) NSArray<SDLChoiceCell *> *pendingPreloadChoices;
+@property (strong, nonatomic) NSMutableArray<SDLChoiceCell *> *pendingMutablePreloadChoices;
@property (strong, nonatomic, nullable) SDLChoiceSet *pendingPresentationSet;
@property (strong, nonatomic, nullable) SDLAsynchronousOperation *pendingPresentOperation;
@@ -281,7 +281,7 @@ describe(@"choice set manager tests", ^{
context(@"when the manager shuts down during preloading", ^{
beforeEach(^{
- testManager.pendingMutablePreloadChoices = [NSMutableSet setWithArray:@[testCell1]];
+ testManager.pendingMutablePreloadChoices = [NSMutableArray setWithArray:@[testCell1]];
[testManager preloadChoices:@[testCell1, testCell2, testCell3] withCompletionHandler:^(NSError * _Nullable error) {
}];
@@ -294,8 +294,8 @@ describe(@"choice set manager tests", ^{
expect(testManager.transactionQueue.operations.firstObject).to(beAnInstanceOf([SDLPreloadChoicesOperation class]));
[testManager.stateMachine setToState:SDLChoiceManagerStateShutdown fromOldState:nil callEnterTransition:NO];
- testManager.pendingMutablePreloadChoices = [NSMutableSet set];
- testManager.preloadedMutableChoices = [NSMutableSet set];
+ testManager.pendingMutablePreloadChoices = [NSMutableArray array];
+ testManager.preloadedMutableChoices = [NSMutableArray array];
SDLPreloadChoicesOperation *testOp = testManager.transactionQueue.operations.firstObject;
testOp.completionBlock();
@@ -316,7 +316,7 @@ describe(@"choice set manager tests", ^{
beforeEach(^{
choiceDelegate = OCMProtocolMock(@protocol(SDLChoiceSetDelegate));
pendingPresentOp = OCMClassMock([SDLPresentChoiceSetOperation class]);
- OCMStub(pendingPresentOp.choiceSet.choices).andReturn([NSSet setWithArray:@[testCell1]]);
+ OCMStub(pendingPresentOp.choiceSet.choices).andReturn([NSArray setWithArray:@[testCell1]]);
testManager.pendingPresentOperation = pendingPresentOp;
testManager.pendingPresentationSet = [[SDLChoiceSet alloc] initWithTitle:@"Test" delegate:choiceDelegate choices:@[testCell1]];