ASIWebPageRequestTests.m
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// ASIWebPageRequestTests.m
// Mac
//
// Created by Ben Copsey on 06/01/2011.
// Copyright 2011 All-Seeing Interactive. All rights reserved.
//
#import "ASIWebPageRequestTests.h"
#import "ASIWebPageRequest.h"
@implementation ASIWebPageRequestTests
- (void)testEncoding
{
NSArray *encodings = [NSArray arrayWithObjects:@"us-ascii",@"iso-8859-1",@"utf-16",@"utf-8",nil];
NSArray *expectedResponses = [NSArray arrayWithObjects:@"Hi there",@"Olá",@"你好",@"今日は",nil];
NSUInteger i;
for (i=0; i<[encodings count]; i++) {
ASIWebPageRequest *request = [ASIWebPageRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://allseeing-i.com/ASIHTTPRequest/tests/asiwebpagerequest/character-encoding/%@",[encodings objectAtIndex:i]]]];
[request setUserInfo:[NSDictionary dictionaryWithObject:[expectedResponses objectAtIndex:i] forKey:@"expected-response"]];
[request setDelegate:self];
[request setUrlReplacementMode:ASIReplaceExternalResourcesWithLocalURLs];
[request startAsynchronous];
}
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
if ([[request userInfo] objectForKey:@"expected-response"]) {
BOOL success = ([[request responseString] rangeOfString:[[request userInfo] objectForKey:@"expected-response"]].location != NSNotFound);
GHAssertTrue(success,@"Response HTML used wrong encoding");
}
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
GHAssertNil([request error],@"Request failed, cannot proceed with test");
}
@end