summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2020-11-13 14:37:52 -0500
committerJoel Fischer <joeljfischer@gmail.com>2020-11-13 14:37:52 -0500
commit9524fbe6c6317084a6d2e0fb811327f4735ab05f (patch)
tree21a541d6e8c3dab0891d769edc6c4229e3e3a47c
parent154d8a467f464abad8ea2af0c10f2e6dfd4aed37 (diff)
downloadsdl_ios-9524fbe6c6317084a6d2e0fb811327f4735ab05f.tar.gz
Fixes and updates for VCUO and tests
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj6
-rw-r--r--SmartDeviceLink/SDLVoiceCommandUpdateOperation.m4
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleMobileHMIStateHandlerSpec.m2
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLVoiceCommandOperationSpec.m12
-rw-r--r--SmartDeviceLinkTests/TestConnectionRequestObject.h23
-rw-r--r--SmartDeviceLinkTests/TestConnectionRequestObject.m23
-rw-r--r--SmartDeviceLinkTests/TestUtilities/TestConnectionManager.h8
-rw-r--r--SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m33
8 files changed, 85 insertions, 26 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index ad8a675d3..c8c83935a 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -296,6 +296,7 @@
4A402561250134CB0080E159 /* SDLStabilityControlsStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A40255F250134CA0080E159 /* SDLStabilityControlsStatus.h */; settings = {ATTRIBUTES = (Public, ); }; };
4A404C66250BBE11003AB65D /* SDLTextAndGraphicUpdateOperationSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A404C65250BBE11003AB65D /* SDLTextAndGraphicUpdateOperationSpec.m */; };
4A404C68250BBE2B003AB65D /* SDLTextAndGraphicStateSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A404C67250BBE2B003AB65D /* SDLTextAndGraphicStateSpec.m */; };
+ 4A41430D255F0A090039C267 /* TestConnectionRequestObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A41430C255F0A090039C267 /* TestConnectionRequestObject.m */; };
4A457DC324A2933E00386CBA /* SDLLifecycleRPCAdapterSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A457DC224A2933E00386CBA /* SDLLifecycleRPCAdapterSpec.m */; };
4A457DD324A3886700386CBA /* SDLLifecycleSyncPDataHandlerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A457DD224A3886700386CBA /* SDLLifecycleSyncPDataHandlerSpec.m */; };
4A457DD524A3C16E00386CBA /* SDLLifecycleMobileHMIStateHandlerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A457DD424A3C16E00386CBA /* SDLLifecycleMobileHMIStateHandlerSpec.m */; };
@@ -2076,6 +2077,8 @@
4A40255F250134CA0080E159 /* SDLStabilityControlsStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDLStabilityControlsStatus.h; path = public/SDLStabilityControlsStatus.h; sourceTree = "<group>"; };
4A404C65250BBE11003AB65D /* SDLTextAndGraphicUpdateOperationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLTextAndGraphicUpdateOperationSpec.m; path = DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m; sourceTree = "<group>"; };
4A404C67250BBE2B003AB65D /* SDLTextAndGraphicStateSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDLTextAndGraphicStateSpec.m; path = DevAPISpecs/SDLTextAndGraphicStateSpec.m; sourceTree = "<group>"; };
+ 4A41430B255F0A090039C267 /* TestConnectionRequestObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestConnectionRequestObject.h; sourceTree = "<group>"; };
+ 4A41430C255F0A090039C267 /* TestConnectionRequestObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestConnectionRequestObject.m; sourceTree = "<group>"; };
4A457DC224A2933E00386CBA /* SDLLifecycleRPCAdapterSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDLLifecycleRPCAdapterSpec.m; path = DevAPISpecs/SDLLifecycleRPCAdapterSpec.m; sourceTree = "<group>"; };
4A457DD224A3886700386CBA /* SDLLifecycleSyncPDataHandlerSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDLLifecycleSyncPDataHandlerSpec.m; path = DevAPISpecs/SDLLifecycleSyncPDataHandlerSpec.m; sourceTree = "<group>"; };
4A457DD424A3C16E00386CBA /* SDLLifecycleMobileHMIStateHandlerSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDLLifecycleMobileHMIStateHandlerSpec.m; path = DevAPISpecs/SDLLifecycleMobileHMIStateHandlerSpec.m; sourceTree = "<group>"; };
@@ -6204,6 +6207,8 @@
8850DB5F1F4475D30053A48D /* TestMultipleFilesConnectionManager.m */,
5D6035D3202CE4A500A429C9 /* TestMultipleRequestsConnectionManager.h */,
5D6035D4202CE4A500A429C9 /* TestMultipleRequestsConnectionManager.m */,
+ 4A41430B255F0A090039C267 /* TestConnectionRequestObject.h */,
+ 4A41430C255F0A090039C267 /* TestConnectionRequestObject.m */,
);
name = "Connection Manager";
sourceTree = "<group>";
@@ -8353,6 +8358,7 @@
162E83181A9BDE8B00906325 /* SDLOnKeyboardInputSpec.m in Sources */,
1EE8C4441F34A1B900FDC2CF /* SDLClimateControlDataSpec.m in Sources */,
162E83701A9BDE8B00906325 /* SDLUpdateTurnListResponseSpec.m in Sources */,
+ 4A41430D255F0A090039C267 /* TestConnectionRequestObject.m in Sources */,
88C23E8822297C6000EA171F /* SDLRPCResponseNotificationSpec.m in Sources */,
162E833B1A9BDE8B00906325 /* SDLSetGlobalPropertiesSpec.m in Sources */,
884AF94C220B3FCC00E22928 /* SDLGetSystemCapabilitySpec.m in Sources */,
diff --git a/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m b/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m
index b4e61ecb2..9205ac830 100644
--- a/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m
+++ b/SmartDeviceLink/SDLVoiceCommandUpdateOperation.m
@@ -117,7 +117,7 @@ NS_ASSUME_NONNULL_BEGIN
if (error != nil) {
errors[request] = error;
} else {
- [weakSelf.currentVoiceCommands addObject:[weakSelf sdl_pendingVoiceCommandWithCommandId:((SDLDeleteCommand *)request).cmdID.unsignedIntValue]];
+ [weakSelf.currentVoiceCommands addObject:[weakSelf sdl_pendingVoiceCommandWithCommandId:((SDLAddCommand *)request).cmdID.unsignedIntValue]];
}
SDLLogV(@"Sending voice commands progress: %f", percentComplete);
@@ -173,7 +173,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (nullable SDLVoiceCommand *)sdl_pendingVoiceCommandWithCommandId:(UInt32)commandId {
- for (SDLVoiceCommand *voiceCommand in self.currentVoiceCommands) {
+ for (SDLVoiceCommand *voiceCommand in self.pendingVoiceCommands) {
if (voiceCommand.commandId == commandId) {
return voiceCommand;
}
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleMobileHMIStateHandlerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleMobileHMIStateHandlerSpec.m
index f2ff80c99..505edd4d5 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleMobileHMIStateHandlerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleMobileHMIStateHandlerSpec.m
@@ -71,7 +71,7 @@ describe(@"SDLLifecycleMobileHMIStateHandler tests", ^{
describe(@"after the manager is stopped", ^{
beforeEach(^{
- [mockConnectionManager.receivedRequests removeAllObjects];
+ [mockConnectionManager reset];
[testManager stop];
});
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLVoiceCommandOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLVoiceCommandOperationSpec.m
index a5186992d..016892053 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLVoiceCommandOperationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLVoiceCommandOperationSpec.m
@@ -71,7 +71,7 @@ describe(@"a voice command operation", ^{
// should have a priority of 'normal'
it(@"should have a priority of 'normal'", ^{
- testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager newVoiceCommands:@[] oldVoiceCommands:@[] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
+ testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager pendingVoiceCommands:@[] oldVoiceCommands:@[] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
}];
expect(@(testOp.queuePriority)).to(equal(@(NSOperationQueuePriorityNormal)));
@@ -79,9 +79,9 @@ describe(@"a voice command operation", ^{
// initializing the operation
describe(@"initializing the operation", ^{
- testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager newVoiceCommands:@[newVoiceCommand1, newVoiceCommand2] oldVoiceCommands:@[oldVoiceCommand1, oldVoiceCommand2] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {}];
+ testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager pendingVoiceCommands:@[newVoiceCommand1, newVoiceCommand2] oldVoiceCommands:@[oldVoiceCommand1, oldVoiceCommand2] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {}];
- expect(testOp.currentVoiceCommands).to(equal(@[oldVoiceCommand1, oldVoiceCommand2]));
+ expect(testOp.oldVoiceCommands).to(equal(@[oldVoiceCommand1, oldVoiceCommand2]));
});
// starting the operation
@@ -90,7 +90,7 @@ describe(@"a voice command operation", ^{
// if it starts cancelled
context(@"if it starts cancelled", ^{
beforeEach(^{
- testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager newVoiceCommands:@[newVoiceCommand1, newVoiceCommand2] oldVoiceCommands:@[oldVoiceCommand1, oldVoiceCommand2] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
+ testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager pendingVoiceCommands:@[newVoiceCommand1, newVoiceCommand2] oldVoiceCommands:@[oldVoiceCommand1, oldVoiceCommand2] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
callbackCurrentVoiceCommands = newCurrentVoiceCommands;
callbackError = error;
}];
@@ -106,7 +106,7 @@ describe(@"a voice command operation", ^{
// if it has voice commands to delete
context(@"if it has voice commands to delete", ^{
beforeEach(^{
- testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager newVoiceCommands:@[] oldVoiceCommands:@[oldVoiceCommand1, oldVoiceCommand2] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
+ testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager pendingVoiceCommands:@[] oldVoiceCommands:@[oldVoiceCommand1, oldVoiceCommand2] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
callbackCurrentVoiceCommands = newCurrentVoiceCommands;
callbackError = error;
}];
@@ -169,7 +169,7 @@ describe(@"a voice command operation", ^{
context(@"if it doesn't have any voice commands to delete", ^{
beforeEach(^{
- testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager newVoiceCommands:@[newVoiceCommand1, newVoiceCommand2] oldVoiceCommands:@[] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
+ testOp = [[SDLVoiceCommandUpdateOperation alloc] initWithConnectionManager:testConnectionManager pendingVoiceCommands:@[newVoiceCommand1, newVoiceCommand2] oldVoiceCommands:@[] updateCompletionHandler:^(NSArray<SDLVoiceCommand *> * _Nonnull newCurrentVoiceCommands, NSError * _Nullable error) {
callbackCurrentVoiceCommands = newCurrentVoiceCommands;
callbackError = error;
}];
diff --git a/SmartDeviceLinkTests/TestConnectionRequestObject.h b/SmartDeviceLinkTests/TestConnectionRequestObject.h
new file mode 100644
index 000000000..4bc6b5098
--- /dev/null
+++ b/SmartDeviceLinkTests/TestConnectionRequestObject.h
@@ -0,0 +1,23 @@
+//
+// TestConnectionRequestObject.h
+// SmartDeviceLinkTests
+//
+// Created by Joel Fischer on 11/13/20.
+// Copyright © 2020 smartdevicelink. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <SmartDeviceLink/SmartDeviceLink.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TestConnectionRequestObject : NSObject
+
+@property (strong, nonatomic) __kindof SDLRPCMessage *message;
+@property (copy, nonatomic, nullable) SDLResponseHandler responseHandler;
+
+- (instancetype)initWithMessage:(__kindof SDLRPCMessage *)message responseHandler:(nullable SDLResponseHandler)handler;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLinkTests/TestConnectionRequestObject.m b/SmartDeviceLinkTests/TestConnectionRequestObject.m
new file mode 100644
index 000000000..a1aa57bc4
--- /dev/null
+++ b/SmartDeviceLinkTests/TestConnectionRequestObject.m
@@ -0,0 +1,23 @@
+//
+// TestConnectionRequestObject.m
+// SmartDeviceLinkTests
+//
+// Created by Joel Fischer on 11/13/20.
+// Copyright © 2020 smartdevicelink. All rights reserved.
+//
+
+#import "TestConnectionRequestObject.h"
+
+@implementation TestConnectionRequestObject
+
+- (instancetype)initWithMessage:(__kindof SDLRPCMessage *)message responseHandler:(SDLResponseHandler)handler {
+ self = [super init];
+ if (!self) { return nil; }
+
+ _message = message;
+ _responseHandler = handler;
+
+ return self;
+}
+
+@end
diff --git a/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.h b/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.h
index 5b07db771..d3dd50a19 100644
--- a/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.h
+++ b/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.h
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "SDLConnectionManagerType.h"
#import "SDLNotificationConstants.h"
+#import "TestConnectionRequestObject.h"
NS_ASSUME_NONNULL_BEGIN
@@ -20,12 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
/**
* All received requests. Chronological order. The 0th element will be the first request received; the nth request will be the n+1th request received.
*/
-@property (copy, nonatomic, readonly) NSMutableArray<__kindof SDLRPCMessage *> *receivedRequests;
+@property (copy, nonatomic, readonly) NSMutableArray<__kindof TestConnectionRequestObject *> *receivedRequestObjects;
-/**
- * The block passed for the last request send with sendRequest:withCompletionHandler:
- */
-@property (copy, nonatomic, nullable) SDLResponseHandler lastRequestBlock;
+@property (copy, nonatomic, readonly) NSArray<__kindof SDLRPCMessage *> *receivedRequests;
@property (copy, nonatomic, nullable) NSMutableArray<SDLMultipleRequestCompletionHandler> *multipleCompletionBlocks;
diff --git a/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m b/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m
index 03b7398c2..4774f8d09 100644
--- a/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m
+++ b/SmartDeviceLinkTests/TestUtilities/TestConnectionManager.m
@@ -21,21 +21,28 @@ NS_ASSUME_NONNULL_BEGIN
return nil;
}
- _receivedRequests = [NSMutableArray<__kindof SDLRPCMessage *> array];
+ _receivedRequestObjects = [NSMutableArray<TestConnectionRequestObject *> array];
_multipleCompletionBlocks = [NSMutableArray array];
return self;
}
+- (NSArray<__kindof SDLRPCMessage *> *)receivedRequests {
+ NSMutableArray<__kindof SDLRPCMessage *> *requests = [NSMutableArray array];
+ [_receivedRequestObjects enumerateObjectsUsingBlock:^(__kindof TestConnectionRequestObject * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+ [requests addObject:obj.message];
+ }];
+
+ return [requests copy];
+}
+
- (void)sendConnectionRPC:(__kindof SDLRPCMessage *)rpc {
- [self.receivedRequests addObject:rpc];
+ [self.receivedRequestObjects addObject:[[TestConnectionRequestObject alloc] initWithMessage:rpc responseHandler:nil]];
}
- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler {
- self.lastRequestBlock = handler;
- SDLRPCRequest *requestRPC = (SDLRPCRequest *)request;
- requestRPC.correlationID = [self test_nextCorrelationID];
- [self.receivedRequests addObject:requestRPC];
+ request.correlationID = [self test_nextCorrelationID];
+ [self.receivedRequestObjects addObject:[[TestConnectionRequestObject alloc] initWithMessage:request responseHandler:handler]];
}
- (void)sendConnectionManagerRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler {
@@ -79,8 +86,9 @@ NS_ASSUME_NONNULL_BEGIN
thisError = error;
}
- if (self.lastRequestBlock != nil) {
- self.lastRequestBlock(self.receivedRequests.lastObject, response, thisError);
+ TestConnectionRequestObject *lastObject = self.receivedRequestObjects.lastObject;
+ if (lastObject.responseHandler != nil) {
+ lastObject.responseHandler((SDLRPCRequest *)lastObject.message, response, thisError);
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Attempted to respond to last request, but there was no last request block" userInfo:nil];
}
@@ -94,8 +102,9 @@ NS_ASSUME_NONNULL_BEGIN
thisError = error;
}
- if (self.lastRequestBlock != nil) {
- self.lastRequestBlock(self.receivedRequests[requestNumber], response, thisError);
+ TestConnectionRequestObject *requestObj = self.receivedRequestObjects[requestNumber];
+ if (requestObj.responseHandler != nil) {
+ requestObj.responseHandler((SDLRPCRequest *)requestObj.message, response, thisError);
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Attempted to respond to last request, but there was no last request block" userInfo:nil];
}
@@ -110,8 +119,8 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)reset {
- _receivedRequests = [NSMutableArray<__kindof SDLRPCMessage *> array];
- _lastRequestBlock = nil;
+ _receivedRequestObjects = [NSMutableArray<__kindof TestConnectionRequestObject *> array];
+ _multipleCompletionBlocks = [NSMutableArray array];
}