IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8597


Ignore:
Timestamp:
Aug 25, 2006, 11:42:29 AM (20 years ago)
Author:
drobbin
Message:

Finished all psArray testing. 100% code coverage!!!

File:
1 edited

Legend:

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

    r8591 r8597  
    2121int main(void)
    2222{
    23     plan_tests(15);
     23    plan_tests(25);
    2424
    2525    diag("Tests for psArray Functions");
     
    168168    diag("\n  >>>Test 3:  psArraySet & psArrayGet Fxns");
    169169    psArray *a = NULL;
    170 
    171     //Check for Memory leaks
    172     {
    173         psFree(a);
     170    psArray *b = NULL;
     171    psS32 *s1 = (psS32*)psAlloc(sizeof(psS32));
     172    *s1 = 2;
     173    psS32 *s2 = (psS32*)psAlloc(sizeof(psS32));
     174    *s2 = 1;
     175    psS32 *s3 = (psS32*)psAlloc(sizeof(psS32));
     176    *s3 = 3;
     177
     178    //Return false for trying to set a NULL psArray
     179    {
     180        ok( !psArraySet(a, 0, (psPtr)s1),
     181            "psArraySet:      return false for NULL input psArray.");
     182    }
     183    //Return false for trying to set an invalid position
     184    a = psArrayAlloc(1);
     185    {
     186        ok( !psArraySet(a, 2, (psPtr)s1),
     187            "psArraySet:      return false for invalid input position.");
     188    }
     189    //Return false for trying to set nalloc position
     190    psArraySet(a, 0, (psPtr)s1);
     191    {
     192        ok( !psArraySet(a, a->nalloc, (psPtr)s2),
     193            "psArraySet:      return false for out-of-range position.");
     194    }
     195    //Return false for an invalid position (-2 = out-of-range neg. index)
     196    {
     197        ok( !psArraySet(a, -2, (psPtr)s2),
     198            "psArraySet:      return false for out-of-range negative position.");
     199    }
     200    //Return true for set to a->n position (< nalloc)
     201    a = psArrayRealloc(a, 10);
     202    {
     203        ok( psArraySet(a, a->n, (psPtr)s2)  && a->n == 2,
     204            "psArraySet:      return true for valid input position.");
     205    }
     206    //Return true for a negative index input
     207    {
     208        ok( psArraySet(a, -2, (psPtr)s3) && a->n == 2 &&
     209            *((psS32*)(a->data[0])) == 3,
     210            "psArraySet:      return true for valid negative input position.");
     211    }
     212
     213    //Return NULL for NULL array input
     214    psS32 *s4 = NULL;
     215    {
     216        s4 = (psS32*)psArrayGet(b, 0);
     217        ok( s4 == NULL,
     218            "psArrayGet:      return NULL for NULL input psArray.");
     219    }
     220    //Return NULL for an out-of-range index
     221    {
     222        s4 = (psS32*)psArrayGet(a, a->n);
     223        ok( s4 == NULL,
     224            "psArrayGet:      return NULL for out-of-range position.");
     225    }
     226    //Return NULL for an out-of-range negative index
     227    {
     228        s4 = (psS32*)psArrayGet(a, -1-a->n);
     229        ok( s4 == NULL,
     230            "psArrayGet:      return NULL for out-of-range negative position.");
     231    }
     232    //Return valid case
     233    {
     234        s4 = (psS32*)psArrayGet(a, 1);
     235        ok( *s4 == 1,
     236            "psArrayGet:      return correct value for valid position.");
     237    }
     238
     239    //Check for Memory leaks
     240    {
     241        psFree(a);
     242        psFree(s1);
     243        psFree(s2);
     244        psFree(s3);
    174245        checkMem();
    175246    }
Note: See TracChangeset for help on using the changeset viewer.