diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2018-01-29 15:02:24 -0500 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2018-01-29 15:02:24 -0500 |
commit | 61113a5352ff89c5f2f1dd788a75513ead62004f (patch) | |
tree | 87933576724751614e2cea9fafe2ebe440b146d3 | |
parent | 2cc91686b3b0a319508438fbaec14c2d51974e03 (diff) | |
download | sdl_ios-61113a5352ff89c5f2f1dd788a75513ead62004f.tar.gz |
Fix #827
* Add a public method for testing and transparency
* Add tests
-rw-r--r-- | SmartDeviceLink/SDLFileManager.h | 5 | ||||
-rw-r--r-- | SmartDeviceLink/SDLFileManager.m | 14 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m | 9 | ||||
-rw-r--r-- | SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testAppAndVehicleIcons@2x.png | bin | 101989 -> 29249 bytes | |||
-rw-r--r-- | SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testLightBackgroundNoAppNoVehicleIcons@2x.png | bin | 43314 -> 29249 bytes | |||
-rw-r--r-- | SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testNoAppNoVehicleIcons@2x.png | bin | 46030 -> 29249 bytes | |||
-rw-r--r-- | SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyAppIcon@2x.png | bin | 52927 -> 29249 bytes | |||
-rw-r--r-- | SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyVehicleIcon@2x.png | bin | 56436 -> 29249 bytes |
8 files changed, 21 insertions, 7 deletions
diff --git a/SmartDeviceLink/SDLFileManager.h b/SmartDeviceLink/SDLFileManager.h index 720e95044..41612cea4 100644 --- a/SmartDeviceLink/SDLFileManager.h +++ b/SmartDeviceLink/SDLFileManager.h @@ -32,6 +32,11 @@ typedef void (^SDLFileManagerStartupCompletionHandler)(BOOL success, NSError *__ @property (copy, nonatomic, readonly) NSSet<SDLFileName *> *remoteFileNames; /** + A set of all names of files uploaded this session (and this session only) + */ +@property (copy, nonatomic, readonly) NSSet<SDLFileName *> *uploadedEphemeralFileNames; + +/** * The number of bytes still available for files for this app. */ @property (assign, nonatomic, readonly) NSUInteger bytesAvailable; diff --git a/SmartDeviceLink/SDLFileManager.m b/SmartDeviceLink/SDLFileManager.m index d7675496e..f50f887f7 100644 --- a/SmartDeviceLink/SDLFileManager.m +++ b/SmartDeviceLink/SDLFileManager.m @@ -40,13 +40,13 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError"; @property (weak, nonatomic) id<SDLConnectionManagerType> connectionManager; // Remote state -@property (strong, nonatomic, readwrite) NSMutableSet<SDLFileName *> *mutableRemoteFileNames; +@property (strong, nonatomic) NSMutableSet<SDLFileName *> *mutableRemoteFileNames; @property (assign, nonatomic, readwrite) NSUInteger bytesAvailable; // Local state @property (strong, nonatomic) NSOperationQueue *transactionQueue; @property (strong, nonatomic) NSMutableDictionary<SDLFileName *, NSOperation *> *uploadsInProgress; -@property (strong, nonatomic) NSMutableSet<SDLFileName *> *localUploadedFileNames; +@property (strong, nonatomic) NSMutableSet<SDLFileName *> *mutableUploadedEphemeralFileNames; @property (strong, nonatomic) SDLStateMachine *stateMachine; @property (copy, nonatomic, nullable) SDLFileManagerStartupCompletionHandler startupCompletionHandler; @@ -72,7 +72,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError"; _transactionQueue.name = @"SDLFileManager Transaction Queue"; _transactionQueue.maxConcurrentOperationCount = 1; _uploadsInProgress = [[NSMutableDictionary alloc] init]; - _localUploadedFileNames = [[NSMutableSet<SDLFileName *> alloc] init]; + _mutableUploadedEphemeralFileNames = [[NSMutableSet<SDLFileName *> alloc] init]; _stateMachine = [[SDLStateMachine alloc] initWithTarget:self initialState:SDLFileManagerStateShutdown states:[self.class sdl_stateTransitionDictionary]]; @@ -103,6 +103,10 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError"; return [NSSet setWithSet:self.mutableRemoteFileNames]; } +- (NSSet<SDLFileName *> *)uploadedEphemeralFileNames { + return [NSSet setWithSet:self.mutableUploadedEphemeralFileNames]; +} + - (NSString *)currentState { return self.stateMachine.currentState; } @@ -275,7 +279,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError"; dispatch_group_enter(uploadFilesTask); // HAX: [#827](https://github.com/smartdevicelink/sdl_ios/issues/827) Older versions of Core had a bug where list files would cache incorrectly. This led to attempted uploads failing due to the system thinking they were already there when they were not. - if (!file.persistent && [self.remoteFileNames containsObject:file.name] && ![self.localUploadedFileNames containsObject:file.name]) { + if (!file.persistent && [self.remoteFileNames containsObject:file.name] && ![self.mutableUploadedEphemeralFileNames containsObject:file.name]) { file.overwrite = true; } @@ -390,7 +394,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError"; } if (success) { [weakSelf.mutableRemoteFileNames addObject:fileName]; - [weakSelf.localUploadedFileNames addObject:fileName]; + [weakSelf.mutableUploadedEphemeralFileNames addObject:fileName]; } if (uploadCompletion != nil) { uploadCompletion(success, bytesAvailable, error); diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m index 355d41273..8f66302b7 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m @@ -29,7 +29,7 @@ SDLFileManagerState *const SDLFileManagerStateReady = @"Ready"; QuickSpecBegin(SDLFileManagerSpec) -describe(@"SDLFileManager", ^{ +fdescribe(@"SDLFileManager", ^{ __block TestConnectionManager *testConnectionManager = nil; __block SDLFileManager *testFileManager = nil; __block NSUInteger initialSpaceAvailable = 250; @@ -225,6 +225,7 @@ describe(@"SDLFileManager", ^{ it(@"should set the file manager state to be waiting", ^{ expect(testFileManager.currentState).to(match(SDLFileManagerStateReady)); + expect(testFileManager.uploadedEphemeralFileNames).to(beEmpty()); }); it(@"should create a putfile with the correct data", ^{ @@ -253,6 +254,7 @@ describe(@"SDLFileManager", ^{ expect(@(testFileManager.bytesAvailable)).toEventually(equal(testResponseBytesAvailable)); expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateReady)); expect(testFileManager.remoteFileNames).toEventually(contain(testFileName)); + expect(testFileManager.uploadedEphemeralFileNames).toEventually(contain(testFileName)); }); it(@"should call the completion handler with the correct data", ^{ @@ -282,6 +284,7 @@ describe(@"SDLFileManager", ^{ expect(@(testFileManager.bytesAvailable)).toEventually(equal(@(initialSpaceAvailable))); expect(testFileManager.remoteFileNames).toEventually(contain(testFileName)); expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateReady)); + expect(testFileManager.uploadedEphemeralFileNames).to(beEmpty()); }); it(@"should call the completion handler with the correct data", ^{ @@ -307,7 +310,7 @@ describe(@"SDLFileManager", ^{ }); }); - context(@"when allow overwrite is false", ^{ + context(@"when allow overwrite is NO", ^{ __block SDLRPCRequest *lastRequest = nil; beforeEach(^{ @@ -373,6 +376,7 @@ describe(@"SDLFileManager", ^{ it(@"should set the file manager state correctly", ^{ expect(@(testFileManager.bytesAvailable)).toEventually(equal(testResponseBytesAvailable)); expect(testFileManager.remoteFileNames).toEventually(contain(testFileName)); + expect(testFileManager.uploadedEphemeralFileNames).toEventually(contain(testUploadFile.name)); expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateReady)); }); @@ -404,6 +408,7 @@ describe(@"SDLFileManager", ^{ it(@"should set the file manager state correctly", ^{ expect(@(testFileManager.bytesAvailable)).toEventually(equal(@(initialSpaceAvailable))); expect(testFileManager.remoteFileNames).toEventuallyNot(contain(testFileName)); + expect(testFileManager.uploadedEphemeralFileNames).toEventuallyNot(contain(testUploadFile.name)); expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateReady)); }); diff --git a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testAppAndVehicleIcons@2x.png b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testAppAndVehicleIcons@2x.png Binary files differindex bef5354d6..3648c2bce 100644 --- a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testAppAndVehicleIcons@2x.png +++ b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testAppAndVehicleIcons@2x.png diff --git a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testLightBackgroundNoAppNoVehicleIcons@2x.png b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testLightBackgroundNoAppNoVehicleIcons@2x.png Binary files differindex 7c3972fd4..3648c2bce 100644 --- a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testLightBackgroundNoAppNoVehicleIcons@2x.png +++ b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testLightBackgroundNoAppNoVehicleIcons@2x.png diff --git a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testNoAppNoVehicleIcons@2x.png b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testNoAppNoVehicleIcons@2x.png Binary files differindex b6bca2f99..3648c2bce 100644 --- a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testNoAppNoVehicleIcons@2x.png +++ b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testNoAppNoVehicleIcons@2x.png diff --git a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyAppIcon@2x.png b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyAppIcon@2x.png Binary files differindex 2081fcdcc..3648c2bce 100644 --- a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyAppIcon@2x.png +++ b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyAppIcon@2x.png diff --git a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyVehicleIcon@2x.png b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyVehicleIcon@2x.png Binary files differindex d83c4e6dc..3648c2bce 100644 --- a/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyVehicleIcon@2x.png +++ b/SmartDeviceLinkTests/ReferenceImages_64/SDLLockScreenViewControllerSnapshotTests/testOnlyVehicleIcon@2x.png |