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