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