From b5396a39e35c31765d57b5b7e53d8179947ed0e7 Mon Sep 17 00:00:00 2001 From: "Muller, Alexander (A.)" Date: Wed, 18 Jan 2017 13:34:15 -0800 Subject: Fixed issue around not calculating an SDLPutFile's currentOffset correctly. Updated unit tests to cover all SDLPutFiles, not just the first. --- SmartDeviceLink/SDLUploadFileOperation.m | 2 +- .../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 *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))); + } + } + }); }); }); -- cgit v1.2.1