diff options
author | Muller, Alexander (A.) <amulle19@ford.com> | 2017-01-18 13:34:15 -0800 |
---|---|---|
committer | Muller, Alexander (A.) <amulle19@ford.com> | 2017-01-18 13:34:15 -0800 |
commit | b5396a39e35c31765d57b5b7e53d8179947ed0e7 (patch) | |
tree | 45ce1a3407f2466f3204cbac74ba58d8d77c0d82 | |
parent | d102326380d144e1c35e6f0ae44be2e9ab387784 (diff) | |
download | sdl_ios-hotfix/issue_495.tar.gz |
Fixed issue around not calculating an SDLPutFile's currentOffset correctly. Updated unit tests to cover all SDLPutFiles, not just the first.hotfix/issue_495
-rw-r--r-- | SmartDeviceLink/SDLUploadFileOperation.m | 2 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m | 27 |
2 files changed, 21 insertions, 8 deletions
diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m index 65910ab5f..f373dc566 100644 --- a/SmartDeviceLink/SDLUploadFileOperation.m +++ b/SmartDeviceLink/SDLUploadFileOperation.m @@ -141,7 +141,7 @@ NS_ASSUME_NONNULL_BEGIN currentOffset = mtuSize; } else { putFile.bulkData = [fileData subdataWithRange:NSMakeRange(currentOffset, [putFile.length unsignedIntegerValue])]; - currentOffset = [putFile.length unsignedIntegerValue]; + currentOffset += [putFile.length unsignedIntegerValue]; } [putFiles addObject:putFile]; diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m index d0a20b03c..b5d2bfcf4 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m @@ -144,15 +144,28 @@ describe(@"Upload File Operation", ^{ NSArray<SDLPutFile *> *putFiles = testConnectionManager.receivedRequests; SDLPutFile *firstPutFile = putFiles.firstObject; - // First putfile - expect(firstPutFile.bulkData).to(equal([testFileData subdataWithRange:NSMakeRange(0, [SDLGlobals globals].maxMTUSize)])); - expect(firstPutFile.length).to(equal(@(testFileData.length))); - expect(firstPutFile.offset).to(equal(@0)); - expect(firstPutFile.persistentFile).to(equal(@NO)); - expect(firstPutFile.syncFileName).to(equal(testFileName)); - NSUInteger numberOfPutFiles = (((testFileData.length - 1) / [SDLGlobals globals].maxMTUSize) + 1); expect(@(putFiles.count)).to(equal(@(numberOfPutFiles))); + + // Test all PutFiles pieces for offset & length. + for (NSUInteger index = 0; index < numberOfPutFiles; index++) { + SDLPutFile *putFile = putFiles[index]; + + expect(putFile.offset).to(equal(@(index * [SDLGlobals globals].maxMTUSize))); + expect(putFile.persistentFile).to(equal(@NO)); + expect(putFile.syncFileName).to(equal(testFileName)); + expect(putFile.bulkData).to(equal([testFileData subdataWithRange:NSMakeRange((index * [SDLGlobals globals].maxMTUSize), MIN(putFile.length.unsignedIntegerValue, [SDLGlobals globals].maxMTUSize))])); + + // First Putfile has some differences due to informing core of the total incoming packet size. + if (index == 0) { + expect(putFile.length).to(equal(@(testFileData.length))); + } else if (index == numberOfPutFiles - 1) { + expect(putFile.length).to(equal(@(testFileData.length - (index * [SDLGlobals globals].maxMTUSize)))); + } else { + expect(putFile.length).to(equal(@([SDLGlobals globals].maxMTUSize))); + } + } + }); }); }); |