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 - Int32 -> Object | 3358 #pragma mark - Int32 -> Object |
3359 | 3359 |
3360 @interface GPBInt32ObjectDictionaryTests : XCTestCase | 3360 @interface GPBInt32ObjectDictionaryTests : XCTestCase |
3361 @end | 3361 @end |
3362 | 3362 |
3363 @implementation GPBInt32ObjectDictionaryTests | 3363 @implementation GPBInt32ObjectDictionaryTests |
3364 | 3364 |
3365 - (void)testEmpty { | 3365 - (void)testEmpty { |
3366 GPBInt32ObjectDictionary *dict = [[GPBInt32ObjectDictionary alloc] init]; | 3366 GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc]
init]; |
3367 XCTAssertNotNil(dict); | 3367 XCTAssertNotNil(dict); |
3368 XCTAssertEqual(dict.count, 0U); | 3368 XCTAssertEqual(dict.count, 0U); |
3369 XCTAssertNil([dict objectForKey:11]); | 3369 XCTAssertNil([dict objectForKey:11]); |
3370 [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, id aObject, BOOL *stop
) { | 3370 [dict enumerateKeysAndObjectsUsingBlock:^(int32_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 GPBInt32ObjectDictionary *dict = [GPBInt32ObjectDictionary dictionaryWithObjec
t:@"abc" forKey:11]; | 3378 GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary dictiona
ryWithObject:@"abc" forKey:11]; |
3379 XCTAssertNotNil(dict); | 3379 XCTAssertNotNil(dict); |
3380 XCTAssertEqual(dict.count, 1U); | 3380 XCTAssertEqual(dict.count, 1U); |
3381 XCTAssertEqualObjects([dict objectForKey:11], @"abc"); | 3381 XCTAssertEqualObjects([dict objectForKey:11], @"abc"); |
3382 XCTAssertNil([dict objectForKey:12]); | 3382 XCTAssertNil([dict objectForKey:12]); |
3383 [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, id aObject, BOOL *stop
) { | 3383 [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOO
L *stop) { |
3384 XCTAssertEqual(aKey, 11); | 3384 XCTAssertEqual(aKey, 11); |
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 int32_t kKeys[] = { 11, 12, 13 }; | 3391 const int32_t kKeys[] = { 11, 12, 13 }; |
3392 const id kObjects[] = { @"abc", @"def", @"ghi" }; | 3392 const NSString* kObjects[] = { @"abc", @"def", @"ghi" }; |
3393 GPBInt32ObjectDictionary *dict = | 3393 GPBInt32ObjectDictionary<NSString*> *dict = |
3394 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects | 3394 [[GPBInt32ObjectDictionary 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:11], @"abc"); | 3399 XCTAssertEqualObjects([dict objectForKey:11], @"abc"); |
3400 XCTAssertEqualObjects([dict objectForKey:12], @"def"); | 3400 XCTAssertEqualObjects([dict objectForKey:12], @"def"); |
3401 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); | 3401 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); |
3402 XCTAssertNil([dict objectForKey:14]); | 3402 XCTAssertNil([dict objectForKey:14]); |
3403 | 3403 |
3404 __block NSUInteger idx = 0; | 3404 __block NSUInteger idx = 0; |
3405 int32_t *seenKeys = malloc(3 * sizeof(int32_t)); | 3405 int32_t *seenKeys = malloc(3 * sizeof(int32_t)); |
3406 id *seenObjects = malloc(3 * sizeof(id)); | 3406 NSString* *seenObjects = malloc(3 * sizeof(NSString*)); |
3407 [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, id aObject, BOOL *stop
) { | 3407 [dict enumerateKeysAndObjectsUsingBlock:^(int32_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:^(int32_t aKey, id aObject, BOOL *stop
) { | 3429 [dict enumerateKeysAndObjectsUsingBlock:^(int32_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 int32_t kKeys1[] = { 11, 12, 13, 14 }; | 3439 const int32_t kKeys1[] = { 11, 12, 13, 14 }; |
3440 const int32_t kKeys2[] = { 12, 11, 14 }; | 3440 const int32_t kKeys2[] = { 12, 11, 14 }; |
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 GPBInt32ObjectDictionary *dict1 = | 3444 GPBInt32ObjectDictionary<NSString*> *dict1 = |
3445 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 | 3445 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 |
3446 forKeys:kKeys1 | 3446 forKeys:kKeys1 |
3447 count:GPBARRAYSIZE(kObjects1)]
; | 3447 count:GPBARRAYSIZE(kObjects1)]
; |
3448 XCTAssertNotNil(dict1); | 3448 XCTAssertNotNil(dict1); |
3449 GPBInt32ObjectDictionary *dict1prime = | 3449 GPBInt32ObjectDictionary<NSString*> *dict1prime = |
3450 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 | 3450 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 |
3451 forKeys:kKeys1 | 3451 forKeys:kKeys1 |
3452 count:GPBARRAYSIZE(kObjects1)]
; | 3452 count:GPBARRAYSIZE(kObjects1)]
; |
3453 XCTAssertNotNil(dict1prime); | 3453 XCTAssertNotNil(dict1prime); |
3454 GPBInt32ObjectDictionary *dict2 = | 3454 GPBInt32ObjectDictionary<NSString*> *dict2 = |
3455 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2 | 3455 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2 |
3456 forKeys:kKeys1 | 3456 forKeys:kKeys1 |
3457 count:GPBARRAYSIZE(kObjects2)]
; | 3457 count:GPBARRAYSIZE(kObjects2)]
; |
3458 XCTAssertNotNil(dict2); | 3458 XCTAssertNotNil(dict2); |
3459 GPBInt32ObjectDictionary *dict3 = | 3459 GPBInt32ObjectDictionary<NSString*> *dict3 = |
3460 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 | 3460 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 |
3461 forKeys:kKeys2 | 3461 forKeys:kKeys2 |
3462 count:GPBARRAYSIZE(kObjects1)]
; | 3462 count:GPBARRAYSIZE(kObjects1)]
; |
3463 XCTAssertNotNil(dict3); | 3463 XCTAssertNotNil(dict3); |
3464 GPBInt32ObjectDictionary *dict4 = | 3464 GPBInt32ObjectDictionary<NSString*> *dict4 = |
3465 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects3 | 3465 [[GPBInt32ObjectDictionary 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 int32_t kKeys[] = { 11, 12, 13, 14 }; | 3493 const int32_t kKeys[] = { 11, 12, 13, 14 }; |
3494 const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3494 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
3495 GPBInt32ObjectDictionary *dict = | 3495 GPBInt32ObjectDictionary<NSString*> *dict = |
3496 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects | 3496 [[GPBInt32ObjectDictionary 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 GPBInt32ObjectDictionary *dict2 = [dict copy]; | 3501 GPBInt32ObjectDictionary<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:[GPBInt32ObjectDictionary class]]); | 3507 XCTAssertTrue([dict2 isKindOfClass:[GPBInt32ObjectDictionary 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 int32_t kKeys[] = { 11, 12, 13, 14 }; | 3514 const int32_t kKeys[] = { 11, 12, 13, 14 }; |
3515 const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3515 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
3516 GPBInt32ObjectDictionary *dict = | 3516 GPBInt32ObjectDictionary<NSString*> *dict = |
3517 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects | 3517 [[GPBInt32ObjectDictionary 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 GPBInt32ObjectDictionary *dict2 = | 3522 GPBInt32ObjectDictionary<NSString*> *dict2 = |
3523 [GPBInt32ObjectDictionary dictionaryWithDictionary:dict]; | 3523 [GPBInt32ObjectDictionary 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 GPBInt32ObjectDictionary *dict = [GPBInt32ObjectDictionary dictionary]; | 3533 GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary 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:11]; | 3537 [dict setObject:@"abc" forKey:11]; |
3538 XCTAssertEqual(dict.count, 1U); | 3538 XCTAssertEqual(dict.count, 1U); |
3539 | 3539 |
3540 const int32_t kKeys[] = { 12, 13, 14 }; | 3540 const int32_t kKeys[] = { 12, 13, 14 }; |
3541 const id kObjects[] = { @"def", @"ghi", @"jkl" }; | 3541 const NSString* kObjects[] = { @"def", @"ghi", @"jkl" }; |
3542 GPBInt32ObjectDictionary *dict2 = | 3542 GPBInt32ObjectDictionary<NSString*> *dict2 = |
3543 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects | 3543 [[GPBInt32ObjectDictionary 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:11], @"abc"); | 3550 XCTAssertEqualObjects([dict objectForKey:11], @"abc"); |
3551 XCTAssertEqualObjects([dict objectForKey:12], @"def"); | 3551 XCTAssertEqualObjects([dict objectForKey:12], @"def"); |
3552 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); | 3552 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); |
3553 XCTAssertEqualObjects([dict objectForKey:14], @"jkl"); | 3553 XCTAssertEqualObjects([dict objectForKey:14], @"jkl"); |
3554 [dict2 release]; | 3554 [dict2 release]; |
3555 } | 3555 } |
3556 | 3556 |
3557 - (void)testRemove { | 3557 - (void)testRemove { |
3558 const int32_t kKeys[] = { 11, 12, 13, 14 }; | 3558 const int32_t kKeys[] = { 11, 12, 13, 14 }; |
3559 const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3559 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
3560 GPBInt32ObjectDictionary *dict = | 3560 GPBInt32ObjectDictionary<NSString*> *dict = |
3561 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects | 3561 [[GPBInt32ObjectDictionary 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:12]; | 3567 [dict removeObjectForKey:12]; |
3568 XCTAssertEqual(dict.count, 3U); | 3568 XCTAssertEqual(dict.count, 3U); |
3569 XCTAssertEqualObjects([dict objectForKey:11], @"abc"); | 3569 XCTAssertEqualObjects([dict objectForKey:11], @"abc"); |
3570 XCTAssertNil([dict objectForKey:12]); | 3570 XCTAssertNil([dict objectForKey:12]); |
(...skipping 19 matching lines...) Expand all Loading... |
3590 XCTAssertEqual(dict.count, 0U); | 3590 XCTAssertEqual(dict.count, 0U); |
3591 XCTAssertNil([dict objectForKey:11]); | 3591 XCTAssertNil([dict objectForKey:11]); |
3592 XCTAssertNil([dict objectForKey:12]); | 3592 XCTAssertNil([dict objectForKey:12]); |
3593 XCTAssertNil([dict objectForKey:13]); | 3593 XCTAssertNil([dict objectForKey:13]); |
3594 XCTAssertNil([dict objectForKey:14]); | 3594 XCTAssertNil([dict objectForKey:14]); |
3595 [dict release]; | 3595 [dict release]; |
3596 } | 3596 } |
3597 | 3597 |
3598 - (void)testInplaceMutation { | 3598 - (void)testInplaceMutation { |
3599 const int32_t kKeys[] = { 11, 12, 13, 14 }; | 3599 const int32_t kKeys[] = { 11, 12, 13, 14 }; |
3600 const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; | 3600 const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; |
3601 GPBInt32ObjectDictionary *dict = | 3601 GPBInt32ObjectDictionary<NSString*> *dict = |
3602 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects | 3602 [[GPBInt32ObjectDictionary 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:11], @"abc"); | 3607 XCTAssertEqualObjects([dict objectForKey:11], @"abc"); |
3608 XCTAssertEqualObjects([dict objectForKey:12], @"def"); | 3608 XCTAssertEqualObjects([dict objectForKey:12], @"def"); |
3609 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); | 3609 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); |
3610 XCTAssertEqualObjects([dict objectForKey:14], @"jkl"); | 3610 XCTAssertEqualObjects([dict objectForKey:14], @"jkl"); |
3611 | 3611 |
3612 [dict setObject:@"jkl" forKey:11]; | 3612 [dict setObject:@"jkl" forKey:11]; |
3613 XCTAssertEqual(dict.count, 4U); | 3613 XCTAssertEqual(dict.count, 4U); |
3614 XCTAssertEqualObjects([dict objectForKey:11], @"jkl"); | 3614 XCTAssertEqualObjects([dict objectForKey:11], @"jkl"); |
3615 XCTAssertEqualObjects([dict objectForKey:12], @"def"); | 3615 XCTAssertEqualObjects([dict objectForKey:12], @"def"); |
3616 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); | 3616 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); |
3617 XCTAssertEqualObjects([dict objectForKey:14], @"jkl"); | 3617 XCTAssertEqualObjects([dict objectForKey:14], @"jkl"); |
3618 | 3618 |
3619 [dict setObject:@"def" forKey:14]; | 3619 [dict setObject:@"def" forKey:14]; |
3620 XCTAssertEqual(dict.count, 4U); | 3620 XCTAssertEqual(dict.count, 4U); |
3621 XCTAssertEqualObjects([dict objectForKey:11], @"jkl"); | 3621 XCTAssertEqualObjects([dict objectForKey:11], @"jkl"); |
3622 XCTAssertEqualObjects([dict objectForKey:12], @"def"); | 3622 XCTAssertEqualObjects([dict objectForKey:12], @"def"); |
3623 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); | 3623 XCTAssertEqualObjects([dict objectForKey:13], @"ghi"); |
3624 XCTAssertEqualObjects([dict objectForKey:14], @"def"); | 3624 XCTAssertEqualObjects([dict objectForKey:14], @"def"); |
3625 | 3625 |
3626 const int32_t kKeys2[] = { 12, 13 }; | 3626 const int32_t kKeys2[] = { 12, 13 }; |
3627 const id kObjects2[] = { @"ghi", @"abc" }; | 3627 const NSString* kObjects2[] = { @"ghi", @"abc" }; |
3628 GPBInt32ObjectDictionary *dict2 = | 3628 GPBInt32ObjectDictionary<NSString*> *dict2 = |
3629 [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2 | 3629 [[GPBInt32ObjectDictionary 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:11], @"jkl"); | 3635 XCTAssertEqualObjects([dict objectForKey:11], @"jkl"); |
3636 XCTAssertEqualObjects([dict objectForKey:12], @"ghi"); | 3636 XCTAssertEqualObjects([dict objectForKey:12], @"ghi"); |
3637 XCTAssertEqualObjects([dict objectForKey:13], @"abc"); | 3637 XCTAssertEqualObjects([dict objectForKey:13], @"abc"); |
3638 XCTAssertEqualObjects([dict objectForKey:14], @"def"); | 3638 XCTAssertEqualObjects([dict objectForKey:14], @"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(Int32, int32_t, 11, 12, 13, 14) | 3646 //%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14) |
3647 | 3647 |
OLD | NEW |