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_psImagePixelManip.c

    r13123 r13614  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-05-02 04:14:33 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-06-04 20:25:32 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1818#define VERBOSE false
    1919
     20void genericImageClipTest(int numRows, int numCols) {
     21    psMemId id = psMemGetId();
     22
     23    psImage *image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     24    for (int row = 0 ; row < numRows ; row++) {
     25        for (int col = 0 ; col < numCols ; col++) {
     26            image->data.F32[row][col] = (float) (row + col);
     27        }
     28    }
     29    psF32 min = (psF64)numRows/2.0;
     30    psF32 max = (psF64)numRows;
     31
     32    psS32 retVal = psImageClip(image, min, (double)PS_MIN_F32, max, (double)PS_MAX_F32);
     33    int numClipped = 0;
     34    bool errorFlag = false;
     35    for (int row=0;row<numRows;row++) {
     36        for (int col=0;col<numCols;col++) {
     37            psF32 value = (psF32)(row+col);
     38            if (value < min) {
     39                numClipped++;
     40                value = PS_MIN_F32;
     41            } else if (value > max) {
     42                numClipped++;
     43                value = PS_MAX_F32;
     44            }
     45            if (fabsf(image->data.F32[row][col]-value) > FLT_EPSILON) {
     46                diag("Pixel value is not as expected (%g vs %g) at %u,%u",
     47                     (psF64)image->data.F32[row][col], (psF64)value, col, row);
     48                errorFlag = true;
     49            }
     50        }
     51    }
     52    ok(!errorFlag, "psImageClip() produced the correct data values");
     53    ok(retVal == numClipped, "Got the expected number of clips");
     54    psFree(image);
     55
     56    ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     57}
     58
     59
    2060psS32 main(psS32 argc, char* argv[])
    2161{
    2262    psLogSetFormat("HLNM");
    2363    psLogSetLevel(PS_LOG_INFO);
    24     plan_tests(107);
     64    plan_tests(122);
    2565
    2666    // test psImageClip()
     
    4989        // and program executions doesn't stop, if input parameter min is larger than max.
    5090        // create image
     91
     92        genericImageClipTest(8, 1);
     93        genericImageClipTest(1, 8);
     94        genericImageClipTest(8, 8);
     95        genericImageClipTest(8, 16);
     96        genericImageClipTest(16, 8);
     97
    5198        #define testImageClipByType(datatype) \
    5299        { \
Note: See TracChangeset for help on using the changeset viewer.