IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 1, 2007, 6:14:33 PM (19 years ago)
Author:
gusciora
Message:

Added tabular file of all psLib functions in Chapter 6 of the SDRS (Data
Manipulation). Most of the test file changes in this check-in are fairly
cosmetic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/types/tap_psPixels_all.c

    r12781 r13123  
    2323    plan_tests(36);
    2424
    25     note("Tests for psPixels Functions");
    26 
     25    //Tests for psPixels Functions
    2726    testPixelsCreate();
    2827    testPixelsManip();
     
    3332void testPixelsCreate(void)
    3433{
    35     note("  >>>Test 1:  psPixels Creation Fxns");
    36 
     34    //Test 1:  psPixels Creation Fxns
    3735    //Return allocated psPixels of length 0 with NULL data.
    3836    psPixels* p0 = psPixelsAlloc(0);
     
    4947    //Make sure psMemCheckPixels works correctly - return true
    5048    {
    51         ok( psMemCheckPixels(p1),
     49        ok(psMemCheckPixels(p1),
    5250            "psMemCheckPixels:      return true for psPixels input.");
    5351    }
     
    5553    {
    5654        int j = 2;
    57         ok( !psMemCheckPixels(&j),
     55        ok(!psMemCheckPixels(&j),
    5856            "psMemCheckPixels:      return false for non-psPixels input.");
    5957    }
     
    6260        psPixels *noPix = psPixelsAlloc(1);
    6361        noPix = psPixelsRealloc(noPix, 0);
    64         ok( noPix->n == 0 && noPix->nalloc == 0,
     62        ok(noPix->n == 0 && noPix->nalloc == 0,
    6563            "psPixelsRealloc:       return re-allocated psPixels of 0 length.");
    6664        psFree(noPix);
     
    7573                     "Skipping 1 tests because psPixels input is of wrong size! =%ld", p0->n);
    7674        p0 = psPixelsRealloc(p0, 2);
    77         ok( p0->n == 2 && fabs(p0->data[0].x - 1.1) < FLT_EPSILON && p0->nalloc == 2,
     75        ok(p0->n == 2 && fabs(p0->data[0].x - 1.1) < FLT_EPSILON && p0->nalloc == 2,
    7876            "psPixelsRealloc:       return properly down-sized psPixels.");
    7977        skip_end();
     
    8381        psPixels *noPix = NULL;
    8482        noPix = psPixelsCopy(noPix, p0);
    85         ok( noPix->n == 2 && fabs(noPix->data[0].x - 1.1) < FLT_EPSILON && noPix->nalloc == 2,
     83        ok(noPix->n == 2 && fabs(noPix->data[0].x - 1.1) < FLT_EPSILON && noPix->nalloc == 2,
    8684            "psPixelsCopy:          return properly copied psPixels.");
    8785        psFree(noPix);
     
    9189        psPixels *noPix = NULL;
    9290        noPix = psPixelsCopy(noPix, NULL);
    93         ok( noPix == NULL,
     91        ok(noPix == NULL,
    9492            "psPixelsCopy:          return NULL for NULL psPixels input.");
    9593    }
     
    105103void testPixelsManip(void)
    106104{
    107     note("  >>>Test 2:  psPixels Manipulation Fxns");
    108 
     105    //psPixels Manipulation Fxns
    109106    //Tests for psPixelsSet
    110107    psPixels *p0 = psPixelsAlloc(1);
     
    114111    //Return false for NULL pixels input
    115112    {
    116         ok( !psPixelsSet(NULL, 0, in),
     113        ok(!psPixelsSet(NULL, 0, in),
    117114            "psPixelsSet:          return false for NULL pixels input.");
    118115    }
    119116    //Return true for valid inputs
    120117    {
    121         ok( psPixelsSet(p0, 0, in),
     118        ok(psPixelsSet(p0, 0, in),
    122119            "psPixelsSet:          return true for valid inputs.");
    123120    }
    124121    //Return false for position == nalloc
    125122    {
    126         ok( !psPixelsSet(p0, 1, in),
     123        ok(!psPixelsSet(p0, 1, in),
    127124            "psPixelsSet:          return false for position == nalloc.");
    128125    }
    129126    //Return false for out-of-range position
    130127    {
    131         ok( !psPixelsSet(p0, 2, in),
     128        ok(!psPixelsSet(p0, 2, in),
    132129            "psPixelsSet:          return false for out-of-range position.");
    133130    }
    134131    //Return false for negative out-of-range position
    135132    {
    136         ok( !psPixelsSet(p0, -2, in),
     133        ok(!psPixelsSet(p0, -2, in),
    137134            "psPixelsSet:          return false for negative out-of-range position.");
    138135    }
    139136    //Return true for valid negative position
    140137    {
    141         ok( psPixelsSet(p0, -1, in),
     138        ok(psPixelsSet(p0, -1, in),
    142139            "psPixelsSet:          return true for valid negative position.");
    143140    }
     
    148145    {
    149146        out = psPixelsGet(NULL, 1);
    150         ok( isnan(out.x) &&  isnan(out.y),
     147        ok(isnan(out.x) &&  isnan(out.y),
    151148            "psPixelsGet:          return NANs for NULL pixels input.");
    152149    }
     
    154151    {
    155152        out = psPixelsGet(p0, 2);
    156         ok( isnan(out.x) &&  isnan(out.y),
     153        ok(isnan(out.x) &&  isnan(out.y),
    157154            "psPixelsGet:          return NANs for out-of-range position.");
    158155    }
     
    160157    {
    161158        out = psPixelsGet(p0, -2);
    162         ok( isnan(out.x) &&  isnan(out.y),
     159        ok(isnan(out.x) &&  isnan(out.y),
    163160            "psPixelsGet:          return NANs for out-of-range negative position.");
    164161    }
     
    166163    {
    167164        out = psPixelsGet(p0, 0);
    168         ok( fabs(out.x - 1.1) < FLT_EPSILON &&  fabs(out.y - 1.2) < FLT_EPSILON,
     165        ok(fabs(out.x - 1.1) < FLT_EPSILON &&  fabs(out.y - 1.2) < FLT_EPSILON,
    169166            "psPixelsGet:          return correct values for valid inputs.");
    170167    }
     
    172169    {
    173170        out = psPixelsGet(p0, -1);
    174         ok( fabs(out.x - 1.1) < FLT_EPSILON &&  fabs(out.y - 1.2) < FLT_EPSILON,
     171        ok(fabs(out.x - 1.1) < FLT_EPSILON &&  fabs(out.y - 1.2) < FLT_EPSILON,
    175172            "psPixelsGet:          return correct values for valid negative position.");
    176173    }
     
    180177    {
    181178        FILE *newFD = fopen("psPixels.out", "w+");
    182         ok ( p_psPixelsPrint(newFD, p0, "PS-PIXELS"),
     179        ok(p_psPixelsPrint(newFD, p0, "PS-PIXELS"),
    183180             "p_psPixelsPrint:      return true for valid input.");
    184181        fflush(NULL);
     
    188185    {
    189186        FILE *dummy = fopen("psPixels.out", "r");
    190         ok ( !p_psPixelsPrint(dummy, p0, "failed test"),
     187        ok(!p_psPixelsPrint(dummy, p0, "failed test"),
    191188             "p_psPixelsPrint:      return false for invalid file input.");
    192189        fclose(dummy);
     
    196193    //Return false for NULL pixels and name inputs
    197194    {
    198         ok ( !p_psPixelsPrint(stdout, NULL, NULL),
     195        ok(!p_psPixelsPrint(stdout, NULL, NULL),
    199196             "p_psPixelsPrint:      return false for NULL pixels and name inputs.");
    200197    }
     
    202199    psPixels *p1 = psPixelsAlloc(0);
    203200    {
    204         ok ( p_psPixelsPrint(NULL, p1, "noPix"),
     201        ok(p_psPixelsPrint(NULL, p1, "noPix"),
    205202             "p_psPixelsPrint:      return true for NULL file and empty pixel data inputs.");
    206203    }
    207204
     205
     206    //----------------------------------------------------------------------
    208207    //psPixelsToMask Tests
    209208    psImage *outImage = NULL;
     
    214213    region.y1 = 5.0;
    215214    psMaskType maskVal = 1;
    216 
    217215    //Return NULL for NULL pixels input
    218216    {
     217        psMemId id = psMemGetId();
    219218        outImage = psPixelsToMask(outImage, NULL, region, maskVal);
    220         ok ( outImage == NULL,
    221              "psPixelsToMask:       return NULL for NULL pixels input.");
    222     }
     219        ok(outImage == NULL, "psPixelsToMask: return NULL for NULL pixels input.");
     220        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     221    }
     222
     223
    223224    //Return NULL for empty pixel data
    224225    {
     226        psMemId id = psMemGetId();
    225227        outImage = psPixelsToMask(outImage, p1, region, maskVal);
    226         ok ( outImage == NULL,
    227              "psPixelsToMask:       return NULL for NULL pixels data input.");
    228     }
     228        ok(outImage == NULL, "psPixelsToMask: return NULL for NULL pixels data input.");
     229        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     230    }
     231
     232
    229233    //Return NULL for bad region input - negative value
    230234    {
     235        psMemId id = psMemGetId();
    231236        outImage = psPixelsToMask(outImage, p0, region, maskVal);
    232         ok ( outImage == NULL,
    233              "psPixelsToMask:       return NULL for negative value in region.");
    234     }
     237        ok(outImage == NULL, "psPixelsToMask: return NULL for negative value in region.");
     238        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     239    }
     240
     241
    235242    //Return NULL for bad region input - upper bound less than lower bound
    236243    region.x0 = 3.0;
    237244    region.x1 = 1.0;
    238245    {
     246        psMemId id = psMemGetId();
    239247        outImage = psPixelsToMask(outImage, p0, region, maskVal);
    240         ok ( outImage == NULL,
    241              "psPixelsToMask:       return NULL for bad region input.");
    242     }
     248        ok(outImage == NULL, "psPixelsToMask: return NULL for bad region input.");
     249        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     250    }
     251
     252
     253    //Return NULL for un-recyclable image - out->type.dimen != PS_DIMEN_IMAGE
    243254    region.x0 = 1.0;
    244255    region.x1 = 3.0;
    245     //Return NULL for un-recyclable image - out->type.dimen != PS_DIMEN_IMAGE
    246256    outImage = psImageAlloc(1, 1, PS_TYPE_S32);
    247257    *(psDimen*)&(outImage->type.dimen) = PS_DIMEN_OTHER;
    248258    {
     259        psMemId id = psMemGetId();
    249260        outImage = psPixelsToMask(outImage, p0, region, maskVal);
    250         ok ( outImage == NULL,
    251              "psPixelsToMask:       return NULL for bad image input.");
    252     }
     261        ok(outImage == NULL, "psPixelsToMask: return NULL for bad image input.");
     262        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     263    }
     264
     265
    253266    //Return valid image for valid inputs
     267    //XXX: Musr check pixel values
    254268    p0 = psPixelsAdd(p0, 1, 2.1, 2.2);
    255269    p0 = psPixelsAdd(p0, 1, 3.1, 3.2);
    256270    p0 = psPixelsAdd(p0, 1, 1.0, 1.0);
    257271    {
     272        psMemId id = psMemGetId();
    258273        outImage = psPixelsToMask(outImage, p0, region, maskVal);
    259         ok ( outImage != NULL,
    260              "psPixelsToMask:       return valid image for valid input.");
    261     }
    262 
     274        ok(outImage != NULL, "psPixelsToMask: return valid image for valid input.");
     275        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     276    }
     277    psFree(outImage);
     278
     279
     280    //----------------------------------------------------------------------
    263281    //psPixelsFromMask Tests
    264     //Return valid psPixels for valid inputs
    265     psFree(outImage);
    266282    outImage = psImageAlloc(31, 99, PS_TYPE_MASK);
    267283    for (int i = 0; i < outImage->numCols; i++) {
     
    270286        }
    271287    }
    272 
    273     {
     288    //Return valid psPixels for valid inputs
     289    //XXX: We never check output psPixels
     290    {
     291        psMemId id = psMemGetId();
    274292        psPixels *outPixels = NULL;
    275293        outPixels = psPixelsFromMask(outPixels, outImage, maskVal);
    276         ok ( outPixels != NULL,
    277              "psPixelsFromMask:     return valid pixels for valid input.");
     294        ok(outPixels != NULL, "psPixelsFromMask: return valid pixels for valid input.");
    278295        psFree(outPixels);
    279     }
     296        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     297    }
     298
    280299
    281300    // Return NULL for NULL image input
    282301    {
     302        psMemId id = psMemGetId();
    283303        psPixels *outPixels = NULL;
    284304        outPixels = psPixelsFromMask(outPixels, NULL, maskVal);
    285         ok ( outPixels == NULL,
    286              "psPixelsFromMask:     return NULL for NULL image input.");
    287     }
     305        ok(outPixels == NULL, "psPixelsFromMask: return NULL for NULL image input.");
     306        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     307    }
     308
    288309
    289310    // Return NULL for image with wrong maskType
    290     *(psElemType*)&(outImage->type.type) = PS_TYPE_U32;
    291     {
     311    {
     312        *(psElemType*)&(outImage->type.type) = PS_TYPE_U32;
     313        psMemId id = psMemGetId();
    292314        psPixels *outPixels = NULL;
    293315        outPixels = psPixelsFromMask(outPixels, outImage, maskVal);
    294         ok ( outPixels == NULL,
    295              "psPixelsFromMask:     return NULL for image with wrong maskType.");
    296     }
    297 
     316        ok(outPixels == NULL, "psPixelsFromMask: return NULL for image with wrong maskType.");
     317        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     318        *(psElemType*)&(outImage->type.type) = PS_TYPE_U8;
     319    }
     320
     321
     322
     323    //----------------------------------------------------------------------
    298324    // psPixelsConcatenate Tests
    299325    // Return NULL for NULL pixels input
    300326    {
     327        psMemId id = psMemGetId();
    301328        psPixels *outPixels = NULL;
    302329        outPixels = psPixelsConcatenate(outPixels, NULL);
    303         ok ( outPixels == NULL,
    304              "psPixelsConcatenate:  return NULL for NULL pixels input.");
     330        ok(outPixels == NULL, "psPixelsConcatenate: return NULL for NULL pixels input.");
     331        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
    305332    }
    306333
     
    308335    //Return copy of input pixels for NULL out pixels
    309336    {
     337        psMemId id = psMemGetId();
    310338        psPixels *outPixels = NULL;
    311339        outPixels = psPixelsFromMask(outPixels, outImage, maskVal);
    312340        outPixels = psPixelsConcatenate(outPixels, p0);
    313         ok ( outPixels->n == 4 && fabs(outPixels->data[0].x - 1.1) < FLT_EPSILON &&
     341        ok(outPixels->n == 4 && fabs(outPixels->data[0].x - 1.1) < FLT_EPSILON &&
    314342             fabs(outPixels->data[0].y - 1.2) < FLT_EPSILON ,
    315343             "psPixelsConcatenate:  return copy of input pixels for NULL out input.");
    316344        psFree(outPixels);
    317     }
    318 
     345        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     346    }
     347
     348
     349    //test psPixelsConcatenate()
    319350    //Return properly concatenated psPixels list
    320     //Set all the compare cases to cover 'comparePixelCoord' as well.
    321     psPixels *outPixels = psPixelsAlloc(5);
    322     in.x = 1.0;
    323     in.y = 1.0;
    324     psPixelsSet(outPixels, 0, in);  //1, 1
    325     psPixelsSet(outPixels, 1, in);  //1, 1
    326     in.y = 2.0;
    327     psPixelsSet(outPixels, 2, in);  //1, 2
    328     in.y = 1.0;
    329     psPixelsSet(outPixels, 3, in);  //1, 1
    330     in.x = 2.0;
    331     psPixelsSet(outPixels, 4, in);  //2, 1
    332 
    333     psPixels *testPixels = psPixelsAlloc(6);
    334     in.x = 1.0;
    335     in.y = 1.0;
    336     psPixelsSet(testPixels, 0, in);  //1, 1
    337     in.y = 2.0;
    338     psPixelsSet(testPixels, 1, in);  //1, 2
    339     in.y = 1.0;
    340     psPixelsSet(testPixels, 2, in);  //1, 1
    341     in.x = 2.0;
    342     psPixelsSet(testPixels, 3, in);  //2, 1
    343     in.x = 1.0;
    344     psPixelsSet(testPixels, 4, in);  //1, 1
    345     in.x = 5.0;
    346     in.y = 3.0;
    347     psPixelsSet(testPixels, 5, in);  //5, 3
    348     //Return properly concatenate pixel list
    349     {
     351    {
     352        psMemId id = psMemGetId();
     353        psPixels *outPixels = psPixelsAlloc(5);
     354        in.x = 1.0;
     355        in.y = 1.0;
     356        psPixelsSet(outPixels, 0, in);  //1, 1
     357        psPixelsSet(outPixels, 1, in);  //1, 1
     358        in.y = 2.0;
     359        psPixelsSet(outPixels, 2, in);  //1, 2
     360        in.y = 1.0;
     361        psPixelsSet(outPixels, 3, in);  //1, 1
     362        in.x = 2.0;
     363        psPixelsSet(outPixels, 4, in);  //2, 1
     364        psPixels *testPixels = psPixelsAlloc(6);
     365        in.x = 1.0;
     366        in.y = 1.0;
     367        psPixelsSet(testPixels, 0, in);  //1, 1
     368        in.y = 2.0;
     369        psPixelsSet(testPixels, 1, in);  //1, 2
     370        in.y = 1.0;
     371        psPixelsSet(testPixels, 2, in);  //1, 1
     372        in.x = 2.0;
     373        psPixelsSet(testPixels, 3, in);  //2, 1
     374        in.x = 1.0;
     375        psPixelsSet(testPixels, 4, in);  //1, 1
     376        in.x = 5.0;
     377        in.y = 3.0;
     378        psPixelsSet(testPixels, 5, in);  //5, 3
    350379        outPixels = psPixelsConcatenate(outPixels, testPixels);
    351         ok ( outPixels->n == 6,
    352              "psPixelsConcatenate:  return properly concatenate pixel list for valid inputs.");
    353     }
    354 
    355 
    356     //Check for Memory leaks
    357     {
     380        ok(outPixels->n == 6, "psPixelsConcatenate:  return properly concatenate pixel list for valid inputs.");
    358381        psFree(testPixels);
    359382        psFree(outPixels);
     383        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     384    }
     385
     386
     387    //Check for Memory leaks
     388    //XXX: Remove this, add memory checks to individual blocks
     389    {
    360390        psFree(outImage);
    361391        psFree(p1);
Note: See TracChangeset for help on using the changeset viewer.