summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2018-09-07 10:50:26 -0400
committerJoel Fischer <joeljfischer@gmail.com>2018-09-07 10:50:26 -0400
commit74f822f27e1796163929d7323c674451477dd322 (patch)
tree2e7c1fa4badd784225135836837f8d563c3ed3cf
parent22d009abac60ae545c2c90a2c8eef7335073ca10 (diff)
downloadsdl_ios-74f822f27e1796163929d7323c674451477dd322.tar.gz
Update for space available being optional in error cases
-rw-r--r--SmartDeviceLink/SDLDeleteFileOperation.m29
-rw-r--r--SmartDeviceLink/SDLDeleteFileResponse.h2
-rw-r--r--SmartDeviceLink/SDLDeleteFileResponse.m4
-rw-r--r--SmartDeviceLink/SDLFileManager.m10
-rw-r--r--SmartDeviceLink/SDLListFilesOperation.m27
-rw-r--r--SmartDeviceLink/SDLListFilesResponse.h2
-rw-r--r--SmartDeviceLink/SDLListFilesResponse.m4
-rw-r--r--SmartDeviceLink/SDLPutFileResponse.h2
-rw-r--r--SmartDeviceLink/SDLPutFileResponse.m4
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.m7
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m75
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m4
12 files changed, 114 insertions, 56 deletions
diff --git a/SmartDeviceLink/SDLDeleteFileOperation.m b/SmartDeviceLink/SDLDeleteFileOperation.m
index f45f3cbdd..4d974a2ad 100644
--- a/SmartDeviceLink/SDLDeleteFileOperation.m
+++ b/SmartDeviceLink/SDLDeleteFileOperation.m
@@ -48,20 +48,21 @@ NS_ASSUME_NONNULL_BEGIN
SDLDeleteFile *deleteFile = [[SDLDeleteFile alloc] initWithFileName:self.fileName];
typeof(self) weakself = self;
- [self.connectionManager sendConnectionManagerRequest:deleteFile
- withResponseHandler:^(__kindof SDLRPCRequest *request, __kindof SDLRPCResponse *response, NSError *error) {
- // Pull out the parameters
- SDLDeleteFileResponse *deleteFileResponse = (SDLDeleteFileResponse *)response;
- BOOL success = [deleteFileResponse.success boolValue];
- NSUInteger bytesAvailable = [deleteFileResponse.spaceAvailable unsignedIntegerValue];
-
- // Callback
- if (weakself.completionHandler != nil) {
- weakself.completionHandler(success, bytesAvailable, error);
- }
-
- [weakself finishOperation];
- }];
+ [self.connectionManager sendConnectionManagerRequest:deleteFile withResponseHandler:^(__kindof SDLRPCRequest *request, __kindof SDLRPCResponse *response, NSError *error) {
+ // Pull out the parameters
+ SDLDeleteFileResponse *deleteFileResponse = (SDLDeleteFileResponse *)response;
+ BOOL success = [deleteFileResponse.success boolValue];
+
+ // If spaceAvailable is nil, set it to the max value
+ NSUInteger bytesAvailable = deleteFileResponse.spaceAvailable != nil ? deleteFileResponse.spaceAvailable.unsignedIntegerValue : 2000000000;
+
+ // Callback
+ if (weakself.completionHandler != nil) {
+ weakself.completionHandler(success, bytesAvailable, error);
+ }
+
+ [weakself finishOperation];
+ }];
}
diff --git a/SmartDeviceLink/SDLDeleteFileResponse.h b/SmartDeviceLink/SDLDeleteFileResponse.h
index 8c3fc4fc5..c639dcdd7 100644
--- a/SmartDeviceLink/SDLDeleteFileResponse.h
+++ b/SmartDeviceLink/SDLDeleteFileResponse.h
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
The remaining available space for your application to store data on the remote system.
*/
-@property (strong, nonatomic) NSNumber<SDLInt> *spaceAvailable;
+@property (nullable, strong, nonatomic) NSNumber<SDLInt> *spaceAvailable;
@end
diff --git a/SmartDeviceLink/SDLDeleteFileResponse.m b/SmartDeviceLink/SDLDeleteFileResponse.m
index 5c54b9852..42689fafe 100644
--- a/SmartDeviceLink/SDLDeleteFileResponse.m
+++ b/SmartDeviceLink/SDLDeleteFileResponse.m
@@ -17,11 +17,11 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (void)setSpaceAvailable:(NSNumber<SDLInt> *)spaceAvailable {
+- (void)setSpaceAvailable:(nullable NSNumber<SDLInt> *)spaceAvailable {
[parameters sdl_setObject:spaceAvailable forName:SDLNameSpaceAvailable];
}
-- (NSNumber<SDLInt> *)spaceAvailable {
+- (nullable NSNumber<SDLInt> *)spaceAvailable {
return [parameters sdl_objectForName:SDLNameSpaceAvailable];
}
diff --git a/SmartDeviceLink/SDLFileManager.m b/SmartDeviceLink/SDLFileManager.m
index 717660f47..9ff7498ef 100644
--- a/SmartDeviceLink/SDLFileManager.m
+++ b/SmartDeviceLink/SDLFileManager.m
@@ -228,13 +228,13 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
__strong typeof(weakSelf) strongSelf = weakSelf;
// Mutate self based on the changes
- strongSelf.bytesAvailable = bytesAvailable;
if (success) {
+ strongSelf.bytesAvailable = bytesAvailable;
[strongSelf.mutableRemoteFileNames removeObject:name];
}
if (handler != nil) {
- handler(success, self.bytesAvailable, error);
+ handler(success, bytesAvailable, error);
}
}];
@@ -385,11 +385,9 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
if (self.uploadsInProgress[file.name]) {
[self.uploadsInProgress removeObjectForKey:file.name];
}
-
- if (bytesAvailable != 0) {
- weakSelf.bytesAvailable = bytesAvailable;
- }
+
if (success) {
+ weakSelf.bytesAvailable = bytesAvailable;
[weakSelf.mutableRemoteFileNames addObject:fileName];
[weakSelf.uploadedEphemeralFileNames addObject:fileName];
} else {
diff --git a/SmartDeviceLink/SDLListFilesOperation.m b/SmartDeviceLink/SDLListFilesOperation.m
index 0cfd85460..ca45ac928 100644
--- a/SmartDeviceLink/SDLListFilesOperation.m
+++ b/SmartDeviceLink/SDLListFilesOperation.m
@@ -47,19 +47,20 @@ NS_ASSUME_NONNULL_BEGIN
SDLListFiles *listFiles = [[SDLListFiles alloc] init];
__weak typeof(self) weakSelf = self;
- [self.connectionManager sendConnectionManagerRequest:listFiles
- withResponseHandler:^(__kindof SDLRPCRequest *request, __kindof SDLRPCResponse *response, NSError *error) {
- SDLListFilesResponse *listFilesResponse = (SDLListFilesResponse *)response;
- BOOL success = [listFilesResponse.success boolValue];
- NSUInteger bytesAvailable = [listFilesResponse.spaceAvailable unsignedIntegerValue];
- NSArray<NSString *> *fileNames = [NSArray arrayWithArray:listFilesResponse.filenames];
-
- if (weakSelf.completionHandler != nil) {
- weakSelf.completionHandler(success, bytesAvailable, fileNames, error);
- }
-
- [weakSelf finishOperation];
- }];
+ [self.connectionManager sendConnectionManagerRequest:listFiles withResponseHandler:^(__kindof SDLRPCRequest *request, __kindof SDLRPCResponse *response, NSError *error) {
+ SDLListFilesResponse *listFilesResponse = (SDLListFilesResponse *)response;
+ BOOL success = [listFilesResponse.success boolValue];
+ NSArray<NSString *> *fileNames = [NSArray arrayWithArray:listFilesResponse.filenames];
+
+ // If spaceAvailable is nil, set it to the max value
+ NSUInteger bytesAvailable = listFilesResponse.spaceAvailable != nil ? listFilesResponse.spaceAvailable.unsignedIntegerValue : 2000000000;
+
+ if (weakSelf.completionHandler != nil) {
+ weakSelf.completionHandler(success, bytesAvailable, fileNames, error);
+ }
+
+ [weakSelf finishOperation];
+ }];
}
diff --git a/SmartDeviceLink/SDLListFilesResponse.h b/SmartDeviceLink/SDLListFilesResponse.h
index b269b11c4..b5ddef16e 100644
--- a/SmartDeviceLink/SDLListFilesResponse.h
+++ b/SmartDeviceLink/SDLListFilesResponse.h
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
Provides the total local space available on the module for the registered app.
*/
-@property (strong, nonatomic) NSNumber<SDLInt> *spaceAvailable;
+@property (nullable, strong, nonatomic) NSNumber<SDLInt> *spaceAvailable;
@end
diff --git a/SmartDeviceLink/SDLListFilesResponse.m b/SmartDeviceLink/SDLListFilesResponse.m
index f78d83acb..376e81702 100644
--- a/SmartDeviceLink/SDLListFilesResponse.m
+++ b/SmartDeviceLink/SDLListFilesResponse.m
@@ -25,11 +25,11 @@ NS_ASSUME_NONNULL_BEGIN
return [parameters sdl_objectForName:SDLNameFilenames];
}
-- (void)setSpaceAvailable:(NSNumber<SDLInt> *)spaceAvailable {
+- (void)setSpaceAvailable:(nullable NSNumber<SDLInt> *)spaceAvailable {
[parameters sdl_setObject:spaceAvailable forName:SDLNameSpaceAvailable];
}
-- (NSNumber<SDLInt> *)spaceAvailable {
+- (nullable NSNumber<SDLInt> *)spaceAvailable {
return [parameters sdl_objectForName:SDLNameSpaceAvailable];
}
diff --git a/SmartDeviceLink/SDLPutFileResponse.h b/SmartDeviceLink/SDLPutFileResponse.h
index 322ab47d4..0c8772125 100644
--- a/SmartDeviceLink/SDLPutFileResponse.h
+++ b/SmartDeviceLink/SDLPutFileResponse.h
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Provides the total local space available in SDL Core for the registered app. If the transfer has systemFile enabled, then the value will be set to 0 automatically.
*/
-@property (strong, nonatomic) NSNumber<SDLInt> *spaceAvailable;
+@property (nullable, strong, nonatomic) NSNumber<SDLInt> *spaceAvailable;
@end
diff --git a/SmartDeviceLink/SDLPutFileResponse.m b/SmartDeviceLink/SDLPutFileResponse.m
index 2d3de3352..93d0caa5e 100644
--- a/SmartDeviceLink/SDLPutFileResponse.m
+++ b/SmartDeviceLink/SDLPutFileResponse.m
@@ -17,11 +17,11 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (void)setSpaceAvailable:(NSNumber<SDLInt> *)spaceAvailable {
+- (void)setSpaceAvailable:(nullable NSNumber<SDLInt> *)spaceAvailable {
[parameters sdl_setObject:spaceAvailable forName:SDLNameSpaceAvailable];
}
-- (NSNumber<SDLInt> *)spaceAvailable {
+- (nullable NSNumber<SDLInt> *)spaceAvailable {
return [parameters sdl_objectForName:SDLNameSpaceAvailable];
}
diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m
index 3eea620ba..620d0f833 100644
--- a/SmartDeviceLink/SDLUploadFileOperation.m
+++ b/SmartDeviceLink/SDLUploadFileOperation.m
@@ -66,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)sdl_sendFile:(SDLFile *)file mtuSize:(NSUInteger)mtuSize withCompletion:(SDLFileManagerUploadCompletionHandler)completion {
__block NSError *streamError = nil;
- __block NSUInteger bytesAvailable = 0;
+ __block NSUInteger bytesAvailable = 2000000000;
__block NSInteger highestCorrelationIDReceived = -1;
if (self.isCancelled) {
@@ -128,6 +128,7 @@ NS_ASSUME_NONNULL_BEGIN
__weak typeof(self) weakself = self;
[self.connectionManager sendConnectionManagerRequest:putFile withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) {
typeof(weakself) strongself = weakself;
+ SDLPutFileResponse *putFileResponse = (SDLPutFileResponse *)response;
// Check if the upload process has been cancelled by another packet. If so, stop the upload process.
// TODO: Is this the right way to handle this case? Should we just abort everything in the future? Should we be deleting what we sent? Should we have an automatic retry strategy based on what the error was?
@@ -147,7 +148,9 @@ NS_ASSUME_NONNULL_BEGIN
// If no errors, watch for a response containing the amount of storage left on the SDL Core
if ([self.class sdl_newHighestCorrelationID:request highestCorrelationIDReceived:highestCorrelationIDReceived]) {
highestCorrelationIDReceived = [request.correlationID integerValue];
- bytesAvailable = [(SDLPutFileResponse *)response spaceAvailable].unsignedIntegerValue;
+
+ // If spaceAvailable is nil, set it to the max value
+ bytesAvailable = putFileResponse.spaceAvailable != nil ? putFileResponse.spaceAvailable.unsignedIntegerValue : 2000000000;
}
dispatch_group_leave(putFileGroup);
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
index 8a5ea9318..68a24e4b6 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
@@ -23,6 +23,7 @@ typedef NSString SDLFileManagerState;
SDLFileManagerState *const SDLFileManagerStateShutdown = @"Shutdown";
SDLFileManagerState *const SDLFileManagerStateFetchingInitialList = @"FetchingInitialList";
SDLFileManagerState *const SDLFileManagerStateReady = @"Ready";
+SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
@interface SDLFileManager ()
@property (strong, nonatomic) NSOperationQueue *transactionQueue;
@@ -123,6 +124,31 @@ describe(@"SDLFileManager", ^{
});
});
+ describe(@"after receiving a ListFiles error", ^{
+ __block SDLListFilesResponse *testListFilesResponse = nil;
+ __block NSSet<NSString *> *testInitialFileNames = nil;
+ __block NSUInteger initialBytesAvailable = 0;
+
+ beforeEach(^{
+ testInitialFileNames = [NSSet setWithArray:@[@"testFile1", @"testFile2", @"testFile3"]];
+ initialBytesAvailable = testFileManager.bytesAvailable;
+
+ testListFilesResponse = [[SDLListFilesResponse alloc] init];
+ testListFilesResponse.success = @NO;
+ testListFilesResponse.spaceAvailable = nil;
+ testListFilesResponse.filenames = nil;
+ [testConnectionManager respondToLastRequestWithResponse:testListFilesResponse];
+ });
+
+ it(@"should handle the error properly", ^{
+ [testConnectionManager respondToLastRequestWithResponse:testListFilesResponse];
+
+ expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateStartupError));
+ expect(testFileManager.remoteFileNames).toEventually(beEmpty());
+ expect(@(testFileManager.bytesAvailable)).toEventually(equal(initialBytesAvailable));
+ });
+ });
+
describe(@"after receiving a ListFiles response", ^{
__block SDLListFilesResponse *testListFilesResponse = nil;
__block NSSet<NSString *> *testInitialFileNames = nil;
@@ -208,6 +234,40 @@ describe(@"SDLFileManager", ^{
expect(testFileManager.remoteFileNames).toNot(contain(someKnownFileName));
});
});
+
+ context(@"when the request returns an error", ^{
+ __block NSUInteger initialSpaceAvailable = 0;
+ __block NSString *someKnownFileName = nil;
+ __block BOOL completionSuccess = NO;
+ __block NSUInteger completionBytesAvailable = 0;
+ __block NSError *completionError = nil;
+
+ beforeEach(^{
+ initialSpaceAvailable = testFileManager.bytesAvailable;
+ someKnownFileName = [testInitialFileNames anyObject];
+ [testFileManager deleteRemoteFileWithName:someKnownFileName completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError * _Nullable error) {
+ completionSuccess = success;
+ completionBytesAvailable = bytesAvailable;
+ completionError = error;
+ }];
+
+ SDLDeleteFileResponse *deleteResponse = [[SDLDeleteFileResponse alloc] init];
+ deleteResponse.success = @NO;
+ deleteResponse.spaceAvailable = nil;
+
+ [NSThread sleepForTimeInterval:0.1];
+
+ [testConnectionManager respondToLastRequestWithResponse:deleteResponse];;
+ });
+
+ it(@"should handle the error properly", ^{
+ expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateReady));
+ expect(completionSuccess).toEventually(beFalse());
+ expect(completionBytesAvailable).toEventually(equal(2000000000));
+ expect(completionError).toNot(beNil());
+ expect(@(testFileManager.bytesAvailable)).toEventually(equal(@(initialSpaceAvailable)));
+ });
+ });
});
describe(@"uploading a new file", ^{
@@ -285,16 +345,11 @@ describe(@"SDLFileManager", ^{
context(@"when the connection returns failure", ^{
__block SDLPutFileResponse *testResponse = nil;
- __block NSNumber *testResponseBytesAvailable = nil;
- __block NSNumber *testResponseSuccess = nil;
beforeEach(^{
- testResponseBytesAvailable = @750;
- testResponseSuccess = @NO;
-
testResponse = [[SDLPutFileResponse alloc] init];
- testResponse.spaceAvailable = testResponseBytesAvailable;
- testResponse.success = testResponseSuccess;
+ testResponse.spaceAvailable = nil;
+ testResponse.success = @NO;
[testConnectionManager respondToLastRequestWithResponse:testResponse];
});
@@ -307,8 +362,8 @@ describe(@"SDLFileManager", ^{
});
it(@"should call the completion handler with the correct data", ^{
- expect(@(completionBytesAvailable)).to(equal(@0));
- expect(@(completionSuccess)).to(equal(testResponseSuccess));
+ expect(completionBytesAvailable).to(equal(2000000000));
+ expect(@(completionSuccess)).to(equal(@NO));
expect(completionError).toEventuallyNot(beNil());
});
@@ -454,7 +509,7 @@ describe(@"SDLFileManager", ^{
});
it(@"should call the completion handler with the correct data", ^{
- expect(@(completionBytesAvailable)).to(equal(@0));
+ expect(@(completionBytesAvailable)).to(equal(@2000000000));
expect(@(completionSuccess)).to(equal(testResponseSuccess));
expect(completionError).toEventuallyNot(beNil());
});
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m
index cbdee6375..9d5bec9a5 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m
@@ -319,11 +319,11 @@ describe(@"the streaming video manager", ^{
context(@"and hmi state changes to background after app becomes inactive", ^{
beforeEach(^{
[streamingLifecycleManager.appStateMachine setToState:SDLAppStateInactive fromOldState:nil callEnterTransition:YES];
- sendNotificationForHMILevel(SDLHMILevelBackground);
+ sendNotificationForHMILevel(SDLHMILevelBackground, SDLVideoStreamingStateNotStreamable);
});
it(@"should close the stream", ^{
- expect(streamingLifecycleManager.currentVideoStreamState).to(equal(SDLVideoStreamStateShuttingDown));
+ expect(streamingLifecycleManager.currentVideoStreamState).to(equal(SDLVideoStreamManagerStateShuttingDown));
});
});
});