This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
303 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
// AFHTTPSerializationTests.m | ||
// | ||
// AFHTTPSerializationTests.m | ||
// AFNetworking Tests | ||
// Copyright (c) 2013 AFNetworking (http://afnetworking.com) | ||
// | ||
// Created by Kevin Harwood on 9/10/13. | ||
// Copyright (c) 2013 AFNetworking. All rights reserved. | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "AFTestCase.h" | ||
|
||
@interface AFHTTPSerializationTests : AFTestCase | ||
#import "AFSerialization.h" | ||
|
||
@interface AFHTTPSerializationTests : AFTestCase | ||
@end | ||
|
||
@implementation AFHTTPSerializationTests | ||
|
||
-(void)testThatAFHTTPResponseSerializationHandlesAll2XXCodes{ | ||
- (void)testThatAFHTTPResponseSerializationHandlesAll2XXCodes { | ||
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)]; | ||
[indexSet | ||
enumerateIndexesUsingBlock:^(NSUInteger statusCode, BOOL *stop) { | ||
NSHTTPURLResponse * response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL | ||
statusCode:statusCode | ||
HTTPVersion:@"1.1" | ||
headerFields:@{@"Content-Type":@"text/html"}]; | ||
AFHTTPResponseSerializer * serializer = [AFHTTPResponseSerializer serializer]; | ||
NSError * error = nil; | ||
[serializer validateResponse:response | ||
data:[@"text" dataUsingEncoding:NSUTF8StringEncoding] | ||
error:&error]; | ||
XCTAssertNil(error, @"Error handling status code %d",statusCode); | ||
}]; | ||
[indexSet enumerateIndexesUsingBlock:^(NSUInteger statusCode, BOOL *stop) { | ||
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}]; | ||
|
||
AFHTTPResponseSerializer *serializer = [AFHTTPResponseSerializer serializer]; | ||
XCTAssert([serializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %d should be acceptable"); | ||
|
||
NSError *error = nil; | ||
[serializer validateResponse:response data:[@"text" dataUsingEncoding:NSUTF8StringEncoding] error:&error]; | ||
|
||
XCTAssertNil(error, @"Error handling status code %d", statusCode); | ||
}]; | ||
} | ||
|
||
-(void)testThatAFHTTPResponseSerializationFailsAll4XX5XXStatusCodes{ | ||
- (void)testThatAFHTTPResponseSerializationFailsAll4XX5XXStatusCodes { | ||
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(400, 200)]; | ||
[indexSet | ||
enumerateIndexesUsingBlock:^(NSUInteger statusCode, BOOL *stop) { | ||
NSHTTPURLResponse * response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL | ||
statusCode:statusCode | ||
HTTPVersion:@"1.1" | ||
headerFields:@{@"Content-Type":@"text/html"}]; | ||
AFHTTPResponseSerializer * serializer = [AFHTTPResponseSerializer serializer]; | ||
NSError * error = nil; | ||
[serializer validateResponse:response | ||
data:[@"text" dataUsingEncoding:NSUTF8StringEncoding] | ||
error:&error]; | ||
XCTAssertNotNil(error, @"Did not fail handling status code %d",statusCode); | ||
}]; | ||
[indexSet enumerateIndexesUsingBlock:^(NSUInteger statusCode, BOOL *stop) { | ||
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}]; | ||
|
||
AFHTTPResponseSerializer *serializer = [AFHTTPResponseSerializer serializer]; | ||
XCTAssert(![serializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %d should not be acceptable"); | ||
|
||
NSError *error = nil; | ||
[serializer validateResponse:response data:[@"text" dataUsingEncoding:NSUTF8StringEncoding] error:&error]; | ||
|
||
XCTAssertNotNil(error, @"Did not fail handling status code %d",statusCode); | ||
}]; | ||
} | ||
|
||
@end |
Oops, something went wrong.