Home | History | Annotate | Download | only in Tests
      1 // Protocol Buffers - Google's data interchange format
      2 // Copyright 2015 Google Inc.  All rights reserved.
      3 // https://developers.google.com/protocol-buffers/
      4 //
      5 // Redistribution and use in source and binary forms, with or without
      6 // modification, are permitted provided that the following conditions are
      7 // met:
      8 //
      9 //     * Redistributions of source code must retain the above copyright
     10 // notice, this list of conditions and the following disclaimer.
     11 //     * Redistributions in binary form must reproduce the above
     12 // copyright notice, this list of conditions and the following disclaimer
     13 // in the documentation and/or other materials provided with the
     14 // distribution.
     15 //     * Neither the name of Google Inc. nor the names of its
     16 // contributors may be used to endorse or promote products derived from
     17 // this software without specific prior written permission.
     18 //
     19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 
     31 #import <Foundation/Foundation.h>
     32 #import <XCTest/XCTest.h>
     33 
     34 #import "GPBDictionary.h"
     35 
     36 #import "GPBTestUtilities.h"
     37 #import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
     38 
     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.
     41 //%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
     42 
     43 //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt32, uint32_t, 100U, 101U)
     44 // This block of code is generated, do not edit it directly.
     45 
     46 #pragma mark - Bool -> UInt32
     47 
     48 @interface GPBBoolUInt32DictionaryTests : XCTestCase
     49 @end
     50 
     51 @implementation GPBBoolUInt32DictionaryTests
     52 
     53 - (void)testEmpty {
     54   GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
     55   XCTAssertNotNil(dict);
     56   XCTAssertEqual(dict.count, 0U);
     57   XCTAssertFalse([dict valueForKey:YES value:NULL]);
     58   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
     59     #pragma unused(aKey, aValue, stop)
     60     XCTFail(@"Shouldn't get here!");
     61   }];
     62   [dict release];
     63 }
     64 
     65 - (void)testOne {
     66   GPBBoolUInt32Dictionary *dict = [GPBBoolUInt32Dictionary dictionaryWithValue:100U forKey:YES];
     67   XCTAssertNotNil(dict);
     68   XCTAssertEqual(dict.count, 1U);
     69   uint32_t value;
     70   XCTAssertTrue([dict valueForKey:YES value:NULL]);
     71   XCTAssertTrue([dict valueForKey:YES value:&value]);
     72   XCTAssertEqual(value, 100U);
     73   XCTAssertFalse([dict valueForKey:NO value:NULL]);
     74   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
     75     XCTAssertEqual(aKey, YES);
     76     XCTAssertEqual(aValue, 100U);
     77     XCTAssertNotEqual(stop, NULL);
     78   }];
     79 }
     80 
     81 - (void)testBasics {
     82   const BOOL kKeys[] = { YES, NO };
     83   const uint32_t kValues[] = { 100U, 101U };
     84   GPBBoolUInt32Dictionary *dict =
     85       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues
     86                                               forKeys:kKeys
     87                                                 count:GPBARRAYSIZE(kValues)];
     88   XCTAssertNotNil(dict);
     89   XCTAssertEqual(dict.count, 2U);
     90   uint32_t value;
     91   XCTAssertTrue([dict valueForKey:YES value:NULL]);
     92   XCTAssertTrue([dict valueForKey:YES value:&value]);
     93   XCTAssertEqual(value, 100U);
     94   XCTAssertTrue([dict valueForKey:NO value:NULL]);
     95   XCTAssertTrue([dict valueForKey:NO value:&value]);
     96   XCTAssertEqual(value, 101U);
     97 
     98   __block NSUInteger idx = 0;
     99   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
    100   uint32_t *seenValues = malloc(2 * sizeof(uint32_t));
    101   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
    102     XCTAssertLessThan(idx, 2U);
    103     seenKeys[idx] = aKey;
    104     seenValues[idx] = aValue;
    105     XCTAssertNotEqual(stop, NULL);
    106     ++idx;
    107   }];
    108   for (int i = 0; i < 2; ++i) {
    109     BOOL foundKey = NO;
    110     for (int j = 0; (j < 2) && !foundKey; ++j) {
    111       if (kKeys[i] == seenKeys[j]) {
    112         foundKey = YES;
    113         XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
    114       }
    115     }
    116     XCTAssertTrue(foundKey, @"i = %d", i);
    117   }
    118   free(seenKeys);
    119   free(seenValues);
    120 
    121   // Stopping the enumeration.
    122   idx = 0;
    123   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
    124     #pragma unused(aKey, aValue)
    125     if (idx == 0) *stop = YES;
    126     XCTAssertNotEqual(idx, 2U);
    127     ++idx;
    128   }];
    129   [dict release];
    130 }
    131 
    132 - (void)testEquality {
    133   const BOOL kKeys1[] = { YES, NO };
    134   const BOOL kKeys2[] = { NO, YES };
    135   const uint32_t kValues1[] = { 100U, 101U };
    136   const uint32_t kValues2[] = { 101U, 100U };
    137   const uint32_t kValues3[] = { 101U };
    138   GPBBoolUInt32Dictionary *dict1 =
    139       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues1
    140                                               forKeys:kKeys1
    141                                                 count:GPBARRAYSIZE(kValues1)];
    142   XCTAssertNotNil(dict1);
    143   GPBBoolUInt32Dictionary *dict1prime =
    144       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues1
    145                                               forKeys:kKeys1
    146                                                 count:GPBARRAYSIZE(kValues1)];
    147   XCTAssertNotNil(dict1prime);
    148   GPBBoolUInt32Dictionary *dict2 =
    149       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues2
    150                                               forKeys:kKeys1
    151                                                 count:GPBARRAYSIZE(kValues2)];
    152   XCTAssertNotNil(dict2);
    153   GPBBoolUInt32Dictionary *dict3 =
    154       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues1
    155                                               forKeys:kKeys2
    156                                                 count:GPBARRAYSIZE(kValues1)];
    157   XCTAssertNotNil(dict3);
    158   GPBBoolUInt32Dictionary *dict4 =
    159       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues3
    160                                               forKeys:kKeys1
    161                                                 count:GPBARRAYSIZE(kValues3)];
    162   XCTAssertNotNil(dict4);
    163 
    164   // 1/1Prime should be different objects, but equal.
    165   XCTAssertNotEqual(dict1, dict1prime);
    166   XCTAssertEqualObjects(dict1, dict1prime);
    167   // Equal, so they must have same hash.
    168   XCTAssertEqual([dict1 hash], [dict1prime hash]);
    169 
    170   // 2 is same keys, different values; not equal.
    171   XCTAssertNotEqualObjects(dict1, dict2);
    172 
    173   // 3 is different keys, same values; not equal.
    174   XCTAssertNotEqualObjects(dict1, dict3);
    175 
    176   // 4 Fewer pairs; not equal
    177   XCTAssertNotEqualObjects(dict1, dict4);
    178 
    179   [dict1 release];
    180   [dict1prime release];
    181   [dict2 release];
    182   [dict3 release];
    183   [dict4 release];
    184 }
    185 
    186 - (void)testCopy {
    187   const BOOL kKeys[] = { YES, NO };
    188   const uint32_t kValues[] = { 100U, 101U };
    189   GPBBoolUInt32Dictionary *dict =
    190       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues
    191                                               forKeys:kKeys
    192                                                 count:GPBARRAYSIZE(kValues)];
    193   XCTAssertNotNil(dict);
    194 
    195   GPBBoolUInt32Dictionary *dict2 = [dict copy];
    196   XCTAssertNotNil(dict2);
    197 
    198   // Should be new object but equal.
    199   XCTAssertNotEqual(dict, dict2);
    200   XCTAssertEqualObjects(dict, dict2);
    201   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt32Dictionary class]]);
    202 
    203   [dict2 release];
    204   [dict release];
    205 }
    206 
    207 - (void)testDictionaryFromDictionary {
    208   const BOOL kKeys[] = { YES, NO };
    209   const uint32_t kValues[] = { 100U, 101U };
    210   GPBBoolUInt32Dictionary *dict =
    211       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues
    212                                               forKeys:kKeys
    213                                                 count:GPBARRAYSIZE(kValues)];
    214   XCTAssertNotNil(dict);
    215 
    216   GPBBoolUInt32Dictionary *dict2 =
    217       [GPBBoolUInt32Dictionary dictionaryWithDictionary:dict];
    218   XCTAssertNotNil(dict2);
    219 
    220   // Should be new pointer, but equal objects.
    221   XCTAssertNotEqual(dict, dict2);
    222   XCTAssertEqualObjects(dict, dict2);
    223   [dict release];
    224 }
    225 
    226 - (void)testAdds {
    227   GPBBoolUInt32Dictionary *dict = [GPBBoolUInt32Dictionary dictionary];
    228   XCTAssertNotNil(dict);
    229 
    230   XCTAssertEqual(dict.count, 0U);
    231   [dict setValue:100U forKey:YES];
    232   XCTAssertEqual(dict.count, 1U);
    233 
    234   const BOOL kKeys[] = { NO };
    235   const uint32_t kValues[] = { 101U };
    236   GPBBoolUInt32Dictionary *dict2 =
    237       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues
    238                                               forKeys:kKeys
    239                                                 count:GPBARRAYSIZE(kValues)];
    240   XCTAssertNotNil(dict2);
    241   [dict addEntriesFromDictionary:dict2];
    242   XCTAssertEqual(dict.count, 2U);
    243 
    244   uint32_t value;
    245   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    246   XCTAssertTrue([dict valueForKey:YES value:&value]);
    247   XCTAssertEqual(value, 100U);
    248   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    249   XCTAssertTrue([dict valueForKey:NO value:&value]);
    250   XCTAssertEqual(value, 101U);
    251   [dict2 release];
    252 }
    253 
    254 - (void)testRemove {
    255   const BOOL kKeys[] = { YES, NO};
    256   const uint32_t kValues[] = { 100U, 101U };
    257   GPBBoolUInt32Dictionary *dict =
    258       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues
    259                                        forKeys:kKeys
    260                                          count:GPBARRAYSIZE(kValues)];
    261   XCTAssertNotNil(dict);
    262   XCTAssertEqual(dict.count, 2U);
    263 
    264   [dict removeValueForKey:NO];
    265   XCTAssertEqual(dict.count, 1U);
    266   uint32_t value;
    267   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    268   XCTAssertTrue([dict valueForKey:YES value:&value]);
    269   XCTAssertEqual(value, 100U);
    270   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    271 
    272   // Remove again does nothing.
    273   [dict removeValueForKey:NO];
    274   XCTAssertEqual(dict.count, 1U);
    275   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    276   XCTAssertTrue([dict valueForKey:YES value:&value]);
    277   XCTAssertEqual(value, 100U);
    278   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    279 
    280   [dict removeAll];
    281   XCTAssertEqual(dict.count, 0U);
    282   XCTAssertFalse([dict valueForKey:YES value:NULL]);
    283   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    284   [dict release];
    285 }
    286 
    287 - (void)testInplaceMutation {
    288   const BOOL kKeys[] = { YES, NO };
    289   const uint32_t kValues[] = { 100U, 101U };
    290   GPBBoolUInt32Dictionary *dict =
    291       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues
    292                                        forKeys:kKeys
    293                                          count:GPBARRAYSIZE(kValues)];
    294   XCTAssertNotNil(dict);
    295   XCTAssertEqual(dict.count, 2U);
    296   uint32_t value;
    297   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    298   XCTAssertTrue([dict valueForKey:YES value:&value]);
    299   XCTAssertEqual(value, 100U);
    300   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    301   XCTAssertTrue([dict valueForKey:NO value:&value]);
    302   XCTAssertEqual(value, 101U);
    303 
    304   [dict setValue:101U forKey:YES];
    305   XCTAssertEqual(dict.count, 2U);
    306   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    307   XCTAssertTrue([dict valueForKey:YES value:&value]);
    308   XCTAssertEqual(value, 101U);
    309   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    310   XCTAssertTrue([dict valueForKey:NO value:&value]);
    311   XCTAssertEqual(value, 101U);
    312 
    313   [dict setValue:100U forKey:NO];
    314   XCTAssertEqual(dict.count, 2U);
    315   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    316   XCTAssertTrue([dict valueForKey:YES value:&value]);
    317   XCTAssertEqual(value, 101U);
    318   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    319   XCTAssertTrue([dict valueForKey:NO value:&value]);
    320   XCTAssertEqual(value, 100U);
    321 
    322   const BOOL kKeys2[] = { NO, YES };
    323   const uint32_t kValues2[] = { 101U, 100U };
    324   GPBBoolUInt32Dictionary *dict2 =
    325       [[GPBBoolUInt32Dictionary alloc] initWithValues:kValues2
    326                                               forKeys:kKeys2
    327                                                 count:GPBARRAYSIZE(kValues2)];
    328   XCTAssertNotNil(dict2);
    329   [dict addEntriesFromDictionary:dict2];
    330   XCTAssertEqual(dict.count, 2U);
    331   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    332   XCTAssertTrue([dict valueForKey:YES value:&value]);
    333   XCTAssertEqual(value, 100U);
    334   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    335   XCTAssertTrue([dict valueForKey:NO value:&value]);
    336   XCTAssertEqual(value, 101U);
    337 
    338   [dict2 release];
    339   [dict release];
    340 }
    341 
    342 @end
    343 
    344 //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int32, int32_t, 200, 201)
    345 // This block of code is generated, do not edit it directly.
    346 
    347 #pragma mark - Bool -> Int32
    348 
    349 @interface GPBBoolInt32DictionaryTests : XCTestCase
    350 @end
    351 
    352 @implementation GPBBoolInt32DictionaryTests
    353 
    354 - (void)testEmpty {
    355   GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
    356   XCTAssertNotNil(dict);
    357   XCTAssertEqual(dict.count, 0U);
    358   XCTAssertFalse([dict valueForKey:YES value:NULL]);
    359   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
    360     #pragma unused(aKey, aValue, stop)
    361     XCTFail(@"Shouldn't get here!");
    362   }];
    363   [dict release];
    364 }
    365 
    366 - (void)testOne {
    367   GPBBoolInt32Dictionary *dict = [GPBBoolInt32Dictionary dictionaryWithValue:200 forKey:YES];
    368   XCTAssertNotNil(dict);
    369   XCTAssertEqual(dict.count, 1U);
    370   int32_t value;
    371   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    372   XCTAssertTrue([dict valueForKey:YES value:&value]);
    373   XCTAssertEqual(value, 200);
    374   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    375   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
    376     XCTAssertEqual(aKey, YES);
    377     XCTAssertEqual(aValue, 200);
    378     XCTAssertNotEqual(stop, NULL);
    379   }];
    380 }
    381 
    382 - (void)testBasics {
    383   const BOOL kKeys[] = { YES, NO };
    384   const int32_t kValues[] = { 200, 201 };
    385   GPBBoolInt32Dictionary *dict =
    386       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues
    387                                              forKeys:kKeys
    388                                                count:GPBARRAYSIZE(kValues)];
    389   XCTAssertNotNil(dict);
    390   XCTAssertEqual(dict.count, 2U);
    391   int32_t value;
    392   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    393   XCTAssertTrue([dict valueForKey:YES value:&value]);
    394   XCTAssertEqual(value, 200);
    395   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    396   XCTAssertTrue([dict valueForKey:NO value:&value]);
    397   XCTAssertEqual(value, 201);
    398 
    399   __block NSUInteger idx = 0;
    400   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
    401   int32_t *seenValues = malloc(2 * sizeof(int32_t));
    402   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
    403     XCTAssertLessThan(idx, 2U);
    404     seenKeys[idx] = aKey;
    405     seenValues[idx] = aValue;
    406     XCTAssertNotEqual(stop, NULL);
    407     ++idx;
    408   }];
    409   for (int i = 0; i < 2; ++i) {
    410     BOOL foundKey = NO;
    411     for (int j = 0; (j < 2) && !foundKey; ++j) {
    412       if (kKeys[i] == seenKeys[j]) {
    413         foundKey = YES;
    414         XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
    415       }
    416     }
    417     XCTAssertTrue(foundKey, @"i = %d", i);
    418   }
    419   free(seenKeys);
    420   free(seenValues);
    421 
    422   // Stopping the enumeration.
    423   idx = 0;
    424   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
    425     #pragma unused(aKey, aValue)
    426     if (idx == 0) *stop = YES;
    427     XCTAssertNotEqual(idx, 2U);
    428     ++idx;
    429   }];
    430   [dict release];
    431 }
    432 
    433 - (void)testEquality {
    434   const BOOL kKeys1[] = { YES, NO };
    435   const BOOL kKeys2[] = { NO, YES };
    436   const int32_t kValues1[] = { 200, 201 };
    437   const int32_t kValues2[] = { 201, 200 };
    438   const int32_t kValues3[] = { 201 };
    439   GPBBoolInt32Dictionary *dict1 =
    440       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues1
    441                                              forKeys:kKeys1
    442                                                count:GPBARRAYSIZE(kValues1)];
    443   XCTAssertNotNil(dict1);
    444   GPBBoolInt32Dictionary *dict1prime =
    445       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues1
    446                                              forKeys:kKeys1
    447                                                count:GPBARRAYSIZE(kValues1)];
    448   XCTAssertNotNil(dict1prime);
    449   GPBBoolInt32Dictionary *dict2 =
    450       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues2
    451                                              forKeys:kKeys1
    452                                                count:GPBARRAYSIZE(kValues2)];
    453   XCTAssertNotNil(dict2);
    454   GPBBoolInt32Dictionary *dict3 =
    455       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues1
    456                                              forKeys:kKeys2
    457                                                count:GPBARRAYSIZE(kValues1)];
    458   XCTAssertNotNil(dict3);
    459   GPBBoolInt32Dictionary *dict4 =
    460       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues3
    461                                              forKeys:kKeys1
    462                                                count:GPBARRAYSIZE(kValues3)];
    463   XCTAssertNotNil(dict4);
    464 
    465   // 1/1Prime should be different objects, but equal.
    466   XCTAssertNotEqual(dict1, dict1prime);
    467   XCTAssertEqualObjects(dict1, dict1prime);
    468   // Equal, so they must have same hash.
    469   XCTAssertEqual([dict1 hash], [dict1prime hash]);
    470 
    471   // 2 is same keys, different values; not equal.
    472   XCTAssertNotEqualObjects(dict1, dict2);
    473 
    474   // 3 is different keys, same values; not equal.
    475   XCTAssertNotEqualObjects(dict1, dict3);
    476 
    477   // 4 Fewer pairs; not equal
    478   XCTAssertNotEqualObjects(dict1, dict4);
    479 
    480   [dict1 release];
    481   [dict1prime release];
    482   [dict2 release];
    483   [dict3 release];
    484   [dict4 release];
    485 }
    486 
    487 - (void)testCopy {
    488   const BOOL kKeys[] = { YES, NO };
    489   const int32_t kValues[] = { 200, 201 };
    490   GPBBoolInt32Dictionary *dict =
    491       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues
    492                                              forKeys:kKeys
    493                                                count:GPBARRAYSIZE(kValues)];
    494   XCTAssertNotNil(dict);
    495 
    496   GPBBoolInt32Dictionary *dict2 = [dict copy];
    497   XCTAssertNotNil(dict2);
    498 
    499   // Should be new object but equal.
    500   XCTAssertNotEqual(dict, dict2);
    501   XCTAssertEqualObjects(dict, dict2);
    502   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt32Dictionary class]]);
    503 
    504   [dict2 release];
    505   [dict release];
    506 }
    507 
    508 - (void)testDictionaryFromDictionary {
    509   const BOOL kKeys[] = { YES, NO };
    510   const int32_t kValues[] = { 200, 201 };
    511   GPBBoolInt32Dictionary *dict =
    512       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues
    513                                              forKeys:kKeys
    514                                                count:GPBARRAYSIZE(kValues)];
    515   XCTAssertNotNil(dict);
    516 
    517   GPBBoolInt32Dictionary *dict2 =
    518       [GPBBoolInt32Dictionary dictionaryWithDictionary:dict];
    519   XCTAssertNotNil(dict2);
    520 
    521   // Should be new pointer, but equal objects.
    522   XCTAssertNotEqual(dict, dict2);
    523   XCTAssertEqualObjects(dict, dict2);
    524   [dict release];
    525 }
    526 
    527 - (void)testAdds {
    528   GPBBoolInt32Dictionary *dict = [GPBBoolInt32Dictionary dictionary];
    529   XCTAssertNotNil(dict);
    530 
    531   XCTAssertEqual(dict.count, 0U);
    532   [dict setValue:200 forKey:YES];
    533   XCTAssertEqual(dict.count, 1U);
    534 
    535   const BOOL kKeys[] = { NO };
    536   const int32_t kValues[] = { 201 };
    537   GPBBoolInt32Dictionary *dict2 =
    538       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues
    539                                              forKeys:kKeys
    540                                                count:GPBARRAYSIZE(kValues)];
    541   XCTAssertNotNil(dict2);
    542   [dict addEntriesFromDictionary:dict2];
    543   XCTAssertEqual(dict.count, 2U);
    544 
    545   int32_t value;
    546   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    547   XCTAssertTrue([dict valueForKey:YES value:&value]);
    548   XCTAssertEqual(value, 200);
    549   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    550   XCTAssertTrue([dict valueForKey:NO value:&value]);
    551   XCTAssertEqual(value, 201);
    552   [dict2 release];
    553 }
    554 
    555 - (void)testRemove {
    556   const BOOL kKeys[] = { YES, NO};
    557   const int32_t kValues[] = { 200, 201 };
    558   GPBBoolInt32Dictionary *dict =
    559       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues
    560                                       forKeys:kKeys
    561                                         count:GPBARRAYSIZE(kValues)];
    562   XCTAssertNotNil(dict);
    563   XCTAssertEqual(dict.count, 2U);
    564 
    565   [dict removeValueForKey:NO];
    566   XCTAssertEqual(dict.count, 1U);
    567   int32_t value;
    568   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    569   XCTAssertTrue([dict valueForKey:YES value:&value]);
    570   XCTAssertEqual(value, 200);
    571   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    572 
    573   // Remove again does nothing.
    574   [dict removeValueForKey:NO];
    575   XCTAssertEqual(dict.count, 1U);
    576   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    577   XCTAssertTrue([dict valueForKey:YES value:&value]);
    578   XCTAssertEqual(value, 200);
    579   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    580 
    581   [dict removeAll];
    582   XCTAssertEqual(dict.count, 0U);
    583   XCTAssertFalse([dict valueForKey:YES value:NULL]);
    584   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    585   [dict release];
    586 }
    587 
    588 - (void)testInplaceMutation {
    589   const BOOL kKeys[] = { YES, NO };
    590   const int32_t kValues[] = { 200, 201 };
    591   GPBBoolInt32Dictionary *dict =
    592       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues
    593                                       forKeys:kKeys
    594                                         count:GPBARRAYSIZE(kValues)];
    595   XCTAssertNotNil(dict);
    596   XCTAssertEqual(dict.count, 2U);
    597   int32_t value;
    598   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    599   XCTAssertTrue([dict valueForKey:YES value:&value]);
    600   XCTAssertEqual(value, 200);
    601   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    602   XCTAssertTrue([dict valueForKey:NO value:&value]);
    603   XCTAssertEqual(value, 201);
    604 
    605   [dict setValue:201 forKey:YES];
    606   XCTAssertEqual(dict.count, 2U);
    607   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    608   XCTAssertTrue([dict valueForKey:YES value:&value]);
    609   XCTAssertEqual(value, 201);
    610   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    611   XCTAssertTrue([dict valueForKey:NO value:&value]);
    612   XCTAssertEqual(value, 201);
    613 
    614   [dict setValue:200 forKey:NO];
    615   XCTAssertEqual(dict.count, 2U);
    616   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    617   XCTAssertTrue([dict valueForKey:YES value:&value]);
    618   XCTAssertEqual(value, 201);
    619   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    620   XCTAssertTrue([dict valueForKey:NO value:&value]);
    621   XCTAssertEqual(value, 200);
    622 
    623   const BOOL kKeys2[] = { NO, YES };
    624   const int32_t kValues2[] = { 201, 200 };
    625   GPBBoolInt32Dictionary *dict2 =
    626       [[GPBBoolInt32Dictionary alloc] initWithValues:kValues2
    627                                              forKeys:kKeys2
    628                                                count:GPBARRAYSIZE(kValues2)];
    629   XCTAssertNotNil(dict2);
    630   [dict addEntriesFromDictionary:dict2];
    631   XCTAssertEqual(dict.count, 2U);
    632   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    633   XCTAssertTrue([dict valueForKey:YES value:&value]);
    634   XCTAssertEqual(value, 200);
    635   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    636   XCTAssertTrue([dict valueForKey:NO value:&value]);
    637   XCTAssertEqual(value, 201);
    638 
    639   [dict2 release];
    640   [dict release];
    641 }
    642 
    643 @end
    644 
    645 //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt64, uint64_t, 300U, 301U)
    646 // This block of code is generated, do not edit it directly.
    647 
    648 #pragma mark - Bool -> UInt64
    649 
    650 @interface GPBBoolUInt64DictionaryTests : XCTestCase
    651 @end
    652 
    653 @implementation GPBBoolUInt64DictionaryTests
    654 
    655 - (void)testEmpty {
    656   GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
    657   XCTAssertNotNil(dict);
    658   XCTAssertEqual(dict.count, 0U);
    659   XCTAssertFalse([dict valueForKey:YES value:NULL]);
    660   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
    661     #pragma unused(aKey, aValue, stop)
    662     XCTFail(@"Shouldn't get here!");
    663   }];
    664   [dict release];
    665 }
    666 
    667 - (void)testOne {
    668   GPBBoolUInt64Dictionary *dict = [GPBBoolUInt64Dictionary dictionaryWithValue:300U forKey:YES];
    669   XCTAssertNotNil(dict);
    670   XCTAssertEqual(dict.count, 1U);
    671   uint64_t value;
    672   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    673   XCTAssertTrue([dict valueForKey:YES value:&value]);
    674   XCTAssertEqual(value, 300U);
    675   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    676   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
    677     XCTAssertEqual(aKey, YES);
    678     XCTAssertEqual(aValue, 300U);
    679     XCTAssertNotEqual(stop, NULL);
    680   }];
    681 }
    682 
    683 - (void)testBasics {
    684   const BOOL kKeys[] = { YES, NO };
    685   const uint64_t kValues[] = { 300U, 301U };
    686   GPBBoolUInt64Dictionary *dict =
    687       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues
    688                                               forKeys:kKeys
    689                                                 count:GPBARRAYSIZE(kValues)];
    690   XCTAssertNotNil(dict);
    691   XCTAssertEqual(dict.count, 2U);
    692   uint64_t value;
    693   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    694   XCTAssertTrue([dict valueForKey:YES value:&value]);
    695   XCTAssertEqual(value, 300U);
    696   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    697   XCTAssertTrue([dict valueForKey:NO value:&value]);
    698   XCTAssertEqual(value, 301U);
    699 
    700   __block NSUInteger idx = 0;
    701   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
    702   uint64_t *seenValues = malloc(2 * sizeof(uint64_t));
    703   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
    704     XCTAssertLessThan(idx, 2U);
    705     seenKeys[idx] = aKey;
    706     seenValues[idx] = aValue;
    707     XCTAssertNotEqual(stop, NULL);
    708     ++idx;
    709   }];
    710   for (int i = 0; i < 2; ++i) {
    711     BOOL foundKey = NO;
    712     for (int j = 0; (j < 2) && !foundKey; ++j) {
    713       if (kKeys[i] == seenKeys[j]) {
    714         foundKey = YES;
    715         XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
    716       }
    717     }
    718     XCTAssertTrue(foundKey, @"i = %d", i);
    719   }
    720   free(seenKeys);
    721   free(seenValues);
    722 
    723   // Stopping the enumeration.
    724   idx = 0;
    725   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
    726     #pragma unused(aKey, aValue)
    727     if (idx == 0) *stop = YES;
    728     XCTAssertNotEqual(idx, 2U);
    729     ++idx;
    730   }];
    731   [dict release];
    732 }
    733 
    734 - (void)testEquality {
    735   const BOOL kKeys1[] = { YES, NO };
    736   const BOOL kKeys2[] = { NO, YES };
    737   const uint64_t kValues1[] = { 300U, 301U };
    738   const uint64_t kValues2[] = { 301U, 300U };
    739   const uint64_t kValues3[] = { 301U };
    740   GPBBoolUInt64Dictionary *dict1 =
    741       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues1
    742                                               forKeys:kKeys1
    743                                                 count:GPBARRAYSIZE(kValues1)];
    744   XCTAssertNotNil(dict1);
    745   GPBBoolUInt64Dictionary *dict1prime =
    746       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues1
    747                                               forKeys:kKeys1
    748                                                 count:GPBARRAYSIZE(kValues1)];
    749   XCTAssertNotNil(dict1prime);
    750   GPBBoolUInt64Dictionary *dict2 =
    751       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues2
    752                                               forKeys:kKeys1
    753                                                 count:GPBARRAYSIZE(kValues2)];
    754   XCTAssertNotNil(dict2);
    755   GPBBoolUInt64Dictionary *dict3 =
    756       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues1
    757                                               forKeys:kKeys2
    758                                                 count:GPBARRAYSIZE(kValues1)];
    759   XCTAssertNotNil(dict3);
    760   GPBBoolUInt64Dictionary *dict4 =
    761       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues3
    762                                               forKeys:kKeys1
    763                                                 count:GPBARRAYSIZE(kValues3)];
    764   XCTAssertNotNil(dict4);
    765 
    766   // 1/1Prime should be different objects, but equal.
    767   XCTAssertNotEqual(dict1, dict1prime);
    768   XCTAssertEqualObjects(dict1, dict1prime);
    769   // Equal, so they must have same hash.
    770   XCTAssertEqual([dict1 hash], [dict1prime hash]);
    771 
    772   // 2 is same keys, different values; not equal.
    773   XCTAssertNotEqualObjects(dict1, dict2);
    774 
    775   // 3 is different keys, same values; not equal.
    776   XCTAssertNotEqualObjects(dict1, dict3);
    777 
    778   // 4 Fewer pairs; not equal
    779   XCTAssertNotEqualObjects(dict1, dict4);
    780 
    781   [dict1 release];
    782   [dict1prime release];
    783   [dict2 release];
    784   [dict3 release];
    785   [dict4 release];
    786 }
    787 
    788 - (void)testCopy {
    789   const BOOL kKeys[] = { YES, NO };
    790   const uint64_t kValues[] = { 300U, 301U };
    791   GPBBoolUInt64Dictionary *dict =
    792       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues
    793                                               forKeys:kKeys
    794                                                 count:GPBARRAYSIZE(kValues)];
    795   XCTAssertNotNil(dict);
    796 
    797   GPBBoolUInt64Dictionary *dict2 = [dict copy];
    798   XCTAssertNotNil(dict2);
    799 
    800   // Should be new object but equal.
    801   XCTAssertNotEqual(dict, dict2);
    802   XCTAssertEqualObjects(dict, dict2);
    803   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt64Dictionary class]]);
    804 
    805   [dict2 release];
    806   [dict release];
    807 }
    808 
    809 - (void)testDictionaryFromDictionary {
    810   const BOOL kKeys[] = { YES, NO };
    811   const uint64_t kValues[] = { 300U, 301U };
    812   GPBBoolUInt64Dictionary *dict =
    813       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues
    814                                               forKeys:kKeys
    815                                                 count:GPBARRAYSIZE(kValues)];
    816   XCTAssertNotNil(dict);
    817 
    818   GPBBoolUInt64Dictionary *dict2 =
    819       [GPBBoolUInt64Dictionary dictionaryWithDictionary:dict];
    820   XCTAssertNotNil(dict2);
    821 
    822   // Should be new pointer, but equal objects.
    823   XCTAssertNotEqual(dict, dict2);
    824   XCTAssertEqualObjects(dict, dict2);
    825   [dict release];
    826 }
    827 
    828 - (void)testAdds {
    829   GPBBoolUInt64Dictionary *dict = [GPBBoolUInt64Dictionary dictionary];
    830   XCTAssertNotNil(dict);
    831 
    832   XCTAssertEqual(dict.count, 0U);
    833   [dict setValue:300U forKey:YES];
    834   XCTAssertEqual(dict.count, 1U);
    835 
    836   const BOOL kKeys[] = { NO };
    837   const uint64_t kValues[] = { 301U };
    838   GPBBoolUInt64Dictionary *dict2 =
    839       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues
    840                                               forKeys:kKeys
    841                                                 count:GPBARRAYSIZE(kValues)];
    842   XCTAssertNotNil(dict2);
    843   [dict addEntriesFromDictionary:dict2];
    844   XCTAssertEqual(dict.count, 2U);
    845 
    846   uint64_t value;
    847   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    848   XCTAssertTrue([dict valueForKey:YES value:&value]);
    849   XCTAssertEqual(value, 300U);
    850   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    851   XCTAssertTrue([dict valueForKey:NO value:&value]);
    852   XCTAssertEqual(value, 301U);
    853   [dict2 release];
    854 }
    855 
    856 - (void)testRemove {
    857   const BOOL kKeys[] = { YES, NO};
    858   const uint64_t kValues[] = { 300U, 301U };
    859   GPBBoolUInt64Dictionary *dict =
    860       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues
    861                                        forKeys:kKeys
    862                                          count:GPBARRAYSIZE(kValues)];
    863   XCTAssertNotNil(dict);
    864   XCTAssertEqual(dict.count, 2U);
    865 
    866   [dict removeValueForKey:NO];
    867   XCTAssertEqual(dict.count, 1U);
    868   uint64_t value;
    869   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    870   XCTAssertTrue([dict valueForKey:YES value:&value]);
    871   XCTAssertEqual(value, 300U);
    872   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    873 
    874   // Remove again does nothing.
    875   [dict removeValueForKey:NO];
    876   XCTAssertEqual(dict.count, 1U);
    877   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    878   XCTAssertTrue([dict valueForKey:YES value:&value]);
    879   XCTAssertEqual(value, 300U);
    880   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    881 
    882   [dict removeAll];
    883   XCTAssertEqual(dict.count, 0U);
    884   XCTAssertFalse([dict valueForKey:YES value:NULL]);
    885   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    886   [dict release];
    887 }
    888 
    889 - (void)testInplaceMutation {
    890   const BOOL kKeys[] = { YES, NO };
    891   const uint64_t kValues[] = { 300U, 301U };
    892   GPBBoolUInt64Dictionary *dict =
    893       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues
    894                                        forKeys:kKeys
    895                                          count:GPBARRAYSIZE(kValues)];
    896   XCTAssertNotNil(dict);
    897   XCTAssertEqual(dict.count, 2U);
    898   uint64_t value;
    899   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    900   XCTAssertTrue([dict valueForKey:YES value:&value]);
    901   XCTAssertEqual(value, 300U);
    902   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    903   XCTAssertTrue([dict valueForKey:NO value:&value]);
    904   XCTAssertEqual(value, 301U);
    905 
    906   [dict setValue:301U forKey:YES];
    907   XCTAssertEqual(dict.count, 2U);
    908   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    909   XCTAssertTrue([dict valueForKey:YES value:&value]);
    910   XCTAssertEqual(value, 301U);
    911   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    912   XCTAssertTrue([dict valueForKey:NO value:&value]);
    913   XCTAssertEqual(value, 301U);
    914 
    915   [dict setValue:300U forKey:NO];
    916   XCTAssertEqual(dict.count, 2U);
    917   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    918   XCTAssertTrue([dict valueForKey:YES value:&value]);
    919   XCTAssertEqual(value, 301U);
    920   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    921   XCTAssertTrue([dict valueForKey:NO value:&value]);
    922   XCTAssertEqual(value, 300U);
    923 
    924   const BOOL kKeys2[] = { NO, YES };
    925   const uint64_t kValues2[] = { 301U, 300U };
    926   GPBBoolUInt64Dictionary *dict2 =
    927       [[GPBBoolUInt64Dictionary alloc] initWithValues:kValues2
    928                                               forKeys:kKeys2
    929                                                 count:GPBARRAYSIZE(kValues2)];
    930   XCTAssertNotNil(dict2);
    931   [dict addEntriesFromDictionary:dict2];
    932   XCTAssertEqual(dict.count, 2U);
    933   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    934   XCTAssertTrue([dict valueForKey:YES value:&value]);
    935   XCTAssertEqual(value, 300U);
    936   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    937   XCTAssertTrue([dict valueForKey:NO value:&value]);
    938   XCTAssertEqual(value, 301U);
    939 
    940   [dict2 release];
    941   [dict release];
    942 }
    943 
    944 @end
    945 
    946 //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int64, int64_t, 400, 401)
    947 // This block of code is generated, do not edit it directly.
    948 
    949 #pragma mark - Bool -> Int64
    950 
    951 @interface GPBBoolInt64DictionaryTests : XCTestCase
    952 @end
    953 
    954 @implementation GPBBoolInt64DictionaryTests
    955 
    956 - (void)testEmpty {
    957   GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
    958   XCTAssertNotNil(dict);
    959   XCTAssertEqual(dict.count, 0U);
    960   XCTAssertFalse([dict valueForKey:YES value:NULL]);
    961   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
    962     #pragma unused(aKey, aValue, stop)
    963     XCTFail(@"Shouldn't get here!");
    964   }];
    965   [dict release];
    966 }
    967 
    968 - (void)testOne {
    969   GPBBoolInt64Dictionary *dict = [GPBBoolInt64Dictionary dictionaryWithValue:400 forKey:YES];
    970   XCTAssertNotNil(dict);
    971   XCTAssertEqual(dict.count, 1U);
    972   int64_t value;
    973   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    974   XCTAssertTrue([dict valueForKey:YES value:&value]);
    975   XCTAssertEqual(value, 400);
    976   XCTAssertFalse([dict valueForKey:NO value:NULL]);
    977   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
    978     XCTAssertEqual(aKey, YES);
    979     XCTAssertEqual(aValue, 400);
    980     XCTAssertNotEqual(stop, NULL);
    981   }];
    982 }
    983 
    984 - (void)testBasics {
    985   const BOOL kKeys[] = { YES, NO };
    986   const int64_t kValues[] = { 400, 401 };
    987   GPBBoolInt64Dictionary *dict =
    988       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues
    989                                              forKeys:kKeys
    990                                                count:GPBARRAYSIZE(kValues)];
    991   XCTAssertNotNil(dict);
    992   XCTAssertEqual(dict.count, 2U);
    993   int64_t value;
    994   XCTAssertTrue([dict valueForKey:YES value:NULL]);
    995   XCTAssertTrue([dict valueForKey:YES value:&value]);
    996   XCTAssertEqual(value, 400);
    997   XCTAssertTrue([dict valueForKey:NO value:NULL]);
    998   XCTAssertTrue([dict valueForKey:NO value:&value]);
    999   XCTAssertEqual(value, 401);
   1000 
   1001   __block NSUInteger idx = 0;
   1002   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
   1003   int64_t *seenValues = malloc(2 * sizeof(int64_t));
   1004   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
   1005     XCTAssertLessThan(idx, 2U);
   1006     seenKeys[idx] = aKey;
   1007     seenValues[idx] = aValue;
   1008     XCTAssertNotEqual(stop, NULL);
   1009     ++idx;
   1010   }];
   1011   for (int i = 0; i < 2; ++i) {
   1012     BOOL foundKey = NO;
   1013     for (int j = 0; (j < 2) && !foundKey; ++j) {
   1014       if (kKeys[i] == seenKeys[j]) {
   1015         foundKey = YES;
   1016         XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
   1017       }
   1018     }
   1019     XCTAssertTrue(foundKey, @"i = %d", i);
   1020   }
   1021   free(seenKeys);
   1022   free(seenValues);
   1023 
   1024   // Stopping the enumeration.
   1025   idx = 0;
   1026   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
   1027     #pragma unused(aKey, aValue)
   1028     if (idx == 0) *stop = YES;
   1029     XCTAssertNotEqual(idx, 2U);
   1030     ++idx;
   1031   }];
   1032   [dict release];
   1033 }
   1034 
   1035 - (void)testEquality {
   1036   const BOOL kKeys1[] = { YES, NO };
   1037   const BOOL kKeys2[] = { NO, YES };
   1038   const int64_t kValues1[] = { 400, 401 };
   1039   const int64_t kValues2[] = { 401, 400 };
   1040   const int64_t kValues3[] = { 401 };
   1041   GPBBoolInt64Dictionary *dict1 =
   1042       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues1
   1043                                              forKeys:kKeys1
   1044                                                count:GPBARRAYSIZE(kValues1)];
   1045   XCTAssertNotNil(dict1);
   1046   GPBBoolInt64Dictionary *dict1prime =
   1047       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues1
   1048                                              forKeys:kKeys1
   1049                                                count:GPBARRAYSIZE(kValues1)];
   1050   XCTAssertNotNil(dict1prime);
   1051   GPBBoolInt64Dictionary *dict2 =
   1052       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues2
   1053                                              forKeys:kKeys1
   1054                                                count:GPBARRAYSIZE(kValues2)];
   1055   XCTAssertNotNil(dict2);
   1056   GPBBoolInt64Dictionary *dict3 =
   1057       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues1
   1058                                              forKeys:kKeys2
   1059                                                count:GPBARRAYSIZE(kValues1)];
   1060   XCTAssertNotNil(dict3);
   1061   GPBBoolInt64Dictionary *dict4 =
   1062       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues3
   1063                                              forKeys:kKeys1
   1064                                                count:GPBARRAYSIZE(kValues3)];
   1065   XCTAssertNotNil(dict4);
   1066 
   1067   // 1/1Prime should be different objects, but equal.
   1068   XCTAssertNotEqual(dict1, dict1prime);
   1069   XCTAssertEqualObjects(dict1, dict1prime);
   1070   // Equal, so they must have same hash.
   1071   XCTAssertEqual([dict1 hash], [dict1prime hash]);
   1072 
   1073   // 2 is same keys, different values; not equal.
   1074   XCTAssertNotEqualObjects(dict1, dict2);
   1075 
   1076   // 3 is different keys, same values; not equal.
   1077   XCTAssertNotEqualObjects(dict1, dict3);
   1078 
   1079   // 4 Fewer pairs; not equal
   1080   XCTAssertNotEqualObjects(dict1, dict4);
   1081 
   1082   [dict1 release];
   1083   [dict1prime release];
   1084   [dict2 release];
   1085   [dict3 release];
   1086   [dict4 release];
   1087 }
   1088 
   1089 - (void)testCopy {
   1090   const BOOL kKeys[] = { YES, NO };
   1091   const int64_t kValues[] = { 400, 401 };
   1092   GPBBoolInt64Dictionary *dict =
   1093       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues
   1094                                              forKeys:kKeys
   1095                                                count:GPBARRAYSIZE(kValues)];
   1096   XCTAssertNotNil(dict);
   1097 
   1098   GPBBoolInt64Dictionary *dict2 = [dict copy];
   1099   XCTAssertNotNil(dict2);
   1100 
   1101   // Should be new object but equal.
   1102   XCTAssertNotEqual(dict, dict2);
   1103   XCTAssertEqualObjects(dict, dict2);
   1104   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt64Dictionary class]]);
   1105 
   1106   [dict2 release];
   1107   [dict release];
   1108 }
   1109 
   1110 - (void)testDictionaryFromDictionary {
   1111   const BOOL kKeys[] = { YES, NO };
   1112   const int64_t kValues[] = { 400, 401 };
   1113   GPBBoolInt64Dictionary *dict =
   1114       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues
   1115                                              forKeys:kKeys
   1116                                                count:GPBARRAYSIZE(kValues)];
   1117   XCTAssertNotNil(dict);
   1118 
   1119   GPBBoolInt64Dictionary *dict2 =
   1120       [GPBBoolInt64Dictionary dictionaryWithDictionary:dict];
   1121   XCTAssertNotNil(dict2);
   1122 
   1123   // Should be new pointer, but equal objects.
   1124   XCTAssertNotEqual(dict, dict2);
   1125   XCTAssertEqualObjects(dict, dict2);
   1126   [dict release];
   1127 }
   1128 
   1129 - (void)testAdds {
   1130   GPBBoolInt64Dictionary *dict = [GPBBoolInt64Dictionary dictionary];
   1131   XCTAssertNotNil(dict);
   1132 
   1133   XCTAssertEqual(dict.count, 0U);
   1134   [dict setValue:400 forKey:YES];
   1135   XCTAssertEqual(dict.count, 1U);
   1136 
   1137   const BOOL kKeys[] = { NO };
   1138   const int64_t kValues[] = { 401 };
   1139   GPBBoolInt64Dictionary *dict2 =
   1140       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues
   1141                                              forKeys:kKeys
   1142                                                count:GPBARRAYSIZE(kValues)];
   1143   XCTAssertNotNil(dict2);
   1144   [dict addEntriesFromDictionary:dict2];
   1145   XCTAssertEqual(dict.count, 2U);
   1146 
   1147   int64_t value;
   1148   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1149   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1150   XCTAssertEqual(value, 400);
   1151   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1152   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1153   XCTAssertEqual(value, 401);
   1154   [dict2 release];
   1155 }
   1156 
   1157 - (void)testRemove {
   1158   const BOOL kKeys[] = { YES, NO};
   1159   const int64_t kValues[] = { 400, 401 };
   1160   GPBBoolInt64Dictionary *dict =
   1161       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues
   1162                                       forKeys:kKeys
   1163                                         count:GPBARRAYSIZE(kValues)];
   1164   XCTAssertNotNil(dict);
   1165   XCTAssertEqual(dict.count, 2U);
   1166 
   1167   [dict removeValueForKey:NO];
   1168   XCTAssertEqual(dict.count, 1U);
   1169   int64_t value;
   1170   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1171   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1172   XCTAssertEqual(value, 400);
   1173   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1174 
   1175   // Remove again does nothing.
   1176   [dict removeValueForKey:NO];
   1177   XCTAssertEqual(dict.count, 1U);
   1178   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1179   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1180   XCTAssertEqual(value, 400);
   1181   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1182 
   1183   [dict removeAll];
   1184   XCTAssertEqual(dict.count, 0U);
   1185   XCTAssertFalse([dict valueForKey:YES value:NULL]);
   1186   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1187   [dict release];
   1188 }
   1189 
   1190 - (void)testInplaceMutation {
   1191   const BOOL kKeys[] = { YES, NO };
   1192   const int64_t kValues[] = { 400, 401 };
   1193   GPBBoolInt64Dictionary *dict =
   1194       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues
   1195                                       forKeys:kKeys
   1196                                         count:GPBARRAYSIZE(kValues)];
   1197   XCTAssertNotNil(dict);
   1198   XCTAssertEqual(dict.count, 2U);
   1199   int64_t value;
   1200   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1201   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1202   XCTAssertEqual(value, 400);
   1203   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1204   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1205   XCTAssertEqual(value, 401);
   1206 
   1207   [dict setValue:401 forKey:YES];
   1208   XCTAssertEqual(dict.count, 2U);
   1209   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1210   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1211   XCTAssertEqual(value, 401);
   1212   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1213   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1214   XCTAssertEqual(value, 401);
   1215 
   1216   [dict setValue:400 forKey:NO];
   1217   XCTAssertEqual(dict.count, 2U);
   1218   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1219   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1220   XCTAssertEqual(value, 401);
   1221   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1222   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1223   XCTAssertEqual(value, 400);
   1224 
   1225   const BOOL kKeys2[] = { NO, YES };
   1226   const int64_t kValues2[] = { 401, 400 };
   1227   GPBBoolInt64Dictionary *dict2 =
   1228       [[GPBBoolInt64Dictionary alloc] initWithValues:kValues2
   1229                                              forKeys:kKeys2
   1230                                                count:GPBARRAYSIZE(kValues2)];
   1231   XCTAssertNotNil(dict2);
   1232   [dict addEntriesFromDictionary:dict2];
   1233   XCTAssertEqual(dict.count, 2U);
   1234   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1235   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1236   XCTAssertEqual(value, 400);
   1237   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1238   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1239   XCTAssertEqual(value, 401);
   1240 
   1241   [dict2 release];
   1242   [dict release];
   1243 }
   1244 
   1245 @end
   1246 
   1247 //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Bool, BOOL, NO, YES)
   1248 // This block of code is generated, do not edit it directly.
   1249 
   1250 #pragma mark - Bool -> Bool
   1251 
   1252 @interface GPBBoolBoolDictionaryTests : XCTestCase
   1253 @end
   1254 
   1255 @implementation GPBBoolBoolDictionaryTests
   1256 
   1257 - (void)testEmpty {
   1258   GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
   1259   XCTAssertNotNil(dict);
   1260   XCTAssertEqual(dict.count, 0U);
   1261   XCTAssertFalse([dict valueForKey:YES value:NULL]);
   1262   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
   1263     #pragma unused(aKey, aValue, stop)
   1264     XCTFail(@"Shouldn't get here!");
   1265   }];
   1266   [dict release];
   1267 }
   1268 
   1269 - (void)testOne {
   1270   GPBBoolBoolDictionary *dict = [GPBBoolBoolDictionary dictionaryWithValue:NO forKey:YES];
   1271   XCTAssertNotNil(dict);
   1272   XCTAssertEqual(dict.count, 1U);
   1273   BOOL value;
   1274   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1275   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1276   XCTAssertEqual(value, NO);
   1277   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1278   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
   1279     XCTAssertEqual(aKey, YES);
   1280     XCTAssertEqual(aValue, NO);
   1281     XCTAssertNotEqual(stop, NULL);
   1282   }];
   1283 }
   1284 
   1285 - (void)testBasics {
   1286   const BOOL kKeys[] = { YES, NO };
   1287   const BOOL kValues[] = { NO, YES };
   1288   GPBBoolBoolDictionary *dict =
   1289       [[GPBBoolBoolDictionary alloc] initWithValues:kValues
   1290                                             forKeys:kKeys
   1291                                               count:GPBARRAYSIZE(kValues)];
   1292   XCTAssertNotNil(dict);
   1293   XCTAssertEqual(dict.count, 2U);
   1294   BOOL value;
   1295   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1296   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1297   XCTAssertEqual(value, NO);
   1298   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1299   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1300   XCTAssertEqual(value, YES);
   1301 
   1302   __block NSUInteger idx = 0;
   1303   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
   1304   BOOL *seenValues = malloc(2 * sizeof(BOOL));
   1305   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
   1306     XCTAssertLessThan(idx, 2U);
   1307     seenKeys[idx] = aKey;
   1308     seenValues[idx] = aValue;
   1309     XCTAssertNotEqual(stop, NULL);
   1310     ++idx;
   1311   }];
   1312   for (int i = 0; i < 2; ++i) {
   1313     BOOL foundKey = NO;
   1314     for (int j = 0; (j < 2) && !foundKey; ++j) {
   1315       if (kKeys[i] == seenKeys[j]) {
   1316         foundKey = YES;
   1317         XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
   1318       }
   1319     }
   1320     XCTAssertTrue(foundKey, @"i = %d", i);
   1321   }
   1322   free(seenKeys);
   1323   free(seenValues);
   1324 
   1325   // Stopping the enumeration.
   1326   idx = 0;
   1327   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
   1328     #pragma unused(aKey, aValue)
   1329     if (idx == 0) *stop = YES;
   1330     XCTAssertNotEqual(idx, 2U);
   1331     ++idx;
   1332   }];
   1333   [dict release];
   1334 }
   1335 
   1336 - (void)testEquality {
   1337   const BOOL kKeys1[] = { YES, NO };
   1338   const BOOL kKeys2[] = { NO, YES };
   1339   const BOOL kValues1[] = { NO, YES };
   1340   const BOOL kValues2[] = { YES, NO };
   1341   const BOOL kValues3[] = { YES };
   1342   GPBBoolBoolDictionary *dict1 =
   1343       [[GPBBoolBoolDictionary alloc] initWithValues:kValues1
   1344                                             forKeys:kKeys1
   1345                                               count:GPBARRAYSIZE(kValues1)];
   1346   XCTAssertNotNil(dict1);
   1347   GPBBoolBoolDictionary *dict1prime =
   1348       [[GPBBoolBoolDictionary alloc] initWithValues:kValues1
   1349                                             forKeys:kKeys1
   1350                                               count:GPBARRAYSIZE(kValues1)];
   1351   XCTAssertNotNil(dict1prime);
   1352   GPBBoolBoolDictionary *dict2 =
   1353       [[GPBBoolBoolDictionary alloc] initWithValues:kValues2
   1354                                             forKeys:kKeys1
   1355                                               count:GPBARRAYSIZE(kValues2)];
   1356   XCTAssertNotNil(dict2);
   1357   GPBBoolBoolDictionary *dict3 =
   1358       [[GPBBoolBoolDictionary alloc] initWithValues:kValues1
   1359                                             forKeys:kKeys2
   1360                                               count:GPBARRAYSIZE(kValues1)];
   1361   XCTAssertNotNil(dict3);
   1362   GPBBoolBoolDictionary *dict4 =
   1363       [[GPBBoolBoolDictionary alloc] initWithValues:kValues3
   1364                                             forKeys:kKeys1
   1365                                               count:GPBARRAYSIZE(kValues3)];
   1366   XCTAssertNotNil(dict4);
   1367 
   1368   // 1/1Prime should be different objects, but equal.
   1369   XCTAssertNotEqual(dict1, dict1prime);
   1370   XCTAssertEqualObjects(dict1, dict1prime);
   1371   // Equal, so they must have same hash.
   1372   XCTAssertEqual([dict1 hash], [dict1prime hash]);
   1373 
   1374   // 2 is same keys, different values; not equal.
   1375   XCTAssertNotEqualObjects(dict1, dict2);
   1376 
   1377   // 3 is different keys, same values; not equal.
   1378   XCTAssertNotEqualObjects(dict1, dict3);
   1379 
   1380   // 4 Fewer pairs; not equal
   1381   XCTAssertNotEqualObjects(dict1, dict4);
   1382 
   1383   [dict1 release];
   1384   [dict1prime release];
   1385   [dict2 release];
   1386   [dict3 release];
   1387   [dict4 release];
   1388 }
   1389 
   1390 - (void)testCopy {
   1391   const BOOL kKeys[] = { YES, NO };
   1392   const BOOL kValues[] = { NO, YES };
   1393   GPBBoolBoolDictionary *dict =
   1394       [[GPBBoolBoolDictionary alloc] initWithValues:kValues
   1395                                             forKeys:kKeys
   1396                                               count:GPBARRAYSIZE(kValues)];
   1397   XCTAssertNotNil(dict);
   1398 
   1399   GPBBoolBoolDictionary *dict2 = [dict copy];
   1400   XCTAssertNotNil(dict2);
   1401 
   1402   // Should be new object but equal.
   1403   XCTAssertNotEqual(dict, dict2);
   1404   XCTAssertEqualObjects(dict, dict2);
   1405   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolBoolDictionary class]]);
   1406 
   1407   [dict2 release];
   1408   [dict release];
   1409 }
   1410 
   1411 - (void)testDictionaryFromDictionary {
   1412   const BOOL kKeys[] = { YES, NO };
   1413   const BOOL kValues[] = { NO, YES };
   1414   GPBBoolBoolDictionary *dict =
   1415       [[GPBBoolBoolDictionary alloc] initWithValues:kValues
   1416                                             forKeys:kKeys
   1417                                               count:GPBARRAYSIZE(kValues)];
   1418   XCTAssertNotNil(dict);
   1419 
   1420   GPBBoolBoolDictionary *dict2 =
   1421       [GPBBoolBoolDictionary dictionaryWithDictionary:dict];
   1422   XCTAssertNotNil(dict2);
   1423 
   1424   // Should be new pointer, but equal objects.
   1425   XCTAssertNotEqual(dict, dict2);
   1426   XCTAssertEqualObjects(dict, dict2);
   1427   [dict release];
   1428 }
   1429 
   1430 - (void)testAdds {
   1431   GPBBoolBoolDictionary *dict = [GPBBoolBoolDictionary dictionary];
   1432   XCTAssertNotNil(dict);
   1433 
   1434   XCTAssertEqual(dict.count, 0U);
   1435   [dict setValue:NO forKey:YES];
   1436   XCTAssertEqual(dict.count, 1U);
   1437 
   1438   const BOOL kKeys[] = { NO };
   1439   const BOOL kValues[] = { YES };
   1440   GPBBoolBoolDictionary *dict2 =
   1441       [[GPBBoolBoolDictionary alloc] initWithValues:kValues
   1442                                             forKeys:kKeys
   1443                                               count:GPBARRAYSIZE(kValues)];
   1444   XCTAssertNotNil(dict2);
   1445   [dict addEntriesFromDictionary:dict2];
   1446   XCTAssertEqual(dict.count, 2U);
   1447 
   1448   BOOL value;
   1449   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1450   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1451   XCTAssertEqual(value, NO);
   1452   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1453   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1454   XCTAssertEqual(value, YES);
   1455   [dict2 release];
   1456 }
   1457 
   1458 - (void)testRemove {
   1459   const BOOL kKeys[] = { YES, NO};
   1460   const BOOL kValues[] = { NO, YES };
   1461   GPBBoolBoolDictionary *dict =
   1462       [[GPBBoolBoolDictionary alloc] initWithValues:kValues
   1463                                      forKeys:kKeys
   1464                                        count:GPBARRAYSIZE(kValues)];
   1465   XCTAssertNotNil(dict);
   1466   XCTAssertEqual(dict.count, 2U);
   1467 
   1468   [dict removeValueForKey:NO];
   1469   XCTAssertEqual(dict.count, 1U);
   1470   BOOL value;
   1471   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1472   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1473   XCTAssertEqual(value, NO);
   1474   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1475 
   1476   // Remove again does nothing.
   1477   [dict removeValueForKey:NO];
   1478   XCTAssertEqual(dict.count, 1U);
   1479   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1480   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1481   XCTAssertEqual(value, NO);
   1482   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1483 
   1484   [dict removeAll];
   1485   XCTAssertEqual(dict.count, 0U);
   1486   XCTAssertFalse([dict valueForKey:YES value:NULL]);
   1487   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1488   [dict release];
   1489 }
   1490 
   1491 - (void)testInplaceMutation {
   1492   const BOOL kKeys[] = { YES, NO };
   1493   const BOOL kValues[] = { NO, YES };
   1494   GPBBoolBoolDictionary *dict =
   1495       [[GPBBoolBoolDictionary alloc] initWithValues:kValues
   1496                                      forKeys:kKeys
   1497                                        count:GPBARRAYSIZE(kValues)];
   1498   XCTAssertNotNil(dict);
   1499   XCTAssertEqual(dict.count, 2U);
   1500   BOOL value;
   1501   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1502   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1503   XCTAssertEqual(value, NO);
   1504   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1505   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1506   XCTAssertEqual(value, YES);
   1507 
   1508   [dict setValue:YES forKey:YES];
   1509   XCTAssertEqual(dict.count, 2U);
   1510   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1511   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1512   XCTAssertEqual(value, YES);
   1513   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1514   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1515   XCTAssertEqual(value, YES);
   1516 
   1517   [dict setValue:NO forKey:NO];
   1518   XCTAssertEqual(dict.count, 2U);
   1519   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1520   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1521   XCTAssertEqual(value, YES);
   1522   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1523   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1524   XCTAssertEqual(value, NO);
   1525 
   1526   const BOOL kKeys2[] = { NO, YES };
   1527   const BOOL kValues2[] = { YES, NO };
   1528   GPBBoolBoolDictionary *dict2 =
   1529       [[GPBBoolBoolDictionary alloc] initWithValues:kValues2
   1530                                             forKeys:kKeys2
   1531                                               count:GPBARRAYSIZE(kValues2)];
   1532   XCTAssertNotNil(dict2);
   1533   [dict addEntriesFromDictionary:dict2];
   1534   XCTAssertEqual(dict.count, 2U);
   1535   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1536   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1537   XCTAssertEqual(value, NO);
   1538   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1539   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1540   XCTAssertEqual(value, YES);
   1541 
   1542   [dict2 release];
   1543   [dict release];
   1544 }
   1545 
   1546 @end
   1547 
   1548 //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Float, float, 500.f, 501.f)
   1549 // This block of code is generated, do not edit it directly.
   1550 
   1551 #pragma mark - Bool -> Float
   1552 
   1553 @interface GPBBoolFloatDictionaryTests : XCTestCase
   1554 @end
   1555 
   1556 @implementation GPBBoolFloatDictionaryTests
   1557 
   1558 - (void)testEmpty {
   1559   GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
   1560   XCTAssertNotNil(dict);
   1561   XCTAssertEqual(dict.count, 0U);
   1562   XCTAssertFalse([dict valueForKey:YES value:NULL]);
   1563   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
   1564     #pragma unused(aKey, aValue, stop)
   1565     XCTFail(@"Shouldn't get here!");
   1566   }];
   1567   [dict release];
   1568 }
   1569 
   1570 - (void)testOne {
   1571   GPBBoolFloatDictionary *dict = [GPBBoolFloatDictionary dictionaryWithValue:500.f forKey:YES];
   1572   XCTAssertNotNil(dict);
   1573   XCTAssertEqual(dict.count, 1U);
   1574   float value;
   1575   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1576   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1577   XCTAssertEqual(value, 500.f);
   1578   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1579   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
   1580     XCTAssertEqual(aKey, YES);
   1581     XCTAssertEqual(aValue, 500.f);
   1582     XCTAssertNotEqual(stop, NULL);
   1583   }];
   1584 }
   1585 
   1586 - (void)testBasics {
   1587   const BOOL kKeys[] = { YES, NO };
   1588   const float kValues[] = { 500.f, 501.f };
   1589   GPBBoolFloatDictionary *dict =
   1590       [[GPBBoolFloatDictionary alloc] initWithValues:kValues
   1591                                              forKeys:kKeys
   1592                                                count:GPBARRAYSIZE(kValues)];
   1593   XCTAssertNotNil(dict);
   1594   XCTAssertEqual(dict.count, 2U);
   1595   float value;
   1596   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1597   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1598   XCTAssertEqual(value, 500.f);
   1599   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1600   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1601   XCTAssertEqual(value, 501.f);
   1602 
   1603   __block NSUInteger idx = 0;
   1604   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
   1605   float *seenValues = malloc(2 * sizeof(float));
   1606   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
   1607     XCTAssertLessThan(idx, 2U);
   1608     seenKeys[idx] = aKey;
   1609     seenValues[idx] = aValue;
   1610     XCTAssertNotEqual(stop, NULL);
   1611     ++idx;
   1612   }];
   1613   for (int i = 0; i < 2; ++i) {
   1614     BOOL foundKey = NO;
   1615     for (int j = 0; (j < 2) && !foundKey; ++j) {
   1616       if (kKeys[i] == seenKeys[j]) {
   1617         foundKey = YES;
   1618         XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
   1619       }
   1620     }
   1621     XCTAssertTrue(foundKey, @"i = %d", i);
   1622   }
   1623   free(seenKeys);
   1624   free(seenValues);
   1625 
   1626   // Stopping the enumeration.
   1627   idx = 0;
   1628   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
   1629     #pragma unused(aKey, aValue)
   1630     if (idx == 0) *stop = YES;
   1631     XCTAssertNotEqual(idx, 2U);
   1632     ++idx;
   1633   }];
   1634   [dict release];
   1635 }
   1636 
   1637 - (void)testEquality {
   1638   const BOOL kKeys1[] = { YES, NO };
   1639   const BOOL kKeys2[] = { NO, YES };
   1640   const float kValues1[] = { 500.f, 501.f };
   1641   const float kValues2[] = { 501.f, 500.f };
   1642   const float kValues3[] = { 501.f };
   1643   GPBBoolFloatDictionary *dict1 =
   1644       [[GPBBoolFloatDictionary alloc] initWithValues:kValues1
   1645                                              forKeys:kKeys1
   1646                                                count:GPBARRAYSIZE(kValues1)];
   1647   XCTAssertNotNil(dict1);
   1648   GPBBoolFloatDictionary *dict1prime =
   1649       [[GPBBoolFloatDictionary alloc] initWithValues:kValues1
   1650                                              forKeys:kKeys1
   1651                                                count:GPBARRAYSIZE(kValues1)];
   1652   XCTAssertNotNil(dict1prime);
   1653   GPBBoolFloatDictionary *dict2 =
   1654       [[GPBBoolFloatDictionary alloc] initWithValues:kValues2
   1655                                              forKeys:kKeys1
   1656                                                count:GPBARRAYSIZE(kValues2)];
   1657   XCTAssertNotNil(dict2);
   1658   GPBBoolFloatDictionary *dict3 =
   1659       [[GPBBoolFloatDictionary alloc] initWithValues:kValues1
   1660                                              forKeys:kKeys2
   1661                                                count:GPBARRAYSIZE(kValues1)];
   1662   XCTAssertNotNil(dict3);
   1663   GPBBoolFloatDictionary *dict4 =
   1664       [[GPBBoolFloatDictionary alloc] initWithValues:kValues3
   1665                                              forKeys:kKeys1
   1666                                                count:GPBARRAYSIZE(kValues3)];
   1667   XCTAssertNotNil(dict4);
   1668 
   1669   // 1/1Prime should be different objects, but equal.
   1670   XCTAssertNotEqual(dict1, dict1prime);
   1671   XCTAssertEqualObjects(dict1, dict1prime);
   1672   // Equal, so they must have same hash.
   1673   XCTAssertEqual([dict1 hash], [dict1prime hash]);
   1674 
   1675   // 2 is same keys, different values; not equal.
   1676   XCTAssertNotEqualObjects(dict1, dict2);
   1677 
   1678   // 3 is different keys, same values; not equal.
   1679   XCTAssertNotEqualObjects(dict1, dict3);
   1680 
   1681   // 4 Fewer pairs; not equal
   1682   XCTAssertNotEqualObjects(dict1, dict4);
   1683 
   1684   [dict1 release];
   1685   [dict1prime release];
   1686   [dict2 release];
   1687   [dict3 release];
   1688   [dict4 release];
   1689 }
   1690 
   1691 - (void)testCopy {
   1692   const BOOL kKeys[] = { YES, NO };
   1693   const float kValues[] = { 500.f, 501.f };
   1694   GPBBoolFloatDictionary *dict =
   1695       [[GPBBoolFloatDictionary alloc] initWithValues:kValues
   1696                                              forKeys:kKeys
   1697                                                count:GPBARRAYSIZE(kValues)];
   1698   XCTAssertNotNil(dict);
   1699 
   1700   GPBBoolFloatDictionary *dict2 = [dict copy];
   1701   XCTAssertNotNil(dict2);
   1702 
   1703   // Should be new object but equal.
   1704   XCTAssertNotEqual(dict, dict2);
   1705   XCTAssertEqualObjects(dict, dict2);
   1706   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolFloatDictionary class]]);
   1707 
   1708   [dict2 release];
   1709   [dict release];
   1710 }
   1711 
   1712 - (void)testDictionaryFromDictionary {
   1713   const BOOL kKeys[] = { YES, NO };
   1714   const float kValues[] = { 500.f, 501.f };
   1715   GPBBoolFloatDictionary *dict =
   1716       [[GPBBoolFloatDictionary alloc] initWithValues:kValues
   1717                                              forKeys:kKeys
   1718                                                count:GPBARRAYSIZE(kValues)];
   1719   XCTAssertNotNil(dict);
   1720 
   1721   GPBBoolFloatDictionary *dict2 =
   1722       [GPBBoolFloatDictionary dictionaryWithDictionary:dict];
   1723   XCTAssertNotNil(dict2);
   1724 
   1725   // Should be new pointer, but equal objects.
   1726   XCTAssertNotEqual(dict, dict2);
   1727   XCTAssertEqualObjects(dict, dict2);
   1728   [dict release];
   1729 }
   1730 
   1731 - (void)testAdds {
   1732   GPBBoolFloatDictionary *dict = [GPBBoolFloatDictionary dictionary];
   1733   XCTAssertNotNil(dict);
   1734 
   1735   XCTAssertEqual(dict.count, 0U);
   1736   [dict setValue:500.f forKey:YES];
   1737   XCTAssertEqual(dict.count, 1U);
   1738 
   1739   const BOOL kKeys[] = { NO };
   1740   const float kValues[] = { 501.f };
   1741   GPBBoolFloatDictionary *dict2 =
   1742       [[GPBBoolFloatDictionary alloc] initWithValues:kValues
   1743                                              forKeys:kKeys
   1744                                                count:GPBARRAYSIZE(kValues)];
   1745   XCTAssertNotNil(dict2);
   1746   [dict addEntriesFromDictionary:dict2];
   1747   XCTAssertEqual(dict.count, 2U);
   1748 
   1749   float value;
   1750   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1751   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1752   XCTAssertEqual(value, 500.f);
   1753   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1754   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1755   XCTAssertEqual(value, 501.f);
   1756   [dict2 release];
   1757 }
   1758 
   1759 - (void)testRemove {
   1760   const BOOL kKeys[] = { YES, NO};
   1761   const float kValues[] = { 500.f, 501.f };
   1762   GPBBoolFloatDictionary *dict =
   1763       [[GPBBoolFloatDictionary alloc] initWithValues:kValues
   1764                                       forKeys:kKeys
   1765                                         count:GPBARRAYSIZE(kValues)];
   1766   XCTAssertNotNil(dict);
   1767   XCTAssertEqual(dict.count, 2U);
   1768 
   1769   [dict removeValueForKey:NO];
   1770   XCTAssertEqual(dict.count, 1U);
   1771   float value;
   1772   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1773   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1774   XCTAssertEqual(value, 500.f);
   1775   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1776 
   1777   // Remove again does nothing.
   1778   [dict removeValueForKey:NO];
   1779   XCTAssertEqual(dict.count, 1U);
   1780   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1781   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1782   XCTAssertEqual(value, 500.f);
   1783   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1784 
   1785   [dict removeAll];
   1786   XCTAssertEqual(dict.count, 0U);
   1787   XCTAssertFalse([dict valueForKey:YES value:NULL]);
   1788   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1789   [dict release];
   1790 }
   1791 
   1792 - (void)testInplaceMutation {
   1793   const BOOL kKeys[] = { YES, NO };
   1794   const float kValues[] = { 500.f, 501.f };
   1795   GPBBoolFloatDictionary *dict =
   1796       [[GPBBoolFloatDictionary alloc] initWithValues:kValues
   1797                                       forKeys:kKeys
   1798                                         count:GPBARRAYSIZE(kValues)];
   1799   XCTAssertNotNil(dict);
   1800   XCTAssertEqual(dict.count, 2U);
   1801   float value;
   1802   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1803   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1804   XCTAssertEqual(value, 500.f);
   1805   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1806   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1807   XCTAssertEqual(value, 501.f);
   1808 
   1809   [dict setValue:501.f forKey:YES];
   1810   XCTAssertEqual(dict.count, 2U);
   1811   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1812   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1813   XCTAssertEqual(value, 501.f);
   1814   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1815   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1816   XCTAssertEqual(value, 501.f);
   1817 
   1818   [dict setValue:500.f forKey:NO];
   1819   XCTAssertEqual(dict.count, 2U);
   1820   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1821   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1822   XCTAssertEqual(value, 501.f);
   1823   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1824   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1825   XCTAssertEqual(value, 500.f);
   1826 
   1827   const BOOL kKeys2[] = { NO, YES };
   1828   const float kValues2[] = { 501.f, 500.f };
   1829   GPBBoolFloatDictionary *dict2 =
   1830       [[GPBBoolFloatDictionary alloc] initWithValues:kValues2
   1831                                              forKeys:kKeys2
   1832                                                count:GPBARRAYSIZE(kValues2)];
   1833   XCTAssertNotNil(dict2);
   1834   [dict addEntriesFromDictionary:dict2];
   1835   XCTAssertEqual(dict.count, 2U);
   1836   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1837   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1838   XCTAssertEqual(value, 500.f);
   1839   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1840   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1841   XCTAssertEqual(value, 501.f);
   1842 
   1843   [dict2 release];
   1844   [dict release];
   1845 }
   1846 
   1847 @end
   1848 
   1849 //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Double, double, 600., 601.)
   1850 // This block of code is generated, do not edit it directly.
   1851 
   1852 #pragma mark - Bool -> Double
   1853 
   1854 @interface GPBBoolDoubleDictionaryTests : XCTestCase
   1855 @end
   1856 
   1857 @implementation GPBBoolDoubleDictionaryTests
   1858 
   1859 - (void)testEmpty {
   1860   GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
   1861   XCTAssertNotNil(dict);
   1862   XCTAssertEqual(dict.count, 0U);
   1863   XCTAssertFalse([dict valueForKey:YES value:NULL]);
   1864   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
   1865     #pragma unused(aKey, aValue, stop)
   1866     XCTFail(@"Shouldn't get here!");
   1867   }];
   1868   [dict release];
   1869 }
   1870 
   1871 - (void)testOne {
   1872   GPBBoolDoubleDictionary *dict = [GPBBoolDoubleDictionary dictionaryWithValue:600. forKey:YES];
   1873   XCTAssertNotNil(dict);
   1874   XCTAssertEqual(dict.count, 1U);
   1875   double value;
   1876   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1877   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1878   XCTAssertEqual(value, 600.);
   1879   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   1880   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
   1881     XCTAssertEqual(aKey, YES);
   1882     XCTAssertEqual(aValue, 600.);
   1883     XCTAssertNotEqual(stop, NULL);
   1884   }];
   1885 }
   1886 
   1887 - (void)testBasics {
   1888   const BOOL kKeys[] = { YES, NO };
   1889   const double kValues[] = { 600., 601. };
   1890   GPBBoolDoubleDictionary *dict =
   1891       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues
   1892                                               forKeys:kKeys
   1893                                                 count:GPBARRAYSIZE(kValues)];
   1894   XCTAssertNotNil(dict);
   1895   XCTAssertEqual(dict.count, 2U);
   1896   double value;
   1897   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   1898   XCTAssertTrue([dict valueForKey:YES value:&value]);
   1899   XCTAssertEqual(value, 600.);
   1900   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   1901   XCTAssertTrue([dict valueForKey:NO value:&value]);
   1902   XCTAssertEqual(value, 601.);
   1903 
   1904   __block NSUInteger idx = 0;
   1905   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
   1906   double *seenValues = malloc(2 * sizeof(double));
   1907   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
   1908     XCTAssertLessThan(idx, 2U);
   1909     seenKeys[idx] = aKey;
   1910     seenValues[idx] = aValue;
   1911     XCTAssertNotEqual(stop, NULL);
   1912     ++idx;
   1913   }];
   1914   for (int i = 0; i < 2; ++i) {
   1915     BOOL foundKey = NO;
   1916     for (int j = 0; (j < 2) && !foundKey; ++j) {
   1917       if (kKeys[i] == seenKeys[j]) {
   1918         foundKey = YES;
   1919         XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
   1920       }
   1921     }
   1922     XCTAssertTrue(foundKey, @"i = %d", i);
   1923   }
   1924   free(seenKeys);
   1925   free(seenValues);
   1926 
   1927   // Stopping the enumeration.
   1928   idx = 0;
   1929   [dict enumerateKeysAndValuesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
   1930     #pragma unused(aKey, aValue)
   1931     if (idx == 0) *stop = YES;
   1932     XCTAssertNotEqual(idx, 2U);
   1933     ++idx;
   1934   }];
   1935   [dict release];
   1936 }
   1937 
   1938 - (void)testEquality {
   1939   const BOOL kKeys1[] = { YES, NO };
   1940   const BOOL kKeys2[] = { NO, YES };
   1941   const double kValues1[] = { 600., 601. };
   1942   const double kValues2[] = { 601., 600. };
   1943   const double kValues3[] = { 601. };
   1944   GPBBoolDoubleDictionary *dict1 =
   1945       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues1
   1946                                               forKeys:kKeys1
   1947                                                 count:GPBARRAYSIZE(kValues1)];
   1948   XCTAssertNotNil(dict1);
   1949   GPBBoolDoubleDictionary *dict1prime =
   1950       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues1
   1951                                               forKeys:kKeys1
   1952                                                 count:GPBARRAYSIZE(kValues1)];
   1953   XCTAssertNotNil(dict1prime);
   1954   GPBBoolDoubleDictionary *dict2 =
   1955       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues2
   1956                                               forKeys:kKeys1
   1957                                                 count:GPBARRAYSIZE(kValues2)];
   1958   XCTAssertNotNil(dict2);
   1959   GPBBoolDoubleDictionary *dict3 =
   1960       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues1
   1961                                               forKeys:kKeys2
   1962                                                 count:GPBARRAYSIZE(kValues1)];
   1963   XCTAssertNotNil(dict3);
   1964   GPBBoolDoubleDictionary *dict4 =
   1965       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues3
   1966                                               forKeys:kKeys1
   1967                                                 count:GPBARRAYSIZE(kValues3)];
   1968   XCTAssertNotNil(dict4);
   1969 
   1970   // 1/1Prime should be different objects, but equal.
   1971   XCTAssertNotEqual(dict1, dict1prime);
   1972   XCTAssertEqualObjects(dict1, dict1prime);
   1973   // Equal, so they must have same hash.
   1974   XCTAssertEqual([dict1 hash], [dict1prime hash]);
   1975 
   1976   // 2 is same keys, different values; not equal.
   1977   XCTAssertNotEqualObjects(dict1, dict2);
   1978 
   1979   // 3 is different keys, same values; not equal.
   1980   XCTAssertNotEqualObjects(dict1, dict3);
   1981 
   1982   // 4 Fewer pairs; not equal
   1983   XCTAssertNotEqualObjects(dict1, dict4);
   1984 
   1985   [dict1 release];
   1986   [dict1prime release];
   1987   [dict2 release];
   1988   [dict3 release];
   1989   [dict4 release];
   1990 }
   1991 
   1992 - (void)testCopy {
   1993   const BOOL kKeys[] = { YES, NO };
   1994   const double kValues[] = { 600., 601. };
   1995   GPBBoolDoubleDictionary *dict =
   1996       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues
   1997                                               forKeys:kKeys
   1998                                                 count:GPBARRAYSIZE(kValues)];
   1999   XCTAssertNotNil(dict);
   2000 
   2001   GPBBoolDoubleDictionary *dict2 = [dict copy];
   2002   XCTAssertNotNil(dict2);
   2003 
   2004   // Should be new object but equal.
   2005   XCTAssertNotEqual(dict, dict2);
   2006   XCTAssertEqualObjects(dict, dict2);
   2007   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolDoubleDictionary class]]);
   2008 
   2009   [dict2 release];
   2010   [dict release];
   2011 }
   2012 
   2013 - (void)testDictionaryFromDictionary {
   2014   const BOOL kKeys[] = { YES, NO };
   2015   const double kValues[] = { 600., 601. };
   2016   GPBBoolDoubleDictionary *dict =
   2017       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues
   2018                                               forKeys:kKeys
   2019                                                 count:GPBARRAYSIZE(kValues)];
   2020   XCTAssertNotNil(dict);
   2021 
   2022   GPBBoolDoubleDictionary *dict2 =
   2023       [GPBBoolDoubleDictionary dictionaryWithDictionary:dict];
   2024   XCTAssertNotNil(dict2);
   2025 
   2026   // Should be new pointer, but equal objects.
   2027   XCTAssertNotEqual(dict, dict2);
   2028   XCTAssertEqualObjects(dict, dict2);
   2029   [dict release];
   2030 }
   2031 
   2032 - (void)testAdds {
   2033   GPBBoolDoubleDictionary *dict = [GPBBoolDoubleDictionary dictionary];
   2034   XCTAssertNotNil(dict);
   2035 
   2036   XCTAssertEqual(dict.count, 0U);
   2037   [dict setValue:600. forKey:YES];
   2038   XCTAssertEqual(dict.count, 1U);
   2039 
   2040   const BOOL kKeys[] = { NO };
   2041   const double kValues[] = { 601. };
   2042   GPBBoolDoubleDictionary *dict2 =
   2043       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues
   2044                                               forKeys:kKeys
   2045                                                 count:GPBARRAYSIZE(kValues)];
   2046   XCTAssertNotNil(dict2);
   2047   [dict addEntriesFromDictionary:dict2];
   2048   XCTAssertEqual(dict.count, 2U);
   2049 
   2050   double value;
   2051   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   2052   XCTAssertTrue([dict valueForKey:YES value:&value]);
   2053   XCTAssertEqual(value, 600.);
   2054   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   2055   XCTAssertTrue([dict valueForKey:NO value:&value]);
   2056   XCTAssertEqual(value, 601.);
   2057   [dict2 release];
   2058 }
   2059 
   2060 - (void)testRemove {
   2061   const BOOL kKeys[] = { YES, NO};
   2062   const double kValues[] = { 600., 601. };
   2063   GPBBoolDoubleDictionary *dict =
   2064       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues
   2065                                        forKeys:kKeys
   2066                                          count:GPBARRAYSIZE(kValues)];
   2067   XCTAssertNotNil(dict);
   2068   XCTAssertEqual(dict.count, 2U);
   2069 
   2070   [dict removeValueForKey:NO];
   2071   XCTAssertEqual(dict.count, 1U);
   2072   double value;
   2073   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   2074   XCTAssertTrue([dict valueForKey:YES value:&value]);
   2075   XCTAssertEqual(value, 600.);
   2076   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   2077 
   2078   // Remove again does nothing.
   2079   [dict removeValueForKey:NO];
   2080   XCTAssertEqual(dict.count, 1U);
   2081   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   2082   XCTAssertTrue([dict valueForKey:YES value:&value]);
   2083   XCTAssertEqual(value, 600.);
   2084   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   2085 
   2086   [dict removeAll];
   2087   XCTAssertEqual(dict.count, 0U);
   2088   XCTAssertFalse([dict valueForKey:YES value:NULL]);
   2089   XCTAssertFalse([dict valueForKey:NO value:NULL]);
   2090   [dict release];
   2091 }
   2092 
   2093 - (void)testInplaceMutation {
   2094   const BOOL kKeys[] = { YES, NO };
   2095   const double kValues[] = { 600., 601. };
   2096   GPBBoolDoubleDictionary *dict =
   2097       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues
   2098                                        forKeys:kKeys
   2099                                          count:GPBARRAYSIZE(kValues)];
   2100   XCTAssertNotNil(dict);
   2101   XCTAssertEqual(dict.count, 2U);
   2102   double value;
   2103   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   2104   XCTAssertTrue([dict valueForKey:YES value:&value]);
   2105   XCTAssertEqual(value, 600.);
   2106   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   2107   XCTAssertTrue([dict valueForKey:NO value:&value]);
   2108   XCTAssertEqual(value, 601.);
   2109 
   2110   [dict setValue:601. forKey:YES];
   2111   XCTAssertEqual(dict.count, 2U);
   2112   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   2113   XCTAssertTrue([dict valueForKey:YES value:&value]);
   2114   XCTAssertEqual(value, 601.);
   2115   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   2116   XCTAssertTrue([dict valueForKey:NO value:&value]);
   2117   XCTAssertEqual(value, 601.);
   2118 
   2119   [dict setValue:600. forKey:NO];
   2120   XCTAssertEqual(dict.count, 2U);
   2121   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   2122   XCTAssertTrue([dict valueForKey:YES value:&value]);
   2123   XCTAssertEqual(value, 601.);
   2124   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   2125   XCTAssertTrue([dict valueForKey:NO value:&value]);
   2126   XCTAssertEqual(value, 600.);
   2127 
   2128   const BOOL kKeys2[] = { NO, YES };
   2129   const double kValues2[] = { 601., 600. };
   2130   GPBBoolDoubleDictionary *dict2 =
   2131       [[GPBBoolDoubleDictionary alloc] initWithValues:kValues2
   2132                                               forKeys:kKeys2
   2133                                                 count:GPBARRAYSIZE(kValues2)];
   2134   XCTAssertNotNil(dict2);
   2135   [dict addEntriesFromDictionary:dict2];
   2136   XCTAssertEqual(dict.count, 2U);
   2137   XCTAssertTrue([dict valueForKey:YES value:NULL]);
   2138   XCTAssertTrue([dict valueForKey:YES value:&value]);
   2139   XCTAssertEqual(value, 600.);
   2140   XCTAssertTrue([dict valueForKey:NO value:NULL]);
   2141   XCTAssertTrue([dict valueForKey:NO value:&value]);
   2142   XCTAssertEqual(value, 601.);
   2143 
   2144   [dict2 release];
   2145   [dict release];
   2146 }
   2147 
   2148 @end
   2149 
   2150 //%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, NSString*, @"abc", @"def")
   2151 // This block of code is generated, do not edit it directly.
   2152 
   2153 #pragma mark - Bool -> Object
   2154 
   2155 @interface GPBBoolObjectDictionaryTests : XCTestCase
   2156 @end
   2157 
   2158 @implementation GPBBoolObjectDictionaryTests
   2159 
   2160 - (void)testEmpty {
   2161   GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
   2162   XCTAssertNotNil(dict);
   2163   XCTAssertEqual(dict.count, 0U);
   2164   XCTAssertNil([dict objectForKey:YES]);
   2165   [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
   2166     #pragma unused(aKey, aObject, stop)
   2167     XCTFail(@"Shouldn't get here!");
   2168   }];
   2169   [dict release];
   2170 }
   2171 
   2172 - (void)testOne {
   2173   GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionaryWithObject:@"abc" forKey:YES];
   2174   XCTAssertNotNil(dict);
   2175   XCTAssertEqual(dict.count, 1U);
   2176   XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
   2177   XCTAssertNil([dict objectForKey:NO]);
   2178   [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
   2179     XCTAssertEqual(aKey, YES);
   2180     XCTAssertEqualObjects(aObject, @"abc");
   2181     XCTAssertNotEqual(stop, NULL);
   2182   }];
   2183 }
   2184 
   2185 - (void)testBasics {
   2186   const BOOL kKeys[] = { YES, NO };
   2187   const NSString* kObjects[] = { @"abc", @"def" };
   2188   GPBBoolObjectDictionary<NSString*> *dict =
   2189       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
   2190                                                forKeys:kKeys
   2191                                                  count:GPBARRAYSIZE(kObjects)];
   2192   XCTAssertNotNil(dict);
   2193   XCTAssertEqual(dict.count, 2U);
   2194   XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
   2195   XCTAssertEqualObjects([dict objectForKey:NO], @"def");
   2196 
   2197   __block NSUInteger idx = 0;
   2198   BOOL *seenKeys = malloc(2 * sizeof(BOOL));
   2199   NSString* *seenObjects = malloc(2 * sizeof(NSString*));
   2200   [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
   2201     XCTAssertLessThan(idx, 2U);
   2202     seenKeys[idx] = aKey;
   2203     seenObjects[idx] = aObject;
   2204     XCTAssertNotEqual(stop, NULL);
   2205     ++idx;
   2206   }];
   2207   for (int i = 0; i < 2; ++i) {
   2208     BOOL foundKey = NO;
   2209     for (int j = 0; (j < 2) && !foundKey; ++j) {
   2210       if (kKeys[i] == seenKeys[j]) {
   2211         foundKey = YES;
   2212         XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
   2213       }
   2214     }
   2215     XCTAssertTrue(foundKey, @"i = %d", i);
   2216   }
   2217   free(seenKeys);
   2218   free(seenObjects);
   2219 
   2220   // Stopping the enumeration.
   2221   idx = 0;
   2222   [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
   2223     #pragma unused(aKey, aObject)
   2224     if (idx == 0) *stop = YES;
   2225     XCTAssertNotEqual(idx, 2U);
   2226     ++idx;
   2227   }];
   2228   [dict release];
   2229 }
   2230 
   2231 - (void)testEquality {
   2232   const BOOL kKeys1[] = { YES, NO };
   2233   const BOOL kKeys2[] = { NO, YES };
   2234   const NSString* kObjects1[] = { @"abc", @"def" };
   2235   const NSString* kObjects2[] = { @"def", @"abc" };
   2236   const NSString* kObjects3[] = { @"def" };
   2237   GPBBoolObjectDictionary<NSString*> *dict1 =
   2238       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
   2239                                                forKeys:kKeys1
   2240                                                  count:GPBARRAYSIZE(kObjects1)];
   2241   XCTAssertNotNil(dict1);
   2242   GPBBoolObjectDictionary<NSString*> *dict1prime =
   2243       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
   2244                                                forKeys:kKeys1
   2245                                                  count:GPBARRAYSIZE(kObjects1)];
   2246   XCTAssertNotNil(dict1prime);
   2247   GPBBoolObjectDictionary<NSString*> *dict2 =
   2248       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
   2249                                                forKeys:kKeys1
   2250                                                  count:GPBARRAYSIZE(kObjects2)];
   2251   XCTAssertNotNil(dict2);
   2252   GPBBoolObjectDictionary<NSString*> *dict3 =
   2253       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
   2254                                                forKeys:kKeys2
   2255                                                  count:GPBARRAYSIZE(kObjects1)];
   2256   XCTAssertNotNil(dict3);
   2257   GPBBoolObjectDictionary<NSString*> *dict4 =
   2258       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects3
   2259                                                forKeys:kKeys1
   2260                                                  count:GPBARRAYSIZE(kObjects3)];
   2261   XCTAssertNotNil(dict4);
   2262 
   2263   // 1/1Prime should be different objects, but equal.
   2264   XCTAssertNotEqual(dict1, dict1prime);
   2265   XCTAssertEqualObjects(dict1, dict1prime);
   2266   // Equal, so they must have same hash.
   2267   XCTAssertEqual([dict1 hash], [dict1prime hash]);
   2268 
   2269   // 2 is same keys, different objects; not equal.
   2270   XCTAssertNotEqualObjects(dict1, dict2);
   2271 
   2272   // 3 is different keys, same objects; not equal.
   2273   XCTAssertNotEqualObjects(dict1, dict3);
   2274 
   2275   // 4 Fewer pairs; not equal
   2276   XCTAssertNotEqualObjects(dict1, dict4);
   2277 
   2278   [dict1 release];
   2279   [dict1prime release];
   2280   [dict2 release];
   2281   [dict3 release];
   2282   [dict4 release];
   2283 }
   2284 
   2285 - (void)testCopy {
   2286   const BOOL kKeys[] = { YES, NO };
   2287   const NSString* kObjects[] = { @"abc", @"def" };
   2288   GPBBoolObjectDictionary<NSString*> *dict =
   2289       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
   2290                                                forKeys:kKeys
   2291                                                  count:GPBARRAYSIZE(kObjects)];
   2292   XCTAssertNotNil(dict);
   2293 
   2294   GPBBoolObjectDictionary<NSString*> *dict2 = [dict copy];
   2295   XCTAssertNotNil(dict2);
   2296 
   2297   // Should be new object but equal.
   2298   XCTAssertNotEqual(dict, dict2);
   2299   XCTAssertEqualObjects(dict, dict2);
   2300   XCTAssertTrue([dict2 isKindOfClass:[GPBBoolObjectDictionary class]]);
   2301 
   2302   [dict2 release];
   2303   [dict release];
   2304 }
   2305 
   2306 - (void)testDictionaryFromDictionary {
   2307   const BOOL kKeys[] = { YES, NO };
   2308   const NSString* kObjects[] = { @"abc", @"def" };
   2309   GPBBoolObjectDictionary<NSString*> *dict =
   2310       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
   2311                                                forKeys:kKeys
   2312                                                  count:GPBARRAYSIZE(kObjects)];
   2313   XCTAssertNotNil(dict);
   2314 
   2315   GPBBoolObjectDictionary<NSString*> *dict2 =
   2316       [GPBBoolObjectDictionary dictionaryWithDictionary:dict];
   2317   XCTAssertNotNil(dict2);
   2318 
   2319   // Should be new pointer, but equal objects.
   2320   XCTAssertNotEqual(dict, dict2);
   2321   XCTAssertEqualObjects(dict, dict2);
   2322   [dict release];
   2323 }
   2324 
   2325 - (void)testAdds {
   2326   GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionary];
   2327   XCTAssertNotNil(dict);
   2328 
   2329   XCTAssertEqual(dict.count, 0U);
   2330   [dict setObject:@"abc" forKey:YES];
   2331   XCTAssertEqual(dict.count, 1U);
   2332 
   2333   const BOOL kKeys[] = { NO };
   2334   const NSString* kObjects[] = { @"def" };
   2335   GPBBoolObjectDictionary<NSString*> *dict2 =
   2336       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
   2337                                                forKeys:kKeys
   2338                                                  count:GPBARRAYSIZE(kObjects)];
   2339   XCTAssertNotNil(dict2);
   2340   [dict addEntriesFromDictionary:dict2];
   2341   XCTAssertEqual(dict.count, 2U);
   2342 
   2343   XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
   2344   XCTAssertEqualObjects([dict objectForKey:NO], @"def");
   2345   [dict2 release];
   2346 }
   2347 
   2348 - (void)testRemove {
   2349   const BOOL kKeys[] = { YES, NO};
   2350   const NSString* kObjects[] = { @"abc", @"def" };
   2351   GPBBoolObjectDictionary<NSString*> *dict =
   2352       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
   2353                                         forKeys:kKeys
   2354                                           count:GPBARRAYSIZE(kObjects)];
   2355   XCTAssertNotNil(dict);
   2356   XCTAssertEqual(dict.count, 2U);
   2357 
   2358   [dict removeObjectForKey:NO];
   2359   XCTAssertEqual(dict.count, 1U);
   2360   XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
   2361   XCTAssertNil([dict objectForKey:NO]);
   2362 
   2363   // Remove again does nothing.
   2364   [dict removeObjectForKey:NO];
   2365   XCTAssertEqual(dict.count, 1U);
   2366   XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
   2367   XCTAssertNil([dict objectForKey:NO]);
   2368 
   2369   [dict removeAll];
   2370   XCTAssertEqual(dict.count, 0U);
   2371   XCTAssertNil([dict objectForKey:YES]);
   2372   XCTAssertNil([dict objectForKey:NO]);
   2373   [dict release];
   2374 }
   2375 
   2376 - (void)testInplaceMutation {
   2377   const BOOL kKeys[] = { YES, NO };
   2378   const NSString* kObjects[] = { @"abc", @"def" };
   2379   GPBBoolObjectDictionary<NSString*> *dict =
   2380       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
   2381                                         forKeys:kKeys
   2382                                           count:GPBARRAYSIZE(kObjects)];
   2383   XCTAssertNotNil(dict);
   2384   XCTAssertEqual(dict.count, 2U);
   2385   XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
   2386   XCTAssertEqualObjects([dict objectForKey:NO], @"def");
   2387 
   2388   [dict setObject:@"def" forKey:YES];
   2389   XCTAssertEqual(dict.count, 2U);
   2390   XCTAssertEqualObjects([dict objectForKey:YES], @"def");
   2391   XCTAssertEqualObjects([dict objectForKey:NO], @"def");
   2392 
   2393   [dict setObject:@"abc" forKey:NO];
   2394   XCTAssertEqual(dict.count, 2U);
   2395   XCTAssertEqualObjects([dict objectForKey:YES], @"def");
   2396   XCTAssertEqualObjects([dict objectForKey:NO], @"abc");
   2397 
   2398   const BOOL kKeys2[] = { NO, YES };
   2399   const NSString* kObjects2[] = { @"def", @"abc" };
   2400   GPBBoolObjectDictionary<NSString*> *dict2 =
   2401       [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
   2402                                                forKeys:kKeys2
   2403                                                  count:GPBARRAYSIZE(kObjects2)];
   2404   XCTAssertNotNil(dict2);
   2405   [dict addEntriesFromDictionary:dict2];
   2406   XCTAssertEqual(dict.count, 2U);
   2407   XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
   2408   XCTAssertEqualObjects([dict objectForKey:NO], @"def");
   2409 
   2410   [dict2 release];
   2411   [dict release];
   2412 }
   2413 
   2414 @end
   2415 
   2416 //%PDDM-EXPAND-END (8 expansions)
   2417 
   2418 
   2419