PageRenderTime 95ms CodeModel.GetById 69ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 19#import "GTMSenTestCase.h"
 20#import "GTMNSDictionary+CaseInsensitive.h"
 21
 22@interface GTMNSDictionary_CaseInsensitiveTest : GTMTestCase
 23@end
 24
 25@implementation GTMNSDictionary_CaseInsensitiveTest
 26
 27- (void)testNSDictionaryCaseInsensitiveAdditions {
 28  NSURL *objKey = [NSURL URLWithString:@"http://WWW.Google.COM/"];
 29  NSURL *lcObjKey = [NSURL URLWithString:[[objKey absoluteString]
 30                                          lowercaseString]];
 31
 32  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
 33                        @"value", @"key",
 34                        @"value", @"KEY",
 35                        @"bar", @"FOO",
 36                        @"yes", objKey,
 37                        nil];
 38
 39  NSDictionary *ciDict =
 40      [NSDictionary gtm_dictionaryWithDictionaryCaseInsensitive:dict];
 41
 42  STAssertNotNil(ciDict, @"gtm_dictionaryWithDictionaryCaseInsensitive failed");
 43
 44  STAssertTrue([ciDict count] == 3,
 45               @"wrong count, multiple 'key' entries should be folded.");
 46
 47  STAssertEqualStrings([ciDict objectForKey:@"foo"], @"bar",
 48                       @"case insensitive key lookup failed");
 49
 50  STAssertEqualStrings([ciDict objectForKey:@"kEy"], @"value",
 51                       @"case insensitive key lookup failed");
 52
 53  STAssertNotNil([ciDict objectForKey:objKey],
 54                 @"exact matches on non-NSString objects should still work.");
 55
 56  STAssertNil([ciDict objectForKey:lcObjKey],
 57              @"only NSString and subclasses are case-insensitive.");
 58
 59  STAssertNotNil([NSDictionary gtm_dictionaryWithDictionaryCaseInsensitive:
 60                  [NSDictionary dictionary]],
 61                 @"empty dictionary should not return nil");
 62
 63  STAssertNotNil([NSDictionary gtm_dictionaryWithDictionaryCaseInsensitive:
 64                  nil],
 65                 @"nil dictionary should return empty dictionary");
 66
 67  STAssertNotNil([[[NSDictionary alloc] gtm_initWithDictionaryCaseInsensitive:
 68                   nil] autorelease],
 69                 @"nil dictionary should return empty dictionary");
 70}
 71
 72- (void)testNSMutableDictionaryCaseInsensitiveAdditions {
 73  NSURL *objKey = [NSURL URLWithString:@"http://WWW.Google.COM/"];
 74  NSURL *lcObjKey = [NSURL URLWithString:[[objKey absoluteString]
 75                                          lowercaseString]];
 76
 77  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
 78                        @"value", @"key",
 79                        @"value", @"KEY",
 80                        @"bar", @"FOO",
 81                        @"yes", objKey,
 82                        nil];
 83
 84  NSMutableDictionary *ciDict =
 85      [NSMutableDictionary gtm_dictionaryWithDictionaryCaseInsensitive:dict];
 86
 87  STAssertNotNil(ciDict, @"gtm_dictionaryWithDictionaryCaseInsensitive failed");
 88
 89  STAssertTrue([ciDict count] == 3,
 90               @"wrong count, multiple 'key' entries should be folded.");
 91
 92  STAssertEqualStrings([ciDict objectForKey:@"foo"], @"bar",
 93                       @"case insensitive key lookup failed");
 94
 95  STAssertEqualStrings([ciDict objectForKey:@"kEy"], @"value",
 96                       @"case insensitive key lookup failed");
 97
 98  STAssertNotNil([ciDict objectForKey:objKey],
 99                 @"exact matches on non-NSString objects should still work.");
100
101  STAssertNil([ciDict objectForKey:lcObjKey],
102              @"only NSString and subclasses are case-insensitive.");
103
104  NSObject *obj = [[[NSObject alloc] init] autorelease];
105  [ciDict setObject:obj forKey:@"kEy"];
106  STAssertEquals([ciDict objectForKey:@"key"], obj,
107                 @"mutable dictionary value not overwritten");
108
109  STAssertNotNil(
110      [NSMutableDictionary gtm_dictionaryWithDictionaryCaseInsensitive:
111       [NSDictionary dictionary]],
112      @"empty dictionary should not return nil");
113
114  STAssertNotNil(
115      [NSMutableDictionary gtm_dictionaryWithDictionaryCaseInsensitive:nil],
116      @"nil dictionary should return empty dictionary");
117}
118
119@end