diff --git a/AliyunOSSSDK.xcodeproj/project.pbxproj b/AliyunOSSSDK.xcodeproj/project.pbxproj index 53594928..6f50b1a0 100644 --- a/AliyunOSSSDK.xcodeproj/project.pbxproj +++ b/AliyunOSSSDK.xcodeproj/project.pbxproj @@ -34,7 +34,6 @@ D80C82111FC8258B008E3900 /* OSSTaskCompletionSource.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183291FC56358000DD9EC /* OSSTaskCompletionSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; D80C82121FC8258F008E3900 /* OSSCancellationToken.h in Headers */ = {isa = PBXBuildFile; fileRef = D871832C1FC56358000DD9EC /* OSSCancellationToken.h */; settings = {ATTRIBUTES = (Public, ); }; }; D80C82131FC82596008E3900 /* OSSIPv6Adapter.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183151FC56358000DD9EC /* OSSIPv6Adapter.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D80C82141FC82599008E3900 /* OSSReachabilityManager.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183161FC56358000DD9EC /* OSSReachabilityManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; D80C82151FC8259C008E3900 /* OSSIPv6PrefixResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = D871831A1FC56358000DD9EC /* OSSIPv6PrefixResolver.h */; settings = {ATTRIBUTES = (Public, ); }; }; D80C88C9201AC1B400F379D8 /* OSSGetObjectACLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = D80C88C7201AC1B400F379D8 /* OSSGetObjectACLRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; D80C88CA201AC1B400F379D8 /* OSSGetObjectACLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = D80C88C7201AC1B400F379D8 /* OSSGetObjectACLRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -136,7 +135,6 @@ D8C41AAD1FCC284F0091699B /* OSSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = D871830D1FC56358000DD9EC /* OSSLog.m */; }; D8C41AB11FCC284F0091699B /* OSSModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183111FC56358000DD9EC /* OSSModel.m */; }; D8C41AB61FCC284F0091699B /* OSSIPv6PrefixResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183171FC56358000DD9EC /* OSSIPv6PrefixResolver.m */; }; - D8C41AB71FCC284F0091699B /* OSSReachabilityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183181FC56358000DD9EC /* OSSReachabilityManager.m */; }; D8C41AB81FCC284F0091699B /* OSSIPv6Adapter.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183191FC56358000DD9EC /* OSSIPv6Adapter.m */; }; D8C41ABB1FCC284F0091699B /* OSSCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = D871831C1FC56358000DD9EC /* OSSCompat.m */; }; D8C41ABD1FCC284F0091699B /* OSSCancellationTokenRegistration.m in Sources */ = {isa = PBXBuildFile; fileRef = D871831F1FC56358000DD9EC /* OSSCancellationTokenRegistration.m */; }; @@ -159,7 +157,6 @@ D8C41AEC1FCC2F920091699B /* OSSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = D871830D1FC56358000DD9EC /* OSSLog.m */; }; D8C41AF01FCC2F920091699B /* OSSModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183111FC56358000DD9EC /* OSSModel.m */; }; D8C41AF51FCC2F920091699B /* OSSIPv6PrefixResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183171FC56358000DD9EC /* OSSIPv6PrefixResolver.m */; }; - D8C41AF61FCC2F920091699B /* OSSReachabilityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183181FC56358000DD9EC /* OSSReachabilityManager.m */; }; D8C41AF71FCC2F920091699B /* OSSIPv6Adapter.m in Sources */ = {isa = PBXBuildFile; fileRef = D87183191FC56358000DD9EC /* OSSIPv6Adapter.m */; }; D8C41AFA1FCC2F920091699B /* OSSCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = D871831C1FC56358000DD9EC /* OSSCompat.m */; }; D8C41AFC1FCC2F920091699B /* OSSCancellationTokenRegistration.m in Sources */ = {isa = PBXBuildFile; fileRef = D871831F1FC56358000DD9EC /* OSSCancellationTokenRegistration.m */; }; @@ -183,7 +180,6 @@ D8C41B231FCC2FD20091699B /* OSSHttpdns.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183121FC56358000DD9EC /* OSSHttpdns.h */; settings = {ATTRIBUTES = (Public, ); }; }; D8C41B241FCC2FD20091699B /* OSSNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183131FC56358000DD9EC /* OSSNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; D8C41B251FCC2FD20091699B /* OSSIPv6Adapter.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183151FC56358000DD9EC /* OSSIPv6Adapter.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D8C41B261FCC2FD20091699B /* OSSReachabilityManager.h in Headers */ = {isa = PBXBuildFile; fileRef = D87183161FC56358000DD9EC /* OSSReachabilityManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; D8C41B2A1FCC2FD20091699B /* OSSIPv6PrefixResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = D871831A1FC56358000DD9EC /* OSSIPv6PrefixResolver.h */; settings = {ATTRIBUTES = (Public, ); }; }; D8C41B2B1FCC2FD20091699B /* OSSDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = D871831B1FC56358000DD9EC /* OSSDefine.h */; settings = {ATTRIBUTES = (Public, ); }; }; D8C41B2D1FCC2FD20091699B /* OSSLog.h in Headers */ = {isa = PBXBuildFile; fileRef = D871831D1FC56358000DD9EC /* OSSLog.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -291,9 +287,7 @@ D87183121FC56358000DD9EC /* OSSHttpdns.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSHttpdns.h; sourceTree = ""; }; D87183131FC56358000DD9EC /* OSSNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSNetworking.h; sourceTree = ""; }; D87183151FC56358000DD9EC /* OSSIPv6Adapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSIPv6Adapter.h; sourceTree = ""; }; - D87183161FC56358000DD9EC /* OSSReachabilityManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSReachabilityManager.h; sourceTree = ""; }; D87183171FC56358000DD9EC /* OSSIPv6PrefixResolver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSIPv6PrefixResolver.m; sourceTree = ""; }; - D87183181FC56358000DD9EC /* OSSReachabilityManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSReachabilityManager.m; sourceTree = ""; }; D87183191FC56358000DD9EC /* OSSIPv6Adapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSSIPv6Adapter.m; sourceTree = ""; }; D871831A1FC56358000DD9EC /* OSSIPv6PrefixResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSIPv6PrefixResolver.h; sourceTree = ""; }; D871831B1FC56358000DD9EC /* OSSDefine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSSDefine.h; sourceTree = ""; }; @@ -494,9 +488,7 @@ isa = PBXGroup; children = ( D87183151FC56358000DD9EC /* OSSIPv6Adapter.h */, - D87183161FC56358000DD9EC /* OSSReachabilityManager.h */, D87183171FC56358000DD9EC /* OSSIPv6PrefixResolver.m */, - D87183181FC56358000DD9EC /* OSSReachabilityManager.m */, D87183191FC56358000DD9EC /* OSSIPv6Adapter.m */, D871831A1FC56358000DD9EC /* OSSIPv6PrefixResolver.h */, ); @@ -556,7 +548,6 @@ D8C41B231FCC2FD20091699B /* OSSHttpdns.h in Headers */, D8C41B241FCC2FD20091699B /* OSSNetworking.h in Headers */, D8C41B251FCC2FD20091699B /* OSSIPv6Adapter.h in Headers */, - D8C41B261FCC2FD20091699B /* OSSReachabilityManager.h in Headers */, D8C41B2A1FCC2FD20091699B /* OSSIPv6PrefixResolver.h in Headers */, D8C41B2B1FCC2FD20091699B /* OSSDefine.h in Headers */, D8C41B2D1FCC2FD20091699B /* OSSLog.h in Headers */, @@ -611,7 +602,6 @@ D80C81FF1FC82554008E3900 /* OSSClient.h in Headers */, D80C82021FC8255B008E3900 /* OSSNetworking.h in Headers */, D80C82131FC82596008E3900 /* OSSIPv6Adapter.h in Headers */, - D80C82141FC82599008E3900 /* OSSReachabilityManager.h in Headers */, D80C82051FC82567008E3900 /* OSSService.h in Headers */, D80C82041FC82562008E3900 /* OSSLog.h in Headers */, D80C82151FC8259C008E3900 /* OSSIPv6PrefixResolver.h in Headers */, @@ -815,7 +805,6 @@ D8C41AF01FCC2F920091699B /* OSSModel.m in Sources */, D8C41AF51FCC2F920091699B /* OSSIPv6PrefixResolver.m in Sources */, D85278062015D58400D7B1DE /* OSSHttpResponseParser.m in Sources */, - D8C41AF61FCC2F920091699B /* OSSReachabilityManager.m in Sources */, D80C88EF201B06E200F379D8 /* OSSDeleteMultipleObjectsResult.m in Sources */, D8C41AF71FCC2F920091699B /* OSSIPv6Adapter.m in Sources */, D827B4192111A6E4003A24F6 /* OSSPutSymlinkRequest.m in Sources */, @@ -868,7 +857,6 @@ D8C41AB11FCC284F0091699B /* OSSModel.m in Sources */, D8C41AB61FCC284F0091699B /* OSSIPv6PrefixResolver.m in Sources */, D85278072015D58400D7B1DE /* OSSHttpResponseParser.m in Sources */, - D8C41AB71FCC284F0091699B /* OSSReachabilityManager.m in Sources */, D80C88F0201B06E200F379D8 /* OSSDeleteMultipleObjectsResult.m in Sources */, D8C41AB81FCC284F0091699B /* OSSIPv6Adapter.m in Sources */, D827B41A2111A6E4003A24F6 /* OSSPutSymlinkRequest.m in Sources */, diff --git a/AliyunOSSSDK/OSSClient.m b/AliyunOSSSDK/OSSClient.m index e2b76760..c06ba1e2 100644 --- a/AliyunOSSSDK/OSSClient.m +++ b/AliyunOSSSDK/OSSClient.m @@ -14,7 +14,6 @@ #import "OSSBolts.h" #import "OSSNetworking.h" #import "OSSXMLDictionary.h" -#import "OSSReachabilityManager.h" #import "OSSIPv6Adapter.h" #import "OSSNetworkingRequestDelegate.h" @@ -78,10 +77,6 @@ - (instancetype)initWithEndpoint:(NSString *)endpoint if (!lock) { lock = [NSObject new]; } - // Monitor the network. If the network type is changed, recheck the IPv6 status. - if (conf.isNeedListenNetworkChanges) { - [OSSReachabilityManager shareInstance]; - } NSOperationQueue * queue = [NSOperationQueue new]; // using for resumable upload and compat old interface @@ -1608,12 +1603,16 @@ - (OSSTask *)multipartUpload:(OSSMultipartUploadRequest *)request resumable:(BOO #pragma clang diagnostic pop NSDictionary *tPartInfo = [localPartInfos objectForKey: [@(remotePartNumber) stringValue]]; - if (tPartInfo != nil) { + if (request.crcFlag == OSSRequestCRCOpen) { + if (tPartInfo == nil) { + uploadedLength -= remotePartSize; + return; + } info.crc64 = [tPartInfo[@"crc64"] unsignedLongLongValue]; - - [uploadedPartInfos addObject:info]; - [alreadyUploadIndex addObject:@(remotePartNumber)]; } + + [uploadedPartInfos addObject:info]; + [alreadyUploadIndex addObject:@(remotePartNumber)]; }]; if ([alreadyUploadIndex count] > 0 && request.uploadProgress && uploadFileSize) { diff --git a/AliyunOSSSDK/OSSHttpResponseParser.m b/AliyunOSSSDK/OSSHttpResponseParser.m index 5dc4b6db..bf03e170 100644 --- a/AliyunOSSSDK/OSSHttpResponseParser.m +++ b/AliyunOSSSDK/OSSHttpResponseParser.m @@ -194,7 +194,8 @@ - (nullable id)constructResultObject getServiceResult.marker = [parseDict objectForKey:OSSMarkerXMLTOKEN]; getServiceResult.maxKeys = [[parseDict objectForKey:OSSMaxKeysXMLTOKEN] intValue]; getServiceResult.isTruncated = [[parseDict objectForKey:OSSIsTruncatedXMLTOKEN] boolValue]; - + getServiceResult.nextMarker = [parseDict objectForKey:OSSNextMarkerXMLTOKEN]; + id bucketObject = [[parseDict objectForKey:OSSBucketsXMLTOKEN] objectForKey:OSSBucketXMLTOKEN]; if ([bucketObject isKindOfClass:[NSArray class]]) { getServiceResult.buckets = bucketObject; diff --git a/AliyunOSSSDK/OSSIPv6/OSSIPv6Adapter.m b/AliyunOSSSDK/OSSIPv6/OSSIPv6Adapter.m index 1ed18ff5..66d5b113 100644 --- a/AliyunOSSSDK/OSSIPv6/OSSIPv6Adapter.m +++ b/AliyunOSSSDK/OSSIPv6/OSSIPv6Adapter.m @@ -8,7 +8,6 @@ #import #import "OSSIPv6Adapter.h" #import "OSSIPv6PrefixResolver.h" -#import "OSSReachabilityManager.h" #import "OSSLog.h" #include diff --git a/AliyunOSSSDK/OSSIPv6/OSSReachabilityManager.h b/AliyunOSSSDK/OSSIPv6/OSSReachabilityManager.h deleted file mode 100644 index 6e5c5990..00000000 --- a/AliyunOSSSDK/OSSIPv6/OSSReachabilityManager.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// OSSReachabilityManager.h -// -// Created by 亿刀 on 14-1-9. -// Edited by junmo on 15-5-16 -// Copyright (c) 2014 Twitter. All rights reserved. -// - -#import - -@interface OSSReachabilityManager : NSObject - -+ (OSSReachabilityManager *)shareInstance; - -@end \ No newline at end of file diff --git a/AliyunOSSSDK/OSSIPv6/OSSReachabilityManager.m b/AliyunOSSSDK/OSSIPv6/OSSReachabilityManager.m deleted file mode 100644 index e0a39152..00000000 --- a/AliyunOSSSDK/OSSIPv6/OSSReachabilityManager.m +++ /dev/null @@ -1,97 +0,0 @@ -// -// OSSReachabilityManager.m -// -// Created by 亿刀 on 14-1-9. -// Edited by junmo on 15-5-16 -// Edited by zhouzhuo on 2016/5/22 -// Copyright (c) 2014 Twitter. All rights reserved. -// - -#import "OSSReachabilityManager.h" -#import "OSSIPv6Adapter.h" -#import "OSSLog.h" - -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - -static char *const OSSReachabilityQueueIdentifier = "com.alibaba.oss.network.ReachabilityQueue"; -static dispatch_queue_t reachabilityQueue; -static NSString *const CHECK_HOSTNAME = @"www.taobao.com"; - -@implementation OSSReachabilityManager { - SCNetworkReachabilityRef _reachabilityRef; -} - -+ (OSSReachabilityManager *)shareInstance -{ - static OSSReachabilityManager *s_SPDYNetworkStatusManager = nil; - - @synchronized([self class]) - { - if (!s_SPDYNetworkStatusManager) - { - s_SPDYNetworkStatusManager = [[OSSReachabilityManager alloc] init]; - } - } - - return s_SPDYNetworkStatusManager; -} - -- (id)init -{ - self = [super init]; - if (self) - { - _reachabilityRef = SCNetworkReachabilityCreateWithName(NULL, [CHECK_HOSTNAME UTF8String]); - - // Start network monitor - [self _startNotifier]; - } - - return self; -} - -- (BOOL)_startNotifier -{ - if (!_reachabilityRef) - { - _reachabilityRef = SCNetworkReachabilityCreateWithName(NULL, [CHECK_HOSTNAME UTF8String]); - } - - if (_reachabilityRef) - { - SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; - - if(SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) - { - reachabilityQueue = dispatch_queue_create(OSSReachabilityQueueIdentifier, DISPATCH_QUEUE_SERIAL); - SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, reachabilityQueue); - - return YES; - } - } - return NO; -} - -// Callback of Network change -static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) -{ - if ([[OSSIPv6Adapter getInstance] isIPv6OnlyNetwork]) { - OSSLogDebug(@"[AlicloudReachabilityManager]: Network changed, Pre network status is IPv6-Only."); - } else { - OSSLogDebug(@"[AlicloudReachabilityManager]: Network changed, Pre network status is not IPv6-Only."); - } - - [[OSSIPv6Adapter getInstance] reResolveIPv6OnlyStatus]; -} - -@end diff --git a/AliyunOSSSDK/OSSModel.h b/AliyunOSSSDK/OSSModel.h index d93db5c1..a746417c 100644 --- a/AliyunOSSSDK/OSSModel.h +++ b/AliyunOSSSDK/OSSModel.h @@ -220,8 +220,8 @@ Sets the session Id for background file transmission */ @property (nonatomic, assign) BOOL crc64Verifiable; -/// Monitor the network. If the network type is changed, recheck the IPv6 status. -@property (nonatomic, assign) BOOL isNeedListenNetworkChanges; +/// Set whether to allow UA to carry system information +@property (nonatomic, assign) BOOL isAllowUACarrySystemInfo; @end diff --git a/AliyunOSSSDK/OSSModel.m b/AliyunOSSSDK/OSSModel.m index 889fbdce..247f555a 100644 --- a/AliyunOSSSDK/OSSModel.m +++ b/AliyunOSSSDK/OSSModel.m @@ -299,6 +299,7 @@ - (instancetype)init { self.isPathStyleAccessEnable = NO; self.isCustomPathPrefixEnable = NO; self.cnameExcludeList = @[]; + self.isAllowUACarrySystemInfo = YES; } return self; } @@ -475,9 +476,13 @@ - (NSString *)getUserAgent:(NSString *)customUserAgent { dispatch_once(&once, ^{ NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier]; #if TARGET_OS_IOS - NSString *systemName = [[[UIDevice currentDevice] systemName] stringByReplacingOccurrencesOfString:@" " withString:@"-"]; - NSString *systemVersion = [[UIDevice currentDevice] systemVersion]; - userAgent = [NSString stringWithFormat:@"%@/%@(/%@/%@/%@)", OSSUAPrefix, OSSSDKVersion, systemName, systemVersion, localeIdentifier]; + if (self.clientConfiguration.isAllowUACarrySystemInfo) { + NSString *systemName = [[[UIDevice currentDevice] systemName] stringByReplacingOccurrencesOfString:@" " withString:@"-"]; + NSString *systemVersion = [[UIDevice currentDevice] systemVersion]; + userAgent = [NSString stringWithFormat:@"%@/%@(/%@/%@/%@)", OSSUAPrefix, OSSSDKVersion, systemName, systemVersion, localeIdentifier]; + } else { + userAgent = [NSString stringWithFormat:@"%@/%@(/%@)", OSSUAPrefix, OSSSDKVersion, localeIdentifier]; + } #elif TARGET_OS_OSX userAgent = [NSString stringWithFormat:@"%@/%@(/%@/%@/%@)", OSSUAPrefix, OSSSDKVersion, @"OSX", [NSProcessInfo processInfo].operatingSystemVersionString, localeIdentifier]; #endif diff --git a/AliyunOSSiOSTests/AliyunOSSiOSTests.m b/AliyunOSSiOSTests/AliyunOSSiOSTests.m index 3f15696a..cb6b08a8 100644 --- a/AliyunOSSiOSTests/AliyunOSSiOSTests.m +++ b/AliyunOSSiOSTests/AliyunOSSiOSTests.m @@ -198,8 +198,10 @@ - (void)testAccessViaHttpProxy { request.bucketName = _privateBucketName; request.objectKey = @"file1m"; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.downloadProgress = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { NSLog(@"%lld, %lld, %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); + [progressTest updateTotalBytes:totalBytesWritten totalBytesExpected:totalBytesExpectedToWrite]; }; OSSTask * task = [testProxyClient getObject:request]; @@ -208,6 +210,7 @@ - (void)testAccessViaHttpProxy { XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testUserAgentConfig { @@ -224,8 +227,10 @@ - (void)testUserAgentConfig { request.bucketName = _privateBucketName; request.objectKey = @"file1m"; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.downloadProgress = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { NSLog(@"progress: %lld, %lld, %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); + [progressTest updateTotalBytes:totalBytesWritten totalBytesExpected:totalBytesExpectedToWrite]; }; OSSTask * task = [testProxyClient getObject:request]; @@ -234,6 +239,7 @@ - (void)testUserAgentConfig { XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); OSSClientConfiguration * conf1 = [OSSClientConfiguration new]; @@ -245,8 +251,10 @@ - (void)testUserAgentConfig { request1.bucketName = _privateBucketName; request1.objectKey = @"file1m"; + progressTest = [OSSProgressTestUtils new]; request1.downloadProgress = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { NSLog(@"progress: %lld, %lld, %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); + [progressTest updateTotalBytes:totalBytesWritten totalBytesExpected:totalBytesExpectedToWrite]; }; OSSTask * task1 = [testProxyClient getObject:request1]; @@ -255,6 +263,7 @@ - (void)testUserAgentConfig { XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } @@ -289,8 +298,10 @@ - (void)testMultiClientInstance { request.uploadingData = [readFile readDataToEndOfFile]; request.contentMd5 = [OSSUtil base64Md5ForData:request.uploadingData]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"1 -------------------- %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [client1 putObject:request]; @@ -306,7 +317,8 @@ - (void)testMultiClientInstance { result.httpResponseHeaderFields); return nil; }] waitUntilFinished]; - + XCTAssertTrue([progressTest completeValidateProgress]); + request = [OSSPutObjectRequest new]; request.bucketName = _privateBucketName; request.objectKey = @"file1m"; @@ -314,8 +326,10 @@ - (void)testMultiClientInstance { request.uploadingData = [readFile readDataToEndOfFile]; request.contentMd5 = [OSSUtil base64Md5ForData:request.uploadingData]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"2 --------------- %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; task = [client2 putObject:request]; @@ -331,6 +345,7 @@ - (void)testMultiClientInstance { result.httpResponseHeaderFields); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testClientInitWithNoneSchemeEndpoint { @@ -354,8 +369,10 @@ - (void)testClientInitWithNoneSchemeEndpoint { request.uploadingData = [readFile readDataToEndOfFile]; request.contentMd5 = [OSSUtil base64Md5ForData:request.uploadingData]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"1 -------------------- %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [client1 putObject:request]; @@ -371,6 +388,7 @@ - (void)testClientInitWithNoneSchemeEndpoint { result.httpResponseHeaderFields); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testMultipartUploadNormal { @@ -380,8 +398,10 @@ - (void)testMultipartUploadNormal { multipartUploadRequest.objectKey = OSS_MULTIPART_UPLOADKEY; multipartUploadRequest.contentType = @"application/octet-stream"; multipartUploadRequest.partSize = 1024 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; multipartUploadRequest.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; @@ -400,6 +420,7 @@ - (void)testMultipartUploadNormal { } return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testMultipartUploadCancel { @@ -411,6 +432,7 @@ - (void)testMultipartUploadCancel { multipartUploadRequest.partSize = 256 * 1024; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + XCTAssertTrue(totalByteSent <= totalBytesExpectedToSend); }; NSString * docDir = [NSString oss_documentDirectory]; multipartUploadRequest.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file10m"]]; @@ -437,8 +459,10 @@ - (void)testResumableUploadNormal { resumableUpload.recordDirectoryPath = cachesDir; resumableUpload.completeMetaHeader = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; resumableUpload.partSize = 256 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; @@ -461,6 +485,7 @@ - (void)testResumableUploadNormal { BOOL isEqual = [self isFileOnOSSBucket:_privateBucketName objectKey:OSS_MULTIPART_UPLOADKEY equalsToLocalFile:[resumableUpload.uploadingFileURL path]]; XCTAssertTrue(isEqual); + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testResumableUploadSetACL { @@ -472,8 +497,10 @@ - (void)testResumableUploadSetACL { NSString *cachesDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; resumableUpload.recordDirectoryPath = cachesDir; resumableUpload.partSize = 100 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; resumableUpload.completeMetaHeader = @{@"x-oss-object-acl": @"public-read-write"}; NSString * docDir = [NSString oss_documentDirectory]; @@ -494,6 +521,7 @@ - (void)testResumableUploadSetACL { return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); BOOL isEqual = [self isFileOnOSSBucket:_privateBucketName objectKey:OSS_MULTIPART_UPLOADKEY equalsToLocalFile:[resumableUpload.uploadingFileURL path]]; XCTAssertTrue(isEqual); @@ -523,8 +551,10 @@ - (void)testResumableUploadServerCallback { @"var1": @"value1", @"var2": @"value2" }; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; NSString * docDir = [NSString oss_documentDirectory]; resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file1m"]]; @@ -546,7 +576,7 @@ - (void)testResumableUploadServerCallback { } return nil; }] waitUntilFinished]; - + XCTAssertTrue([progressTest completeValidateProgress]); } @@ -563,6 +593,7 @@ - (void)testResumbleUploadCancel { resumableUpload.completeMetaHeader = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; resumableUpload.partSize = 256 * 1024; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { + XCTAssertTrue(totalByteSent <= totalBytesExpectedToSend); NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); }; NSString * docDir = [NSString oss_documentDirectory]; @@ -644,8 +675,10 @@ - (void)testResumbleUploadAbort { resumableUpload.completeMetaHeader = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; resumableUpload.partSize = 256 * 1024; resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file5m"]]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; resumeTask = [client resumableUpload:resumableUpload]; [[resumeTask continueWithBlock:^id(OSSTask *task) { @@ -655,6 +688,7 @@ - (void)testResumbleUploadAbort { XCTAssertTrue(![[NSFileManager defaultManager] fileExistsAtPath:recordFilePath]); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testResumbleUploadCancelResumble { @@ -673,6 +707,7 @@ - (void)testResumbleUploadCancelResumble { if(totalByteSent >= totalBytesExpectedToSend /2){ cancel = YES; } + XCTAssertTrue(totalByteSent <= totalBytesExpectedToSend); }; resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; OSSTask * resumeTask = [client resumableUpload:resumableUpload]; @@ -698,9 +733,11 @@ - (void)testResumbleUploadCancelResumble { resumableUpload.completeMetaHeader = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; resumableUpload.partSize = 100 * 1024; resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); XCTAssertGreaterThan(totalByteSent, totalBytesExpectedToSend / 3); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; resumeTask = [client resumableUpload:resumableUpload]; [[resumeTask continueWithBlock:^id(OSSTask *task) { @@ -710,7 +747,7 @@ - (void)testResumbleUploadCancelResumble { XCTAssertTrue(![[NSFileManager defaultManager] fileExistsAtPath:recordFilePath]); return nil; }] waitUntilFinished]; - + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testResumableUploadSmallFile { @@ -722,8 +759,10 @@ - (void)testResumableUploadSmallFile { resumableUpload.contentType = @"application/octet-stream"; resumableUpload.completeMetaHeader = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; resumableUpload.partSize = 1024 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; NSString * docDir = [NSString oss_documentDirectory]; resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file1k"]]; @@ -738,6 +777,7 @@ - (void)testResumableUploadSmallFile { BOOL isEqual = [self isFileOnOSSBucket:_privateBucketName objectKey:OSS_MULTIPART_UPLOADKEY equalsToLocalFile:[resumableUpload.uploadingFileURL path]]; XCTAssertTrue(isEqual); + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testResumableUploadResumeUpload { @@ -765,6 +805,7 @@ - (void)testResumableUploadResumeUpload { XCTAssertEqual(OSSClientErrorCodeTaskCancelled, task.error.code); return nil; }] waitUntilFinished]; + resumableUpload = [OSSResumableUploadRequest new]; resumableUpload.bucketName = _privateBucketName; @@ -787,7 +828,6 @@ - (void)testResumableUploadResumeUpload { return nil; }] waitUntilFinished]; - BOOL isEqual = [self isFileOnOSSBucket:_privateBucketName objectKey:OSS_MULTIPART_UPLOADKEY equalsToLocalFile:[resumableUpload.uploadingFileURL path]]; XCTAssertTrue(isEqual); } @@ -802,8 +842,10 @@ - (void)testResumableUploadwithinvalidpartSize { resumableUpload.contentType = @"application/octet-stream"; resumableUpload.completeMetaHeader = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; resumableUpload.partSize = 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; NSString * docDir = [NSString oss_documentDirectory]; resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file10m"]]; @@ -814,6 +856,7 @@ - (void)testResumableUploadwithinvalidpartSize { NSLog(@"task.error: %@", task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testResumableUploadWithNotSetRecordPath{ @@ -822,8 +865,10 @@ - (void)testResumableUploadWithNotSetRecordPath{ resumableUpload.objectKey = OSS_MULTIPART_UPLOADKEY; resumableUpload.contentType = @"application/octet-stream"; resumableUpload.completeMetaHeader = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; OSSTask * resumeTask = [client resumableUpload:resumableUpload]; @@ -833,6 +878,7 @@ - (void)testResumableUploadWithNotSetRecordPath{ XCTAssertTrue(![[NSFileManager defaultManager] fileExistsAtPath:recordFilePath]); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } #pragma mark concurrent diff --git a/AliyunOSSiOSTests/OSSBucketTests.m b/AliyunOSSiOSTests/OSSBucketTests.m index 9a35d7b8..093e017d 100644 --- a/AliyunOSSiOSTests/OSSBucketTests.m +++ b/AliyunOSSiOSTests/OSSBucketTests.m @@ -102,6 +102,16 @@ - (void)testAPI_getService XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + + OSSGetServiceResult *result = nil; + do { + request = [OSSGetServiceRequest new]; + request.maxKeys = 2; + request.marker = result.nextMarker; + task = [_client getService:request]; + [task waitUntilFinished]; + result = task.result; + } while (result.isTruncated); } - (void)testAPI_deleteBucket diff --git a/AliyunOSSiOSTests/OSSCrc64Tests.m b/AliyunOSSiOSTests/OSSCrc64Tests.m index 618794f1..26d38275 100644 --- a/AliyunOSSiOSTests/OSSCrc64Tests.m +++ b/AliyunOSSiOSTests/OSSCrc64Tests.m @@ -109,9 +109,10 @@ - (void)test_putObjectWithCrc64Check request.objectKey = objectKey; request.uploadingFileURL = fileURL; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; - + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"bytesSent: %lld, totalByteSent: %lld, totalBytesExpectedToSend: %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -119,6 +120,7 @@ - (void)test_putObjectWithCrc64Check XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } } @@ -130,8 +132,10 @@ - (void)testA_appendObject{ request.objectKey = @"appendObject"; request.appendPosition = 0; request.uploadingFileURL = [NSURL fileURLWithPath:filePath]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; __block int64_t nextAppendPosition = 0; @@ -144,13 +148,16 @@ - (void)testA_appendObject{ lastCrc64ecma = result.remoteCRC64ecma; return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); request.bucketName = _privateBucketName; request.objectKey = @"appendObject"; request.appendPosition = nextAppendPosition; request.uploadingFileURL = [NSURL fileURLWithPath:filePath]; + progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; task = [_client appendObject:request withCrc64ecma:lastCrc64ecma]; @@ -158,6 +165,7 @@ - (void)testA_appendObject{ XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)test_getObject @@ -211,8 +219,10 @@ - (void)test_MultipartUploadNormal { multipartUploadRequest.bucketName = _privateBucketName; multipartUploadRequest.objectKey = objectkey; multipartUploadRequest.partSize = 1024 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; multipartUploadRequest.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; OSSTask * multipartTask = [_client multipartUpload:multipartUploadRequest]; @@ -229,6 +239,7 @@ - (void)test_MultipartUploadNormal { } return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } @@ -270,11 +281,13 @@ - (void)test_resumbleUploadCancelResumble { resumableUpload.recordDirectoryPath = cachesDir; resumableUpload.partSize = 100 * 1024; resumableUpload.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"bigfile" withExtension:@"zip"]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); if (bytesSent != 0) { XCTAssertTrue(totalByteSent / bytesSent >= 1000); } + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; resumeTask = [_client resumableUpload:resumableUpload]; [[resumeTask continueWithBlock:^id(OSSTask *task) { @@ -284,7 +297,7 @@ - (void)test_resumbleUploadCancelResumble { XCTAssertTrue(![[NSFileManager defaultManager] fileExistsAtPath:recordFilePath]); return nil; }] waitUntilFinished]; - + XCTAssertTrue([progressTest completeValidateProgress]); } - (NSString *)getRecordFilePath:(OSSResumableUploadRequest *)resumableUpload { diff --git a/AliyunOSSiOSTests/OSSModelTests.m b/AliyunOSSiOSTests/OSSModelTests.m index 48e965da..fa3ed467 100644 --- a/AliyunOSSiOSTests/OSSModelTests.m +++ b/AliyunOSSiOSTests/OSSModelTests.m @@ -10,6 +10,9 @@ #import #import +@import AliyunOSSiOS.OSSAllRequestNeededMessage; +@import AliyunOSSiOS.OSSDefine; + @interface OSSModelTests : XCTestCase @end @@ -44,4 +47,28 @@ - (void)testForOSSSyncMutableDictionary XCTAssertNotNil(syncMutableDict.allKeys); } +- (void)testForOSSUASettingInterceptorWithNotAllowUACarrySystemInfo { + NSString *ua = @"User-Agent"; + NSString *location = [[NSLocale currentLocale] localeIdentifier]; + + OSSClientConfiguration *clientConfig = [OSSClientConfiguration new]; + clientConfig.isAllowUACarrySystemInfo = NO; + OSSUASettingInterceptor *interceptor = [[OSSUASettingInterceptor alloc] initWithClientConfiguration:clientConfig]; + + OSSAllRequestNeededMessage *allRequestMessage = [OSSAllRequestNeededMessage new]; + [interceptor interceptRequestMessage:allRequestMessage]; + NSString *expectValue = [NSString stringWithFormat:@"%@/%@(/%@)", OSSUAPrefix, OSSSDKVersion, location]; + XCTAssertTrue([allRequestMessage.headerParams[ua] isEqualToString:expectValue]); + + clientConfig = [OSSClientConfiguration new]; + clientConfig.isAllowUACarrySystemInfo = NO; + clientConfig.userAgentMark = @"userAgent"; + interceptor = [[OSSUASettingInterceptor alloc] initWithClientConfiguration:clientConfig]; + + allRequestMessage = [OSSAllRequestNeededMessage new]; + [interceptor interceptRequestMessage:allRequestMessage]; + expectValue = [NSString stringWithFormat:@"%@/%@(/%@)/%@", OSSUAPrefix, OSSSDKVersion, location, clientConfig.userAgentMark]; + XCTAssertTrue([allRequestMessage.headerParams[ua] isEqualToString:expectValue]); +} + @end diff --git a/AliyunOSSiOSTests/OSSObjectTests.m b/AliyunOSSiOSTests/OSSObjectTests.m index c9d443b1..1803bac1 100644 --- a/AliyunOSSiOSTests/OSSObjectTests.m +++ b/AliyunOSSiOSTests/OSSObjectTests.m @@ -146,9 +146,10 @@ - (void)testAPI_putObjectFromNSData request.uploadingData = [readFile readDataToEndOfFile]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); - + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -156,6 +157,7 @@ - (void)testAPI_putObjectFromNSData XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_putObjectFromFile @@ -174,8 +176,10 @@ - (void)testAPI_putObjectFromFile // 在统一config 中修改 // request.crcFlag = OSSRequestCRCOpen; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"bytesSent: %lld, totalByteSent: %lld, totalBytesExpectedToSend: %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -187,6 +191,7 @@ - (void)testAPI_putObjectFromFile XCTAssertTrue(isEqual); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } } @@ -227,8 +232,10 @@ - (void)testAPI_putObjectWithoutContentType // request.crcFlag = OSSRequestCRCOpen; request.uploadingData = [readFile readDataToEndOfFile]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"bytesSent: %lld, totalByteSent: %lld, totalBytesExpectedToSend: %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; request.contentType = @""; @@ -238,6 +245,7 @@ - (void)testAPI_putObjectWithoutContentType XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); OSSHeadObjectRequest * head = [OSSHeadObjectRequest new]; head.bucketName = _privateBucketName; @@ -270,8 +278,10 @@ - (void)testAPI_putObjectWithContentType request.uploadingData = [readFile readDataToEndOfFile]; request.contentType = @"application/special"; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -284,6 +294,7 @@ - (void)testAPI_putObjectWithContentType XCTAssertEqual(200, result.httpResponseCode); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); OSSHeadObjectRequest * head = [OSSHeadObjectRequest new]; head.bucketName = _privateBucketName; @@ -319,8 +330,10 @@ - (void)testAPI_putObjectWithServerCallback @"var1": @"value1", @"var2": @"value2" }; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -328,6 +341,7 @@ - (void)testAPI_putObjectWithServerCallback XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_putObjectACL @@ -381,8 +395,10 @@ - (void)testAPI_appendObject request.objectKey = @"appendObject"; request.appendPosition = 0; request.uploadingFileURL = [NSURL fileURLWithPath:filePath]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; __block int64_t nextAppendPosition = 0; @@ -395,13 +411,16 @@ - (void)testAPI_appendObject lastCrc64ecma = result.remoteCRC64ecma; return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); request.bucketName = _privateBucketName; request.objectKey = @"appendObject"; request.appendPosition = nextAppendPosition; request.uploadingFileURL = [NSURL fileURLWithPath:filePath]; + progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; task = [_client appendObject:request withCrc64ecma:lastCrc64ecma]; @@ -409,6 +428,7 @@ - (void)testAPI_appendObject XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } #pragma mark - getObject @@ -1003,8 +1023,10 @@ - (void)testAPI_PutObjectWithErrorRetry request.uploadingData = [readFile readDataToEndOfFile]; request.contentMd5 = [OSSUtil base64Md5ForData:request.uploadingData]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; request.uploadRetryCallback = ^{ NSLog(@"put object call retry"); @@ -1015,7 +1037,8 @@ - (void)testAPI_PutObjectWithErrorRetry XCTAssertNil(task.error); return nil; }] waitUntilFinished]; - + XCTAssertTrue([progressTest completeValidateProgress]); + BOOL isEqual = [self checkMd5WithBucketName:_privateBucketName objectKey:fileName localFilePath:filePath]; @@ -1060,8 +1083,10 @@ - (void)testAPI_putObjectWithCheckingDataMd5 request.uploadingData = [readFile readDataToEndOfFile]; request.contentMd5 = [OSSUtil base64Md5ForData:request.uploadingData]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -1069,6 +1094,7 @@ - (void)testAPI_putObjectWithCheckingDataMd5 XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_putObjectWithCheckingFileMd5 @@ -1085,9 +1111,10 @@ - (void)testAPI_putObjectWithCheckingFileMd5 request.uploadingFileURL = fileURL; request.contentMd5 = [OSSUtil base64Md5ForFilePath:fileURL.path]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); - + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -1095,6 +1122,7 @@ - (void)testAPI_putObjectWithCheckingFileMd5 XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_putObjectWithInvalidMd5 @@ -1111,8 +1139,10 @@ - (void)testAPI_putObjectWithInvalidMd5 request.uploadingFileURL = fileURL; request.contentMd5 = @"invliadmd5valuetotest"; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -1121,6 +1151,7 @@ - (void)testAPI_putObjectWithInvalidMd5 XCTAssertEqual(-1 * 400, task.error.code); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_customExcludeCname @@ -1184,8 +1215,8 @@ - (void)testAPI_cancelPutObejct cancelled = YES; return nil; }]; - - [NSThread sleepForTimeInterval:1]; + + [NSThread sleepForTimeInterval:0.1]; [request cancel]; [NSThread sleepForTimeInterval:1]; XCTAssertTrue(cancelled); @@ -1213,7 +1244,7 @@ - (void)testAPI_cancelGetObject return nil; }]; - [NSThread sleepForTimeInterval:1]; + [NSThread sleepForTimeInterval:0.1]; [request cancel]; [NSThread sleepForTimeInterval:1]; XCTAssertTrue(completed); @@ -1337,8 +1368,10 @@ - (void)testAPI_putObjectWithErrorOfInvalidBucketName NSURL * fileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file1m"]]; request.uploadingFileURL = fileURL; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -1347,6 +1380,7 @@ - (void)testAPI_putObjectWithErrorOfInvalidBucketName XCTAssertEqual(OSSClientErrorCodeInvalidArgument, task.error.code); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_putObjectWithErrorOfInvalidKey @@ -1359,8 +1393,10 @@ - (void)testAPI_putObjectWithErrorOfInvalidKey NSURL * fileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file1m"]]; request.uploadingFileURL = fileURL; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -1369,6 +1405,7 @@ - (void)testAPI_putObjectWithErrorOfInvalidKey XCTAssertEqual(OSSClientErrorCodeInvalidArgument, task.error.code); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_getObjectWithErrorOfAccessDenied @@ -1416,8 +1453,10 @@ - (void)testAPI_putObjectWithErrorOfNoSource request.bucketName = _privateBucketName; request.objectKey = @"file1m"; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [_client putObject:request]; @@ -1427,6 +1466,7 @@ - (void)testAPI_putObjectWithErrorOfNoSource XCTAssertEqual(OSSClientErrorCodeInvalidArgument, task.error.code); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_putObjectWithErrorOfNoCredentialProvier @@ -1443,8 +1483,10 @@ - (void)testAPI_putObjectWithErrorOfNoCredentialProvier request.uploadingData = [readFile readDataToEndOfFile]; request.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"value1", @"x-oss-meta-name1", nil]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; request.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * task = [tempClient putObject:request]; @@ -1456,7 +1498,8 @@ - (void)testAPI_putObjectWithErrorOfNoCredentialProvier task = [tempClient presignConstrainURLWithBucketName:_privateBucketName withObjectKey:@"file1m" withExpirationInterval:3600]; [task waitUntilFinished]; - XCTAssertTrue([OSSClientErrorDomain isEqualToString:task.error.domain]); + XCTAssertTrue([OSSClientErrorDomain isEqualToString:task.error.domain]); + XCTAssertTrue([progressTest completeValidateProgress]); } #pragma mark - cname @@ -1738,8 +1781,10 @@ - (void)testAPI_multipartRequestWithoutUploadingURL { multipartUploadRequest.objectKey = OSS_MULTIPART_UPLOADKEY; multipartUploadRequest.contentType = @"application/octet-stream"; multipartUploadRequest.partSize = 1024 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * multipartTask = [_client multipartUpload:multipartUploadRequest]; @@ -1747,6 +1792,7 @@ - (void)testAPI_multipartRequestWithoutUploadingURL { XCTAssertNotNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_multipartRequest_concurrently { @@ -1761,14 +1807,17 @@ - (void)testAPI_multipartRequest_concurrently { multipartUploadRequest.contentType = @"application/octet-stream"; multipartUploadRequest.uploadingFileURL = [NSURL fileURLWithPath:[[NSString oss_documentDirectory] stringByAppendingPathComponent:@"file5m"]]; multipartUploadRequest.partSize = 256 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { XCTAssertTrue(totalBytesExpectedToSend >= totalByteSent); - }; + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; + }; [queue addOperationWithBlock:^{ OSSTask * task = [_client multipartUpload:multipartUploadRequest]; [task waitUntilFinished]; XCTAssertNotNil(task.result); + XCTAssertTrue([progressTest completeValidateProgress]); }]; } [queue waitUntilAllOperationsAreFinished]; @@ -1781,8 +1830,11 @@ - (void)testAPI_multipartRequestWithWrongFileURL { multipartUploadRequest.objectKey = OSS_MULTIPART_UPLOADKEY; multipartUploadRequest.contentType = @"application/octet-stream"; multipartUploadRequest.partSize = 1024 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { + XCTAssertTrue(totalByteSent <= totalBytesExpectedToSend); NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; multipartUploadRequest.uploadingFileURL = [NSURL URLWithString:@"http://www.alibaba-inc.com"]; @@ -1794,6 +1846,7 @@ - (void)testAPI_multipartRequestWithWrongFileURL { return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_multipartRequestWithUnexistFileURL { @@ -1803,8 +1856,10 @@ - (void)testAPI_multipartRequestWithUnexistFileURL { multipartUploadRequest.objectKey = OSS_MULTIPART_UPLOADKEY; multipartUploadRequest.contentType = @"application/octet-stream"; multipartUploadRequest.partSize = 1024 * 1024; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; NSString * docDir = [NSString oss_documentDirectory]; multipartUploadRequest.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"unexistfile"]]; @@ -1815,6 +1870,7 @@ - (void)testAPI_multipartRequestWithUnexistFileURL { XCTAssertNotNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_multipartRequestWithoutPartSize { @@ -1824,8 +1880,10 @@ - (void)testAPI_multipartRequestWithoutPartSize { multipartUploadRequest.objectKey = OSS_MULTIPART_UPLOADKEY; multipartUploadRequest.contentType = @"application/octet-stream"; multipartUploadRequest.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * multipartTask = [_client multipartUpload:multipartUploadRequest]; @@ -1833,6 +1891,7 @@ - (void)testAPI_multipartRequestWithoutPartSize { XCTAssertNil(task.error); return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_multipartRequestWithoutObjectKey { @@ -1843,8 +1902,10 @@ - (void)testAPI_multipartRequestWithoutObjectKey { multipartUploadRequest.partSize = 1024 * 1024; multipartUploadRequest.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * multipartTask = [_client multipartUpload:multipartUploadRequest]; @@ -1853,6 +1914,7 @@ - (void)testAPI_multipartRequestWithoutObjectKey { return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_multipartRequestWithoutBucketName { @@ -1862,8 +1924,10 @@ - (void)testAPI_multipartRequestWithoutBucketName { multipartUploadRequest.objectKey = OSS_MULTIPART_UPLOADKEY; multipartUploadRequest.partSize = 1024 * 1024; multipartUploadRequest.uploadingFileURL = [[NSBundle mainBundle] URLForResource:@"wangwang" withExtension:@"zip"]; + OSSProgressTestUtils *progressTest = [OSSProgressTestUtils new]; multipartUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"progress: %lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); + [progressTest updateTotalBytes:totalByteSent totalBytesExpected:totalBytesExpectedToSend]; }; OSSTask * multipartTask = [_client multipartUpload:multipartUploadRequest]; @@ -1872,6 +1936,7 @@ - (void)testAPI_multipartRequestWithoutBucketName { return nil; }] waitUntilFinished]; + XCTAssertTrue([progressTest completeValidateProgress]); } - (void)testAPI_dataTaskAndUploadTaskSimultaneously { diff --git a/AliyunOSSiOSTests/OSSTestUtils.h b/AliyunOSSiOSTests/OSSTestUtils.h index fc3c79bb..fc212ac2 100644 --- a/AliyunOSSiOSTests/OSSTestUtils.h +++ b/AliyunOSSiOSTests/OSSTestUtils.h @@ -13,3 +13,10 @@ + (void)cleanBucket: (NSString *)bucket with: (OSSClient *)client; + (void) putTestDataWithKey: (NSString *)key withClient: (OSSClient *)client withBucket: (NSString *)bucket; @end + +@interface OSSProgressTestUtils : NSObject + +- (void)updateTotalBytes:(int64_t)totalBytesSent totalBytesExpected:(int64_t)totalBytesExpectedToSend; +- (BOOL)completeValidateProgress; + +@end diff --git a/AliyunOSSiOSTests/OSSTestUtils.m b/AliyunOSSiOSTests/OSSTestUtils.m index 59ae09d2..7e390e90 100644 --- a/AliyunOSSiOSTests/OSSTestUtils.m +++ b/AliyunOSSiOSTests/OSSTestUtils.m @@ -7,6 +7,7 @@ // #import "OSSTestUtils.h" +#import @implementation OSSTestUtils + (void)cleanBucket: (NSString *)bucket with: (OSSClient *)client { @@ -71,3 +72,23 @@ + (void) putTestDataWithKey: (NSString *)key withClient: (OSSClient *)client wit } @end + +@interface OSSProgressTestUtils() + +@property (nonatomic, assign) int64_t totalBytesSent; +@property (nonatomic, assign) int64_t totalBytesExpectedToSend; + +@end + +@implementation OSSProgressTestUtils + +- (void)updateTotalBytes:(int64_t)totalBytesSent totalBytesExpected:(int64_t)totalBytesExpectedToSend { + XCTAssertTrue(totalBytesSent <= totalBytesExpectedToSend); + self.totalBytesSent = totalBytesSent; + self.totalBytesExpectedToSend = totalBytesExpectedToSend; +} +- (BOOL)completeValidateProgress { + return self.totalBytesSent == self.totalBytesExpectedToSend; +} + +@end