IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 29, 2004, 10:17:58 AM (22 years ago)
Author:
desonia
Message:

changes associated with the testing of psImageSubsection.

File:
1 edited

Legend:

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

    r1920 r1929  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-09-28 23:26:49 $
     8 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-09-29 20:17:58 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222
    2323static int testImageAlloc(void);
    24 static int testImageSubset(void);
    2524static int testImageCopy(void);
    2625
     
    2827                              {testImageAlloc,546,"psImageAlloc",0,false},
    2928                              {testImageAlloc,548,"psImageFree",0,true},
    30                               {testImageSubset,547,"psImageSubset",0,false},
    31                               {testImageSubset,550,"psImageSubset",0,true},
    3229                              {testImageCopy,551,"psImageCopy",0,false},
    3330                              {NULL}
     
    252249
    253250    psFree(image);
    254 
    255     return 0;
    256 }
    257 
    258 // #547: psImageSubset shall create child image of a specified size from a parent psImage structure
    259 int testImageSubset(void)
    260 {
    261     psImage preSubsetStruct;
    262     psImage* original;
    263     psImage* subset1 = NULL;
    264     psImage* subset2 = NULL;
    265     psImage* subset3 = NULL;
    266     int c = 128;
    267     int r = 256;
    268 
    269     original = psImageAlloc(c,r,PS_TYPE_U32);
    270     for (int row=0;row<r;row++) {
    271         for (int col=0;col<c;col++) {
    272             original->data.F32[row][col] = row*1000+col;
    273         }
    274     }
    275 
    276     memcpy(&preSubsetStruct,original,sizeof(psImage));
    277 
    278     subset2 = psImageSubset(original,c/4,r/4,c/4+c/2,r/4+r/2);
    279 
    280     subset3 = psImageSubset(original,0,0,c/2,r/2);
    281 
    282     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members nrow and ncol are equal to "
    283              "the input parameter nrow and ncol respectively.");
    284 
    285     if (subset2->numCols != c/2 || subset2->numRows != r/2) {
    286         psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
    287                 subset2->numCols, subset2->numRows, c/2,r/2);
    288         return 1;
    289     }
    290 
    291     if (subset3->numCols != c/2 || subset3->numRows != r/2) {
    292         psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
    293                 subset3->numCols, subset3->numRows, c/2,r/2);
    294         return 2;
    295     }
    296 
    297     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure contains expected values in the "
    298              "row member, if the input psImage structure image contains known values.");
    299 
    300     for (int row=0;row<r/2;row++) {
    301         for (int col=0;col<c/2;col++) {
    302             if (subset2->data.U32[row][col] != original->data.U32[row+r/4][col+c/4]) {
    303                 psError(__func__,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
    304                         row,col,subset2->data.U32[row][col], original->data.U32[row+r/4][col+c/4]);
    305                 return 3;
    306             }
    307             if (subset3->data.U32[row][col] != original->data.U32[row][col]) {
    308                 psError(__func__,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
    309                         row,col,subset2->data.U32[row][col], original->data.U32[row][col]);
    310                 return 4;
    311             }
    312         }
    313     }
    314 
    315     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member type is equal to the input "
    316              "psImage structure member type.");
    317 
    318     if (subset2->type.type != PS_TYPE_U32) {
    319         psError(__func__,"psImageSubset output type was not proper(%d, should be %d).",
    320                 subset2->type.type, PS_TYPE_U32);
    321         return 6;
    322     }
    323     if (subset3->type.type != PS_TYPE_U32) {
    324         psError(__func__,"psImageSubset output type was not proper(%d, should be %d).",
    325                 subset3->type.type, PS_TYPE_U32);
    326         return 7;
    327     }
    328 
    329     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members row0 and col0 are equal to "
    330              "the input parameters row0 and col0 respectively.");
    331 
    332     if (subset2->col0 != c/4 || subset2->row0 != r/4) {
    333         psError(__func__,"psImageSubset didn't set col0/row0 for subset2 (%d/%d, should be %d/%d).",
    334                 subset2->col0,subset2->row0,c/4,r/4);
    335         return 8;
    336     }
    337     if (subset3->col0 != 0 || subset3->row0 != 0) {
    338         psError(__func__,"psImageSubset didn't set col0/row0 for subset3 (%d/%d, should be %d/%d).",
    339                 subset3->col0,subset3->row0,0,0);
    340         return 9;
    341     }
    342 
    343     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member parent is equal to the "
    344              "input psImage structure pointer image.");
    345 
    346     if (subset2->parent != original || subset3->parent != original) {
    347         psError(__func__,"psImageSubset didn't set parent.");
    348         return 10;
    349     }
    350 
    351     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member children is null.");
    352 
    353     if (subset2->children != NULL || subset3->children != NULL) {
    354         psError(__func__,"psImageSubset didn't set children to NULL.");
    355         return 11;
    356     }
    357 
    358     psLogMsg(__func__,PS_LOG_INFO,"Verify the input psImage structure image only has the following members "
    359              "changed: 1) Nchildren is increased by one. 2) parent contains pointer psImage structure "
    360              "out at parent[Nchildren-1].");
    361 
    362     if (original->children == NULL || original->children->n != 2) {
    363         psError(__func__,"psImageSubset didn't increment number of children by one per subset.");
    364         return 12;
    365     }
    366     if (original->children->data[0] != subset2 || original->children->data[1] != subset3) {
    367         psError(__func__,"psImageSubset didn't properly store the children pointers.");
    368         return 13;
    369     }
    370 
    371     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
    372              "execution doesn't stop, if the input parameter image is null. Also verified the input "
    373              "psImage structure is not modified.");
    374 
    375     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    376     subset1 = psImageSubset(NULL,0,0,c/2,r/2);
    377     if (subset1 != NULL) {
    378         psError(__func__,"psImageSubset didn't return NULL when input image was NULL.");
    379         return 14;
    380     }
    381 
    382     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
    383              " execution doesn't stop, if the input parameters nrow and/or ncol are zero. Also verify "
    384              "input psImage structure is not modified.");
    385 
    386     memcpy(&preSubsetStruct,original,sizeof(psImage));
    387     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    388     subset1 = psImageSubset(original,0,r/2,c/2,r/2);
    389     if (subset1 != NULL) {
    390         psError(__func__,"psImageSubset didn't return NULL when numRows=0.");
    391         return 15;
    392     }
    393     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    394     subset1 = psImageSubset(original,c/2,0,c/2,r/2);
    395     if (subset1 != NULL) {
    396         psError(__func__,"psImageSubset didn't return NULL when numCols=0.");
    397         return 16;
    398     }
    399     if (memcmp(original,&preSubsetStruct,sizeof(psImage)) != 0) {
    400         psError(__func__,"psImageSubset changed the original struct though it failed to subset.");
    401         return 17;
    402     }
    403 
    404 
    405     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
    406              "execution doesn't stop, if the input parameters row0 and col0 are not within the range of "
    407              "values of psImage structure image.");
    408 
    409     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    410     subset1 = psImageSubset(original,0,0,c/2,r*2);
    411     if (subset1 != NULL) {
    412         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
    413                 "image (via cols).");
    414         return 18;
    415     }
    416     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    417     subset1 = psImageSubset(original,0,0,c*2,r/2);
    418     if (subset1 != NULL) {
    419         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
    420                 "image (via rows).");
    421         return 19;
    422     }
    423     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    424     subset1 = psImageSubset(original,-1,0,c/2,r/2);
    425     if (subset1 != NULL) {
    426         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
    427                 "image (col0=-1).");
    428         return 20;
    429     }
    430     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    431     subset1 = psImageSubset(original,0,-1,c/2,r/2);
    432     if (subset1 != NULL) {
    433         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
    434                 "image (row0=-1).");
    435         return 21;
    436     }
    437 
    438     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
    439              "execution doesn't stop if the input parameters nrow, ncol, row0 and col0 specify a range of "
    440              "data not within the input psImage structure image.  Also verify the input psImage structure "
    441              "is not modified.");
    442 
    443     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    444     subset1 = psImageSubset(original,0,0,c/2,r+1);
    445     if (subset1 != NULL) {
    446         psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via rows).");
    447         return 22;
    448     }
    449     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    450     subset1 = psImageSubset(original,0,0,c+1,r/2);
    451     if (subset1 != NULL) {
    452         psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via cols).");
    453         return 23;
    454     }
    455     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    456     subset1 = psImageSubset(original,0,0,c+1,r+1);
    457     if (subset1 != NULL) {
    458         psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via row+cols).");
    459         return 24;
    460     }
    461 
    462     psLogMsg(__func__, PS_LOG_INFO, "psImageFreeChildren shall deallocate any children images of a "
    463              "psImage structure");
    464 
    465     memcpy(&preSubsetStruct,original,sizeof(psImage));
    466 
    467     psImageFreeChildren(original);
    468 
    469     // Verify the returned psImage structure member Nchildren is set to zero.
    470     if (original->children != NULL && original->children->n > 0) {
    471         psError(__func__,"psImageFreeChildren didn't set number of children to zero.");
    472         return 25;
    473     }
    474 
    475     //Verify the returned psImage structure members type, nrow, ncol, row0, col0, rows and parent are not
    476     // modified.
    477     if (preSubsetStruct.numRows != original->numRows ||
    478             preSubsetStruct.numCols != original->numCols ||
    479             preSubsetStruct.row0 != original->row0 ||
    480             preSubsetStruct.col0 != original->col0) {
    481 
    482         psError(__func__,"psImageFreeChildren modified parent's non-children elements.");
    483         return 27;
    484     }
    485 
    486     psFree(original);
    487251
    488252    return 0;
Note: See TracChangeset for help on using the changeset viewer.