Add tests for the responseStringEncoding property

This commit is contained in:
Cédric Luthi 2013-05-21 17:51:39 +02:00
parent efb36aaa99
commit 8d8beb8d01

View file

@ -147,6 +147,8 @@
expect(numberOfRedirects).will.equal(5);
}
#pragma mark - Pause
- (void)testThatOperationCanBePaused{
[Expecta setAsynchronousTestTimeout:3.0];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/1" relativeToURL:self.baseURL]];
@ -197,4 +199,38 @@
expect(blockResponseObject).willNot.beNil();
}
#pragma mark - Response String Encoding
- (void) testThatTextStringEncodingIsISOLatin1WhenNoCharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSISOLatin1StringEncoding);
}
- (void) testThatTextStringEncodingIsShiftJISWhenShiftJISCharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22Shift_JIS%22" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSShiftJISStringEncoding);
}
- (void) testThatTextStringEncodingIsUTF8WhenInvalidCharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22invalid%22" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding);
}
- (void) testThatTextStringEncodingIsUTF8WhenUTF8CharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22UTF-8%22" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding);
}
@end