Skip to content

Commit 871ef57

Browse files
committed
throw excption when no completion handler
1 parent 9031940 commit 871ef57

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

QiniuSDK/Storage/QNUploadManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ + (BOOL)checkAndNotifyError:(NSString*)key
6262
complete:(QNUpCompletionHandler)completionHandler {
6363
NSString *desc = nil;
6464
if (completionHandler == nil) {
65-
// todo throe excetpion
66-
//NSException *e = [NSEx];
65+
@throw [NSException exceptionWithName:NSInvalidArgumentException
66+
reason:@"no completionHandler" userInfo:nil];
6767
return YES;
6868
}
6969
if (data == nil && file == nil) {

QiniuSDKTests/QNFormUploadTest.m

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,83 @@ - (void)testUpUnAuth {
6565
XCTAssert(testInfo.reqId, @"Pass");
6666
}
6767

68+
- (void)testNoData {
69+
__block QNResponseInfo *testInfo = nil;
70+
__block NSDictionary *testResp = nil;
71+
NSString *token = @"noauth";
72+
[self.upManager putData:nil key:@"hello" token:token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
73+
testInfo = info;
74+
testResp = resp;
75+
} option:nil];
76+
77+
AGWW_WAIT_WHILE(testInfo == nil, 100.0);
78+
NSLog(@"%@", testInfo);
79+
XCTAssert(testInfo.statusCode == kQNInvalidArgument, @"Pass");
80+
}
81+
82+
- (void)testNoFile {
83+
__block QNResponseInfo *testInfo = nil;
84+
__block NSDictionary *testResp = nil;
85+
NSString *token = @"noauth";
86+
[self.upManager putFile:nil key:@"hello" token:token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
87+
testInfo = info;
88+
testResp = resp;
89+
} option:nil];
90+
91+
AGWW_WAIT_WHILE(testInfo == nil, 100.0);
92+
NSLog(@"%@", testInfo);
93+
XCTAssert(testInfo.statusCode == kQNInvalidArgument, @"Pass");
94+
}
95+
96+
97+
- (void)testNoToken {
98+
__block QNResponseInfo *testInfo = nil;
99+
__block NSDictionary *testResp = nil;
100+
NSData *data = [@"Hello, World!" dataUsingEncoding : NSUTF8StringEncoding];
101+
[self.upManager putData:data key:@"hello" token:nil complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
102+
testInfo = info;
103+
testResp = resp;
104+
} option:nil];
105+
106+
AGWW_WAIT_WHILE(testInfo == nil, 100.0);
107+
NSLog(@"%@", testInfo);
108+
XCTAssert(testInfo.statusCode == kQNInvalidArgument, @"Pass");
109+
110+
testInfo = nil;
111+
testResp = nil;
112+
[self.upManager putData:data key:@"hello" token:@"" complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
113+
testInfo = info;
114+
testResp = resp;
115+
} option:nil];
116+
117+
AGWW_WAIT_WHILE(testInfo == nil, 100.0);
118+
NSLog(@"%@", testInfo);
119+
XCTAssert(testInfo.statusCode == kQNInvalidArgument, @"Pass");
120+
121+
testInfo = nil;
122+
testResp = nil;
123+
[self.upManager putData:nil key:@"hello" token:nil complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
124+
testInfo = info;
125+
testResp = resp;
126+
} option:nil];
127+
128+
AGWW_WAIT_WHILE(testInfo == nil, 100.0);
129+
NSLog(@"%@", testInfo);
130+
XCTAssert(testInfo.statusCode == kQNInvalidArgument, @"Pass");
131+
}
132+
133+
- (void)testNoComplete {
134+
NSException *e;
135+
@try {
136+
[self.upManager putFile:nil key:nil token:nil complete: nil option:nil]; }
137+
@catch (NSException *exception) {
138+
e = exception;
139+
}
140+
141+
XCTAssert(e != nil, @"Pass");
142+
XCTAssert([e.name isEqualToString:NSInvalidArgumentException], @"Pass");
143+
}
144+
145+
146+
68147
@end

0 commit comments

Comments
 (0)