]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/v32test.cpp
1 /********************************************************************
3 * Copyright (c) 2002-2007, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
10 // ICU Regular Expressions test, part of intltest.
23 //---------------------------------------------------------------------------
25 // Test class boilerplate
27 //---------------------------------------------------------------------------
28 UVector32Test::UVector32Test()
33 UVector32Test::~UVector32Test()
39 void UVector32Test::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
41 if (exec
) logln("TestSuite UVector32Test: ");
44 case 0: name
= "UVector32_API";
45 if (exec
) UVector32_API();
48 break; //needed to end loop
53 //---------------------------------------------------------------------------
55 // Error Checking / Reporting macros used in all of the tests.
57 //---------------------------------------------------------------------------
58 #define TEST_CHECK_STATUS(status) \
59 if (U_FAILURE(status)) {\
60 errln("UVector32Test failure at line %d. status=%s\n", __LINE__, u_errorName(status));\
64 #define TEST_ASSERT(expr) \
66 errln("UVector32Test failure at line %d.\n", __LINE__);\
69 //---------------------------------------------------------------------------
71 // UVector32_API Check for basic functionality of UVector32.
73 //---------------------------------------------------------------------------
74 void UVector32Test::UVector32_API() {
76 UErrorCode status
= U_ZERO_ERROR
;
80 a
= new UVector32(status
);
81 TEST_CHECK_STATUS(status
);
84 status
= U_ZERO_ERROR
;
85 a
= new UVector32(2000, status
);
86 TEST_CHECK_STATUS(status
);
92 status
= U_ZERO_ERROR
;
93 a
= new UVector32(status
);
94 a
->addElement(10, status
);
95 a
->addElement(20, status
);
96 a
->addElement(30, status
);
97 b
= new UVector32(status
);
98 b
->assign(*a
, status
);
99 TEST_ASSERT(b
->size() == 3);
100 TEST_ASSERT(b
->elementAti(1) == 20);
101 TEST_CHECK_STATUS(status
);
106 // operator == and != and equals()
108 status
= U_ZERO_ERROR
;
109 a
= new UVector32(status
);
110 a
->addElement(10, status
);
111 a
->addElement(20, status
);
112 a
->addElement(30, status
);
113 b
= new UVector32(status
);
114 TEST_ASSERT(*b
!= *a
);
115 TEST_ASSERT(!(*b
== *a
));
116 TEST_ASSERT(!b
->equals(*a
));
117 b
->assign(*a
, status
);
118 TEST_ASSERT(*b
== *a
);
119 TEST_ASSERT(!(*b
!= *a
));
120 TEST_ASSERT(b
->equals(*a
));
121 b
->addElement(666, status
);
122 TEST_ASSERT(*b
!= *a
);
123 TEST_ASSERT(!(*b
== *a
));
124 TEST_ASSERT(!b
->equals(*a
));
125 TEST_CHECK_STATUS(status
);
130 // addElement(). Covered by above tests.
136 status
= U_ZERO_ERROR
;
137 a
= new UVector32(status
);
138 a
->addElement(10, status
);
139 a
->addElement(20, status
);
140 a
->addElement(30, status
);
141 a
->setElementAt(666, 1);
142 TEST_ASSERT(a
->elementAti(0) == 10);
143 TEST_ASSERT(a
->elementAti(1) == 666);
144 TEST_ASSERT(a
->size() == 3);
145 TEST_CHECK_STATUS(status
);
151 status
= U_ZERO_ERROR
;
152 a
= new UVector32(status
);
153 a
->addElement(10, status
);
154 a
->addElement(20, status
);
155 a
->addElement(30, status
);
156 a
->insertElementAt(666, 1, status
);
157 TEST_ASSERT(a
->elementAti(0) == 10);
158 TEST_ASSERT(a
->elementAti(1) == 666);
159 TEST_ASSERT(a
->elementAti(2) == 20);
160 TEST_ASSERT(a
->elementAti(3) == 30);
161 TEST_ASSERT(a
->size() == 4);
162 TEST_CHECK_STATUS(status
);
166 // elementAti() covered by above tests
172 status
= U_ZERO_ERROR
;
173 a
= new UVector32(status
);
174 a
->addElement(10, status
);
175 a
->addElement(20, status
);
176 a
->addElement(30, status
);
177 TEST_ASSERT(a
->lastElementi() == 30);
178 TEST_CHECK_STATUS(status
);
185 status
= U_ZERO_ERROR
;
186 a
= new UVector32(status
);
187 a
->addElement(10, status
);
188 a
->addElement(20, status
);
189 a
->addElement(30, status
);
190 TEST_ASSERT(a
->indexOf(30, 0) == 2);
191 TEST_ASSERT(a
->indexOf(40, 0) == -1);
192 TEST_ASSERT(a
->indexOf(10, 0) == 0);
193 TEST_ASSERT(a
->indexOf(10, 1) == -1);
194 TEST_CHECK_STATUS(status
);
201 status
= U_ZERO_ERROR
;
202 a
= new UVector32(status
);
203 a
->addElement(10, status
);
204 a
->addElement(20, status
);
205 a
->addElement(30, status
);
206 TEST_ASSERT(a
->contains(10) == TRUE
);
207 TEST_ASSERT(a
->contains(11) == FALSE
);
208 TEST_ASSERT(a
->contains(20) == TRUE
);
209 TEST_ASSERT(a
->contains(-10) == FALSE
);
210 TEST_CHECK_STATUS(status
);
217 status
= U_ZERO_ERROR
;
218 a
= new UVector32(status
);
219 a
->addElement(10, status
);
220 a
->addElement(20, status
);
221 a
->addElement(30, status
);
222 b
= new UVector32(status
);
223 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
224 b
->addElement(2, status
);
225 TEST_ASSERT(a
->containsAll(*b
) == FALSE
);
226 b
->setElementAt(10, 0);
227 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
228 TEST_ASSERT(b
->containsAll(*a
) == FALSE
);
229 b
->addElement(30, status
);
230 b
->addElement(20, status
);
231 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
232 TEST_ASSERT(b
->containsAll(*a
) == TRUE
);
233 b
->addElement(2, status
);
234 TEST_ASSERT(a
->containsAll(*b
) == FALSE
);
235 TEST_ASSERT(b
->containsAll(*a
) == TRUE
);
236 TEST_CHECK_STATUS(status
);
243 status
= U_ZERO_ERROR
;
244 a
= new UVector32(status
);
245 a
->addElement(10, status
);
246 a
->addElement(20, status
);
247 a
->addElement(30, status
);
248 b
= new UVector32(status
);
250 TEST_ASSERT(a
->size() == 3);
251 b
->addElement(20, status
);
253 TEST_ASSERT(a
->size() == 2);
254 TEST_ASSERT(a
->contains(10)==TRUE
);
255 TEST_ASSERT(a
->contains(30)==TRUE
);
256 b
->addElement(10, status
);
258 TEST_ASSERT(a
->size() == 1);
259 TEST_ASSERT(a
->contains(30) == TRUE
);
260 TEST_CHECK_STATUS(status
);
267 status
= U_ZERO_ERROR
;
268 a
= new UVector32(status
);
269 a
->addElement(10, status
);
270 a
->addElement(20, status
);
271 a
->addElement(30, status
);
272 b
= new UVector32(status
);
273 b
->addElement(10, status
);
274 b
->addElement(20, status
);
275 b
->addElement(30, status
);
276 b
->addElement(15, status
);
278 TEST_ASSERT(a
->size() == 3);
279 b
->removeElementAt(1);
281 TEST_ASSERT(a
->contains(20) == FALSE
);
282 TEST_ASSERT(a
->size() == 2);
283 b
->removeAllElements();
284 TEST_ASSERT(b
->size() == 0);
286 TEST_ASSERT(a
->size() == 0);
287 TEST_CHECK_STATUS(status
);
292 // removeElementAt Tested above.
296 // removeAllElments Tested above
300 // size() tested above
306 status
= U_ZERO_ERROR
;
307 a
= new UVector32(status
);
308 TEST_ASSERT(a
->isEmpty() == TRUE
);
309 a
->addElement(10, status
);
310 TEST_ASSERT(a
->isEmpty() == FALSE
);
311 a
->addElement(20, status
);
312 a
->removeElementAt(0);
313 TEST_ASSERT(a
->isEmpty() == FALSE
);
314 a
->removeElementAt(0);
315 TEST_ASSERT(a
->isEmpty() == TRUE
);
316 TEST_CHECK_STATUS(status
);
321 // ensureCapacity, expandCapacity
323 status
= U_ZERO_ERROR
;
324 a
= new UVector32(status
);
325 TEST_ASSERT(a
->isEmpty() == TRUE
);
326 a
->addElement(10, status
);
327 TEST_ASSERT(a
->ensureCapacity(5000, status
)== TRUE
);
328 TEST_ASSERT(a
->expandCapacity(20000, status
) == TRUE
);
329 TEST_CHECK_STATUS(status
);
335 status
= U_ZERO_ERROR
;
336 a
= new UVector32(status
);
337 a
->addElement(10, status
);
338 a
->addElement(20, status
);
339 a
->addElement(30, status
);
341 TEST_ASSERT(a
->size() == 100);
342 TEST_ASSERT(a
->elementAti(0) == 10);
343 TEST_ASSERT(a
->elementAti(1) == 20);
344 TEST_ASSERT(a
->elementAti(2) == 30);
345 TEST_ASSERT(a
->elementAti(3) == 0);
346 a
->setElementAt(666, 99);
347 a
->setElementAt(777, 100);
348 TEST_ASSERT(a
->elementAti(99) == 666);
349 TEST_ASSERT(a
->elementAti(100) == 0);
351 TEST_ASSERT(a
->elementAti(1) == 20);
352 TEST_ASSERT(a
->elementAti(2) == 0);
353 TEST_ASSERT(a
->size() == 2);
355 TEST_ASSERT(a
->empty() == TRUE
);
356 TEST_ASSERT(a
->size() == 0);
358 TEST_CHECK_STATUS(status
);
364 status
= U_ZERO_ERROR
;
365 a
= new UVector32(status
);
366 a
->addElement(10, status
);
367 a
->addElement(20, status
);
368 a
->addElement(30, status
);
369 b
= new UVector32(status
);
370 TEST_ASSERT(a
->containsNone(*b
) == TRUE
);
371 b
->addElement(5, status
);
372 TEST_ASSERT(a
->containsNone(*b
) == TRUE
);
373 b
->addElement(30, status
);
374 TEST_ASSERT(a
->containsNone(*b
) == FALSE
);
376 TEST_CHECK_STATUS(status
);
383 status
= U_ZERO_ERROR
;
384 a
= new UVector32(status
);
385 a
->sortedInsert(30, status
);
386 a
->sortedInsert(20, status
);
387 a
->sortedInsert(10, status
);
388 TEST_ASSERT(a
->elementAti(0) == 10);
389 TEST_ASSERT(a
->elementAti(1) == 20);
390 TEST_ASSERT(a
->elementAti(2) == 30);
392 TEST_CHECK_STATUS(status
);
398 status
= U_ZERO_ERROR
;
399 a
= new UVector32(status
);
400 a
->addElement(10, status
);
401 a
->addElement(20, status
);
402 int32_t *buf
= a
->getBuffer();
403 TEST_ASSERT(buf
[0] == 10);
404 TEST_ASSERT(buf
[1] == 20);
407 resizedBuf
= a
->getBuffer();
408 //TEST_ASSERT(buf != resizedBuf); // The buffer might have been realloc'd
409 TEST_ASSERT(resizedBuf
[0] == 10);
410 TEST_ASSERT(resizedBuf
[1] == 20);
412 TEST_CHECK_STATUS(status
);
419 status
= U_ZERO_ERROR
;
420 a
= new UVector32(status
);
421 TEST_ASSERT(a
->empty() == TRUE
);
422 a
->addElement(10, status
);
423 TEST_ASSERT(a
->empty() == FALSE
);
424 a
->addElement(20, status
);
425 a
->removeElementAt(0);
426 TEST_ASSERT(a
->empty() == FALSE
);
427 a
->removeElementAt(0);
428 TEST_ASSERT(a
->empty() == TRUE
);
429 TEST_CHECK_STATUS(status
);
436 status
= U_ZERO_ERROR
;
437 a
= new UVector32(status
);
438 a
->addElement(10, status
);
439 TEST_ASSERT(a
->peeki() == 10);
440 a
->addElement(20, status
);
441 TEST_ASSERT(a
->peeki() == 20);
442 a
->addElement(30, status
);
443 TEST_ASSERT(a
->peeki() == 30);
444 TEST_CHECK_STATUS(status
);
451 status
= U_ZERO_ERROR
;
452 a
= new UVector32(status
);
453 a
->addElement(10, status
);
454 a
->addElement(20, status
);
455 a
->addElement(30, status
);
456 TEST_ASSERT(a
->popi() == 30);
457 TEST_ASSERT(a
->popi() == 20);
458 TEST_ASSERT(a
->popi() == 10);
459 TEST_ASSERT(a
->popi() == 0);
460 TEST_ASSERT(a
->isEmpty());
461 TEST_CHECK_STATUS(status
);
467 status
= U_ZERO_ERROR
;
468 a
= new UVector32(status
);
469 TEST_ASSERT(a
->push(10, status
) == 10);
470 TEST_ASSERT(a
->push(20, status
) == 20);
471 TEST_ASSERT(a
->push(30, status
) == 30);
472 TEST_ASSERT(a
->size() == 3);
473 TEST_ASSERT(a
->popi() == 30);
474 TEST_ASSERT(a
->popi() == 20);
475 TEST_ASSERT(a
->popi() == 10);
476 TEST_ASSERT(a
->isEmpty());
477 TEST_CHECK_STATUS(status
);
484 status
= U_ZERO_ERROR
;
485 a
= new UVector32(status
);
486 a
->ensureCapacity(1000, status
);
490 TEST_CHECK_STATUS(status
);