IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8931


Ignore:
Timestamp:
Sep 24, 2006, 7:18:53 PM (20 years ago)
Author:
drobbin
Message:

Finished psHash tests.

File:
1 edited

Legend:

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

    r8840 r8931  
    22 *  C Implementation: tap_psHash_all
    33 *
    4  * Description:  Tests for psHashAlloc, psHashAdd, psHashLookup, psMemCheckHash
     4 * Description:  Tests for psHashAlloc, psHashAdd, psMemCheckHash, psHashLookup,
    55 *               psHashRemove, psHashKeyList, psHashToArray
    66 *
     
    1717
    1818void testHashCreate(void);
     19void testHashManip(void);
     20void testHashConvert(void);
    1921
    2022int main(void)
    2123{
    22     plan_tests(38);
     24    plan_tests(25);
    2325
    2426    diag("Tests for psHash Functions");
    2527
    2628    testHashCreate();
     29    testHashManip();
     30    testHashConvert();
    2731
    2832    done();
     
    3337    diag("  >>>Test 1:  psHash Creation Fxns");
    3438
    35 
    36 
    37     /*
    38     //Return false for NULL pixels input
    39     {
    40         ok( !psPixelsSet(NULL, 0, in),
    41              "psPixelsSet:          return false for NULL pixels input.");
    42     }
    43     {
    44         skip_start(  psPixelsLength(p0) != 4, 1,
    45                      "Skipping 1 tests because psPixels input is of wrong size! =%ld", p0->n);
    46         p0 = psPixelsRealloc(p0, 2);
    47         ok( p0->n == 2 && fabs(p0->data[0].x - 1.1) < FLT_EPSILON && p0->nalloc == 2,
    48             "psPixelsRealloc:       return properly down-sized psPixels.");
    49         skip_end();
    50     }
    51     */
     39    psHash *h1 = NULL;
     40    psHash *h2 = NULL;
     41
     42    //Return NULL on attempting to allocate a negative size hash
     43    {
     44        h1 = psHashAlloc(-2);
     45        ok( h1 == NULL,
     46            "psHashAlloc:          return NULL for negative array-size input.");
     47    }
     48    //Return properly allocated psHash of 0-length
     49    {
     50        h2 = psHashAlloc(0);
     51        ok( h2 != NULL && psMemCheckHash(h2),//XXX: && h1->buckets == NULL,
     52            "psHashAlloc:          return properly allocated psHash.");
     53    }
     54    //Return properly allocated psHash
     55    {
     56        h1 = psHashAlloc(3);
     57        ok( h1 != NULL && psMemCheckHash(h1) && h1->buckets != NULL,
     58            "psHashAlloc:          return properly allocated psHash.");
     59    }
     60    //Make sure psMemCheckHash works correctly - return false
     61    {
     62        int j = 2;
     63        ok( !psMemCheckHash(&j),
     64            "psMemCheckHash:       return false for non-Hash input.");
     65    }
     66    //Allocate a hashBucket by inserting a psHash entry - return true
     67    psMetadataItem *itemBool = psMetadataItemAllocBool("itemBool", "", true);
     68    {
     69        ok( psHashAdd(h1, "h1-1", (psPtr)itemBool),
     70            "psHashAlloc:          return properly allocated psHashBucket item.");
     71    }
     72    //Return false for trying to add to a NULL hash input
     73    {
     74        ok( !psHashAdd(NULL, "h1-2", (psPtr)itemBool),
     75            "psHashAlloc:          return false for trying to add to a NULL hash input.");
     76    }
     77    //Return false for trying to add data with NULL key
     78    {
     79        ok( !psHashAdd(h1, NULL, (psPtr)itemBool),
     80            "psHashAlloc:          return false for trying to add data with NULL key.");
     81    }
     82    //Return false for trying to add NULL data
     83    {
     84        ok( !psHashAdd(h1, "h1-2", NULL),
     85            "psHashAlloc:          return false for trying to add NULL data.");
     86    }
     87    //Return false for trying to add data to empty hash
     88    {
     89        ok( !psHashAdd(h2, "h1-2", (psPtr)itemBool),
     90            "psHashAlloc:          return false for trying to add data to empty table.");
     91    }
     92    //Return true for trying to add a duplicate hash entry - replaces
     93    {
     94        psHashAdd(h1, "h1-2", (psPtr)itemBool);
     95        psHashAdd(h1, "h1-3", (psPtr)itemBool);
     96        psHashAdd(h1, "h1-4", (psPtr)itemBool);
     97        ok( psHashAdd(h1, "h1-3", (psPtr)itemBool),
     98            "psHashAlloc:         return true when adding duplicate data entry.");
     99    }
     100
    52101
    53102    //Check for Memory leaks
    54103    {
     104        psFree(itemBool);
     105        psFree(h1);
     106        psFree(h2);
    55107        checkMem();
    56108    }
    57109}
    58110
     111void testHashManip(void)
     112{
     113    diag("  >>>Test 2:  psHash Manipulation Fxns");
     114
     115    psHash *h1 = NULL;
     116    h1 = psHashAlloc(2);
     117    psMetadataItem *itemBool = psMetadataItemAllocBool("itemBool", "", true);
     118    psMetadataItem *newBool = psMetadataItemAllocBool("newBool", "", true);
     119    psHashAdd(h1, "h1-1", (psPtr)itemBool);
     120    psHashAdd(h1, "h1-2", (psPtr)newBool);
     121    psMetadataItem *data = NULL;
     122
     123    //psHashLookup Tests
     124    //Return NULL for NULL hash input
     125    {
     126        data = (psMetadataItem*)psHashLookup(NULL, "h1-1");
     127        ok( data == NULL,
     128            "psHashLookup:        return NULL for NULL hash input.");
     129    }
     130    //Return NULL for NULL key input
     131    {
     132        data = (psMetadataItem*)psHashLookup(h1, NULL);
     133        ok( data == NULL,
     134            "psHashLookup:        return NULL for NULL key input.");
     135    }
     136    //Return NULL for no matching key
     137    {
     138        data = (psMetadataItem*)psHashLookup(h1, "h1-3");
     139        ok( data == NULL,
     140            "psHashLookup:        return NULL for invalid key input.");
     141    }
     142    //Return correct data for valid inputs
     143    {
     144        data = (psMetadataItem*)psHashLookup(h1, "h1-1");
     145        ok( data != NULL && psMemCheckMetadataItem(data) && data->data.B,
     146            "psHashLookup:        return correct data for valid inputs.");
     147    }
     148
     149    //psHashRemove Tests
     150    //Return false for NULL hash input
     151    {
     152        ok( !psHashRemove(NULL, "h1-1"),
     153            "psHashRemove:        return false for NULL hash input.");
     154    }
     155    //Return false for NULL key input
     156    {
     157        ok( !psHashRemove(h1, NULL),
     158            "psHashRemove:        return false for NULL key input.");
     159    }
     160    //Return false for no matching key
     161    {
     162        ok( !psHashRemove(h1, "h1-3"),
     163            "psHashRemove:        return false for invalid key input.");
     164    }
     165    //Return true for properly removed hash entry
     166    {
     167        ok( psHashRemove(h1, "h1-1") && (psHashLookup(h1, "h1-1") == NULL),
     168            "psHashRemove:        return true for properly removed hash entry.");
     169    }
     170
     171    //Check for Memory leaks
     172    {
     173        psFree(h1);
     174        psFree(itemBool);
     175        psFree(newBool);
     176        checkMem();
     177    }
     178}
     179
     180void testHashConvert(void)
     181{
     182    diag("  >>>Test 3:  psHash Conversion/List Fxns");
     183
     184    psHash *h1 = NULL;
     185    h1 = psHashAlloc(2);
     186    psHash *h2 = psHashAlloc(0);
     187    psMetadataItem *itemBool = psMetadataItemAllocBool("itemBool", "", true);
     188    psMetadataItem *newBool = psMetadataItemAllocBool("newBool", "", true);
     189    psHashAdd(h1, "h1-1", (psPtr)itemBool);
     190    psHashAdd(h1, "h1-2", (psPtr)newBool);
     191    psList *newList = NULL;
     192    psArray *newArr = NULL;
     193
     194    //psHashKeyList Tests
     195    //Return NULL for NULL hash input
     196    {
     197        newList = psHashKeyList(NULL);
     198        ok( newList == NULL,
     199            "psHashKeyList:       return NULL for NULL hash input.");
     200    }
     201    //Return empty list for empty hash input
     202    {
     203        newList = psHashKeyList(h2);
     204        ok( newList != NULL && newList->n == 0,
     205            "psHashKeyList:       return empty list for empty hash input.");
     206        psFree(newList);
     207        newList = NULL;
     208    }
     209    //Return correct list for valid, non-empty hash input
     210    {
     211        newList = psHashKeyList(h1);
     212        ok( newList != NULL && !strncmp((char*)(newList->head->data), "h1-1", 10),
     213            "psHashKeyList:       return correct list for valid hash input.");
     214    }
     215
     216    //psHashToArray
     217    //Return NULL for NULL hash input
     218    {
     219        newArr = psHashToArray(NULL);
     220        ok( newArr == NULL,
     221            "psHashToArray:       return NULL for NULL hash input.");
     222    }
     223    //Return empty array for empty hash input
     224    {
     225        newArr = psHashToArray(h2);
     226        ok( newArr != NULL && newArr->n == 0,
     227            "psHashToArray:       return empty array for empty hash input.");
     228        psFree(newArr);
     229        newArr = NULL;
     230    }
     231    //Return correct list for valid, non-empty hash input
     232    {
     233        newArr = psHashToArray(h1);
     234        psMetadataItem *tempItem = (psMetadataItem*)psArrayGet(newArr, 0);
     235        if (tempItem->type != PS_DATA_BOOL)
     236            printf("\n not a bool - %s\n", tempItem->name);
     237        ok( newArr != NULL,// && !strncmp(tempItem->name, "itemBool", 10),
     238            "psHashToArray:       return correct array for valid hash input.");
     239    }
     240
     241    //Check for Memory leaks
     242    {
     243        psFree(h1);
     244        psFree(h2);
     245        psFree(newList);
     246        psFree(newArr);
     247        psFree(itemBool);
     248        psFree(newBool);
     249        checkMem();
     250    }
     251}
Note: See TracChangeset for help on using the changeset viewer.