/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMNSDictionary+CaseInsensitiveTest.m

http://macfuse.googlecode.com/ · Objective C · 119 lines · 74 code · 28 blank · 17 comment · 2 complexity · 1bbf32c1d921c293476936f150eb86b0 MD5 · raw file

  1. //
  2. // GTMNSDictionary+CaseInsensitiveTest.m
  3. //
  4. // Copyright 2009 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import "GTMSenTestCase.h"
  19. #import "GTMNSDictionary+CaseInsensitive.h"
  20. @interface GTMNSDictionary_CaseInsensitiveTest : GTMTestCase
  21. @end
  22. @implementation GTMNSDictionary_CaseInsensitiveTest
  23. - (void)testNSDictionaryCaseInsensitiveAdditions {
  24. NSURL *objKey = [NSURL URLWithString:@"http://WWW.Google.COM/"];
  25. NSURL *lcObjKey = [NSURL URLWithString:[[objKey absoluteString]
  26. lowercaseString]];
  27. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
  28. @"value", @"key",
  29. @"value", @"KEY",
  30. @"bar", @"FOO",
  31. @"yes", objKey,
  32. nil];
  33. NSDictionary *ciDict =
  34. [NSDictionary gtm_dictionaryWithDictionaryCaseInsensitive:dict];
  35. STAssertNotNil(ciDict, @"gtm_dictionaryWithDictionaryCaseInsensitive failed");
  36. STAssertTrue([ciDict count] == 3,
  37. @"wrong count, multiple 'key' entries should be folded.");
  38. STAssertEqualStrings([ciDict objectForKey:@"foo"], @"bar",
  39. @"case insensitive key lookup failed");
  40. STAssertEqualStrings([ciDict objectForKey:@"kEy"], @"value",
  41. @"case insensitive key lookup failed");
  42. STAssertNotNil([ciDict objectForKey:objKey],
  43. @"exact matches on non-NSString objects should still work.");
  44. STAssertNil([ciDict objectForKey:lcObjKey],
  45. @"only NSString and subclasses are case-insensitive.");
  46. STAssertNotNil([NSDictionary gtm_dictionaryWithDictionaryCaseInsensitive:
  47. [NSDictionary dictionary]],
  48. @"empty dictionary should not return nil");
  49. STAssertNotNil([NSDictionary gtm_dictionaryWithDictionaryCaseInsensitive:
  50. nil],
  51. @"nil dictionary should return empty dictionary");
  52. STAssertNotNil([[[NSDictionary alloc] gtm_initWithDictionaryCaseInsensitive:
  53. nil] autorelease],
  54. @"nil dictionary should return empty dictionary");
  55. }
  56. - (void)testNSMutableDictionaryCaseInsensitiveAdditions {
  57. NSURL *objKey = [NSURL URLWithString:@"http://WWW.Google.COM/"];
  58. NSURL *lcObjKey = [NSURL URLWithString:[[objKey absoluteString]
  59. lowercaseString]];
  60. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
  61. @"value", @"key",
  62. @"value", @"KEY",
  63. @"bar", @"FOO",
  64. @"yes", objKey,
  65. nil];
  66. NSMutableDictionary *ciDict =
  67. [NSMutableDictionary gtm_dictionaryWithDictionaryCaseInsensitive:dict];
  68. STAssertNotNil(ciDict, @"gtm_dictionaryWithDictionaryCaseInsensitive failed");
  69. STAssertTrue([ciDict count] == 3,
  70. @"wrong count, multiple 'key' entries should be folded.");
  71. STAssertEqualStrings([ciDict objectForKey:@"foo"], @"bar",
  72. @"case insensitive key lookup failed");
  73. STAssertEqualStrings([ciDict objectForKey:@"kEy"], @"value",
  74. @"case insensitive key lookup failed");
  75. STAssertNotNil([ciDict objectForKey:objKey],
  76. @"exact matches on non-NSString objects should still work.");
  77. STAssertNil([ciDict objectForKey:lcObjKey],
  78. @"only NSString and subclasses are case-insensitive.");
  79. NSObject *obj = [[[NSObject alloc] init] autorelease];
  80. [ciDict setObject:obj forKey:@"kEy"];
  81. STAssertEquals([ciDict objectForKey:@"key"], obj,
  82. @"mutable dictionary value not overwritten");
  83. STAssertNotNil(
  84. [NSMutableDictionary gtm_dictionaryWithDictionaryCaseInsensitive:
  85. [NSDictionary dictionary]],
  86. @"empty dictionary should not return nil");
  87. STAssertNotNil(
  88. [NSMutableDictionary gtm_dictionaryWithDictionaryCaseInsensitive:nil],
  89. @"nil dictionary should return empty dictionary");
  90. }
  91. @end