IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 4, 2007, 10:25:32 AM (19 years ago)
Author:
gusciora
Message:

Improved test coverage.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/imageops/tap_psImageStructManip.c

    r13123 r13614  
    55*  @author Robert DeSonia, MHPCC
    66*
    7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    8 *  @date $Date: 2007-05-02 04:14:33 $
     7*  psLib functions tested:
     8*     psImageSubset()
     9*     psImageCopy()
     10*     psImageTrim()
     11*
     12*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2007-06-04 20:25:32 $
    914*
    1015*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1621#include "pstap.h"
    1722
    18 psS32 main( psS32 argc, char* argv[] )
     23
     24void genericImageSubsetTest(int numRows, int numCols)
    1925{
    20     psLogSetFormat("HLNM");
    21     psLogSetLevel(PS_LOG_INFO);
    22     plan_tests(185);
    23 
    24 
    2526    // psImageSubset shall create child image of a specified size from a
    2627    // parent psImage structure
     
    2930        psMemId id = psMemGetId();
    3031        psImage preSubsetStruct;
    31         psS32 c = 128;
    32         psS32 r = 256;
    33         psRegion region1 = psRegionSet(0, c/2, 0, r/2);
    34         psRegion region2 = psRegionSet(c/4, c/4+c/2, r/4, r/4+r/2);
    35 
    36         psImage* original = psImageAlloc(c,r,PS_TYPE_U32);
    37         for (psS32 row=0;row<r;row++) {
    38             for (psS32 col=0;col<c;col++) {
     32        psRegion region1 = psRegionSet(0, numCols/2, 0, numRows/2);
     33        psRegion region2 = psRegionSet(numCols/4, numCols/4+numCols/2, numRows/4, numRows/4+numRows/2);
     34
     35        psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32);
     36        for (psS32 row=0;row<numRows;row++) {
     37            for (psS32 col=0;col<numCols;col++) {
    3938                original->data.F32[row][col] = row*1000+col;
    4039            }
    4140        }
    4241
    43         memcpy(&preSubsetStruct,original,sizeof(psImage));
    44         psImage* subset2 = psImageSubset(original,region2);
     42        memcpy(&preSubsetStruct, original, sizeof(psImage));
     43        psImage* subset2 = psImageSubset(original, region2);
    4544        ok(subset2, "psImageSubset() returned non-NULL (subset2)");
    4645        skip_start(subset2 == NULL, 25, "Skipping tests because psImageSubset() returned NULL");
    47         psImage* subset3 = psImageSubset(original,region1);
     46        psImage* subset3 = psImageSubset(original, region1);
    4847        ok(subset3, "psImageSubset() returned non-NULL (subset3)");
    4948        skip_start(subset3 == NULL, 24, "Skipping tests because psImageSubset() returned NULL");
     
    5150        // Verify the returned psImage structure members nrow and ncol are equal to
    5251        // the input parameter nrow and ncol respectively
    53         ok(subset2->numCols == c/2 && subset2->numRows == r/2,
     52        ok(subset2->numCols == numCols/2 && subset2->numRows == numRows/2,
    5453           "psImageSubset output size set properly");
    55         ok(subset3->numCols == c/2 && subset3->numRows == r/2,
     54        ok(subset3->numCols == numCols/2 && subset3->numRows == numRows/2,
    5655           "psImageSubset output size set properly");
    5756
    5857        // Verify the returned psImage structure contains expected values in the
    5958        // row member, if the input psImage structure image contains known values
    60 
    6159        bool errorFlag = false;
    62         for (psS32 row=0;row<r/2;row++) {
    63             for (psS32 col=0;col<c/2;col++) {
    64                 if (subset2->data.U32[row][col] != original->data.U32[row+r/4][col+c/4]) {
     60        for (psS32 row=0;row<numRows/2;row++) {
     61            for (psS32 col=0;col<numCols/2;col++) {
     62                if (subset2->data.U32[row][col] != original->data.U32[row+numRows/4][col+numCols/4]) {
    6563                    diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
    66                          row,col,subset2->data.U32[row][col], original->data.U32[row+r/4][col+c/4]);
     64                         row,col,subset2->data.U32[row][col], original->data.U32[row+numRows/4][col+numCols/4]);
    6765                    errorFlag = true;
    6866                }
     
    8381        // Verify the returned psImage structure members row0 and col0 are equal to
    8482        // the input parameters row0 and col0 respectively
    85         ok(subset2->col0 == c/4 && subset2->row0 == r/4,
     83        ok(subset2->col0 == numCols/4 && subset2->row0 == numRows/4,
    8684           "psImageSubset() set col0/row0 correctly (subset2)");
    8785        ok(subset3->col0 == 0 && subset3->row0 == 0,
     
    10199        ok(original->children->data[0] == subset2 && original->children->data[1] == subset3,
    102100           "psImageSubset did properly store the children pointers.");
    103 
    104101
    105102        // Verify the returned psImage structure pointer is null and program
     
    111108        ok(subset1 == NULL, "psImageSubset returned NULL when input image was NULL.");
    112109
    113 
    114110        // Verify the returned psImage structure pointer is null and program
    115111        // execution doesn't stop, if the input parameters nrow and/or ncol are zero.
     
    117113        // An error should follow...
    118114        // XXX: Verify error
    119         memcpy(&preSubsetStruct,original,sizeof(psImage));
    120         subset1 = psImageSubset(original, psRegionSet(0,c/2,r/2,r/2));
    121         ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0.");
    122         // An error should follow...
    123         // XXX: Verify error
    124         subset1 = psImageSubset(original,psRegionSet(c/2,c/2,0,r/2));
    125         ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0.");
    126         ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0,
    127            "psImageSubset didn't change the original struct though it failed to subset.");
     115        {
     116            memcpy(&preSubsetStruct,original,sizeof(psImage));
     117            subset1 = psImageSubset(original, psRegionSet(0,numCols/2,numRows/2,numRows/2));
     118            ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0.");
     119            // An error should follow...
     120            // XXX: Verify error
     121            subset1 = psImageSubset(original,psRegionSet(numCols/2,numCols/2,0,numRows/2));
     122            ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0.");
     123            ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0,
     124               "psImageSubset didn't change the original struct though it failed to subset.");
     125        }
    128126
    129127        // Verify the returned psImage structure pointer is null and program
     
    132130        // An error should follow...
    133131        // XXX: Verify error
    134         subset1 = psImageSubset(original, psRegionSet(0,c/2, 0,r*2));
    135         ok(subset1 == NULL,
    136            "psImageSubset returned NULL when subset origin was outside of image (via cols)");
    137         // An error should follow...
    138         // XXX: Verify error
    139         subset1 = psImageSubset(original,psRegionSet(0,c*2,0,r/2));
    140         ok(subset1 == NULL,
    141            "psImageSubset returned NULL when subset origin was outside of image (via rows)");
    142         // An error should follow...
    143         // XXX: Verify error
    144         subset1 = psImageSubset(original, psRegionSet(-1,c/2,0,r/2));
    145         ok(subset1 == NULL,
    146            "psImageSubset returned NULL when subset origin was outside of image (col0=-1)");
    147         // An error should follow...
    148         // XXX: Verify error
    149         subset1 = psImageSubset(original, psRegionSet(0,c/2,-1,r/2));
    150         ok(subset1 == NULL,
    151            "psImageSubset returned NULL when subset origin was outside of image (row0=-1)");
    152 
     132        {
     133            subset1 = psImageSubset(original, psRegionSet(0,numCols/2, 0,numRows*2));
     134            ok(subset1 == NULL,
     135               "psImageSubset returned NULL when subset origin was outside of image (via cols)");
     136            // An error should follow...
     137            // XXX: Verify error
     138            subset1 = psImageSubset(original,psRegionSet(0,numCols*2,0,numRows/2));
     139            ok(subset1 == NULL,
     140               "psImageSubset returned NULL when subset origin was outside of image (via rows)");
     141            // An error should follow...
     142            // XXX: Verify error
     143            subset1 = psImageSubset(original, psRegionSet(-1,numCols/2,0,numRows/2));
     144            ok(subset1 == NULL,
     145               "psImageSubset returned NULL when subset origin was outside of image (col0=-1)");
     146            // An error should follow...
     147            // XXX: Verify error
     148            subset1 = psImageSubset(original, psRegionSet(0,numCols/2,-1,numRows/2));
     149            ok(subset1 == NULL,
     150               "psImageSubset returned NULL when subset origin was outside of image (row0=-1)");
     151        }   
    153152
    154153        // Verify the returned psImage structure pointer is null and program
     
    158157        // An error should follow...
    159158        // XXX: Verify error
    160         subset1 = psImageSubset(original,psRegionSet(0,c/2,0,r+1));
    161         ok(subset1 == NULL,
    162            "psImageSubset returned NULL when subset was outside of image (via rows)");
    163         // An error should follow...
    164         // XXX: Verify error
    165         subset1 = psImageSubset(original, psRegionSet(0,c+1,0,r/2));
    166         ok(subset1 == NULL,
    167            "psImageSubset returned NULL when subset was outside of image (via cols)");
    168         // An error should follow...
    169         // XXX: Verify error
    170         subset1 = psImageSubset(original,psRegionSet(0,c+1,0,r+1));
    171         ok(subset1 == NULL,
    172            "psImageSubset returned NULL when subset was outside of image (via row+cols)");
    173 
     159        {
     160            subset1 = psImageSubset(original,psRegionSet(0,numCols/2,0,numRows+1));
     161            ok(subset1 == NULL,
     162               "psImageSubset returned NULL when subset was outside of image (via rows)");
     163            // An error should follow...
     164            // XXX: Verify error
     165            subset1 = psImageSubset(original, psRegionSet(0,numCols+1,0,numRows/2));
     166            ok(subset1 == NULL,
     167               "psImageSubset returned NULL when subset was outside of image (via cols)");
     168            // An error should follow...
     169            // XXX: Verify error
     170            subset1 = psImageSubset(original,psRegionSet(0,numCols+1,0,numRows+1));
     171            ok(subset1 == NULL,
     172               "psImageSubset returned NULL when subset was outside of image (via row+cols)");
     173        }
    174174
    175175        // psImageFreeChildren shall deallocate any children images of a
     
    196196        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    197197    }
     198}
     199
     200psS32 main(psS32 argc, char* argv[])
     201{
     202    psLogSetFormat("HLNM");
     203    psLogSetLevel(PS_LOG_INFO);
     204    plan_tests(239);
     205
     206    genericImageSubsetTest(128, 256);
     207    genericImageSubsetTest(256, 128);
     208    genericImageSubsetTest(128, 128);
    198209
    199210    // psImageCopy()
Note: See TracChangeset for help on using the changeset viewer.