1*5c2921b0SApple OSS Distributions /*
2*5c2921b0SApple OSS Distributions * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3*5c2921b0SApple OSS Distributions *
4*5c2921b0SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*5c2921b0SApple OSS Distributions *
6*5c2921b0SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*5c2921b0SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*5c2921b0SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*5c2921b0SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*5c2921b0SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*5c2921b0SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*5c2921b0SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*5c2921b0SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*5c2921b0SApple OSS Distributions *
15*5c2921b0SApple OSS Distributions * Please obtain a copy of the License at
16*5c2921b0SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*5c2921b0SApple OSS Distributions *
18*5c2921b0SApple OSS Distributions * The Original Code and all software distributed under the License are
19*5c2921b0SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*5c2921b0SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*5c2921b0SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*5c2921b0SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*5c2921b0SApple OSS Distributions * Please see the License for the specific language governing rights and
24*5c2921b0SApple OSS Distributions * limitations under the License.
25*5c2921b0SApple OSS Distributions *
26*5c2921b0SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*5c2921b0SApple OSS Distributions */
28*5c2921b0SApple OSS Distributions #if DEBUG
29*5c2921b0SApple OSS Distributions #include "Tests.h"
30*5c2921b0SApple OSS Distributions
31*5c2921b0SApple OSS Distributions #include <libkern/c++/OSArray.h>
32*5c2921b0SApple OSS Distributions #include <libkern/c++/OSSet.h>
33*5c2921b0SApple OSS Distributions #include <libkern/c++/OSDictionary.h>
34*5c2921b0SApple OSS Distributions #include <libkern/c++/OSString.h>
35*5c2921b0SApple OSS Distributions #include <libkern/c++/OSSymbol.h>
36*5c2921b0SApple OSS Distributions #include <libkern/c++/OSCollectionIterator.h>
37*5c2921b0SApple OSS Distributions
38*5c2921b0SApple OSS Distributions void
testArray()39*5c2921b0SApple OSS Distributions testArray()
40*5c2921b0SApple OSS Distributions {
41*5c2921b0SApple OSS Distributions bool res = true;
42*5c2921b0SApple OSS Distributions void *spaceCheck, *spaceCheck2, *spaceCheck3;
43*5c2921b0SApple OSS Distributions int i, j, count, count2;
44*5c2921b0SApple OSS Distributions OSObject *cache[numStrCache], *str, *sym;
45*5c2921b0SApple OSS Distributions OSArray *array1, *array2;
46*5c2921b0SApple OSS Distributions
47*5c2921b0SApple OSS Distributions // Do first test without memory leak tests to initialise the metaclass
48*5c2921b0SApple OSS Distributions array1 = OSArray::withCapacity(1);
49*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "0a", array1);
50*5c2921b0SApple OSS Distributions if (array1) {
51*5c2921b0SApple OSS Distributions array1->release();
52*5c2921b0SApple OSS Distributions }
53*5c2921b0SApple OSS Distributions
54*5c2921b0SApple OSS Distributions // Grow the symbol pool to maximum
55*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
56*5c2921b0SApple OSS Distributions cache[i] = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
57*5c2921b0SApple OSS Distributions }
58*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
59*5c2921b0SApple OSS Distributions cache[i]->release();
60*5c2921b0SApple OSS Distributions }
61*5c2921b0SApple OSS Distributions
62*5c2921b0SApple OSS Distributions // Create and destroy an array
63*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
64*5c2921b0SApple OSS Distributions array1 = OSArray::withCapacity(1);
65*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1a", array1);
66*5c2921b0SApple OSS Distributions if (array1) {
67*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1b", !array1->getCount());
68*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1c", 1 == array1->getCapacity());
69*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1d", 1 == array1->getCapacityIncrement());
70*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1e", 4 == array1->setCapacityIncrement(4));
71*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1f", 4 == array1->getCapacityIncrement());
72*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1g", 8 == array1->ensureCapacity(5));
73*5c2921b0SApple OSS Distributions
74*5c2921b0SApple OSS Distributions spaceCheck2 = checkPointSpace();
75*5c2921b0SApple OSS Distributions cache[0] = IOString::withCStringNoCopy(strCache[0]);
76*5c2921b0SApple OSS Distributions
77*5c2921b0SApple OSS Distributions spaceCheck3 = checkPointSpace();
78*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1h", array1->setObject(cache[0]));
79*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1i", cache[0] == array1->getObject(0));
80*5c2921b0SApple OSS Distributions cache[0]->release();
81*5c2921b0SApple OSS Distributions res = res && checkSpace("(A)1j", spaceCheck3, 0);
82*5c2921b0SApple OSS Distributions
83*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1k", 1 == array1->getCount());
84*5c2921b0SApple OSS Distributions array1->flushCollection();
85*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "1l", !array1->getCount());
86*5c2921b0SApple OSS Distributions res = res && checkSpace("(A)1m", spaceCheck2, 0);
87*5c2921b0SApple OSS Distributions
88*5c2921b0SApple OSS Distributions array1->release();
89*5c2921b0SApple OSS Distributions }
90*5c2921b0SApple OSS Distributions res = res && checkSpace("(A)1", spaceCheck, 0);
91*5c2921b0SApple OSS Distributions
92*5c2921b0SApple OSS Distributions // Check the creation of a sizable OSArray from an array of IOObjects
93*5c2921b0SApple OSS Distributions // Also check indexing into the array.
94*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
95*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
96*5c2921b0SApple OSS Distributions cache[i] = OSString::withCStringNoCopy(strCache[i]);
97*5c2921b0SApple OSS Distributions }
98*5c2921b0SApple OSS Distributions array1 = OSArray::withObjects(cache, numStrCache, numStrCache);
99*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "2a", array1);
100*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
101*5c2921b0SApple OSS Distributions cache[i]->release();
102*5c2921b0SApple OSS Distributions }
103*5c2921b0SApple OSS Distributions if (array1) {
104*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "2b", numStrCache == (int) array1->getCount());
105*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "2c", numStrCache == (int) array1->getCapacity());
106*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "2d",
107*5c2921b0SApple OSS Distributions numStrCache == (int) array1->getCapacityIncrement());
108*5c2921b0SApple OSS Distributions
109*5c2921b0SApple OSS Distributions for (i = 0; (str = array1->getObject(i)); i++) {
110*5c2921b0SApple OSS Distributions if (str != cache[i]) {
111*5c2921b0SApple OSS Distributions verPrintf(("testArray(A) test 2e%d failed\n", i));
112*5c2921b0SApple OSS Distributions res = false;
113*5c2921b0SApple OSS Distributions }
114*5c2921b0SApple OSS Distributions }
115*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "2f", numStrCache == i);
116*5c2921b0SApple OSS Distributions array1->release();
117*5c2921b0SApple OSS Distributions }
118*5c2921b0SApple OSS Distributions res = res && checkSpace("(A)2", spaceCheck, 0);
119*5c2921b0SApple OSS Distributions
120*5c2921b0SApple OSS Distributions // Test array creation from another array by both the setObject method
121*5c2921b0SApple OSS Distributions // and the withArray factory. And test __takeObject code first
122*5c2921b0SApple OSS Distributions // with tail removal then with head removal
123*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
124*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
125*5c2921b0SApple OSS Distributions cache[i] = OSString::withCStringNoCopy(strCache[i]);
126*5c2921b0SApple OSS Distributions }
127*5c2921b0SApple OSS Distributions array1 = OSArray::withObjects(cache, numStrCache, numStrCache);
128*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3a", array1);
129*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
130*5c2921b0SApple OSS Distributions cache[i]->release();
131*5c2921b0SApple OSS Distributions }
132*5c2921b0SApple OSS Distributions array2 = 0;
133*5c2921b0SApple OSS Distributions if (array1) {
134*5c2921b0SApple OSS Distributions array2 = OSArray::withCapacity(1);
135*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3b", array2);
136*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3c", !array2->getCount());
137*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3d", array2->setObject(array1));
138*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3e", array1->getCount() == array2->getCount());
139*5c2921b0SApple OSS Distributions }
140*5c2921b0SApple OSS Distributions if (array2) {
141*5c2921b0SApple OSS Distributions count = 0;
142*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3f", numStrCache == (int) array2->getCount());
143*5c2921b0SApple OSS Distributions for (i = array2->getCount(); (str = array2->__takeObject(--i));) {
144*5c2921b0SApple OSS Distributions if (str != cache[i]) {
145*5c2921b0SApple OSS Distributions verPrintf(("testArray(A) test 3g%d failed\n", i));
146*5c2921b0SApple OSS Distributions res = false;
147*5c2921b0SApple OSS Distributions }
148*5c2921b0SApple OSS Distributions count += ((int) array2->getCount() == i);
149*5c2921b0SApple OSS Distributions str->release();
150*5c2921b0SApple OSS Distributions }
151*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3h", count == numStrCache);
152*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3i", -1 == i);
153*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3j", !array2->getCount());
154*5c2921b0SApple OSS Distributions
155*5c2921b0SApple OSS Distributions spaceCheck2 = checkPointSpace();
156*5c2921b0SApple OSS Distributions array2->flushCollection();
157*5c2921b0SApple OSS Distributions res = res && checkSpace("(A)3k", spaceCheck2, 0);
158*5c2921b0SApple OSS Distributions
159*5c2921b0SApple OSS Distributions array2->release();
160*5c2921b0SApple OSS Distributions array2 = 0;
161*5c2921b0SApple OSS Distributions }
162*5c2921b0SApple OSS Distributions if (array1) {
163*5c2921b0SApple OSS Distributions array2 = OSArray::withArray(array1, numStrCache - 1);
164*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3l", !array2);
165*5c2921b0SApple OSS Distributions array2 = OSArray::withArray(array1, array1->getCount());
166*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3m", array2);
167*5c2921b0SApple OSS Distributions array1->release();
168*5c2921b0SApple OSS Distributions }
169*5c2921b0SApple OSS Distributions if (array2) {
170*5c2921b0SApple OSS Distributions count = 0;
171*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3o", numStrCache == (int) array2->getCount());
172*5c2921b0SApple OSS Distributions for (i = 0; (str = array2->__takeObject(0)); i++) {
173*5c2921b0SApple OSS Distributions count += (str == cache[i]);
174*5c2921b0SApple OSS Distributions str->release();
175*5c2921b0SApple OSS Distributions }
176*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3p", count == numStrCache);
177*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "3q", !array2->getCount());
178*5c2921b0SApple OSS Distributions array2->release();
179*5c2921b0SApple OSS Distributions array2 = 0;
180*5c2921b0SApple OSS Distributions }
181*5c2921b0SApple OSS Distributions res = res && checkSpace("(A)3", spaceCheck, 0);
182*5c2921b0SApple OSS Distributions
183*5c2921b0SApple OSS Distributions // Test object replacement from one array to another
184*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
185*5c2921b0SApple OSS Distributions array1 = OSArray::withCapacity(numStrCache);
186*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4a", array1);
187*5c2921b0SApple OSS Distributions if (array1) {
188*5c2921b0SApple OSS Distributions count = count2 = 0;
189*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
190*5c2921b0SApple OSS Distributions str = OSString::withCStringNoCopy(strCache[i]);
191*5c2921b0SApple OSS Distributions count += array1->setObject(str);
192*5c2921b0SApple OSS Distributions count2 += (str == array1->lastObject());
193*5c2921b0SApple OSS Distributions str->release();
194*5c2921b0SApple OSS Distributions }
195*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4b", numStrCache == (int) array1->getCount());
196*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4c", count == numStrCache);
197*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4d", count2 == numStrCache);
198*5c2921b0SApple OSS Distributions }
199*5c2921b0SApple OSS Distributions array2 = OSArray::withCapacity(1);
200*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4e", array2);
201*5c2921b0SApple OSS Distributions if (array2) {
202*5c2921b0SApple OSS Distributions count = count2 = 0;
203*5c2921b0SApple OSS Distributions str = (OSObject *) OSSymbol::withCStringNoCopy(strCache[0]);
204*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
205*5c2921b0SApple OSS Distributions sym = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
206*5c2921b0SApple OSS Distributions count += array2->setObject(sym, 0);
207*5c2921b0SApple OSS Distributions count2 += (str == array2->lastObject());
208*5c2921b0SApple OSS Distributions sym->release();
209*5c2921b0SApple OSS Distributions }
210*5c2921b0SApple OSS Distributions str->release();
211*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4f", numStrCache == (int) array2->getCount());
212*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4g", count == numStrCache);
213*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4h", count2 == numStrCache);
214*5c2921b0SApple OSS Distributions }
215*5c2921b0SApple OSS Distributions if (array1 && array2) {
216*5c2921b0SApple OSS Distributions count = count2 = 0;
217*5c2921b0SApple OSS Distributions for (i = array1->getCount() - 1; (sym = array2->__takeObject(0)); i--) {
218*5c2921b0SApple OSS Distributions str = array1->replaceObject(sym, i);
219*5c2921b0SApple OSS Distributions count += (str != 0);
220*5c2921b0SApple OSS Distributions count2 += (sym != str);
221*5c2921b0SApple OSS Distributions if (str) {
222*5c2921b0SApple OSS Distributions str->release();
223*5c2921b0SApple OSS Distributions }
224*5c2921b0SApple OSS Distributions if (sym) {
225*5c2921b0SApple OSS Distributions sym->release();
226*5c2921b0SApple OSS Distributions }
227*5c2921b0SApple OSS Distributions }
228*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4k", numStrCache == (int) array1->getCount());
229*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4l", count == numStrCache);
230*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "4m", count2 == numStrCache);
231*5c2921b0SApple OSS Distributions array1->release();
232*5c2921b0SApple OSS Distributions array2->release();
233*5c2921b0SApple OSS Distributions } else {
234*5c2921b0SApple OSS Distributions if (array1) {
235*5c2921b0SApple OSS Distributions array1->release();
236*5c2921b0SApple OSS Distributions }
237*5c2921b0SApple OSS Distributions if (array2) {
238*5c2921b0SApple OSS Distributions array2->release();
239*5c2921b0SApple OSS Distributions }
240*5c2921b0SApple OSS Distributions }
241*5c2921b0SApple OSS Distributions res = res && checkSpace("(A)4", spaceCheck, 0);
242*5c2921b0SApple OSS Distributions
243*5c2921b0SApple OSS Distributions // Test array duplicate removal
244*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
245*5c2921b0SApple OSS Distributions array1 = OSArray::withCapacity(numStrCache);
246*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "5a", array1);
247*5c2921b0SApple OSS Distributions if (array1) {
248*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
249*5c2921b0SApple OSS Distributions sym = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
250*5c2921b0SApple OSS Distributions count += array1->setObject(sym);
251*5c2921b0SApple OSS Distributions sym->release();
252*5c2921b0SApple OSS Distributions }
253*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "5b", numStrCache == (int) array1->getCount());
254*5c2921b0SApple OSS Distributions
255*5c2921b0SApple OSS Distributions // remove duplicates
256*5c2921b0SApple OSS Distributions for (i = 0; (sym = array1->getObject(i));) {
257*5c2921b0SApple OSS Distributions if (sym->getRetainCount() == 1) {
258*5c2921b0SApple OSS Distributions i++;
259*5c2921b0SApple OSS Distributions } else {
260*5c2921b0SApple OSS Distributions //sym = array1->__takeObject(i);
261*5c2921b0SApple OSS Distributions //sym->release();
262*5c2921b0SApple OSS Distributions array1->removeObject(i);
263*5c2921b0SApple OSS Distributions }
264*5c2921b0SApple OSS Distributions }
265*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "5c", numStrCache != (int) array1->getCount());
266*5c2921b0SApple OSS Distributions
267*5c2921b0SApple OSS Distributions // check to see that all symbols are really there
268*5c2921b0SApple OSS Distributions for (count = 0, i = 0; i < numStrCache; i++) {
269*5c2921b0SApple OSS Distributions sym = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
270*5c2921b0SApple OSS Distributions for (count2 = false, j = 0; (str = array1->getObject(j)); j++) {
271*5c2921b0SApple OSS Distributions if (str == sym) {
272*5c2921b0SApple OSS Distributions count2 = true;
273*5c2921b0SApple OSS Distributions break;
274*5c2921b0SApple OSS Distributions }
275*5c2921b0SApple OSS Distributions }
276*5c2921b0SApple OSS Distributions count += count2;
277*5c2921b0SApple OSS Distributions sym->release();
278*5c2921b0SApple OSS Distributions }
279*5c2921b0SApple OSS Distributions TEST_ASSERT('A', "5c", count == numStrCache);
280*5c2921b0SApple OSS Distributions array1->release();
281*5c2921b0SApple OSS Distributions }
282*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)5", spaceCheck, 0);
283*5c2921b0SApple OSS Distributions
284*5c2921b0SApple OSS Distributions if (res) {
285*5c2921b0SApple OSS Distributions verPrintf(("testArray: All OSArray Tests passed\n"));
286*5c2921b0SApple OSS Distributions } else {
287*5c2921b0SApple OSS Distributions logPrintf(("testArray: Some OSArray Tests failed\n"));
288*5c2921b0SApple OSS Distributions }
289*5c2921b0SApple OSS Distributions }
290*5c2921b0SApple OSS Distributions
291*5c2921b0SApple OSS Distributions void
testSet()292*5c2921b0SApple OSS Distributions testSet()
293*5c2921b0SApple OSS Distributions {
294*5c2921b0SApple OSS Distributions bool res = true;
295*5c2921b0SApple OSS Distributions void *spaceCheck, *spaceCheck2, *spaceCheck3;
296*5c2921b0SApple OSS Distributions int i, count, count2;
297*5c2921b0SApple OSS Distributions OSObject *cache[numStrCache], *str, *sym;
298*5c2921b0SApple OSS Distributions OSSet *set1, *set2;
299*5c2921b0SApple OSS Distributions OSArray *array;
300*5c2921b0SApple OSS Distributions
301*5c2921b0SApple OSS Distributions // Do first test without memory leak tests to initialise the metaclass
302*5c2921b0SApple OSS Distributions set1 = OSSet::withCapacity(1);
303*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "0a", set1);
304*5c2921b0SApple OSS Distributions if (set1) {
305*5c2921b0SApple OSS Distributions set1->release();
306*5c2921b0SApple OSS Distributions }
307*5c2921b0SApple OSS Distributions
308*5c2921b0SApple OSS Distributions // Grow the symbol pool to maximum
309*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
310*5c2921b0SApple OSS Distributions cache[i] = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
311*5c2921b0SApple OSS Distributions }
312*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
313*5c2921b0SApple OSS Distributions cache[i]->release();
314*5c2921b0SApple OSS Distributions }
315*5c2921b0SApple OSS Distributions
316*5c2921b0SApple OSS Distributions // Create and destroy an set
317*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
318*5c2921b0SApple OSS Distributions set1 = OSSet::withCapacity(1);
319*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1a", set1);
320*5c2921b0SApple OSS Distributions if (set1) {
321*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1b", !set1->getCount());
322*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1c", 1 == set1->getCapacity());
323*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1d", 1 == set1->getCapacityIncrement());
324*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1e", 4 == set1->setCapacityIncrement(4));
325*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1f", 4 == set1->getCapacityIncrement());
326*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1g", 8 == set1->ensureCapacity(5));
327*5c2921b0SApple OSS Distributions
328*5c2921b0SApple OSS Distributions spaceCheck2 = checkPointSpace();
329*5c2921b0SApple OSS Distributions cache[0] = IOString::withCStringNoCopy(strCache[0]);
330*5c2921b0SApple OSS Distributions
331*5c2921b0SApple OSS Distributions spaceCheck3 = checkPointSpace();
332*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1h", set1->setObject(cache[0]));
333*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1i", set1->containsObject(cache[0]));
334*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1j", cache[0] == set1->getAnyObject());
335*5c2921b0SApple OSS Distributions cache[0]->release();
336*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)1k", spaceCheck3, 0);
337*5c2921b0SApple OSS Distributions
338*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1l", 1 == set1->getCount());
339*5c2921b0SApple OSS Distributions set1->flushCollection();
340*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "1m", !set1->getCount());
341*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)1n", spaceCheck2, 0);
342*5c2921b0SApple OSS Distributions
343*5c2921b0SApple OSS Distributions set1->release();
344*5c2921b0SApple OSS Distributions }
345*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)1", spaceCheck, 0);
346*5c2921b0SApple OSS Distributions
347*5c2921b0SApple OSS Distributions // Check the creation of a sizable OSSet from an set of IOObjects
348*5c2921b0SApple OSS Distributions // Also check member test of set.
349*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
350*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
351*5c2921b0SApple OSS Distributions cache[i] = OSString::withCStringNoCopy(strCache[i]);
352*5c2921b0SApple OSS Distributions }
353*5c2921b0SApple OSS Distributions set1 = OSSet::withObjects(cache, numStrCache, numStrCache);
354*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "2a", set1);
355*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
356*5c2921b0SApple OSS Distributions cache[i]->release();
357*5c2921b0SApple OSS Distributions }
358*5c2921b0SApple OSS Distributions if (set1) {
359*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "2b", numStrCache == (int) set1->getCount());
360*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "2c", numStrCache == (int) set1->getCapacity());
361*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "2d",
362*5c2921b0SApple OSS Distributions numStrCache == (int) set1->getCapacityIncrement());
363*5c2921b0SApple OSS Distributions
364*5c2921b0SApple OSS Distributions count = 0;
365*5c2921b0SApple OSS Distributions for (i = set1->getCount(); --i >= 0;) {
366*5c2921b0SApple OSS Distributions count += set1->member(cache[i]);
367*5c2921b0SApple OSS Distributions }
368*5c2921b0SApple OSS Distributions
369*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "2e", numStrCache == count);
370*5c2921b0SApple OSS Distributions set1->release();
371*5c2921b0SApple OSS Distributions }
372*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)2", spaceCheck, 0);
373*5c2921b0SApple OSS Distributions
374*5c2921b0SApple OSS Distributions // Test set creation from another set by both the setObject method
375*5c2921b0SApple OSS Distributions // and the withArray factory. And test __takeObject code first
376*5c2921b0SApple OSS Distributions // with tail removal then with head removal
377*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
378*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
379*5c2921b0SApple OSS Distributions cache[i] = OSString::withCStringNoCopy(strCache[i]);
380*5c2921b0SApple OSS Distributions }
381*5c2921b0SApple OSS Distributions set1 = OSSet::withObjects(cache, numStrCache, numStrCache);
382*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3a", set1);
383*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
384*5c2921b0SApple OSS Distributions cache[i]->release();
385*5c2921b0SApple OSS Distributions }
386*5c2921b0SApple OSS Distributions set2 = 0;
387*5c2921b0SApple OSS Distributions if (set1) {
388*5c2921b0SApple OSS Distributions set2 = OSSet::withCapacity(set1->getCount());
389*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3b", set2);
390*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3c", !set2->getCount());
391*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3d", set2->setObject(set1));
392*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3e", set1->getCount() == set2->getCount());
393*5c2921b0SApple OSS Distributions }
394*5c2921b0SApple OSS Distributions if (set2) {
395*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3f", numStrCache == (int) set2->getCount());
396*5c2921b0SApple OSS Distributions count = count2 = 0;
397*5c2921b0SApple OSS Distributions while ((str = set2->getAnyObject())) {
398*5c2921b0SApple OSS Distributions count += set2->__takeObject(str);
399*5c2921b0SApple OSS Distributions count2 += set1->member(str);
400*5c2921b0SApple OSS Distributions str->release();
401*5c2921b0SApple OSS Distributions }
402*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3g", !set2->getCount());
403*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3h", numStrCache == count);
404*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3i", numStrCache == count2);
405*5c2921b0SApple OSS Distributions
406*5c2921b0SApple OSS Distributions spaceCheck2 = checkPointSpace();
407*5c2921b0SApple OSS Distributions set2->flushCollection();
408*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)3j", spaceCheck2, 0);
409*5c2921b0SApple OSS Distributions
410*5c2921b0SApple OSS Distributions set2->release();
411*5c2921b0SApple OSS Distributions set2 = 0;
412*5c2921b0SApple OSS Distributions }
413*5c2921b0SApple OSS Distributions if (set1) {
414*5c2921b0SApple OSS Distributions set2 = OSSet::withSet(set1, numStrCache - 1);
415*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3k", !set2);
416*5c2921b0SApple OSS Distributions set2 = OSSet::withSet(set1, set1->getCount());
417*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3l", set2);
418*5c2921b0SApple OSS Distributions set1->release();
419*5c2921b0SApple OSS Distributions }
420*5c2921b0SApple OSS Distributions if (set2) {
421*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3m", numStrCache == (int) set2->getCount());
422*5c2921b0SApple OSS Distributions i = count = count2 = 0;
423*5c2921b0SApple OSS Distributions while ((str = set2->getAnyObject())) {
424*5c2921b0SApple OSS Distributions count += set2->__takeObject(str);
425*5c2921b0SApple OSS Distributions count2 += (cache[i++] == str);
426*5c2921b0SApple OSS Distributions str->release();
427*5c2921b0SApple OSS Distributions }
428*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3n", !set2->getCount());
429*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3o", numStrCache == count);
430*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "3p", numStrCache == count2);
431*5c2921b0SApple OSS Distributions
432*5c2921b0SApple OSS Distributions set2->release();
433*5c2921b0SApple OSS Distributions set2 = 0;
434*5c2921b0SApple OSS Distributions }
435*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)3", spaceCheck, 0);
436*5c2921b0SApple OSS Distributions
437*5c2921b0SApple OSS Distributions // Test duplicate removal
438*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
439*5c2921b0SApple OSS Distributions set2 = 0;
440*5c2921b0SApple OSS Distributions set1 = OSSet::withCapacity(numStrCache);
441*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "4a", set1);
442*5c2921b0SApple OSS Distributions if (set1) {
443*5c2921b0SApple OSS Distributions count = 0;
444*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
445*5c2921b0SApple OSS Distributions sym = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
446*5c2921b0SApple OSS Distributions count += set1->setObject(sym);
447*5c2921b0SApple OSS Distributions sym->release();
448*5c2921b0SApple OSS Distributions }
449*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "4b", numStrCache != (int) set1->getCount());
450*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "4c", count == (int) set1->getCount());
451*5c2921b0SApple OSS Distributions
452*5c2921b0SApple OSS Distributions count = count2 = 0;
453*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
454*5c2921b0SApple OSS Distributions sym = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
455*5c2921b0SApple OSS Distributions count += set1->member(sym);
456*5c2921b0SApple OSS Distributions count2 += sym->getRetainCount();
457*5c2921b0SApple OSS Distributions sym->release();
458*5c2921b0SApple OSS Distributions }
459*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "4d", count == numStrCache);
460*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "4e", count2 == numStrCache * 2);
461*5c2921b0SApple OSS Distributions
462*5c2921b0SApple OSS Distributions set2 = OSSet::withSet(set1, 2 * set1->getCount());
463*5c2921b0SApple OSS Distributions }
464*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "4f", set2);
465*5c2921b0SApple OSS Distributions if (set2) {
466*5c2921b0SApple OSS Distributions set2->setObject(set1);
467*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "4g", set1->getCount() == set2->getCount());
468*5c2921b0SApple OSS Distributions set1->release();
469*5c2921b0SApple OSS Distributions set2->release();
470*5c2921b0SApple OSS Distributions }
471*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)4", spaceCheck, 0);
472*5c2921b0SApple OSS Distributions
473*5c2921b0SApple OSS Distributions // Test array duplicate removal
474*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
475*5c2921b0SApple OSS Distributions array = OSArray::withCapacity(numStrCache);
476*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
477*5c2921b0SApple OSS Distributions sym = (OSObject *) OSSymbol::withCStringNoCopy(strCache[i]);
478*5c2921b0SApple OSS Distributions count += array->setObject(sym);
479*5c2921b0SApple OSS Distributions sym->release();
480*5c2921b0SApple OSS Distributions }
481*5c2921b0SApple OSS Distributions set1 = OSSet::withArray(array, numStrCache);
482*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "5a", set1);
483*5c2921b0SApple OSS Distributions if (set1) {
484*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "5b", array->getCount() != set1->getCount());
485*5c2921b0SApple OSS Distributions array->release();
486*5c2921b0SApple OSS Distributions
487*5c2921b0SApple OSS Distributions count = count2 = set1->getCount();
488*5c2921b0SApple OSS Distributions while ((sym = set1->getAnyObject())) {
489*5c2921b0SApple OSS Distributions count -= set1->__takeObject(sym);
490*5c2921b0SApple OSS Distributions count2 -= sym->getRetainCount();
491*5c2921b0SApple OSS Distributions sym->release();
492*5c2921b0SApple OSS Distributions }
493*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "5c", !count);
494*5c2921b0SApple OSS Distributions TEST_ASSERT('S', "5d", !count2);
495*5c2921b0SApple OSS Distributions set1->release();
496*5c2921b0SApple OSS Distributions }
497*5c2921b0SApple OSS Distributions res = res && checkSpace("(S)5", spaceCheck, 0);
498*5c2921b0SApple OSS Distributions
499*5c2921b0SApple OSS Distributions if (res) {
500*5c2921b0SApple OSS Distributions verPrintf(("testSet: All OSSet Tests passed\n"));
501*5c2921b0SApple OSS Distributions } else {
502*5c2921b0SApple OSS Distributions logPrintf(("testSet: Some OSSet Tests failed\n"));
503*5c2921b0SApple OSS Distributions }
504*5c2921b0SApple OSS Distributions }
505*5c2921b0SApple OSS Distributions
506*5c2921b0SApple OSS Distributions void
testDictionary()507*5c2921b0SApple OSS Distributions testDictionary()
508*5c2921b0SApple OSS Distributions {
509*5c2921b0SApple OSS Distributions bool res = true;
510*5c2921b0SApple OSS Distributions void *spaceCheck, *spaceCheck2, *spaceCheck3;
511*5c2921b0SApple OSS Distributions OSObject *cache[numStrCache];
512*5c2921b0SApple OSS Distributions OSString *str;
513*5c2921b0SApple OSS Distributions const OSSymbol *symCache[numStrCache], *sym;
514*5c2921b0SApple OSS Distributions OSDictionary *dict1, *dict2;
515*5c2921b0SApple OSS Distributions int i, numSymbols, count1, count2;
516*5c2921b0SApple OSS Distributions
517*5c2921b0SApple OSS Distributions // Do first test without memory leak tests to initialise the metaclass
518*5c2921b0SApple OSS Distributions dict1 = OSDictionary::withCapacity(1);
519*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "0a", dict1);
520*5c2921b0SApple OSS Distributions if (dict1) {
521*5c2921b0SApple OSS Distributions dict1->release();
522*5c2921b0SApple OSS Distributions }
523*5c2921b0SApple OSS Distributions
524*5c2921b0SApple OSS Distributions // Grow the symbol pool to maximum
525*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
526*5c2921b0SApple OSS Distributions symCache[i] = OSSymbol::withCStringNoCopy(strCache[i]);
527*5c2921b0SApple OSS Distributions }
528*5c2921b0SApple OSS Distributions for (i = 0; i < numStrCache; i++) {
529*5c2921b0SApple OSS Distributions symCache[i]->release();
530*5c2921b0SApple OSS Distributions }
531*5c2921b0SApple OSS Distributions
532*5c2921b0SApple OSS Distributions // Create and destroy a dictionary
533*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
534*5c2921b0SApple OSS Distributions dict1 = OSDictionary::withCapacity(1);
535*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1a", dict1);
536*5c2921b0SApple OSS Distributions if (dict1) {
537*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1b", !dict1->getCount());
538*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1c", 1 == dict1->getCapacity());
539*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1d", 1 == dict1->getCapacityIncrement());
540*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1e", 4 == dict1->setCapacityIncrement(4));
541*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1f", 4 == dict1->getCapacityIncrement());
542*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1g", 8 == dict1->ensureCapacity(5));
543*5c2921b0SApple OSS Distributions
544*5c2921b0SApple OSS Distributions spaceCheck2 = checkPointSpace();
545*5c2921b0SApple OSS Distributions sym = OSSymbol::withCStringNoCopy(strCache[0]);
546*5c2921b0SApple OSS Distributions
547*5c2921b0SApple OSS Distributions spaceCheck3 = checkPointSpace();
548*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1h", dict1->setObject((OSObject *) sym, sym));
549*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1i", (OSObject *) sym == dict1->getObject(sym));
550*5c2921b0SApple OSS Distributions sym->release();
551*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1i", 2 == sym->getRetainCount());
552*5c2921b0SApple OSS Distributions res = res && checkSpace("(D)1j", spaceCheck3, 0);
553*5c2921b0SApple OSS Distributions
554*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1k", 1 == dict1->getCount());
555*5c2921b0SApple OSS Distributions dict1->flushCollection();
556*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "1l", !dict1->getCount());
557*5c2921b0SApple OSS Distributions res = res && checkSpace("(D)1m", spaceCheck2, 0);
558*5c2921b0SApple OSS Distributions
559*5c2921b0SApple OSS Distributions dict1->release();
560*5c2921b0SApple OSS Distributions }
561*5c2921b0SApple OSS Distributions res = res && checkSpace("(D)1", spaceCheck, 0);
562*5c2921b0SApple OSS Distributions
563*5c2921b0SApple OSS Distributions // Check the creation of a sizable OSDictionary from an array of IOObjects
564*5c2921b0SApple OSS Distributions // Also check indexing into the array.
565*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
566*5c2921b0SApple OSS Distributions for (i = 0, numSymbols = 0; i < numStrCache; i++) {
567*5c2921b0SApple OSS Distributions sym = OSSymbol::withCStringNoCopy(strCache[i]);
568*5c2921b0SApple OSS Distributions if (1 == sym->getRetainCount()) {
569*5c2921b0SApple OSS Distributions symCache[numSymbols++] = sym;
570*5c2921b0SApple OSS Distributions } else {
571*5c2921b0SApple OSS Distributions sym->release();
572*5c2921b0SApple OSS Distributions }
573*5c2921b0SApple OSS Distributions }
574*5c2921b0SApple OSS Distributions dict1 = OSDictionary::withObjects(
575*5c2921b0SApple OSS Distributions (OSObject **) symCache, symCache, numSymbols, numSymbols);
576*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "2a", dict1);
577*5c2921b0SApple OSS Distributions count1 = count2 = 0;
578*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
579*5c2921b0SApple OSS Distributions count1 += (symCache[i]->getRetainCount() == 3);
580*5c2921b0SApple OSS Distributions }
581*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "2b", count1 == numSymbols);
582*5c2921b0SApple OSS Distributions if (dict1) {
583*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "2c", numSymbols == (int) dict1->getCount());
584*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "2d", numSymbols == (int) dict1->getCapacity());
585*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "2e",
586*5c2921b0SApple OSS Distributions numSymbols == (int) dict1->getCapacityIncrement());
587*5c2921b0SApple OSS Distributions
588*5c2921b0SApple OSS Distributions for (i = dict1->getCount(); --i >= 0;) {
589*5c2921b0SApple OSS Distributions str = (OSString *) dict1->getObject(symCache[i]);
590*5c2921b0SApple OSS Distributions if (str != (OSString *) symCache[i]) {
591*5c2921b0SApple OSS Distributions verPrintf(("testDictionary(D) test 2f%d failed\n", i));
592*5c2921b0SApple OSS Distributions res = false;
593*5c2921b0SApple OSS Distributions }
594*5c2921b0SApple OSS Distributions }
595*5c2921b0SApple OSS Distributions dict1->release();
596*5c2921b0SApple OSS Distributions }
597*5c2921b0SApple OSS Distributions count1 = count2 = 0;
598*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
599*5c2921b0SApple OSS Distributions count1 += (symCache[i]->getRetainCount() == 1);
600*5c2921b0SApple OSS Distributions symCache[i]->release();
601*5c2921b0SApple OSS Distributions }
602*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "2g", count1 == numSymbols);
603*5c2921b0SApple OSS Distributions res = res && checkSpace("(D)2", spaceCheck, 0);
604*5c2921b0SApple OSS Distributions
605*5c2921b0SApple OSS Distributions // Check the creation of a sizable Dictionary from an array of IOStrings
606*5c2921b0SApple OSS Distributions // Also check searching dictionary use OSString for a key.
607*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
608*5c2921b0SApple OSS Distributions for (i = 0, numSymbols = 0; i < numStrCache; i++) {
609*5c2921b0SApple OSS Distributions sym = OSSymbol::withCStringNoCopy(strCache[i]);
610*5c2921b0SApple OSS Distributions if (1 == sym->getRetainCount()) {
611*5c2921b0SApple OSS Distributions cache[numSymbols] = OSString::withCStringNoCopy(strCache[i]);
612*5c2921b0SApple OSS Distributions symCache[numSymbols] = sym;
613*5c2921b0SApple OSS Distributions numSymbols++;
614*5c2921b0SApple OSS Distributions } else {
615*5c2921b0SApple OSS Distributions sym->release();
616*5c2921b0SApple OSS Distributions }
617*5c2921b0SApple OSS Distributions }
618*5c2921b0SApple OSS Distributions dict1 = OSDictionary::withObjects((OSObject **) symCache,
619*5c2921b0SApple OSS Distributions (OSString **) cache,
620*5c2921b0SApple OSS Distributions numSymbols, numSymbols);
621*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3a", dict1);
622*5c2921b0SApple OSS Distributions count1 = count2 = 0;
623*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
624*5c2921b0SApple OSS Distributions count1 += (symCache[i]->getRetainCount() == 3);
625*5c2921b0SApple OSS Distributions count2 += (cache[i]->getRetainCount() == 1);
626*5c2921b0SApple OSS Distributions }
627*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3b", count1 == numSymbols);
628*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3c", count2 == numSymbols);
629*5c2921b0SApple OSS Distributions if (dict1) {
630*5c2921b0SApple OSS Distributions count1 = count2 = 0;
631*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
632*5c2921b0SApple OSS Distributions str = (OSString *) cache[i];
633*5c2921b0SApple OSS Distributions count1 += (symCache[i] == (const OSSymbol *) dict1->getObject(str));
634*5c2921b0SApple OSS Distributions count2 += (symCache[i]->getRetainCount() == 3);
635*5c2921b0SApple OSS Distributions }
636*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3d", count1 == numSymbols);
637*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3e", count2 == numSymbols);
638*5c2921b0SApple OSS Distributions
639*5c2921b0SApple OSS Distributions count1 = count2 = 0;
640*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
641*5c2921b0SApple OSS Distributions const char *cStr = ((OSString *) cache[i])->getCStringNoCopy();
642*5c2921b0SApple OSS Distributions
643*5c2921b0SApple OSS Distributions count1 += (symCache[i] == (const OSSymbol *) dict1->getObject(cStr));
644*5c2921b0SApple OSS Distributions count2 += (symCache[i]->getRetainCount() == 3);
645*5c2921b0SApple OSS Distributions }
646*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3f", count1 == numSymbols);
647*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3g", count2 == numSymbols);
648*5c2921b0SApple OSS Distributions
649*5c2921b0SApple OSS Distributions dict1->release();
650*5c2921b0SApple OSS Distributions }
651*5c2921b0SApple OSS Distributions count1 = count2 = 0;
652*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
653*5c2921b0SApple OSS Distributions count1 += (symCache[i]->getRetainCount() == 1);
654*5c2921b0SApple OSS Distributions count2 += (cache[i]->getRetainCount() == 1);
655*5c2921b0SApple OSS Distributions symCache[i]->release();
656*5c2921b0SApple OSS Distributions cache[i]->release();
657*5c2921b0SApple OSS Distributions }
658*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "3h", count1 == numSymbols);
659*5c2921b0SApple OSS Distributions res = res && checkSpace("(D)3", spaceCheck, 0);
660*5c2921b0SApple OSS Distributions
661*5c2921b0SApple OSS Distributions // Check the creation of a small dictionary then grow it one item at a time
662*5c2921b0SApple OSS Distributions // Create a new dictionary from the old dictionary.
663*5c2921b0SApple OSS Distributions // Finally remove each item permanently.
664*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
665*5c2921b0SApple OSS Distributions for (i = 0, numSymbols = 0; i < numStrCache; i++) {
666*5c2921b0SApple OSS Distributions sym = OSSymbol::withCStringNoCopy(strCache[i]);
667*5c2921b0SApple OSS Distributions if (1 == sym->getRetainCount()) {
668*5c2921b0SApple OSS Distributions cache[numSymbols] = OSString::withCStringNoCopy(strCache[i]);
669*5c2921b0SApple OSS Distributions symCache[numSymbols] = sym;
670*5c2921b0SApple OSS Distributions numSymbols++;
671*5c2921b0SApple OSS Distributions } else {
672*5c2921b0SApple OSS Distributions sym->release();
673*5c2921b0SApple OSS Distributions }
674*5c2921b0SApple OSS Distributions }
675*5c2921b0SApple OSS Distributions dict2 = 0;
676*5c2921b0SApple OSS Distributions dict1 = OSDictionary::withCapacity(1);
677*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4a", dict1);
678*5c2921b0SApple OSS Distributions if (dict1) {
679*5c2921b0SApple OSS Distributions count1 = count2 = 0;
680*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
681*5c2921b0SApple OSS Distributions sym = symCache[i];
682*5c2921b0SApple OSS Distributions count1 += ((OSObject *) sym == dict1->setObject((OSObject *) sym,
683*5c2921b0SApple OSS Distributions sym->getCStringNoCopy()));
684*5c2921b0SApple OSS Distributions count2 += (sym->getRetainCount() == 3);
685*5c2921b0SApple OSS Distributions }
686*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4b", numSymbols == (int) dict1->getCount());
687*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4c", numSymbols == count1);
688*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4d", numSymbols == count2);
689*5c2921b0SApple OSS Distributions
690*5c2921b0SApple OSS Distributions dict2 = OSDictionary::withDictionary(dict1, numSymbols - 1);
691*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4b", !dict2);
692*5c2921b0SApple OSS Distributions dict2 = OSDictionary::withDictionary(dict1, numSymbols);
693*5c2921b0SApple OSS Distributions }
694*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4e", dict2);
695*5c2921b0SApple OSS Distributions if (dict2) {
696*5c2921b0SApple OSS Distributions dict1->release(); dict1 = 0;
697*5c2921b0SApple OSS Distributions
698*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4f", numSymbols == (int) dict2->getCount());
699*5c2921b0SApple OSS Distributions
700*5c2921b0SApple OSS Distributions count1 = count2 = 0;
701*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
702*5c2921b0SApple OSS Distributions OSObject *replacedObject;
703*5c2921b0SApple OSS Distributions
704*5c2921b0SApple OSS Distributions sym = symCache[i];
705*5c2921b0SApple OSS Distributions str = (OSString *) cache[i];
706*5c2921b0SApple OSS Distributions replacedObject = dict2->setObject(str, str);
707*5c2921b0SApple OSS Distributions count1 += ((OSString *) sym == replacedObject);
708*5c2921b0SApple OSS Distributions replacedObject->release();
709*5c2921b0SApple OSS Distributions count2 += (sym->getRetainCount() == 2);
710*5c2921b0SApple OSS Distributions str->release();
711*5c2921b0SApple OSS Distributions }
712*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4g", numSymbols == count1);
713*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4h", numSymbols == count2);
714*5c2921b0SApple OSS Distributions
715*5c2921b0SApple OSS Distributions count1 = count2 = 0;
716*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
717*5c2921b0SApple OSS Distributions sym = symCache[i];
718*5c2921b0SApple OSS Distributions str = (OSString *) cache[i];
719*5c2921b0SApple OSS Distributions count1 += (str == dict2->__takeObject(sym));
720*5c2921b0SApple OSS Distributions str->release();
721*5c2921b0SApple OSS Distributions count2 += (sym->getRetainCount() == 1);
722*5c2921b0SApple OSS Distributions sym->release();
723*5c2921b0SApple OSS Distributions }
724*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4i", numSymbols == count1);
725*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4j", numSymbols == count2);
726*5c2921b0SApple OSS Distributions TEST_ASSERT('D', "4k", !dict2->getCount());
727*5c2921b0SApple OSS Distributions dict2->release(); dict2 = 0;
728*5c2921b0SApple OSS Distributions } else if (dict1) {
729*5c2921b0SApple OSS Distributions dict1->release();
730*5c2921b0SApple OSS Distributions }
731*5c2921b0SApple OSS Distributions res = res && checkSpace("(D)4", spaceCheck, 0);
732*5c2921b0SApple OSS Distributions
733*5c2921b0SApple OSS Distributions if (res) {
734*5c2921b0SApple OSS Distributions verPrintf(("testDictionary: All OSDictionary Tests passed\n"));
735*5c2921b0SApple OSS Distributions } else {
736*5c2921b0SApple OSS Distributions logPrintf(("testDictionary: Some OSDictionary Tests failed\n"));
737*5c2921b0SApple OSS Distributions }
738*5c2921b0SApple OSS Distributions }
739*5c2921b0SApple OSS Distributions
740*5c2921b0SApple OSS Distributions void
testIterator()741*5c2921b0SApple OSS Distributions testIterator()
742*5c2921b0SApple OSS Distributions {
743*5c2921b0SApple OSS Distributions bool res = true;
744*5c2921b0SApple OSS Distributions void *spaceCheck;
745*5c2921b0SApple OSS Distributions OSObject *cache[numStrCache];
746*5c2921b0SApple OSS Distributions OSString *str = 0;
747*5c2921b0SApple OSS Distributions const OSSymbol *symCache[numStrCache], *sym;
748*5c2921b0SApple OSS Distributions OSDictionary *dict;
749*5c2921b0SApple OSS Distributions OSSet *set;
750*5c2921b0SApple OSS Distributions OSArray *array, *bigReturn;
751*5c2921b0SApple OSS Distributions OSCollectionIterator *iter1, *iter2;
752*5c2921b0SApple OSS Distributions int i, numSymbols, count1, count2, count3;
753*5c2921b0SApple OSS Distributions
754*5c2921b0SApple OSS Distributions // Setup symbol and string pools
755*5c2921b0SApple OSS Distributions for (i = 0, numSymbols = 0; i < numStrCache; i++) {
756*5c2921b0SApple OSS Distributions sym = OSSymbol::withCStringNoCopy(strCache[i]);
757*5c2921b0SApple OSS Distributions if (1 == sym->getRetainCount()) {
758*5c2921b0SApple OSS Distributions cache[numSymbols] = OSString::withCStringNoCopy(strCache[i]);
759*5c2921b0SApple OSS Distributions symCache[numSymbols] = sym;
760*5c2921b0SApple OSS Distributions numSymbols++;
761*5c2921b0SApple OSS Distributions } else {
762*5c2921b0SApple OSS Distributions sym->release();
763*5c2921b0SApple OSS Distributions }
764*5c2921b0SApple OSS Distributions }
765*5c2921b0SApple OSS Distributions
766*5c2921b0SApple OSS Distributions // Test the array iterator
767*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
768*5c2921b0SApple OSS Distributions iter1 = iter2 = 0;
769*5c2921b0SApple OSS Distributions array = OSArray::withCapacity(numSymbols);
770*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1a", array);
771*5c2921b0SApple OSS Distributions if (array) {
772*5c2921b0SApple OSS Distributions count1 = count2 = 0;
773*5c2921b0SApple OSS Distributions for (i = numSymbols; --i >= 0;) {
774*5c2921b0SApple OSS Distributions count1 += array->setObject(cache[i], 0);
775*5c2921b0SApple OSS Distributions }
776*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1b", count1 == numSymbols);
777*5c2921b0SApple OSS Distributions
778*5c2921b0SApple OSS Distributions iter1 = OSCollectionIterator::withCollection(array);
779*5c2921b0SApple OSS Distributions iter2 = OSCollectionIterator::withCollection(array);
780*5c2921b0SApple OSS Distributions }
781*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1c", iter1);
782*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1d", iter2);
783*5c2921b0SApple OSS Distributions if (iter1 && iter2) {
784*5c2921b0SApple OSS Distributions count1 = count2 = count3 = 0;
785*5c2921b0SApple OSS Distributions for (i = 0; (str = (IOString *) iter1->getNextObject()); i++) {
786*5c2921b0SApple OSS Distributions bigReturn = iter2->nextEntries();
787*5c2921b0SApple OSS Distributions count1 += (bigReturn->getCount() == 1);
788*5c2921b0SApple OSS Distributions count2 += (cache[i] == bigReturn->getObject(0));
789*5c2921b0SApple OSS Distributions count3 += (cache[i] == str);
790*5c2921b0SApple OSS Distributions }
791*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1e", count1 == numSymbols);
792*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1f", count2 == numSymbols);
793*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1g", count3 == numSymbols);
794*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1h", iter1->valid());
795*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1i", iter2->valid());
796*5c2921b0SApple OSS Distributions
797*5c2921b0SApple OSS Distributions iter1->reset();
798*5c2921b0SApple OSS Distributions str = (OSString *) array->__takeObject(0);
799*5c2921b0SApple OSS Distributions array->setObject(str, 0);
800*5c2921b0SApple OSS Distributions str->release();
801*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1j", !iter1->getNextObject());
802*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1k", !iter1->valid());
803*5c2921b0SApple OSS Distributions
804*5c2921b0SApple OSS Distributions iter1->reset();
805*5c2921b0SApple OSS Distributions count1 = count2 = count3 = 0;
806*5c2921b0SApple OSS Distributions for (i = 0;; i++) {
807*5c2921b0SApple OSS Distributions if (i & 1) {
808*5c2921b0SApple OSS Distributions str = (OSString *) iter1->getNextObject();
809*5c2921b0SApple OSS Distributions } else if ((bigReturn = iter1->nextEntries())) {
810*5c2921b0SApple OSS Distributions str = (OSString *) bigReturn->getObject(0);
811*5c2921b0SApple OSS Distributions } else {
812*5c2921b0SApple OSS Distributions str = 0;
813*5c2921b0SApple OSS Distributions }
814*5c2921b0SApple OSS Distributions
815*5c2921b0SApple OSS Distributions if (!str) {
816*5c2921b0SApple OSS Distributions break;
817*5c2921b0SApple OSS Distributions }
818*5c2921b0SApple OSS Distributions count1 += (cache[i] == str);
819*5c2921b0SApple OSS Distributions }
820*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1l", count1 == numSymbols);
821*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1m", i == numSymbols);
822*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1n", iter1->valid());
823*5c2921b0SApple OSS Distributions
824*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "1o", 3 == array->getRetainCount());
825*5c2921b0SApple OSS Distributions array->release();
826*5c2921b0SApple OSS Distributions }
827*5c2921b0SApple OSS Distributions
828*5c2921b0SApple OSS Distributions if (iter1) {
829*5c2921b0SApple OSS Distributions iter1->release();
830*5c2921b0SApple OSS Distributions }
831*5c2921b0SApple OSS Distributions if (iter2) {
832*5c2921b0SApple OSS Distributions iter2->release();
833*5c2921b0SApple OSS Distributions }
834*5c2921b0SApple OSS Distributions res = res && checkSpace("(I)1", spaceCheck, 0);
835*5c2921b0SApple OSS Distributions
836*5c2921b0SApple OSS Distributions // Test the set iterator
837*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
838*5c2921b0SApple OSS Distributions iter1 = 0;
839*5c2921b0SApple OSS Distributions set = OSSet::withCapacity(numSymbols);
840*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2a", set);
841*5c2921b0SApple OSS Distributions if (set) {
842*5c2921b0SApple OSS Distributions count1 = count2 = 0;
843*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
844*5c2921b0SApple OSS Distributions count1 += set->setObject(cache[i]);
845*5c2921b0SApple OSS Distributions }
846*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2b", count1 == numSymbols);
847*5c2921b0SApple OSS Distributions
848*5c2921b0SApple OSS Distributions iter1 = OSCollectionIterator::withCollection(set);
849*5c2921b0SApple OSS Distributions iter2 = OSCollectionIterator::withCollection(set);
850*5c2921b0SApple OSS Distributions }
851*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2c", iter1);
852*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2d", iter2);
853*5c2921b0SApple OSS Distributions if (iter1 && iter2) {
854*5c2921b0SApple OSS Distributions count1 = count2 = count3 = 0;
855*5c2921b0SApple OSS Distributions for (i = 0; (str = (IOString *) iter1->getNextObject()); i++) {
856*5c2921b0SApple OSS Distributions bigReturn = iter2->nextEntries();
857*5c2921b0SApple OSS Distributions count1 += (bigReturn->getCount() == 1);
858*5c2921b0SApple OSS Distributions count2 += (cache[i] == bigReturn->getObject(0));
859*5c2921b0SApple OSS Distributions count3 += (cache[i] == str);
860*5c2921b0SApple OSS Distributions }
861*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2e", count1 == numSymbols);
862*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2f", count2 == numSymbols);
863*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2g", count3 == numSymbols);
864*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2h", iter1->valid());
865*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2i", iter2->valid());
866*5c2921b0SApple OSS Distributions
867*5c2921b0SApple OSS Distributions iter1->reset();
868*5c2921b0SApple OSS Distributions count1 = count2 = count3 = 0;
869*5c2921b0SApple OSS Distributions for (i = 0;; i++) {
870*5c2921b0SApple OSS Distributions if (i & 1) {
871*5c2921b0SApple OSS Distributions str = (OSString *) iter1->getNextObject();
872*5c2921b0SApple OSS Distributions } else if ((bigReturn = iter1->nextEntries())) {
873*5c2921b0SApple OSS Distributions str = (OSString *) bigReturn->getObject(0);
874*5c2921b0SApple OSS Distributions } else {
875*5c2921b0SApple OSS Distributions str = 0;
876*5c2921b0SApple OSS Distributions }
877*5c2921b0SApple OSS Distributions
878*5c2921b0SApple OSS Distributions if (!str) {
879*5c2921b0SApple OSS Distributions break;
880*5c2921b0SApple OSS Distributions }
881*5c2921b0SApple OSS Distributions count1 += (cache[i] == str);
882*5c2921b0SApple OSS Distributions }
883*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2l", count1 == numSymbols);
884*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2m", i == numSymbols);
885*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2n", iter1->valid());
886*5c2921b0SApple OSS Distributions
887*5c2921b0SApple OSS Distributions iter1->reset();
888*5c2921b0SApple OSS Distributions str = (OSString *) set->getAnyObject();
889*5c2921b0SApple OSS Distributions (void) set->__takeObject(str);
890*5c2921b0SApple OSS Distributions set->setObject(str);
891*5c2921b0SApple OSS Distributions str->release();
892*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2j", !iter1->getNextObject());
893*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2k", !iter1->valid());
894*5c2921b0SApple OSS Distributions
895*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "2o", 3 == set->getRetainCount());
896*5c2921b0SApple OSS Distributions set->release();
897*5c2921b0SApple OSS Distributions }
898*5c2921b0SApple OSS Distributions
899*5c2921b0SApple OSS Distributions if (iter1) {
900*5c2921b0SApple OSS Distributions iter1->release();
901*5c2921b0SApple OSS Distributions }
902*5c2921b0SApple OSS Distributions if (iter2) {
903*5c2921b0SApple OSS Distributions iter2->release();
904*5c2921b0SApple OSS Distributions }
905*5c2921b0SApple OSS Distributions res = res && checkSpace("(I)2", spaceCheck, 0);
906*5c2921b0SApple OSS Distributions
907*5c2921b0SApple OSS Distributions // Test the dictionary iterator
908*5c2921b0SApple OSS Distributions spaceCheck = checkPointSpace();
909*5c2921b0SApple OSS Distributions iter1 = 0;
910*5c2921b0SApple OSS Distributions dict = OSDictionary::withCapacity(numSymbols);
911*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3a", dict);
912*5c2921b0SApple OSS Distributions if (dict) {
913*5c2921b0SApple OSS Distributions count1 = count2 = 0;
914*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
915*5c2921b0SApple OSS Distributions count1 += (0 != dict->setObject(cache[i], symCache[i]));
916*5c2921b0SApple OSS Distributions }
917*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3b", count1 == numSymbols);
918*5c2921b0SApple OSS Distributions
919*5c2921b0SApple OSS Distributions iter1 = OSCollectionIterator::withCollection(dict);
920*5c2921b0SApple OSS Distributions iter2 = OSCollectionIterator::withCollection(dict);
921*5c2921b0SApple OSS Distributions }
922*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3c", iter1);
923*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3d", iter2);
924*5c2921b0SApple OSS Distributions if (iter1 && iter2) {
925*5c2921b0SApple OSS Distributions count1 = count2 = count3 = 0;
926*5c2921b0SApple OSS Distributions for (i = 0; (sym = (const IOSymbol *) iter1->getNextObject()); i++) {
927*5c2921b0SApple OSS Distributions bigReturn = iter2->nextEntries();
928*5c2921b0SApple OSS Distributions count1 += (bigReturn->getCount() == 2);
929*5c2921b0SApple OSS Distributions count2 += (cache[i] == bigReturn->getObject(1));
930*5c2921b0SApple OSS Distributions count3 += (symCache[i] == sym);
931*5c2921b0SApple OSS Distributions }
932*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3e", count1 == numSymbols);
933*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3f", count2 == numSymbols);
934*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3g", count3 == numSymbols);
935*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3h", iter1->valid());
936*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3i", iter2->valid());
937*5c2921b0SApple OSS Distributions
938*5c2921b0SApple OSS Distributions iter1->reset();
939*5c2921b0SApple OSS Distributions count1 = count2 = count3 = 0;
940*5c2921b0SApple OSS Distributions i = 0;
941*5c2921b0SApple OSS Distributions for (i = 0;; i++) {
942*5c2921b0SApple OSS Distributions if (i & 1) {
943*5c2921b0SApple OSS Distributions sym = (const OSSymbol *) iter1->getNextObject();
944*5c2921b0SApple OSS Distributions str = 0;
945*5c2921b0SApple OSS Distributions } else if ((bigReturn = iter1->nextEntries())) {
946*5c2921b0SApple OSS Distributions sym = (const OSSymbol *) bigReturn->getObject(0);
947*5c2921b0SApple OSS Distributions str = (OSString *) bigReturn->getObject(1);
948*5c2921b0SApple OSS Distributions } else {
949*5c2921b0SApple OSS Distributions sym = 0;
950*5c2921b0SApple OSS Distributions }
951*5c2921b0SApple OSS Distributions
952*5c2921b0SApple OSS Distributions if (!sym) {
953*5c2921b0SApple OSS Distributions break;
954*5c2921b0SApple OSS Distributions }
955*5c2921b0SApple OSS Distributions
956*5c2921b0SApple OSS Distributions count1 += (symCache[i] == sym);
957*5c2921b0SApple OSS Distributions count2 += (!str || cache[i] == str);
958*5c2921b0SApple OSS Distributions }
959*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3l", count1 == numSymbols);
960*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3m", count2 == numSymbols);
961*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3n", i == numSymbols);
962*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3o", iter1->valid());
963*5c2921b0SApple OSS Distributions
964*5c2921b0SApple OSS Distributions iter1->reset();
965*5c2921b0SApple OSS Distributions str = (OSString *) dict->__takeObject(symCache[numSymbols - 1]);
966*5c2921b0SApple OSS Distributions dict->setObject(str, symCache[numSymbols - 1]);
967*5c2921b0SApple OSS Distributions str->release();
968*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3j", !iter1->getNextObject());
969*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3k", !iter1->valid());
970*5c2921b0SApple OSS Distributions
971*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "3p", 3 == dict->getRetainCount());
972*5c2921b0SApple OSS Distributions dict->release();
973*5c2921b0SApple OSS Distributions }
974*5c2921b0SApple OSS Distributions
975*5c2921b0SApple OSS Distributions if (iter1) {
976*5c2921b0SApple OSS Distributions iter1->release();
977*5c2921b0SApple OSS Distributions }
978*5c2921b0SApple OSS Distributions if (iter2) {
979*5c2921b0SApple OSS Distributions iter2->release();
980*5c2921b0SApple OSS Distributions }
981*5c2921b0SApple OSS Distributions res = res && checkSpace("(I)3", spaceCheck, 0);
982*5c2921b0SApple OSS Distributions
983*5c2921b0SApple OSS Distributions count1 = count2 = count3 = 0;
984*5c2921b0SApple OSS Distributions for (i = 0; i < numSymbols; i++) {
985*5c2921b0SApple OSS Distributions count1 += (1 == cache[i]->getRetainCount());
986*5c2921b0SApple OSS Distributions count2 += (1 == symCache[i]->getRetainCount());
987*5c2921b0SApple OSS Distributions cache[i]->release();
988*5c2921b0SApple OSS Distributions symCache[i]->release();
989*5c2921b0SApple OSS Distributions }
990*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "4a", count1 == numSymbols);
991*5c2921b0SApple OSS Distributions TEST_ASSERT('I', "4b", count2 == numSymbols);
992*5c2921b0SApple OSS Distributions
993*5c2921b0SApple OSS Distributions if (res) {
994*5c2921b0SApple OSS Distributions verPrintf(("testIterator: All OSCollectionIterator Tests passed\n"));
995*5c2921b0SApple OSS Distributions } else {
996*5c2921b0SApple OSS Distributions logPrintf(("testIterator: Some OSCollectionIterator Tests failed\n"));
997*5c2921b0SApple OSS Distributions }
998*5c2921b0SApple OSS Distributions }
999*5c2921b0SApple OSS Distributions
1000*5c2921b0SApple OSS Distributions #endif /* DEBUG */
1001