Changeset 903 for trunk/psLib/test/collections/tst_psDlist.c
- Timestamp:
- Jun 7, 2004, 2:58:39 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/collections/tst_psDlist.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/collections/tst_psDlist.c
r902 r903 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-06-0 7 23:20:21$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-06-08 00:58:39 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 21 21 static int testDlistAdd(void); 22 22 static int testDlistGet(void); 23 static int testDlistRemove(void); 23 24 24 25 testDescription tests[] = { … … 26 27 {testDlistAdd,"488-testDlistAdd",0}, 27 28 {testDlistGet,"489-testDlistGet",0}, 29 {testDlistRemove,"490-testDlistRemove",0}, 28 30 {NULL} 29 31 }; … … 294 296 */ 295 297 296 psLogMsg(__func__,PS_LOG_INFO,"psDlistGet(list,which) shall be tested with "297 "the following instances");298 299 298 // 1. list is NULL. 300 299 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error"); … … 380 379 return 0; 381 380 } 381 382 int testDlistRemove(void) 383 { 384 int currentId = psMemGetId(); 385 psDlist* list = NULL; 386 int* data; 387 388 /* 389 psDlistRemove(list,data,which) should be tested under the following conditions: 390 391 1. list is NULL 392 2. which is PS_DLIST_HEAD (remove first element of list) 393 3. which is PS_DLIST_TAIL (remove last element of list) 394 4. which is PS_DLIST_NEXT (element right of cursor [which should be head,tail, and neither]) 395 5. which is PS_DLIST_PREV (element left of cursor [which should be head,tail, and neither]) 396 6. which is PS_DLIST_UNKNOWN and data=NULL (error) 397 7. which is PS_DLIST_UNKNOWN and data=[head,tail,other list items] 398 8. which is PS_DLIST_UNKNOWN and data!=NULL and data!=any element in list 399 400 In all conditions that are not an error, list.n shall be decremented and only the specified element 401 shall be removed. After each step, list.n should be checked to verify that it is the true 402 number of elements in list. 403 */ 404 405 // 1. list is NULL. 406 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error"); 407 if (psDlistRemove(list,NULL,PS_DLIST_HEAD) != NULL) { 408 psError(__func__,"psDlistGet didn't return NULL given a NULL list."); 409 return 1; 410 }; 411 412 // create a list 413 list = psDlistAlloc(NULL); 414 415 for (int lcv=0;lcv<15;lcv++) { 416 data = psAlloc(sizeof(int)); 417 *data = lcv; 418 list = psDlistAdd(list,data,PS_DLIST_TAIL); 419 } 420 421 422 // 2. which is PS_DLIST_HEAD (remove first element of list) 423 data = psDlistRemove(list,NULL,PS_DLIST_HEAD); 424 if (data == NULL || *data != 0) { 425 printListInt(list); 426 psError(__func__,"Failed to remove PS_DLIST_HEAD"); 427 return 1; 428 } 429 psFree(data); 430 if (list->size != 14) { 431 printListInt(list); 432 psError(__func__,"Didn't decrement size properly to 14."); 433 return 1; 434 } 435 436 // 3. which is PS_DLIST_TAIL (remove last element of list) 437 data = psDlistRemove(list,NULL,PS_DLIST_TAIL); 438 if (data == NULL || *data != 14) { 439 printListInt(list); 440 psError(__func__,"Failed to remove PS_DLIST_TAIL"); 441 return 1; 442 } 443 psFree(data); 444 if (list->size != 13) { 445 printListInt(list); 446 psError(__func__,"Didn't decrement size properly to 13."); 447 return 1; 448 } 449 450 // 4. which is PS_DLIST_NEXT (element right of cursor [which should be head,tail, and neither]) 451 psDlistSetIterator(list,PS_DLIST_HEAD); 452 data = psDlistRemove(list,NULL,PS_DLIST_NEXT); 453 if (data == NULL || *data != 2) { 454 printListInt(list); 455 psError(__func__,"Failed to remove PS_DLIST_NEXT @ PS_DLIST_HEAD"); 456 return 1; 457 } 458 psFree(data); 459 if (list->size != 12) { 460 printListInt(list); 461 psError(__func__,"Didn't decrement size properly to 12."); 462 return 1; 463 } 464 465 psDlistSetIterator(list,PS_DLIST_TAIL); 466 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 467 data = psDlistRemove(list,NULL,PS_DLIST_NEXT); 468 if (data != NULL) { 469 printListInt(list); 470 psError(__func__,"Removed something with PS_DLIST_NEXT @ PS_DLIST_TAIL"); 471 return 1; 472 } 473 474 psDlistSetIterator(list,2); 475 data = psDlistRemove(list,NULL,PS_DLIST_NEXT); 476 if (data == NULL || *data != 5) { 477 printListInt(list); 478 psError(__func__,"Failed to remove PS_DLIST_NEXT @ which=2"); 479 return 1; 480 } 481 psFree(data); 482 if (list->size != 11) { 483 printListInt(list); 484 psError(__func__,"Didn't decrement size properly to 11."); 485 return 1; 486 } 487 488 // 5. which is PS_DLIST_PREV (element left of cursor [which should be head,tail, and neither]) 489 psDlistSetIterator(list,PS_DLIST_HEAD); 490 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 491 data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS); 492 if (data != NULL) { 493 printListInt(list); 494 psError(__func__,"removed something for PS_DLIST_PREVIOUS @ PS_DLIST_HEAD"); 495 return 1; 496 } 497 498 psDlistSetIterator(list,PS_DLIST_TAIL); 499 data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS); 500 if (data == NULL || *data != 12) { 501 printListInt(list); 502 psError(__func__,"Failed to remove PS_DLIST_PREVIOUS @ PS_DLIST_TAIL"); 503 return 1; 504 } 505 psFree(data); 506 if (list->size != 10) { 507 printListInt(list); 508 psError(__func__,"Didn't decrement size properly to 10."); 509 return 1; 510 } 511 512 psDlistSetIterator(list,2); 513 data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS); 514 if (data == NULL || *data != 3) { 515 printListInt(list); 516 psError(__func__,"Failed to remove PS_DLIST_PREVIOUS @ which=2"); 517 return 1; 518 } 519 psFree(data); 520 if (list->size != 9) { 521 printListInt(list); 522 psError(__func__,"Didn't decrement size properly to 9."); 523 return 1; 524 } 525 526 // 6. which is PS_DLIST_UNKNOWN and data=NULL (error) 527 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 528 data = psDlistRemove(list,NULL,PS_DLIST_UNKNOWN); 529 if (data != NULL) { 530 printListInt(list); 531 psError(__func__,"removed something for PS_DLIST_UNKNOWN with data=NULL"); 532 return 1; 533 } 534 535 // 7. which is PS_DLIST_UNKNOWN and data=[head,tail,other list items] 536 data = psDlistGet(list,PS_DLIST_HEAD); 537 data = psDlistRemove(list,data,PS_DLIST_UNKNOWN); 538 if (data == NULL || *data != 1) { 539 printListInt(list); 540 psError(__func__,"Failed to remove PS_DLIST_UNKNOWN @ PS_DLIST_HEAD"); 541 return 1; 542 } 543 psFree(data); 544 if (list->size != 8) { 545 printListInt(list); 546 psError(__func__,"Didn't decrement size properly to 8."); 547 return 1; 548 } 549 550 data = psDlistGet(list,PS_DLIST_TAIL); 551 data = psDlistRemove(list,data,PS_DLIST_UNKNOWN); 552 if (data == NULL || *data != 13) { 553 printListInt(list); 554 psError(__func__,"Failed to remove PS_DLIST_UNKNOWN @ PS_DLIST_TAIL"); 555 return 1; 556 } 557 psFree(data); 558 if (list->size != 7) { 559 printListInt(list); 560 psError(__func__,"Didn't decrement size properly to 7."); 561 return 1; 562 } 563 564 psDlistSetIterator(list,PS_DLIST_HEAD); 565 data = psDlistGet(list,PS_DLIST_NEXT); 566 567 data = psDlistRemove(list,data,PS_DLIST_UNKNOWN); 568 if (data == NULL || *data != 6) { 569 printListInt(list); 570 psError(__func__,"Failed to remove PS_DLIST_UNKNOWN @ which=1"); 571 return 1; 572 } 573 psFree(data); 574 if (list->size != 6) { 575 printListInt(list); 576 psError(__func__,"Didn't decrement size properly to 6."); 577 return 1; 578 } 579 580 // 8. which is PS_DLIST_UNKNOWN and data!=NULL and data!=any element in list 581 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 582 data = psDlistRemove(list,data,PS_DLIST_UNKNOWN); 583 if (data != NULL) { 584 printListInt(list); 585 psError(__func__,"removed something for PS_DLIST_UNKNOWN with previously removed item"); 586 return 1; 587 } 588 589 // clear out the list 590 psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD)); 591 psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD)); 592 psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD)); 593 psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD)); 594 psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD)); 595 596 data = psDlistRemove(list,data,PS_DLIST_HEAD); 597 if (data == NULL || *data != 11) { 598 printListInt(list); 599 psError(__func__,"Failed to remove last element"); 600 return 1; 601 } 602 psFree(data); 603 604 if (list->size != 0) { 605 printListInt(list); 606 psError(__func__,"Didn't remove all the elements."); 607 return 1; 608 } 609 610 psDlistFree(list,PS_FREE); 611 612 psMemCheckLeaks(currentId,NULL,NULL); 613 psMemCheckCorruption(1); 614 615 return 0; 616 617 }
Note:
See TracChangeset
for help on using the changeset viewer.
