Changeset 844
- Timestamp:
- Jun 3, 2004, 2:19:54 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImage.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImage.c
r831 r844 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-06-0 2 23:29:29$8 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-06-04 00:19:54 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #include "psTest.h" 19 19 #include "pslib.h" 20 #include "psType.h" 20 21 21 22 static int testImageAlloc(void); 22 23 static int testImageSubset(void); 24 static int testImageCopy(void); 23 25 24 26 testDescription tests[] = { 25 27 {testImageAlloc,"546/548-testImageAlloc/Free",0}, 26 {testImageSubset,"547/549-testImageSubset",0}, 28 {testImageSubset,"547/550-testImageSubset",0}, 29 {testImageCopy,"551-testImageCopy",0}, 27 30 {NULL} 28 31 }; … … 385 388 "psImage structure is not modified."); 386 389 390 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 387 391 subset1 = psImageSubset(NULL,NULL,c/2,r/2,0,0); 388 392 if (subset1 != NULL) { … … 396 400 397 401 memcpy(&preSubsetStruct,original,sizeof(psImage)); 402 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 398 403 subset1 = psImageSubset(NULL,original,c/2,0,0,0); 399 404 if (subset1 != NULL) { … … 401 406 return 15; 402 407 } 408 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 403 409 subset1 = psImageSubset(NULL,original,0,r/2,0,0); 404 410 if (subset1 != NULL) { … … 416 422 "values of psImage structure image."); 417 423 424 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 418 425 subset1 = psImageSubset(NULL,original,c/2,r/2,c,0); 419 426 if (subset1 != NULL) { … … 422 429 return 18; 423 430 } 431 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 424 432 subset1 = psImageSubset(NULL,original,c/2,r/2,0,r); 425 433 if (subset1 != NULL) { … … 428 436 return 19; 429 437 } 438 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 430 439 subset1 = psImageSubset(NULL,original,c/2,r/2,-1,0); 431 440 if (subset1 != NULL) { … … 434 443 return 20; 435 444 } 445 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 436 446 subset1 = psImageSubset(NULL,original,c/2,r/2,0,-1); 437 447 if (subset1 != NULL) { … … 446 456 "is not modified."); 447 457 458 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 448 459 subset1 = psImageSubset(NULL,original,c/2,r/2,c/2,0); 449 460 if (subset1 != NULL) { … … 451 462 return 22; 452 463 } 464 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 453 465 subset1 = psImageSubset(NULL,original,c/2,r/2,0,r/2); 454 466 if (subset1 != NULL) { … … 456 468 return 23; 457 469 } 470 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 458 471 subset1 = psImageSubset(NULL,original,c/2,r/2,c/2,r/2); 459 472 if (subset1 != NULL) { … … 465 478 "psImage structure"); 466 479 480 memcpy(&preSubsetStruct,original,sizeof(psImage)); 481 467 482 psImageFreeChildren(original); 468 483 469 484 // Verify the returned psImage structure member Nchildren is set to zero. 470 485 if (original->nChildren != 0) { 471 psError(__func__,"psImageFreeChildren row+cols).");486 psError(__func__,"psImageFreeChildren didn't set nChildren to zero."); 472 487 return 25; 473 488 } 474 489 490 // Verify the returned psImage structure member children pointer is set to null. 491 if (original->children != NULL) { 492 psError(__func__,"psImageFreeChildren didn't set children ptr to NULL."); 493 return 26; 494 } 495 496 //Verify the returned psImage structure members type, nrow, ncol, row0, col0, rows and parent are not 497 // modified. 498 if (preSubsetStruct.numRows != original->numRows || 499 preSubsetStruct.numCols != original->numCols || 500 preSubsetStruct.row0 != original->row0 || 501 preSubsetStruct.col0 != original->col0) { 502 503 psError(__func__,"psImageFreeChildren modified parent's non-children elements."); 504 return 27; 505 } 475 506 476 507 psImageFree(original); 508 509 // Verify no memory leaks or corruption are detected for a psImage structure 510 // Verify no memory leaks or corruption are detected for a psImage structure 477 511 psMemCheckLeaks(currentId,NULL,NULL); 478 512 psMemCheckCorruption(1); … … 480 514 return 0; 481 515 } 516 517 int testImageCopy(void) 518 { 519 psImage* img = NULL; 520 psImage* img2 = NULL; 521 psImage* img3 = NULL; 522 unsigned int c = 128; 523 unsigned int r = 256; 524 int currentId = psMemGetId(); 525 526 img = psImageAlloc(c,r,PS_TYPE_F32); 527 for (unsigned row=0;row<r;row++) { 528 psF32* imgRow = img->data.F32[row]; 529 for (unsigned col=0;col<c;col++) { 530 imgRow[col] = (psF32)(row+col); 531 } 532 } 533 img2 = psImageAlloc(c,r,PS_TYPE_F32); 534 for (unsigned row=0;row<r;row++) { 535 psF32* img2Row = img2->data.F32[row]; 536 for (unsigned col=0;col<c;col++) { 537 img2Row[col] = 0.0f; 538 } 539 } 540 541 img3 = psImageCopy(img2,img,PS_TYPE_F32); 542 543 // Verify the returned psImage structure pointer is equal to the input parameter output. 544 if (img2 != img3) { 545 psError(__func__,"the image given for recycled wasn't"); 546 return 1; 547 } 548 549 // Verify the returned psImage structure member are equal to the values in 550 // the input psImage structure input. 551 for (unsigned row=0;row<r;row++) { 552 psF32* imgRow = img->data.F32[row]; 553 psF32* img2Row = img2->data.F32[row]; 554 for (unsigned col=0;col<c;col++) { 555 if (imgRow[col] - (row+col) > FLT_EPSILON) { 556 psError(__func__,"Input image was changed at %d,%d (%f)!", 557 col,row,imgRow[col]); 558 return 2; 559 } 560 561 if (imgRow[col] != img2Row[col]) { 562 psError(__func__,"returned psImage values after copy don't match!"); 563 return 2; 564 } 565 } 566 } 567 568 // Verify the returned psImage structure pointer is null and program 569 // execution doesn't stop, if the input parameter input is null. 570 psLogMsg(__func__,PS_LOG_INFO,"An error should follow..."); 571 img3 = psImageCopy(NULL,NULL,PS_TYPE_F32); 572 if (img3 != NULL) { 573 psError(__func__,"psImageCopy didn't return NULL when input image was NULL."); 574 return 3; 575 } 576 577 img2 = psImageCopy(img2,img,PS_TYPE_U8); 578 for (unsigned row=0;row<r;row++) { 579 psF32* imgRow = img->data.F32[row]; 580 psU8* img2Row = img2->data.U8[row]; 581 for (unsigned col=0;col<c;col++) { 582 if (imgRow[col] - (row+col) > FLT_EPSILON) { 583 psError(__func__,"Input image was changed at %d,%d (%f)!", 584 col,row,imgRow[col]); 585 return 2; 586 } 587 588 if (row+col != img2Row[col]) { 589 psError(__func__,"returned psImage values after copy don't match at %d,%d (%d vs %d)", 590 col,row,img2Row[col], row+col); 591 return 2; 592 } 593 } 594 } 595 596 img2 = psImageCopy(img2,img,PS_TYPE_U16); 597 img2 = psImageCopy(img2,img,PS_TYPE_U32); 598 img2 = psImageCopy(img2,img,PS_TYPE_S8); 599 img2 = psImageCopy(img2,img,PS_TYPE_S16); 600 img2 = psImageCopy(img2,img,PS_TYPE_S32); 601 img2 = psImageCopy(img2,img,PS_TYPE_F64); 602 img2 = psImageCopy(img2,img,PS_TYPE_C32); 603 img2 = psImageCopy(img2,img,PS_TYPE_C64); 604 605 psImageFree(img); 606 psImageFree(img2); 607 608 if (psMemCheckLeaks(currentId,NULL,NULL) != 0) { 609 psAbort(__func__,"Memory Leaks!"); 610 } 611 psMemCheckCorruption(1); 612 613 return 0; 614 }
Note:
See TracChangeset
for help on using the changeset viewer.
