/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

  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. #import <XCTest/XCTest.h>
  16. #import "GTMHTTPFetcher.h"
  17. #import "GTMHTTPFetcherLogging.h"
  18. @interface GTMHTTPFetcherUtilityTest : XCTestCase
  19. @end
  20. @interface GTMHTTPFetcher (GTMHTTPFetcherLoggingInternal)
  21. + (NSString *)snipSubstringOfString:(NSString *)originalStr
  22. betweenStartString:(NSString *)startStr
  23. endString:(NSString *)endStr;
  24. @end
  25. @implementation GTMHTTPFetcherUtilityTest
  26. #if !STRIP_GTM_FETCH_LOGGING
  27. - (void)testLogSnipping {
  28. // enpty string
  29. NSString *orig = @"";
  30. NSString *expected = orig;
  31. NSString *result = [GTMHTTPFetcher snipSubstringOfString:orig
  32. betweenStartString:@"jkl"
  33. endString:@"mno"];
  34. XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
  35. // snip the middle
  36. orig = @"abcdefg";
  37. expected = @"abcd_snip_fg";
  38. result = [GTMHTTPFetcher snipSubstringOfString:orig
  39. betweenStartString:@"abcd"
  40. endString:@"fg"];
  41. XCTAssertEqualObjects(result, expected, @"simple snip in the middle failure");
  42. // snip to the end
  43. orig = @"abcdefg";
  44. expected = @"abcd_snip_";
  45. result = [GTMHTTPFetcher snipSubstringOfString:orig
  46. betweenStartString:@"abcd"
  47. endString:@"xyz"];
  48. XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
  49. // start string not found, so nothing should be snipped
  50. orig = @"abcdefg";
  51. expected = orig;
  52. result = [GTMHTTPFetcher snipSubstringOfString:orig
  53. betweenStartString:@"jkl"
  54. endString:@"mno"];
  55. XCTAssertEqualObjects(result, expected, @"simple snip to end failure");
  56. // nothing between start and end
  57. orig = @"abcdefg";
  58. expected = @"abcd_snip_efg";
  59. result = [GTMHTTPFetcher snipSubstringOfString:orig
  60. betweenStartString:@"abcd"
  61. endString:@"efg"];
  62. XCTAssertEqualObjects(result, expected, @"snip of empty string failure");
  63. // snip like in OAuth
  64. orig = @"OAuth oauth_consumer_key=\"example.net\", "
  65. "oauth_token=\"1%2FpXi_-mBSegSbB-m9HprlwlxF6NF7IL7_9PDZok\", "
  66. "oauth_signature=\"blP%2BG72aSQ2XadLLTk%2BNzUV6Wes%3D\"";
  67. expected = @"OAuth oauth_consumer_key=\"example.net\", "
  68. "oauth_token=\"_snip_\", "
  69. "oauth_signature=\"blP%2BG72aSQ2XadLLTk%2BNzUV6Wes%3D\"";
  70. result = [GTMHTTPFetcher snipSubstringOfString:orig
  71. betweenStartString:@"oauth_token=\""
  72. endString:@"\""];
  73. XCTAssertEqualObjects(result, expected, @"realistic snip failure");
  74. }
  75. #endif
  76. - (void)testGTMCleanedUserAgentString {
  77. NSString *result = GTMCleanedUserAgentString(nil);
  78. NSString *expected = nil;
  79. XCTAssertEqualObjects(result, expected);
  80. result = GTMCleanedUserAgentString(@"");
  81. expected = @"";
  82. XCTAssertEqualObjects(result, expected);
  83. result = GTMCleanedUserAgentString(@"frog in tree/[1.2.3]");
  84. expected = @"frog_in_tree1.2.3";
  85. XCTAssertEqualObjects(result, expected);
  86. result = GTMCleanedUserAgentString(@"\\iPod ({Touch])\n\r");
  87. expected = @"iPod_Touch";
  88. XCTAssertEqualObjects(result, expected);
  89. }
  90. - (void)testGTMSystemVersionString {
  91. #if TARGET_OS_MAC && !TARGET_OS_IPHONE
  92. NSString *result = GTMSystemVersionString();
  93. XCTAssertTrue([result hasPrefix:@"MacOSX/"]);
  94. #else
  95. STAssertTrue(NO, @"Add system version string test for this configuration");
  96. #endif
  97. }
  98. - (void)testGTMApplicationIdentifier {
  99. NSBundle *bundle = [NSBundle bundleForClass:[self class]];
  100. NSString *result = GTMApplicationIdentifier(bundle);
  101. XCTAssertEqualObjects(result, @"com.yourcompany.UnitTests/1.0");
  102. }
  103. @end