IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2624


Ignore:
Timestamp:
Dec 3, 2004, 4:43:17 PM (22 years ago)
Author:
evanalst
Message:

Updated test cases for psHashRemove.

Location:
trunk/psLib/test/collections
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/collections/tst_psHash03.c

    r2392 r2624  
    2020ID;
    2121static void IdFree(ID *id);
    22 
    23 // NOTE: This is my own little routine I used in debugging a memory
    24 // leak.  I will take this out of this file later.
    25 void printMemBlocks(char *myString)
    26 {
    27     psMemBlock **memBlocks = NULL;
    28     psMemBlock *tmp = NULL;
    29     psS32 numBlocks = 0;
    30 
    31     numBlocks = psMemCheckLeaks(currentId, &memBlocks, NULL,false);
    32     printf("******************** %s ********************\n", myString);
    33     printf("%d mem blocks\n", psMemCheckLeaks(currentId,NULL,stderr,false));
    34     printf("%d blocks\n", numBlocks);
    35     printf("*  ");
    36     if (memBlocks != NULL) {
    37         for (tmp = *memBlocks; tmp != NULL; tmp = tmp->nextBlock) {
    38             printf("%d ", (psS32) tmp->id);
    39         }
    40     }
    41     printf("*\n");
    42     printf("*************************************************\n");
    43     psFree(memBlocks);
    44 }
    4522
    4623static ID *IdAlloc(const char *name)
     
    7956    currentId = psMemGetId();
    8057
    81     printPositiveTestHeader(stdout,
    82                             "psHash functions",
    83                             "psHashRemove()");
     58    printPositiveTestHeader(stdout,"psHash functions","psHashRemove");
    8459
     60    // Add items to hash table
    8561    myHashTable = psHashAlloc(NUM_HASH_TABLE_BUCKETS);
    86 
    8762    i = 0;
    8863    while (myKeys[i] != NULL) {
     
    9368    TotalKeys = i - 1;
    9469
     70    // Verify items which were just add to hash table
    9571    i = TotalKeys;
    9672    while (i >= 0) {
     
    10076            fprintf(stderr, "%s: Hash table entry for key %s was %s (should be %s).\n",
    10177                    __func__, myKeys[i], id->name, myData[i]);
     78            return 1;
    10279        }
    10380        i--;
    10481    }
    10582
     83    // Remove each item from the table and verify item is no longer in the list
    10684    i = 0;
    10785    while (myKeys[i] != NULL) {
     
    11189        if (!retVal) {
    11290            fprintf(stderr,"%s: Hash table entry not removed.\n",__func__);
     91            return 2;
    11392        }
    11493        id = psHashLookup(myHashTable, myKeys[i]);
     
    11695            fprintf(stderr, "%s: Hash table entry for key %s not removed.\n",
    11796                    __func__, "IDA");
     97            return 3;
    11898        }
    11999        i++;
    120100    }
     101    printFooter(stdout,"psHash functions","psHashRemove()",true);
    121102
    122     printFooter(stdout,
    123                 "psHash functions",
    124                 "psHashRemove()",
    125                 testStatus);
     103    // Use an invalid key in the hash table: verify false is returned
     104    printNegativeTestHeader(stdout,"psHashRemove","Invalid key","Key is not found in table",0);
     105    if (psHashRemove(myHashTable,"BogusKey") ) {
     106        psError(PS_ERR_UNKNOWN,true,"psHashRemove removed an entry with a bogus key.");
     107        return 4;
     108    }
     109    printFooter(stdout,"psHashRemove","Invalid key",true);
     110
     111    // Remove with null table
     112    printNegativeTestHeader(stdout,"psHashRemove","NULL table","Can not remove with NULL table",0);
     113    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message: psHashRemove with null table");
     114    retVal = psHashRemove(NULL,"ENTRY02");
     115    if (retVal) {
     116        psError(PS_ERR_UNKNOWN,true,"psHashRemove removed an entry from NULL hash table.");
     117        return 5;
     118    }
     119    printFooter(stdout,"psHashRemove","NULL table",true);
     120
     121    // Remove with null key
     122    printNegativeTestHeader(stdout,"psHashRemove","NULL key","Can not remove with NULL key",0);
     123    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message: psHashRemove with null key");
     124    if (psHashRemove(myHashTable,NULL) ) {
     125        psError(PS_ERR_UNKNOWN,true,"psHashRemove removed an entry from NULL key");
     126        return 6;
     127    }
     128    printFooter(stdout,"psHashRemove","NULL key",true);
    126129
    127130    psFree(myHashTable);
     
    130133    }
    131134    memLeaks = psMemCheckLeaks(currentId,NULL,stdout,false);
    132     if (0 != memLeaks) {
     135    if (memLeaks != 0) {
    133136        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    134137    }
  • trunk/psLib/test/collections/verified/tst_psHash03.stderr

    r1421 r2624  
     1<DATE><TIME>|<HOST>|I|main
     2    Following should generate an error message: psHashRemove with null table
     3<DATE><TIME>|<HOST>|E|psHashRemove (psHash.c:<LINENO>)
     4    Input psHash can not be NULL.
     5<DATE><TIME>|<HOST>|I|main
     6    Following should generate an error message: psHashRemove with null key
     7<DATE><TIME>|<HOST>|E|psHashRemove (psHash.c:<LINENO>)
     8    Input key can not be NULL.
  • trunk/psLib/test/collections/verified/tst_psHash03.stdout

    r1421 r2624  
    11/***************************** TESTPOINT ******************************************\
    22*             TestFile: tst_psHash03.c                                             *
    3 *            TestPoint: psHash functions{psHashRemove()}                           *
     3*            TestPoint: psHash functions{psHashRemove                           *
    44*             TestType: Positive                                                   *
    55\**********************************************************************************/
     
    88---> TESTPOINT PASSED (psHash functions{psHashRemove()} | tst_psHash03.c)
    99
     10/***************************** TESTPOINT ******************************************\
     11*             TestFile: tst_psHash03.c                                             *
     12*            TestPoint: psHashRemove{Invalid key}                                  *
     13*             TestType: Negative                                                   *
     14*    ExpectedErrorText: Key is not found in table                                  *
     15*  ExpectedStatusValue: 0                                                          *
     16\**********************************************************************************/
     17
     18
     19---> TESTPOINT PASSED (psHashRemove{Invalid key} | tst_psHash03.c)
     20
     21/***************************** TESTPOINT ******************************************\
     22*             TestFile: tst_psHash03.c                                             *
     23*            TestPoint: psHashRemove{NULL table}                                   *
     24*             TestType: Negative                                                   *
     25*    ExpectedErrorText: Can not remove with NULL table                             *
     26*  ExpectedStatusValue: 0                                                          *
     27\**********************************************************************************/
     28
     29
     30---> TESTPOINT PASSED (psHashRemove{NULL table} | tst_psHash03.c)
     31
     32/***************************** TESTPOINT ******************************************\
     33*             TestFile: tst_psHash03.c                                             *
     34*            TestPoint: psHashRemove{NULL key}                                     *
     35*             TestType: Negative                                                   *
     36*    ExpectedErrorText: Can not remove with NULL key                               *
     37*  ExpectedStatusValue: 0                                                          *
     38\**********************************************************************************/
     39
     40
     41---> TESTPOINT PASSED (psHashRemove{NULL key} | tst_psHash03.c)
     42
Note: See TracChangeset for help on using the changeset viewer.