1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
|
/* Copyright (C) 2001 ACUNIA
This file is part of Mauve.
Mauve is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Mauve is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
// Tags: JDK1.2
package gnu.testlet.java.util.Vector;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.util.*;
import java.lang.NullPointerException;
import java.lang.UnsupportedOperationException;
/**
* This file contains testcode for java.util.Vector.<br>
* <br>
* WRITTEN BY ACUNIA <br>
* <br>
*
*/
public class AcuniaVectorTest extends Vector implements Testlet
{
protected TestHarness th;
public AcuniaVectorTest() { /* Public Constructor needed for Testlet */ }
public void test (TestHarness harness)
{
th = harness;
test_Vector();
test_contains();
test_containsAll();
test_indexOf ();
test_isEmpty();
test_lastIndexOf();
test_size();
test_get ();
test_copyInto();
test_elementAt();
test_elements();
test_firstElement();
test_lastElement();
test_add();
test_addAll();
test_addElement();
test_clear();
test_insertElementAt();
test_remove();
try { test_removeAll(); }
catch (UnsupportedOperationException ue) {th.fail("method removeAll() is not supported");}
test_removeAllElements();
test_removeElement();
test_removeElementAt();
test_removeRange();
try {test_retainAll();}
catch (UnsupportedOperationException ue) {th.fail("method retainAll() is not supported");}
try { test_set(); }
catch (UnsupportedOperationException ue) {th.fail("method set() is not supported");}
test_setElementAt();
test_setSize();
test_capacity();
test_ensureCapacity();
test_trimToSize();
try { test_subList(); }
catch (UnsupportedOperationException ue) {th.fail("method subList() is not supported");}
try { test_toArray(); }
catch (ArrayStoreException ae) { th.fail("failure in System.arraycopy, got exception: "+ae); }
test_clone();
test_equals();
test_hashCode();
test_toString();
test_behaviour();
test_iterator();
}
public Vector buildknownV() {
Vector v = new Vector();
Float f;
for (int i =0; i < 11; i++)
{
f = new Float((float)i);
v.addElement(f);
}
return v;
}
/**
* implemented.
*
*/
public void test_Vector(){
th.checkPoint("Vector()");
Vector v = new Vector();
th.check(v.capacity()==10 , "check default capacity");
th.checkPoint("Vector(java.util.Collection)");
v = new Vector(buildknownV());
v.equals(buildknownV());
th.checkPoint("Vector(int)");
v = new Vector(20);
th.check(v.capacity()==20 , "check default capacity");
th.checkPoint("Vector(int,int)");
v = new Vector(20,5);
th.check(v.capacity()==20 , "check default capacity");
}
/**
* implemented.
*
*/
public void test_contains(){
th.checkPoint("contains(java.lang.Object)boolean");
Vector v = buildknownV();
Object o = new Object();
Float f = new Float(5.0f);
th.check(!v.contains(null) , "null is allowed -- 1");
v.addElement(null);
th.check(v.contains(null) , "null is allowed -- 2");
th.check( v.contains(f) , "contains -- 1");
f = new Float(15.0f);
th.check(! v.contains(f) , "contains -- 2");
th.check(! v.contains(o) , "contains -- 3");
v.addElement(o);
th.check( v.contains(o) , "contains -- 4");
th.check(! v.contains(new Object()) , "contains -- 5");
}
/**
* implemented.<br>
* since jdk 1.2 <br>
* needs extra testing <br>
*/
public void test_containsAll(){
th.checkPoint("containsAll(java.util.Colection)boolean");
Vector v = new Vector();
try { v.containsAll(null);
th.fail("should throw NullPointerException");
}
catch (NullPointerException ne) { th.check(true); }
v.addElement("a"); v.addElement("b"); v.addElement("c");
v.addElement(null);
Collection c = (Collection) v.clone();
v.addElement("d"); v.addElement("e"); v.addElement("f");
th.check(v.containsAll(c) , "checking ContainsAll -- 1");
v.removeElement("a");
th.check(!v.containsAll(c) , "checking ContainsAll -- 2");
try { v.containsAll(null);
th.fail("should throw NullPointerException");
}
catch (NullPointerException ne) { th.check(true); }
}
/**
* implemented.
*
*/
public void test_indexOf(){
th.checkPoint("indexOf(java.lang.Object)int");
Vector v = buildknownV();
Object o = new Object();
Float f = new Float(5.0f);
th.check( v.indexOf(f) == 5 , "contains -- 1");
f = new Float(15.0f);
th.check( v.indexOf(f) == -1 , "contains -- 2");
th.check( v.indexOf(o) == -1, "contains -- 3");
v.addElement(o);
th.check( v.indexOf(o) == 11 , "contains -- 4");
th.check( v.indexOf(new Object()) == -1 , "contains -- 5");
try {v.indexOf(null);
th.check(true);
v.addElement(null);
th.check(v.indexOf(null) == 12, "null was added to the Vector");
}
catch(NullPointerException ne) { th.fail("shouldn't throw NullPointerException"); }
th.checkPoint("indexOf(java.lang.Object,int)int");
v = buildknownV();
o = new Object();
f = new Float(5.0f);
th.check( v.indexOf(f,2) == 5 , "contains -- 1");
th.check( v.indexOf(f,6) == -1 , "contains -- 2");
f = new Float(15.0f);
th.check( v.indexOf(f,4) == -1 , "contains -- 3");
th.check( v.indexOf(o,3) == -1, "contains -- 4");
v.addElement(o);
th.check( v.indexOf(o,11) == 11 , "contains -- 5");
v.addElement(f);
th.check( v.indexOf(o,12) == -1 , "contains -- 6");
th.check( v.indexOf(new Object(),1) == -1 , "contains -- 7");
try {v.indexOf(null,3);
th.check(true);
v.addElement(null);
th.check(v.indexOf(null,13) == 13, "null was added to the Vector");
}
catch(NullPointerException ne) { th.fail("shouldn't throw NullPointerException"); }
try {f = new Float(10.0f);
th.check(v.indexOf(f,333)== -1 ,"checking bounderies");
}
catch(Exception ne) { th.fail("shouldn't throw an Exception"); }
try {v.indexOf(f,-1);
th.fail("shouldn't throw NullPointerException");
}
catch(Exception ne) { th.check(true); }
}
/**
* implemented.
*
*/
public void test_isEmpty(){
th.checkPoint("isEmpty()boolean");
Vector v = new Vector();
th.check(v.isEmpty() ,"testing isEmpty -- 1");
th.check(!buildknownV().isEmpty() ,"testing isEmpty -- 2");
}
/**
* implemented .
*
*/
public void test_lastIndexOf(){
th.checkPoint("lastIndexOf(java.lang.Object)int");
Vector v = buildknownV();
Object o = new Object();
Float f = new Float(5.0f);
th.check( v.lastIndexOf(f) == 5 , "contains -- 1");
f = new Float(15.0f);
th.check( v.lastIndexOf(f) == -1 , "contains -- 2");
th.check( v.lastIndexOf(o) == -1, "contains -- 3");
v.addElement(o);
th.check( v.lastIndexOf(o) == 11 , "contains -- 4");
th.check( v.lastIndexOf(new Object()) == -1 , "contains -- 5");
try {v.lastIndexOf(null);
th.check(true);
v.addElement(null);
th.check(v.lastIndexOf(null) == 12, "null was added to the Vector");
}
catch(NullPointerException ne) { th.fail("shouldn't throw NullPointerException"); }
th.checkPoint("lastIndexOf(java.lang.Object,int)int");
v = buildknownV();
o = new Object();
f = new Float(5.0f);
th.check( v.lastIndexOf(f,5) == 5 , "contains -- 1");
th.check( v.lastIndexOf(f,4) == -1 , "contains -- 2");
f = new Float(15.0f);
th.check( v.lastIndexOf(f,4) == -1 , "contains -- 3");
th.check( v.lastIndexOf(o,3) == -1, "contains -- 4");
v.addElement(o);
th.check( v.lastIndexOf(o,11) == 11 , "contains -- 5");
v.addElement(f);
th.check( v.lastIndexOf(o,10) == -1 , "contains -- 6");
th.check( v.lastIndexOf(new Object(),10) == -1 , "contains -- 7");
try {v.lastIndexOf(null,12);
th.check(true);
v.addElement(null);
th.check(v.lastIndexOf(null,13) == 13, "null was added to the Vector");
th.check(v.lastIndexOf(null,12) == -1, "null was added to the Vector, on pos 13");
}
catch(NullPointerException ne) { th.fail("shouldn't throw NullPointerException"); }
try {f = new Float(10.0f);
th.check(v.lastIndexOf(f,-1)== -1 ,"checking bounderies");
}
catch(Exception ne) { th.fail("shouldn't throw an Exception"); }
try {v.lastIndexOf(f,91);
th.fail("shouldn't throw NullPointerException");
}
catch(Exception ne) { th.check(true); }
}
/**
* implemented .
*
*/
public void test_size(){
th.checkPoint("size()int");
Vector v = buildknownV();
th.check(v.size() == 11 , "size -- 1 - got: "+v.size());
v.addElement(null);
th.check(v.size() == 12 , "size -- 2 - got: "+v.size());
v.addElement(new Object());
th.check(v.size() == 13 , "size -- 3 - got: "+v.size());
v = new Vector();
th.check(v.size() == 0 , "size -- 4 - got: "+v.size());
}
/**
* implemented.<br>
* since jdk 1.2
*/
public void test_get(){
th.checkPoint("get(int)java.lang.Object");
Vector v = buildknownV();
try { v.get(-1);
th.fail("should throw exception -- 1");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try { v.get(11);
th.fail("should throw exception -- 2");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
v = new Vector();
v.addElement("a"); v.addElement(null); v.addElement("c");
v.addElement(null);
th.check(v.get(0).equals("a") && v.get(2).equals("c") , "checking get -- 1");
th.check(v.get(1) == null && v.get(3) == null , "checking get -- 2");
}
/**
* implemented.
*
*/
public void test_copyInto(){
th.checkPoint("copyInto([java.lang.Object)void");
Vector v = buildknownV();
StringBuffer bf= new StringBuffer("smartmove");
v.addElement(bf);
Object o[] = new Object[5];
try { v.copyInto(o);
th.fail("should throw ArrayIndexOutOfBoundsException");
}
catch(ArrayIndexOutOfBoundsException ae) { th.check(true); }
o = new Object[15];
v.copyInto(o);
for (int i=0 ; i < 11 ; i++ )
{ th.check( o[i] == v.elementAt(i),"checking copyInto -- "+(i+1)+" - got: "+o[i]); }
th.check( o[11] == v.elementAt(11) , "checking stringbuffer");
th.check(o.length == 15);
}
/**
* implemented.
*
*/
public void test_elementAt(){
th.checkPoint("elementAt(int)java.lang.Object");
Vector v = new Vector();
v.addElement(null);
Float f =new Float(23.0f);
Double d =new Double(54.5);
v.addElement(f);
v.addElement(d);
th.check( v.elementAt(0) == null );
th.check( v.elementAt(1) == f );
th.check( v.elementAt(2) == d );
try {v.elementAt(-1);
th.fail("should throw ArrayIndexOutOfBoundsException -- 1");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try {v.elementAt(3);
th.fail("should throw ArrayIndexOutOfBoundsException -- 2");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
}
/**
* implemented.
*
*/
public void test_elements(){
th.checkPoint("elements()java.util.Enumeration");
Vector v = buildknownV();
v.addElement(null);
Float f =new Float(23.0f);
Double d =new Double(54.5);
v.addElement(f);
v.addElement(d);
Enumeration e = v.elements();
for (int i=0; i < 11 ; i++ )
{ th.check( ((Float)e.nextElement()).intValue() == i,"checking elements -- "+(i+1)); }
try {
th.check(e.hasMoreElements(), "null in vector might give problems -- 1");
th.check(e.nextElement() == null , "null in vector might give problems -- 2");
th.check(e.hasMoreElements(), "null in vector might give problems -- 3");
th.check(e.nextElement() == f , "null in vector might give problems -- 4");
th.check(e.nextElement() == d , "null in vector might give problems -- 5");
th.check(!e.hasMoreElements(), "null in vector might give problems -- 6");
}
catch (Exception te) { th.debug("caught unwanted exception: "+te); }
v = new Vector();
th.check( v.elements() != null);
}
/**
* implemented.
*
*/
public void test_firstElement(){
th.checkPoint("firstElement()java.lang.Object");
Vector v = new Vector();
try { v.firstElement();
th.fail("should throw NoSuchElementException");
}
catch(NoSuchElementException ne) { th.check(true); }
v.addElement(null);
th.check(v.firstElement() == null );
v = new Vector();
Float f =new Float(23.0f);
v.addElement(f);
th.check(v.firstElement() == f );
v = new Vector();
Double d =new Double(54.5);
v.addElement(d);
v.addElement(null);
v.addElement(f);
th.check(v.firstElement() == d );
}
/**
* implemented.
*
*/
public void test_lastElement(){
th.checkPoint("lastElement()java.lang.Object");
Vector v = new Vector();
try { v.lastElement();
th.fail("should throw NoSuchElementException");
}
catch(NoSuchElementException ne) { th.check(true); }
v.addElement(null);
th.check(v.lastElement() == null );
v = buildknownV();
v.addElement(null);
th.check(v.lastElement() == null );
Float f =new Float(23.0f);
v.addElement(f);
th.check(v.lastElement() == f );
v = new Vector();
Double d =new Double(54.5);
v.addElement(d);
th.check(v.lastElement() == d );
}
/**
* implemented. <br>
* since jdk 1.2
*/
public void test_add(){
th.checkPoint("add(java.lang.Object)boolean");
Vector v = new Vector();
th.check(v.add("a") && v.add(null), "checking returns boolean -- 1");
th.check(v.add("c") && v.add(null), "checking returns boolean -- 2");
th.check(v.get(0)=="a" && v.get(2)=="c", "checking addedcat right position -- 1");
th.checkPoint("add(int,java.lang.Object)void");
v = buildknownV();
try { v.add(-1,"a");
th.fail("should throw exception -- 1");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try { v.add(12,"a");
th.fail("should throw exception -- 2");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try { v.add(11,"a");
th.check(true);
}
catch (ArrayIndexOutOfBoundsException ae) { th.fail("shouldn't throw exception -- 1"); }
v = new Vector();
v.add(0,"a"); v.add(0,null);
v.add(1,"c"); v.add(2,null);
th.check(v.get(3).equals("a") && v.get(1).equals("c") , "checking get -- 1");
th.check(v.get(0) == null && v.get(2) == null , "checking get -- 2");
v.add(4,"b"); v.add(5,null);
th.check(v.get(4) == "b" && v.get(5) == null , "checking get -- 3");
}
/**
* implemented.<br>
* since jdk 1.2
*/
public void test_addAll(){
th.checkPoint("addAll(java.util.Collection)boolean");
Vector v =new Vector();
try { v.addAll(null);
th.fail("should throw NullPointerException");
}
catch (NullPointerException ne) { th.check(true); }
Collection c = (Collection) v;
th.check(!v.addAll(c) ,"checking returnvalue -- 1");
v.add("a"); v.add("b"); v.add("c");
c = (Collection) v;
v = buildknownV();
th.check(v.addAll(c) ,"checking returnvalue -- 2");
th.check(v.containsAll(c), "extra on containsAll -- 1");
th.check(v.get(11)=="a" && v.get(12)=="b" && v.get(13)=="c", "checking added on right positions");
th.checkPoint("addAll(int,java.util.Collection)boolean");
v =new Vector();
c = (Collection) v;
th.check(!v.addAll(0,c) ,"checking returnvalue -- 1");
v.add("a"); v.add("b"); v.add("c");
c = (Collection) v;
v = buildknownV();
try { v.addAll(-1,c);
th.fail("should throw exception -- 1");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try { v.addAll(12,c);
th.fail("should throw exception -- 2");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try { th.check(v.addAll(11,c),"checking returnvalue -- 2"); }
catch (ArrayIndexOutOfBoundsException ae) { th.fail("shouldn't throw exception -- 1"); }
th.check(v.containsAll(c), "extra on containsAll -- 1");
th.check(v.get(11)=="a" && v.get(12)=="b" && v.get(13)=="c", "checking added on right positions -- 1");
th.check(v.addAll(1,c),"checking returnvalue -- 3");
th.check(v.get(1)=="a" && v.get(2)=="b" && v.get(3)=="c", "checking added on right positions -- 2");
}
/**
* implemented. <br>
* just very, very basic testing <br>
* --> errors in addElement will also make others tests fail
*/
public void test_addElement(){
th.checkPoint("addElement(java.lang.Object)void");
Vector v = new Vector();
v.addElement("a");
th.check(v.size() == 1 , "check size -- 1");
th.check(v.elementAt(0) == "a" );
v.addElement(null);
th.check(v.size() == 2 , "check size -- 2");
th.check(v.elementAt(1) == null );
}
/**
* implemented. <br>
* since jdk 1.2
*/
public void test_clear(){
th.checkPoint("clear()void");
Vector v = buildknownV();
int c = v.capacity();
v.clear();
th.check(v.isEmpty() && (v.size()==0), "make sure all is gone");
th.check(c == v.capacity() , "capacity stays the same, got: "+v.capacity()+", but exp.: "+c);
}
/**
* implemented.
*
*/
public void test_insertElementAt(){
th.checkPoint("insertElementAt(java.lang.Object,int)void");
Vector v = buildknownV();
v.insertElementAt("a",5);
int i;
for (i=0 ; i < 5 ; i++ )
{ th.check( ((Float)v.elementAt(i)).intValue() == i, "Float value didn't change -- "+(i+1)); }
for (i=6 ; i < 12 ; i++ )
{ th.check( ((Float)v.elementAt(i)).intValue() == i-1 , "checking shifted elements -- "+(i-5)); }
th.check(v.elementAt(5) == "a" );
try {
v.insertElementAt("a",12);
th.check(v.elementAt(12) == "a" );
}
catch (Exception e) { th.fail("shouldn't throw an Exception -- caught: "+e); }
try {
v.insertElementAt("a",14);
th.fail("should throw an ArrayIndexOutOfBoundsException -- 1" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
try {
v.insertElementAt("a",-1);
th.fail("should throw an ArrayIndexOutOfBoundsException -- 2" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
v = buildknownV();
v.insertElementAt(null,5);
for (i=0 ; i < 5 ; i++ )
{ th.check( ((Float)v.elementAt(i)).intValue() == i, "Float value didn't change inserted null -- "+(i+1)); }
for (i=6 ; i < 12 ; i++ )
{ th.check( ((Float)v.elementAt(i)).intValue() == i-1 , "checking shifted elements inserted null -- "+(i-5)); }
th.check(v.elementAt(5) == null );
}
/**
* implemented. <br>
* since jdk 1.2
*/
public void test_remove(){
th.checkPoint("remove(int)java.lang.Object");
Vector v = buildknownV();
try {
v.remove(-1);
th.fail("should throw an ArrayIndexOutOfBoundsException -- 1" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
try {
v.remove(11);
th.fail("should throw an ArrayIndexOutOfBoundsException -- 2" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
th.check( ((Float)v.remove(5)).intValue() == 5 , "checking returnvalue remove -- 1");
int i; boolean ok = true;
th.check(v.size() == 10 , "checking new Size");
for (i=0; i < 5 ; i++)
{ if (((Float)v.get(i)).intValue() != i) ok = false; }
th.check(ok , "checking order Floats in Vector -- 1");
ok = true;
for (i=5; i < 10 ; i++)
{ if (((Float)v.get(i)).intValue() != (i+1)) ok = false; }
th.check(ok , "checking order Floats in Vector -- 2");
v.add(5,null);
th.check( v.remove(5) == null , "checking returnvalue remove -- 2");
ok = true;
for (i=0; i < 5 ; i++)
{ if (((Float)v.get(i)).intValue() != i) ok = false; }
th.check(ok , "checking order Floats in Vector -- 3");
ok = true;
for (i=5; i < 10 ; i++)
{ if (((Float)v.get(i)).intValue() != (i+1)) ok = false; }
th.check(ok , "checking order Floats in Vector -- 4");
th.check( ((Float)v.remove(9)).intValue() == 10 , "checking returnvalue remove -- 3");
th.check( ((Float)v.remove(0)).intValue() == 0 , "checking returnvalue remove -- 4");
th.check( ((Float)v.remove(0)).intValue() == 1 , "checking returnvalue remove -- 5");
v = new Vector();
try {
v.remove(0);
th.fail("should throw an ArrayIndexOutOfBoundsException -- 3" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
th.checkPoint("remove(java.lang.Object)boolean");
v = new Vector();
th.check(!v.remove("a") ,"checking remove on empty vector-- 1");
th.check(!v.remove("a") ,"checking remove on empty vector-- 2");
v.add("a"); v.add(null); v.add("a");
v.add("c"); v.add("d"); v.add(null);
th.check(v.remove("a") ,"checking returnvalue remove -- 1");
th.check(v.get(0)==null && v.get(1)=="a" && v.get(2)=="c" &&v.get(3)=="d" &&v.get(4)==null , "checking order of elements -- 1");
th.check(v.remove("a") ,"checking returnvalue remove -- 2");
th.check(v.get(0)==null && v.get(1)=="c" &&v.get(2)=="d" &&v.get(3)==null , "checking order of elements -- 2");
th.check(!v.remove("a") ,"checking returnvalue remove -- 3");
th.check(v.get(0)==null && v.get(1)=="c" &&v.get(2)=="d" &&v.get(3)==null , "checking order of elements -- 3");
th.check(v.remove(null) ,"checking returnvalue remove -- 4");
th.check(v.get(0)=="c" &&v.get(1)=="d" &&v.get(2)==null , "checking order of elements -- 4");
th.check(v.remove(null) ,"checking returnvalue remove -- 5");
th.check(v.get(0)=="c" &&v.get(1)=="d", "checking order of elements -- 5");
th.check(!v.remove(null) ,"checking returnvalue remove -- 6");
th.check(v.get(0)=="c" &&v.get(1)=="d", "checking order of elements -- 6");
}
/**
* implemented. <br>
* since jdk 1.2
*/
public void test_removeAll() throws UnsupportedOperationException{
th.checkPoint("removeAll(java.util.Collection)boolean");
Vector v = new Vector();
/**
* Disabled. A little too strict.
We will allow removing null from an empty Vector.
try { v.removeAll(null);
th.fail("should throw NullPointerException");
}
catch (NullPointerException ne) { th.check(true); }
*/
v.add("a");
try { v.removeAll(null);
th.fail("should throw NullPointerException");
}
catch (NullPointerException ne) { th.check(true); }
th.debug(v.toString());
v.add("b");
th.debug(v.toString());
v.add(null);
th.debug(v.toString() + " == c");
Collection c = (Collection) v;
v = buildknownV();
th.debug(v.toString() + " == v");
th.check(!v.removeAll(c) , "checking returnvalue of removeAll -- 1");
th.debug(v.toString());
th.check(v.equals(buildknownV()) , "v didn't change");
th.debug(c.toString() + " == c");
v.addAll(c);
th.debug(v.toString() + " v afet addAll(c)");
th.check(v.removeAll(c) , "checking returnvalue of removeAll -- 2");
th.debug(v.toString() + " v after removeAll(c)");
th.check(v.equals(buildknownV()) , "v did change to original v");
v.add(2,null);
th.debug(v.toString() + "add(2,null)");
v.add(4,"a");
th.debug(v.toString() + "add(4,a)");
v.add(9,"b");
th.debug(v.toString() + "add(9,b)");
v.addAll(0,c);
th.debug(v.toString());
v.add(2,null); v.add(4,"a"); v.add(9,"b"); v.addAll(c);
th.debug(v.toString());
th.check(v.removeAll(c) , "checking returnvalue of removeAll -- 3");
th.debug(v.toString());
th.check(v, buildknownV(), "make sure all elements are removed");
th.debug(v.toString());
}
/**
* implemented.
*
*/
public void test_removeAllElements(){
th.checkPoint("removeAllElements()void");
Vector v = buildknownV();
int c = v.capacity();
v.removeAllElements();
th.check(v.isEmpty() && (v.size()==0), "make sure all is gone");
th.check(c == v.capacity() , "capacity stays the same, got: "+v.capacity()+", but exp.: "+c);
}
/**
* implemented.
*
*/
public void test_removeElement(){
th.checkPoint("removeElement(java.lang.Object)boolean");
Vector v = buildknownV();
v.addElement("a"); v.addElement(null);
v.addElement("a"); v.addElement(null);
v.addElement("a"); v.addElement(null);
th.check(v.removeElement("a") , "element is in there -- 1");
th.check(v.size() == 16 , "size is one less -- 1");
th.check(!v.removeElement("c") , "element isn't in there -- 1");
int i; boolean ok = true;
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 1");
th.check( (v.elementAt(11) == null) && (v.elementAt(13) == null) && (v.elementAt(15) == null) ,"checking order -- 1");
th.check( (v.elementAt(12) == "a") && (v.elementAt(14) == "a") ,"checking order -- 2");
ok = true;
th.check(v.removeElement("a") , "element is in there -- 2");
th.check(v.size() == 15 , "size is one less -- 2");
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 2");
th.check( (v.elementAt(11) == null) && (v.elementAt(12) == null) && (v.elementAt(14) == null) ,"checking order -- 3");
th.check( (v.elementAt(13) == "a") ,"checking order -- 4");
ok = true;
th.check(v.removeElement("a") , "element is in there -- 3");
th.check(v.size() == 14 , "size is one less -- 3");
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 3 ");
th.check( (v.elementAt(11) == null) && (v.elementAt(12) == null) && (v.elementAt(13) == null) ,"checking order -- 5");
th.check(!(v.contains("a")) ,"checking contents -- 1");
th.check(!v.removeElement("a") , "element isn't in there -- 2");
ok = true;
th.check(v.removeElement(null) , "element is in there -- 4");
th.check(v.size() == 13 , "size is one less -- 4");
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 4");
th.check( (v.elementAt(11) == null) && (v.elementAt(12) == null) ,"checking order -- 6");
th.check(v.removeElement(null) , "element is in there -- 5");
th.check(v.removeElement(null) , "element is in there -- 6");
th.check(!v.removeElement(null) , "element isn't in there -- 3");
}
/**
* implemented.
*
*/
public void test_removeElementAt(){
th.checkPoint("removeElementAt(int)void");
Vector v = buildknownV();
v.addElement("a"); v.addElement("b");
v.addElement("a"); v.addElement(null);
v.addElement("a"); v.addElement("b");
v.removeElementAt(11);
th.check(v.size() == 16 , "size is one less -- 1");
int i; boolean ok = true;
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 1");
th.check( (v.elementAt(11) == "b") && (v.elementAt(13) == null) && (v.elementAt(15) == "b") ,"checking order -- 1");
th.check( (v.elementAt(12) == "a") && (v.elementAt(14) == "a") ,"checking order -- 2");
ok = true;
v.removeElementAt(12);
th.check(v.size() == 15 , "size is one less -- 2");
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 2");
th.check( (v.elementAt(11) == "b") && (v.elementAt(12) == null) && (v.elementAt(14) == "b") ,"checking order -- 3");
th.check( (v.elementAt(13) == "a") ,"checking order -- 4");
ok = true;
v.removeElementAt(13);
th.check(v.size() == 14 , "size is one less -- 3");
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 3 ");
th.check( (v.elementAt(11) == "b") && (v.elementAt(12) == null) && (v.elementAt(13) == "b") ,"checking order -- 5");
th.check(!(v.contains("a")) ,"checking contents -- 1");
ok = true;
v.removeElementAt(12);
th.check(v.size() == 13 , "size is one less -- 4");
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 4");
th.check( (v.elementAt(11) == "b") && (v.elementAt(12) == "b") ,"checking order -- 5");
th.check(!(v.contains(null)) ,"checking contents -- 2");
v = buildknownV();
try { v.removeElementAt(-1);
th.fail("should throw ArrayIndexOutOfBoundsException -- 1");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try { v.removeElementAt(11);
th.fail("should throw ArrayIndexOutOfBoundsException -- 2");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
}
/**
* implemented.<br>
* since jdk 1.2 <br>
* removeRange is a protected method
*/
public void test_removeRange(){
th.checkPoint("removeRange(int,int)void");
AcuniaVectorTest xal = new AcuniaVectorTest(buildAL());
ArrayList al = buildAL();
xal.ensureCapacity(40);
try {
xal.removeRange(0,-1);
th.fail("should throw an IndexOutOfBoundsException -- 1");
}
catch(IndexOutOfBoundsException ioobe) { th.check(true); }
th.check(xal.equals(al) , "ArrayList must not be changed -- 1");
try {
xal.removeRange(-1,2);
th.fail("should throw an IndexOutOfBoundsException -- 2");
}
catch(IndexOutOfBoundsException ioobe) { th.check(true); }
th.check(xal.equals(al) , "ArrayList must not be changed -- 2");
try {
xal.removeRange(3,2);
th.fail("should throw an IndexOutOfBoundsException -- 3");
}
catch(IndexOutOfBoundsException ioobe) { th.check(true); }
catch(IllegalArgumentException iae) {
th.fail("should throw an IndexOutOfBoundsException, "
+ "not IllegalArumentException -- 3");
}
try {
th.check(al.equals(xal) , "ArrayList must not be changed -- 3");
}
catch(Exception e) { th.debug("bad operations messed up the Vector");}
xal = new AcuniaVectorTest(buildAL());
xal.ensureCapacity(40);
try {
xal.removeRange(3,15);
th.fail("should throw an IndexOutOfBoundsException -- 4");
}
catch(IndexOutOfBoundsException ioobe) { th.check(true); }
th.check(xal.equals(al) , "ArrayList must not be changed -- 4");
xal = new AcuniaVectorTest(buildAL());
xal.ensureCapacity(40);
try {
xal.removeRange(15,13);
th.fail("should throw an IndexOutOfBoundsException -- 5");
}
catch(IndexOutOfBoundsException ioobe) { th.check(true); }
catch(IllegalArgumentException iae) {
th.fail("should throw an IndexOutOfBoundsException, "
+ "not IllegalArumentException -- 5");
}
try {
th.check(xal.equals(al) , "ArrayList must not be changed -- 5");
}
catch(Exception e) { th.debug("bad operations messed up the Vector");}
xal = new AcuniaVectorTest(buildAL());
xal.ensureCapacity(40);
xal.removeRange(14,14);
th.check(xal.size() == 14 , "no elements should have been removed -- 6, size = "+xal.size());
xal.removeRange(10,14);
th.check(xal.size() == 10 , "4 elements should have been removed");
th.check( "a".equals(xal.get(0)) && "a".equals(xal.get(5)) && "a".equals(xal.get(7)) ,"check contents -- 1");
xal.removeRange(2,7);
th.check(xal.size() == 5 , "5 elements should have been removed");
th.check( "a".equals(xal.get(0)) && "c".equals(xal.get(1)) && "a".equals(xal.get(2))
&& "c".equals(xal.get(3)) && "u".equals(xal.get(4)) ,"check contents -- 2");
xal.removeRange(0,2);
th.check( "a".equals(xal.get(0)) && "c".equals(xal.get(1)) && "u".equals(xal.get(2)) ,"check contents -- 3");
th.check(xal.size() == 3 , "2 elements should have been removed");
}
/**
* implemented.<br>
* since jdk 1.2
*/
public void test_retainAll(){
th.checkPoint("retainAll(java.util.Collection)boolean");
Vector v = new Vector();
/**
* Disabled. A little too strict.
We will allow retaining null from an empty Vector.
try { v.retainAll(null);
th.fail("should throw NullPointerException");
}
catch (NullPointerException ne) { th.check(true); }
*/
v.add("a");
try { v.retainAll(null);
th.fail("should throw NullPointerException");
}
catch (NullPointerException ne) { th.check(true); }
v.add("b"); v.add(null);
Collection c = (Collection) v;
v = buildknownV();
th.check(v.retainAll(c) , "checking returnvalue of retainAll -- 1");
th.check(v.size() == 0 , "v is emptied");
v = buildknownV();
v.addAll(c);
th.check(v.retainAll(c) , "checking returnvalue of retainAll -- 2");
th.check(v.get(2)==null && v.get(1)=="b" && v.get(0)=="a" , "v is has elements of c");
th.check(v.equals(c) , "extra check on Vector.equals()");
th.check(v.size() == 3 , "checking new size() -- 1");
v = buildknownV();
th.debug(v + " == v");
v.add(2,null);
th.debug(v + " - add(2,null)");
v.add(4,"a");
th.debug(v + " - add(4,a)");
v.add(9,"b");
th.debug(v + " - add(9,b)");
th.debug(c + " == c");
v.addAll(10,c);
th.debug(v + " - add(10,c)");
boolean b = v.retainAll(c);
th.debug(v + " - retainAll(c)");
th.check(b , "checking returnvalue of retainAll -- 3");
th.check(v.get(0)==null && v.get(2)=="b" && v.get(1)=="a" , "multiple copies of an element shouldn't be deleted -- 1"+v);
th.check(v.get(5)==null && v.get(4)=="b" && v.get(3)=="a" , "multiple copies of an element shouldn't be deleted -- 2"+v);
th.check(v.size() == 6 , "checking new size() -- 2");
v = buildknownV();
v.add(2,null);
th.check(v.retainAll(c) , "checking returnvalue of retainAll -- 3");
th.check(v.get(0)==null , "checking contents of the vector -- 1");
th.check(v.size() == 1 , "checking new size() -- 2");
}
/**
* implemented.<br>
* since jdk 1.2
*/
public void test_set() throws UnsupportedOperationException{
th.checkPoint("set(int,java.lang.Object)java.lang.Object");
Vector v = new Vector();
try {
v.set(-1,"a");
th.fail("should throw an ArrayIndexOutOfBoundsException -- 1" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
try {
v.set(0,"a");
th.fail("should throw an ArrayIndexOutOfBoundsException -- 2" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
v = buildknownV();
try {
v.set(-1,"a");
th.fail("should throw an ArrayIndexOutOfBoundsException -- 3" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
try {
v.set(11,"a");
th.fail("should throw an ArrayIndexOutOfBoundsException -- 4" );
}
catch (ArrayIndexOutOfBoundsException e) { th.check(true); }
th.check( ((Float)v.set(5,"a")).intValue()==5 , "checking returnvalue of set -- 1");
th.check( ((Float)v.set(0,null)).intValue()==0 , "checking returnvalue of set -- 2");
th.check( v.get(5) == "a" , "checking effect of set -- 1");
th.check( v.get(0) == null , "checking effect of set -- 2");
th.check( v.set(5,"a") == "a" , "checking returnvalue of set -- 3");
th.check( v.set(0,null) == null , "checking returnvalue of set -- 4");
th.check( v.get(5) == "a" , "checking effect of set -- 1");
th.check( v.get(0) == null , "checking effect of set -- 2");
}
/**
* implemented.
*
*/
public void test_setElementAt(){
th.checkPoint("setElementAt(java.lang.Object,int)void");
Vector v = buildknownV();
try { v.setElementAt("a",-1);
th.fail("should throw ArrayIndexOutOfBoundsException -- 1");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
try { v.setElementAt("a",11);
th.fail("should throw ArrayIndexOutOfBoundsException -- 2");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
v.setElementAt("a",5);
th.check(v.elementAt(5) == "a" , "validate set -- 1");
v.setElementAt("b",0);
th.check(v.elementAt(0) == "b" , "validate set -- 2");
v.setElementAt("c",10);
th.check(v.elementAt(10) == "c" , "validate set -- 3");
v.setElementAt("d",5);
th.check(v.elementAt(5) == "d" , "validate set -- 4");
th.check(!v.contains("a"), "check contents -- 1");
v.setElementAt(null,5);
th.check(v.elementAt(5) == null , "validate set -- 5");
v.setElementAt("a",5);
th.check(v.elementAt(5) == "a" , "validate set -- 6");
th.check(!v.contains(null), "check contents -- 2");
}
/**
* implemented.
*
*/
public void test_setSize(){
th.checkPoint("setSize(int)void");
Vector v = buildknownV();
try { v.setSize(-1);
th.fail("should throw ArrayIndexOutOfBoundsException -- 1");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true, "good job!"); }
int i; boolean ok = true;
int size = 25;
v.setSize(size);
th.check(v.size() == size ,"checking new size -- 1");
try { v.elementAt(size);
th.fail("should throw ArrayIndexOutOfBoundsException -- 2");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 1");
ok = true;
for (i=11 ; i < size ; i++ )
{ if (v.elementAt(i)!= null) ok = false; }
th.check( ok , "null value not added -- 1");
size =5;
v.setSize(size);
th.check(v.size() == size ,"checking new size -- 2");
for (i=0 ; i < size ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float value didn't change -- 2");
try { v.elementAt(size);
th.fail("should throw ArrayIndexOutOfBoundsException -- 3");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
size =0;
v.setSize(size);
th.check(v.size() == size ,"checking new size -- 3");
try { v.elementAt(size);
th.fail("should throw ArrayIndexOutOfBoundsException -- 4");
}
catch (ArrayIndexOutOfBoundsException ae) { th.check(true); }
}
/**
* implemented.<br>
* --> errors in capacity will make ensurecapacity fail
*/
public void test_capacity(){
th.checkPoint("capacity()int");
Vector v = new Vector(15);
th.check(v.capacity() == 15, "checking capacity");
}
/**
* implemented.
*
*/
public void test_ensureCapacity(){
th.checkPoint("ensureCapacity(int)void");
Vector v = new Vector(10);
v.ensureCapacity(9);
th.check(v.capacity() == 10, "checking capacity -- 1");
v.ensureCapacity(15);
th.check(v.capacity() == 20, "checking capacity -- 2");
v.ensureCapacity(41);
th.check(v.capacity() == 41, "checking capacity -- 3");
v = new Vector(10,15);
v.ensureCapacity(9);
th.check(v.capacity() == 10, "checking capacity -- 4");
v.ensureCapacity(15);
th.check(v.capacity() == 25, "checking capacity -- 5");
v.ensureCapacity(55);
th.check(v.capacity() == 55, "checking capacity -- 6");
}
/**
* implemented.
*
*/
public void test_trimToSize(){
th.checkPoint("trimToSize()void");
Vector v = buildknownV();
int size = v.size();
v.ensureCapacity(20);
v.trimToSize();
th.check( v.capacity() == size );
int i; boolean ok = true;
for (i=0 ; i < 11 ; i++ )
{ if (((Float)v.elementAt(i)).intValue() != i) ok = false; }
th.check( ok , "Float values didn't change -- 1");
v.addElement("a");
th.check(v.capacity() == 22, "adding an elements raises the capacity");
}
/**
* implemented --> MIGHT NEED EXTRA TESTING. <br>
* since jdk 1.2 <br>
* the behaviour of the subList related to the Vector is not tested <br>
* completly --> may be tested in other places?
*/
public void test_subList() throws UnsupportedOperationException{
th.checkPoint("subList(int,int)java.util.List");
Vector v = new Vector();
try {
v.subList(-1,0);
th.fail("should throw an IndexOutOfBoundsException -- 1" );
}
catch (IndexOutOfBoundsException e) { th.check(true); }
try {
v.subList(0,1);
th.fail("should throw an IndexOutOfBoundsException -- 2" );
}
catch (IndexOutOfBoundsException e) { th.check(true); }
try {
th.check(v.subList(0,0).size()==0);
}
catch (IndexOutOfBoundsException e) { th.fail("shouldn't throw an IndexOutOfBoundsException -- 3" ); }
try {
v.subList(1,0);
th.fail("should throw an IllegalArgumentException -- 4" );
}
catch (IllegalArgumentException e) { th.check(true); }
v = buildknownV();
try {
v.subList(-1,6);
th.fail("should throw an IndexOutOfBoundsException -- 5" );
}
catch (IndexOutOfBoundsException e) { th.check(true); }
try {
v.subList(10,9);
th.fail("should throw an IllegalArgumentException -- 6" );
}
catch (IllegalArgumentException e) { th.check(true); }
try {
v.subList(1,12);
th.fail("should throw an IndexOutOfBoundsException -- 7" );
}
catch (IndexOutOfBoundsException e) { th.check(true); }
try {
th.check(v.subList(11,11).size() ==0 );
}
catch (IndexOutOfBoundsException e) { th.fail("shouldn't throw an IndexOutOfBoundsException -- 8" ); }
List l = v.subList(0,11);
th.check(v.equals(l) , "checking sublist for equality");
v.add("a");
try { l.get(3);
th.fail("should throw a ConcurrentModificationException -- 1" );
}
catch (ConcurrentModificationException e) { th.check(true); }
v = new Vector();
v.add("a"); v.add("b"); v.add(null); v.add("c"); v.add("d");
l = v.subList(2,5);
th.check(l.get(0) == null && l.get(1)=="c" && l.get(2)=="d" , "checking elements -- 1");
th.check(l.set(0,"g")==null , "checking set");
th.check(v.get(2)=="g" , "modifications in l should reflect on v -- 1");
th.check(l.get(0) == "g" && l.get(1)=="c" && l.get(2)=="d" , "checking elements -- 1");
l.clear();
th.check(v.size()==2 && v.get(0)=="a" && v.get(1)=="b" ,"modifications in l should reflect on v -- 1");
//th.debug("DEBUG -- done with check");
v.add(null); v.add("c"); v.add("d");
//th.debug("DEBUG -- done adding");
l = v.subList(2,5);
//th.debug("DEBUG -- done sublisting");
try { v.addAll(l);
th.fail("should throw a ConcurrentModificationException");
// during this method call l might be overridden ...
}
catch (ConcurrentModificationException e) { th.check(true); }
}
/**
* implemented.<br>
* since jdk 1.2
*/
public void test_toArray(){
th.checkPoint("toArray()[java.lang.Object");
Vector v = new Vector();
v.add("a"); v.add(null); v.add("b");
Object o[]=v.toArray();
th.check(o[0]== "a" && o[1] == null && o[2] == "b" , "checking elements -- 1");
th.check(o.length == 3 , "checking size Object array");
th.checkPoint("toArray([java.lang.Object)[java.lang.Object");
v = new Vector();
try { v.toArray(null);
th.fail("should throw NullPointerException -- 1");
}
catch (NullPointerException ne) { th.check(true); }
v.add("a"); v.add(null); v.add("b");
String sa[] = new String[5];
sa[3] = "deleteme"; sa[4] = "leavemealone";
th.check(v.toArray(sa) == sa , "sa is large enough, no new array created");
th.check(sa[0]=="a" && sa[1] == null && sa[2] == "b" , "checking elements -- 1"+sa[0]+", "+sa[1]+", "+sa[2]);
th.check(sa.length == 5 , "checking size Object array");
th.check(sa[3]==null && sa[4]=="leavemealone", "check other elements -- 1"+sa[3]+", "+sa[4]);
v = buildknownV();
try { v.toArray(null);
th.fail("should throw NullPointerException -- 2");
}
catch (NullPointerException ne) { th.check(true); }
try { v.toArray(sa);
th.fail("should throw an ArrayStoreException");
}
catch (ArrayStoreException ae) { th.check(true); }
v.add(null);
Float far[],fa[] = new Float[12];
far = (Float[])v.toArray(fa);
th.check( far == fa , "returned array is the same");
try { sa = (String[])v.toArray(fa);
th.fail("should throw ClassCastException");
}
catch (ClassCastException ce) { th.check(true); }
}
/**
* implemented.
*
*/
public void test_clone(){
th.checkPoint("clone()java.lang.Object");
Vector cv,v = new Vector(10,5);
v.addElement("a") ;v.addElement("b") ;v.addElement("c");
cv = (Vector)v.clone();
th.check(cv.size() == v.size(), "checking size -- 1");
th.check(cv.capacity() , v.capacity(), "checking capacity -- 1");
cv.ensureCapacity(11);
th.check(cv.capacity() , 15, "capacityIncrement was not defined correctly");
//this could fail if capacity is not cloned correctly ...
th.check(v.capacity() == 10, "changes in one object doen't affect the other -- 1");
v.addElement("d");
th.check(cv.size() == 3, "changes in one object doen't affect the other -- 2");
}
/**
* implementation. <br>
* overrides Object.equals() since jdk1.2 <br>
*
*/
public void test_equals(){
th.checkPoint("equals(java.lang.Object)boolean");
Vector v = buildknownV();
th.check(v.equals(buildknownV()), "objects are equal -- 1");
v.removeElementAt(1);
th.check(!v.equals(buildknownV()), "objects are not equal -- 1");
v = buildknownV();
v.ensureCapacity(25);
th.check(v.equals(buildknownV()), "objects are equal -- 2");
ArrayList al = new ArrayList(v);
th.check(v.equals(al) , "checking ... -- 1");
v = new Vector();
al = new ArrayList();
th.check(v.equals(al) , "checking ... -- 2");
v.add(null);
al.add(null);
th.check(v.equals(al) , "checking ... -- 3");
v.add("a"); v.add(null);
al.add(null); al.add("a");
th.check(!v.equals(al) , "checking ... -- 4");
}
/**
* implemented.
*
*/
public void test_hashCode(){
th.checkPoint("hashCode()int");
Vector v = new Vector();
th.check(v.hashCode() == 1 , "check calculation hashcode -- 1 - got: "+v.hashCode());
v.addElement("a");
th.check(v.hashCode() == 31 + "a".hashCode() , "check calculation hashcode -- 2 - got: "+v.hashCode());
Integer i = new Integer(324);
v.addElement(i);
th.check(v.hashCode() == 31*31 + 31*"a".hashCode() + i.hashCode() , "check calculation hashcode -- 3 - got: "+v.hashCode());
v = new Vector();
v.addElement(null);
th.check(v.hashCode() == 31, "check calculation hashcode -- 4 - got: "+v.hashCode());
}
/**
* implemented.
*
*/
public void test_toString(){
th.checkPoint("toString()java.lang.String");
Vector v =new Vector();
th.check(v.toString().equals("[]"), "checking toString -- 1 - got: "+v);
v.addElement("a");
th.check(v.toString().equals("[a]"), "checking toString -- 2 - got: "+v);
Integer i = new Integer(324);
v.addElement(i);
th.check(v.toString().equals("[a, 324]"), "checking toString -- 3 - got: "+v);
v.addElement("abcd");
th.check(v.toString().equals("[a, 324, abcd]"), "checking toString -- 4 - got: "+v);
}
/**
* implemented. <br>
* <br>
* this method isn't defined in Vector but we test the inherited method ...
*/
public void test_iterator(){
th.checkPoint("iterator()java.util.Iterator");
Vector v = new Vector();
v.add("a"); v.add("c"); v.add("u"); v.add("n"); v.add("i"); v.add("a");
v.add(null); v.add("!");
Iterator it = v.iterator();
Vector vc = (Vector) v.clone();
int i=0;
Object o;
while (it.hasNext()) {
o = it.next();
if (!vc.remove(o)) th.debug("didn't find "+o+" in vector");
if (i++> 20) break;
}
th.check( i < 20 , "check for infinite loop");
th.check(vc.isEmpty() ,"all elements iterated");
try {
it.next();
th.fail("should throw a NoSuchElementException");
}
catch(NoSuchElementException nsee) { th.check(true); }
it = v.iterator();
try {
it.remove();
th.fail("should throw an IllegalStateException -- 1");
}
catch(IllegalStateException ise) { th.check(true); }
it.next();
it.remove();
try {
it.remove();
th.fail("should throw an IllegalStateException -- 2");
}
catch(IllegalStateException ise) { th.check(true); }
v.add("new");
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- 1");
}
catch(ConcurrentModificationException cme) { th.check(true); }
try {
it.remove();
th.fail("should throw a ConcurrentModificationException -- 2");
}
catch(ConcurrentModificationException cme) { th.check(true); }
catch(IllegalStateException ise) { th.debug("ConcurrentModificationException should be triggered first"); }
it = v.iterator();
while (it.hasNext()) {
o = it.next();
it.remove();
if (v.contains(o)) th.fail("removed wrong element when tried to remove "+o+", got:"+v);
if (i++> 20) break;
}
th.check(v.isEmpty() , "all elements are removed");
// check if modCount is updated correctly !!!
v.add("a"); v.add("c"); v.add("u"); v.add("n"); v.add("i"); v.add("a");
it = v.iterator();
v.contains("a");
v.containsAll(v);
v.indexOf("a");
v.isEmpty();
v.lastIndexOf("a");
v.size();
v.get(2);
v.hashCode();
v.equals(v);
v.toArray();
v.toArray(new Object[2]);
v.copyInto(new Object[10]);
v.elementAt(2);
v.elements();
v.firstElement();
v.lastElement();
v.capacity();
v.trimToSize();
v.subList(2,5);
v.clone();
v.toString();
try {
it.next();
th.check(true, "Ok -- 1");
}
catch(Exception e) { th.fail("should not throw an Exception, got "+e);}
it = v.iterator();
v.add(3,"a");
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- add(int,Object)");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 2"); }
it = v.iterator();
v.add("a");
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- add(Object)");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 3"); }
it = v.iterator();
v.addAll((Collection)v.clone());
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- addAll(int,Col)");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 4"); }
it = v.iterator();
v.addAll(3,(Collection)v.clone());
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- addAll(Col)");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 5"); }
it = v.iterator();
v.addElement("b");
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- addElement");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 6"); }
it = v.iterator();
v.insertElementAt("b",4);
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- insertElementAt");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 7"); }
it = v.iterator();
v.remove(4);
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- remove(int)");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 8"); }
it = v.iterator();
v.remove("b");
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- remove(Object)");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 9"); }
Vector rv = new Vector();
rv.add("a"); rv.add("b");
it = v.iterator();
v.removeAll(rv);
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- removeAll");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 10"); }
it = v.iterator();
v.removeElement("c");
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- removeElement");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 11"); }
it = v.iterator();
v.removeElementAt(7);
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- removeElementAt");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 12"); }
rv = (Vector)v.clone();
rv.remove(null); rv.remove(null); rv.remove(null);
v.add(null);
it = v.iterator();
v.retainAll(rv);
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- retainAll");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 13"); }
it = v.iterator();
v.setSize(v.size()-2);
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- setSize");
}
catch(ConcurrentModificationException cme) { th.check(true, "Ok -- 16"); }
it = v.iterator();
v.removeAllElements();
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- removeAllElements");
}
catch(ConcurrentModificationException cme) { th.check(true); }
catch(NoSuchElementException nsee) { th.debug("ConcurrentModificationException should be triggered first"); }
v.add("a");
it = v.iterator();
v.clear();
try {
it.next();
th.fail("should throw a ConcurrentModificationException -- clear");
}
catch(ConcurrentModificationException cme) { th.check(true); }
catch(NoSuchElementException nsee) { th.debug("ConcurrentModificationException should be triggered first"); }
}
/**
* not implemented. <br>
* excessive testing
*/
public void test_behaviour(){
th.checkPoint("()");
Vector v = buildknownV();
ArrayList al = new ArrayList(v);
th.check( al.size() == v.size(), "checking size");
Iterator it = al.iterator();
it.next();
try {
it.remove();
th.check(true , "passed remove");
}
catch(Exception e) { th.fail("got bad exception, "+e); }
}
protected ArrayList buildAL() {
Vector v = new Vector();
v.add("a"); v.add("c"); v.add("u"); v.add("n"); v.add("i"); v.add("a"); v.add(null);
v.add("a"); v.add("c"); v.add("u"); v.add("n"); v.add("i"); v.add("a"); v.add(null);
return new ArrayList(v);
}
// The following fields and method are necessary for extending and Vector.
private boolean didRemoveRange=false;
private int from = -1;
private int to = -1;
public AcuniaVectorTest(Collection c){
super(c);
}
public void removeRange(int fidx, int tidx) {
didRemoveRange=true;
to = tidx;
from = fidx;
super.removeRange(fidx, tidx);
}
public boolean get_dRR() {
return didRemoveRange;
}
public void set_dRR(boolean b) {
didRemoveRange = b;
}
public int get_to() {
return to;
}
public int get_from() {
return from;
}
}
|