]>
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) \
61 if (U_FAILURE(status)) {\
62 errln("UVector32Test failure at line %d. status=%s\n", __LINE__, u_errorName(status));\
66 #define TEST_ASSERT(expr) \
68 errln("UVector32Test failure at line %d.\n", __LINE__);\
71 //---------------------------------------------------------------------------
73 // UVector32_API Check for basic functionality of UVector32.
75 //---------------------------------------------------------------------------
76 void UVector32Test::UVector32_API() {
78 UErrorCode status
= U_ZERO_ERROR
;
82 a
= new UVector32(status
);
83 TEST_CHECK_STATUS(status
);
86 status
= U_ZERO_ERROR
;
87 a
= new UVector32(2000, status
);
88 TEST_CHECK_STATUS(status
);
94 status
= U_ZERO_ERROR
;
95 a
= new UVector32(status
);
96 a
->addElement(10, status
);
97 a
->addElement(20, status
);
98 a
->addElement(30, status
);
99 b
= new UVector32(status
);
100 b
->assign(*a
, status
);
101 TEST_ASSERT(b
->size() == 3);
102 TEST_ASSERT(b
->elementAti(1) == 20);
103 TEST_CHECK_STATUS(status
);
108 // operator == and != and equals()
110 status
= U_ZERO_ERROR
;
111 a
= new UVector32(status
);
112 a
->addElement(10, status
);
113 a
->addElement(20, status
);
114 a
->addElement(30, status
);
115 b
= new UVector32(status
);
116 TEST_ASSERT(*b
!= *a
);
117 TEST_ASSERT(!(*b
== *a
));
118 TEST_ASSERT(!b
->equals(*a
));
119 b
->assign(*a
, status
);
120 TEST_ASSERT(*b
== *a
);
121 TEST_ASSERT(!(*b
!= *a
));
122 TEST_ASSERT(b
->equals(*a
));
123 b
->addElement(666, status
);
124 TEST_ASSERT(*b
!= *a
);
125 TEST_ASSERT(!(*b
== *a
));
126 TEST_ASSERT(!b
->equals(*a
));
127 TEST_CHECK_STATUS(status
);
132 // addElement(). Covered by above tests.
138 status
= U_ZERO_ERROR
;
139 a
= new UVector32(status
);
140 a
->addElement(10, status
);
141 a
->addElement(20, status
);
142 a
->addElement(30, status
);
143 a
->setElementAt(666, 1);
144 TEST_ASSERT(a
->elementAti(0) == 10);
145 TEST_ASSERT(a
->elementAti(1) == 666);
146 TEST_ASSERT(a
->size() == 3);
147 TEST_CHECK_STATUS(status
);
153 status
= U_ZERO_ERROR
;
154 a
= new UVector32(status
);
155 a
->addElement(10, status
);
156 a
->addElement(20, status
);
157 a
->addElement(30, status
);
158 a
->insertElementAt(666, 1, status
);
159 TEST_ASSERT(a
->elementAti(0) == 10);
160 TEST_ASSERT(a
->elementAti(1) == 666);
161 TEST_ASSERT(a
->elementAti(2) == 20);
162 TEST_ASSERT(a
->elementAti(3) == 30);
163 TEST_ASSERT(a
->size() == 4);
164 TEST_CHECK_STATUS(status
);
168 // elementAti() covered by above tests
174 status
= U_ZERO_ERROR
;
175 a
= new UVector32(status
);
176 a
->addElement(10, status
);
177 a
->addElement(20, status
);
178 a
->addElement(30, status
);
179 TEST_ASSERT(a
->lastElementi() == 30);
180 TEST_CHECK_STATUS(status
);
187 status
= U_ZERO_ERROR
;
188 a
= new UVector32(status
);
189 a
->addElement(10, status
);
190 a
->addElement(20, status
);
191 a
->addElement(30, status
);
192 TEST_ASSERT(a
->indexOf(30, 0) == 2);
193 TEST_ASSERT(a
->indexOf(40, 0) == -1);
194 TEST_ASSERT(a
->indexOf(10, 0) == 0);
195 TEST_ASSERT(a
->indexOf(10, 1) == -1);
196 TEST_CHECK_STATUS(status
);
203 status
= U_ZERO_ERROR
;
204 a
= new UVector32(status
);
205 a
->addElement(10, status
);
206 a
->addElement(20, status
);
207 a
->addElement(30, status
);
208 TEST_ASSERT(a
->contains(10) == TRUE
);
209 TEST_ASSERT(a
->contains(11) == FALSE
);
210 TEST_ASSERT(a
->contains(20) == TRUE
);
211 TEST_ASSERT(a
->contains(-10) == FALSE
);
212 TEST_CHECK_STATUS(status
);
219 status
= U_ZERO_ERROR
;
220 a
= new UVector32(status
);
221 a
->addElement(10, status
);
222 a
->addElement(20, status
);
223 a
->addElement(30, status
);
224 b
= new UVector32(status
);
225 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
226 b
->addElement(2, status
);
227 TEST_ASSERT(a
->containsAll(*b
) == FALSE
);
228 b
->setElementAt(10, 0);
229 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
230 TEST_ASSERT(b
->containsAll(*a
) == FALSE
);
231 b
->addElement(30, status
);
232 b
->addElement(20, status
);
233 TEST_ASSERT(a
->containsAll(*b
) == TRUE
);
234 TEST_ASSERT(b
->containsAll(*a
) == TRUE
);
235 b
->addElement(2, status
);
236 TEST_ASSERT(a
->containsAll(*b
) == FALSE
);
237 TEST_ASSERT(b
->containsAll(*a
) == TRUE
);
238 TEST_CHECK_STATUS(status
);
245 status
= U_ZERO_ERROR
;
246 a
= new UVector32(status
);
247 a
->addElement(10, status
);
248 a
->addElement(20, status
);
249 a
->addElement(30, status
);
250 b
= new UVector32(status
);
252 TEST_ASSERT(a
->size() == 3);
253 b
->addElement(20, status
);
255 TEST_ASSERT(a
->size() == 2);
256 TEST_ASSERT(a
->contains(10)==TRUE
);
257 TEST_ASSERT(a
->contains(30)==TRUE
);
258 b
->addElement(10, status
);
260 TEST_ASSERT(a
->size() == 1);
261 TEST_ASSERT(a
->contains(30) == TRUE
);
262 TEST_CHECK_STATUS(status
);
269 status
= U_ZERO_ERROR
;
270 a
= new UVector32(status
);
271 a
->addElement(10, status
);
272 a
->addElement(20, status
);
273 a
->addElement(30, status
);
274 b
= new UVector32(status
);
275 b
->addElement(10, status
);
276 b
->addElement(20, status
);
277 b
->addElement(30, status
);
278 b
->addElement(15, status
);
280 TEST_ASSERT(a
->size() == 3);
281 b
->removeElementAt(1);
283 TEST_ASSERT(a
->contains(20) == FALSE
);
284 TEST_ASSERT(a
->size() == 2);
285 b
->removeAllElements();
286 TEST_ASSERT(b
->size() == 0);
288 TEST_ASSERT(a
->size() == 0);
289 TEST_CHECK_STATUS(status
);
294 // removeElementAt Tested above.
298 // removeAllElments Tested above
302 // size() tested above
308 status
= U_ZERO_ERROR
;
309 a
= new UVector32(status
);
310 TEST_ASSERT(a
->isEmpty() == TRUE
);
311 a
->addElement(10, status
);
312 TEST_ASSERT(a
->isEmpty() == FALSE
);
313 a
->addElement(20, status
);
314 a
->removeElementAt(0);
315 TEST_ASSERT(a
->isEmpty() == FALSE
);
316 a
->removeElementAt(0);
317 TEST_ASSERT(a
->isEmpty() == TRUE
);
318 TEST_CHECK_STATUS(status
);
323 // ensureCapacity, expandCapacity
325 status
= U_ZERO_ERROR
;
326 a
= new UVector32(status
);
327 TEST_ASSERT(a
->isEmpty() == TRUE
);
328 a
->addElement(10, status
);
329 TEST_ASSERT(a
->ensureCapacity(5000, status
)== TRUE
);
330 TEST_ASSERT(a
->expandCapacity(20000, status
) == TRUE
);
331 TEST_CHECK_STATUS(status
);
337 status
= U_ZERO_ERROR
;
338 a
= new UVector32(status
);
339 a
->addElement(10, status
);
340 a
->addElement(20, status
);
341 a
->addElement(30, status
);
343 TEST_ASSERT(a
->size() == 100);
344 TEST_ASSERT(a
->elementAti(0) == 10);
345 TEST_ASSERT(a
->elementAti(1) == 20);
346 TEST_ASSERT(a
->elementAti(2) == 30);
347 TEST_ASSERT(a
->elementAti(3) == 0);
348 a
->setElementAt(666, 99);
349 a
->setElementAt(777, 100);
350 TEST_ASSERT(a
->elementAti(99) == 666);
351 TEST_ASSERT(a
->elementAti(100) == 0);
353 TEST_ASSERT(a
->elementAti(1) == 20);
354 TEST_ASSERT(a
->elementAti(2) == 0);
355 TEST_ASSERT(a
->size() == 2);
357 TEST_ASSERT(a
->empty() == TRUE
);
358 TEST_ASSERT(a
->size() == 0);
360 TEST_CHECK_STATUS(status
);
366 status
= U_ZERO_ERROR
;
367 a
= new UVector32(status
);
368 a
->addElement(10, status
);
369 a
->addElement(20, status
);
370 a
->addElement(30, status
);
371 b
= new UVector32(status
);
372 TEST_ASSERT(a
->containsNone(*b
) == TRUE
);
373 b
->addElement(5, status
);
374 TEST_ASSERT(a
->containsNone(*b
) == TRUE
);
375 b
->addElement(30, status
);
376 TEST_ASSERT(a
->containsNone(*b
) == FALSE
);
378 TEST_CHECK_STATUS(status
);
385 status
= U_ZERO_ERROR
;
386 a
= new UVector32(status
);
387 a
->sortedInsert(30, status
);
388 a
->sortedInsert(20, status
);
389 a
->sortedInsert(10, status
);
390 TEST_ASSERT(a
->elementAti(0) == 10);
391 TEST_ASSERT(a
->elementAti(1) == 20);
392 TEST_ASSERT(a
->elementAti(2) == 30);
394 TEST_CHECK_STATUS(status
);
400 status
= U_ZERO_ERROR
;
401 a
= new UVector32(status
);
402 a
->addElement(10, status
);
403 a
->addElement(20, status
);
404 int32_t *buf
= a
->getBuffer();
405 TEST_ASSERT(buf
[0] == 10);
406 TEST_ASSERT(buf
[1] == 20);
409 resizedBuf
= a
->getBuffer();
410 //TEST_ASSERT(buf != resizedBuf); // The buffer might have been realloc'd
411 TEST_ASSERT(resizedBuf
[0] == 10);
412 TEST_ASSERT(resizedBuf
[1] == 20);
414 TEST_CHECK_STATUS(status
);
421 status
= U_ZERO_ERROR
;
422 a
= new UVector32(status
);
423 TEST_ASSERT(a
->empty() == TRUE
);
424 a
->addElement(10, status
);
425 TEST_ASSERT(a
->empty() == FALSE
);
426 a
->addElement(20, status
);
427 a
->removeElementAt(0);
428 TEST_ASSERT(a
->empty() == FALSE
);
429 a
->removeElementAt(0);
430 TEST_ASSERT(a
->empty() == TRUE
);
431 TEST_CHECK_STATUS(status
);
438 status
= U_ZERO_ERROR
;
439 a
= new UVector32(status
);
440 a
->addElement(10, status
);
441 TEST_ASSERT(a
->peeki() == 10);
442 a
->addElement(20, status
);
443 TEST_ASSERT(a
->peeki() == 20);
444 a
->addElement(30, status
);
445 TEST_ASSERT(a
->peeki() == 30);
446 TEST_CHECK_STATUS(status
);
453 status
= U_ZERO_ERROR
;
454 a
= new UVector32(status
);
455 a
->addElement(10, status
);
456 a
->addElement(20, status
);
457 a
->addElement(30, status
);
458 TEST_ASSERT(a
->popi() == 30);
459 TEST_ASSERT(a
->popi() == 20);
460 TEST_ASSERT(a
->popi() == 10);
461 TEST_ASSERT(a
->popi() == 0);
462 TEST_ASSERT(a
->isEmpty());
463 TEST_CHECK_STATUS(status
);
469 status
= U_ZERO_ERROR
;
470 a
= new UVector32(status
);
471 TEST_ASSERT(a
->push(10, status
) == 10);
472 TEST_ASSERT(a
->push(20, status
) == 20);
473 TEST_ASSERT(a
->push(30, status
) == 30);
474 TEST_ASSERT(a
->size() == 3);
475 TEST_ASSERT(a
->popi() == 30);
476 TEST_ASSERT(a
->popi() == 20);
477 TEST_ASSERT(a
->popi() == 10);
478 TEST_ASSERT(a
->isEmpty());
479 TEST_CHECK_STATUS(status
);
486 status
= U_ZERO_ERROR
;
487 a
= new UVector32(status
);
488 a
->ensureCapacity(1000, status
);
492 TEST_CHECK_STATUS(status
);