| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2015 Google Inc. All rights reserved. | 2 // Copyright 2015 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 // Pull in the macros (using an external file because expanding all tests | 39 // Pull in the macros (using an external file because expanding all tests |
| 40 // in a single file makes a file that is failing to work with within Xcode. | 40 // in a single file makes a file that is failing to work with within Xcode. |
| 41 //%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm | 41 //%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm |
| 42 | 42 |
| 43 //%PDDM-EXPAND TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL) | 43 //%PDDM-EXPAND TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL) |
| 44 // This block of code is generated, do not edit it directly. | 44 // This block of code is generated, do not edit it directly. |
| 45 | 45 |
| 46 // To let the testing macros work, add some extra methods to simplify things. | 46 // To let the testing macros work, add some extra methods to simplify things. |
| 47 @interface GPBInt64EnumDictionary (TestingTweak) | 47 @interface GPBInt64EnumDictionary (TestingTweak) |
| 48 + (instancetype)dictionaryWithValue:(int32_t)value forKey:(int64_t)key; | 48 + (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int64_t)key; |
| 49 - (instancetype)initWithValues:(const int32_t [])values | 49 - (instancetype)initWithEnums:(const int32_t [])values |
| 50 forKeys:(const int64_t [])keys | 50 forKeys:(const int64_t [])keys |
| 51 count:(NSUInteger)count; | 51 count:(NSUInteger)count; |
| 52 @end | 52 @end |
| 53 | 53 |
| 54 static BOOL TestingEnum_IsValidValue(int32_t value) { | 54 static BOOL TestingEnum_IsValidValue(int32_t value) { |
| 55 switch (value) { | 55 switch (value) { |
| 56 case 700: | 56 case 700: |
| 57 case 701: | 57 case 701: |
| 58 case 702: | 58 case 702: |
| 59 case 703: | 59 case 703: |
| 60 return YES; | 60 return YES; |
| 61 default: | 61 default: |
| 62 return NO; | 62 return NO; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 @implementation GPBInt64EnumDictionary (TestingTweak) | 66 @implementation GPBInt64EnumDictionary (TestingTweak) |
| 67 + (instancetype)dictionaryWithValue:(int32_t)value forKey:(int64_t)key { | 67 + (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int64_t)key { |
| 68 // Cast is needed to compiler knows what class we are invoking initWithValues:
on to get the | 68 // Cast is needed to compiler knows what class we are invoking initWithValues:
on to get the |
| 69 // type correct. | 69 // type correct. |
| 70 return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:Test
ingEnum_IsValidValue | 70 return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:Test
ingEnum_IsValidValue |
| 71 rawValues:&val
ue | 71 rawValues:&val
ue |
| 72 forKeys:&key | 72 forKeys:&key |
| 73 count:1] a
utorelease]; | 73 count:1] a
utorelease]; |
| 74 } | 74 } |
| 75 - (instancetype)initWithValues:(const int32_t [])values | 75 - (instancetype)initWithEnums:(const int32_t [])values |
| 76 forKeys:(const int64_t [])keys | 76 forKeys:(const int64_t [])keys |
| 77 count:(NSUInteger)count { | 77 count:(NSUInteger)count { |
| 78 return [self initWithValidationFunction:TestingEnum_IsValidValue | 78 return [self initWithValidationFunction:TestingEnum_IsValidValue |
| 79 rawValues:values | 79 rawValues:values |
| 80 forKeys:keys | 80 forKeys:keys |
| 81 count:count]; | 81 count:count]; |
| 82 } | 82 } |
| 83 @end | 83 @end |
| 84 | 84 |
| 85 | 85 |
| 86 #pragma mark - Int64 -> UInt32 | 86 #pragma mark - Int64 -> UInt32 |
| 87 | 87 |
| 88 @interface GPBInt64UInt32DictionaryTests : XCTestCase | 88 @interface GPBInt64UInt32DictionaryTests : XCTestCase |
| 89 @end | 89 @end |
| 90 | 90 |
| 91 @implementation GPBInt64UInt32DictionaryTests | 91 @implementation GPBInt64UInt32DictionaryTests |
| 92 | 92 |
| 93 - (void)testEmpty { | 93 - (void)testEmpty { |
| 94 GPBInt64UInt32Dictionary *dict = [[GPBInt64UInt32Dictionary alloc] init]; | 94 GPBInt64UInt32Dictionary *dict = [[GPBInt64UInt32Dictionary alloc] init]; |
| 95 XCTAssertNotNil(dict); | 95 XCTAssertNotNil(dict); |
| 96 XCTAssertEqual(dict.count, 0U); | 96 XCTAssertEqual(dict.count, 0U); |
| 97 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 97 XCTAssertFalse([dict getUInt32:NULL forKey:21LL]); |
| 98 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *
stop) { | 98 [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL
*stop) { |
| 99 #pragma unused(aKey, aValue, stop) | 99 #pragma unused(aKey, aValue, stop) |
| 100 XCTFail(@"Shouldn't get here!"); | 100 XCTFail(@"Shouldn't get here!"); |
| 101 }]; | 101 }]; |
| 102 [dict release]; | 102 [dict release]; |
| 103 } | 103 } |
| 104 | 104 |
| 105 - (void)testOne { | 105 - (void)testOne { |
| 106 GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionaryWithValue
:100U forKey:21LL]; | 106 GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionaryWithUInt3
2:100U forKey:21LL]; |
| 107 XCTAssertNotNil(dict); | 107 XCTAssertNotNil(dict); |
| 108 XCTAssertEqual(dict.count, 1U); | 108 XCTAssertEqual(dict.count, 1U); |
| 109 uint32_t value; | 109 uint32_t value; |
| 110 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 110 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 111 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 111 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 112 XCTAssertEqual(value, 100U); | 112 XCTAssertEqual(value, 100U); |
| 113 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 113 XCTAssertFalse([dict getUInt32:NULL forKey:22LL]); |
| 114 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *
stop) { | 114 [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL
*stop) { |
| 115 XCTAssertEqual(aKey, 21LL); | 115 XCTAssertEqual(aKey, 21LL); |
| 116 XCTAssertEqual(aValue, 100U); | 116 XCTAssertEqual(aValue, 100U); |
| 117 XCTAssertNotEqual(stop, NULL); | 117 XCTAssertNotEqual(stop, NULL); |
| 118 }]; | 118 }]; |
| 119 } | 119 } |
| 120 | 120 |
| 121 - (void)testBasics { | 121 - (void)testBasics { |
| 122 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 122 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 123 const uint32_t kValues[] = { 100U, 101U, 102U }; | 123 const uint32_t kValues[] = { 100U, 101U, 102U }; |
| 124 GPBInt64UInt32Dictionary *dict = | 124 GPBInt64UInt32Dictionary *dict = |
| 125 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues | 125 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues |
| 126 forKeys:kKeys | 126 forKeys:kKeys |
| 127 count:GPBARRAYSIZE(kValues)]; | 127 count:GPBARRAYSIZE(kValues)]; |
| 128 XCTAssertNotNil(dict); | 128 XCTAssertNotNil(dict); |
| 129 XCTAssertEqual(dict.count, 3U); | 129 XCTAssertEqual(dict.count, 3U); |
| 130 uint32_t value; | 130 uint32_t value; |
| 131 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 131 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 132 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 132 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 133 XCTAssertEqual(value, 100U); | 133 XCTAssertEqual(value, 100U); |
| 134 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 134 XCTAssertTrue([dict getUInt32:NULL forKey:22LL]); |
| 135 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 135 XCTAssertTrue([dict getUInt32:&value forKey:22LL]); |
| 136 XCTAssertEqual(value, 101U); | 136 XCTAssertEqual(value, 101U); |
| 137 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 137 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 138 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 138 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 139 XCTAssertEqual(value, 102U); | 139 XCTAssertEqual(value, 102U); |
| 140 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 140 XCTAssertFalse([dict getUInt32:NULL forKey:24LL]); |
| 141 | 141 |
| 142 __block NSUInteger idx = 0; | 142 __block NSUInteger idx = 0; |
| 143 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 143 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 144 uint32_t *seenValues = malloc(3 * sizeof(uint32_t)); | 144 uint32_t *seenValues = malloc(3 * sizeof(uint32_t)); |
| 145 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *
stop) { | 145 [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL
*stop) { |
| 146 XCTAssertLessThan(idx, 3U); | 146 XCTAssertLessThan(idx, 3U); |
| 147 seenKeys[idx] = aKey; | 147 seenKeys[idx] = aKey; |
| 148 seenValues[idx] = aValue; | 148 seenValues[idx] = aValue; |
| 149 XCTAssertNotEqual(stop, NULL); | 149 XCTAssertNotEqual(stop, NULL); |
| 150 ++idx; | 150 ++idx; |
| 151 }]; | 151 }]; |
| 152 for (int i = 0; i < 3; ++i) { | 152 for (int i = 0; i < 3; ++i) { |
| 153 BOOL foundKey = NO; | 153 BOOL foundKey = NO; |
| 154 for (int j = 0; (j < 3) && !foundKey; ++j) { | 154 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 155 if (kKeys[i] == seenKeys[j]) { | 155 if (kKeys[i] == seenKeys[j]) { |
| 156 foundKey = YES; | 156 foundKey = YES; |
| 157 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 157 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 XCTAssertTrue(foundKey, @"i = %d", i); | 160 XCTAssertTrue(foundKey, @"i = %d", i); |
| 161 } | 161 } |
| 162 free(seenKeys); | 162 free(seenKeys); |
| 163 free(seenValues); | 163 free(seenValues); |
| 164 | 164 |
| 165 // Stopping the enumeration. | 165 // Stopping the enumeration. |
| 166 idx = 0; | 166 idx = 0; |
| 167 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *
stop) { | 167 [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL
*stop) { |
| 168 #pragma unused(aKey, aValue) | 168 #pragma unused(aKey, aValue) |
| 169 if (idx == 1) *stop = YES; | 169 if (idx == 1) *stop = YES; |
| 170 XCTAssertNotEqual(idx, 2U); | 170 XCTAssertNotEqual(idx, 2U); |
| 171 ++idx; | 171 ++idx; |
| 172 }]; | 172 }]; |
| 173 [dict release]; | 173 [dict release]; |
| 174 } | 174 } |
| 175 | 175 |
| 176 - (void)testEquality { | 176 - (void)testEquality { |
| 177 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 177 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 178 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 178 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 179 const uint32_t kValues1[] = { 100U, 101U, 102U }; | 179 const uint32_t kValues1[] = { 100U, 101U, 102U }; |
| 180 const uint32_t kValues2[] = { 100U, 103U, 102U }; | 180 const uint32_t kValues2[] = { 100U, 103U, 102U }; |
| 181 const uint32_t kValues3[] = { 100U, 101U, 102U, 103U }; | 181 const uint32_t kValues3[] = { 100U, 101U, 102U, 103U }; |
| 182 GPBInt64UInt32Dictionary *dict1 = | 182 GPBInt64UInt32Dictionary *dict1 = |
| 183 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues1 | 183 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1 |
| 184 forKeys:kKeys1 | 184 forKeys:kKeys1 |
| 185 count:GPBARRAYSIZE(kValues1)]; | 185 count:GPBARRAYSIZE(kValues1)]; |
| 186 XCTAssertNotNil(dict1); | 186 XCTAssertNotNil(dict1); |
| 187 GPBInt64UInt32Dictionary *dict1prime = | 187 GPBInt64UInt32Dictionary *dict1prime = |
| 188 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues1 | 188 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1 |
| 189 forKeys:kKeys1 | 189 forKeys:kKeys1 |
| 190 count:GPBARRAYSIZE(kValues1)]; | 190 count:GPBARRAYSIZE(kValues1)]; |
| 191 XCTAssertNotNil(dict1prime); | 191 XCTAssertNotNil(dict1prime); |
| 192 GPBInt64UInt32Dictionary *dict2 = | 192 GPBInt64UInt32Dictionary *dict2 = |
| 193 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues2 | 193 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues2 |
| 194 forKeys:kKeys1 | 194 forKeys:kKeys1 |
| 195 count:GPBARRAYSIZE(kValues2)]; | 195 count:GPBARRAYSIZE(kValues2)]; |
| 196 XCTAssertNotNil(dict2); | 196 XCTAssertNotNil(dict2); |
| 197 GPBInt64UInt32Dictionary *dict3 = | 197 GPBInt64UInt32Dictionary *dict3 = |
| 198 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues1 | 198 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1 |
| 199 forKeys:kKeys2 | 199 forKeys:kKeys2 |
| 200 count:GPBARRAYSIZE(kValues1)]; | 200 count:GPBARRAYSIZE(kValues1)]; |
| 201 XCTAssertNotNil(dict3); | 201 XCTAssertNotNil(dict3); |
| 202 GPBInt64UInt32Dictionary *dict4 = | 202 GPBInt64UInt32Dictionary *dict4 = |
| 203 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues3 | 203 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues3 |
| 204 forKeys:kKeys1 | 204 forKeys:kKeys1 |
| 205 count:GPBARRAYSIZE(kValues3)]; | 205 count:GPBARRAYSIZE(kValues3)]; |
| 206 XCTAssertNotNil(dict4); | 206 XCTAssertNotNil(dict4); |
| 207 | 207 |
| 208 // 1/1Prime should be different objects, but equal. | 208 // 1/1Prime should be different objects, but equal. |
| 209 XCTAssertNotEqual(dict1, dict1prime); | 209 XCTAssertNotEqual(dict1, dict1prime); |
| 210 XCTAssertEqualObjects(dict1, dict1prime); | 210 XCTAssertEqualObjects(dict1, dict1prime); |
| 211 // Equal, so they must have same hash. | 211 // Equal, so they must have same hash. |
| 212 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 212 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 213 | 213 |
| 214 // 2 is same keys, different values; not equal. | 214 // 2 is same keys, different values; not equal. |
| 215 XCTAssertNotEqualObjects(dict1, dict2); | 215 XCTAssertNotEqualObjects(dict1, dict2); |
| 216 | 216 |
| 217 // 3 is different keys, same values; not equal. | 217 // 3 is different keys, same values; not equal. |
| 218 XCTAssertNotEqualObjects(dict1, dict3); | 218 XCTAssertNotEqualObjects(dict1, dict3); |
| 219 | 219 |
| 220 // 4 extra pair; not equal | 220 // 4 extra pair; not equal |
| 221 XCTAssertNotEqualObjects(dict1, dict4); | 221 XCTAssertNotEqualObjects(dict1, dict4); |
| 222 | 222 |
| 223 [dict1 release]; | 223 [dict1 release]; |
| 224 [dict1prime release]; | 224 [dict1prime release]; |
| 225 [dict2 release]; | 225 [dict2 release]; |
| 226 [dict3 release]; | 226 [dict3 release]; |
| 227 [dict4 release]; | 227 [dict4 release]; |
| 228 } | 228 } |
| 229 | 229 |
| 230 - (void)testCopy { | 230 - (void)testCopy { |
| 231 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 231 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 232 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; | 232 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; |
| 233 GPBInt64UInt32Dictionary *dict = | 233 GPBInt64UInt32Dictionary *dict = |
| 234 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues | 234 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues |
| 235 forKeys:kKeys | 235 forKeys:kKeys |
| 236 count:GPBARRAYSIZE(kValues)]; | 236 count:GPBARRAYSIZE(kValues)]; |
| 237 XCTAssertNotNil(dict); | 237 XCTAssertNotNil(dict); |
| 238 | 238 |
| 239 GPBInt64UInt32Dictionary *dict2 = [dict copy]; | 239 GPBInt64UInt32Dictionary *dict2 = [dict copy]; |
| 240 XCTAssertNotNil(dict2); | 240 XCTAssertNotNil(dict2); |
| 241 | 241 |
| 242 // Should be new object but equal. | 242 // Should be new object but equal. |
| 243 XCTAssertNotEqual(dict, dict2); | 243 XCTAssertNotEqual(dict, dict2); |
| 244 XCTAssertEqualObjects(dict, dict2); | 244 XCTAssertEqualObjects(dict, dict2); |
| 245 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt32Dictionary class]]); | 245 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt32Dictionary class]]); |
| 246 | 246 |
| 247 [dict2 release]; | 247 [dict2 release]; |
| 248 [dict release]; | 248 [dict release]; |
| 249 } | 249 } |
| 250 | 250 |
| 251 - (void)testDictionaryFromDictionary { | 251 - (void)testDictionaryFromDictionary { |
| 252 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 252 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 253 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; | 253 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; |
| 254 GPBInt64UInt32Dictionary *dict = | 254 GPBInt64UInt32Dictionary *dict = |
| 255 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues | 255 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues |
| 256 forKeys:kKeys | 256 forKeys:kKeys |
| 257 count:GPBARRAYSIZE(kValues)]; | 257 count:GPBARRAYSIZE(kValues)]; |
| 258 XCTAssertNotNil(dict); | 258 XCTAssertNotNil(dict); |
| 259 | 259 |
| 260 GPBInt64UInt32Dictionary *dict2 = | 260 GPBInt64UInt32Dictionary *dict2 = |
| 261 [GPBInt64UInt32Dictionary dictionaryWithDictionary:dict]; | 261 [GPBInt64UInt32Dictionary dictionaryWithDictionary:dict]; |
| 262 XCTAssertNotNil(dict2); | 262 XCTAssertNotNil(dict2); |
| 263 | 263 |
| 264 // Should be new pointer, but equal objects. | 264 // Should be new pointer, but equal objects. |
| 265 XCTAssertNotEqual(dict, dict2); | 265 XCTAssertNotEqual(dict, dict2); |
| 266 XCTAssertEqualObjects(dict, dict2); | 266 XCTAssertEqualObjects(dict, dict2); |
| 267 [dict release]; | 267 [dict release]; |
| 268 } | 268 } |
| 269 | 269 |
| 270 - (void)testAdds { | 270 - (void)testAdds { |
| 271 GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionary]; | 271 GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionary]; |
| 272 XCTAssertNotNil(dict); | 272 XCTAssertNotNil(dict); |
| 273 | 273 |
| 274 XCTAssertEqual(dict.count, 0U); | 274 XCTAssertEqual(dict.count, 0U); |
| 275 [dict setValue:100U forKey:21LL]; | 275 [dict setUInt32:100U forKey:21LL]; |
| 276 XCTAssertEqual(dict.count, 1U); | 276 XCTAssertEqual(dict.count, 1U); |
| 277 | 277 |
| 278 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 278 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 279 const uint32_t kValues[] = { 101U, 102U, 103U }; | 279 const uint32_t kValues[] = { 101U, 102U, 103U }; |
| 280 GPBInt64UInt32Dictionary *dict2 = | 280 GPBInt64UInt32Dictionary *dict2 = |
| 281 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues | 281 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues |
| 282 forKeys:kKeys | 282 forKeys:kKeys |
| 283 count:GPBARRAYSIZE(kValues)]; | 283 count:GPBARRAYSIZE(kValues)]; |
| 284 XCTAssertNotNil(dict2); | 284 XCTAssertNotNil(dict2); |
| 285 [dict addEntriesFromDictionary:dict2]; | 285 [dict addEntriesFromDictionary:dict2]; |
| 286 XCTAssertEqual(dict.count, 4U); | 286 XCTAssertEqual(dict.count, 4U); |
| 287 | 287 |
| 288 uint32_t value; | 288 uint32_t value; |
| 289 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 289 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 290 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 290 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 291 XCTAssertEqual(value, 100U); | 291 XCTAssertEqual(value, 100U); |
| 292 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 292 XCTAssertTrue([dict getUInt32:NULL forKey:22LL]); |
| 293 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 293 XCTAssertTrue([dict getUInt32:&value forKey:22LL]); |
| 294 XCTAssertEqual(value, 101U); | 294 XCTAssertEqual(value, 101U); |
| 295 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 295 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 296 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 296 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 297 XCTAssertEqual(value, 102U); | 297 XCTAssertEqual(value, 102U); |
| 298 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 298 XCTAssertTrue([dict getUInt32:NULL forKey:24LL]); |
| 299 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 299 XCTAssertTrue([dict getUInt32:&value forKey:24LL]); |
| 300 XCTAssertEqual(value, 103U); | 300 XCTAssertEqual(value, 103U); |
| 301 [dict2 release]; | 301 [dict2 release]; |
| 302 } | 302 } |
| 303 | 303 |
| 304 - (void)testRemove { | 304 - (void)testRemove { |
| 305 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 305 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 306 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; | 306 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; |
| 307 GPBInt64UInt32Dictionary *dict = | 307 GPBInt64UInt32Dictionary *dict = |
| 308 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues | 308 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues |
| 309 forKeys:kKeys | 309 forKeys:kKeys |
| 310 count:GPBARRAYSIZE(kValues)]; | 310 count:GPBARRAYSIZE(kValues)]; |
| 311 XCTAssertNotNil(dict); | 311 XCTAssertNotNil(dict); |
| 312 XCTAssertEqual(dict.count, 4U); | 312 XCTAssertEqual(dict.count, 4U); |
| 313 | 313 |
| 314 [dict removeValueForKey:22LL]; | 314 [dict removeUInt32ForKey:22LL]; |
| 315 XCTAssertEqual(dict.count, 3U); | 315 XCTAssertEqual(dict.count, 3U); |
| 316 uint32_t value; | 316 uint32_t value; |
| 317 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 317 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 318 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 318 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 319 XCTAssertEqual(value, 100U); | 319 XCTAssertEqual(value, 100U); |
| 320 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 320 XCTAssertFalse([dict getUInt32:NULL forKey:22LL]); |
| 321 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 321 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 322 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 322 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 323 XCTAssertEqual(value, 102U); | 323 XCTAssertEqual(value, 102U); |
| 324 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 324 XCTAssertTrue([dict getUInt32:NULL forKey:24LL]); |
| 325 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 325 XCTAssertTrue([dict getUInt32:&value forKey:24LL]); |
| 326 XCTAssertEqual(value, 103U); | 326 XCTAssertEqual(value, 103U); |
| 327 | 327 |
| 328 // Remove again does nothing. | 328 // Remove again does nothing. |
| 329 [dict removeValueForKey:22LL]; | 329 [dict removeUInt32ForKey:22LL]; |
| 330 XCTAssertEqual(dict.count, 3U); | 330 XCTAssertEqual(dict.count, 3U); |
| 331 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 331 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 332 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 332 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 333 XCTAssertEqual(value, 100U); | 333 XCTAssertEqual(value, 100U); |
| 334 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 334 XCTAssertFalse([dict getUInt32:NULL forKey:22LL]); |
| 335 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 335 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 336 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 336 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 337 XCTAssertEqual(value, 102U); | 337 XCTAssertEqual(value, 102U); |
| 338 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 338 XCTAssertTrue([dict getUInt32:NULL forKey:24LL]); |
| 339 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 339 XCTAssertTrue([dict getUInt32:&value forKey:24LL]); |
| 340 XCTAssertEqual(value, 103U); | 340 XCTAssertEqual(value, 103U); |
| 341 | 341 |
| 342 [dict removeValueForKey:24LL]; | 342 [dict removeUInt32ForKey:24LL]; |
| 343 XCTAssertEqual(dict.count, 2U); | 343 XCTAssertEqual(dict.count, 2U); |
| 344 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 344 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 345 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 345 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 346 XCTAssertEqual(value, 100U); | 346 XCTAssertEqual(value, 100U); |
| 347 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 347 XCTAssertFalse([dict getUInt32:NULL forKey:22LL]); |
| 348 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 348 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 349 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 349 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 350 XCTAssertEqual(value, 102U); | 350 XCTAssertEqual(value, 102U); |
| 351 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 351 XCTAssertFalse([dict getUInt32:NULL forKey:24LL]); |
| 352 | 352 |
| 353 [dict removeAll]; | 353 [dict removeAll]; |
| 354 XCTAssertEqual(dict.count, 0U); | 354 XCTAssertEqual(dict.count, 0U); |
| 355 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 355 XCTAssertFalse([dict getUInt32:NULL forKey:21LL]); |
| 356 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 356 XCTAssertFalse([dict getUInt32:NULL forKey:22LL]); |
| 357 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 357 XCTAssertFalse([dict getUInt32:NULL forKey:23LL]); |
| 358 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 358 XCTAssertFalse([dict getUInt32:NULL forKey:24LL]); |
| 359 [dict release]; | 359 [dict release]; |
| 360 } | 360 } |
| 361 | 361 |
| 362 - (void)testInplaceMutation { | 362 - (void)testInplaceMutation { |
| 363 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 363 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 364 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; | 364 const uint32_t kValues[] = { 100U, 101U, 102U, 103U }; |
| 365 GPBInt64UInt32Dictionary *dict = | 365 GPBInt64UInt32Dictionary *dict = |
| 366 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues | 366 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues |
| 367 forKeys:kKeys | 367 forKeys:kKeys |
| 368 count:GPBARRAYSIZE(kValues)]; | 368 count:GPBARRAYSIZE(kValues)]; |
| 369 XCTAssertNotNil(dict); | 369 XCTAssertNotNil(dict); |
| 370 XCTAssertEqual(dict.count, 4U); | 370 XCTAssertEqual(dict.count, 4U); |
| 371 uint32_t value; | 371 uint32_t value; |
| 372 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 372 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 373 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 373 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 374 XCTAssertEqual(value, 100U); | 374 XCTAssertEqual(value, 100U); |
| 375 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 375 XCTAssertTrue([dict getUInt32:NULL forKey:22LL]); |
| 376 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 376 XCTAssertTrue([dict getUInt32:&value forKey:22LL]); |
| 377 XCTAssertEqual(value, 101U); | 377 XCTAssertEqual(value, 101U); |
| 378 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 378 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 379 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 379 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 380 XCTAssertEqual(value, 102U); | 380 XCTAssertEqual(value, 102U); |
| 381 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 381 XCTAssertTrue([dict getUInt32:NULL forKey:24LL]); |
| 382 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 382 XCTAssertTrue([dict getUInt32:&value forKey:24LL]); |
| 383 XCTAssertEqual(value, 103U); | 383 XCTAssertEqual(value, 103U); |
| 384 | 384 |
| 385 [dict setValue:103U forKey:21LL]; | 385 [dict setUInt32:103U forKey:21LL]; |
| 386 XCTAssertEqual(dict.count, 4U); | 386 XCTAssertEqual(dict.count, 4U); |
| 387 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 387 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 388 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 388 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 389 XCTAssertEqual(value, 103U); | 389 XCTAssertEqual(value, 103U); |
| 390 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 390 XCTAssertTrue([dict getUInt32:NULL forKey:22LL]); |
| 391 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 391 XCTAssertTrue([dict getUInt32:&value forKey:22LL]); |
| 392 XCTAssertEqual(value, 101U); | 392 XCTAssertEqual(value, 101U); |
| 393 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 393 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 394 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 394 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 395 XCTAssertEqual(value, 102U); | 395 XCTAssertEqual(value, 102U); |
| 396 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 396 XCTAssertTrue([dict getUInt32:NULL forKey:24LL]); |
| 397 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 397 XCTAssertTrue([dict getUInt32:&value forKey:24LL]); |
| 398 XCTAssertEqual(value, 103U); | 398 XCTAssertEqual(value, 103U); |
| 399 | 399 |
| 400 [dict setValue:101U forKey:24LL]; | 400 [dict setUInt32:101U forKey:24LL]; |
| 401 XCTAssertEqual(dict.count, 4U); | 401 XCTAssertEqual(dict.count, 4U); |
| 402 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 402 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 403 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 403 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 404 XCTAssertEqual(value, 103U); | 404 XCTAssertEqual(value, 103U); |
| 405 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 405 XCTAssertTrue([dict getUInt32:NULL forKey:22LL]); |
| 406 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 406 XCTAssertTrue([dict getUInt32:&value forKey:22LL]); |
| 407 XCTAssertEqual(value, 101U); | 407 XCTAssertEqual(value, 101U); |
| 408 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 408 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 409 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 409 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 410 XCTAssertEqual(value, 102U); | 410 XCTAssertEqual(value, 102U); |
| 411 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 411 XCTAssertTrue([dict getUInt32:NULL forKey:24LL]); |
| 412 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 412 XCTAssertTrue([dict getUInt32:&value forKey:24LL]); |
| 413 XCTAssertEqual(value, 101U); | 413 XCTAssertEqual(value, 101U); |
| 414 | 414 |
| 415 const int64_t kKeys2[] = { 22LL, 23LL }; | 415 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 416 const uint32_t kValues2[] = { 102U, 100U }; | 416 const uint32_t kValues2[] = { 102U, 100U }; |
| 417 GPBInt64UInt32Dictionary *dict2 = | 417 GPBInt64UInt32Dictionary *dict2 = |
| 418 [[GPBInt64UInt32Dictionary alloc] initWithValues:kValues2 | 418 [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues2 |
| 419 forKeys:kKeys2 | 419 forKeys:kKeys2 |
| 420 count:GPBARRAYSIZE(kValues2)]; | 420 count:GPBARRAYSIZE(kValues2)]; |
| 421 XCTAssertNotNil(dict2); | 421 XCTAssertNotNil(dict2); |
| 422 [dict addEntriesFromDictionary:dict2]; | 422 [dict addEntriesFromDictionary:dict2]; |
| 423 XCTAssertEqual(dict.count, 4U); | 423 XCTAssertEqual(dict.count, 4U); |
| 424 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 424 XCTAssertTrue([dict getUInt32:NULL forKey:21LL]); |
| 425 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 425 XCTAssertTrue([dict getUInt32:&value forKey:21LL]); |
| 426 XCTAssertEqual(value, 103U); | 426 XCTAssertEqual(value, 103U); |
| 427 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 427 XCTAssertTrue([dict getUInt32:NULL forKey:22LL]); |
| 428 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 428 XCTAssertTrue([dict getUInt32:&value forKey:22LL]); |
| 429 XCTAssertEqual(value, 102U); | 429 XCTAssertEqual(value, 102U); |
| 430 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 430 XCTAssertTrue([dict getUInt32:NULL forKey:23LL]); |
| 431 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 431 XCTAssertTrue([dict getUInt32:&value forKey:23LL]); |
| 432 XCTAssertEqual(value, 100U); | 432 XCTAssertEqual(value, 100U); |
| 433 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 433 XCTAssertTrue([dict getUInt32:NULL forKey:24LL]); |
| 434 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 434 XCTAssertTrue([dict getUInt32:&value forKey:24LL]); |
| 435 XCTAssertEqual(value, 101U); | 435 XCTAssertEqual(value, 101U); |
| 436 | 436 |
| 437 [dict2 release]; | 437 [dict2 release]; |
| 438 [dict release]; | 438 [dict release]; |
| 439 } | 439 } |
| 440 | 440 |
| 441 @end | 441 @end |
| 442 | 442 |
| 443 #pragma mark - Int64 -> Int32 | 443 #pragma mark - Int64 -> Int32 |
| 444 | 444 |
| 445 @interface GPBInt64Int32DictionaryTests : XCTestCase | 445 @interface GPBInt64Int32DictionaryTests : XCTestCase |
| 446 @end | 446 @end |
| 447 | 447 |
| 448 @implementation GPBInt64Int32DictionaryTests | 448 @implementation GPBInt64Int32DictionaryTests |
| 449 | 449 |
| 450 - (void)testEmpty { | 450 - (void)testEmpty { |
| 451 GPBInt64Int32Dictionary *dict = [[GPBInt64Int32Dictionary alloc] init]; | 451 GPBInt64Int32Dictionary *dict = [[GPBInt64Int32Dictionary alloc] init]; |
| 452 XCTAssertNotNil(dict); | 452 XCTAssertNotNil(dict); |
| 453 XCTAssertEqual(dict.count, 0U); | 453 XCTAssertEqual(dict.count, 0U); |
| 454 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 454 XCTAssertFalse([dict getInt32:NULL forKey:21LL]); |
| 455 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 455 [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { |
| 456 #pragma unused(aKey, aValue, stop) | 456 #pragma unused(aKey, aValue, stop) |
| 457 XCTFail(@"Shouldn't get here!"); | 457 XCTFail(@"Shouldn't get here!"); |
| 458 }]; | 458 }]; |
| 459 [dict release]; | 459 [dict release]; |
| 460 } | 460 } |
| 461 | 461 |
| 462 - (void)testOne { | 462 - (void)testOne { |
| 463 GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionaryWithValue:2
00 forKey:21LL]; | 463 GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionaryWithInt32:2
00 forKey:21LL]; |
| 464 XCTAssertNotNil(dict); | 464 XCTAssertNotNil(dict); |
| 465 XCTAssertEqual(dict.count, 1U); | 465 XCTAssertEqual(dict.count, 1U); |
| 466 int32_t value; | 466 int32_t value; |
| 467 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 467 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 468 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 468 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 469 XCTAssertEqual(value, 200); | 469 XCTAssertEqual(value, 200); |
| 470 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 470 XCTAssertFalse([dict getInt32:NULL forKey:22LL]); |
| 471 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 471 [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { |
| 472 XCTAssertEqual(aKey, 21LL); | 472 XCTAssertEqual(aKey, 21LL); |
| 473 XCTAssertEqual(aValue, 200); | 473 XCTAssertEqual(aValue, 200); |
| 474 XCTAssertNotEqual(stop, NULL); | 474 XCTAssertNotEqual(stop, NULL); |
| 475 }]; | 475 }]; |
| 476 } | 476 } |
| 477 | 477 |
| 478 - (void)testBasics { | 478 - (void)testBasics { |
| 479 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 479 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 480 const int32_t kValues[] = { 200, 201, 202 }; | 480 const int32_t kValues[] = { 200, 201, 202 }; |
| 481 GPBInt64Int32Dictionary *dict = | 481 GPBInt64Int32Dictionary *dict = |
| 482 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues | 482 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues |
| 483 forKeys:kKeys | 483 forKeys:kKeys |
| 484 count:GPBARRAYSIZE(kValues)]; | 484 count:GPBARRAYSIZE(kValues)]; |
| 485 XCTAssertNotNil(dict); | 485 XCTAssertNotNil(dict); |
| 486 XCTAssertEqual(dict.count, 3U); | 486 XCTAssertEqual(dict.count, 3U); |
| 487 int32_t value; | 487 int32_t value; |
| 488 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 488 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 489 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 489 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 490 XCTAssertEqual(value, 200); | 490 XCTAssertEqual(value, 200); |
| 491 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 491 XCTAssertTrue([dict getInt32:NULL forKey:22LL]); |
| 492 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 492 XCTAssertTrue([dict getInt32:&value forKey:22LL]); |
| 493 XCTAssertEqual(value, 201); | 493 XCTAssertEqual(value, 201); |
| 494 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 494 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 495 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 495 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 496 XCTAssertEqual(value, 202); | 496 XCTAssertEqual(value, 202); |
| 497 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 497 XCTAssertFalse([dict getInt32:NULL forKey:24LL]); |
| 498 | 498 |
| 499 __block NSUInteger idx = 0; | 499 __block NSUInteger idx = 0; |
| 500 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 500 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 501 int32_t *seenValues = malloc(3 * sizeof(int32_t)); | 501 int32_t *seenValues = malloc(3 * sizeof(int32_t)); |
| 502 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 502 [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { |
| 503 XCTAssertLessThan(idx, 3U); | 503 XCTAssertLessThan(idx, 3U); |
| 504 seenKeys[idx] = aKey; | 504 seenKeys[idx] = aKey; |
| 505 seenValues[idx] = aValue; | 505 seenValues[idx] = aValue; |
| 506 XCTAssertNotEqual(stop, NULL); | 506 XCTAssertNotEqual(stop, NULL); |
| 507 ++idx; | 507 ++idx; |
| 508 }]; | 508 }]; |
| 509 for (int i = 0; i < 3; ++i) { | 509 for (int i = 0; i < 3; ++i) { |
| 510 BOOL foundKey = NO; | 510 BOOL foundKey = NO; |
| 511 for (int j = 0; (j < 3) && !foundKey; ++j) { | 511 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 512 if (kKeys[i] == seenKeys[j]) { | 512 if (kKeys[i] == seenKeys[j]) { |
| 513 foundKey = YES; | 513 foundKey = YES; |
| 514 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 514 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 XCTAssertTrue(foundKey, @"i = %d", i); | 517 XCTAssertTrue(foundKey, @"i = %d", i); |
| 518 } | 518 } |
| 519 free(seenKeys); | 519 free(seenKeys); |
| 520 free(seenValues); | 520 free(seenValues); |
| 521 | 521 |
| 522 // Stopping the enumeration. | 522 // Stopping the enumeration. |
| 523 idx = 0; | 523 idx = 0; |
| 524 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 524 [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { |
| 525 #pragma unused(aKey, aValue) | 525 #pragma unused(aKey, aValue) |
| 526 if (idx == 1) *stop = YES; | 526 if (idx == 1) *stop = YES; |
| 527 XCTAssertNotEqual(idx, 2U); | 527 XCTAssertNotEqual(idx, 2U); |
| 528 ++idx; | 528 ++idx; |
| 529 }]; | 529 }]; |
| 530 [dict release]; | 530 [dict release]; |
| 531 } | 531 } |
| 532 | 532 |
| 533 - (void)testEquality { | 533 - (void)testEquality { |
| 534 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 534 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 535 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 535 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 536 const int32_t kValues1[] = { 200, 201, 202 }; | 536 const int32_t kValues1[] = { 200, 201, 202 }; |
| 537 const int32_t kValues2[] = { 200, 203, 202 }; | 537 const int32_t kValues2[] = { 200, 203, 202 }; |
| 538 const int32_t kValues3[] = { 200, 201, 202, 203 }; | 538 const int32_t kValues3[] = { 200, 201, 202, 203 }; |
| 539 GPBInt64Int32Dictionary *dict1 = | 539 GPBInt64Int32Dictionary *dict1 = |
| 540 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues1 | 540 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1 |
| 541 forKeys:kKeys1 | 541 forKeys:kKeys1 |
| 542 count:GPBARRAYSIZE(kValues1)]; | 542 count:GPBARRAYSIZE(kValues1)]; |
| 543 XCTAssertNotNil(dict1); | 543 XCTAssertNotNil(dict1); |
| 544 GPBInt64Int32Dictionary *dict1prime = | 544 GPBInt64Int32Dictionary *dict1prime = |
| 545 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues1 | 545 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1 |
| 546 forKeys:kKeys1 | 546 forKeys:kKeys1 |
| 547 count:GPBARRAYSIZE(kValues1)]; | 547 count:GPBARRAYSIZE(kValues1)]; |
| 548 XCTAssertNotNil(dict1prime); | 548 XCTAssertNotNil(dict1prime); |
| 549 GPBInt64Int32Dictionary *dict2 = | 549 GPBInt64Int32Dictionary *dict2 = |
| 550 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues2 | 550 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues2 |
| 551 forKeys:kKeys1 | 551 forKeys:kKeys1 |
| 552 count:GPBARRAYSIZE(kValues2)]; | 552 count:GPBARRAYSIZE(kValues2)]; |
| 553 XCTAssertNotNil(dict2); | 553 XCTAssertNotNil(dict2); |
| 554 GPBInt64Int32Dictionary *dict3 = | 554 GPBInt64Int32Dictionary *dict3 = |
| 555 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues1 | 555 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1 |
| 556 forKeys:kKeys2 | 556 forKeys:kKeys2 |
| 557 count:GPBARRAYSIZE(kValues1)]; | 557 count:GPBARRAYSIZE(kValues1)]; |
| 558 XCTAssertNotNil(dict3); | 558 XCTAssertNotNil(dict3); |
| 559 GPBInt64Int32Dictionary *dict4 = | 559 GPBInt64Int32Dictionary *dict4 = |
| 560 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues3 | 560 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues3 |
| 561 forKeys:kKeys1 | 561 forKeys:kKeys1 |
| 562 count:GPBARRAYSIZE(kValues3)]; | 562 count:GPBARRAYSIZE(kValues3)]; |
| 563 XCTAssertNotNil(dict4); | 563 XCTAssertNotNil(dict4); |
| 564 | 564 |
| 565 // 1/1Prime should be different objects, but equal. | 565 // 1/1Prime should be different objects, but equal. |
| 566 XCTAssertNotEqual(dict1, dict1prime); | 566 XCTAssertNotEqual(dict1, dict1prime); |
| 567 XCTAssertEqualObjects(dict1, dict1prime); | 567 XCTAssertEqualObjects(dict1, dict1prime); |
| 568 // Equal, so they must have same hash. | 568 // Equal, so they must have same hash. |
| 569 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 569 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 570 | 570 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 581 [dict1prime release]; | 581 [dict1prime release]; |
| 582 [dict2 release]; | 582 [dict2 release]; |
| 583 [dict3 release]; | 583 [dict3 release]; |
| 584 [dict4 release]; | 584 [dict4 release]; |
| 585 } | 585 } |
| 586 | 586 |
| 587 - (void)testCopy { | 587 - (void)testCopy { |
| 588 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 588 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 589 const int32_t kValues[] = { 200, 201, 202, 203 }; | 589 const int32_t kValues[] = { 200, 201, 202, 203 }; |
| 590 GPBInt64Int32Dictionary *dict = | 590 GPBInt64Int32Dictionary *dict = |
| 591 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues | 591 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues |
| 592 forKeys:kKeys | 592 forKeys:kKeys |
| 593 count:GPBARRAYSIZE(kValues)]; | 593 count:GPBARRAYSIZE(kValues)]; |
| 594 XCTAssertNotNil(dict); | 594 XCTAssertNotNil(dict); |
| 595 | 595 |
| 596 GPBInt64Int32Dictionary *dict2 = [dict copy]; | 596 GPBInt64Int32Dictionary *dict2 = [dict copy]; |
| 597 XCTAssertNotNil(dict2); | 597 XCTAssertNotNil(dict2); |
| 598 | 598 |
| 599 // Should be new object but equal. | 599 // Should be new object but equal. |
| 600 XCTAssertNotEqual(dict, dict2); | 600 XCTAssertNotEqual(dict, dict2); |
| 601 XCTAssertEqualObjects(dict, dict2); | 601 XCTAssertEqualObjects(dict, dict2); |
| 602 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int32Dictionary class]]); | 602 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int32Dictionary class]]); |
| 603 | 603 |
| 604 [dict2 release]; | 604 [dict2 release]; |
| 605 [dict release]; | 605 [dict release]; |
| 606 } | 606 } |
| 607 | 607 |
| 608 - (void)testDictionaryFromDictionary { | 608 - (void)testDictionaryFromDictionary { |
| 609 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 609 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 610 const int32_t kValues[] = { 200, 201, 202, 203 }; | 610 const int32_t kValues[] = { 200, 201, 202, 203 }; |
| 611 GPBInt64Int32Dictionary *dict = | 611 GPBInt64Int32Dictionary *dict = |
| 612 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues | 612 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues |
| 613 forKeys:kKeys | 613 forKeys:kKeys |
| 614 count:GPBARRAYSIZE(kValues)]; | 614 count:GPBARRAYSIZE(kValues)]; |
| 615 XCTAssertNotNil(dict); | 615 XCTAssertNotNil(dict); |
| 616 | 616 |
| 617 GPBInt64Int32Dictionary *dict2 = | 617 GPBInt64Int32Dictionary *dict2 = |
| 618 [GPBInt64Int32Dictionary dictionaryWithDictionary:dict]; | 618 [GPBInt64Int32Dictionary dictionaryWithDictionary:dict]; |
| 619 XCTAssertNotNil(dict2); | 619 XCTAssertNotNil(dict2); |
| 620 | 620 |
| 621 // Should be new pointer, but equal objects. | 621 // Should be new pointer, but equal objects. |
| 622 XCTAssertNotEqual(dict, dict2); | 622 XCTAssertNotEqual(dict, dict2); |
| 623 XCTAssertEqualObjects(dict, dict2); | 623 XCTAssertEqualObjects(dict, dict2); |
| 624 [dict release]; | 624 [dict release]; |
| 625 } | 625 } |
| 626 | 626 |
| 627 - (void)testAdds { | 627 - (void)testAdds { |
| 628 GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionary]; | 628 GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionary]; |
| 629 XCTAssertNotNil(dict); | 629 XCTAssertNotNil(dict); |
| 630 | 630 |
| 631 XCTAssertEqual(dict.count, 0U); | 631 XCTAssertEqual(dict.count, 0U); |
| 632 [dict setValue:200 forKey:21LL]; | 632 [dict setInt32:200 forKey:21LL]; |
| 633 XCTAssertEqual(dict.count, 1U); | 633 XCTAssertEqual(dict.count, 1U); |
| 634 | 634 |
| 635 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 635 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 636 const int32_t kValues[] = { 201, 202, 203 }; | 636 const int32_t kValues[] = { 201, 202, 203 }; |
| 637 GPBInt64Int32Dictionary *dict2 = | 637 GPBInt64Int32Dictionary *dict2 = |
| 638 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues | 638 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues |
| 639 forKeys:kKeys | 639 forKeys:kKeys |
| 640 count:GPBARRAYSIZE(kValues)]; | 640 count:GPBARRAYSIZE(kValues)]; |
| 641 XCTAssertNotNil(dict2); | 641 XCTAssertNotNil(dict2); |
| 642 [dict addEntriesFromDictionary:dict2]; | 642 [dict addEntriesFromDictionary:dict2]; |
| 643 XCTAssertEqual(dict.count, 4U); | 643 XCTAssertEqual(dict.count, 4U); |
| 644 | 644 |
| 645 int32_t value; | 645 int32_t value; |
| 646 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 646 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 647 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 647 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 648 XCTAssertEqual(value, 200); | 648 XCTAssertEqual(value, 200); |
| 649 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 649 XCTAssertTrue([dict getInt32:NULL forKey:22LL]); |
| 650 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 650 XCTAssertTrue([dict getInt32:&value forKey:22LL]); |
| 651 XCTAssertEqual(value, 201); | 651 XCTAssertEqual(value, 201); |
| 652 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 652 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 653 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 653 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 654 XCTAssertEqual(value, 202); | 654 XCTAssertEqual(value, 202); |
| 655 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 655 XCTAssertTrue([dict getInt32:NULL forKey:24LL]); |
| 656 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 656 XCTAssertTrue([dict getInt32:&value forKey:24LL]); |
| 657 XCTAssertEqual(value, 203); | 657 XCTAssertEqual(value, 203); |
| 658 [dict2 release]; | 658 [dict2 release]; |
| 659 } | 659 } |
| 660 | 660 |
| 661 - (void)testRemove { | 661 - (void)testRemove { |
| 662 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 662 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 663 const int32_t kValues[] = { 200, 201, 202, 203 }; | 663 const int32_t kValues[] = { 200, 201, 202, 203 }; |
| 664 GPBInt64Int32Dictionary *dict = | 664 GPBInt64Int32Dictionary *dict = |
| 665 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues | 665 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues |
| 666 forKeys:kKeys | 666 forKeys:kKeys |
| 667 count:GPBARRAYSIZE(kValues)]; | 667 count:GPBARRAYSIZE(kValues)]; |
| 668 XCTAssertNotNil(dict); | 668 XCTAssertNotNil(dict); |
| 669 XCTAssertEqual(dict.count, 4U); | 669 XCTAssertEqual(dict.count, 4U); |
| 670 | 670 |
| 671 [dict removeValueForKey:22LL]; | 671 [dict removeInt32ForKey:22LL]; |
| 672 XCTAssertEqual(dict.count, 3U); | 672 XCTAssertEqual(dict.count, 3U); |
| 673 int32_t value; | 673 int32_t value; |
| 674 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 674 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 675 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 675 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 676 XCTAssertEqual(value, 200); | 676 XCTAssertEqual(value, 200); |
| 677 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 677 XCTAssertFalse([dict getInt32:NULL forKey:22LL]); |
| 678 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 678 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 679 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 679 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 680 XCTAssertEqual(value, 202); | 680 XCTAssertEqual(value, 202); |
| 681 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 681 XCTAssertTrue([dict getInt32:NULL forKey:24LL]); |
| 682 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 682 XCTAssertTrue([dict getInt32:&value forKey:24LL]); |
| 683 XCTAssertEqual(value, 203); | 683 XCTAssertEqual(value, 203); |
| 684 | 684 |
| 685 // Remove again does nothing. | 685 // Remove again does nothing. |
| 686 [dict removeValueForKey:22LL]; | 686 [dict removeInt32ForKey:22LL]; |
| 687 XCTAssertEqual(dict.count, 3U); | 687 XCTAssertEqual(dict.count, 3U); |
| 688 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 688 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 689 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 689 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 690 XCTAssertEqual(value, 200); | 690 XCTAssertEqual(value, 200); |
| 691 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 691 XCTAssertFalse([dict getInt32:NULL forKey:22LL]); |
| 692 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 692 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 693 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 693 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 694 XCTAssertEqual(value, 202); | 694 XCTAssertEqual(value, 202); |
| 695 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 695 XCTAssertTrue([dict getInt32:NULL forKey:24LL]); |
| 696 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 696 XCTAssertTrue([dict getInt32:&value forKey:24LL]); |
| 697 XCTAssertEqual(value, 203); | 697 XCTAssertEqual(value, 203); |
| 698 | 698 |
| 699 [dict removeValueForKey:24LL]; | 699 [dict removeInt32ForKey:24LL]; |
| 700 XCTAssertEqual(dict.count, 2U); | 700 XCTAssertEqual(dict.count, 2U); |
| 701 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 701 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 702 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 702 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 703 XCTAssertEqual(value, 200); | 703 XCTAssertEqual(value, 200); |
| 704 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 704 XCTAssertFalse([dict getInt32:NULL forKey:22LL]); |
| 705 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 705 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 706 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 706 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 707 XCTAssertEqual(value, 202); | 707 XCTAssertEqual(value, 202); |
| 708 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 708 XCTAssertFalse([dict getInt32:NULL forKey:24LL]); |
| 709 | 709 |
| 710 [dict removeAll]; | 710 [dict removeAll]; |
| 711 XCTAssertEqual(dict.count, 0U); | 711 XCTAssertEqual(dict.count, 0U); |
| 712 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 712 XCTAssertFalse([dict getInt32:NULL forKey:21LL]); |
| 713 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 713 XCTAssertFalse([dict getInt32:NULL forKey:22LL]); |
| 714 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 714 XCTAssertFalse([dict getInt32:NULL forKey:23LL]); |
| 715 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 715 XCTAssertFalse([dict getInt32:NULL forKey:24LL]); |
| 716 [dict release]; | 716 [dict release]; |
| 717 } | 717 } |
| 718 | 718 |
| 719 - (void)testInplaceMutation { | 719 - (void)testInplaceMutation { |
| 720 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 720 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 721 const int32_t kValues[] = { 200, 201, 202, 203 }; | 721 const int32_t kValues[] = { 200, 201, 202, 203 }; |
| 722 GPBInt64Int32Dictionary *dict = | 722 GPBInt64Int32Dictionary *dict = |
| 723 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues | 723 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues |
| 724 forKeys:kKeys | 724 forKeys:kKeys |
| 725 count:GPBARRAYSIZE(kValues)]; | 725 count:GPBARRAYSIZE(kValues)]; |
| 726 XCTAssertNotNil(dict); | 726 XCTAssertNotNil(dict); |
| 727 XCTAssertEqual(dict.count, 4U); | 727 XCTAssertEqual(dict.count, 4U); |
| 728 int32_t value; | 728 int32_t value; |
| 729 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 729 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 730 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 730 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 731 XCTAssertEqual(value, 200); | 731 XCTAssertEqual(value, 200); |
| 732 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 732 XCTAssertTrue([dict getInt32:NULL forKey:22LL]); |
| 733 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 733 XCTAssertTrue([dict getInt32:&value forKey:22LL]); |
| 734 XCTAssertEqual(value, 201); | 734 XCTAssertEqual(value, 201); |
| 735 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 735 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 736 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 736 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 737 XCTAssertEqual(value, 202); | 737 XCTAssertEqual(value, 202); |
| 738 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 738 XCTAssertTrue([dict getInt32:NULL forKey:24LL]); |
| 739 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 739 XCTAssertTrue([dict getInt32:&value forKey:24LL]); |
| 740 XCTAssertEqual(value, 203); | 740 XCTAssertEqual(value, 203); |
| 741 | 741 |
| 742 [dict setValue:203 forKey:21LL]; | 742 [dict setInt32:203 forKey:21LL]; |
| 743 XCTAssertEqual(dict.count, 4U); | 743 XCTAssertEqual(dict.count, 4U); |
| 744 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 744 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 745 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 745 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 746 XCTAssertEqual(value, 203); | 746 XCTAssertEqual(value, 203); |
| 747 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 747 XCTAssertTrue([dict getInt32:NULL forKey:22LL]); |
| 748 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 748 XCTAssertTrue([dict getInt32:&value forKey:22LL]); |
| 749 XCTAssertEqual(value, 201); | 749 XCTAssertEqual(value, 201); |
| 750 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 750 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 751 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 751 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 752 XCTAssertEqual(value, 202); | 752 XCTAssertEqual(value, 202); |
| 753 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 753 XCTAssertTrue([dict getInt32:NULL forKey:24LL]); |
| 754 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 754 XCTAssertTrue([dict getInt32:&value forKey:24LL]); |
| 755 XCTAssertEqual(value, 203); | 755 XCTAssertEqual(value, 203); |
| 756 | 756 |
| 757 [dict setValue:201 forKey:24LL]; | 757 [dict setInt32:201 forKey:24LL]; |
| 758 XCTAssertEqual(dict.count, 4U); | 758 XCTAssertEqual(dict.count, 4U); |
| 759 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 759 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 760 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 760 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 761 XCTAssertEqual(value, 203); | 761 XCTAssertEqual(value, 203); |
| 762 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 762 XCTAssertTrue([dict getInt32:NULL forKey:22LL]); |
| 763 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 763 XCTAssertTrue([dict getInt32:&value forKey:22LL]); |
| 764 XCTAssertEqual(value, 201); | 764 XCTAssertEqual(value, 201); |
| 765 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 765 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 766 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 766 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 767 XCTAssertEqual(value, 202); | 767 XCTAssertEqual(value, 202); |
| 768 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 768 XCTAssertTrue([dict getInt32:NULL forKey:24LL]); |
| 769 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 769 XCTAssertTrue([dict getInt32:&value forKey:24LL]); |
| 770 XCTAssertEqual(value, 201); | 770 XCTAssertEqual(value, 201); |
| 771 | 771 |
| 772 const int64_t kKeys2[] = { 22LL, 23LL }; | 772 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 773 const int32_t kValues2[] = { 202, 200 }; | 773 const int32_t kValues2[] = { 202, 200 }; |
| 774 GPBInt64Int32Dictionary *dict2 = | 774 GPBInt64Int32Dictionary *dict2 = |
| 775 [[GPBInt64Int32Dictionary alloc] initWithValues:kValues2 | 775 [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues2 |
| 776 forKeys:kKeys2 | 776 forKeys:kKeys2 |
| 777 count:GPBARRAYSIZE(kValues2)]; | 777 count:GPBARRAYSIZE(kValues2)]; |
| 778 XCTAssertNotNil(dict2); | 778 XCTAssertNotNil(dict2); |
| 779 [dict addEntriesFromDictionary:dict2]; | 779 [dict addEntriesFromDictionary:dict2]; |
| 780 XCTAssertEqual(dict.count, 4U); | 780 XCTAssertEqual(dict.count, 4U); |
| 781 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 781 XCTAssertTrue([dict getInt32:NULL forKey:21LL]); |
| 782 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 782 XCTAssertTrue([dict getInt32:&value forKey:21LL]); |
| 783 XCTAssertEqual(value, 203); | 783 XCTAssertEqual(value, 203); |
| 784 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 784 XCTAssertTrue([dict getInt32:NULL forKey:22LL]); |
| 785 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 785 XCTAssertTrue([dict getInt32:&value forKey:22LL]); |
| 786 XCTAssertEqual(value, 202); | 786 XCTAssertEqual(value, 202); |
| 787 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 787 XCTAssertTrue([dict getInt32:NULL forKey:23LL]); |
| 788 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 788 XCTAssertTrue([dict getInt32:&value forKey:23LL]); |
| 789 XCTAssertEqual(value, 200); | 789 XCTAssertEqual(value, 200); |
| 790 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 790 XCTAssertTrue([dict getInt32:NULL forKey:24LL]); |
| 791 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 791 XCTAssertTrue([dict getInt32:&value forKey:24LL]); |
| 792 XCTAssertEqual(value, 201); | 792 XCTAssertEqual(value, 201); |
| 793 | 793 |
| 794 [dict2 release]; | 794 [dict2 release]; |
| 795 [dict release]; | 795 [dict release]; |
| 796 } | 796 } |
| 797 | 797 |
| 798 @end | 798 @end |
| 799 | 799 |
| 800 #pragma mark - Int64 -> UInt64 | 800 #pragma mark - Int64 -> UInt64 |
| 801 | 801 |
| 802 @interface GPBInt64UInt64DictionaryTests : XCTestCase | 802 @interface GPBInt64UInt64DictionaryTests : XCTestCase |
| 803 @end | 803 @end |
| 804 | 804 |
| 805 @implementation GPBInt64UInt64DictionaryTests | 805 @implementation GPBInt64UInt64DictionaryTests |
| 806 | 806 |
| 807 - (void)testEmpty { | 807 - (void)testEmpty { |
| 808 GPBInt64UInt64Dictionary *dict = [[GPBInt64UInt64Dictionary alloc] init]; | 808 GPBInt64UInt64Dictionary *dict = [[GPBInt64UInt64Dictionary alloc] init]; |
| 809 XCTAssertNotNil(dict); | 809 XCTAssertNotNil(dict); |
| 810 XCTAssertEqual(dict.count, 0U); | 810 XCTAssertEqual(dict.count, 0U); |
| 811 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 811 XCTAssertFalse([dict getUInt64:NULL forKey:21LL]); |
| 812 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *
stop) { | 812 [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL
*stop) { |
| 813 #pragma unused(aKey, aValue, stop) | 813 #pragma unused(aKey, aValue, stop) |
| 814 XCTFail(@"Shouldn't get here!"); | 814 XCTFail(@"Shouldn't get here!"); |
| 815 }]; | 815 }]; |
| 816 [dict release]; | 816 [dict release]; |
| 817 } | 817 } |
| 818 | 818 |
| 819 - (void)testOne { | 819 - (void)testOne { |
| 820 GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionaryWithValue
:300U forKey:21LL]; | 820 GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionaryWithUInt6
4:300U forKey:21LL]; |
| 821 XCTAssertNotNil(dict); | 821 XCTAssertNotNil(dict); |
| 822 XCTAssertEqual(dict.count, 1U); | 822 XCTAssertEqual(dict.count, 1U); |
| 823 uint64_t value; | 823 uint64_t value; |
| 824 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 824 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 825 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 825 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 826 XCTAssertEqual(value, 300U); | 826 XCTAssertEqual(value, 300U); |
| 827 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 827 XCTAssertFalse([dict getUInt64:NULL forKey:22LL]); |
| 828 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *
stop) { | 828 [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL
*stop) { |
| 829 XCTAssertEqual(aKey, 21LL); | 829 XCTAssertEqual(aKey, 21LL); |
| 830 XCTAssertEqual(aValue, 300U); | 830 XCTAssertEqual(aValue, 300U); |
| 831 XCTAssertNotEqual(stop, NULL); | 831 XCTAssertNotEqual(stop, NULL); |
| 832 }]; | 832 }]; |
| 833 } | 833 } |
| 834 | 834 |
| 835 - (void)testBasics { | 835 - (void)testBasics { |
| 836 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 836 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 837 const uint64_t kValues[] = { 300U, 301U, 302U }; | 837 const uint64_t kValues[] = { 300U, 301U, 302U }; |
| 838 GPBInt64UInt64Dictionary *dict = | 838 GPBInt64UInt64Dictionary *dict = |
| 839 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues | 839 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues |
| 840 forKeys:kKeys | 840 forKeys:kKeys |
| 841 count:GPBARRAYSIZE(kValues)]; | 841 count:GPBARRAYSIZE(kValues)]; |
| 842 XCTAssertNotNil(dict); | 842 XCTAssertNotNil(dict); |
| 843 XCTAssertEqual(dict.count, 3U); | 843 XCTAssertEqual(dict.count, 3U); |
| 844 uint64_t value; | 844 uint64_t value; |
| 845 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 845 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 846 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 846 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 847 XCTAssertEqual(value, 300U); | 847 XCTAssertEqual(value, 300U); |
| 848 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 848 XCTAssertTrue([dict getUInt64:NULL forKey:22LL]); |
| 849 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 849 XCTAssertTrue([dict getUInt64:&value forKey:22LL]); |
| 850 XCTAssertEqual(value, 301U); | 850 XCTAssertEqual(value, 301U); |
| 851 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 851 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 852 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 852 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 853 XCTAssertEqual(value, 302U); | 853 XCTAssertEqual(value, 302U); |
| 854 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 854 XCTAssertFalse([dict getUInt64:NULL forKey:24LL]); |
| 855 | 855 |
| 856 __block NSUInteger idx = 0; | 856 __block NSUInteger idx = 0; |
| 857 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 857 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 858 uint64_t *seenValues = malloc(3 * sizeof(uint64_t)); | 858 uint64_t *seenValues = malloc(3 * sizeof(uint64_t)); |
| 859 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *
stop) { | 859 [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL
*stop) { |
| 860 XCTAssertLessThan(idx, 3U); | 860 XCTAssertLessThan(idx, 3U); |
| 861 seenKeys[idx] = aKey; | 861 seenKeys[idx] = aKey; |
| 862 seenValues[idx] = aValue; | 862 seenValues[idx] = aValue; |
| 863 XCTAssertNotEqual(stop, NULL); | 863 XCTAssertNotEqual(stop, NULL); |
| 864 ++idx; | 864 ++idx; |
| 865 }]; | 865 }]; |
| 866 for (int i = 0; i < 3; ++i) { | 866 for (int i = 0; i < 3; ++i) { |
| 867 BOOL foundKey = NO; | 867 BOOL foundKey = NO; |
| 868 for (int j = 0; (j < 3) && !foundKey; ++j) { | 868 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 869 if (kKeys[i] == seenKeys[j]) { | 869 if (kKeys[i] == seenKeys[j]) { |
| 870 foundKey = YES; | 870 foundKey = YES; |
| 871 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 871 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 872 } | 872 } |
| 873 } | 873 } |
| 874 XCTAssertTrue(foundKey, @"i = %d", i); | 874 XCTAssertTrue(foundKey, @"i = %d", i); |
| 875 } | 875 } |
| 876 free(seenKeys); | 876 free(seenKeys); |
| 877 free(seenValues); | 877 free(seenValues); |
| 878 | 878 |
| 879 // Stopping the enumeration. | 879 // Stopping the enumeration. |
| 880 idx = 0; | 880 idx = 0; |
| 881 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *
stop) { | 881 [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL
*stop) { |
| 882 #pragma unused(aKey, aValue) | 882 #pragma unused(aKey, aValue) |
| 883 if (idx == 1) *stop = YES; | 883 if (idx == 1) *stop = YES; |
| 884 XCTAssertNotEqual(idx, 2U); | 884 XCTAssertNotEqual(idx, 2U); |
| 885 ++idx; | 885 ++idx; |
| 886 }]; | 886 }]; |
| 887 [dict release]; | 887 [dict release]; |
| 888 } | 888 } |
| 889 | 889 |
| 890 - (void)testEquality { | 890 - (void)testEquality { |
| 891 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 891 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 892 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 892 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 893 const uint64_t kValues1[] = { 300U, 301U, 302U }; | 893 const uint64_t kValues1[] = { 300U, 301U, 302U }; |
| 894 const uint64_t kValues2[] = { 300U, 303U, 302U }; | 894 const uint64_t kValues2[] = { 300U, 303U, 302U }; |
| 895 const uint64_t kValues3[] = { 300U, 301U, 302U, 303U }; | 895 const uint64_t kValues3[] = { 300U, 301U, 302U, 303U }; |
| 896 GPBInt64UInt64Dictionary *dict1 = | 896 GPBInt64UInt64Dictionary *dict1 = |
| 897 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues1 | 897 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1 |
| 898 forKeys:kKeys1 | 898 forKeys:kKeys1 |
| 899 count:GPBARRAYSIZE(kValues1)]; | 899 count:GPBARRAYSIZE(kValues1)]; |
| 900 XCTAssertNotNil(dict1); | 900 XCTAssertNotNil(dict1); |
| 901 GPBInt64UInt64Dictionary *dict1prime = | 901 GPBInt64UInt64Dictionary *dict1prime = |
| 902 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues1 | 902 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1 |
| 903 forKeys:kKeys1 | 903 forKeys:kKeys1 |
| 904 count:GPBARRAYSIZE(kValues1)]; | 904 count:GPBARRAYSIZE(kValues1)]; |
| 905 XCTAssertNotNil(dict1prime); | 905 XCTAssertNotNil(dict1prime); |
| 906 GPBInt64UInt64Dictionary *dict2 = | 906 GPBInt64UInt64Dictionary *dict2 = |
| 907 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues2 | 907 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues2 |
| 908 forKeys:kKeys1 | 908 forKeys:kKeys1 |
| 909 count:GPBARRAYSIZE(kValues2)]; | 909 count:GPBARRAYSIZE(kValues2)]; |
| 910 XCTAssertNotNil(dict2); | 910 XCTAssertNotNil(dict2); |
| 911 GPBInt64UInt64Dictionary *dict3 = | 911 GPBInt64UInt64Dictionary *dict3 = |
| 912 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues1 | 912 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1 |
| 913 forKeys:kKeys2 | 913 forKeys:kKeys2 |
| 914 count:GPBARRAYSIZE(kValues1)]; | 914 count:GPBARRAYSIZE(kValues1)]; |
| 915 XCTAssertNotNil(dict3); | 915 XCTAssertNotNil(dict3); |
| 916 GPBInt64UInt64Dictionary *dict4 = | 916 GPBInt64UInt64Dictionary *dict4 = |
| 917 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues3 | 917 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues3 |
| 918 forKeys:kKeys1 | 918 forKeys:kKeys1 |
| 919 count:GPBARRAYSIZE(kValues3)]; | 919 count:GPBARRAYSIZE(kValues3)]; |
| 920 XCTAssertNotNil(dict4); | 920 XCTAssertNotNil(dict4); |
| 921 | 921 |
| 922 // 1/1Prime should be different objects, but equal. | 922 // 1/1Prime should be different objects, but equal. |
| 923 XCTAssertNotEqual(dict1, dict1prime); | 923 XCTAssertNotEqual(dict1, dict1prime); |
| 924 XCTAssertEqualObjects(dict1, dict1prime); | 924 XCTAssertEqualObjects(dict1, dict1prime); |
| 925 // Equal, so they must have same hash. | 925 // Equal, so they must have same hash. |
| 926 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 926 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 927 | 927 |
| 928 // 2 is same keys, different values; not equal. | 928 // 2 is same keys, different values; not equal. |
| 929 XCTAssertNotEqualObjects(dict1, dict2); | 929 XCTAssertNotEqualObjects(dict1, dict2); |
| 930 | 930 |
| 931 // 3 is different keys, same values; not equal. | 931 // 3 is different keys, same values; not equal. |
| 932 XCTAssertNotEqualObjects(dict1, dict3); | 932 XCTAssertNotEqualObjects(dict1, dict3); |
| 933 | 933 |
| 934 // 4 extra pair; not equal | 934 // 4 extra pair; not equal |
| 935 XCTAssertNotEqualObjects(dict1, dict4); | 935 XCTAssertNotEqualObjects(dict1, dict4); |
| 936 | 936 |
| 937 [dict1 release]; | 937 [dict1 release]; |
| 938 [dict1prime release]; | 938 [dict1prime release]; |
| 939 [dict2 release]; | 939 [dict2 release]; |
| 940 [dict3 release]; | 940 [dict3 release]; |
| 941 [dict4 release]; | 941 [dict4 release]; |
| 942 } | 942 } |
| 943 | 943 |
| 944 - (void)testCopy { | 944 - (void)testCopy { |
| 945 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 945 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 946 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; | 946 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; |
| 947 GPBInt64UInt64Dictionary *dict = | 947 GPBInt64UInt64Dictionary *dict = |
| 948 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues | 948 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues |
| 949 forKeys:kKeys | 949 forKeys:kKeys |
| 950 count:GPBARRAYSIZE(kValues)]; | 950 count:GPBARRAYSIZE(kValues)]; |
| 951 XCTAssertNotNil(dict); | 951 XCTAssertNotNil(dict); |
| 952 | 952 |
| 953 GPBInt64UInt64Dictionary *dict2 = [dict copy]; | 953 GPBInt64UInt64Dictionary *dict2 = [dict copy]; |
| 954 XCTAssertNotNil(dict2); | 954 XCTAssertNotNil(dict2); |
| 955 | 955 |
| 956 // Should be new object but equal. | 956 // Should be new object but equal. |
| 957 XCTAssertNotEqual(dict, dict2); | 957 XCTAssertNotEqual(dict, dict2); |
| 958 XCTAssertEqualObjects(dict, dict2); | 958 XCTAssertEqualObjects(dict, dict2); |
| 959 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt64Dictionary class]]); | 959 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt64Dictionary class]]); |
| 960 | 960 |
| 961 [dict2 release]; | 961 [dict2 release]; |
| 962 [dict release]; | 962 [dict release]; |
| 963 } | 963 } |
| 964 | 964 |
| 965 - (void)testDictionaryFromDictionary { | 965 - (void)testDictionaryFromDictionary { |
| 966 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 966 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 967 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; | 967 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; |
| 968 GPBInt64UInt64Dictionary *dict = | 968 GPBInt64UInt64Dictionary *dict = |
| 969 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues | 969 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues |
| 970 forKeys:kKeys | 970 forKeys:kKeys |
| 971 count:GPBARRAYSIZE(kValues)]; | 971 count:GPBARRAYSIZE(kValues)]; |
| 972 XCTAssertNotNil(dict); | 972 XCTAssertNotNil(dict); |
| 973 | 973 |
| 974 GPBInt64UInt64Dictionary *dict2 = | 974 GPBInt64UInt64Dictionary *dict2 = |
| 975 [GPBInt64UInt64Dictionary dictionaryWithDictionary:dict]; | 975 [GPBInt64UInt64Dictionary dictionaryWithDictionary:dict]; |
| 976 XCTAssertNotNil(dict2); | 976 XCTAssertNotNil(dict2); |
| 977 | 977 |
| 978 // Should be new pointer, but equal objects. | 978 // Should be new pointer, but equal objects. |
| 979 XCTAssertNotEqual(dict, dict2); | 979 XCTAssertNotEqual(dict, dict2); |
| 980 XCTAssertEqualObjects(dict, dict2); | 980 XCTAssertEqualObjects(dict, dict2); |
| 981 [dict release]; | 981 [dict release]; |
| 982 } | 982 } |
| 983 | 983 |
| 984 - (void)testAdds { | 984 - (void)testAdds { |
| 985 GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionary]; | 985 GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionary]; |
| 986 XCTAssertNotNil(dict); | 986 XCTAssertNotNil(dict); |
| 987 | 987 |
| 988 XCTAssertEqual(dict.count, 0U); | 988 XCTAssertEqual(dict.count, 0U); |
| 989 [dict setValue:300U forKey:21LL]; | 989 [dict setUInt64:300U forKey:21LL]; |
| 990 XCTAssertEqual(dict.count, 1U); | 990 XCTAssertEqual(dict.count, 1U); |
| 991 | 991 |
| 992 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 992 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 993 const uint64_t kValues[] = { 301U, 302U, 303U }; | 993 const uint64_t kValues[] = { 301U, 302U, 303U }; |
| 994 GPBInt64UInt64Dictionary *dict2 = | 994 GPBInt64UInt64Dictionary *dict2 = |
| 995 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues | 995 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues |
| 996 forKeys:kKeys | 996 forKeys:kKeys |
| 997 count:GPBARRAYSIZE(kValues)]; | 997 count:GPBARRAYSIZE(kValues)]; |
| 998 XCTAssertNotNil(dict2); | 998 XCTAssertNotNil(dict2); |
| 999 [dict addEntriesFromDictionary:dict2]; | 999 [dict addEntriesFromDictionary:dict2]; |
| 1000 XCTAssertEqual(dict.count, 4U); | 1000 XCTAssertEqual(dict.count, 4U); |
| 1001 | 1001 |
| 1002 uint64_t value; | 1002 uint64_t value; |
| 1003 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1003 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1004 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1004 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1005 XCTAssertEqual(value, 300U); | 1005 XCTAssertEqual(value, 300U); |
| 1006 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1006 XCTAssertTrue([dict getUInt64:NULL forKey:22LL]); |
| 1007 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1007 XCTAssertTrue([dict getUInt64:&value forKey:22LL]); |
| 1008 XCTAssertEqual(value, 301U); | 1008 XCTAssertEqual(value, 301U); |
| 1009 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1009 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1010 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1010 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1011 XCTAssertEqual(value, 302U); | 1011 XCTAssertEqual(value, 302U); |
| 1012 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1012 XCTAssertTrue([dict getUInt64:NULL forKey:24LL]); |
| 1013 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1013 XCTAssertTrue([dict getUInt64:&value forKey:24LL]); |
| 1014 XCTAssertEqual(value, 303U); | 1014 XCTAssertEqual(value, 303U); |
| 1015 [dict2 release]; | 1015 [dict2 release]; |
| 1016 } | 1016 } |
| 1017 | 1017 |
| 1018 - (void)testRemove { | 1018 - (void)testRemove { |
| 1019 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1019 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1020 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; | 1020 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; |
| 1021 GPBInt64UInt64Dictionary *dict = | 1021 GPBInt64UInt64Dictionary *dict = |
| 1022 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues | 1022 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues |
| 1023 forKeys:kKeys | 1023 forKeys:kKeys |
| 1024 count:GPBARRAYSIZE(kValues)]; | 1024 count:GPBARRAYSIZE(kValues)]; |
| 1025 XCTAssertNotNil(dict); | 1025 XCTAssertNotNil(dict); |
| 1026 XCTAssertEqual(dict.count, 4U); | 1026 XCTAssertEqual(dict.count, 4U); |
| 1027 | 1027 |
| 1028 [dict removeValueForKey:22LL]; | 1028 [dict removeUInt64ForKey:22LL]; |
| 1029 XCTAssertEqual(dict.count, 3U); | 1029 XCTAssertEqual(dict.count, 3U); |
| 1030 uint64_t value; | 1030 uint64_t value; |
| 1031 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1031 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1032 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1032 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1033 XCTAssertEqual(value, 300U); | 1033 XCTAssertEqual(value, 300U); |
| 1034 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1034 XCTAssertFalse([dict getUInt64:NULL forKey:22LL]); |
| 1035 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1035 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1036 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1036 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1037 XCTAssertEqual(value, 302U); | 1037 XCTAssertEqual(value, 302U); |
| 1038 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1038 XCTAssertTrue([dict getUInt64:NULL forKey:24LL]); |
| 1039 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1039 XCTAssertTrue([dict getUInt64:&value forKey:24LL]); |
| 1040 XCTAssertEqual(value, 303U); | 1040 XCTAssertEqual(value, 303U); |
| 1041 | 1041 |
| 1042 // Remove again does nothing. | 1042 // Remove again does nothing. |
| 1043 [dict removeValueForKey:22LL]; | 1043 [dict removeUInt64ForKey:22LL]; |
| 1044 XCTAssertEqual(dict.count, 3U); | 1044 XCTAssertEqual(dict.count, 3U); |
| 1045 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1045 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1046 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1046 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1047 XCTAssertEqual(value, 300U); | 1047 XCTAssertEqual(value, 300U); |
| 1048 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1048 XCTAssertFalse([dict getUInt64:NULL forKey:22LL]); |
| 1049 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1049 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1050 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1050 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1051 XCTAssertEqual(value, 302U); | 1051 XCTAssertEqual(value, 302U); |
| 1052 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1052 XCTAssertTrue([dict getUInt64:NULL forKey:24LL]); |
| 1053 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1053 XCTAssertTrue([dict getUInt64:&value forKey:24LL]); |
| 1054 XCTAssertEqual(value, 303U); | 1054 XCTAssertEqual(value, 303U); |
| 1055 | 1055 |
| 1056 [dict removeValueForKey:24LL]; | 1056 [dict removeUInt64ForKey:24LL]; |
| 1057 XCTAssertEqual(dict.count, 2U); | 1057 XCTAssertEqual(dict.count, 2U); |
| 1058 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1058 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1059 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1059 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1060 XCTAssertEqual(value, 300U); | 1060 XCTAssertEqual(value, 300U); |
| 1061 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1061 XCTAssertFalse([dict getUInt64:NULL forKey:22LL]); |
| 1062 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1062 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1063 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1063 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1064 XCTAssertEqual(value, 302U); | 1064 XCTAssertEqual(value, 302U); |
| 1065 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1065 XCTAssertFalse([dict getUInt64:NULL forKey:24LL]); |
| 1066 | 1066 |
| 1067 [dict removeAll]; | 1067 [dict removeAll]; |
| 1068 XCTAssertEqual(dict.count, 0U); | 1068 XCTAssertEqual(dict.count, 0U); |
| 1069 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 1069 XCTAssertFalse([dict getUInt64:NULL forKey:21LL]); |
| 1070 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1070 XCTAssertFalse([dict getUInt64:NULL forKey:22LL]); |
| 1071 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 1071 XCTAssertFalse([dict getUInt64:NULL forKey:23LL]); |
| 1072 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1072 XCTAssertFalse([dict getUInt64:NULL forKey:24LL]); |
| 1073 [dict release]; | 1073 [dict release]; |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 - (void)testInplaceMutation { | 1076 - (void)testInplaceMutation { |
| 1077 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1077 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1078 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; | 1078 const uint64_t kValues[] = { 300U, 301U, 302U, 303U }; |
| 1079 GPBInt64UInt64Dictionary *dict = | 1079 GPBInt64UInt64Dictionary *dict = |
| 1080 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues | 1080 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues |
| 1081 forKeys:kKeys | 1081 forKeys:kKeys |
| 1082 count:GPBARRAYSIZE(kValues)]; | 1082 count:GPBARRAYSIZE(kValues)]; |
| 1083 XCTAssertNotNil(dict); | 1083 XCTAssertNotNil(dict); |
| 1084 XCTAssertEqual(dict.count, 4U); | 1084 XCTAssertEqual(dict.count, 4U); |
| 1085 uint64_t value; | 1085 uint64_t value; |
| 1086 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1086 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1087 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1087 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1088 XCTAssertEqual(value, 300U); | 1088 XCTAssertEqual(value, 300U); |
| 1089 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1089 XCTAssertTrue([dict getUInt64:NULL forKey:22LL]); |
| 1090 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1090 XCTAssertTrue([dict getUInt64:&value forKey:22LL]); |
| 1091 XCTAssertEqual(value, 301U); | 1091 XCTAssertEqual(value, 301U); |
| 1092 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1092 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1093 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1093 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1094 XCTAssertEqual(value, 302U); | 1094 XCTAssertEqual(value, 302U); |
| 1095 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1095 XCTAssertTrue([dict getUInt64:NULL forKey:24LL]); |
| 1096 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1096 XCTAssertTrue([dict getUInt64:&value forKey:24LL]); |
| 1097 XCTAssertEqual(value, 303U); | 1097 XCTAssertEqual(value, 303U); |
| 1098 | 1098 |
| 1099 [dict setValue:303U forKey:21LL]; | 1099 [dict setUInt64:303U forKey:21LL]; |
| 1100 XCTAssertEqual(dict.count, 4U); | 1100 XCTAssertEqual(dict.count, 4U); |
| 1101 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1101 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1102 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1102 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1103 XCTAssertEqual(value, 303U); | 1103 XCTAssertEqual(value, 303U); |
| 1104 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1104 XCTAssertTrue([dict getUInt64:NULL forKey:22LL]); |
| 1105 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1105 XCTAssertTrue([dict getUInt64:&value forKey:22LL]); |
| 1106 XCTAssertEqual(value, 301U); | 1106 XCTAssertEqual(value, 301U); |
| 1107 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1107 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1108 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1108 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1109 XCTAssertEqual(value, 302U); | 1109 XCTAssertEqual(value, 302U); |
| 1110 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1110 XCTAssertTrue([dict getUInt64:NULL forKey:24LL]); |
| 1111 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1111 XCTAssertTrue([dict getUInt64:&value forKey:24LL]); |
| 1112 XCTAssertEqual(value, 303U); | 1112 XCTAssertEqual(value, 303U); |
| 1113 | 1113 |
| 1114 [dict setValue:301U forKey:24LL]; | 1114 [dict setUInt64:301U forKey:24LL]; |
| 1115 XCTAssertEqual(dict.count, 4U); | 1115 XCTAssertEqual(dict.count, 4U); |
| 1116 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1116 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1117 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1117 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1118 XCTAssertEqual(value, 303U); | 1118 XCTAssertEqual(value, 303U); |
| 1119 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1119 XCTAssertTrue([dict getUInt64:NULL forKey:22LL]); |
| 1120 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1120 XCTAssertTrue([dict getUInt64:&value forKey:22LL]); |
| 1121 XCTAssertEqual(value, 301U); | 1121 XCTAssertEqual(value, 301U); |
| 1122 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1122 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1123 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1123 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1124 XCTAssertEqual(value, 302U); | 1124 XCTAssertEqual(value, 302U); |
| 1125 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1125 XCTAssertTrue([dict getUInt64:NULL forKey:24LL]); |
| 1126 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1126 XCTAssertTrue([dict getUInt64:&value forKey:24LL]); |
| 1127 XCTAssertEqual(value, 301U); | 1127 XCTAssertEqual(value, 301U); |
| 1128 | 1128 |
| 1129 const int64_t kKeys2[] = { 22LL, 23LL }; | 1129 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 1130 const uint64_t kValues2[] = { 302U, 300U }; | 1130 const uint64_t kValues2[] = { 302U, 300U }; |
| 1131 GPBInt64UInt64Dictionary *dict2 = | 1131 GPBInt64UInt64Dictionary *dict2 = |
| 1132 [[GPBInt64UInt64Dictionary alloc] initWithValues:kValues2 | 1132 [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues2 |
| 1133 forKeys:kKeys2 | 1133 forKeys:kKeys2 |
| 1134 count:GPBARRAYSIZE(kValues2)]; | 1134 count:GPBARRAYSIZE(kValues2)]; |
| 1135 XCTAssertNotNil(dict2); | 1135 XCTAssertNotNil(dict2); |
| 1136 [dict addEntriesFromDictionary:dict2]; | 1136 [dict addEntriesFromDictionary:dict2]; |
| 1137 XCTAssertEqual(dict.count, 4U); | 1137 XCTAssertEqual(dict.count, 4U); |
| 1138 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1138 XCTAssertTrue([dict getUInt64:NULL forKey:21LL]); |
| 1139 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1139 XCTAssertTrue([dict getUInt64:&value forKey:21LL]); |
| 1140 XCTAssertEqual(value, 303U); | 1140 XCTAssertEqual(value, 303U); |
| 1141 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1141 XCTAssertTrue([dict getUInt64:NULL forKey:22LL]); |
| 1142 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1142 XCTAssertTrue([dict getUInt64:&value forKey:22LL]); |
| 1143 XCTAssertEqual(value, 302U); | 1143 XCTAssertEqual(value, 302U); |
| 1144 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1144 XCTAssertTrue([dict getUInt64:NULL forKey:23LL]); |
| 1145 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1145 XCTAssertTrue([dict getUInt64:&value forKey:23LL]); |
| 1146 XCTAssertEqual(value, 300U); | 1146 XCTAssertEqual(value, 300U); |
| 1147 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1147 XCTAssertTrue([dict getUInt64:NULL forKey:24LL]); |
| 1148 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1148 XCTAssertTrue([dict getUInt64:&value forKey:24LL]); |
| 1149 XCTAssertEqual(value, 301U); | 1149 XCTAssertEqual(value, 301U); |
| 1150 | 1150 |
| 1151 [dict2 release]; | 1151 [dict2 release]; |
| 1152 [dict release]; | 1152 [dict release]; |
| 1153 } | 1153 } |
| 1154 | 1154 |
| 1155 @end | 1155 @end |
| 1156 | 1156 |
| 1157 #pragma mark - Int64 -> Int64 | 1157 #pragma mark - Int64 -> Int64 |
| 1158 | 1158 |
| 1159 @interface GPBInt64Int64DictionaryTests : XCTestCase | 1159 @interface GPBInt64Int64DictionaryTests : XCTestCase |
| 1160 @end | 1160 @end |
| 1161 | 1161 |
| 1162 @implementation GPBInt64Int64DictionaryTests | 1162 @implementation GPBInt64Int64DictionaryTests |
| 1163 | 1163 |
| 1164 - (void)testEmpty { | 1164 - (void)testEmpty { |
| 1165 GPBInt64Int64Dictionary *dict = [[GPBInt64Int64Dictionary alloc] init]; | 1165 GPBInt64Int64Dictionary *dict = [[GPBInt64Int64Dictionary alloc] init]; |
| 1166 XCTAssertNotNil(dict); | 1166 XCTAssertNotNil(dict); |
| 1167 XCTAssertEqual(dict.count, 0U); | 1167 XCTAssertEqual(dict.count, 0U); |
| 1168 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 1168 XCTAssertFalse([dict getInt64:NULL forKey:21LL]); |
| 1169 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { | 1169 [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { |
| 1170 #pragma unused(aKey, aValue, stop) | 1170 #pragma unused(aKey, aValue, stop) |
| 1171 XCTFail(@"Shouldn't get here!"); | 1171 XCTFail(@"Shouldn't get here!"); |
| 1172 }]; | 1172 }]; |
| 1173 [dict release]; | 1173 [dict release]; |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 - (void)testOne { | 1176 - (void)testOne { |
| 1177 GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionaryWithValue:4
00 forKey:21LL]; | 1177 GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionaryWithInt64:4
00 forKey:21LL]; |
| 1178 XCTAssertNotNil(dict); | 1178 XCTAssertNotNil(dict); |
| 1179 XCTAssertEqual(dict.count, 1U); | 1179 XCTAssertEqual(dict.count, 1U); |
| 1180 int64_t value; | 1180 int64_t value; |
| 1181 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1181 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1182 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1182 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1183 XCTAssertEqual(value, 400); | 1183 XCTAssertEqual(value, 400); |
| 1184 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1184 XCTAssertFalse([dict getInt64:NULL forKey:22LL]); |
| 1185 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { | 1185 [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { |
| 1186 XCTAssertEqual(aKey, 21LL); | 1186 XCTAssertEqual(aKey, 21LL); |
| 1187 XCTAssertEqual(aValue, 400); | 1187 XCTAssertEqual(aValue, 400); |
| 1188 XCTAssertNotEqual(stop, NULL); | 1188 XCTAssertNotEqual(stop, NULL); |
| 1189 }]; | 1189 }]; |
| 1190 } | 1190 } |
| 1191 | 1191 |
| 1192 - (void)testBasics { | 1192 - (void)testBasics { |
| 1193 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 1193 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 1194 const int64_t kValues[] = { 400, 401, 402 }; | 1194 const int64_t kValues[] = { 400, 401, 402 }; |
| 1195 GPBInt64Int64Dictionary *dict = | 1195 GPBInt64Int64Dictionary *dict = |
| 1196 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues | 1196 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues |
| 1197 forKeys:kKeys | 1197 forKeys:kKeys |
| 1198 count:GPBARRAYSIZE(kValues)]; | 1198 count:GPBARRAYSIZE(kValues)]; |
| 1199 XCTAssertNotNil(dict); | 1199 XCTAssertNotNil(dict); |
| 1200 XCTAssertEqual(dict.count, 3U); | 1200 XCTAssertEqual(dict.count, 3U); |
| 1201 int64_t value; | 1201 int64_t value; |
| 1202 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1202 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1203 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1203 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1204 XCTAssertEqual(value, 400); | 1204 XCTAssertEqual(value, 400); |
| 1205 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1205 XCTAssertTrue([dict getInt64:NULL forKey:22LL]); |
| 1206 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1206 XCTAssertTrue([dict getInt64:&value forKey:22LL]); |
| 1207 XCTAssertEqual(value, 401); | 1207 XCTAssertEqual(value, 401); |
| 1208 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1208 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1209 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1209 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1210 XCTAssertEqual(value, 402); | 1210 XCTAssertEqual(value, 402); |
| 1211 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1211 XCTAssertFalse([dict getInt64:NULL forKey:24LL]); |
| 1212 | 1212 |
| 1213 __block NSUInteger idx = 0; | 1213 __block NSUInteger idx = 0; |
| 1214 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 1214 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 1215 int64_t *seenValues = malloc(3 * sizeof(int64_t)); | 1215 int64_t *seenValues = malloc(3 * sizeof(int64_t)); |
| 1216 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { | 1216 [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { |
| 1217 XCTAssertLessThan(idx, 3U); | 1217 XCTAssertLessThan(idx, 3U); |
| 1218 seenKeys[idx] = aKey; | 1218 seenKeys[idx] = aKey; |
| 1219 seenValues[idx] = aValue; | 1219 seenValues[idx] = aValue; |
| 1220 XCTAssertNotEqual(stop, NULL); | 1220 XCTAssertNotEqual(stop, NULL); |
| 1221 ++idx; | 1221 ++idx; |
| 1222 }]; | 1222 }]; |
| 1223 for (int i = 0; i < 3; ++i) { | 1223 for (int i = 0; i < 3; ++i) { |
| 1224 BOOL foundKey = NO; | 1224 BOOL foundKey = NO; |
| 1225 for (int j = 0; (j < 3) && !foundKey; ++j) { | 1225 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 1226 if (kKeys[i] == seenKeys[j]) { | 1226 if (kKeys[i] == seenKeys[j]) { |
| 1227 foundKey = YES; | 1227 foundKey = YES; |
| 1228 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 1228 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 1229 } | 1229 } |
| 1230 } | 1230 } |
| 1231 XCTAssertTrue(foundKey, @"i = %d", i); | 1231 XCTAssertTrue(foundKey, @"i = %d", i); |
| 1232 } | 1232 } |
| 1233 free(seenKeys); | 1233 free(seenKeys); |
| 1234 free(seenValues); | 1234 free(seenValues); |
| 1235 | 1235 |
| 1236 // Stopping the enumeration. | 1236 // Stopping the enumeration. |
| 1237 idx = 0; | 1237 idx = 0; |
| 1238 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { | 1238 [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *s
top) { |
| 1239 #pragma unused(aKey, aValue) | 1239 #pragma unused(aKey, aValue) |
| 1240 if (idx == 1) *stop = YES; | 1240 if (idx == 1) *stop = YES; |
| 1241 XCTAssertNotEqual(idx, 2U); | 1241 XCTAssertNotEqual(idx, 2U); |
| 1242 ++idx; | 1242 ++idx; |
| 1243 }]; | 1243 }]; |
| 1244 [dict release]; | 1244 [dict release]; |
| 1245 } | 1245 } |
| 1246 | 1246 |
| 1247 - (void)testEquality { | 1247 - (void)testEquality { |
| 1248 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 1248 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1249 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 1249 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 1250 const int64_t kValues1[] = { 400, 401, 402 }; | 1250 const int64_t kValues1[] = { 400, 401, 402 }; |
| 1251 const int64_t kValues2[] = { 400, 403, 402 }; | 1251 const int64_t kValues2[] = { 400, 403, 402 }; |
| 1252 const int64_t kValues3[] = { 400, 401, 402, 403 }; | 1252 const int64_t kValues3[] = { 400, 401, 402, 403 }; |
| 1253 GPBInt64Int64Dictionary *dict1 = | 1253 GPBInt64Int64Dictionary *dict1 = |
| 1254 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues1 | 1254 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1 |
| 1255 forKeys:kKeys1 | 1255 forKeys:kKeys1 |
| 1256 count:GPBARRAYSIZE(kValues1)]; | 1256 count:GPBARRAYSIZE(kValues1)]; |
| 1257 XCTAssertNotNil(dict1); | 1257 XCTAssertNotNil(dict1); |
| 1258 GPBInt64Int64Dictionary *dict1prime = | 1258 GPBInt64Int64Dictionary *dict1prime = |
| 1259 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues1 | 1259 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1 |
| 1260 forKeys:kKeys1 | 1260 forKeys:kKeys1 |
| 1261 count:GPBARRAYSIZE(kValues1)]; | 1261 count:GPBARRAYSIZE(kValues1)]; |
| 1262 XCTAssertNotNil(dict1prime); | 1262 XCTAssertNotNil(dict1prime); |
| 1263 GPBInt64Int64Dictionary *dict2 = | 1263 GPBInt64Int64Dictionary *dict2 = |
| 1264 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues2 | 1264 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues2 |
| 1265 forKeys:kKeys1 | 1265 forKeys:kKeys1 |
| 1266 count:GPBARRAYSIZE(kValues2)]; | 1266 count:GPBARRAYSIZE(kValues2)]; |
| 1267 XCTAssertNotNil(dict2); | 1267 XCTAssertNotNil(dict2); |
| 1268 GPBInt64Int64Dictionary *dict3 = | 1268 GPBInt64Int64Dictionary *dict3 = |
| 1269 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues1 | 1269 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1 |
| 1270 forKeys:kKeys2 | 1270 forKeys:kKeys2 |
| 1271 count:GPBARRAYSIZE(kValues1)]; | 1271 count:GPBARRAYSIZE(kValues1)]; |
| 1272 XCTAssertNotNil(dict3); | 1272 XCTAssertNotNil(dict3); |
| 1273 GPBInt64Int64Dictionary *dict4 = | 1273 GPBInt64Int64Dictionary *dict4 = |
| 1274 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues3 | 1274 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues3 |
| 1275 forKeys:kKeys1 | 1275 forKeys:kKeys1 |
| 1276 count:GPBARRAYSIZE(kValues3)]; | 1276 count:GPBARRAYSIZE(kValues3)]; |
| 1277 XCTAssertNotNil(dict4); | 1277 XCTAssertNotNil(dict4); |
| 1278 | 1278 |
| 1279 // 1/1Prime should be different objects, but equal. | 1279 // 1/1Prime should be different objects, but equal. |
| 1280 XCTAssertNotEqual(dict1, dict1prime); | 1280 XCTAssertNotEqual(dict1, dict1prime); |
| 1281 XCTAssertEqualObjects(dict1, dict1prime); | 1281 XCTAssertEqualObjects(dict1, dict1prime); |
| 1282 // Equal, so they must have same hash. | 1282 // Equal, so they must have same hash. |
| 1283 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 1283 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 1284 | 1284 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1295 [dict1prime release]; | 1295 [dict1prime release]; |
| 1296 [dict2 release]; | 1296 [dict2 release]; |
| 1297 [dict3 release]; | 1297 [dict3 release]; |
| 1298 [dict4 release]; | 1298 [dict4 release]; |
| 1299 } | 1299 } |
| 1300 | 1300 |
| 1301 - (void)testCopy { | 1301 - (void)testCopy { |
| 1302 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1302 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1303 const int64_t kValues[] = { 400, 401, 402, 403 }; | 1303 const int64_t kValues[] = { 400, 401, 402, 403 }; |
| 1304 GPBInt64Int64Dictionary *dict = | 1304 GPBInt64Int64Dictionary *dict = |
| 1305 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues | 1305 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues |
| 1306 forKeys:kKeys | 1306 forKeys:kKeys |
| 1307 count:GPBARRAYSIZE(kValues)]; | 1307 count:GPBARRAYSIZE(kValues)]; |
| 1308 XCTAssertNotNil(dict); | 1308 XCTAssertNotNil(dict); |
| 1309 | 1309 |
| 1310 GPBInt64Int64Dictionary *dict2 = [dict copy]; | 1310 GPBInt64Int64Dictionary *dict2 = [dict copy]; |
| 1311 XCTAssertNotNil(dict2); | 1311 XCTAssertNotNil(dict2); |
| 1312 | 1312 |
| 1313 // Should be new object but equal. | 1313 // Should be new object but equal. |
| 1314 XCTAssertNotEqual(dict, dict2); | 1314 XCTAssertNotEqual(dict, dict2); |
| 1315 XCTAssertEqualObjects(dict, dict2); | 1315 XCTAssertEqualObjects(dict, dict2); |
| 1316 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int64Dictionary class]]); | 1316 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int64Dictionary class]]); |
| 1317 | 1317 |
| 1318 [dict2 release]; | 1318 [dict2 release]; |
| 1319 [dict release]; | 1319 [dict release]; |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 - (void)testDictionaryFromDictionary { | 1322 - (void)testDictionaryFromDictionary { |
| 1323 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1323 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1324 const int64_t kValues[] = { 400, 401, 402, 403 }; | 1324 const int64_t kValues[] = { 400, 401, 402, 403 }; |
| 1325 GPBInt64Int64Dictionary *dict = | 1325 GPBInt64Int64Dictionary *dict = |
| 1326 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues | 1326 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues |
| 1327 forKeys:kKeys | 1327 forKeys:kKeys |
| 1328 count:GPBARRAYSIZE(kValues)]; | 1328 count:GPBARRAYSIZE(kValues)]; |
| 1329 XCTAssertNotNil(dict); | 1329 XCTAssertNotNil(dict); |
| 1330 | 1330 |
| 1331 GPBInt64Int64Dictionary *dict2 = | 1331 GPBInt64Int64Dictionary *dict2 = |
| 1332 [GPBInt64Int64Dictionary dictionaryWithDictionary:dict]; | 1332 [GPBInt64Int64Dictionary dictionaryWithDictionary:dict]; |
| 1333 XCTAssertNotNil(dict2); | 1333 XCTAssertNotNil(dict2); |
| 1334 | 1334 |
| 1335 // Should be new pointer, but equal objects. | 1335 // Should be new pointer, but equal objects. |
| 1336 XCTAssertNotEqual(dict, dict2); | 1336 XCTAssertNotEqual(dict, dict2); |
| 1337 XCTAssertEqualObjects(dict, dict2); | 1337 XCTAssertEqualObjects(dict, dict2); |
| 1338 [dict release]; | 1338 [dict release]; |
| 1339 } | 1339 } |
| 1340 | 1340 |
| 1341 - (void)testAdds { | 1341 - (void)testAdds { |
| 1342 GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionary]; | 1342 GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionary]; |
| 1343 XCTAssertNotNil(dict); | 1343 XCTAssertNotNil(dict); |
| 1344 | 1344 |
| 1345 XCTAssertEqual(dict.count, 0U); | 1345 XCTAssertEqual(dict.count, 0U); |
| 1346 [dict setValue:400 forKey:21LL]; | 1346 [dict setInt64:400 forKey:21LL]; |
| 1347 XCTAssertEqual(dict.count, 1U); | 1347 XCTAssertEqual(dict.count, 1U); |
| 1348 | 1348 |
| 1349 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 1349 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 1350 const int64_t kValues[] = { 401, 402, 403 }; | 1350 const int64_t kValues[] = { 401, 402, 403 }; |
| 1351 GPBInt64Int64Dictionary *dict2 = | 1351 GPBInt64Int64Dictionary *dict2 = |
| 1352 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues | 1352 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues |
| 1353 forKeys:kKeys | 1353 forKeys:kKeys |
| 1354 count:GPBARRAYSIZE(kValues)]; | 1354 count:GPBARRAYSIZE(kValues)]; |
| 1355 XCTAssertNotNil(dict2); | 1355 XCTAssertNotNil(dict2); |
| 1356 [dict addEntriesFromDictionary:dict2]; | 1356 [dict addEntriesFromDictionary:dict2]; |
| 1357 XCTAssertEqual(dict.count, 4U); | 1357 XCTAssertEqual(dict.count, 4U); |
| 1358 | 1358 |
| 1359 int64_t value; | 1359 int64_t value; |
| 1360 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1360 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1361 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1361 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1362 XCTAssertEqual(value, 400); | 1362 XCTAssertEqual(value, 400); |
| 1363 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1363 XCTAssertTrue([dict getInt64:NULL forKey:22LL]); |
| 1364 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1364 XCTAssertTrue([dict getInt64:&value forKey:22LL]); |
| 1365 XCTAssertEqual(value, 401); | 1365 XCTAssertEqual(value, 401); |
| 1366 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1366 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1367 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1367 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1368 XCTAssertEqual(value, 402); | 1368 XCTAssertEqual(value, 402); |
| 1369 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1369 XCTAssertTrue([dict getInt64:NULL forKey:24LL]); |
| 1370 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1370 XCTAssertTrue([dict getInt64:&value forKey:24LL]); |
| 1371 XCTAssertEqual(value, 403); | 1371 XCTAssertEqual(value, 403); |
| 1372 [dict2 release]; | 1372 [dict2 release]; |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 - (void)testRemove { | 1375 - (void)testRemove { |
| 1376 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1376 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1377 const int64_t kValues[] = { 400, 401, 402, 403 }; | 1377 const int64_t kValues[] = { 400, 401, 402, 403 }; |
| 1378 GPBInt64Int64Dictionary *dict = | 1378 GPBInt64Int64Dictionary *dict = |
| 1379 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues | 1379 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues |
| 1380 forKeys:kKeys | 1380 forKeys:kKeys |
| 1381 count:GPBARRAYSIZE(kValues)]; | 1381 count:GPBARRAYSIZE(kValues)]; |
| 1382 XCTAssertNotNil(dict); | 1382 XCTAssertNotNil(dict); |
| 1383 XCTAssertEqual(dict.count, 4U); | 1383 XCTAssertEqual(dict.count, 4U); |
| 1384 | 1384 |
| 1385 [dict removeValueForKey:22LL]; | 1385 [dict removeInt64ForKey:22LL]; |
| 1386 XCTAssertEqual(dict.count, 3U); | 1386 XCTAssertEqual(dict.count, 3U); |
| 1387 int64_t value; | 1387 int64_t value; |
| 1388 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1388 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1389 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1389 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1390 XCTAssertEqual(value, 400); | 1390 XCTAssertEqual(value, 400); |
| 1391 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1391 XCTAssertFalse([dict getInt64:NULL forKey:22LL]); |
| 1392 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1392 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1393 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1393 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1394 XCTAssertEqual(value, 402); | 1394 XCTAssertEqual(value, 402); |
| 1395 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1395 XCTAssertTrue([dict getInt64:NULL forKey:24LL]); |
| 1396 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1396 XCTAssertTrue([dict getInt64:&value forKey:24LL]); |
| 1397 XCTAssertEqual(value, 403); | 1397 XCTAssertEqual(value, 403); |
| 1398 | 1398 |
| 1399 // Remove again does nothing. | 1399 // Remove again does nothing. |
| 1400 [dict removeValueForKey:22LL]; | 1400 [dict removeInt64ForKey:22LL]; |
| 1401 XCTAssertEqual(dict.count, 3U); | 1401 XCTAssertEqual(dict.count, 3U); |
| 1402 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1402 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1403 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1403 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1404 XCTAssertEqual(value, 400); | 1404 XCTAssertEqual(value, 400); |
| 1405 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1405 XCTAssertFalse([dict getInt64:NULL forKey:22LL]); |
| 1406 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1406 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1407 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1407 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1408 XCTAssertEqual(value, 402); | 1408 XCTAssertEqual(value, 402); |
| 1409 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1409 XCTAssertTrue([dict getInt64:NULL forKey:24LL]); |
| 1410 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1410 XCTAssertTrue([dict getInt64:&value forKey:24LL]); |
| 1411 XCTAssertEqual(value, 403); | 1411 XCTAssertEqual(value, 403); |
| 1412 | 1412 |
| 1413 [dict removeValueForKey:24LL]; | 1413 [dict removeInt64ForKey:24LL]; |
| 1414 XCTAssertEqual(dict.count, 2U); | 1414 XCTAssertEqual(dict.count, 2U); |
| 1415 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1415 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1416 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1416 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1417 XCTAssertEqual(value, 400); | 1417 XCTAssertEqual(value, 400); |
| 1418 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1418 XCTAssertFalse([dict getInt64:NULL forKey:22LL]); |
| 1419 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1419 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1420 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1420 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1421 XCTAssertEqual(value, 402); | 1421 XCTAssertEqual(value, 402); |
| 1422 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1422 XCTAssertFalse([dict getInt64:NULL forKey:24LL]); |
| 1423 | 1423 |
| 1424 [dict removeAll]; | 1424 [dict removeAll]; |
| 1425 XCTAssertEqual(dict.count, 0U); | 1425 XCTAssertEqual(dict.count, 0U); |
| 1426 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 1426 XCTAssertFalse([dict getInt64:NULL forKey:21LL]); |
| 1427 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1427 XCTAssertFalse([dict getInt64:NULL forKey:22LL]); |
| 1428 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 1428 XCTAssertFalse([dict getInt64:NULL forKey:23LL]); |
| 1429 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1429 XCTAssertFalse([dict getInt64:NULL forKey:24LL]); |
| 1430 [dict release]; | 1430 [dict release]; |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 - (void)testInplaceMutation { | 1433 - (void)testInplaceMutation { |
| 1434 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1434 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1435 const int64_t kValues[] = { 400, 401, 402, 403 }; | 1435 const int64_t kValues[] = { 400, 401, 402, 403 }; |
| 1436 GPBInt64Int64Dictionary *dict = | 1436 GPBInt64Int64Dictionary *dict = |
| 1437 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues | 1437 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues |
| 1438 forKeys:kKeys | 1438 forKeys:kKeys |
| 1439 count:GPBARRAYSIZE(kValues)]; | 1439 count:GPBARRAYSIZE(kValues)]; |
| 1440 XCTAssertNotNil(dict); | 1440 XCTAssertNotNil(dict); |
| 1441 XCTAssertEqual(dict.count, 4U); | 1441 XCTAssertEqual(dict.count, 4U); |
| 1442 int64_t value; | 1442 int64_t value; |
| 1443 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1443 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1444 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1444 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1445 XCTAssertEqual(value, 400); | 1445 XCTAssertEqual(value, 400); |
| 1446 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1446 XCTAssertTrue([dict getInt64:NULL forKey:22LL]); |
| 1447 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1447 XCTAssertTrue([dict getInt64:&value forKey:22LL]); |
| 1448 XCTAssertEqual(value, 401); | 1448 XCTAssertEqual(value, 401); |
| 1449 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1449 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1450 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1450 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1451 XCTAssertEqual(value, 402); | 1451 XCTAssertEqual(value, 402); |
| 1452 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1452 XCTAssertTrue([dict getInt64:NULL forKey:24LL]); |
| 1453 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1453 XCTAssertTrue([dict getInt64:&value forKey:24LL]); |
| 1454 XCTAssertEqual(value, 403); | 1454 XCTAssertEqual(value, 403); |
| 1455 | 1455 |
| 1456 [dict setValue:403 forKey:21LL]; | 1456 [dict setInt64:403 forKey:21LL]; |
| 1457 XCTAssertEqual(dict.count, 4U); | 1457 XCTAssertEqual(dict.count, 4U); |
| 1458 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1458 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1459 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1459 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1460 XCTAssertEqual(value, 403); | 1460 XCTAssertEqual(value, 403); |
| 1461 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1461 XCTAssertTrue([dict getInt64:NULL forKey:22LL]); |
| 1462 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1462 XCTAssertTrue([dict getInt64:&value forKey:22LL]); |
| 1463 XCTAssertEqual(value, 401); | 1463 XCTAssertEqual(value, 401); |
| 1464 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1464 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1465 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1465 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1466 XCTAssertEqual(value, 402); | 1466 XCTAssertEqual(value, 402); |
| 1467 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1467 XCTAssertTrue([dict getInt64:NULL forKey:24LL]); |
| 1468 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1468 XCTAssertTrue([dict getInt64:&value forKey:24LL]); |
| 1469 XCTAssertEqual(value, 403); | 1469 XCTAssertEqual(value, 403); |
| 1470 | 1470 |
| 1471 [dict setValue:401 forKey:24LL]; | 1471 [dict setInt64:401 forKey:24LL]; |
| 1472 XCTAssertEqual(dict.count, 4U); | 1472 XCTAssertEqual(dict.count, 4U); |
| 1473 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1473 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1474 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1474 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1475 XCTAssertEqual(value, 403); | 1475 XCTAssertEqual(value, 403); |
| 1476 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1476 XCTAssertTrue([dict getInt64:NULL forKey:22LL]); |
| 1477 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1477 XCTAssertTrue([dict getInt64:&value forKey:22LL]); |
| 1478 XCTAssertEqual(value, 401); | 1478 XCTAssertEqual(value, 401); |
| 1479 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1479 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1480 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1480 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1481 XCTAssertEqual(value, 402); | 1481 XCTAssertEqual(value, 402); |
| 1482 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1482 XCTAssertTrue([dict getInt64:NULL forKey:24LL]); |
| 1483 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1483 XCTAssertTrue([dict getInt64:&value forKey:24LL]); |
| 1484 XCTAssertEqual(value, 401); | 1484 XCTAssertEqual(value, 401); |
| 1485 | 1485 |
| 1486 const int64_t kKeys2[] = { 22LL, 23LL }; | 1486 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 1487 const int64_t kValues2[] = { 402, 400 }; | 1487 const int64_t kValues2[] = { 402, 400 }; |
| 1488 GPBInt64Int64Dictionary *dict2 = | 1488 GPBInt64Int64Dictionary *dict2 = |
| 1489 [[GPBInt64Int64Dictionary alloc] initWithValues:kValues2 | 1489 [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues2 |
| 1490 forKeys:kKeys2 | 1490 forKeys:kKeys2 |
| 1491 count:GPBARRAYSIZE(kValues2)]; | 1491 count:GPBARRAYSIZE(kValues2)]; |
| 1492 XCTAssertNotNil(dict2); | 1492 XCTAssertNotNil(dict2); |
| 1493 [dict addEntriesFromDictionary:dict2]; | 1493 [dict addEntriesFromDictionary:dict2]; |
| 1494 XCTAssertEqual(dict.count, 4U); | 1494 XCTAssertEqual(dict.count, 4U); |
| 1495 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1495 XCTAssertTrue([dict getInt64:NULL forKey:21LL]); |
| 1496 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1496 XCTAssertTrue([dict getInt64:&value forKey:21LL]); |
| 1497 XCTAssertEqual(value, 403); | 1497 XCTAssertEqual(value, 403); |
| 1498 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1498 XCTAssertTrue([dict getInt64:NULL forKey:22LL]); |
| 1499 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1499 XCTAssertTrue([dict getInt64:&value forKey:22LL]); |
| 1500 XCTAssertEqual(value, 402); | 1500 XCTAssertEqual(value, 402); |
| 1501 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1501 XCTAssertTrue([dict getInt64:NULL forKey:23LL]); |
| 1502 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1502 XCTAssertTrue([dict getInt64:&value forKey:23LL]); |
| 1503 XCTAssertEqual(value, 400); | 1503 XCTAssertEqual(value, 400); |
| 1504 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1504 XCTAssertTrue([dict getInt64:NULL forKey:24LL]); |
| 1505 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1505 XCTAssertTrue([dict getInt64:&value forKey:24LL]); |
| 1506 XCTAssertEqual(value, 401); | 1506 XCTAssertEqual(value, 401); |
| 1507 | 1507 |
| 1508 [dict2 release]; | 1508 [dict2 release]; |
| 1509 [dict release]; | 1509 [dict release]; |
| 1510 } | 1510 } |
| 1511 | 1511 |
| 1512 @end | 1512 @end |
| 1513 | 1513 |
| 1514 #pragma mark - Int64 -> Bool | 1514 #pragma mark - Int64 -> Bool |
| 1515 | 1515 |
| 1516 @interface GPBInt64BoolDictionaryTests : XCTestCase | 1516 @interface GPBInt64BoolDictionaryTests : XCTestCase |
| 1517 @end | 1517 @end |
| 1518 | 1518 |
| 1519 @implementation GPBInt64BoolDictionaryTests | 1519 @implementation GPBInt64BoolDictionaryTests |
| 1520 | 1520 |
| 1521 - (void)testEmpty { | 1521 - (void)testEmpty { |
| 1522 GPBInt64BoolDictionary *dict = [[GPBInt64BoolDictionary alloc] init]; | 1522 GPBInt64BoolDictionary *dict = [[GPBInt64BoolDictionary alloc] init]; |
| 1523 XCTAssertNotNil(dict); | 1523 XCTAssertNotNil(dict); |
| 1524 XCTAssertEqual(dict.count, 0U); | 1524 XCTAssertEqual(dict.count, 0U); |
| 1525 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 1525 XCTAssertFalse([dict getBool:NULL forKey:21LL]); |
| 1526 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop
) { | 1526 [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop)
{ |
| 1527 #pragma unused(aKey, aValue, stop) | 1527 #pragma unused(aKey, aValue, stop) |
| 1528 XCTFail(@"Shouldn't get here!"); | 1528 XCTFail(@"Shouldn't get here!"); |
| 1529 }]; | 1529 }]; |
| 1530 [dict release]; | 1530 [dict release]; |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 - (void)testOne { | 1533 - (void)testOne { |
| 1534 GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionaryWithValue:YES
forKey:21LL]; | 1534 GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionaryWithBool:YES
forKey:21LL]; |
| 1535 XCTAssertNotNil(dict); | 1535 XCTAssertNotNil(dict); |
| 1536 XCTAssertEqual(dict.count, 1U); | 1536 XCTAssertEqual(dict.count, 1U); |
| 1537 BOOL value; | 1537 BOOL value; |
| 1538 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1538 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1539 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1539 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1540 XCTAssertEqual(value, YES); | 1540 XCTAssertEqual(value, YES); |
| 1541 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1541 XCTAssertFalse([dict getBool:NULL forKey:22LL]); |
| 1542 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop
) { | 1542 [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop)
{ |
| 1543 XCTAssertEqual(aKey, 21LL); | 1543 XCTAssertEqual(aKey, 21LL); |
| 1544 XCTAssertEqual(aValue, YES); | 1544 XCTAssertEqual(aValue, YES); |
| 1545 XCTAssertNotEqual(stop, NULL); | 1545 XCTAssertNotEqual(stop, NULL); |
| 1546 }]; | 1546 }]; |
| 1547 } | 1547 } |
| 1548 | 1548 |
| 1549 - (void)testBasics { | 1549 - (void)testBasics { |
| 1550 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 1550 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 1551 const BOOL kValues[] = { YES, YES, NO }; | 1551 const BOOL kValues[] = { YES, YES, NO }; |
| 1552 GPBInt64BoolDictionary *dict = | 1552 GPBInt64BoolDictionary *dict = |
| 1553 [[GPBInt64BoolDictionary alloc] initWithValues:kValues | 1553 [[GPBInt64BoolDictionary alloc] initWithBools:kValues |
| 1554 forKeys:kKeys | 1554 forKeys:kKeys |
| 1555 count:GPBARRAYSIZE(kValues)]; | 1555 count:GPBARRAYSIZE(kValues)]; |
| 1556 XCTAssertNotNil(dict); | 1556 XCTAssertNotNil(dict); |
| 1557 XCTAssertEqual(dict.count, 3U); | 1557 XCTAssertEqual(dict.count, 3U); |
| 1558 BOOL value; | 1558 BOOL value; |
| 1559 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1559 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1560 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1560 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1561 XCTAssertEqual(value, YES); | 1561 XCTAssertEqual(value, YES); |
| 1562 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1562 XCTAssertTrue([dict getBool:NULL forKey:22LL]); |
| 1563 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1563 XCTAssertTrue([dict getBool:&value forKey:22LL]); |
| 1564 XCTAssertEqual(value, YES); | 1564 XCTAssertEqual(value, YES); |
| 1565 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1565 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1566 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1566 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1567 XCTAssertEqual(value, NO); | 1567 XCTAssertEqual(value, NO); |
| 1568 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1568 XCTAssertFalse([dict getBool:NULL forKey:24LL]); |
| 1569 | 1569 |
| 1570 __block NSUInteger idx = 0; | 1570 __block NSUInteger idx = 0; |
| 1571 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 1571 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 1572 BOOL *seenValues = malloc(3 * sizeof(BOOL)); | 1572 BOOL *seenValues = malloc(3 * sizeof(BOOL)); |
| 1573 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop
) { | 1573 [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop)
{ |
| 1574 XCTAssertLessThan(idx, 3U); | 1574 XCTAssertLessThan(idx, 3U); |
| 1575 seenKeys[idx] = aKey; | 1575 seenKeys[idx] = aKey; |
| 1576 seenValues[idx] = aValue; | 1576 seenValues[idx] = aValue; |
| 1577 XCTAssertNotEqual(stop, NULL); | 1577 XCTAssertNotEqual(stop, NULL); |
| 1578 ++idx; | 1578 ++idx; |
| 1579 }]; | 1579 }]; |
| 1580 for (int i = 0; i < 3; ++i) { | 1580 for (int i = 0; i < 3; ++i) { |
| 1581 BOOL foundKey = NO; | 1581 BOOL foundKey = NO; |
| 1582 for (int j = 0; (j < 3) && !foundKey; ++j) { | 1582 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 1583 if (kKeys[i] == seenKeys[j]) { | 1583 if (kKeys[i] == seenKeys[j]) { |
| 1584 foundKey = YES; | 1584 foundKey = YES; |
| 1585 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 1585 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 1586 } | 1586 } |
| 1587 } | 1587 } |
| 1588 XCTAssertTrue(foundKey, @"i = %d", i); | 1588 XCTAssertTrue(foundKey, @"i = %d", i); |
| 1589 } | 1589 } |
| 1590 free(seenKeys); | 1590 free(seenKeys); |
| 1591 free(seenValues); | 1591 free(seenValues); |
| 1592 | 1592 |
| 1593 // Stopping the enumeration. | 1593 // Stopping the enumeration. |
| 1594 idx = 0; | 1594 idx = 0; |
| 1595 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop
) { | 1595 [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop)
{ |
| 1596 #pragma unused(aKey, aValue) | 1596 #pragma unused(aKey, aValue) |
| 1597 if (idx == 1) *stop = YES; | 1597 if (idx == 1) *stop = YES; |
| 1598 XCTAssertNotEqual(idx, 2U); | 1598 XCTAssertNotEqual(idx, 2U); |
| 1599 ++idx; | 1599 ++idx; |
| 1600 }]; | 1600 }]; |
| 1601 [dict release]; | 1601 [dict release]; |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 - (void)testEquality { | 1604 - (void)testEquality { |
| 1605 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 1605 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1606 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 1606 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 1607 const BOOL kValues1[] = { YES, YES, NO }; | 1607 const BOOL kValues1[] = { YES, YES, NO }; |
| 1608 const BOOL kValues2[] = { YES, NO, NO }; | 1608 const BOOL kValues2[] = { YES, NO, NO }; |
| 1609 const BOOL kValues3[] = { YES, YES, NO, NO }; | 1609 const BOOL kValues3[] = { YES, YES, NO, NO }; |
| 1610 GPBInt64BoolDictionary *dict1 = | 1610 GPBInt64BoolDictionary *dict1 = |
| 1611 [[GPBInt64BoolDictionary alloc] initWithValues:kValues1 | 1611 [[GPBInt64BoolDictionary alloc] initWithBools:kValues1 |
| 1612 forKeys:kKeys1 | 1612 forKeys:kKeys1 |
| 1613 count:GPBARRAYSIZE(kValues1)]; | 1613 count:GPBARRAYSIZE(kValues1)]; |
| 1614 XCTAssertNotNil(dict1); | 1614 XCTAssertNotNil(dict1); |
| 1615 GPBInt64BoolDictionary *dict1prime = | 1615 GPBInt64BoolDictionary *dict1prime = |
| 1616 [[GPBInt64BoolDictionary alloc] initWithValues:kValues1 | 1616 [[GPBInt64BoolDictionary alloc] initWithBools:kValues1 |
| 1617 forKeys:kKeys1 | 1617 forKeys:kKeys1 |
| 1618 count:GPBARRAYSIZE(kValues1)]; | 1618 count:GPBARRAYSIZE(kValues1)]; |
| 1619 XCTAssertNotNil(dict1prime); | 1619 XCTAssertNotNil(dict1prime); |
| 1620 GPBInt64BoolDictionary *dict2 = | 1620 GPBInt64BoolDictionary *dict2 = |
| 1621 [[GPBInt64BoolDictionary alloc] initWithValues:kValues2 | 1621 [[GPBInt64BoolDictionary alloc] initWithBools:kValues2 |
| 1622 forKeys:kKeys1 | 1622 forKeys:kKeys1 |
| 1623 count:GPBARRAYSIZE(kValues2)]; | 1623 count:GPBARRAYSIZE(kValues2)]; |
| 1624 XCTAssertNotNil(dict2); | 1624 XCTAssertNotNil(dict2); |
| 1625 GPBInt64BoolDictionary *dict3 = | 1625 GPBInt64BoolDictionary *dict3 = |
| 1626 [[GPBInt64BoolDictionary alloc] initWithValues:kValues1 | 1626 [[GPBInt64BoolDictionary alloc] initWithBools:kValues1 |
| 1627 forKeys:kKeys2 | 1627 forKeys:kKeys2 |
| 1628 count:GPBARRAYSIZE(kValues1)]; | 1628 count:GPBARRAYSIZE(kValues1)]; |
| 1629 XCTAssertNotNil(dict3); | 1629 XCTAssertNotNil(dict3); |
| 1630 GPBInt64BoolDictionary *dict4 = | 1630 GPBInt64BoolDictionary *dict4 = |
| 1631 [[GPBInt64BoolDictionary alloc] initWithValues:kValues3 | 1631 [[GPBInt64BoolDictionary alloc] initWithBools:kValues3 |
| 1632 forKeys:kKeys1 | 1632 forKeys:kKeys1 |
| 1633 count:GPBARRAYSIZE(kValues3)]; | 1633 count:GPBARRAYSIZE(kValues3)]; |
| 1634 XCTAssertNotNil(dict4); | 1634 XCTAssertNotNil(dict4); |
| 1635 | 1635 |
| 1636 // 1/1Prime should be different objects, but equal. | 1636 // 1/1Prime should be different objects, but equal. |
| 1637 XCTAssertNotEqual(dict1, dict1prime); | 1637 XCTAssertNotEqual(dict1, dict1prime); |
| 1638 XCTAssertEqualObjects(dict1, dict1prime); | 1638 XCTAssertEqualObjects(dict1, dict1prime); |
| 1639 // Equal, so they must have same hash. | 1639 // Equal, so they must have same hash. |
| 1640 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 1640 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 1641 | 1641 |
| 1642 // 2 is same keys, different values; not equal. | 1642 // 2 is same keys, different values; not equal. |
| 1643 XCTAssertNotEqualObjects(dict1, dict2); | 1643 XCTAssertNotEqualObjects(dict1, dict2); |
| 1644 | 1644 |
| 1645 // 3 is different keys, same values; not equal. | 1645 // 3 is different keys, same values; not equal. |
| 1646 XCTAssertNotEqualObjects(dict1, dict3); | 1646 XCTAssertNotEqualObjects(dict1, dict3); |
| 1647 | 1647 |
| 1648 // 4 extra pair; not equal | 1648 // 4 extra pair; not equal |
| 1649 XCTAssertNotEqualObjects(dict1, dict4); | 1649 XCTAssertNotEqualObjects(dict1, dict4); |
| 1650 | 1650 |
| 1651 [dict1 release]; | 1651 [dict1 release]; |
| 1652 [dict1prime release]; | 1652 [dict1prime release]; |
| 1653 [dict2 release]; | 1653 [dict2 release]; |
| 1654 [dict3 release]; | 1654 [dict3 release]; |
| 1655 [dict4 release]; | 1655 [dict4 release]; |
| 1656 } | 1656 } |
| 1657 | 1657 |
| 1658 - (void)testCopy { | 1658 - (void)testCopy { |
| 1659 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1659 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1660 const BOOL kValues[] = { YES, YES, NO, NO }; | 1660 const BOOL kValues[] = { YES, YES, NO, NO }; |
| 1661 GPBInt64BoolDictionary *dict = | 1661 GPBInt64BoolDictionary *dict = |
| 1662 [[GPBInt64BoolDictionary alloc] initWithValues:kValues | 1662 [[GPBInt64BoolDictionary alloc] initWithBools:kValues |
| 1663 forKeys:kKeys | 1663 forKeys:kKeys |
| 1664 count:GPBARRAYSIZE(kValues)]; | 1664 count:GPBARRAYSIZE(kValues)]; |
| 1665 XCTAssertNotNil(dict); | 1665 XCTAssertNotNil(dict); |
| 1666 | 1666 |
| 1667 GPBInt64BoolDictionary *dict2 = [dict copy]; | 1667 GPBInt64BoolDictionary *dict2 = [dict copy]; |
| 1668 XCTAssertNotNil(dict2); | 1668 XCTAssertNotNil(dict2); |
| 1669 | 1669 |
| 1670 // Should be new object but equal. | 1670 // Should be new object but equal. |
| 1671 XCTAssertNotEqual(dict, dict2); | 1671 XCTAssertNotEqual(dict, dict2); |
| 1672 XCTAssertEqualObjects(dict, dict2); | 1672 XCTAssertEqualObjects(dict, dict2); |
| 1673 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64BoolDictionary class]]); | 1673 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64BoolDictionary class]]); |
| 1674 | 1674 |
| 1675 [dict2 release]; | 1675 [dict2 release]; |
| 1676 [dict release]; | 1676 [dict release]; |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 - (void)testDictionaryFromDictionary { | 1679 - (void)testDictionaryFromDictionary { |
| 1680 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1680 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1681 const BOOL kValues[] = { YES, YES, NO, NO }; | 1681 const BOOL kValues[] = { YES, YES, NO, NO }; |
| 1682 GPBInt64BoolDictionary *dict = | 1682 GPBInt64BoolDictionary *dict = |
| 1683 [[GPBInt64BoolDictionary alloc] initWithValues:kValues | 1683 [[GPBInt64BoolDictionary alloc] initWithBools:kValues |
| 1684 forKeys:kKeys | 1684 forKeys:kKeys |
| 1685 count:GPBARRAYSIZE(kValues)]; | 1685 count:GPBARRAYSIZE(kValues)]; |
| 1686 XCTAssertNotNil(dict); | 1686 XCTAssertNotNil(dict); |
| 1687 | 1687 |
| 1688 GPBInt64BoolDictionary *dict2 = | 1688 GPBInt64BoolDictionary *dict2 = |
| 1689 [GPBInt64BoolDictionary dictionaryWithDictionary:dict]; | 1689 [GPBInt64BoolDictionary dictionaryWithDictionary:dict]; |
| 1690 XCTAssertNotNil(dict2); | 1690 XCTAssertNotNil(dict2); |
| 1691 | 1691 |
| 1692 // Should be new pointer, but equal objects. | 1692 // Should be new pointer, but equal objects. |
| 1693 XCTAssertNotEqual(dict, dict2); | 1693 XCTAssertNotEqual(dict, dict2); |
| 1694 XCTAssertEqualObjects(dict, dict2); | 1694 XCTAssertEqualObjects(dict, dict2); |
| 1695 [dict release]; | 1695 [dict release]; |
| 1696 } | 1696 } |
| 1697 | 1697 |
| 1698 - (void)testAdds { | 1698 - (void)testAdds { |
| 1699 GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionary]; | 1699 GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionary]; |
| 1700 XCTAssertNotNil(dict); | 1700 XCTAssertNotNil(dict); |
| 1701 | 1701 |
| 1702 XCTAssertEqual(dict.count, 0U); | 1702 XCTAssertEqual(dict.count, 0U); |
| 1703 [dict setValue:YES forKey:21LL]; | 1703 [dict setBool:YES forKey:21LL]; |
| 1704 XCTAssertEqual(dict.count, 1U); | 1704 XCTAssertEqual(dict.count, 1U); |
| 1705 | 1705 |
| 1706 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 1706 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 1707 const BOOL kValues[] = { YES, NO, NO }; | 1707 const BOOL kValues[] = { YES, NO, NO }; |
| 1708 GPBInt64BoolDictionary *dict2 = | 1708 GPBInt64BoolDictionary *dict2 = |
| 1709 [[GPBInt64BoolDictionary alloc] initWithValues:kValues | 1709 [[GPBInt64BoolDictionary alloc] initWithBools:kValues |
| 1710 forKeys:kKeys | 1710 forKeys:kKeys |
| 1711 count:GPBARRAYSIZE(kValues)]; | 1711 count:GPBARRAYSIZE(kValues)]; |
| 1712 XCTAssertNotNil(dict2); | 1712 XCTAssertNotNil(dict2); |
| 1713 [dict addEntriesFromDictionary:dict2]; | 1713 [dict addEntriesFromDictionary:dict2]; |
| 1714 XCTAssertEqual(dict.count, 4U); | 1714 XCTAssertEqual(dict.count, 4U); |
| 1715 | 1715 |
| 1716 BOOL value; | 1716 BOOL value; |
| 1717 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1717 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1718 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1718 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1719 XCTAssertEqual(value, YES); | 1719 XCTAssertEqual(value, YES); |
| 1720 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1720 XCTAssertTrue([dict getBool:NULL forKey:22LL]); |
| 1721 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1721 XCTAssertTrue([dict getBool:&value forKey:22LL]); |
| 1722 XCTAssertEqual(value, YES); | 1722 XCTAssertEqual(value, YES); |
| 1723 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1723 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1724 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1724 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1725 XCTAssertEqual(value, NO); | 1725 XCTAssertEqual(value, NO); |
| 1726 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1726 XCTAssertTrue([dict getBool:NULL forKey:24LL]); |
| 1727 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1727 XCTAssertTrue([dict getBool:&value forKey:24LL]); |
| 1728 XCTAssertEqual(value, NO); | 1728 XCTAssertEqual(value, NO); |
| 1729 [dict2 release]; | 1729 [dict2 release]; |
| 1730 } | 1730 } |
| 1731 | 1731 |
| 1732 - (void)testRemove { | 1732 - (void)testRemove { |
| 1733 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1733 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1734 const BOOL kValues[] = { YES, YES, NO, NO }; | 1734 const BOOL kValues[] = { YES, YES, NO, NO }; |
| 1735 GPBInt64BoolDictionary *dict = | 1735 GPBInt64BoolDictionary *dict = |
| 1736 [[GPBInt64BoolDictionary alloc] initWithValues:kValues | 1736 [[GPBInt64BoolDictionary alloc] initWithBools:kValues |
| 1737 forKeys:kKeys | 1737 forKeys:kKeys |
| 1738 count:GPBARRAYSIZE(kValues)]; | 1738 count:GPBARRAYSIZE(kValues)]; |
| 1739 XCTAssertNotNil(dict); | 1739 XCTAssertNotNil(dict); |
| 1740 XCTAssertEqual(dict.count, 4U); | 1740 XCTAssertEqual(dict.count, 4U); |
| 1741 | 1741 |
| 1742 [dict removeValueForKey:22LL]; | 1742 [dict removeBoolForKey:22LL]; |
| 1743 XCTAssertEqual(dict.count, 3U); | 1743 XCTAssertEqual(dict.count, 3U); |
| 1744 BOOL value; | 1744 BOOL value; |
| 1745 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1745 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1746 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1746 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1747 XCTAssertEqual(value, YES); | 1747 XCTAssertEqual(value, YES); |
| 1748 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1748 XCTAssertFalse([dict getBool:NULL forKey:22LL]); |
| 1749 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1749 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1750 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1750 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1751 XCTAssertEqual(value, NO); | 1751 XCTAssertEqual(value, NO); |
| 1752 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1752 XCTAssertTrue([dict getBool:NULL forKey:24LL]); |
| 1753 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1753 XCTAssertTrue([dict getBool:&value forKey:24LL]); |
| 1754 XCTAssertEqual(value, NO); | 1754 XCTAssertEqual(value, NO); |
| 1755 | 1755 |
| 1756 // Remove again does nothing. | 1756 // Remove again does nothing. |
| 1757 [dict removeValueForKey:22LL]; | 1757 [dict removeBoolForKey:22LL]; |
| 1758 XCTAssertEqual(dict.count, 3U); | 1758 XCTAssertEqual(dict.count, 3U); |
| 1759 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1759 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1760 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1760 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1761 XCTAssertEqual(value, YES); | 1761 XCTAssertEqual(value, YES); |
| 1762 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1762 XCTAssertFalse([dict getBool:NULL forKey:22LL]); |
| 1763 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1763 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1764 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1764 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1765 XCTAssertEqual(value, NO); | 1765 XCTAssertEqual(value, NO); |
| 1766 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1766 XCTAssertTrue([dict getBool:NULL forKey:24LL]); |
| 1767 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1767 XCTAssertTrue([dict getBool:&value forKey:24LL]); |
| 1768 XCTAssertEqual(value, NO); | 1768 XCTAssertEqual(value, NO); |
| 1769 | 1769 |
| 1770 [dict removeValueForKey:24LL]; | 1770 [dict removeBoolForKey:24LL]; |
| 1771 XCTAssertEqual(dict.count, 2U); | 1771 XCTAssertEqual(dict.count, 2U); |
| 1772 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1772 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1773 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1773 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1774 XCTAssertEqual(value, YES); | 1774 XCTAssertEqual(value, YES); |
| 1775 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1775 XCTAssertFalse([dict getBool:NULL forKey:22LL]); |
| 1776 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1776 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1777 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1777 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1778 XCTAssertEqual(value, NO); | 1778 XCTAssertEqual(value, NO); |
| 1779 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1779 XCTAssertFalse([dict getBool:NULL forKey:24LL]); |
| 1780 | 1780 |
| 1781 [dict removeAll]; | 1781 [dict removeAll]; |
| 1782 XCTAssertEqual(dict.count, 0U); | 1782 XCTAssertEqual(dict.count, 0U); |
| 1783 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 1783 XCTAssertFalse([dict getBool:NULL forKey:21LL]); |
| 1784 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1784 XCTAssertFalse([dict getBool:NULL forKey:22LL]); |
| 1785 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 1785 XCTAssertFalse([dict getBool:NULL forKey:23LL]); |
| 1786 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1786 XCTAssertFalse([dict getBool:NULL forKey:24LL]); |
| 1787 [dict release]; | 1787 [dict release]; |
| 1788 } | 1788 } |
| 1789 | 1789 |
| 1790 - (void)testInplaceMutation { | 1790 - (void)testInplaceMutation { |
| 1791 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 1791 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1792 const BOOL kValues[] = { YES, YES, NO, NO }; | 1792 const BOOL kValues[] = { YES, YES, NO, NO }; |
| 1793 GPBInt64BoolDictionary *dict = | 1793 GPBInt64BoolDictionary *dict = |
| 1794 [[GPBInt64BoolDictionary alloc] initWithValues:kValues | 1794 [[GPBInt64BoolDictionary alloc] initWithBools:kValues |
| 1795 forKeys:kKeys | 1795 forKeys:kKeys |
| 1796 count:GPBARRAYSIZE(kValues)]; | 1796 count:GPBARRAYSIZE(kValues)]; |
| 1797 XCTAssertNotNil(dict); | 1797 XCTAssertNotNil(dict); |
| 1798 XCTAssertEqual(dict.count, 4U); | 1798 XCTAssertEqual(dict.count, 4U); |
| 1799 BOOL value; | 1799 BOOL value; |
| 1800 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1800 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1801 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1801 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1802 XCTAssertEqual(value, YES); | 1802 XCTAssertEqual(value, YES); |
| 1803 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1803 XCTAssertTrue([dict getBool:NULL forKey:22LL]); |
| 1804 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1804 XCTAssertTrue([dict getBool:&value forKey:22LL]); |
| 1805 XCTAssertEqual(value, YES); | 1805 XCTAssertEqual(value, YES); |
| 1806 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1806 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1807 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1807 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1808 XCTAssertEqual(value, NO); | 1808 XCTAssertEqual(value, NO); |
| 1809 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1809 XCTAssertTrue([dict getBool:NULL forKey:24LL]); |
| 1810 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1810 XCTAssertTrue([dict getBool:&value forKey:24LL]); |
| 1811 XCTAssertEqual(value, NO); | 1811 XCTAssertEqual(value, NO); |
| 1812 | 1812 |
| 1813 [dict setValue:NO forKey:21LL]; | 1813 [dict setBool:NO forKey:21LL]; |
| 1814 XCTAssertEqual(dict.count, 4U); | 1814 XCTAssertEqual(dict.count, 4U); |
| 1815 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1815 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1816 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1816 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1817 XCTAssertEqual(value, NO); | 1817 XCTAssertEqual(value, NO); |
| 1818 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1818 XCTAssertTrue([dict getBool:NULL forKey:22LL]); |
| 1819 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1819 XCTAssertTrue([dict getBool:&value forKey:22LL]); |
| 1820 XCTAssertEqual(value, YES); | 1820 XCTAssertEqual(value, YES); |
| 1821 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1821 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1822 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1822 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1823 XCTAssertEqual(value, NO); | 1823 XCTAssertEqual(value, NO); |
| 1824 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1824 XCTAssertTrue([dict getBool:NULL forKey:24LL]); |
| 1825 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1825 XCTAssertTrue([dict getBool:&value forKey:24LL]); |
| 1826 XCTAssertEqual(value, NO); | 1826 XCTAssertEqual(value, NO); |
| 1827 | 1827 |
| 1828 [dict setValue:YES forKey:24LL]; | 1828 [dict setBool:YES forKey:24LL]; |
| 1829 XCTAssertEqual(dict.count, 4U); | 1829 XCTAssertEqual(dict.count, 4U); |
| 1830 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1830 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1831 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1831 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1832 XCTAssertEqual(value, NO); | 1832 XCTAssertEqual(value, NO); |
| 1833 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1833 XCTAssertTrue([dict getBool:NULL forKey:22LL]); |
| 1834 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1834 XCTAssertTrue([dict getBool:&value forKey:22LL]); |
| 1835 XCTAssertEqual(value, YES); | 1835 XCTAssertEqual(value, YES); |
| 1836 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1836 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1837 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1837 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1838 XCTAssertEqual(value, NO); | 1838 XCTAssertEqual(value, NO); |
| 1839 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1839 XCTAssertTrue([dict getBool:NULL forKey:24LL]); |
| 1840 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1840 XCTAssertTrue([dict getBool:&value forKey:24LL]); |
| 1841 XCTAssertEqual(value, YES); | 1841 XCTAssertEqual(value, YES); |
| 1842 | 1842 |
| 1843 const int64_t kKeys2[] = { 22LL, 23LL }; | 1843 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 1844 const BOOL kValues2[] = { NO, YES }; | 1844 const BOOL kValues2[] = { NO, YES }; |
| 1845 GPBInt64BoolDictionary *dict2 = | 1845 GPBInt64BoolDictionary *dict2 = |
| 1846 [[GPBInt64BoolDictionary alloc] initWithValues:kValues2 | 1846 [[GPBInt64BoolDictionary alloc] initWithBools:kValues2 |
| 1847 forKeys:kKeys2 | 1847 forKeys:kKeys2 |
| 1848 count:GPBARRAYSIZE(kValues2)]; | 1848 count:GPBARRAYSIZE(kValues2)]; |
| 1849 XCTAssertNotNil(dict2); | 1849 XCTAssertNotNil(dict2); |
| 1850 [dict addEntriesFromDictionary:dict2]; | 1850 [dict addEntriesFromDictionary:dict2]; |
| 1851 XCTAssertEqual(dict.count, 4U); | 1851 XCTAssertEqual(dict.count, 4U); |
| 1852 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1852 XCTAssertTrue([dict getBool:NULL forKey:21LL]); |
| 1853 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1853 XCTAssertTrue([dict getBool:&value forKey:21LL]); |
| 1854 XCTAssertEqual(value, NO); | 1854 XCTAssertEqual(value, NO); |
| 1855 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1855 XCTAssertTrue([dict getBool:NULL forKey:22LL]); |
| 1856 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1856 XCTAssertTrue([dict getBool:&value forKey:22LL]); |
| 1857 XCTAssertEqual(value, NO); | 1857 XCTAssertEqual(value, NO); |
| 1858 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1858 XCTAssertTrue([dict getBool:NULL forKey:23LL]); |
| 1859 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1859 XCTAssertTrue([dict getBool:&value forKey:23LL]); |
| 1860 XCTAssertEqual(value, YES); | 1860 XCTAssertEqual(value, YES); |
| 1861 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 1861 XCTAssertTrue([dict getBool:NULL forKey:24LL]); |
| 1862 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 1862 XCTAssertTrue([dict getBool:&value forKey:24LL]); |
| 1863 XCTAssertEqual(value, YES); | 1863 XCTAssertEqual(value, YES); |
| 1864 | 1864 |
| 1865 [dict2 release]; | 1865 [dict2 release]; |
| 1866 [dict release]; | 1866 [dict release]; |
| 1867 } | 1867 } |
| 1868 | 1868 |
| 1869 @end | 1869 @end |
| 1870 | 1870 |
| 1871 #pragma mark - Int64 -> Float | 1871 #pragma mark - Int64 -> Float |
| 1872 | 1872 |
| 1873 @interface GPBInt64FloatDictionaryTests : XCTestCase | 1873 @interface GPBInt64FloatDictionaryTests : XCTestCase |
| 1874 @end | 1874 @end |
| 1875 | 1875 |
| 1876 @implementation GPBInt64FloatDictionaryTests | 1876 @implementation GPBInt64FloatDictionaryTests |
| 1877 | 1877 |
| 1878 - (void)testEmpty { | 1878 - (void)testEmpty { |
| 1879 GPBInt64FloatDictionary *dict = [[GPBInt64FloatDictionary alloc] init]; | 1879 GPBInt64FloatDictionary *dict = [[GPBInt64FloatDictionary alloc] init]; |
| 1880 XCTAssertNotNil(dict); | 1880 XCTAssertNotNil(dict); |
| 1881 XCTAssertEqual(dict.count, 0U); | 1881 XCTAssertEqual(dict.count, 0U); |
| 1882 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 1882 XCTAssertFalse([dict getFloat:NULL forKey:21LL]); |
| 1883 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { | 1883 [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { |
| 1884 #pragma unused(aKey, aValue, stop) | 1884 #pragma unused(aKey, aValue, stop) |
| 1885 XCTFail(@"Shouldn't get here!"); | 1885 XCTFail(@"Shouldn't get here!"); |
| 1886 }]; | 1886 }]; |
| 1887 [dict release]; | 1887 [dict release]; |
| 1888 } | 1888 } |
| 1889 | 1889 |
| 1890 - (void)testOne { | 1890 - (void)testOne { |
| 1891 GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionaryWithValue:5
00.f forKey:21LL]; | 1891 GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionaryWithFloat:5
00.f forKey:21LL]; |
| 1892 XCTAssertNotNil(dict); | 1892 XCTAssertNotNil(dict); |
| 1893 XCTAssertEqual(dict.count, 1U); | 1893 XCTAssertEqual(dict.count, 1U); |
| 1894 float value; | 1894 float value; |
| 1895 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1895 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 1896 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1896 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 1897 XCTAssertEqual(value, 500.f); | 1897 XCTAssertEqual(value, 500.f); |
| 1898 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 1898 XCTAssertFalse([dict getFloat:NULL forKey:22LL]); |
| 1899 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { | 1899 [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { |
| 1900 XCTAssertEqual(aKey, 21LL); | 1900 XCTAssertEqual(aKey, 21LL); |
| 1901 XCTAssertEqual(aValue, 500.f); | 1901 XCTAssertEqual(aValue, 500.f); |
| 1902 XCTAssertNotEqual(stop, NULL); | 1902 XCTAssertNotEqual(stop, NULL); |
| 1903 }]; | 1903 }]; |
| 1904 } | 1904 } |
| 1905 | 1905 |
| 1906 - (void)testBasics { | 1906 - (void)testBasics { |
| 1907 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 1907 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 1908 const float kValues[] = { 500.f, 501.f, 502.f }; | 1908 const float kValues[] = { 500.f, 501.f, 502.f }; |
| 1909 GPBInt64FloatDictionary *dict = | 1909 GPBInt64FloatDictionary *dict = |
| 1910 [[GPBInt64FloatDictionary alloc] initWithValues:kValues | 1910 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues |
| 1911 forKeys:kKeys | 1911 forKeys:kKeys |
| 1912 count:GPBARRAYSIZE(kValues)]; | 1912 count:GPBARRAYSIZE(kValues)]; |
| 1913 XCTAssertNotNil(dict); | 1913 XCTAssertNotNil(dict); |
| 1914 XCTAssertEqual(dict.count, 3U); | 1914 XCTAssertEqual(dict.count, 3U); |
| 1915 float value; | 1915 float value; |
| 1916 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 1916 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 1917 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 1917 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 1918 XCTAssertEqual(value, 500.f); | 1918 XCTAssertEqual(value, 500.f); |
| 1919 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 1919 XCTAssertTrue([dict getFloat:NULL forKey:22LL]); |
| 1920 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 1920 XCTAssertTrue([dict getFloat:&value forKey:22LL]); |
| 1921 XCTAssertEqual(value, 501.f); | 1921 XCTAssertEqual(value, 501.f); |
| 1922 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 1922 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 1923 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 1923 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 1924 XCTAssertEqual(value, 502.f); | 1924 XCTAssertEqual(value, 502.f); |
| 1925 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 1925 XCTAssertFalse([dict getFloat:NULL forKey:24LL]); |
| 1926 | 1926 |
| 1927 __block NSUInteger idx = 0; | 1927 __block NSUInteger idx = 0; |
| 1928 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 1928 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 1929 float *seenValues = malloc(3 * sizeof(float)); | 1929 float *seenValues = malloc(3 * sizeof(float)); |
| 1930 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { | 1930 [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { |
| 1931 XCTAssertLessThan(idx, 3U); | 1931 XCTAssertLessThan(idx, 3U); |
| 1932 seenKeys[idx] = aKey; | 1932 seenKeys[idx] = aKey; |
| 1933 seenValues[idx] = aValue; | 1933 seenValues[idx] = aValue; |
| 1934 XCTAssertNotEqual(stop, NULL); | 1934 XCTAssertNotEqual(stop, NULL); |
| 1935 ++idx; | 1935 ++idx; |
| 1936 }]; | 1936 }]; |
| 1937 for (int i = 0; i < 3; ++i) { | 1937 for (int i = 0; i < 3; ++i) { |
| 1938 BOOL foundKey = NO; | 1938 BOOL foundKey = NO; |
| 1939 for (int j = 0; (j < 3) && !foundKey; ++j) { | 1939 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 1940 if (kKeys[i] == seenKeys[j]) { | 1940 if (kKeys[i] == seenKeys[j]) { |
| 1941 foundKey = YES; | 1941 foundKey = YES; |
| 1942 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 1942 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 1943 } | 1943 } |
| 1944 } | 1944 } |
| 1945 XCTAssertTrue(foundKey, @"i = %d", i); | 1945 XCTAssertTrue(foundKey, @"i = %d", i); |
| 1946 } | 1946 } |
| 1947 free(seenKeys); | 1947 free(seenKeys); |
| 1948 free(seenValues); | 1948 free(seenValues); |
| 1949 | 1949 |
| 1950 // Stopping the enumeration. | 1950 // Stopping the enumeration. |
| 1951 idx = 0; | 1951 idx = 0; |
| 1952 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { | 1952 [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *sto
p) { |
| 1953 #pragma unused(aKey, aValue) | 1953 #pragma unused(aKey, aValue) |
| 1954 if (idx == 1) *stop = YES; | 1954 if (idx == 1) *stop = YES; |
| 1955 XCTAssertNotEqual(idx, 2U); | 1955 XCTAssertNotEqual(idx, 2U); |
| 1956 ++idx; | 1956 ++idx; |
| 1957 }]; | 1957 }]; |
| 1958 [dict release]; | 1958 [dict release]; |
| 1959 } | 1959 } |
| 1960 | 1960 |
| 1961 - (void)testEquality { | 1961 - (void)testEquality { |
| 1962 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 1962 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 1963 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 1963 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 1964 const float kValues1[] = { 500.f, 501.f, 502.f }; | 1964 const float kValues1[] = { 500.f, 501.f, 502.f }; |
| 1965 const float kValues2[] = { 500.f, 503.f, 502.f }; | 1965 const float kValues2[] = { 500.f, 503.f, 502.f }; |
| 1966 const float kValues3[] = { 500.f, 501.f, 502.f, 503.f }; | 1966 const float kValues3[] = { 500.f, 501.f, 502.f, 503.f }; |
| 1967 GPBInt64FloatDictionary *dict1 = | 1967 GPBInt64FloatDictionary *dict1 = |
| 1968 [[GPBInt64FloatDictionary alloc] initWithValues:kValues1 | 1968 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1 |
| 1969 forKeys:kKeys1 | 1969 forKeys:kKeys1 |
| 1970 count:GPBARRAYSIZE(kValues1)]; | 1970 count:GPBARRAYSIZE(kValues1)]; |
| 1971 XCTAssertNotNil(dict1); | 1971 XCTAssertNotNil(dict1); |
| 1972 GPBInt64FloatDictionary *dict1prime = | 1972 GPBInt64FloatDictionary *dict1prime = |
| 1973 [[GPBInt64FloatDictionary alloc] initWithValues:kValues1 | 1973 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1 |
| 1974 forKeys:kKeys1 | 1974 forKeys:kKeys1 |
| 1975 count:GPBARRAYSIZE(kValues1)]; | 1975 count:GPBARRAYSIZE(kValues1)]; |
| 1976 XCTAssertNotNil(dict1prime); | 1976 XCTAssertNotNil(dict1prime); |
| 1977 GPBInt64FloatDictionary *dict2 = | 1977 GPBInt64FloatDictionary *dict2 = |
| 1978 [[GPBInt64FloatDictionary alloc] initWithValues:kValues2 | 1978 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues2 |
| 1979 forKeys:kKeys1 | 1979 forKeys:kKeys1 |
| 1980 count:GPBARRAYSIZE(kValues2)]; | 1980 count:GPBARRAYSIZE(kValues2)]; |
| 1981 XCTAssertNotNil(dict2); | 1981 XCTAssertNotNil(dict2); |
| 1982 GPBInt64FloatDictionary *dict3 = | 1982 GPBInt64FloatDictionary *dict3 = |
| 1983 [[GPBInt64FloatDictionary alloc] initWithValues:kValues1 | 1983 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1 |
| 1984 forKeys:kKeys2 | 1984 forKeys:kKeys2 |
| 1985 count:GPBARRAYSIZE(kValues1)]; | 1985 count:GPBARRAYSIZE(kValues1)]; |
| 1986 XCTAssertNotNil(dict3); | 1986 XCTAssertNotNil(dict3); |
| 1987 GPBInt64FloatDictionary *dict4 = | 1987 GPBInt64FloatDictionary *dict4 = |
| 1988 [[GPBInt64FloatDictionary alloc] initWithValues:kValues3 | 1988 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues3 |
| 1989 forKeys:kKeys1 | 1989 forKeys:kKeys1 |
| 1990 count:GPBARRAYSIZE(kValues3)]; | 1990 count:GPBARRAYSIZE(kValues3)]; |
| 1991 XCTAssertNotNil(dict4); | 1991 XCTAssertNotNil(dict4); |
| 1992 | 1992 |
| 1993 // 1/1Prime should be different objects, but equal. | 1993 // 1/1Prime should be different objects, but equal. |
| 1994 XCTAssertNotEqual(dict1, dict1prime); | 1994 XCTAssertNotEqual(dict1, dict1prime); |
| 1995 XCTAssertEqualObjects(dict1, dict1prime); | 1995 XCTAssertEqualObjects(dict1, dict1prime); |
| 1996 // Equal, so they must have same hash. | 1996 // Equal, so they must have same hash. |
| 1997 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 1997 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 1998 | 1998 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2009 [dict1prime release]; | 2009 [dict1prime release]; |
| 2010 [dict2 release]; | 2010 [dict2 release]; |
| 2011 [dict3 release]; | 2011 [dict3 release]; |
| 2012 [dict4 release]; | 2012 [dict4 release]; |
| 2013 } | 2013 } |
| 2014 | 2014 |
| 2015 - (void)testCopy { | 2015 - (void)testCopy { |
| 2016 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2016 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2017 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; | 2017 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; |
| 2018 GPBInt64FloatDictionary *dict = | 2018 GPBInt64FloatDictionary *dict = |
| 2019 [[GPBInt64FloatDictionary alloc] initWithValues:kValues | 2019 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues |
| 2020 forKeys:kKeys | 2020 forKeys:kKeys |
| 2021 count:GPBARRAYSIZE(kValues)]; | 2021 count:GPBARRAYSIZE(kValues)]; |
| 2022 XCTAssertNotNil(dict); | 2022 XCTAssertNotNil(dict); |
| 2023 | 2023 |
| 2024 GPBInt64FloatDictionary *dict2 = [dict copy]; | 2024 GPBInt64FloatDictionary *dict2 = [dict copy]; |
| 2025 XCTAssertNotNil(dict2); | 2025 XCTAssertNotNil(dict2); |
| 2026 | 2026 |
| 2027 // Should be new object but equal. | 2027 // Should be new object but equal. |
| 2028 XCTAssertNotEqual(dict, dict2); | 2028 XCTAssertNotEqual(dict, dict2); |
| 2029 XCTAssertEqualObjects(dict, dict2); | 2029 XCTAssertEqualObjects(dict, dict2); |
| 2030 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64FloatDictionary class]]); | 2030 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64FloatDictionary class]]); |
| 2031 | 2031 |
| 2032 [dict2 release]; | 2032 [dict2 release]; |
| 2033 [dict release]; | 2033 [dict release]; |
| 2034 } | 2034 } |
| 2035 | 2035 |
| 2036 - (void)testDictionaryFromDictionary { | 2036 - (void)testDictionaryFromDictionary { |
| 2037 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2037 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2038 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; | 2038 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; |
| 2039 GPBInt64FloatDictionary *dict = | 2039 GPBInt64FloatDictionary *dict = |
| 2040 [[GPBInt64FloatDictionary alloc] initWithValues:kValues | 2040 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues |
| 2041 forKeys:kKeys | 2041 forKeys:kKeys |
| 2042 count:GPBARRAYSIZE(kValues)]; | 2042 count:GPBARRAYSIZE(kValues)]; |
| 2043 XCTAssertNotNil(dict); | 2043 XCTAssertNotNil(dict); |
| 2044 | 2044 |
| 2045 GPBInt64FloatDictionary *dict2 = | 2045 GPBInt64FloatDictionary *dict2 = |
| 2046 [GPBInt64FloatDictionary dictionaryWithDictionary:dict]; | 2046 [GPBInt64FloatDictionary dictionaryWithDictionary:dict]; |
| 2047 XCTAssertNotNil(dict2); | 2047 XCTAssertNotNil(dict2); |
| 2048 | 2048 |
| 2049 // Should be new pointer, but equal objects. | 2049 // Should be new pointer, but equal objects. |
| 2050 XCTAssertNotEqual(dict, dict2); | 2050 XCTAssertNotEqual(dict, dict2); |
| 2051 XCTAssertEqualObjects(dict, dict2); | 2051 XCTAssertEqualObjects(dict, dict2); |
| 2052 [dict release]; | 2052 [dict release]; |
| 2053 } | 2053 } |
| 2054 | 2054 |
| 2055 - (void)testAdds { | 2055 - (void)testAdds { |
| 2056 GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionary]; | 2056 GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionary]; |
| 2057 XCTAssertNotNil(dict); | 2057 XCTAssertNotNil(dict); |
| 2058 | 2058 |
| 2059 XCTAssertEqual(dict.count, 0U); | 2059 XCTAssertEqual(dict.count, 0U); |
| 2060 [dict setValue:500.f forKey:21LL]; | 2060 [dict setFloat:500.f forKey:21LL]; |
| 2061 XCTAssertEqual(dict.count, 1U); | 2061 XCTAssertEqual(dict.count, 1U); |
| 2062 | 2062 |
| 2063 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 2063 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 2064 const float kValues[] = { 501.f, 502.f, 503.f }; | 2064 const float kValues[] = { 501.f, 502.f, 503.f }; |
| 2065 GPBInt64FloatDictionary *dict2 = | 2065 GPBInt64FloatDictionary *dict2 = |
| 2066 [[GPBInt64FloatDictionary alloc] initWithValues:kValues | 2066 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues |
| 2067 forKeys:kKeys | 2067 forKeys:kKeys |
| 2068 count:GPBARRAYSIZE(kValues)]; | 2068 count:GPBARRAYSIZE(kValues)]; |
| 2069 XCTAssertNotNil(dict2); | 2069 XCTAssertNotNil(dict2); |
| 2070 [dict addEntriesFromDictionary:dict2]; | 2070 [dict addEntriesFromDictionary:dict2]; |
| 2071 XCTAssertEqual(dict.count, 4U); | 2071 XCTAssertEqual(dict.count, 4U); |
| 2072 | 2072 |
| 2073 float value; | 2073 float value; |
| 2074 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2074 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2075 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2075 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2076 XCTAssertEqual(value, 500.f); | 2076 XCTAssertEqual(value, 500.f); |
| 2077 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2077 XCTAssertTrue([dict getFloat:NULL forKey:22LL]); |
| 2078 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2078 XCTAssertTrue([dict getFloat:&value forKey:22LL]); |
| 2079 XCTAssertEqual(value, 501.f); | 2079 XCTAssertEqual(value, 501.f); |
| 2080 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2080 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2081 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2081 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2082 XCTAssertEqual(value, 502.f); | 2082 XCTAssertEqual(value, 502.f); |
| 2083 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2083 XCTAssertTrue([dict getFloat:NULL forKey:24LL]); |
| 2084 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2084 XCTAssertTrue([dict getFloat:&value forKey:24LL]); |
| 2085 XCTAssertEqual(value, 503.f); | 2085 XCTAssertEqual(value, 503.f); |
| 2086 [dict2 release]; | 2086 [dict2 release]; |
| 2087 } | 2087 } |
| 2088 | 2088 |
| 2089 - (void)testRemove { | 2089 - (void)testRemove { |
| 2090 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2090 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2091 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; | 2091 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; |
| 2092 GPBInt64FloatDictionary *dict = | 2092 GPBInt64FloatDictionary *dict = |
| 2093 [[GPBInt64FloatDictionary alloc] initWithValues:kValues | 2093 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues |
| 2094 forKeys:kKeys | 2094 forKeys:kKeys |
| 2095 count:GPBARRAYSIZE(kValues)]; | 2095 count:GPBARRAYSIZE(kValues)]; |
| 2096 XCTAssertNotNil(dict); | 2096 XCTAssertNotNil(dict); |
| 2097 XCTAssertEqual(dict.count, 4U); | 2097 XCTAssertEqual(dict.count, 4U); |
| 2098 | 2098 |
| 2099 [dict removeValueForKey:22LL]; | 2099 [dict removeFloatForKey:22LL]; |
| 2100 XCTAssertEqual(dict.count, 3U); | 2100 XCTAssertEqual(dict.count, 3U); |
| 2101 float value; | 2101 float value; |
| 2102 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2102 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2103 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2103 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2104 XCTAssertEqual(value, 500.f); | 2104 XCTAssertEqual(value, 500.f); |
| 2105 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2105 XCTAssertFalse([dict getFloat:NULL forKey:22LL]); |
| 2106 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2106 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2107 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2107 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2108 XCTAssertEqual(value, 502.f); | 2108 XCTAssertEqual(value, 502.f); |
| 2109 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2109 XCTAssertTrue([dict getFloat:NULL forKey:24LL]); |
| 2110 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2110 XCTAssertTrue([dict getFloat:&value forKey:24LL]); |
| 2111 XCTAssertEqual(value, 503.f); | 2111 XCTAssertEqual(value, 503.f); |
| 2112 | 2112 |
| 2113 // Remove again does nothing. | 2113 // Remove again does nothing. |
| 2114 [dict removeValueForKey:22LL]; | 2114 [dict removeFloatForKey:22LL]; |
| 2115 XCTAssertEqual(dict.count, 3U); | 2115 XCTAssertEqual(dict.count, 3U); |
| 2116 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2116 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2117 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2117 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2118 XCTAssertEqual(value, 500.f); | 2118 XCTAssertEqual(value, 500.f); |
| 2119 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2119 XCTAssertFalse([dict getFloat:NULL forKey:22LL]); |
| 2120 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2120 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2121 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2121 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2122 XCTAssertEqual(value, 502.f); | 2122 XCTAssertEqual(value, 502.f); |
| 2123 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2123 XCTAssertTrue([dict getFloat:NULL forKey:24LL]); |
| 2124 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2124 XCTAssertTrue([dict getFloat:&value forKey:24LL]); |
| 2125 XCTAssertEqual(value, 503.f); | 2125 XCTAssertEqual(value, 503.f); |
| 2126 | 2126 |
| 2127 [dict removeValueForKey:24LL]; | 2127 [dict removeFloatForKey:24LL]; |
| 2128 XCTAssertEqual(dict.count, 2U); | 2128 XCTAssertEqual(dict.count, 2U); |
| 2129 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2129 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2130 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2130 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2131 XCTAssertEqual(value, 500.f); | 2131 XCTAssertEqual(value, 500.f); |
| 2132 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2132 XCTAssertFalse([dict getFloat:NULL forKey:22LL]); |
| 2133 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2133 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2134 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2134 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2135 XCTAssertEqual(value, 502.f); | 2135 XCTAssertEqual(value, 502.f); |
| 2136 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2136 XCTAssertFalse([dict getFloat:NULL forKey:24LL]); |
| 2137 | 2137 |
| 2138 [dict removeAll]; | 2138 [dict removeAll]; |
| 2139 XCTAssertEqual(dict.count, 0U); | 2139 XCTAssertEqual(dict.count, 0U); |
| 2140 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 2140 XCTAssertFalse([dict getFloat:NULL forKey:21LL]); |
| 2141 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2141 XCTAssertFalse([dict getFloat:NULL forKey:22LL]); |
| 2142 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 2142 XCTAssertFalse([dict getFloat:NULL forKey:23LL]); |
| 2143 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2143 XCTAssertFalse([dict getFloat:NULL forKey:24LL]); |
| 2144 [dict release]; | 2144 [dict release]; |
| 2145 } | 2145 } |
| 2146 | 2146 |
| 2147 - (void)testInplaceMutation { | 2147 - (void)testInplaceMutation { |
| 2148 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2148 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2149 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; | 2149 const float kValues[] = { 500.f, 501.f, 502.f, 503.f }; |
| 2150 GPBInt64FloatDictionary *dict = | 2150 GPBInt64FloatDictionary *dict = |
| 2151 [[GPBInt64FloatDictionary alloc] initWithValues:kValues | 2151 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues |
| 2152 forKeys:kKeys | 2152 forKeys:kKeys |
| 2153 count:GPBARRAYSIZE(kValues)]; | 2153 count:GPBARRAYSIZE(kValues)]; |
| 2154 XCTAssertNotNil(dict); | 2154 XCTAssertNotNil(dict); |
| 2155 XCTAssertEqual(dict.count, 4U); | 2155 XCTAssertEqual(dict.count, 4U); |
| 2156 float value; | 2156 float value; |
| 2157 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2157 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2158 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2158 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2159 XCTAssertEqual(value, 500.f); | 2159 XCTAssertEqual(value, 500.f); |
| 2160 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2160 XCTAssertTrue([dict getFloat:NULL forKey:22LL]); |
| 2161 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2161 XCTAssertTrue([dict getFloat:&value forKey:22LL]); |
| 2162 XCTAssertEqual(value, 501.f); | 2162 XCTAssertEqual(value, 501.f); |
| 2163 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2163 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2164 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2164 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2165 XCTAssertEqual(value, 502.f); | 2165 XCTAssertEqual(value, 502.f); |
| 2166 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2166 XCTAssertTrue([dict getFloat:NULL forKey:24LL]); |
| 2167 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2167 XCTAssertTrue([dict getFloat:&value forKey:24LL]); |
| 2168 XCTAssertEqual(value, 503.f); | 2168 XCTAssertEqual(value, 503.f); |
| 2169 | 2169 |
| 2170 [dict setValue:503.f forKey:21LL]; | 2170 [dict setFloat:503.f forKey:21LL]; |
| 2171 XCTAssertEqual(dict.count, 4U); | 2171 XCTAssertEqual(dict.count, 4U); |
| 2172 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2172 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2173 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2173 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2174 XCTAssertEqual(value, 503.f); | 2174 XCTAssertEqual(value, 503.f); |
| 2175 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2175 XCTAssertTrue([dict getFloat:NULL forKey:22LL]); |
| 2176 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2176 XCTAssertTrue([dict getFloat:&value forKey:22LL]); |
| 2177 XCTAssertEqual(value, 501.f); | 2177 XCTAssertEqual(value, 501.f); |
| 2178 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2178 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2179 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2179 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2180 XCTAssertEqual(value, 502.f); | 2180 XCTAssertEqual(value, 502.f); |
| 2181 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2181 XCTAssertTrue([dict getFloat:NULL forKey:24LL]); |
| 2182 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2182 XCTAssertTrue([dict getFloat:&value forKey:24LL]); |
| 2183 XCTAssertEqual(value, 503.f); | 2183 XCTAssertEqual(value, 503.f); |
| 2184 | 2184 |
| 2185 [dict setValue:501.f forKey:24LL]; | 2185 [dict setFloat:501.f forKey:24LL]; |
| 2186 XCTAssertEqual(dict.count, 4U); | 2186 XCTAssertEqual(dict.count, 4U); |
| 2187 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2187 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2188 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2188 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2189 XCTAssertEqual(value, 503.f); | 2189 XCTAssertEqual(value, 503.f); |
| 2190 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2190 XCTAssertTrue([dict getFloat:NULL forKey:22LL]); |
| 2191 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2191 XCTAssertTrue([dict getFloat:&value forKey:22LL]); |
| 2192 XCTAssertEqual(value, 501.f); | 2192 XCTAssertEqual(value, 501.f); |
| 2193 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2193 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2194 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2194 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2195 XCTAssertEqual(value, 502.f); | 2195 XCTAssertEqual(value, 502.f); |
| 2196 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2196 XCTAssertTrue([dict getFloat:NULL forKey:24LL]); |
| 2197 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2197 XCTAssertTrue([dict getFloat:&value forKey:24LL]); |
| 2198 XCTAssertEqual(value, 501.f); | 2198 XCTAssertEqual(value, 501.f); |
| 2199 | 2199 |
| 2200 const int64_t kKeys2[] = { 22LL, 23LL }; | 2200 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 2201 const float kValues2[] = { 502.f, 500.f }; | 2201 const float kValues2[] = { 502.f, 500.f }; |
| 2202 GPBInt64FloatDictionary *dict2 = | 2202 GPBInt64FloatDictionary *dict2 = |
| 2203 [[GPBInt64FloatDictionary alloc] initWithValues:kValues2 | 2203 [[GPBInt64FloatDictionary alloc] initWithFloats:kValues2 |
| 2204 forKeys:kKeys2 | 2204 forKeys:kKeys2 |
| 2205 count:GPBARRAYSIZE(kValues2)]; | 2205 count:GPBARRAYSIZE(kValues2)]; |
| 2206 XCTAssertNotNil(dict2); | 2206 XCTAssertNotNil(dict2); |
| 2207 [dict addEntriesFromDictionary:dict2]; | 2207 [dict addEntriesFromDictionary:dict2]; |
| 2208 XCTAssertEqual(dict.count, 4U); | 2208 XCTAssertEqual(dict.count, 4U); |
| 2209 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2209 XCTAssertTrue([dict getFloat:NULL forKey:21LL]); |
| 2210 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2210 XCTAssertTrue([dict getFloat:&value forKey:21LL]); |
| 2211 XCTAssertEqual(value, 503.f); | 2211 XCTAssertEqual(value, 503.f); |
| 2212 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2212 XCTAssertTrue([dict getFloat:NULL forKey:22LL]); |
| 2213 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2213 XCTAssertTrue([dict getFloat:&value forKey:22LL]); |
| 2214 XCTAssertEqual(value, 502.f); | 2214 XCTAssertEqual(value, 502.f); |
| 2215 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2215 XCTAssertTrue([dict getFloat:NULL forKey:23LL]); |
| 2216 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2216 XCTAssertTrue([dict getFloat:&value forKey:23LL]); |
| 2217 XCTAssertEqual(value, 500.f); | 2217 XCTAssertEqual(value, 500.f); |
| 2218 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2218 XCTAssertTrue([dict getFloat:NULL forKey:24LL]); |
| 2219 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2219 XCTAssertTrue([dict getFloat:&value forKey:24LL]); |
| 2220 XCTAssertEqual(value, 501.f); | 2220 XCTAssertEqual(value, 501.f); |
| 2221 | 2221 |
| 2222 [dict2 release]; | 2222 [dict2 release]; |
| 2223 [dict release]; | 2223 [dict release]; |
| 2224 } | 2224 } |
| 2225 | 2225 |
| 2226 @end | 2226 @end |
| 2227 | 2227 |
| 2228 #pragma mark - Int64 -> Double | 2228 #pragma mark - Int64 -> Double |
| 2229 | 2229 |
| 2230 @interface GPBInt64DoubleDictionaryTests : XCTestCase | 2230 @interface GPBInt64DoubleDictionaryTests : XCTestCase |
| 2231 @end | 2231 @end |
| 2232 | 2232 |
| 2233 @implementation GPBInt64DoubleDictionaryTests | 2233 @implementation GPBInt64DoubleDictionaryTests |
| 2234 | 2234 |
| 2235 - (void)testEmpty { | 2235 - (void)testEmpty { |
| 2236 GPBInt64DoubleDictionary *dict = [[GPBInt64DoubleDictionary alloc] init]; | 2236 GPBInt64DoubleDictionary *dict = [[GPBInt64DoubleDictionary alloc] init]; |
| 2237 XCTAssertNotNil(dict); | 2237 XCTAssertNotNil(dict); |
| 2238 XCTAssertEqual(dict.count, 0U); | 2238 XCTAssertEqual(dict.count, 0U); |
| 2239 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 2239 XCTAssertFalse([dict getDouble:NULL forKey:21LL]); |
| 2240 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, double aValue, BOOL *st
op) { | 2240 [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *s
top) { |
| 2241 #pragma unused(aKey, aValue, stop) | 2241 #pragma unused(aKey, aValue, stop) |
| 2242 XCTFail(@"Shouldn't get here!"); | 2242 XCTFail(@"Shouldn't get here!"); |
| 2243 }]; | 2243 }]; |
| 2244 [dict release]; | 2244 [dict release]; |
| 2245 } | 2245 } |
| 2246 | 2246 |
| 2247 - (void)testOne { | 2247 - (void)testOne { |
| 2248 GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionaryWithValue
:600. forKey:21LL]; | 2248 GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionaryWithDoubl
e:600. forKey:21LL]; |
| 2249 XCTAssertNotNil(dict); | 2249 XCTAssertNotNil(dict); |
| 2250 XCTAssertEqual(dict.count, 1U); | 2250 XCTAssertEqual(dict.count, 1U); |
| 2251 double value; | 2251 double value; |
| 2252 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2252 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2253 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2253 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2254 XCTAssertEqual(value, 600.); | 2254 XCTAssertEqual(value, 600.); |
| 2255 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2255 XCTAssertFalse([dict getDouble:NULL forKey:22LL]); |
| 2256 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, double aValue, BOOL *st
op) { | 2256 [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *s
top) { |
| 2257 XCTAssertEqual(aKey, 21LL); | 2257 XCTAssertEqual(aKey, 21LL); |
| 2258 XCTAssertEqual(aValue, 600.); | 2258 XCTAssertEqual(aValue, 600.); |
| 2259 XCTAssertNotEqual(stop, NULL); | 2259 XCTAssertNotEqual(stop, NULL); |
| 2260 }]; | 2260 }]; |
| 2261 } | 2261 } |
| 2262 | 2262 |
| 2263 - (void)testBasics { | 2263 - (void)testBasics { |
| 2264 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 2264 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 2265 const double kValues[] = { 600., 601., 602. }; | 2265 const double kValues[] = { 600., 601., 602. }; |
| 2266 GPBInt64DoubleDictionary *dict = | 2266 GPBInt64DoubleDictionary *dict = |
| 2267 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues | 2267 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues |
| 2268 forKeys:kKeys | 2268 forKeys:kKeys |
| 2269 count:GPBARRAYSIZE(kValues)]; | 2269 count:GPBARRAYSIZE(kValues)]; |
| 2270 XCTAssertNotNil(dict); | 2270 XCTAssertNotNil(dict); |
| 2271 XCTAssertEqual(dict.count, 3U); | 2271 XCTAssertEqual(dict.count, 3U); |
| 2272 double value; | 2272 double value; |
| 2273 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2273 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2274 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2274 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2275 XCTAssertEqual(value, 600.); | 2275 XCTAssertEqual(value, 600.); |
| 2276 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2276 XCTAssertTrue([dict getDouble:NULL forKey:22LL]); |
| 2277 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2277 XCTAssertTrue([dict getDouble:&value forKey:22LL]); |
| 2278 XCTAssertEqual(value, 601.); | 2278 XCTAssertEqual(value, 601.); |
| 2279 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2279 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2280 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2280 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2281 XCTAssertEqual(value, 602.); | 2281 XCTAssertEqual(value, 602.); |
| 2282 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2282 XCTAssertFalse([dict getDouble:NULL forKey:24LL]); |
| 2283 | 2283 |
| 2284 __block NSUInteger idx = 0; | 2284 __block NSUInteger idx = 0; |
| 2285 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 2285 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 2286 double *seenValues = malloc(3 * sizeof(double)); | 2286 double *seenValues = malloc(3 * sizeof(double)); |
| 2287 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, double aValue, BOOL *st
op) { | 2287 [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *s
top) { |
| 2288 XCTAssertLessThan(idx, 3U); | 2288 XCTAssertLessThan(idx, 3U); |
| 2289 seenKeys[idx] = aKey; | 2289 seenKeys[idx] = aKey; |
| 2290 seenValues[idx] = aValue; | 2290 seenValues[idx] = aValue; |
| 2291 XCTAssertNotEqual(stop, NULL); | 2291 XCTAssertNotEqual(stop, NULL); |
| 2292 ++idx; | 2292 ++idx; |
| 2293 }]; | 2293 }]; |
| 2294 for (int i = 0; i < 3; ++i) { | 2294 for (int i = 0; i < 3; ++i) { |
| 2295 BOOL foundKey = NO; | 2295 BOOL foundKey = NO; |
| 2296 for (int j = 0; (j < 3) && !foundKey; ++j) { | 2296 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 2297 if (kKeys[i] == seenKeys[j]) { | 2297 if (kKeys[i] == seenKeys[j]) { |
| 2298 foundKey = YES; | 2298 foundKey = YES; |
| 2299 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 2299 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 2300 } | 2300 } |
| 2301 } | 2301 } |
| 2302 XCTAssertTrue(foundKey, @"i = %d", i); | 2302 XCTAssertTrue(foundKey, @"i = %d", i); |
| 2303 } | 2303 } |
| 2304 free(seenKeys); | 2304 free(seenKeys); |
| 2305 free(seenValues); | 2305 free(seenValues); |
| 2306 | 2306 |
| 2307 // Stopping the enumeration. | 2307 // Stopping the enumeration. |
| 2308 idx = 0; | 2308 idx = 0; |
| 2309 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, double aValue, BOOL *st
op) { | 2309 [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *s
top) { |
| 2310 #pragma unused(aKey, aValue) | 2310 #pragma unused(aKey, aValue) |
| 2311 if (idx == 1) *stop = YES; | 2311 if (idx == 1) *stop = YES; |
| 2312 XCTAssertNotEqual(idx, 2U); | 2312 XCTAssertNotEqual(idx, 2U); |
| 2313 ++idx; | 2313 ++idx; |
| 2314 }]; | 2314 }]; |
| 2315 [dict release]; | 2315 [dict release]; |
| 2316 } | 2316 } |
| 2317 | 2317 |
| 2318 - (void)testEquality { | 2318 - (void)testEquality { |
| 2319 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 2319 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2320 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 2320 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 2321 const double kValues1[] = { 600., 601., 602. }; | 2321 const double kValues1[] = { 600., 601., 602. }; |
| 2322 const double kValues2[] = { 600., 603., 602. }; | 2322 const double kValues2[] = { 600., 603., 602. }; |
| 2323 const double kValues3[] = { 600., 601., 602., 603. }; | 2323 const double kValues3[] = { 600., 601., 602., 603. }; |
| 2324 GPBInt64DoubleDictionary *dict1 = | 2324 GPBInt64DoubleDictionary *dict1 = |
| 2325 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues1 | 2325 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1 |
| 2326 forKeys:kKeys1 | 2326 forKeys:kKeys1 |
| 2327 count:GPBARRAYSIZE(kValues1)]; | 2327 count:GPBARRAYSIZE(kValues1)]; |
| 2328 XCTAssertNotNil(dict1); | 2328 XCTAssertNotNil(dict1); |
| 2329 GPBInt64DoubleDictionary *dict1prime = | 2329 GPBInt64DoubleDictionary *dict1prime = |
| 2330 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues1 | 2330 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1 |
| 2331 forKeys:kKeys1 | 2331 forKeys:kKeys1 |
| 2332 count:GPBARRAYSIZE(kValues1)]; | 2332 count:GPBARRAYSIZE(kValues1)]; |
| 2333 XCTAssertNotNil(dict1prime); | 2333 XCTAssertNotNil(dict1prime); |
| 2334 GPBInt64DoubleDictionary *dict2 = | 2334 GPBInt64DoubleDictionary *dict2 = |
| 2335 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues2 | 2335 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues2 |
| 2336 forKeys:kKeys1 | 2336 forKeys:kKeys1 |
| 2337 count:GPBARRAYSIZE(kValues2)]; | 2337 count:GPBARRAYSIZE(kValues2)]; |
| 2338 XCTAssertNotNil(dict2); | 2338 XCTAssertNotNil(dict2); |
| 2339 GPBInt64DoubleDictionary *dict3 = | 2339 GPBInt64DoubleDictionary *dict3 = |
| 2340 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues1 | 2340 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1 |
| 2341 forKeys:kKeys2 | 2341 forKeys:kKeys2 |
| 2342 count:GPBARRAYSIZE(kValues1)]; | 2342 count:GPBARRAYSIZE(kValues1)]; |
| 2343 XCTAssertNotNil(dict3); | 2343 XCTAssertNotNil(dict3); |
| 2344 GPBInt64DoubleDictionary *dict4 = | 2344 GPBInt64DoubleDictionary *dict4 = |
| 2345 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues3 | 2345 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues3 |
| 2346 forKeys:kKeys1 | 2346 forKeys:kKeys1 |
| 2347 count:GPBARRAYSIZE(kValues3)]; | 2347 count:GPBARRAYSIZE(kValues3)]; |
| 2348 XCTAssertNotNil(dict4); | 2348 XCTAssertNotNil(dict4); |
| 2349 | 2349 |
| 2350 // 1/1Prime should be different objects, but equal. | 2350 // 1/1Prime should be different objects, but equal. |
| 2351 XCTAssertNotEqual(dict1, dict1prime); | 2351 XCTAssertNotEqual(dict1, dict1prime); |
| 2352 XCTAssertEqualObjects(dict1, dict1prime); | 2352 XCTAssertEqualObjects(dict1, dict1prime); |
| 2353 // Equal, so they must have same hash. | 2353 // Equal, so they must have same hash. |
| 2354 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 2354 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 2355 | 2355 |
| 2356 // 2 is same keys, different values; not equal. | 2356 // 2 is same keys, different values; not equal. |
| 2357 XCTAssertNotEqualObjects(dict1, dict2); | 2357 XCTAssertNotEqualObjects(dict1, dict2); |
| 2358 | 2358 |
| 2359 // 3 is different keys, same values; not equal. | 2359 // 3 is different keys, same values; not equal. |
| 2360 XCTAssertNotEqualObjects(dict1, dict3); | 2360 XCTAssertNotEqualObjects(dict1, dict3); |
| 2361 | 2361 |
| 2362 // 4 extra pair; not equal | 2362 // 4 extra pair; not equal |
| 2363 XCTAssertNotEqualObjects(dict1, dict4); | 2363 XCTAssertNotEqualObjects(dict1, dict4); |
| 2364 | 2364 |
| 2365 [dict1 release]; | 2365 [dict1 release]; |
| 2366 [dict1prime release]; | 2366 [dict1prime release]; |
| 2367 [dict2 release]; | 2367 [dict2 release]; |
| 2368 [dict3 release]; | 2368 [dict3 release]; |
| 2369 [dict4 release]; | 2369 [dict4 release]; |
| 2370 } | 2370 } |
| 2371 | 2371 |
| 2372 - (void)testCopy { | 2372 - (void)testCopy { |
| 2373 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2373 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2374 const double kValues[] = { 600., 601., 602., 603. }; | 2374 const double kValues[] = { 600., 601., 602., 603. }; |
| 2375 GPBInt64DoubleDictionary *dict = | 2375 GPBInt64DoubleDictionary *dict = |
| 2376 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues | 2376 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues |
| 2377 forKeys:kKeys | 2377 forKeys:kKeys |
| 2378 count:GPBARRAYSIZE(kValues)]; | 2378 count:GPBARRAYSIZE(kValues)]; |
| 2379 XCTAssertNotNil(dict); | 2379 XCTAssertNotNil(dict); |
| 2380 | 2380 |
| 2381 GPBInt64DoubleDictionary *dict2 = [dict copy]; | 2381 GPBInt64DoubleDictionary *dict2 = [dict copy]; |
| 2382 XCTAssertNotNil(dict2); | 2382 XCTAssertNotNil(dict2); |
| 2383 | 2383 |
| 2384 // Should be new object but equal. | 2384 // Should be new object but equal. |
| 2385 XCTAssertNotEqual(dict, dict2); | 2385 XCTAssertNotEqual(dict, dict2); |
| 2386 XCTAssertEqualObjects(dict, dict2); | 2386 XCTAssertEqualObjects(dict, dict2); |
| 2387 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64DoubleDictionary class]]); | 2387 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64DoubleDictionary class]]); |
| 2388 | 2388 |
| 2389 [dict2 release]; | 2389 [dict2 release]; |
| 2390 [dict release]; | 2390 [dict release]; |
| 2391 } | 2391 } |
| 2392 | 2392 |
| 2393 - (void)testDictionaryFromDictionary { | 2393 - (void)testDictionaryFromDictionary { |
| 2394 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2394 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2395 const double kValues[] = { 600., 601., 602., 603. }; | 2395 const double kValues[] = { 600., 601., 602., 603. }; |
| 2396 GPBInt64DoubleDictionary *dict = | 2396 GPBInt64DoubleDictionary *dict = |
| 2397 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues | 2397 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues |
| 2398 forKeys:kKeys | 2398 forKeys:kKeys |
| 2399 count:GPBARRAYSIZE(kValues)]; | 2399 count:GPBARRAYSIZE(kValues)]; |
| 2400 XCTAssertNotNil(dict); | 2400 XCTAssertNotNil(dict); |
| 2401 | 2401 |
| 2402 GPBInt64DoubleDictionary *dict2 = | 2402 GPBInt64DoubleDictionary *dict2 = |
| 2403 [GPBInt64DoubleDictionary dictionaryWithDictionary:dict]; | 2403 [GPBInt64DoubleDictionary dictionaryWithDictionary:dict]; |
| 2404 XCTAssertNotNil(dict2); | 2404 XCTAssertNotNil(dict2); |
| 2405 | 2405 |
| 2406 // Should be new pointer, but equal objects. | 2406 // Should be new pointer, but equal objects. |
| 2407 XCTAssertNotEqual(dict, dict2); | 2407 XCTAssertNotEqual(dict, dict2); |
| 2408 XCTAssertEqualObjects(dict, dict2); | 2408 XCTAssertEqualObjects(dict, dict2); |
| 2409 [dict release]; | 2409 [dict release]; |
| 2410 } | 2410 } |
| 2411 | 2411 |
| 2412 - (void)testAdds { | 2412 - (void)testAdds { |
| 2413 GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionary]; | 2413 GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionary]; |
| 2414 XCTAssertNotNil(dict); | 2414 XCTAssertNotNil(dict); |
| 2415 | 2415 |
| 2416 XCTAssertEqual(dict.count, 0U); | 2416 XCTAssertEqual(dict.count, 0U); |
| 2417 [dict setValue:600. forKey:21LL]; | 2417 [dict setDouble:600. forKey:21LL]; |
| 2418 XCTAssertEqual(dict.count, 1U); | 2418 XCTAssertEqual(dict.count, 1U); |
| 2419 | 2419 |
| 2420 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 2420 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 2421 const double kValues[] = { 601., 602., 603. }; | 2421 const double kValues[] = { 601., 602., 603. }; |
| 2422 GPBInt64DoubleDictionary *dict2 = | 2422 GPBInt64DoubleDictionary *dict2 = |
| 2423 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues | 2423 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues |
| 2424 forKeys:kKeys | 2424 forKeys:kKeys |
| 2425 count:GPBARRAYSIZE(kValues)]; | 2425 count:GPBARRAYSIZE(kValues)]; |
| 2426 XCTAssertNotNil(dict2); | 2426 XCTAssertNotNil(dict2); |
| 2427 [dict addEntriesFromDictionary:dict2]; | 2427 [dict addEntriesFromDictionary:dict2]; |
| 2428 XCTAssertEqual(dict.count, 4U); | 2428 XCTAssertEqual(dict.count, 4U); |
| 2429 | 2429 |
| 2430 double value; | 2430 double value; |
| 2431 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2431 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2432 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2432 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2433 XCTAssertEqual(value, 600.); | 2433 XCTAssertEqual(value, 600.); |
| 2434 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2434 XCTAssertTrue([dict getDouble:NULL forKey:22LL]); |
| 2435 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2435 XCTAssertTrue([dict getDouble:&value forKey:22LL]); |
| 2436 XCTAssertEqual(value, 601.); | 2436 XCTAssertEqual(value, 601.); |
| 2437 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2437 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2438 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2438 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2439 XCTAssertEqual(value, 602.); | 2439 XCTAssertEqual(value, 602.); |
| 2440 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2440 XCTAssertTrue([dict getDouble:NULL forKey:24LL]); |
| 2441 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2441 XCTAssertTrue([dict getDouble:&value forKey:24LL]); |
| 2442 XCTAssertEqual(value, 603.); | 2442 XCTAssertEqual(value, 603.); |
| 2443 [dict2 release]; | 2443 [dict2 release]; |
| 2444 } | 2444 } |
| 2445 | 2445 |
| 2446 - (void)testRemove { | 2446 - (void)testRemove { |
| 2447 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2447 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2448 const double kValues[] = { 600., 601., 602., 603. }; | 2448 const double kValues[] = { 600., 601., 602., 603. }; |
| 2449 GPBInt64DoubleDictionary *dict = | 2449 GPBInt64DoubleDictionary *dict = |
| 2450 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues | 2450 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues |
| 2451 forKeys:kKeys | 2451 forKeys:kKeys |
| 2452 count:GPBARRAYSIZE(kValues)]; | 2452 count:GPBARRAYSIZE(kValues)]; |
| 2453 XCTAssertNotNil(dict); | 2453 XCTAssertNotNil(dict); |
| 2454 XCTAssertEqual(dict.count, 4U); | 2454 XCTAssertEqual(dict.count, 4U); |
| 2455 | 2455 |
| 2456 [dict removeValueForKey:22LL]; | 2456 [dict removeDoubleForKey:22LL]; |
| 2457 XCTAssertEqual(dict.count, 3U); | 2457 XCTAssertEqual(dict.count, 3U); |
| 2458 double value; | 2458 double value; |
| 2459 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2459 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2460 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2460 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2461 XCTAssertEqual(value, 600.); | 2461 XCTAssertEqual(value, 600.); |
| 2462 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2462 XCTAssertFalse([dict getDouble:NULL forKey:22LL]); |
| 2463 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2463 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2464 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2464 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2465 XCTAssertEqual(value, 602.); | 2465 XCTAssertEqual(value, 602.); |
| 2466 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2466 XCTAssertTrue([dict getDouble:NULL forKey:24LL]); |
| 2467 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2467 XCTAssertTrue([dict getDouble:&value forKey:24LL]); |
| 2468 XCTAssertEqual(value, 603.); | 2468 XCTAssertEqual(value, 603.); |
| 2469 | 2469 |
| 2470 // Remove again does nothing. | 2470 // Remove again does nothing. |
| 2471 [dict removeValueForKey:22LL]; | 2471 [dict removeDoubleForKey:22LL]; |
| 2472 XCTAssertEqual(dict.count, 3U); | 2472 XCTAssertEqual(dict.count, 3U); |
| 2473 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2473 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2474 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2474 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2475 XCTAssertEqual(value, 600.); | 2475 XCTAssertEqual(value, 600.); |
| 2476 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2476 XCTAssertFalse([dict getDouble:NULL forKey:22LL]); |
| 2477 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2477 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2478 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2478 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2479 XCTAssertEqual(value, 602.); | 2479 XCTAssertEqual(value, 602.); |
| 2480 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2480 XCTAssertTrue([dict getDouble:NULL forKey:24LL]); |
| 2481 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2481 XCTAssertTrue([dict getDouble:&value forKey:24LL]); |
| 2482 XCTAssertEqual(value, 603.); | 2482 XCTAssertEqual(value, 603.); |
| 2483 | 2483 |
| 2484 [dict removeValueForKey:24LL]; | 2484 [dict removeDoubleForKey:24LL]; |
| 2485 XCTAssertEqual(dict.count, 2U); | 2485 XCTAssertEqual(dict.count, 2U); |
| 2486 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2486 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2487 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2487 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2488 XCTAssertEqual(value, 600.); | 2488 XCTAssertEqual(value, 600.); |
| 2489 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2489 XCTAssertFalse([dict getDouble:NULL forKey:22LL]); |
| 2490 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2490 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2491 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2491 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2492 XCTAssertEqual(value, 602.); | 2492 XCTAssertEqual(value, 602.); |
| 2493 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2493 XCTAssertFalse([dict getDouble:NULL forKey:24LL]); |
| 2494 | 2494 |
| 2495 [dict removeAll]; | 2495 [dict removeAll]; |
| 2496 XCTAssertEqual(dict.count, 0U); | 2496 XCTAssertEqual(dict.count, 0U); |
| 2497 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 2497 XCTAssertFalse([dict getDouble:NULL forKey:21LL]); |
| 2498 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2498 XCTAssertFalse([dict getDouble:NULL forKey:22LL]); |
| 2499 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 2499 XCTAssertFalse([dict getDouble:NULL forKey:23LL]); |
| 2500 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2500 XCTAssertFalse([dict getDouble:NULL forKey:24LL]); |
| 2501 [dict release]; | 2501 [dict release]; |
| 2502 } | 2502 } |
| 2503 | 2503 |
| 2504 - (void)testInplaceMutation { | 2504 - (void)testInplaceMutation { |
| 2505 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2505 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2506 const double kValues[] = { 600., 601., 602., 603. }; | 2506 const double kValues[] = { 600., 601., 602., 603. }; |
| 2507 GPBInt64DoubleDictionary *dict = | 2507 GPBInt64DoubleDictionary *dict = |
| 2508 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues | 2508 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues |
| 2509 forKeys:kKeys | 2509 forKeys:kKeys |
| 2510 count:GPBARRAYSIZE(kValues)]; | 2510 count:GPBARRAYSIZE(kValues)]; |
| 2511 XCTAssertNotNil(dict); | 2511 XCTAssertNotNil(dict); |
| 2512 XCTAssertEqual(dict.count, 4U); | 2512 XCTAssertEqual(dict.count, 4U); |
| 2513 double value; | 2513 double value; |
| 2514 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2514 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2515 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2515 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2516 XCTAssertEqual(value, 600.); | 2516 XCTAssertEqual(value, 600.); |
| 2517 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2517 XCTAssertTrue([dict getDouble:NULL forKey:22LL]); |
| 2518 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2518 XCTAssertTrue([dict getDouble:&value forKey:22LL]); |
| 2519 XCTAssertEqual(value, 601.); | 2519 XCTAssertEqual(value, 601.); |
| 2520 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2520 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2521 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2521 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2522 XCTAssertEqual(value, 602.); | 2522 XCTAssertEqual(value, 602.); |
| 2523 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2523 XCTAssertTrue([dict getDouble:NULL forKey:24LL]); |
| 2524 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2524 XCTAssertTrue([dict getDouble:&value forKey:24LL]); |
| 2525 XCTAssertEqual(value, 603.); | 2525 XCTAssertEqual(value, 603.); |
| 2526 | 2526 |
| 2527 [dict setValue:603. forKey:21LL]; | 2527 [dict setDouble:603. forKey:21LL]; |
| 2528 XCTAssertEqual(dict.count, 4U); | 2528 XCTAssertEqual(dict.count, 4U); |
| 2529 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2529 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2530 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2530 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2531 XCTAssertEqual(value, 603.); | 2531 XCTAssertEqual(value, 603.); |
| 2532 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2532 XCTAssertTrue([dict getDouble:NULL forKey:22LL]); |
| 2533 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2533 XCTAssertTrue([dict getDouble:&value forKey:22LL]); |
| 2534 XCTAssertEqual(value, 601.); | 2534 XCTAssertEqual(value, 601.); |
| 2535 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2535 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2536 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2536 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2537 XCTAssertEqual(value, 602.); | 2537 XCTAssertEqual(value, 602.); |
| 2538 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2538 XCTAssertTrue([dict getDouble:NULL forKey:24LL]); |
| 2539 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2539 XCTAssertTrue([dict getDouble:&value forKey:24LL]); |
| 2540 XCTAssertEqual(value, 603.); | 2540 XCTAssertEqual(value, 603.); |
| 2541 | 2541 |
| 2542 [dict setValue:601. forKey:24LL]; | 2542 [dict setDouble:601. forKey:24LL]; |
| 2543 XCTAssertEqual(dict.count, 4U); | 2543 XCTAssertEqual(dict.count, 4U); |
| 2544 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2544 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2545 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2545 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2546 XCTAssertEqual(value, 603.); | 2546 XCTAssertEqual(value, 603.); |
| 2547 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2547 XCTAssertTrue([dict getDouble:NULL forKey:22LL]); |
| 2548 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2548 XCTAssertTrue([dict getDouble:&value forKey:22LL]); |
| 2549 XCTAssertEqual(value, 601.); | 2549 XCTAssertEqual(value, 601.); |
| 2550 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2550 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2551 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2551 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2552 XCTAssertEqual(value, 602.); | 2552 XCTAssertEqual(value, 602.); |
| 2553 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2553 XCTAssertTrue([dict getDouble:NULL forKey:24LL]); |
| 2554 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2554 XCTAssertTrue([dict getDouble:&value forKey:24LL]); |
| 2555 XCTAssertEqual(value, 601.); | 2555 XCTAssertEqual(value, 601.); |
| 2556 | 2556 |
| 2557 const int64_t kKeys2[] = { 22LL, 23LL }; | 2557 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 2558 const double kValues2[] = { 602., 600. }; | 2558 const double kValues2[] = { 602., 600. }; |
| 2559 GPBInt64DoubleDictionary *dict2 = | 2559 GPBInt64DoubleDictionary *dict2 = |
| 2560 [[GPBInt64DoubleDictionary alloc] initWithValues:kValues2 | 2560 [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues2 |
| 2561 forKeys:kKeys2 | 2561 forKeys:kKeys2 |
| 2562 count:GPBARRAYSIZE(kValues2)]; | 2562 count:GPBARRAYSIZE(kValues2)]; |
| 2563 XCTAssertNotNil(dict2); | 2563 XCTAssertNotNil(dict2); |
| 2564 [dict addEntriesFromDictionary:dict2]; | 2564 [dict addEntriesFromDictionary:dict2]; |
| 2565 XCTAssertEqual(dict.count, 4U); | 2565 XCTAssertEqual(dict.count, 4U); |
| 2566 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2566 XCTAssertTrue([dict getDouble:NULL forKey:21LL]); |
| 2567 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2567 XCTAssertTrue([dict getDouble:&value forKey:21LL]); |
| 2568 XCTAssertEqual(value, 603.); | 2568 XCTAssertEqual(value, 603.); |
| 2569 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2569 XCTAssertTrue([dict getDouble:NULL forKey:22LL]); |
| 2570 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2570 XCTAssertTrue([dict getDouble:&value forKey:22LL]); |
| 2571 XCTAssertEqual(value, 602.); | 2571 XCTAssertEqual(value, 602.); |
| 2572 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2572 XCTAssertTrue([dict getDouble:NULL forKey:23LL]); |
| 2573 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2573 XCTAssertTrue([dict getDouble:&value forKey:23LL]); |
| 2574 XCTAssertEqual(value, 600.); | 2574 XCTAssertEqual(value, 600.); |
| 2575 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2575 XCTAssertTrue([dict getDouble:NULL forKey:24LL]); |
| 2576 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2576 XCTAssertTrue([dict getDouble:&value forKey:24LL]); |
| 2577 XCTAssertEqual(value, 601.); | 2577 XCTAssertEqual(value, 601.); |
| 2578 | 2578 |
| 2579 [dict2 release]; | 2579 [dict2 release]; |
| 2580 [dict release]; | 2580 [dict release]; |
| 2581 } | 2581 } |
| 2582 | 2582 |
| 2583 @end | 2583 @end |
| 2584 | 2584 |
| 2585 #pragma mark - Int64 -> Enum | 2585 #pragma mark - Int64 -> Enum |
| 2586 | 2586 |
| 2587 @interface GPBInt64EnumDictionaryTests : XCTestCase | 2587 @interface GPBInt64EnumDictionaryTests : XCTestCase |
| 2588 @end | 2588 @end |
| 2589 | 2589 |
| 2590 @implementation GPBInt64EnumDictionaryTests | 2590 @implementation GPBInt64EnumDictionaryTests |
| 2591 | 2591 |
| 2592 - (void)testEmpty { | 2592 - (void)testEmpty { |
| 2593 GPBInt64EnumDictionary *dict = [[GPBInt64EnumDictionary alloc] init]; | 2593 GPBInt64EnumDictionary *dict = [[GPBInt64EnumDictionary alloc] init]; |
| 2594 XCTAssertNotNil(dict); | 2594 XCTAssertNotNil(dict); |
| 2595 XCTAssertEqual(dict.count, 0U); | 2595 XCTAssertEqual(dict.count, 0U); |
| 2596 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 2596 XCTAssertFalse([dict getEnum:NULL forKey:21LL]); |
| 2597 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 2597 [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *st
op) { |
| 2598 #pragma unused(aKey, aValue, stop) | 2598 #pragma unused(aKey, aValue, stop) |
| 2599 XCTFail(@"Shouldn't get here!"); | 2599 XCTFail(@"Shouldn't get here!"); |
| 2600 }]; | 2600 }]; |
| 2601 [dict release]; | 2601 [dict release]; |
| 2602 } | 2602 } |
| 2603 | 2603 |
| 2604 - (void)testOne { | 2604 - (void)testOne { |
| 2605 GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionaryWithValue:700
forKey:21LL]; | 2605 GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionaryWithEnum:700
forKey:21LL]; |
| 2606 XCTAssertNotNil(dict); | 2606 XCTAssertNotNil(dict); |
| 2607 XCTAssertEqual(dict.count, 1U); | 2607 XCTAssertEqual(dict.count, 1U); |
| 2608 int32_t value; | 2608 int32_t value; |
| 2609 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2609 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2610 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2610 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2611 XCTAssertEqual(value, 700); | 2611 XCTAssertEqual(value, 700); |
| 2612 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2612 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 2613 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 2613 [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *st
op) { |
| 2614 XCTAssertEqual(aKey, 21LL); | 2614 XCTAssertEqual(aKey, 21LL); |
| 2615 XCTAssertEqual(aValue, 700); | 2615 XCTAssertEqual(aValue, 700); |
| 2616 XCTAssertNotEqual(stop, NULL); | 2616 XCTAssertNotEqual(stop, NULL); |
| 2617 }]; | 2617 }]; |
| 2618 } | 2618 } |
| 2619 | 2619 |
| 2620 - (void)testBasics { | 2620 - (void)testBasics { |
| 2621 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 2621 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 2622 const int32_t kValues[] = { 700, 701, 702 }; | 2622 const int32_t kValues[] = { 700, 701, 702 }; |
| 2623 GPBInt64EnumDictionary *dict = | 2623 GPBInt64EnumDictionary *dict = |
| 2624 [[GPBInt64EnumDictionary alloc] initWithValues:kValues | 2624 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues |
| 2625 forKeys:kKeys | 2625 forKeys:kKeys |
| 2626 count:GPBARRAYSIZE(kValues)]; | 2626 count:GPBARRAYSIZE(kValues)]; |
| 2627 XCTAssertNotNil(dict); | 2627 XCTAssertNotNil(dict); |
| 2628 XCTAssertEqual(dict.count, 3U); | 2628 XCTAssertEqual(dict.count, 3U); |
| 2629 int32_t value; | 2629 int32_t value; |
| 2630 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2630 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2631 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2631 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2632 XCTAssertEqual(value, 700); | 2632 XCTAssertEqual(value, 700); |
| 2633 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2633 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 2634 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2634 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 2635 XCTAssertEqual(value, 701); | 2635 XCTAssertEqual(value, 701); |
| 2636 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2636 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2637 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2637 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2638 XCTAssertEqual(value, 702); | 2638 XCTAssertEqual(value, 702); |
| 2639 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2639 XCTAssertFalse([dict getEnum:NULL forKey:24LL]); |
| 2640 | 2640 |
| 2641 __block NSUInteger idx = 0; | 2641 __block NSUInteger idx = 0; |
| 2642 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 2642 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 2643 int32_t *seenValues = malloc(3 * sizeof(int32_t)); | 2643 int32_t *seenValues = malloc(3 * sizeof(int32_t)); |
| 2644 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 2644 [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *st
op) { |
| 2645 XCTAssertLessThan(idx, 3U); | 2645 XCTAssertLessThan(idx, 3U); |
| 2646 seenKeys[idx] = aKey; | 2646 seenKeys[idx] = aKey; |
| 2647 seenValues[idx] = aValue; | 2647 seenValues[idx] = aValue; |
| 2648 XCTAssertNotEqual(stop, NULL); | 2648 XCTAssertNotEqual(stop, NULL); |
| 2649 ++idx; | 2649 ++idx; |
| 2650 }]; | 2650 }]; |
| 2651 for (int i = 0; i < 3; ++i) { | 2651 for (int i = 0; i < 3; ++i) { |
| 2652 BOOL foundKey = NO; | 2652 BOOL foundKey = NO; |
| 2653 for (int j = 0; (j < 3) && !foundKey; ++j) { | 2653 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 2654 if (kKeys[i] == seenKeys[j]) { | 2654 if (kKeys[i] == seenKeys[j]) { |
| 2655 foundKey = YES; | 2655 foundKey = YES; |
| 2656 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); | 2656 XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j); |
| 2657 } | 2657 } |
| 2658 } | 2658 } |
| 2659 XCTAssertTrue(foundKey, @"i = %d", i); | 2659 XCTAssertTrue(foundKey, @"i = %d", i); |
| 2660 } | 2660 } |
| 2661 free(seenKeys); | 2661 free(seenKeys); |
| 2662 free(seenValues); | 2662 free(seenValues); |
| 2663 | 2663 |
| 2664 // Stopping the enumeration. | 2664 // Stopping the enumeration. |
| 2665 idx = 0; | 2665 idx = 0; |
| 2666 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 2666 [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *st
op) { |
| 2667 #pragma unused(aKey, aValue) | 2667 #pragma unused(aKey, aValue) |
| 2668 if (idx == 1) *stop = YES; | 2668 if (idx == 1) *stop = YES; |
| 2669 XCTAssertNotEqual(idx, 2U); | 2669 XCTAssertNotEqual(idx, 2U); |
| 2670 ++idx; | 2670 ++idx; |
| 2671 }]; | 2671 }]; |
| 2672 [dict release]; | 2672 [dict release]; |
| 2673 } | 2673 } |
| 2674 | 2674 |
| 2675 - (void)testEquality { | 2675 - (void)testEquality { |
| 2676 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 2676 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2677 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 2677 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 2678 const int32_t kValues1[] = { 700, 701, 702 }; | 2678 const int32_t kValues1[] = { 700, 701, 702 }; |
| 2679 const int32_t kValues2[] = { 700, 703, 702 }; | 2679 const int32_t kValues2[] = { 700, 703, 702 }; |
| 2680 const int32_t kValues3[] = { 700, 701, 702, 703 }; | 2680 const int32_t kValues3[] = { 700, 701, 702, 703 }; |
| 2681 GPBInt64EnumDictionary *dict1 = | 2681 GPBInt64EnumDictionary *dict1 = |
| 2682 [[GPBInt64EnumDictionary alloc] initWithValues:kValues1 | 2682 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1 |
| 2683 forKeys:kKeys1 | 2683 forKeys:kKeys1 |
| 2684 count:GPBARRAYSIZE(kValues1)]; | 2684 count:GPBARRAYSIZE(kValues1)]; |
| 2685 XCTAssertNotNil(dict1); | 2685 XCTAssertNotNil(dict1); |
| 2686 GPBInt64EnumDictionary *dict1prime = | 2686 GPBInt64EnumDictionary *dict1prime = |
| 2687 [[GPBInt64EnumDictionary alloc] initWithValues:kValues1 | 2687 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1 |
| 2688 forKeys:kKeys1 | 2688 forKeys:kKeys1 |
| 2689 count:GPBARRAYSIZE(kValues1)]; | 2689 count:GPBARRAYSIZE(kValues1)]; |
| 2690 XCTAssertNotNil(dict1prime); | 2690 XCTAssertNotNil(dict1prime); |
| 2691 GPBInt64EnumDictionary *dict2 = | 2691 GPBInt64EnumDictionary *dict2 = |
| 2692 [[GPBInt64EnumDictionary alloc] initWithValues:kValues2 | 2692 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues2 |
| 2693 forKeys:kKeys1 | 2693 forKeys:kKeys1 |
| 2694 count:GPBARRAYSIZE(kValues2)]; | 2694 count:GPBARRAYSIZE(kValues2)]; |
| 2695 XCTAssertNotNil(dict2); | 2695 XCTAssertNotNil(dict2); |
| 2696 GPBInt64EnumDictionary *dict3 = | 2696 GPBInt64EnumDictionary *dict3 = |
| 2697 [[GPBInt64EnumDictionary alloc] initWithValues:kValues1 | 2697 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1 |
| 2698 forKeys:kKeys2 | 2698 forKeys:kKeys2 |
| 2699 count:GPBARRAYSIZE(kValues1)]; | 2699 count:GPBARRAYSIZE(kValues1)]; |
| 2700 XCTAssertNotNil(dict3); | 2700 XCTAssertNotNil(dict3); |
| 2701 GPBInt64EnumDictionary *dict4 = | 2701 GPBInt64EnumDictionary *dict4 = |
| 2702 [[GPBInt64EnumDictionary alloc] initWithValues:kValues3 | 2702 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues3 |
| 2703 forKeys:kKeys1 | 2703 forKeys:kKeys1 |
| 2704 count:GPBARRAYSIZE(kValues3)]; | 2704 count:GPBARRAYSIZE(kValues3)]; |
| 2705 XCTAssertNotNil(dict4); | 2705 XCTAssertNotNil(dict4); |
| 2706 | 2706 |
| 2707 // 1/1Prime should be different objects, but equal. | 2707 // 1/1Prime should be different objects, but equal. |
| 2708 XCTAssertNotEqual(dict1, dict1prime); | 2708 XCTAssertNotEqual(dict1, dict1prime); |
| 2709 XCTAssertEqualObjects(dict1, dict1prime); | 2709 XCTAssertEqualObjects(dict1, dict1prime); |
| 2710 // Equal, so they must have same hash. | 2710 // Equal, so they must have same hash. |
| 2711 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 2711 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 2712 | 2712 |
| 2713 // 2 is same keys, different values; not equal. | 2713 // 2 is same keys, different values; not equal. |
| 2714 XCTAssertNotEqualObjects(dict1, dict2); | 2714 XCTAssertNotEqualObjects(dict1, dict2); |
| 2715 | 2715 |
| 2716 // 3 is different keys, same values; not equal. | 2716 // 3 is different keys, same values; not equal. |
| 2717 XCTAssertNotEqualObjects(dict1, dict3); | 2717 XCTAssertNotEqualObjects(dict1, dict3); |
| 2718 | 2718 |
| 2719 // 4 extra pair; not equal | 2719 // 4 extra pair; not equal |
| 2720 XCTAssertNotEqualObjects(dict1, dict4); | 2720 XCTAssertNotEqualObjects(dict1, dict4); |
| 2721 | 2721 |
| 2722 [dict1 release]; | 2722 [dict1 release]; |
| 2723 [dict1prime release]; | 2723 [dict1prime release]; |
| 2724 [dict2 release]; | 2724 [dict2 release]; |
| 2725 [dict3 release]; | 2725 [dict3 release]; |
| 2726 [dict4 release]; | 2726 [dict4 release]; |
| 2727 } | 2727 } |
| 2728 | 2728 |
| 2729 - (void)testCopy { | 2729 - (void)testCopy { |
| 2730 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2730 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2731 const int32_t kValues[] = { 700, 701, 702, 703 }; | 2731 const int32_t kValues[] = { 700, 701, 702, 703 }; |
| 2732 GPBInt64EnumDictionary *dict = | 2732 GPBInt64EnumDictionary *dict = |
| 2733 [[GPBInt64EnumDictionary alloc] initWithValues:kValues | 2733 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues |
| 2734 forKeys:kKeys | 2734 forKeys:kKeys |
| 2735 count:GPBARRAYSIZE(kValues)]; | 2735 count:GPBARRAYSIZE(kValues)]; |
| 2736 XCTAssertNotNil(dict); | 2736 XCTAssertNotNil(dict); |
| 2737 | 2737 |
| 2738 GPBInt64EnumDictionary *dict2 = [dict copy]; | 2738 GPBInt64EnumDictionary *dict2 = [dict copy]; |
| 2739 XCTAssertNotNil(dict2); | 2739 XCTAssertNotNil(dict2); |
| 2740 | 2740 |
| 2741 // Should be new object but equal. | 2741 // Should be new object but equal. |
| 2742 XCTAssertNotEqual(dict, dict2); | 2742 XCTAssertNotEqual(dict, dict2); |
| 2743 XCTAssertEqualObjects(dict, dict2); | 2743 XCTAssertEqualObjects(dict, dict2); |
| 2744 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64EnumDictionary class]]); | 2744 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64EnumDictionary class]]); |
| 2745 | 2745 |
| 2746 [dict2 release]; | 2746 [dict2 release]; |
| 2747 [dict release]; | 2747 [dict release]; |
| 2748 } | 2748 } |
| 2749 | 2749 |
| 2750 - (void)testDictionaryFromDictionary { | 2750 - (void)testDictionaryFromDictionary { |
| 2751 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2751 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2752 const int32_t kValues[] = { 700, 701, 702, 703 }; | 2752 const int32_t kValues[] = { 700, 701, 702, 703 }; |
| 2753 GPBInt64EnumDictionary *dict = | 2753 GPBInt64EnumDictionary *dict = |
| 2754 [[GPBInt64EnumDictionary alloc] initWithValues:kValues | 2754 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues |
| 2755 forKeys:kKeys | 2755 forKeys:kKeys |
| 2756 count:GPBARRAYSIZE(kValues)]; | 2756 count:GPBARRAYSIZE(kValues)]; |
| 2757 XCTAssertNotNil(dict); | 2757 XCTAssertNotNil(dict); |
| 2758 | 2758 |
| 2759 GPBInt64EnumDictionary *dict2 = | 2759 GPBInt64EnumDictionary *dict2 = |
| 2760 [GPBInt64EnumDictionary dictionaryWithDictionary:dict]; | 2760 [GPBInt64EnumDictionary dictionaryWithDictionary:dict]; |
| 2761 XCTAssertNotNil(dict2); | 2761 XCTAssertNotNil(dict2); |
| 2762 | 2762 |
| 2763 // Should be new pointer, but equal objects. | 2763 // Should be new pointer, but equal objects. |
| 2764 XCTAssertNotEqual(dict, dict2); | 2764 XCTAssertNotEqual(dict, dict2); |
| 2765 XCTAssertEqualObjects(dict, dict2); | 2765 XCTAssertEqualObjects(dict, dict2); |
| 2766 [dict release]; | 2766 [dict release]; |
| 2767 } | 2767 } |
| 2768 | 2768 |
| 2769 - (void)testAdds { | 2769 - (void)testAdds { |
| 2770 GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionary]; | 2770 GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionary]; |
| 2771 XCTAssertNotNil(dict); | 2771 XCTAssertNotNil(dict); |
| 2772 | 2772 |
| 2773 XCTAssertEqual(dict.count, 0U); | 2773 XCTAssertEqual(dict.count, 0U); |
| 2774 [dict setValue:700 forKey:21LL]; | 2774 [dict setEnum:700 forKey:21LL]; |
| 2775 XCTAssertEqual(dict.count, 1U); | 2775 XCTAssertEqual(dict.count, 1U); |
| 2776 | 2776 |
| 2777 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 2777 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 2778 const int32_t kValues[] = { 701, 702, 703 }; | 2778 const int32_t kValues[] = { 701, 702, 703 }; |
| 2779 GPBInt64EnumDictionary *dict2 = | 2779 GPBInt64EnumDictionary *dict2 = |
| 2780 [[GPBInt64EnumDictionary alloc] initWithValues:kValues | 2780 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues |
| 2781 forKeys:kKeys | 2781 forKeys:kKeys |
| 2782 count:GPBARRAYSIZE(kValues)]; | 2782 count:GPBARRAYSIZE(kValues)]; |
| 2783 XCTAssertNotNil(dict2); | 2783 XCTAssertNotNil(dict2); |
| 2784 [dict addRawEntriesFromDictionary:dict2]; | 2784 [dict addRawEntriesFromDictionary:dict2]; |
| 2785 XCTAssertEqual(dict.count, 4U); | 2785 XCTAssertEqual(dict.count, 4U); |
| 2786 | 2786 |
| 2787 int32_t value; | 2787 int32_t value; |
| 2788 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2788 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2789 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2789 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2790 XCTAssertEqual(value, 700); | 2790 XCTAssertEqual(value, 700); |
| 2791 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2791 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 2792 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2792 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 2793 XCTAssertEqual(value, 701); | 2793 XCTAssertEqual(value, 701); |
| 2794 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2794 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2795 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2795 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2796 XCTAssertEqual(value, 702); | 2796 XCTAssertEqual(value, 702); |
| 2797 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2797 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 2798 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2798 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 2799 XCTAssertEqual(value, 703); | 2799 XCTAssertEqual(value, 703); |
| 2800 [dict2 release]; | 2800 [dict2 release]; |
| 2801 } | 2801 } |
| 2802 | 2802 |
| 2803 - (void)testRemove { | 2803 - (void)testRemove { |
| 2804 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2804 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2805 const int32_t kValues[] = { 700, 701, 702, 703 }; | 2805 const int32_t kValues[] = { 700, 701, 702, 703 }; |
| 2806 GPBInt64EnumDictionary *dict = | 2806 GPBInt64EnumDictionary *dict = |
| 2807 [[GPBInt64EnumDictionary alloc] initWithValues:kValues | 2807 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues |
| 2808 forKeys:kKeys | 2808 forKeys:kKeys |
| 2809 count:GPBARRAYSIZE(kValues)]; | 2809 count:GPBARRAYSIZE(kValues)]; |
| 2810 XCTAssertNotNil(dict); | 2810 XCTAssertNotNil(dict); |
| 2811 XCTAssertEqual(dict.count, 4U); | 2811 XCTAssertEqual(dict.count, 4U); |
| 2812 | 2812 |
| 2813 [dict removeValueForKey:22LL]; | 2813 [dict removeEnumForKey:22LL]; |
| 2814 XCTAssertEqual(dict.count, 3U); | 2814 XCTAssertEqual(dict.count, 3U); |
| 2815 int32_t value; | 2815 int32_t value; |
| 2816 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2816 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2817 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2817 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2818 XCTAssertEqual(value, 700); | 2818 XCTAssertEqual(value, 700); |
| 2819 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2819 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 2820 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2820 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2821 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2821 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2822 XCTAssertEqual(value, 702); | 2822 XCTAssertEqual(value, 702); |
| 2823 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2823 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 2824 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2824 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 2825 XCTAssertEqual(value, 703); | 2825 XCTAssertEqual(value, 703); |
| 2826 | 2826 |
| 2827 // Remove again does nothing. | 2827 // Remove again does nothing. |
| 2828 [dict removeValueForKey:22LL]; | 2828 [dict removeEnumForKey:22LL]; |
| 2829 XCTAssertEqual(dict.count, 3U); | 2829 XCTAssertEqual(dict.count, 3U); |
| 2830 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2830 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2831 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2831 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2832 XCTAssertEqual(value, 700); | 2832 XCTAssertEqual(value, 700); |
| 2833 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2833 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 2834 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2834 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2835 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2835 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2836 XCTAssertEqual(value, 702); | 2836 XCTAssertEqual(value, 702); |
| 2837 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2837 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 2838 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2838 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 2839 XCTAssertEqual(value, 703); | 2839 XCTAssertEqual(value, 703); |
| 2840 | 2840 |
| 2841 [dict removeValueForKey:24LL]; | 2841 [dict removeEnumForKey:24LL]; |
| 2842 XCTAssertEqual(dict.count, 2U); | 2842 XCTAssertEqual(dict.count, 2U); |
| 2843 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2843 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2844 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2844 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2845 XCTAssertEqual(value, 700); | 2845 XCTAssertEqual(value, 700); |
| 2846 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2846 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 2847 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2847 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2848 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2848 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2849 XCTAssertEqual(value, 702); | 2849 XCTAssertEqual(value, 702); |
| 2850 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2850 XCTAssertFalse([dict getEnum:NULL forKey:24LL]); |
| 2851 | 2851 |
| 2852 [dict removeAll]; | 2852 [dict removeAll]; |
| 2853 XCTAssertEqual(dict.count, 0U); | 2853 XCTAssertEqual(dict.count, 0U); |
| 2854 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 2854 XCTAssertFalse([dict getEnum:NULL forKey:21LL]); |
| 2855 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 2855 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 2856 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 2856 XCTAssertFalse([dict getEnum:NULL forKey:23LL]); |
| 2857 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 2857 XCTAssertFalse([dict getEnum:NULL forKey:24LL]); |
| 2858 [dict release]; | 2858 [dict release]; |
| 2859 } | 2859 } |
| 2860 | 2860 |
| 2861 - (void)testInplaceMutation { | 2861 - (void)testInplaceMutation { |
| 2862 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 2862 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 2863 const int32_t kValues[] = { 700, 701, 702, 703 }; | 2863 const int32_t kValues[] = { 700, 701, 702, 703 }; |
| 2864 GPBInt64EnumDictionary *dict = | 2864 GPBInt64EnumDictionary *dict = |
| 2865 [[GPBInt64EnumDictionary alloc] initWithValues:kValues | 2865 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues |
| 2866 forKeys:kKeys | 2866 forKeys:kKeys |
| 2867 count:GPBARRAYSIZE(kValues)]; | 2867 count:GPBARRAYSIZE(kValues)]; |
| 2868 XCTAssertNotNil(dict); | 2868 XCTAssertNotNil(dict); |
| 2869 XCTAssertEqual(dict.count, 4U); | 2869 XCTAssertEqual(dict.count, 4U); |
| 2870 int32_t value; | 2870 int32_t value; |
| 2871 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2871 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2872 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2872 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2873 XCTAssertEqual(value, 700); | 2873 XCTAssertEqual(value, 700); |
| 2874 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2874 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 2875 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2875 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 2876 XCTAssertEqual(value, 701); | 2876 XCTAssertEqual(value, 701); |
| 2877 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2877 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2878 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2878 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2879 XCTAssertEqual(value, 702); | 2879 XCTAssertEqual(value, 702); |
| 2880 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2880 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 2881 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2881 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 2882 XCTAssertEqual(value, 703); | 2882 XCTAssertEqual(value, 703); |
| 2883 | 2883 |
| 2884 [dict setValue:703 forKey:21LL]; | 2884 [dict setEnum:703 forKey:21LL]; |
| 2885 XCTAssertEqual(dict.count, 4U); | 2885 XCTAssertEqual(dict.count, 4U); |
| 2886 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2886 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2887 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2887 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2888 XCTAssertEqual(value, 703); | 2888 XCTAssertEqual(value, 703); |
| 2889 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2889 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 2890 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2890 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 2891 XCTAssertEqual(value, 701); | 2891 XCTAssertEqual(value, 701); |
| 2892 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2892 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2893 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2893 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2894 XCTAssertEqual(value, 702); | 2894 XCTAssertEqual(value, 702); |
| 2895 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2895 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 2896 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2896 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 2897 XCTAssertEqual(value, 703); | 2897 XCTAssertEqual(value, 703); |
| 2898 | 2898 |
| 2899 [dict setValue:701 forKey:24LL]; | 2899 [dict setEnum:701 forKey:24LL]; |
| 2900 XCTAssertEqual(dict.count, 4U); | 2900 XCTAssertEqual(dict.count, 4U); |
| 2901 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2901 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2902 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2902 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2903 XCTAssertEqual(value, 703); | 2903 XCTAssertEqual(value, 703); |
| 2904 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2904 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 2905 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2905 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 2906 XCTAssertEqual(value, 701); | 2906 XCTAssertEqual(value, 701); |
| 2907 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2907 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2908 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2908 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2909 XCTAssertEqual(value, 702); | 2909 XCTAssertEqual(value, 702); |
| 2910 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2910 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 2911 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2911 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 2912 XCTAssertEqual(value, 701); | 2912 XCTAssertEqual(value, 701); |
| 2913 | 2913 |
| 2914 const int64_t kKeys2[] = { 22LL, 23LL }; | 2914 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 2915 const int32_t kValues2[] = { 702, 700 }; | 2915 const int32_t kValues2[] = { 702, 700 }; |
| 2916 GPBInt64EnumDictionary *dict2 = | 2916 GPBInt64EnumDictionary *dict2 = |
| 2917 [[GPBInt64EnumDictionary alloc] initWithValues:kValues2 | 2917 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues2 |
| 2918 forKeys:kKeys2 | 2918 forKeys:kKeys2 |
| 2919 count:GPBARRAYSIZE(kValues2)]; | 2919 count:GPBARRAYSIZE(kValues2)]; |
| 2920 XCTAssertNotNil(dict2); | 2920 XCTAssertNotNil(dict2); |
| 2921 [dict addRawEntriesFromDictionary:dict2]; | 2921 [dict addRawEntriesFromDictionary:dict2]; |
| 2922 XCTAssertEqual(dict.count, 4U); | 2922 XCTAssertEqual(dict.count, 4U); |
| 2923 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 2923 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 2924 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 2924 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 2925 XCTAssertEqual(value, 703); | 2925 XCTAssertEqual(value, 703); |
| 2926 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2926 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 2927 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2927 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 2928 XCTAssertEqual(value, 702); | 2928 XCTAssertEqual(value, 702); |
| 2929 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 2929 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 2930 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 2930 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 2931 XCTAssertEqual(value, 700); | 2931 XCTAssertEqual(value, 700); |
| 2932 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 2932 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 2933 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 2933 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 2934 XCTAssertEqual(value, 701); | 2934 XCTAssertEqual(value, 701); |
| 2935 | 2935 |
| 2936 [dict2 release]; | 2936 [dict2 release]; |
| 2937 [dict release]; | 2937 [dict release]; |
| 2938 } | 2938 } |
| 2939 | 2939 |
| 2940 @end | 2940 @end |
| 2941 | 2941 |
| 2942 #pragma mark - Int64 -> Enum (Unknown Enums) | 2942 #pragma mark - Int64 -> Enum (Unknown Enums) |
| 2943 | 2943 |
| 2944 @interface GPBInt64EnumDictionaryUnknownEnumTests : XCTestCase | 2944 @interface GPBInt64EnumDictionaryUnknownEnumTests : XCTestCase |
| 2945 @end | 2945 @end |
| 2946 | 2946 |
| 2947 @implementation GPBInt64EnumDictionaryUnknownEnumTests | 2947 @implementation GPBInt64EnumDictionaryUnknownEnumTests |
| 2948 | 2948 |
| 2949 - (void)testRawBasics { | 2949 - (void)testRawBasics { |
| 2950 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 2950 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 2951 const int32_t kValues[] = { 700, 801, 702 }; | 2951 const int32_t kValues[] = { 700, 801, 702 }; |
| 2952 GPBInt64EnumDictionary *dict = | 2952 GPBInt64EnumDictionary *dict = |
| 2953 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue | 2953 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue |
| 2954 rawValues:kValues | 2954 rawValues:kValues |
| 2955 forKeys:kKeys | 2955 forKeys:kKeys |
| 2956 count:GPBARRAYSIZE(kV
alues)]; | 2956 count:GPBARRAYSIZE(kV
alues)]; |
| 2957 XCTAssertNotNil(dict); | 2957 XCTAssertNotNil(dict); |
| 2958 XCTAssertEqual(dict.count, 3U); | 2958 XCTAssertEqual(dict.count, 3U); |
| 2959 XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer co
mparison | 2959 XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer co
mparison |
| 2960 int32_t value; | 2960 int32_t value; |
| 2961 XCTAssertTrue([dict valueForKey:21LL rawValue:NULL]); | 2961 XCTAssertTrue([dict getRawValue:NULL forKey:21LL]); |
| 2962 XCTAssertTrue([dict valueForKey:21LL rawValue:&value]); | 2962 XCTAssertTrue([dict getRawValue:&value forKey:21LL]); |
| 2963 XCTAssertEqual(value, 700); | 2963 XCTAssertEqual(value, 700); |
| 2964 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 2964 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 2965 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 2965 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 2966 XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue); | 2966 XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue); |
| 2967 XCTAssertTrue([dict valueForKey:22LL rawValue:NULL]); | 2967 XCTAssertTrue([dict getRawValue:NULL forKey:22LL]); |
| 2968 XCTAssertTrue([dict valueForKey:22LL rawValue:&value]); | 2968 XCTAssertTrue([dict getRawValue:&value forKey:22LL]); |
| 2969 XCTAssertEqual(value, 801); | 2969 XCTAssertEqual(value, 801); |
| 2970 XCTAssertTrue([dict valueForKey:23LL rawValue:NULL]); | 2970 XCTAssertTrue([dict getRawValue:NULL forKey:23LL]); |
| 2971 XCTAssertTrue([dict valueForKey:23LL rawValue:&value]); | 2971 XCTAssertTrue([dict getRawValue:&value forKey:23LL]); |
| 2972 XCTAssertEqual(value, 702); | 2972 XCTAssertEqual(value, 702); |
| 2973 XCTAssertFalse([dict valueForKey:24LL rawValue:NULL]); | 2973 XCTAssertFalse([dict getRawValue:NULL forKey:24LL]); |
| 2974 | 2974 |
| 2975 __block NSUInteger idx = 0; | 2975 __block NSUInteger idx = 0; |
| 2976 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 2976 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 2977 int32_t *seenValues = malloc(3 * sizeof(int32_t)); | 2977 int32_t *seenValues = malloc(3 * sizeof(int32_t)); |
| 2978 [dict enumerateKeysAndValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *s
top) { | 2978 [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *st
op) { |
| 2979 XCTAssertLessThan(idx, 3U); | 2979 XCTAssertLessThan(idx, 3U); |
| 2980 seenKeys[idx] = aKey; | 2980 seenKeys[idx] = aKey; |
| 2981 seenValues[idx] = aValue; | 2981 seenValues[idx] = aValue; |
| 2982 XCTAssertNotEqual(stop, NULL); | 2982 XCTAssertNotEqual(stop, NULL); |
| 2983 ++idx; | 2983 ++idx; |
| 2984 }]; | 2984 }]; |
| 2985 for (int i = 0; i < 3; ++i) { | 2985 for (int i = 0; i < 3; ++i) { |
| 2986 BOOL foundKey = NO; | 2986 BOOL foundKey = NO; |
| 2987 for (int j = 0; (j < 3) && !foundKey; ++j) { | 2987 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 2988 if (kKeys[i] == seenKeys[j]) { | 2988 if (kKeys[i] == seenKeys[j]) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3129 XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer compari
son | 3129 XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer compari
son |
| 3130 [dict release]; | 3130 [dict release]; |
| 3131 } | 3131 } |
| 3132 | 3132 |
| 3133 - (void)testUnknownAdds { | 3133 - (void)testUnknownAdds { |
| 3134 GPBInt64EnumDictionary *dict = | 3134 GPBInt64EnumDictionary *dict = |
| 3135 [GPBInt64EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValid
Value]; | 3135 [GPBInt64EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValid
Value]; |
| 3136 XCTAssertNotNil(dict); | 3136 XCTAssertNotNil(dict); |
| 3137 | 3137 |
| 3138 XCTAssertEqual(dict.count, 0U); | 3138 XCTAssertEqual(dict.count, 0U); |
| 3139 XCTAssertThrowsSpecificNamed([dict setValue:801 forKey:22LL], // Unknown | 3139 XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:22LL], // Unknown |
| 3140 NSException, NSInvalidArgumentException); | 3140 NSException, NSInvalidArgumentException); |
| 3141 XCTAssertEqual(dict.count, 0U); | 3141 XCTAssertEqual(dict.count, 0U); |
| 3142 [dict setRawValue:801 forKey:22LL]; // Unknown | 3142 [dict setRawValue:801 forKey:22LL]; // Unknown |
| 3143 XCTAssertEqual(dict.count, 1U); | 3143 XCTAssertEqual(dict.count, 1U); |
| 3144 | 3144 |
| 3145 const int64_t kKeys[] = { 21LL, 23LL, 24LL }; | 3145 const int64_t kKeys[] = { 21LL, 23LL, 24LL }; |
| 3146 const int32_t kValues[] = { 700, 702, 803 }; // Unknown | 3146 const int32_t kValues[] = { 700, 702, 803 }; // Unknown |
| 3147 GPBInt64EnumDictionary *dict2 = | 3147 GPBInt64EnumDictionary *dict2 = |
| 3148 [[GPBInt64EnumDictionary alloc] initWithValues:kValues | 3148 [[GPBInt64EnumDictionary alloc] initWithEnums:kValues |
| 3149 forKeys:kKeys | 3149 forKeys:kKeys |
| 3150 count:GPBARRAYSIZE(kValues)]; | 3150 count:GPBARRAYSIZE(kValues)]; |
| 3151 XCTAssertNotNil(dict2); | 3151 XCTAssertNotNil(dict2); |
| 3152 [dict addRawEntriesFromDictionary:dict2]; | 3152 [dict addRawEntriesFromDictionary:dict2]; |
| 3153 XCTAssertEqual(dict.count, 4U); | 3153 XCTAssertEqual(dict.count, 4U); |
| 3154 | 3154 |
| 3155 int32_t value; | 3155 int32_t value; |
| 3156 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 3156 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 3157 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 3157 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 3158 XCTAssertEqual(value, 700); | 3158 XCTAssertEqual(value, 700); |
| 3159 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 3159 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 3160 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 3160 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 3161 XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue); | 3161 XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue); |
| 3162 XCTAssertTrue([dict valueForKey:22LL rawValue:NULL]); | 3162 XCTAssertTrue([dict getRawValue:NULL forKey:22LL]); |
| 3163 XCTAssertTrue([dict valueForKey:22LL rawValue:&value]); | 3163 XCTAssertTrue([dict getRawValue:&value forKey:22LL]); |
| 3164 XCTAssertEqual(value, 801); | 3164 XCTAssertEqual(value, 801); |
| 3165 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3165 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3166 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3166 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3167 XCTAssertEqual(value, 702); | 3167 XCTAssertEqual(value, 702); |
| 3168 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 3168 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 3169 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 3169 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 3170 XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue); | 3170 XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue); |
| 3171 XCTAssertTrue([dict valueForKey:24LL rawValue:NULL]); | 3171 XCTAssertTrue([dict getRawValue:NULL forKey:24LL]); |
| 3172 XCTAssertTrue([dict valueForKey:24LL rawValue:&value]); | 3172 XCTAssertTrue([dict getRawValue:&value forKey:24LL]); |
| 3173 XCTAssertEqual(value, 803); | 3173 XCTAssertEqual(value, 803); |
| 3174 [dict2 release]; | 3174 [dict2 release]; |
| 3175 } | 3175 } |
| 3176 | 3176 |
| 3177 - (void)testUnknownRemove { | 3177 - (void)testUnknownRemove { |
| 3178 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 3178 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3179 const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns | 3179 const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns |
| 3180 GPBInt64EnumDictionary *dict = | 3180 GPBInt64EnumDictionary *dict = |
| 3181 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue | 3181 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue |
| 3182 rawValues:kValues | 3182 rawValues:kValues |
| 3183 forKeys:kKeys | 3183 forKeys:kKeys |
| 3184 count:GPBARRAYSIZE(kV
alues)]; | 3184 count:GPBARRAYSIZE(kV
alues)]; |
| 3185 XCTAssertNotNil(dict); | 3185 XCTAssertNotNil(dict); |
| 3186 XCTAssertEqual(dict.count, 4U); | 3186 XCTAssertEqual(dict.count, 4U); |
| 3187 | 3187 |
| 3188 [dict removeValueForKey:22LL]; | 3188 [dict removeEnumForKey:22LL]; |
| 3189 XCTAssertEqual(dict.count, 3U); | 3189 XCTAssertEqual(dict.count, 3U); |
| 3190 int32_t value; | 3190 int32_t value; |
| 3191 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 3191 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 3192 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 3192 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 3193 XCTAssertEqual(value, 700); | 3193 XCTAssertEqual(value, 700); |
| 3194 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 3194 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 3195 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3195 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3196 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3196 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3197 XCTAssertEqual(value, 702); | 3197 XCTAssertEqual(value, 702); |
| 3198 XCTAssertTrue([dict valueForKey:24LL rawValue:NULL]); | 3198 XCTAssertTrue([dict getRawValue:NULL forKey:24LL]); |
| 3199 XCTAssertTrue([dict valueForKey:24LL rawValue:&value]); | 3199 XCTAssertTrue([dict getRawValue:&value forKey:24LL]); |
| 3200 XCTAssertEqual(value, 803); | 3200 XCTAssertEqual(value, 803); |
| 3201 | 3201 |
| 3202 // Remove again does nothing. | 3202 // Remove again does nothing. |
| 3203 [dict removeValueForKey:22LL]; | 3203 [dict removeEnumForKey:22LL]; |
| 3204 XCTAssertEqual(dict.count, 3U); | 3204 XCTAssertEqual(dict.count, 3U); |
| 3205 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 3205 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 3206 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 3206 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 3207 XCTAssertEqual(value, 700); | 3207 XCTAssertEqual(value, 700); |
| 3208 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 3208 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 3209 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3209 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3210 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3210 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3211 XCTAssertEqual(value, 702); | 3211 XCTAssertEqual(value, 702); |
| 3212 XCTAssertTrue([dict valueForKey:24LL rawValue:NULL]); | 3212 XCTAssertTrue([dict getRawValue:NULL forKey:24LL]); |
| 3213 XCTAssertTrue([dict valueForKey:24LL rawValue:&value]); | 3213 XCTAssertTrue([dict getRawValue:&value forKey:24LL]); |
| 3214 XCTAssertEqual(value, 803); | 3214 XCTAssertEqual(value, 803); |
| 3215 | 3215 |
| 3216 [dict removeValueForKey:24LL]; | 3216 [dict removeEnumForKey:24LL]; |
| 3217 XCTAssertEqual(dict.count, 2U); | 3217 XCTAssertEqual(dict.count, 2U); |
| 3218 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 3218 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 3219 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 3219 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 3220 XCTAssertEqual(value, 700); | 3220 XCTAssertEqual(value, 700); |
| 3221 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 3221 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 3222 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3222 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3223 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3223 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3224 XCTAssertEqual(value, 702); | 3224 XCTAssertEqual(value, 702); |
| 3225 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 3225 XCTAssertFalse([dict getEnum:NULL forKey:24LL]); |
| 3226 | 3226 |
| 3227 [dict removeAll]; | 3227 [dict removeAll]; |
| 3228 XCTAssertEqual(dict.count, 0U); | 3228 XCTAssertEqual(dict.count, 0U); |
| 3229 XCTAssertFalse([dict valueForKey:21LL value:NULL]); | 3229 XCTAssertFalse([dict getEnum:NULL forKey:21LL]); |
| 3230 XCTAssertFalse([dict valueForKey:22LL value:NULL]); | 3230 XCTAssertFalse([dict getEnum:NULL forKey:22LL]); |
| 3231 XCTAssertFalse([dict valueForKey:23LL value:NULL]); | 3231 XCTAssertFalse([dict getEnum:NULL forKey:23LL]); |
| 3232 XCTAssertFalse([dict valueForKey:24LL value:NULL]); | 3232 XCTAssertFalse([dict getEnum:NULL forKey:24LL]); |
| 3233 [dict release]; | 3233 [dict release]; |
| 3234 } | 3234 } |
| 3235 | 3235 |
| 3236 - (void)testInplaceMutationUnknowns { | 3236 - (void)testInplaceMutationUnknowns { |
| 3237 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 3237 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3238 const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns | 3238 const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns |
| 3239 GPBInt64EnumDictionary *dict = | 3239 GPBInt64EnumDictionary *dict = |
| 3240 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue | 3240 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue |
| 3241 rawValues:kValues | 3241 rawValues:kValues |
| 3242 forKeys:kKeys | 3242 forKeys:kKeys |
| 3243 count:GPBARRAYSIZE(kV
alues)]; | 3243 count:GPBARRAYSIZE(kV
alues)]; |
| 3244 XCTAssertNotNil(dict); | 3244 XCTAssertNotNil(dict); |
| 3245 XCTAssertEqual(dict.count, 4U); | 3245 XCTAssertEqual(dict.count, 4U); |
| 3246 int32_t value; | 3246 int32_t value; |
| 3247 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 3247 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 3248 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 3248 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 3249 XCTAssertEqual(value, 700); | 3249 XCTAssertEqual(value, 700); |
| 3250 XCTAssertTrue([dict valueForKey:22LL rawValue:NULL]); | 3250 XCTAssertTrue([dict getRawValue:NULL forKey:22LL]); |
| 3251 XCTAssertTrue([dict valueForKey:22LL rawValue:&value]); | 3251 XCTAssertTrue([dict getRawValue:&value forKey:22LL]); |
| 3252 XCTAssertEqual(value, 801); | 3252 XCTAssertEqual(value, 801); |
| 3253 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3253 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3254 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3254 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3255 XCTAssertEqual(value, 702); | 3255 XCTAssertEqual(value, 702); |
| 3256 XCTAssertTrue([dict valueForKey:24LL rawValue:NULL]); | 3256 XCTAssertTrue([dict getRawValue:NULL forKey:24LL]); |
| 3257 XCTAssertTrue([dict valueForKey:24LL rawValue:&value]); | 3257 XCTAssertTrue([dict getRawValue:&value forKey:24LL]); |
| 3258 XCTAssertEqual(value, 803); | 3258 XCTAssertEqual(value, 803); |
| 3259 | 3259 |
| 3260 XCTAssertThrowsSpecificNamed([dict setValue:803 forKey:21LL], // Unknown | 3260 XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:21LL], // Unknown |
| 3261 NSException, NSInvalidArgumentException); | 3261 NSException, NSInvalidArgumentException); |
| 3262 XCTAssertEqual(dict.count, 4U); | 3262 XCTAssertEqual(dict.count, 4U); |
| 3263 XCTAssertTrue([dict valueForKey:21LL value:NULL]); | 3263 XCTAssertTrue([dict getEnum:NULL forKey:21LL]); |
| 3264 XCTAssertTrue([dict valueForKey:21LL value:&value]); | 3264 XCTAssertTrue([dict getEnum:&value forKey:21LL]); |
| 3265 XCTAssertEqual(value, 700); | 3265 XCTAssertEqual(value, 700); |
| 3266 XCTAssertTrue([dict valueForKey:22LL rawValue:NULL]); | 3266 XCTAssertTrue([dict getRawValue:NULL forKey:22LL]); |
| 3267 XCTAssertTrue([dict valueForKey:22LL rawValue:&value]); | 3267 XCTAssertTrue([dict getRawValue:&value forKey:22LL]); |
| 3268 XCTAssertEqual(value, 801); | 3268 XCTAssertEqual(value, 801); |
| 3269 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3269 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3270 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3270 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3271 XCTAssertEqual(value, 702); | 3271 XCTAssertEqual(value, 702); |
| 3272 XCTAssertTrue([dict valueForKey:24LL rawValue:NULL]); | 3272 XCTAssertTrue([dict getRawValue:NULL forKey:24LL]); |
| 3273 XCTAssertTrue([dict valueForKey:24LL rawValue:&value]); | 3273 XCTAssertTrue([dict getRawValue:&value forKey:24LL]); |
| 3274 XCTAssertEqual(value, 803); | 3274 XCTAssertEqual(value, 803); |
| 3275 | 3275 |
| 3276 [dict setRawValue:803 forKey:21LL]; // Unknown | 3276 [dict setRawValue:803 forKey:21LL]; // Unknown |
| 3277 XCTAssertEqual(dict.count, 4U); | 3277 XCTAssertEqual(dict.count, 4U); |
| 3278 XCTAssertTrue([dict valueForKey:21LL rawValue:NULL]); | 3278 XCTAssertTrue([dict getRawValue:NULL forKey:21LL]); |
| 3279 XCTAssertTrue([dict valueForKey:21LL rawValue:&value]); | 3279 XCTAssertTrue([dict getRawValue:&value forKey:21LL]); |
| 3280 XCTAssertEqual(value, 803); | 3280 XCTAssertEqual(value, 803); |
| 3281 XCTAssertTrue([dict valueForKey:22LL rawValue:NULL]); | 3281 XCTAssertTrue([dict getRawValue:NULL forKey:22LL]); |
| 3282 XCTAssertTrue([dict valueForKey:22LL rawValue:&value]); | 3282 XCTAssertTrue([dict getRawValue:&value forKey:22LL]); |
| 3283 XCTAssertEqual(value, 801); | 3283 XCTAssertEqual(value, 801); |
| 3284 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3284 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3285 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3285 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3286 XCTAssertEqual(value, 702); | 3286 XCTAssertEqual(value, 702); |
| 3287 XCTAssertTrue([dict valueForKey:24LL rawValue:NULL]); | 3287 XCTAssertTrue([dict getRawValue:NULL forKey:24LL]); |
| 3288 XCTAssertTrue([dict valueForKey:24LL rawValue:&value]); | 3288 XCTAssertTrue([dict getRawValue:&value forKey:24LL]); |
| 3289 XCTAssertEqual(value, 803); | 3289 XCTAssertEqual(value, 803); |
| 3290 | 3290 |
| 3291 [dict setRawValue:700 forKey:24LL]; | 3291 [dict setRawValue:700 forKey:24LL]; |
| 3292 XCTAssertEqual(dict.count, 4U); | 3292 XCTAssertEqual(dict.count, 4U); |
| 3293 XCTAssertTrue([dict valueForKey:21LL rawValue:NULL]); | 3293 XCTAssertTrue([dict getRawValue:NULL forKey:21LL]); |
| 3294 XCTAssertTrue([dict valueForKey:21LL rawValue:&value]); | 3294 XCTAssertTrue([dict getRawValue:&value forKey:21LL]); |
| 3295 XCTAssertEqual(value, 803); | 3295 XCTAssertEqual(value, 803); |
| 3296 XCTAssertTrue([dict valueForKey:22LL rawValue:NULL]); | 3296 XCTAssertTrue([dict getRawValue:NULL forKey:22LL]); |
| 3297 XCTAssertTrue([dict valueForKey:22LL rawValue:&value]); | 3297 XCTAssertTrue([dict getRawValue:&value forKey:22LL]); |
| 3298 XCTAssertEqual(value, 801); | 3298 XCTAssertEqual(value, 801); |
| 3299 XCTAssertTrue([dict valueForKey:23LL value:NULL]); | 3299 XCTAssertTrue([dict getEnum:NULL forKey:23LL]); |
| 3300 XCTAssertTrue([dict valueForKey:23LL value:&value]); | 3300 XCTAssertTrue([dict getEnum:&value forKey:23LL]); |
| 3301 XCTAssertEqual(value, 702); | 3301 XCTAssertEqual(value, 702); |
| 3302 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 3302 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 3303 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 3303 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 3304 XCTAssertEqual(value, 700); | 3304 XCTAssertEqual(value, 700); |
| 3305 | 3305 |
| 3306 const int64_t kKeys2[] = { 22LL, 23LL }; | 3306 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 3307 const int32_t kValues2[] = { 702, 801 }; // Unknown | 3307 const int32_t kValues2[] = { 702, 801 }; // Unknown |
| 3308 GPBInt64EnumDictionary *dict2 = | 3308 GPBInt64EnumDictionary *dict2 = |
| 3309 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue | 3309 [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsV
alidValue |
| 3310 rawValues:kValues2 | 3310 rawValues:kValues2 |
| 3311 forKeys:kKeys2 | 3311 forKeys:kKeys2 |
| 3312 count:GPBARRAYSIZE(kV
alues2)]; | 3312 count:GPBARRAYSIZE(kV
alues2)]; |
| 3313 XCTAssertNotNil(dict2); | 3313 XCTAssertNotNil(dict2); |
| 3314 [dict addRawEntriesFromDictionary:dict2]; | 3314 [dict addRawEntriesFromDictionary:dict2]; |
| 3315 XCTAssertEqual(dict.count, 4U); | 3315 XCTAssertEqual(dict.count, 4U); |
| 3316 XCTAssertTrue([dict valueForKey:21LL rawValue:NULL]); | 3316 XCTAssertTrue([dict getRawValue:NULL forKey:21LL]); |
| 3317 XCTAssertTrue([dict valueForKey:21LL rawValue:&value]); | 3317 XCTAssertTrue([dict getRawValue:&value forKey:21LL]); |
| 3318 XCTAssertEqual(value, 803); | 3318 XCTAssertEqual(value, 803); |
| 3319 XCTAssertTrue([dict valueForKey:22LL value:NULL]); | 3319 XCTAssertTrue([dict getEnum:NULL forKey:22LL]); |
| 3320 XCTAssertTrue([dict valueForKey:22LL value:&value]); | 3320 XCTAssertTrue([dict getEnum:&value forKey:22LL]); |
| 3321 XCTAssertEqual(value, 702); | 3321 XCTAssertEqual(value, 702); |
| 3322 XCTAssertTrue([dict valueForKey:23LL rawValue:NULL]); | 3322 XCTAssertTrue([dict getRawValue:NULL forKey:23LL]); |
| 3323 XCTAssertTrue([dict valueForKey:23LL rawValue:&value]); | 3323 XCTAssertTrue([dict getRawValue:&value forKey:23LL]); |
| 3324 XCTAssertEqual(value, 801); | 3324 XCTAssertEqual(value, 801); |
| 3325 XCTAssertTrue([dict valueForKey:24LL value:NULL]); | 3325 XCTAssertTrue([dict getEnum:NULL forKey:24LL]); |
| 3326 XCTAssertTrue([dict valueForKey:24LL value:&value]); | 3326 XCTAssertTrue([dict getEnum:&value forKey:24LL]); |
| 3327 XCTAssertEqual(value, 700); | 3327 XCTAssertEqual(value, 700); |
| 3328 | 3328 |
| 3329 [dict2 release]; | 3329 [dict2 release]; |
| 3330 [dict release]; | 3330 [dict release]; |
| 3331 } | 3331 } |
| 3332 | 3332 |
| 3333 - (void)testCopyUnknowns { | 3333 - (void)testCopyUnknowns { |
| 3334 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 3334 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3335 const int32_t kValues[] = { 700, 801, 702, 803 }; | 3335 const int32_t kValues[] = { 700, 801, 702, 803 }; |
| 3336 GPBInt64EnumDictionary *dict = | 3336 GPBInt64EnumDictionary *dict = |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3552 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); | 3552 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); |
| 3553 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); | 3553 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); |
| 3554 [dict2 release]; | 3554 [dict2 release]; |
| 3555 } | 3555 } |
| 3556 | 3556 |
| 3557 - (void)testRemove { | 3557 - (void)testRemove { |
| 3558 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 3558 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3559 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3559 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
| 3560 GPBInt64ObjectDictionary<NSString*> *dict = | 3560 GPBInt64ObjectDictionary<NSString*> *dict = |
| 3561 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects | 3561 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects |
| 3562 forKeys:kKeys | 3562 forKeys:kKeys |
| 3563 count:GPBARRAYSIZE(kObjects)]; | 3563 count:GPBARRAYSIZE(kObjects)]; |
| 3564 XCTAssertNotNil(dict); | 3564 XCTAssertNotNil(dict); |
| 3565 XCTAssertEqual(dict.count, 4U); | 3565 XCTAssertEqual(dict.count, 4U); |
| 3566 | 3566 |
| 3567 [dict removeObjectForKey:22LL]; | 3567 [dict removeObjectForKey:22LL]; |
| 3568 XCTAssertEqual(dict.count, 3U); | 3568 XCTAssertEqual(dict.count, 3U); |
| 3569 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); | 3569 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); |
| 3570 XCTAssertNil([dict objectForKey:22LL]); | 3570 XCTAssertNil([dict objectForKey:22LL]); |
| 3571 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); | 3571 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); |
| 3572 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); | 3572 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); |
| 3573 | 3573 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3593 XCTAssertNil([dict objectForKey:23LL]); | 3593 XCTAssertNil([dict objectForKey:23LL]); |
| 3594 XCTAssertNil([dict objectForKey:24LL]); | 3594 XCTAssertNil([dict objectForKey:24LL]); |
| 3595 [dict release]; | 3595 [dict release]; |
| 3596 } | 3596 } |
| 3597 | 3597 |
| 3598 - (void)testInplaceMutation { | 3598 - (void)testInplaceMutation { |
| 3599 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 3599 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3600 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3600 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
| 3601 GPBInt64ObjectDictionary<NSString*> *dict = | 3601 GPBInt64ObjectDictionary<NSString*> *dict = |
| 3602 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects | 3602 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects |
| 3603 forKeys:kKeys | 3603 forKeys:kKeys |
| 3604 count:GPBARRAYSIZE(kObjects)]; | 3604 count:GPBARRAYSIZE(kObjects)]; |
| 3605 XCTAssertNotNil(dict); | 3605 XCTAssertNotNil(dict); |
| 3606 XCTAssertEqual(dict.count, 4U); | 3606 XCTAssertEqual(dict.count, 4U); |
| 3607 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); | 3607 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); |
| 3608 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); | 3608 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); |
| 3609 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); | 3609 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); |
| 3610 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); | 3610 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); |
| 3611 | 3611 |
| 3612 [dict setObject:@"jkl" forKey:21LL]; | 3612 [dict setObject:@"jkl" forKey:21LL]; |
| 3613 XCTAssertEqual(dict.count, 4U); | 3613 XCTAssertEqual(dict.count, 4U); |
| 3614 XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl"); | 3614 XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl"); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3638 XCTAssertEqualObjects([dict objectForKey:24LL], @"def"); | 3638 XCTAssertEqualObjects([dict objectForKey:24LL], @"def"); |
| 3639 | 3639 |
| 3640 [dict2 release]; | 3640 [dict2 release]; |
| 3641 [dict release]; | 3641 [dict release]; |
| 3642 } | 3642 } |
| 3643 | 3643 |
| 3644 @end | 3644 @end |
| 3645 | 3645 |
| 3646 //%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL) | 3646 //%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL) |
| 3647 | 3647 |
| OLD | NEW |