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