]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/v32test.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 2002-2007, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
12 // ICU Regular Expressions test, part of intltest.
25 //---------------------------------------------------------------------------
27 // Test class boilerplate
29 //---------------------------------------------------------------------------
30 UVector32Test::UVector32Test()
35 UVector32Test::~UVector32Test()
41 void UVector32Test::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
43 if (exec
) logln("TestSuite UVector32Test: ");
46 case 0: name
= "UVector32_API";
47 if (exec
) UVector32_API();
50 break; //needed to end loop
55 //---------------------------------------------------------------------------
57 // Error Checking / Reporting macros used in all of the tests.
59 //---------------------------------------------------------------------------
60 #define TEST_CHECK_STATUS(status) UPRV_BLOCK_MACRO_BEGIN {\
61 if (U_FAILURE(status)) {\
62 errln("UVector32Test failure at line %d. status=%s\n", __LINE__, u_errorName(status));\
65 } UPRV_BLOCK_MACRO_END
67 #define TEST_ASSERT(expr) UPRV_BLOCK_MACRO_BEGIN {\
69 errln("UVector32Test failure at line %d.\n", __LINE__);\
71 } UPRV_BLOCK_MACRO_END
73 //---------------------------------------------------------------------------
75 // UVector32_API Check for basic functionality of UVector32.
77 //---------------------------------------------------------------------------
78 void UVector32Test::UVector32_API() {
80 UErrorCode status
= U_ZERO_ERROR
;
84 a
= new UVector32(status
);
85 TEST_CHECK_STATUS(status
);
88 status
= U_ZERO_ERROR
;
89 a
= new UVector32(2000, status
);
90 TEST_CHECK_STATUS(status
);
96 status
= U_ZERO_ERROR
;
97 a
= new UVector32(status
);
98 a
->addElement(10, status
);
99 a
->addElement(20, status
);
100 a
->addElement(30, status
);
101 b
= new UVector32(status
);
102 b
->assign(*a
, status
);
103 TEST_ASSERT(b
->size() == 3);
104 TEST_ASSERT(b
->elementAti(1) == 20);
105 TEST_CHECK_STATUS(status
);
110 // operator == and != and equals()
112 status
= U_ZERO_ERROR
;
113 a
= new UVector32(status
);
114 a
->addElement(10, status
);
115 a
->addElement(20, status
);
116 a
->addElement(30, status
);
117 b
= new UVector32(status
);
118 TEST_ASSERT(*b
!= *a
);
119 TEST_ASSERT(!(*b
== *a
));
120 TEST_ASSERT(!b
->equals(*a
));
121 b
->assign(*a
, status
);
122 TEST_ASSERT(*b
== *a
);
123 TEST_ASSERT(!(*b
!= *a
));
124 TEST_ASSERT(b
->equals(*a
));
125 b
->addElement(666, status
);
126 TEST_ASSERT(*b
!= *a
);
127 TEST_ASSERT(!(*b
== *a
));
128 TEST_ASSERT(!b
->equals(*a
));
129 TEST_CHECK_STATUS(status
);
134 // addElement(). Covered by above tests.
140 status
= U_ZERO_ERROR
;
141 a
= new UVector32(status
);
142 a
->addElement(10, status
);
143 a
->addElement(20, status
);
144 a
->addElement(30, status
);
145 a
->setElementAt(666, 1);
146 TEST_ASSERT(a
->elementAti(0) == 10);
147 TEST_ASSERT(a
->elementAti(1) == 666);
148 TEST_ASSERT(a
->size() == 3);
149 TEST_CHECK_STATUS(status
);
155 status
= U_ZERO_ERROR
;
156 a
= new UVector32(status
);
157 a
->addElement(10, status
);
158 a
->addElement(20, status
);
159 a
->addElement(30, status
);
160 a
->insertElementAt(666, 1, status
);
161 TEST_ASSERT(a
->elementAti(0) == 10);
162 TEST_ASSERT(a
->elementAti(1) == 666);
163 TEST_ASSERT(a
->elementAti(2) == 20);
164 TEST_ASSERT(a
->elementAti(3) == 30);
165 TEST_ASSERT(a
->size() == 4);
166 TEST_CHECK_STATUS(status
);
170 // elementAti() covered by above tests
176 status
= U_ZERO_ERROR
;
177 a
= new UVector32(status
);
178 a
->addElement(10, status
);
179 a
->addElement(20, status
);
180 a
->addElement(30, status
);
181 TEST_ASSERT(a
->lastElementi() == 30);
182 TEST_CHECK_STATUS(status
);
189 status
= U_ZERO_ERROR
;
190 a
= new UVector32(status
);
191 a
->addElement(10, status
);
192 a
->addElement(20, status
);
193 a
->addElement(30, status
);
194 TEST_ASSERT(a
->indexOf(30, 0) == 2);
195 TEST_ASSERT(a
->indexOf(40, 0) == -1);
196 TEST_ASSERT(a
->indexOf(10, 0) == 0);
197 TEST_ASSERT(a
->indexOf(10, 1) == -1);
198 TEST_CHECK_STATUS(status
);
205 status
= U_ZERO_ERROR
;
206 a
= new UVector32(status
);
207 a
->addElement(10, status
);
208 a
->addElement(20, status
);
209 a
->addElement(30, status
);
210 TEST_ASSERT(a
->contains(10) == TRUE
);
211 TEST_ASSERT(a
->contains(11) == FALSE
);
212 TEST_ASSERT(a
->contains(20) == TRUE
);
213 TEST_ASSERT(a
->contains(-10) == FALSE
);
214 TEST_CHECK_STATUS(status
);
221 status
= U_ZERO_ERROR
;
222 a
= new UVector32(status
);
223 a
->addElement(10, status
);
224 a
->addElement(20, status
);
225 a
->addElement(30, status
);
226 b
= new UVector32(status
);
227 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
228 b
->addElement(2, status
);
229 TEST_ASSERT(a
->containsAll(*b
) == FALSE
);
230 b
->setElementAt(10, 0);
231 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
232 TEST_ASSERT(b
->containsAll(*a
) == FALSE
);
233 b
->addElement(30, status
);
234 b
->addElement(20, status
);
235 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
236 TEST_ASSERT(b
->containsAll(*a
) == TRUE
);
237 b
->addElement(2, status
);
238 TEST_ASSERT(a
->containsAll(*b
) == FALSE
);
239 TEST_ASSERT(b
->containsAll(*a
) == TRUE
);
240 TEST_CHECK_STATUS(status
);
247 status
= U_ZERO_ERROR
;
248 a
= new UVector32(status
);
249 a
->addElement(10, status
);
250 a
->addElement(20, status
);
251 a
->addElement(30, status
);
252 b
= new UVector32(status
);
254 TEST_ASSERT(a
->size() == 3);
255 b
->addElement(20, status
);
257 TEST_ASSERT(a
->size() == 2);
258 TEST_ASSERT(a
->contains(10)==TRUE
);
259 TEST_ASSERT(a
->contains(30)==TRUE
);
260 b
->addElement(10, status
);
262 TEST_ASSERT(a
->size() == 1);
263 TEST_ASSERT(a
->contains(30) == TRUE
);
264 TEST_CHECK_STATUS(status
);
271 status
= U_ZERO_ERROR
;
272 a
= new UVector32(status
);
273 a
->addElement(10, status
);
274 a
->addElement(20, status
);
275 a
->addElement(30, status
);
276 b
= new UVector32(status
);
277 b
->addElement(10, status
);
278 b
->addElement(20, status
);
279 b
->addElement(30, status
);
280 b
->addElement(15, status
);
282 TEST_ASSERT(a
->size() == 3);
283 b
->removeElementAt(1);
285 TEST_ASSERT(a
->contains(20) == FALSE
);
286 TEST_ASSERT(a
->size() == 2);
287 b
->removeAllElements();
288 TEST_ASSERT(b
->size() == 0);
290 TEST_ASSERT(a
->size() == 0);
291 TEST_CHECK_STATUS(status
);
296 // removeElementAt Tested above.
300 // removeAllElments Tested above
304 // size() tested above
310 status
= U_ZERO_ERROR
;
311 a
= new UVector32(status
);
312 TEST_ASSERT(a
->isEmpty() == TRUE
);
313 a
->addElement(10, status
);
314 TEST_ASSERT(a
->isEmpty() == FALSE
);
315 a
->addElement(20, status
);
316 a
->removeElementAt(0);
317 TEST_ASSERT(a
->isEmpty() == FALSE
);
318 a
->removeElementAt(0);
319 TEST_ASSERT(a
->isEmpty() == TRUE
);
320 TEST_CHECK_STATUS(status
);
325 // ensureCapacity, expandCapacity
327 status
= U_ZERO_ERROR
;
328 a
= new UVector32(status
);
329 TEST_ASSERT(a
->isEmpty() == TRUE
);
330 a
->addElement(10, status
);
331 TEST_ASSERT(a
->ensureCapacity(5000, status
)== TRUE
);
332 TEST_ASSERT(a
->expandCapacity(20000, status
) == TRUE
);
333 TEST_CHECK_STATUS(status
);
339 status
= U_ZERO_ERROR
;
340 a
= new UVector32(status
);
341 a
->addElement(10, status
);
342 a
->addElement(20, status
);
343 a
->addElement(30, status
);
345 TEST_ASSERT(a
->size() == 100);
346 TEST_ASSERT(a
->elementAti(0) == 10);
347 TEST_ASSERT(a
->elementAti(1) == 20);
348 TEST_ASSERT(a
->elementAti(2) == 30);
349 TEST_ASSERT(a
->elementAti(3) == 0);
350 a
->setElementAt(666, 99);
351 a
->setElementAt(777, 100);
352 TEST_ASSERT(a
->elementAti(99) == 666);
353 TEST_ASSERT(a
->elementAti(100) == 0);
355 TEST_ASSERT(a
->elementAti(1) == 20);
356 TEST_ASSERT(a
->elementAti(2) == 0);
357 TEST_ASSERT(a
->size() == 2);
359 TEST_ASSERT(a
->empty() == TRUE
);
360 TEST_ASSERT(a
->size() == 0);
362 TEST_CHECK_STATUS(status
);
368 status
= U_ZERO_ERROR
;
369 a
= new UVector32(status
);
370 a
->addElement(10, status
);
371 a
->addElement(20, status
);
372 a
->addElement(30, status
);
373 b
= new UVector32(status
);
374 TEST_ASSERT(a
->containsNone(*b
) == TRUE
);
375 b
->addElement(5, status
);
376 TEST_ASSERT(a
->containsNone(*b
) == TRUE
);
377 b
->addElement(30, status
);
378 TEST_ASSERT(a
->containsNone(*b
) == FALSE
);
380 TEST_CHECK_STATUS(status
);
387 status
= U_ZERO_ERROR
;
388 a
= new UVector32(status
);
389 a
->sortedInsert(30, status
);
390 a
->sortedInsert(20, status
);
391 a
->sortedInsert(10, status
);
392 TEST_ASSERT(a
->elementAti(0) == 10);
393 TEST_ASSERT(a
->elementAti(1) == 20);
394 TEST_ASSERT(a
->elementAti(2) == 30);
396 TEST_CHECK_STATUS(status
);
402 status
= U_ZERO_ERROR
;
403 a
= new UVector32(status
);
404 a
->addElement(10, status
);
405 a
->addElement(20, status
);
406 int32_t *buf
= a
->getBuffer();
407 TEST_ASSERT(buf
[0] == 10);
408 TEST_ASSERT(buf
[1] == 20);
411 resizedBuf
= a
->getBuffer();
412 //TEST_ASSERT(buf != resizedBuf); // The buffer might have been realloc'd
413 TEST_ASSERT(resizedBuf
[0] == 10);
414 TEST_ASSERT(resizedBuf
[1] == 20);
416 TEST_CHECK_STATUS(status
);
423 status
= U_ZERO_ERROR
;
424 a
= new UVector32(status
);
425 TEST_ASSERT(a
->empty() == TRUE
);
426 a
->addElement(10, status
);
427 TEST_ASSERT(a
->empty() == FALSE
);
428 a
->addElement(20, status
);
429 a
->removeElementAt(0);
430 TEST_ASSERT(a
->empty() == FALSE
);
431 a
->removeElementAt(0);
432 TEST_ASSERT(a
->empty() == TRUE
);
433 TEST_CHECK_STATUS(status
);
440 status
= U_ZERO_ERROR
;
441 a
= new UVector32(status
);
442 a
->addElement(10, status
);
443 TEST_ASSERT(a
->peeki() == 10);
444 a
->addElement(20, status
);
445 TEST_ASSERT(a
->peeki() == 20);
446 a
->addElement(30, status
);
447 TEST_ASSERT(a
->peeki() == 30);
448 TEST_CHECK_STATUS(status
);
455 status
= U_ZERO_ERROR
;
456 a
= new UVector32(status
);
457 a
->addElement(10, status
);
458 a
->addElement(20, status
);
459 a
->addElement(30, status
);
460 TEST_ASSERT(a
->popi() == 30);
461 TEST_ASSERT(a
->popi() == 20);
462 TEST_ASSERT(a
->popi() == 10);
463 TEST_ASSERT(a
->popi() == 0);
464 TEST_ASSERT(a
->isEmpty());
465 TEST_CHECK_STATUS(status
);
471 status
= U_ZERO_ERROR
;
472 a
= new UVector32(status
);
473 TEST_ASSERT(a
->push(10, status
) == 10);
474 TEST_ASSERT(a
->push(20, status
) == 20);
475 TEST_ASSERT(a
->push(30, status
) == 30);
476 TEST_ASSERT(a
->size() == 3);
477 TEST_ASSERT(a
->popi() == 30);
478 TEST_ASSERT(a
->popi() == 20);
479 TEST_ASSERT(a
->popi() == 10);
480 TEST_ASSERT(a
->isEmpty());
481 TEST_CHECK_STATUS(status
);
488 status
= U_ZERO_ERROR
;
489 a
= new UVector32(status
);
490 a
->ensureCapacity(1000, status
);
494 TEST_CHECK_STATUS(status
);