IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2620


Ignore:
Timestamp:
Dec 3, 2004, 2:02:57 PM (22 years ago)
Author:
evanalst
Message:

Add additional test cases to cover invalid arguments for psHashAdd and
to test the replacement function.

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

Legend:

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

    r2392 r2620  
    33 *****************************************************************************/
    44#include <stdio.h>
     5#include <string.h>
    56#include "pslib.h"
    67#include "psTest.h"
     
    3839    psS32 currentId = psMemGetId();
    3940    ID* id = NULL;
     41    ID* replaceId = NULL;
    4042    psS32 memLeaks        = 0;
     43    psBool  retVal = false;
    4144
    42     printPositiveTestHeader(stdout,
    43                             "psHash functions",
    44                             "psHashFree()");
     45    // Allocate memory for Hash Table
     46    printPositiveTestHeader(stdout,"psHash functions","psHashAlloc");
     47    myHashTable = psHashAlloc(NUM_HASH_TABLE_BUCKETS);
     48    if(myHashTable == NULL) {
     49        psError(PS_ERR_UNKNOWN,true,"Unable to allocate psHash table");
     50        return 10;
     51    }
     52    printFooter(stdout,"psHash functions","psHashAlloc",true);
    4553
    46     myHashTable = psHashAlloc(NUM_HASH_TABLE_BUCKETS);
     54    // Add items to Hash table
    4755    id = IdAlloc("IDA");
    48     psHashAdd(myHashTable, "ENTRY00", id);
     56    printPositiveTestHeader(stdout,"psHash functions","psHashAdd");
     57    retVal = psHashAdd(myHashTable, "ENTRY00", id);
    4958    psFree(id);
     59    if( !retVal) {
     60        psError(PS_ERR_UNKNOWN, true, "psHashAdd unable to add ENTRY00");
     61        return 1;
     62    }
     63
    5064    id = IdAlloc("IDB");
    51     psHashAdd(myHashTable, "ENTRY01", id);
     65    retVal = psHashAdd(myHashTable, "ENTRY01", id);
    5266    psFree(id);
     67    if (!retVal) {
     68        psError(PS_ERR_UNKNOWN, true, "psHashAdd unable to add ENTRY01");
     69        return 2;
     70    }
     71
    5372    id = IdAlloc("IDC");
    54     psHashAdd(myHashTable, "ENTRY02", id);
     73    retVal = psHashAdd(myHashTable, "ENTRY02", id);
    5574    psFree(id);
     75    if(!retVal) {
     76        psError(PS_ERR_UNKNOWN,true,"psHashAdd unable to add ENTRY02");
     77        return 3;
     78    }
     79
    5680    id = IdAlloc("IDD");
    57     psHashAdd(myHashTable, "ENTRY03", id);
     81    retVal =psHashAdd(myHashTable, "ENTRY03", id);
    5882    psFree(id);
     83    if(!retVal) {
     84        psError(PS_ERR_UNKNOWN,true,"psHashAdd unable to add ENTRY03");
     85        return 4;
     86    }
     87    printFooter(stdout,"psHash functions","psHashAdd",true);
     88
     89    // Replace item with same key
     90    printPositiveTestHeader(stdout,"psHash replace item","psHashAdd");
     91    id = IdAlloc("IDE");
     92    retVal = psHashAdd(myHashTable,"ENTRY02",id);
     93    if(!retVal) {
     94        psError(PS_ERR_UNKNOWN,true,"psHashAdd unable to replace ENTRY02");
     95        return 5;
     96    }
     97    replaceId = psHashLookup(myHashTable,"ENTRY02");
     98    if(strcmp(replaceId->name,"IDE") != 0) {
     99        psError(PS_ERR_UNKNOWN,true,"psHashAdd did not replace ENTRY02 with correct item");
     100        return 6;
     101    }
     102    printFooter(stdout,"psHash replace item","psHashAdd",true);
     103
     104    // Add with NULL hash table specified
     105    printNegativeTestHeader(stdout,"psHashAdd","NULL hash table","Hash table can not be NULL.",0);
     106    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message: psHashAdd with null table");
     107    retVal = psHashAdd(NULL,"ENTRY04",id);
     108    if(retVal) {
     109        psError(PS_ERR_UNKNOWN,true,"psHashAdd added entry to NULL hash table.");
     110        return 20;
     111    }
     112    printFooter(stdout,"psHashAdd","NULL hash table",true);
     113
     114    // Add with key to valid hash table NULL
     115    printNegativeTestHeader(stdout,"psHashAdd","NULL key","Hash key can not be NULL.",0);
     116    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message: psHashAdd with null key");
     117    retVal = psHashAdd(myHashTable,NULL,id);
     118    if(retVal) {
     119        psError(PS_ERR_UNKNOWN,true,"psHashAdd added entry to hash table with NULL key.");
     120        return 21;
     121    }
     122    printFooter(stdout,"psHashAdd","NULL hash key",true);
     123
     124    // Add NULL hash data to valid table and key
     125    printNegativeTestHeader(stdout,"psHashAdd","NULL hash data","Hash data can not be NULL.",0);
     126    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message: psHashAdd with null data");
     127    retVal = psHashAdd(myHashTable,"ENTRY04",NULL);
     128    if(retVal) {
     129        psError(PS_ERR_UNKNOWN,true,"psHashAdd added entry to hash table with NULL data.");
     130        return 22;
     131    }
     132    printFooter(stdout,"psHashAdd","NULL hash data",true);
     133
     134    // Free hash table
     135    printPositiveTestHeader(stdout,"psHash functions","psHashFree");
     136    psFree(id);
     137
    59138    psFree(myHashTable);
    60139
    61     if (imGlobal != 4) {
     140    if (imGlobal != 5) {
    62141        fprintf(stderr, "%s: only (%d/4) entries were freed",
    63142                __func__, imGlobal);
     
    65144    }
    66145
    67     printFooter(stdout,
    68                 "psHash functions",
    69                 "psHashFree()",
    70                 testStatus);
     146    printFooter(stdout,"psHash functions","psHashFree()",testStatus);
    71147
    72148    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
    73     if (0 != memLeaks) {
     149    if (memLeaks != 0) {
    74150        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    75151    }
  • trunk/psLib/test/collections/verified/tst_psHash01.stderr

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

    r1421 r2620  
    11/***************************** TESTPOINT ******************************************\
    22*             TestFile: tst_psHash01.c                                             *
    3 *            TestPoint: psHash functions{psHashFree()}                             *
     3*            TestPoint: psHash functions{psHashAlloc}                              *
     4*             TestType: Positive                                                   *
     5\**********************************************************************************/
     6
     7
     8---> TESTPOINT PASSED (psHash functions{psHashAlloc} | tst_psHash01.c)
     9
     10/***************************** TESTPOINT ******************************************\
     11*             TestFile: tst_psHash01.c                                             *
     12*            TestPoint: psHash functions{psHashAdd}                                *
     13*             TestType: Positive                                                   *
     14\**********************************************************************************/
     15
     16
     17---> TESTPOINT PASSED (psHash functions{psHashAdd} | tst_psHash01.c)
     18
     19/***************************** TESTPOINT ******************************************\
     20*             TestFile: tst_psHash01.c                                             *
     21*            TestPoint: psHash replace item{psHashAdd}                             *
     22*             TestType: Positive                                                   *
     23\**********************************************************************************/
     24
     25
     26---> TESTPOINT PASSED (psHash replace item{psHashAdd} | tst_psHash01.c)
     27
     28/***************************** TESTPOINT ******************************************\
     29*             TestFile: tst_psHash01.c                                             *
     30*            TestPoint: psHashAdd{NULL hash table}                                 *
     31*             TestType: Negative                                                   *
     32*    ExpectedErrorText: Hash table can not be NULL.                                *
     33*  ExpectedStatusValue: 0                                                          *
     34\**********************************************************************************/
     35
     36
     37---> TESTPOINT PASSED (psHashAdd{NULL hash table} | tst_psHash01.c)
     38
     39/***************************** TESTPOINT ******************************************\
     40*             TestFile: tst_psHash01.c                                             *
     41*            TestPoint: psHashAdd{NULL key}                                        *
     42*             TestType: Negative                                                   *
     43*    ExpectedErrorText: Hash key can not be NULL.                                  *
     44*  ExpectedStatusValue: 0                                                          *
     45\**********************************************************************************/
     46
     47
     48---> TESTPOINT PASSED (psHashAdd{NULL hash key} | tst_psHash01.c)
     49
     50/***************************** TESTPOINT ******************************************\
     51*             TestFile: tst_psHash01.c                                             *
     52*            TestPoint: psHashAdd{NULL hash data}                                  *
     53*             TestType: Negative                                                   *
     54*    ExpectedErrorText: Hash data can not be NULL.                                 *
     55*  ExpectedStatusValue: 0                                                          *
     56\**********************************************************************************/
     57
     58
     59---> TESTPOINT PASSED (psHashAdd{NULL hash data} | tst_psHash01.c)
     60
     61/***************************** TESTPOINT ******************************************\
     62*             TestFile: tst_psHash01.c                                             *
     63*            TestPoint: psHash functions{psHashFree}                               *
    464*             TestType: Positive                                                   *
    565\**********************************************************************************/
Note: See TracChangeset for help on using the changeset viewer.