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