summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.m2
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m27
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)));
+ }
+ }
+
});
});
});