PageRenderTime 41ms CodeModel.GetById 14ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 1ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/HTTPFetcher/Tests/GTMHTTPFetcherUtilityTest.m

http://macfuse.googlecode.com/
Objective C | 121 lines | 83 code | 18 blank | 20 comment | 1 complexity | 7881ffb29d9a9954339b2799196aec7c MD5 | raw file
  1/* Copyright (c) 2010 Google Inc.
  2 *
  3 * Licensed under the Apache License, Version 2.0 (the "License");
  4 * you may not use this file except in compliance with the License.
  5 * You may obtain a copy of the License at
  6 *
  7 *     http://www.apache.org/licenses/LICENSE-2.0
  8 *
  9 * Unless required by applicable law or agreed to in writing, software
 10 * distributed under the License is distributed on an "AS IS" BASIS,
 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 * See the License for the specific language governing permissions and
 13 * limitations under the License.
 14 */
 15
 16#import <XCTest/XCTest.h>
 17
 18#import "GTMHTTPFetcher.h"
 19#import "GTMHTTPFetcherLogging.h"
 20
 21@interface GTMHTTPFetcherUtilityTest : XCTestCase
 22@end
 23
 24@interface GTMHTTPFetcher (GTMHTTPFetcherLoggingInternal)
 25+ (NSString *)snipSubstringOfString:(NSString *)originalStr
 26                 betweenStartString:(NSString *)startStr
 27                          endString:(NSString *)endStr;
 28@end
 29
 30
 31@implementation GTMHTTPFetcherUtilityTest
 32
 33#if !STRIP_GTM_FETCH_LOGGING
 34- (void)testLogSnipping {
 35  // enpty string
 36  NSString *orig = @"";
 37  NSString *expected = orig;
 38  NSString *result = [GTMHTTPFetcher snipSubstringOfString:orig
 39                                        betweenStartString:@"jkl"
 40                                                 endString:@"mno"];
 41  XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
 42
 43  // snip the middle
 44  orig = @"abcdefg";
 45  expected = @"abcd_snip_fg";
 46  result = [GTMHTTPFetcher snipSubstringOfString:orig
 47                              betweenStartString:@"abcd"
 48                                       endString:@"fg"];
 49  XCTAssertEqualObjects(result, expected, @"simple snip in the middle failure");
 50
 51  // snip to the end
 52  orig = @"abcdefg";
 53  expected = @"abcd_snip_";
 54  result = [GTMHTTPFetcher snipSubstringOfString:orig
 55                              betweenStartString:@"abcd"
 56                                       endString:@"xyz"];
 57  XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
 58
 59  // start string not found, so nothing should be snipped
 60  orig = @"abcdefg";
 61  expected = orig;
 62  result = [GTMHTTPFetcher snipSubstringOfString:orig
 63                              betweenStartString:@"jkl"
 64                                       endString:@"mno"];
 65  XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
 66
 67  // nothing between start and end
 68  orig = @"abcdefg";
 69  expected = @"abcd_snip_efg";
 70  result = [GTMHTTPFetcher snipSubstringOfString:orig
 71                              betweenStartString:@"abcd"
 72                                       endString:@"efg"];
 73  XCTAssertEqualObjects(result, expected, @"snip of empty string failure");
 74
 75  // snip like in OAuth
 76  orig = @"OAuth oauth_consumer_key=\"example.net\", "
 77  "oauth_token=\"1%2FpXi_-mBSegSbB-m9HprlwlxF6NF7IL7_9PDZok\", "
 78  "oauth_signature=\"blP%2BG72aSQ2XadLLTk%2BNzUV6Wes%3D\"";
 79  expected = @"OAuth oauth_consumer_key=\"example.net\", "
 80  "oauth_token=\"_snip_\", "
 81  "oauth_signature=\"blP%2BG72aSQ2XadLLTk%2BNzUV6Wes%3D\"";
 82  result = [GTMHTTPFetcher snipSubstringOfString:orig
 83                              betweenStartString:@"oauth_token=\""
 84                                       endString:@"\""];
 85  XCTAssertEqualObjects(result, expected, @"realistic snip failure");
 86}
 87#endif
 88
 89- (void)testGTMCleanedUserAgentString {
 90  NSString *result = GTMCleanedUserAgentString(nil);
 91  NSString *expected = nil;
 92  XCTAssertEqualObjects(result, expected);
 93
 94  result = GTMCleanedUserAgentString(@"");
 95  expected = @"";
 96  XCTAssertEqualObjects(result, expected);
 97
 98  result = GTMCleanedUserAgentString(@"frog in tree/[1.2.3]");
 99  expected = @"frog_in_tree1.2.3";
100  XCTAssertEqualObjects(result, expected);
101
102  result = GTMCleanedUserAgentString(@"\\iPod ({Touch])\n\r");
103  expected = @"iPod_Touch";
104  XCTAssertEqualObjects(result, expected);
105}
106
107- (void)testGTMSystemVersionString {
108#if TARGET_OS_MAC && !TARGET_OS_IPHONE
109  NSString *result = GTMSystemVersionString();
110  XCTAssertTrue([result hasPrefix:@"MacOSX/"]);
111#else
112  STAssertTrue(NO, @"Add system version string test for this configuration");
113#endif
114}
115
116- (void)testGTMApplicationIdentifier {
117  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
118  NSString *result = GTMApplicationIdentifier(bundle);
119  XCTAssertEqualObjects(result, @"com.yourcompany.UnitTests/1.0");
120}
121@end