Skip to content

Commit

Permalink
Add tests for the responseStringEncoding property
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed May 21, 2013
1 parent efb36aa commit 8d8beb8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Tests/AFHTTPRequestOperationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ - (void)testThatRedirectBlockIsCalledMultipleTimesWhenMultiple302sAreEncountered
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]];
Expand Down Expand Up @@ -197,4 +199,38 @@ - (void)testThatPausedOperationCanBeCompleted{
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

0 comments on commit 8d8beb8

Please sign in to comment.