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