summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuller, Alexander (A.) <amulle19@ford.com>2017-01-25 12:27:15 -0800
committerMuller, Alexander (A.) <amulle19@ford.com>2017-01-25 12:27:15 -0800
commit65b04fbec044924f32a2fbe5faf69bb460b26fa7 (patch)
tree4ef04cfcdbc161b103a811f79110a9e4608c5cb6
parent782fe40e9e044bfbd6ee15af97a6cf867c664b33 (diff)
parent21cc10ffeed809384bb6aa8f88f3e7d20b7dcc4e (diff)
downloadsdl_ios-65b04fbec044924f32a2fbe5faf69bb460b26fa7.tar.gz
Merge remote-tracking branch 'origin/master' into hotfix/issue_509_stop_proxy
* origin/master: Revert "Updated SDLManagerError enum to include a warning case." Updated SDLManagerError enum to include a warning case. Fixed issue with test case not passing. Update with changes to make registration handling testable Actual failure in registration now calls the readyHandler Fixed issue relating to getting unhandled warnings from RAI Response. # Conflicts: # SmartDeviceLink/SDLLifecycleManager.m # SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
-rw-r--r--SmartDeviceLink/SDLLifecycleManager.h8
-rw-r--r--SmartDeviceLink/SDLLifecycleManager.m36
-rw-r--r--SmartDeviceLink/SDLStateMachine.h2
-rw-r--r--SmartDeviceLink/SDLStateMachine.m19
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m47
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m1
6 files changed, 71 insertions, 42 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.h b/SmartDeviceLink/SDLLifecycleManager.h
index a761ba63c..71fb00b36 100644
--- a/SmartDeviceLink/SDLLifecycleManager.h
+++ b/SmartDeviceLink/SDLLifecycleManager.h
@@ -67,13 +67,13 @@ typedef void (^SDLManagerReadyBlock)(BOOL success, NSError *_Nullable error);
// Deprecated internal proxy object
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-@property (strong, nonatomic, readonly, nullable) SDLProxy *proxy;
+@property (strong, nonatomic, nullable) SDLProxy *proxy;
#pragma clang diagnostic pop
-@property (assign, nonatomic, readonly) UInt16 lastCorrelationId;
+@property (assign, nonatomic) UInt16 lastCorrelationId;
@property (copy, nonatomic, readonly) SDLLifecycleState *lifecycleState;
-@property (copy, nonatomic, readonly, nullable) SDLHMILevel *hmiLevel;
-@property (strong, nonatomic, readonly, nullable) SDLRegisterAppInterfaceResponse *registerResponse;
+@property (copy, nonatomic, nullable) SDLHMILevel *hmiLevel;
+@property (strong, nonatomic, nullable) SDLRegisterAppInterfaceResponse *registerResponse;
#pragma mark Lifecycle
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m
index 66e6a10a2..fa617f64e 100644
--- a/SmartDeviceLink/SDLLifecycleManager.m
+++ b/SmartDeviceLink/SDLLifecycleManager.m
@@ -58,21 +58,12 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready";
@interface SDLLifecycleManager () <SDLConnectionManagerType>
// Readonly public properties
-@property (copy, nonatomic, readwrite, nullable) SDLHMILevel *hmiLevel;
@property (copy, nonatomic, readwrite) SDLConfiguration *configuration;
-@property (assign, nonatomic, readwrite) UInt16 lastCorrelationId;
-@property (strong, nonatomic, readwrite, nullable) SDLRegisterAppInterfaceResponse *registerResponse;
@property (strong, nonatomic, readwrite) SDLNotificationDispatcher *notificationDispatcher;
@property (strong, nonatomic, readwrite) SDLResponseDispatcher *responseDispatcher;
@property (strong, nonatomic, readwrite) SDLStateMachine *lifecycleStateMachine;
@property (assign, nonatomic, readwrite, getter=shouldRestartProxy) BOOL restartProxy;
-// Deprecated internal proxy object
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-@property (strong, nonatomic, readwrite, nullable) SDLProxy *proxy;
-#pragma clang diagnostic pop
-
// Private properties
@property (copy, nonatomic) SDLManagerReadyBlock readyHandler;
@@ -215,8 +206,10 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready";
__weak typeof(self) weakSelf = self;
[self sdl_sendRequest:regRequest
withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) {
+ // If the success BOOL is NO or we received an error at this point, we failed. Call the ready handler and transition to the DISCONNECTED state.
if (error != nil || ![response.success boolValue]) {
[SDLDebugTool logFormat:@"Failed to register the app. Error: %@, Response: %@", error, response];
+ weakSelf.readyHandler(NO, error);
[weakSelf.lifecycleStateMachine transitionToState:SDLLifecycleStateStopped];
return;
}
@@ -276,32 +269,15 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready";
- (void)didEnterStateReady {
SDLResult *registerResult = self.registerResponse.resultCode;
NSString *registerInfo = self.registerResponse.info;
-
- BOOL success = NO;
NSError *startError = nil;
-
- if ([registerResult isEqualToEnum:[SDLResult WARNINGS]] || [registerResult isEqualToEnum:[SDLResult RESUME_FAILED]]) {
- // We succeeded, but with warnings
+ // If the resultCode isn't success, we got a warning. Errors were handled in `didEnterStateConnected`.
+ if (![registerResult isEqualToEnum:[SDLResult SUCCESS]]) {
startError = [NSError sdl_lifecycle_startedWithBadResult:registerResult info:registerInfo];
- success = YES;
- } else if (![registerResult isEqualToEnum:[SDLResult SUCCESS]]) {
- // We did not succeed in registering
- startError = [NSError sdl_lifecycle_failedWithBadResult:registerResult info:registerInfo];
- success = NO;
- } else {
- // We succeeded
- success = YES;
- }
-
- // Notify the block, send the notification if we succeeded.
- self.readyHandler(success, startError);
-
- if (!success) {
- [self.lifecycleStateMachine transitionToState:SDLLifecycleStateReady];
- return;
}
+ // If we got to this point, we succeeded, send the error if there was a warning.
+ self.readyHandler(YES, startError);
[self.notificationDispatcher postNotificationName:SDLDidBecomeReady infoObject:nil];
// Send the hmi level going from NONE to whatever we're at now (could still be NONE)
diff --git a/SmartDeviceLink/SDLStateMachine.h b/SmartDeviceLink/SDLStateMachine.h
index 3690261f9..fa3b3093b 100644
--- a/SmartDeviceLink/SDLStateMachine.h
+++ b/SmartDeviceLink/SDLStateMachine.h
@@ -88,7 +88,7 @@ extern SDLStateMachineTransitionFormat const SDLStateMachineTransitionFormatDidE
*
* @param state The state to set to
*/
-- (void)setToState:(SDLState *)state;
+- (void)setToState:(SDLState *)state fromOldState:(nullable SDLState *)oldState callEnterTransition:(BOOL)shouldCall;
/**
* Return whether or not the current state is the passed state
diff --git a/SmartDeviceLink/SDLStateMachine.m b/SmartDeviceLink/SDLStateMachine.m
index 126f0e55b..ab5c54689 100644
--- a/SmartDeviceLink/SDLStateMachine.m
+++ b/SmartDeviceLink/SDLStateMachine.m
@@ -109,12 +109,25 @@ SDLStateMachineTransitionFormat const SDLStateMachineTransitionFormatDidEnter =
#pragma mark - Helpers
-- (void)setToState:(SDLState *)state {
+- (void)setToState:(SDLState *)state fromOldState:(nullable SDLState *)oldState callEnterTransition:(BOOL)shouldCall {
if (![self.states.allKeys containsObject:state]) {
return;
}
- self.currentState = state;
+ if (oldState != nil && shouldCall) {
+ self.currentState = oldState;
+ [self transitionToState:state];
+ } else if (shouldCall) {
+ SEL didEnter = NSSelectorFromString([NSString stringWithFormat:SDLStateMachineTransitionFormatDidEnter, state]);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+ if ([self.target respondsToSelector:didEnter]) {
+ [self.target performSelector:didEnter];
+#pragma clang diagnostic pop
+ }
+ } else {
+ self.currentState = state;
+ }
}
/**
@@ -139,4 +152,4 @@ SDLStateMachineTransitionFormat const SDLStateMachineTransitionFormatDidEnter =
@end
-NS_ASSUME_NONNULL_END \ No newline at end of file
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
index 58dd68ad1..eb685441e 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
@@ -21,6 +21,7 @@
#import "SDLProxyFactory.h"
#import "SDLRegisterAppInterface.h"
#import "SDLRegisterAppInterfaceResponse.h"
+#import "SDLResult.h"
#import "SDLShow.h"
#import "SDLStateMachine.h"
#import "SDLTextAlignment.h"
@@ -157,8 +158,17 @@ describe(@"a lifecycle manager", ^{
});
describe(@"when started", ^{
+ __block BOOL readyHandlerSuccess = NO;
+ __block NSError *readyHandlerError = nil;
+
beforeEach(^{
- [testManager startWithReadyHandler:^(BOOL success, NSError * _Nullable error) {}];
+ readyHandlerSuccess = NO;
+ readyHandlerError = nil;
+
+ [testManager startWithReadyHandler:^(BOOL success, NSError * _Nullable error) {
+ readyHandlerSuccess = success;
+ readyHandlerError = error;
+ }];
});
it(@"should initialize the proxy property", ^{
@@ -206,7 +216,7 @@ describe(@"a lifecycle manager", ^{
describe(@"in the connected state", ^{
beforeEach(^{
- [testManager.lifecycleStateMachine setToState:SDLLifecycleStateConnected];
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateConnected fromOldState:nil callEnterTransition:NO];
});
describe(@"after receiving a register app interface response", ^{
@@ -253,10 +263,41 @@ describe(@"a lifecycle manager", ^{
});
});
});
+
+ describe(@"transitioning to the ready state", ^{
+ context(@"when the register response is a success", ^{
+ it(@"should call the ready handler with success", ^{
+ SDLRegisterAppInterfaceResponse *response = [[SDLRegisterAppInterfaceResponse alloc] init];
+ response.resultCode = [SDLResult SUCCESS];
+ testManager.registerResponse = response;
+
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady fromOldState:nil callEnterTransition:YES];
+
+ expect(@(readyHandlerSuccess)).to(equal(@YES));
+ expect(readyHandlerError).to(beNil());
+ });
+ });
+
+ context(@"when the register response is a warning", ^{
+ it(@"should call the ready handler with success but error", ^{
+ SDLRegisterAppInterfaceResponse *response = [[SDLRegisterAppInterfaceResponse alloc] init];
+ response.resultCode = [SDLResult WARNINGS];
+ response.info = @"some info";
+ testManager.registerResponse = response;
+
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady fromOldState:nil callEnterTransition:YES];
+
+ expect(@(readyHandlerSuccess)).to(equal(@YES));
+ expect(readyHandlerError).toNot(beNil());
+ expect(@(readyHandlerError.code)).to(equal(@(SDLManagerErrorRegistrationFailed)));
+ expect(readyHandlerError.userInfo[NSLocalizedFailureReasonErrorKey]).to(match(response.info));
+ });
+ });
+ });
describe(@"in the ready state", ^{
beforeEach(^{
- [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady];
+ [testManager.lifecycleStateMachine setToState:SDLLifecycleStateReady fromOldState:nil callEnterTransition:NO];
});
it(@"can send an RPC", ^{
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m
index b5d2bfcf4..15371a53b 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m
@@ -142,7 +142,6 @@ describe(@"Upload File Operation", ^{
it(@"should send correct putfiles", ^{
NSArray<SDLPutFile *> *putFiles = testConnectionManager.receivedRequests;
- SDLPutFile *firstPutFile = putFiles.firstObject;
NSUInteger numberOfPutFiles = (((testFileData.length - 1) / [SDLGlobals globals].maxMTUSize) + 1);
expect(@(putFiles.count)).to(equal(@(numberOfPutFiles)));