Changeset 2624
- Timestamp:
- Dec 3, 2004, 4:43:17 PM (22 years ago)
- Location:
- trunk/psLib/test/collections
- Files:
-
- 3 edited
-
tst_psHash03.c (modified) (7 diffs)
-
verified/tst_psHash03.stderr (modified) (1 diff)
-
verified/tst_psHash03.stdout (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/collections/tst_psHash03.c
r2392 r2624 20 20 ID; 21 21 static void IdFree(ID *id); 22 23 // NOTE: This is my own little routine I used in debugging a memory24 // 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 }45 22 46 23 static ID *IdAlloc(const char *name) … … 79 56 currentId = psMemGetId(); 80 57 81 printPositiveTestHeader(stdout, 82 "psHash functions", 83 "psHashRemove()"); 58 printPositiveTestHeader(stdout,"psHash functions","psHashRemove"); 84 59 60 // Add items to hash table 85 61 myHashTable = psHashAlloc(NUM_HASH_TABLE_BUCKETS); 86 87 62 i = 0; 88 63 while (myKeys[i] != NULL) { … … 93 68 TotalKeys = i - 1; 94 69 70 // Verify items which were just add to hash table 95 71 i = TotalKeys; 96 72 while (i >= 0) { … … 100 76 fprintf(stderr, "%s: Hash table entry for key %s was %s (should be %s).\n", 101 77 __func__, myKeys[i], id->name, myData[i]); 78 return 1; 102 79 } 103 80 i--; 104 81 } 105 82 83 // Remove each item from the table and verify item is no longer in the list 106 84 i = 0; 107 85 while (myKeys[i] != NULL) { … … 111 89 if (!retVal) { 112 90 fprintf(stderr,"%s: Hash table entry not removed.\n",__func__); 91 return 2; 113 92 } 114 93 id = psHashLookup(myHashTable, myKeys[i]); … … 116 95 fprintf(stderr, "%s: Hash table entry for key %s not removed.\n", 117 96 __func__, "IDA"); 97 return 3; 118 98 } 119 99 i++; 120 100 } 101 printFooter(stdout,"psHash functions","psHashRemove()",true); 121 102 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); 126 129 127 130 psFree(myHashTable); … … 130 133 } 131 134 memLeaks = psMemCheckLeaks(currentId,NULL,stdout,false); 132 if ( 0 != memLeaks) {135 if (memLeaks != 0) { 133 136 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 134 137 } -
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 1 1 /***************************** TESTPOINT ******************************************\ 2 2 * TestFile: tst_psHash03.c * 3 * TestPoint: psHash functions{psHashRemove ()}*3 * TestPoint: psHash functions{psHashRemove} * 4 4 * TestType: Positive * 5 5 \**********************************************************************************/ … … 8 8 ---> TESTPOINT PASSED (psHash functions{psHashRemove()} | tst_psHash03.c) 9 9 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.
