| 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 3345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3356 @end | 3356 @end |
| 3357 | 3357 |
| 3358 #pragma mark - Int64 -> Object | 3358 #pragma mark - Int64 -> Object |
| 3359 | 3359 |
| 3360 @interface GPBInt64ObjectDictionaryTests : XCTestCase | 3360 @interface GPBInt64ObjectDictionaryTests : XCTestCase |
| 3361 @end | 3361 @end |
| 3362 | 3362 |
| 3363 @implementation GPBInt64ObjectDictionaryTests | 3363 @implementation GPBInt64ObjectDictionaryTests |
| 3364 | 3364 |
| 3365 - (void)testEmpty { | 3365 - (void)testEmpty { |
| 3366 GPBInt64ObjectDictionary *dict = [[GPBInt64ObjectDictionary alloc] init]; | 3366 GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc]
init]; |
| 3367 XCTAssertNotNil(dict); | 3367 XCTAssertNotNil(dict); |
| 3368 XCTAssertEqual(dict.count, 0U); | 3368 XCTAssertEqual(dict.count, 0U); |
| 3369 XCTAssertNil([dict objectForKey:21LL]); | 3369 XCTAssertNil([dict objectForKey:21LL]); |
| 3370 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop
) { | 3370 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOO
L *stop) { |
| 3371 #pragma unused(aKey, aObject, stop) | 3371 #pragma unused(aKey, aObject, stop) |
| 3372 XCTFail(@"Shouldn't get here!"); | 3372 XCTFail(@"Shouldn't get here!"); |
| 3373 }]; | 3373 }]; |
| 3374 [dict release]; | 3374 [dict release]; |
| 3375 } | 3375 } |
| 3376 | 3376 |
| 3377 - (void)testOne { | 3377 - (void)testOne { |
| 3378 GPBInt64ObjectDictionary *dict = [GPBInt64ObjectDictionary dictionaryWithObjec
t:@"abc" forKey:21LL]; | 3378 GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictiona
ryWithObject:@"abc" forKey:21LL]; |
| 3379 XCTAssertNotNil(dict); | 3379 XCTAssertNotNil(dict); |
| 3380 XCTAssertEqual(dict.count, 1U); | 3380 XCTAssertEqual(dict.count, 1U); |
| 3381 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); | 3381 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); |
| 3382 XCTAssertNil([dict objectForKey:22LL]); | 3382 XCTAssertNil([dict objectForKey:22LL]); |
| 3383 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop
) { | 3383 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOO
L *stop) { |
| 3384 XCTAssertEqual(aKey, 21LL); | 3384 XCTAssertEqual(aKey, 21LL); |
| 3385 XCTAssertEqualObjects(aObject, @"abc"); | 3385 XCTAssertEqualObjects(aObject, @"abc"); |
| 3386 XCTAssertNotEqual(stop, NULL); | 3386 XCTAssertNotEqual(stop, NULL); |
| 3387 }]; | 3387 }]; |
| 3388 } | 3388 } |
| 3389 | 3389 |
| 3390 - (void)testBasics { | 3390 - (void)testBasics { |
| 3391 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; | 3391 const int64_t kKeys[] = { 21LL, 22LL, 23LL }; |
| 3392 const id kObjects[] = { @"abc", @"def", @"ghi" }; | 3392 const NSString* kObjects[] = { @"abc", @"def", @"ghi" }; |
| 3393 GPBInt64ObjectDictionary *dict = | 3393 GPBInt64ObjectDictionary<NSString*> *dict = |
| 3394 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects | 3394 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects |
| 3395 forKeys:kKeys | 3395 forKeys:kKeys |
| 3396 count:GPBARRAYSIZE(kObjects)]; | 3396 count:GPBARRAYSIZE(kObjects)]; |
| 3397 XCTAssertNotNil(dict); | 3397 XCTAssertNotNil(dict); |
| 3398 XCTAssertEqual(dict.count, 3U); | 3398 XCTAssertEqual(dict.count, 3U); |
| 3399 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); | 3399 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); |
| 3400 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); | 3400 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); |
| 3401 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); | 3401 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); |
| 3402 XCTAssertNil([dict objectForKey:24LL]); | 3402 XCTAssertNil([dict objectForKey:24LL]); |
| 3403 | 3403 |
| 3404 __block NSUInteger idx = 0; | 3404 __block NSUInteger idx = 0; |
| 3405 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); | 3405 int64_t *seenKeys = malloc(3 * sizeof(int64_t)); |
| 3406 id *seenObjects = malloc(3 * sizeof(id)); | 3406 NSString* *seenObjects = malloc(3 * sizeof(NSString*)); |
| 3407 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop
) { | 3407 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOO
L *stop) { |
| 3408 XCTAssertLessThan(idx, 3U); | 3408 XCTAssertLessThan(idx, 3U); |
| 3409 seenKeys[idx] = aKey; | 3409 seenKeys[idx] = aKey; |
| 3410 seenObjects[idx] = aObject; | 3410 seenObjects[idx] = aObject; |
| 3411 XCTAssertNotEqual(stop, NULL); | 3411 XCTAssertNotEqual(stop, NULL); |
| 3412 ++idx; | 3412 ++idx; |
| 3413 }]; | 3413 }]; |
| 3414 for (int i = 0; i < 3; ++i) { | 3414 for (int i = 0; i < 3; ++i) { |
| 3415 BOOL foundKey = NO; | 3415 BOOL foundKey = NO; |
| 3416 for (int j = 0; (j < 3) && !foundKey; ++j) { | 3416 for (int j = 0; (j < 3) && !foundKey; ++j) { |
| 3417 if (kKeys[i] == seenKeys[j]) { | 3417 if (kKeys[i] == seenKeys[j]) { |
| 3418 foundKey = YES; | 3418 foundKey = YES; |
| 3419 XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i,
j); | 3419 XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i,
j); |
| 3420 } | 3420 } |
| 3421 } | 3421 } |
| 3422 XCTAssertTrue(foundKey, @"i = %d", i); | 3422 XCTAssertTrue(foundKey, @"i = %d", i); |
| 3423 } | 3423 } |
| 3424 free(seenKeys); | 3424 free(seenKeys); |
| 3425 free(seenObjects); | 3425 free(seenObjects); |
| 3426 | 3426 |
| 3427 // Stopping the enumeration. | 3427 // Stopping the enumeration. |
| 3428 idx = 0; | 3428 idx = 0; |
| 3429 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop
) { | 3429 [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOO
L *stop) { |
| 3430 #pragma unused(aKey, aObject) | 3430 #pragma unused(aKey, aObject) |
| 3431 if (idx == 1) *stop = YES; | 3431 if (idx == 1) *stop = YES; |
| 3432 XCTAssertNotEqual(idx, 2U); | 3432 XCTAssertNotEqual(idx, 2U); |
| 3433 ++idx; | 3433 ++idx; |
| 3434 }]; | 3434 }]; |
| 3435 [dict release]; | 3435 [dict release]; |
| 3436 } | 3436 } |
| 3437 | 3437 |
| 3438 - (void)testEquality { | 3438 - (void)testEquality { |
| 3439 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; | 3439 const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3440 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; | 3440 const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; |
| 3441 const id kObjects1[] = { @"abc", @"def", @"ghi" }; | 3441 const NSString* kObjects1[] = { @"abc", @"def", @"ghi" }; |
| 3442 const id kObjects2[] = { @"abc", @"jkl", @"ghi" }; | 3442 const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" }; |
| 3443 const id kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3443 const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; |
| 3444 GPBInt64ObjectDictionary *dict1 = | 3444 GPBInt64ObjectDictionary<NSString*> *dict1 = |
| 3445 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 | 3445 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 |
| 3446 forKeys:kKeys1 | 3446 forKeys:kKeys1 |
| 3447 count:GPBARRAYSIZE(kObjects1)]
; | 3447 count:GPBARRAYSIZE(kObjects1)]
; |
| 3448 XCTAssertNotNil(dict1); | 3448 XCTAssertNotNil(dict1); |
| 3449 GPBInt64ObjectDictionary *dict1prime = | 3449 GPBInt64ObjectDictionary<NSString*> *dict1prime = |
| 3450 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 | 3450 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 |
| 3451 forKeys:kKeys1 | 3451 forKeys:kKeys1 |
| 3452 count:GPBARRAYSIZE(kObjects1)]
; | 3452 count:GPBARRAYSIZE(kObjects1)]
; |
| 3453 XCTAssertNotNil(dict1prime); | 3453 XCTAssertNotNil(dict1prime); |
| 3454 GPBInt64ObjectDictionary *dict2 = | 3454 GPBInt64ObjectDictionary<NSString*> *dict2 = |
| 3455 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2 | 3455 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2 |
| 3456 forKeys:kKeys1 | 3456 forKeys:kKeys1 |
| 3457 count:GPBARRAYSIZE(kObjects2)]
; | 3457 count:GPBARRAYSIZE(kObjects2)]
; |
| 3458 XCTAssertNotNil(dict2); | 3458 XCTAssertNotNil(dict2); |
| 3459 GPBInt64ObjectDictionary *dict3 = | 3459 GPBInt64ObjectDictionary<NSString*> *dict3 = |
| 3460 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 | 3460 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 |
| 3461 forKeys:kKeys2 | 3461 forKeys:kKeys2 |
| 3462 count:GPBARRAYSIZE(kObjects1)]
; | 3462 count:GPBARRAYSIZE(kObjects1)]
; |
| 3463 XCTAssertNotNil(dict3); | 3463 XCTAssertNotNil(dict3); |
| 3464 GPBInt64ObjectDictionary *dict4 = | 3464 GPBInt64ObjectDictionary<NSString*> *dict4 = |
| 3465 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects3 | 3465 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects3 |
| 3466 forKeys:kKeys1 | 3466 forKeys:kKeys1 |
| 3467 count:GPBARRAYSIZE(kObjects3)]
; | 3467 count:GPBARRAYSIZE(kObjects3)]
; |
| 3468 XCTAssertNotNil(dict4); | 3468 XCTAssertNotNil(dict4); |
| 3469 | 3469 |
| 3470 // 1/1Prime should be different objects, but equal. | 3470 // 1/1Prime should be different objects, but equal. |
| 3471 XCTAssertNotEqual(dict1, dict1prime); | 3471 XCTAssertNotEqual(dict1, dict1prime); |
| 3472 XCTAssertEqualObjects(dict1, dict1prime); | 3472 XCTAssertEqualObjects(dict1, dict1prime); |
| 3473 // Equal, so they must have same hash. | 3473 // Equal, so they must have same hash. |
| 3474 XCTAssertEqual([dict1 hash], [dict1prime hash]); | 3474 XCTAssertEqual([dict1 hash], [dict1prime hash]); |
| 3475 | 3475 |
| 3476 // 2 is same keys, different objects; not equal. | 3476 // 2 is same keys, different objects; not equal. |
| 3477 XCTAssertNotEqualObjects(dict1, dict2); | 3477 XCTAssertNotEqualObjects(dict1, dict2); |
| 3478 | 3478 |
| 3479 // 3 is different keys, same objects; not equal. | 3479 // 3 is different keys, same objects; not equal. |
| 3480 XCTAssertNotEqualObjects(dict1, dict3); | 3480 XCTAssertNotEqualObjects(dict1, dict3); |
| 3481 | 3481 |
| 3482 // 4 extra pair; not equal | 3482 // 4 extra pair; not equal |
| 3483 XCTAssertNotEqualObjects(dict1, dict4); | 3483 XCTAssertNotEqualObjects(dict1, dict4); |
| 3484 | 3484 |
| 3485 [dict1 release]; | 3485 [dict1 release]; |
| 3486 [dict1prime release]; | 3486 [dict1prime release]; |
| 3487 [dict2 release]; | 3487 [dict2 release]; |
| 3488 [dict3 release]; | 3488 [dict3 release]; |
| 3489 [dict4 release]; | 3489 [dict4 release]; |
| 3490 } | 3490 } |
| 3491 | 3491 |
| 3492 - (void)testCopy { | 3492 - (void)testCopy { |
| 3493 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 3493 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3494 const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3494 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
| 3495 GPBInt64ObjectDictionary *dict = | 3495 GPBInt64ObjectDictionary<NSString*> *dict = |
| 3496 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects | 3496 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects |
| 3497 forKeys:kKeys | 3497 forKeys:kKeys |
| 3498 count:GPBARRAYSIZE(kObjects)]; | 3498 count:GPBARRAYSIZE(kObjects)]; |
| 3499 XCTAssertNotNil(dict); | 3499 XCTAssertNotNil(dict); |
| 3500 | 3500 |
| 3501 GPBInt64ObjectDictionary *dict2 = [dict copy]; | 3501 GPBInt64ObjectDictionary<NSString*> *dict2 = [dict copy]; |
| 3502 XCTAssertNotNil(dict2); | 3502 XCTAssertNotNil(dict2); |
| 3503 | 3503 |
| 3504 // Should be new object but equal. | 3504 // Should be new object but equal. |
| 3505 XCTAssertNotEqual(dict, dict2); | 3505 XCTAssertNotEqual(dict, dict2); |
| 3506 XCTAssertEqualObjects(dict, dict2); | 3506 XCTAssertEqualObjects(dict, dict2); |
| 3507 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64ObjectDictionary class]]); | 3507 XCTAssertTrue([dict2 isKindOfClass:[GPBInt64ObjectDictionary class]]); |
| 3508 | 3508 |
| 3509 [dict2 release]; | 3509 [dict2 release]; |
| 3510 [dict release]; | 3510 [dict release]; |
| 3511 } | 3511 } |
| 3512 | 3512 |
| 3513 - (void)testDictionaryFromDictionary { | 3513 - (void)testDictionaryFromDictionary { |
| 3514 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; | 3514 const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; |
| 3515 const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3515 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
| 3516 GPBInt64ObjectDictionary *dict = | 3516 GPBInt64ObjectDictionary<NSString*> *dict = |
| 3517 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects | 3517 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects |
| 3518 forKeys:kKeys | 3518 forKeys:kKeys |
| 3519 count:GPBARRAYSIZE(kObjects)]; | 3519 count:GPBARRAYSIZE(kObjects)]; |
| 3520 XCTAssertNotNil(dict); | 3520 XCTAssertNotNil(dict); |
| 3521 | 3521 |
| 3522 GPBInt64ObjectDictionary *dict2 = | 3522 GPBInt64ObjectDictionary<NSString*> *dict2 = |
| 3523 [GPBInt64ObjectDictionary dictionaryWithDictionary:dict]; | 3523 [GPBInt64ObjectDictionary dictionaryWithDictionary:dict]; |
| 3524 XCTAssertNotNil(dict2); | 3524 XCTAssertNotNil(dict2); |
| 3525 | 3525 |
| 3526 // Should be new pointer, but equal objects. | 3526 // Should be new pointer, but equal objects. |
| 3527 XCTAssertNotEqual(dict, dict2); | 3527 XCTAssertNotEqual(dict, dict2); |
| 3528 XCTAssertEqualObjects(dict, dict2); | 3528 XCTAssertEqualObjects(dict, dict2); |
| 3529 [dict release]; | 3529 [dict release]; |
| 3530 } | 3530 } |
| 3531 | 3531 |
| 3532 - (void)testAdds { | 3532 - (void)testAdds { |
| 3533 GPBInt64ObjectDictionary *dict = [GPBInt64ObjectDictionary dictionary]; | 3533 GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictiona
ry]; |
| 3534 XCTAssertNotNil(dict); | 3534 XCTAssertNotNil(dict); |
| 3535 | 3535 |
| 3536 XCTAssertEqual(dict.count, 0U); | 3536 XCTAssertEqual(dict.count, 0U); |
| 3537 [dict setObject:@"abc" forKey:21LL]; | 3537 [dict setObject:@"abc" forKey:21LL]; |
| 3538 XCTAssertEqual(dict.count, 1U); | 3538 XCTAssertEqual(dict.count, 1U); |
| 3539 | 3539 |
| 3540 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; | 3540 const int64_t kKeys[] = { 22LL, 23LL, 24LL }; |
| 3541 const id kObjects[] = { @"def", @"ghi", @"jkl" }; | 3541 const NSString* kObjects[] = { @"def", @"ghi", @"jkl" }; |
| 3542 GPBInt64ObjectDictionary *dict2 = | 3542 GPBInt64ObjectDictionary<NSString*> *dict2 = |
| 3543 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects | 3543 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects |
| 3544 forKeys:kKeys | 3544 forKeys:kKeys |
| 3545 count:GPBARRAYSIZE(kObjects)]; | 3545 count:GPBARRAYSIZE(kObjects)]; |
| 3546 XCTAssertNotNil(dict2); | 3546 XCTAssertNotNil(dict2); |
| 3547 [dict addEntriesFromDictionary:dict2]; | 3547 [dict addEntriesFromDictionary:dict2]; |
| 3548 XCTAssertEqual(dict.count, 4U); | 3548 XCTAssertEqual(dict.count, 4U); |
| 3549 | 3549 |
| 3550 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); | 3550 XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); |
| 3551 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); | 3551 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); |
| 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 id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3559 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
| 3560 GPBInt64ObjectDictionary *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]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3590 XCTAssertEqual(dict.count, 0U); | 3590 XCTAssertEqual(dict.count, 0U); |
| 3591 XCTAssertNil([dict objectForKey:21LL]); | 3591 XCTAssertNil([dict objectForKey:21LL]); |
| 3592 XCTAssertNil([dict objectForKey:22LL]); | 3592 XCTAssertNil([dict objectForKey:22LL]); |
| 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 id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3600 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
| 3601 GPBInt64ObjectDictionary *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"); |
| 3615 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); | 3615 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); |
| 3616 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); | 3616 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); |
| 3617 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); | 3617 XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl"); |
| 3618 | 3618 |
| 3619 [dict setObject:@"def" forKey:24LL]; | 3619 [dict setObject:@"def" forKey:24LL]; |
| 3620 XCTAssertEqual(dict.count, 4U); | 3620 XCTAssertEqual(dict.count, 4U); |
| 3621 XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl"); | 3621 XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl"); |
| 3622 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); | 3622 XCTAssertEqualObjects([dict objectForKey:22LL], @"def"); |
| 3623 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); | 3623 XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi"); |
| 3624 XCTAssertEqualObjects([dict objectForKey:24LL], @"def"); | 3624 XCTAssertEqualObjects([dict objectForKey:24LL], @"def"); |
| 3625 | 3625 |
| 3626 const int64_t kKeys2[] = { 22LL, 23LL }; | 3626 const int64_t kKeys2[] = { 22LL, 23LL }; |
| 3627 const id kObjects2[] = { @"ghi", @"abc" }; | 3627 const NSString* kObjects2[] = { @"ghi", @"abc" }; |
| 3628 GPBInt64ObjectDictionary *dict2 = | 3628 GPBInt64ObjectDictionary<NSString*> *dict2 = |
| 3629 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2 | 3629 [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2 |
| 3630 forKeys:kKeys2 | 3630 forKeys:kKeys2 |
| 3631 count:GPBARRAYSIZE(kObjects2)]
; | 3631 count:GPBARRAYSIZE(kObjects2)]
; |
| 3632 XCTAssertNotNil(dict2); | 3632 XCTAssertNotNil(dict2); |
| 3633 [dict addEntriesFromDictionary:dict2]; | 3633 [dict addEntriesFromDictionary:dict2]; |
| 3634 XCTAssertEqual(dict.count, 4U); | 3634 XCTAssertEqual(dict.count, 4U); |
| 3635 XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl"); | 3635 XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl"); |
| 3636 XCTAssertEqualObjects([dict objectForKey:22LL], @"ghi"); | 3636 XCTAssertEqualObjects([dict objectForKey:22LL], @"ghi"); |
| 3637 XCTAssertEqualObjects([dict objectForKey:23LL], @"abc"); | 3637 XCTAssertEqualObjects([dict objectForKey:23LL], @"abc"); |
| 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 |