/Source/externals/GData/Source/HTTPFetcher/Tests/GTMHTTPFetcherUtilityTest.m
http://google-email-uploader-mac.googlecode.com/ · Objective C · 121 lines · 83 code · 18 blank · 20 comment · 1 complexity · 7881ffb29d9a9954339b2799196aec7c MD5 · raw file
- /* Copyright (c) 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #import <XCTest/XCTest.h>
- #import "GTMHTTPFetcher.h"
- #import "GTMHTTPFetcherLogging.h"
- @interface GTMHTTPFetcherUtilityTest : XCTestCase
- @end
- @interface GTMHTTPFetcher (GTMHTTPFetcherLoggingInternal)
- + (NSString *)snipSubstringOfString:(NSString *)originalStr
- betweenStartString:(NSString *)startStr
- endString:(NSString *)endStr;
- @end
- @implementation GTMHTTPFetcherUtilityTest
- #if !STRIP_GTM_FETCH_LOGGING
- - (void)testLogSnipping {
- // enpty string
- NSString *orig = @"";
- NSString *expected = orig;
- NSString *result = [GTMHTTPFetcher snipSubstringOfString:orig
- betweenStartString:@"jkl"
- endString:@"mno"];
- XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
- // snip the middle
- orig = @"abcdefg";
- expected = @"abcd_snip_fg";
- result = [GTMHTTPFetcher snipSubstringOfString:orig
- betweenStartString:@"abcd"
- endString:@"fg"];
- XCTAssertEqualObjects(result, expected, @"simple snip in the middle failure");
- // snip to the end
- orig = @"abcdefg";
- expected = @"abcd_snip_";
- result = [GTMHTTPFetcher snipSubstringOfString:orig
- betweenStartString:@"abcd"
- endString:@"xyz"];
- XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
- // start string not found, so nothing should be snipped
- orig = @"abcdefg";
- expected = orig;
- result = [GTMHTTPFetcher snipSubstringOfString:orig
- betweenStartString:@"jkl"
- endString:@"mno"];
- XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
- // nothing between start and end
- orig = @"abcdefg";
- expected = @"abcd_snip_efg";
- result = [GTMHTTPFetcher snipSubstringOfString:orig
- betweenStartString:@"abcd"
- endString:@"efg"];
- XCTAssertEqualObjects(result, expected, @"snip of empty string failure");
- // snip like in OAuth
- orig = @"OAuth oauth_consumer_key=\"example.net\", "
- "oauth_token=\"1%2FpXi_-mBSegSbB-m9HprlwlxF6NF7IL7_9PDZok\", "
- "oauth_signature=\"blP%2BG72aSQ2XadLLTk%2BNzUV6Wes%3D\"";
- expected = @"OAuth oauth_consumer_key=\"example.net\", "
- "oauth_token=\"_snip_\", "
- "oauth_signature=\"blP%2BG72aSQ2XadLLTk%2BNzUV6Wes%3D\"";
- result = [GTMHTTPFetcher snipSubstringOfString:orig
- betweenStartString:@"oauth_token=\""
- endString:@"\""];
- XCTAssertEqualObjects(result, expected, @"realistic snip failure");
- }
- #endif
- - (void)testGTMCleanedUserAgentString {
- NSString *result = GTMCleanedUserAgentString(nil);
- NSString *expected = nil;
- XCTAssertEqualObjects(result, expected);
- result = GTMCleanedUserAgentString(@"");
- expected = @"";
- XCTAssertEqualObjects(result, expected);
- result = GTMCleanedUserAgentString(@"frog in tree/[1.2.3]");
- expected = @"frog_in_tree1.2.3";
- XCTAssertEqualObjects(result, expected);
- result = GTMCleanedUserAgentString(@"\\iPod ({Touch])\n\r");
- expected = @"iPod_Touch";
- XCTAssertEqualObjects(result, expected);
- }
- - (void)testGTMSystemVersionString {
- #if TARGET_OS_MAC && !TARGET_OS_IPHONE
- NSString *result = GTMSystemVersionString();
- XCTAssertTrue([result hasPrefix:@"MacOSX/"]);
- #else
- STAssertTrue(NO, @"Add system version string test for this configuration");
- #endif
- }
- - (void)testGTMApplicationIdentifier {
- NSBundle *bundle = [NSBundle bundleForClass:[self class]];
- NSString *result = GTMApplicationIdentifier(bundle);
- XCTAssertEqualObjects(result, @"com.yourcompany.UnitTests/1.0");
- }
- @end