IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 3, 2004, 2:19:54 PM (22 years ago)
Author:
desonia
Message:

added tests for psImageCopy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImage.c

    r831 r844  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-02 23:29:29 $
     8 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-04 00:19:54 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include "psTest.h"
    1919#include "pslib.h"
     20#include "psType.h"
    2021
    2122static int testImageAlloc(void);
    2223static int testImageSubset(void);
     24static int testImageCopy(void);
    2325
    2426testDescription tests[] = {
    2527                              {testImageAlloc,"546/548-testImageAlloc/Free",0},
    26                               {testImageSubset,"547/549-testImageSubset",0},
     28                              {testImageSubset,"547/550-testImageSubset",0},
     29                              {testImageCopy,"551-testImageCopy",0},
    2730                              {NULL}
    2831                          };
     
    385388             "psImage structure is not modified.");
    386389
     390    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    387391    subset1 = psImageSubset(NULL,NULL,c/2,r/2,0,0);
    388392    if (subset1 != NULL) {
     
    396400
    397401    memcpy(&preSubsetStruct,original,sizeof(psImage));
     402    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    398403    subset1 = psImageSubset(NULL,original,c/2,0,0,0);
    399404    if (subset1 != NULL) {
     
    401406        return 15;
    402407    }
     408    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    403409    subset1 = psImageSubset(NULL,original,0,r/2,0,0);
    404410    if (subset1 != NULL) {
     
    416422             "values of psImage structure image.");
    417423
     424    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    418425    subset1 = psImageSubset(NULL,original,c/2,r/2,c,0);
    419426    if (subset1 != NULL) {
     
    422429        return 18;
    423430    }
     431    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    424432    subset1 = psImageSubset(NULL,original,c/2,r/2,0,r);
    425433    if (subset1 != NULL) {
     
    428436        return 19;
    429437    }
     438    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    430439    subset1 = psImageSubset(NULL,original,c/2,r/2,-1,0);
    431440    if (subset1 != NULL) {
     
    434443        return 20;
    435444    }
     445    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    436446    subset1 = psImageSubset(NULL,original,c/2,r/2,0,-1);
    437447    if (subset1 != NULL) {
     
    446456             "is not modified.");
    447457
     458    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    448459    subset1 = psImageSubset(NULL,original,c/2,r/2,c/2,0);
    449460    if (subset1 != NULL) {
     
    451462        return 22;
    452463    }
     464    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    453465    subset1 = psImageSubset(NULL,original,c/2,r/2,0,r/2);
    454466    if (subset1 != NULL) {
     
    456468        return 23;
    457469    }
     470    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    458471    subset1 = psImageSubset(NULL,original,c/2,r/2,c/2,r/2);
    459472    if (subset1 != NULL) {
     
    465478             "psImage structure");
    466479
     480    memcpy(&preSubsetStruct,original,sizeof(psImage));
     481
    467482    psImageFreeChildren(original);
    468483
    469484    // Verify the returned psImage structure member Nchildren is set to zero.
    470485    if (original->nChildren != 0) {
    471         psError(__func__,"psImageFreeChildren row+cols).");
     486        psError(__func__,"psImageFreeChildren didn't set nChildren to zero.");
    472487        return 25;
    473488    }
    474489
     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    }
    475506
    476507    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
    477511    psMemCheckLeaks(currentId,NULL,NULL);
    478512    psMemCheckCorruption(1);
     
    480514    return 0;
    481515}
     516
     517int 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.