Refactoring image request tests
This commit is contained in:
parent
ea23240fbb
commit
52a8a94b66
2 changed files with 63 additions and 18 deletions
|
|
@ -112,8 +112,7 @@
|
||||||
|
|
||||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
|
||||||
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
||||||
[operation setCompletionBlockWithSuccess:nil
|
[operation setCompletionBlockWithSuccess:nil failure:nil];
|
||||||
failure:nil];
|
|
||||||
[operation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
|
[operation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
|
||||||
if(redirectResponse){
|
if(redirectResponse){
|
||||||
success = YES;
|
success = YES;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// AFHTTPRequestOperationTests.m
|
// AFImageRequestOperationTests.m
|
||||||
//
|
//
|
||||||
// Copyright (c) 2013 AFNetworking (http://afnetworking.com)
|
// Copyright (c) 2013 AFNetworking (http://afnetworking.com)
|
||||||
//
|
//
|
||||||
|
|
@ -35,10 +35,58 @@
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
- (void)testThatImageRequestOperationAcceptsCorrectFormatTypes {
|
- (void)testThatImageRequestOperationAcceptsTIFFContentType {
|
||||||
NSArray *acceptedFormats = @[@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap"];
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/tiff" relativeToURL:self.baseURL]];
|
||||||
for (NSString *format in acceptedFormats) {
|
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
||||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"/response-headers?Content-Type=%@", format] relativeToURL:self.baseURL]];
|
[operation start];
|
||||||
|
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(operation.error).will.beNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatImageRequestOperationAcceptsJPEGContentType {
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/jpeg" relativeToURL:self.baseURL]];
|
||||||
|
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
||||||
|
[operation start];
|
||||||
|
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(operation.error).will.beNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatImageRequestOperationAcceptsGIFContentType {
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/gif" relativeToURL:self.baseURL]];
|
||||||
|
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
||||||
|
[operation start];
|
||||||
|
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(operation.error).will.beNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatImageRequestOperationAcceptsPNGContentType {
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/png" relativeToURL:self.baseURL]];
|
||||||
|
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
||||||
|
[operation start];
|
||||||
|
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(operation.error).will.beNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatImageRequestOperationAcceptsIconContentTypes {
|
||||||
|
NSArray *acceptableIconContentTypes = @[@"image/ico", @"image/x-icon"];
|
||||||
|
for (NSString *contentType in acceptableIconContentTypes) {
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"/response-headers?Content-Type=%@", contentType] relativeToURL:self.baseURL]];
|
||||||
|
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
||||||
|
[operation start];
|
||||||
|
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(operation.error).will.beNil();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatImageRequestOperationAcceptsBitmapContentTypes {
|
||||||
|
NSArray *acceptableBitmapContentTypes = @[@"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap"];
|
||||||
|
for (NSString *contentType in acceptableBitmapContentTypes) {
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"/response-headers?Content-Type=%@", contentType] relativeToURL:self.baseURL]];
|
||||||
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
||||||
[operation start];
|
[operation start];
|
||||||
|
|
||||||
|
|
@ -48,7 +96,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatImageRequestOperationDoesNotAcceptInvalidFormatTypes {
|
- (void)testThatImageRequestOperationDoesNotAcceptInvalidFormatTypes {
|
||||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/badFormat" relativeToURL:self.baseURL]];
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/invalid" relativeToURL:self.baseURL]];
|
||||||
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
|
||||||
[operation start];
|
[operation start];
|
||||||
|
|
||||||
|
|
@ -75,20 +123,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testImageProcessingBlockIsRunOnSuccess {
|
- (void)testImageProcessingBlockIsRunOnSuccess {
|
||||||
__block UIImage *blockImage = nil;
|
__block BOOL imageProcessingBlockExecuted = NO;
|
||||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/png" relativeToURL:self.baseURL]];
|
|
||||||
|
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=image/png" relativeToURL:self.baseURL]];
|
||||||
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:^UIImage *(UIImage *image) {
|
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:^UIImage *(UIImage *image) {
|
||||||
blockImage = [[UIImage alloc] init];
|
imageProcessingBlockExecuted = YES;
|
||||||
return blockImage;
|
return image;
|
||||||
} success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
|
} success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
|
||||||
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
return;
|
||||||
}];
|
} failure:nil];
|
||||||
|
|
||||||
[operation start];
|
[operation start];
|
||||||
expect([operation isFinished]).will.beTruthy();
|
expect([operation isFinished]).will.beTruthy();
|
||||||
expect(operation.error).will.beNil();
|
expect(operation.error).will.beNil();
|
||||||
expect(blockImage).willNot.beNil();
|
expect(imageProcessingBlockExecuted).will.beTruthy();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testImageProcessingBlockIsNotRunOnFailure {
|
- (void)testImageProcessingBlockIsNotRunOnFailure {
|
||||||
|
|
@ -98,9 +146,7 @@
|
||||||
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:^UIImage *(UIImage *image) {
|
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:^UIImage *(UIImage *image) {
|
||||||
blockImage = [[UIImage alloc] init];
|
blockImage = [[UIImage alloc] init];
|
||||||
return blockImage;
|
return blockImage;
|
||||||
} success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
|
} success:nil failure:nil];
|
||||||
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
|
||||||
}];
|
|
||||||
[operation start];
|
[operation start];
|
||||||
|
|
||||||
expect([operation isFinished]).will.beTruthy();
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue