Changeset 3063
- Timestamp:
- Jan 19, 2005, 2:30:05 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/collections/tst_psList.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/collections/tst_psList.c
r2699 r3063 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $9 * @date $Date: 200 4-12-11 01:24:15 $8 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-01-20 00:30:05 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 static psS32 testListFree(void); 27 27 static psS32 testListSort(void); 28 static psS32 testListAddAfter(void); 29 static psS32 testListAddBefore(void); 28 30 29 31 testDescription tests[] = { … … 36 38 {testListFree,627,"psListFree",0,false}, 37 39 {testListSort,624,"psListSort",0,false}, 40 {testListAddAfter,811,"psListAddAfter",0,false}, 41 {testListAddBefore,811,"psListAddBefore",0,false}, 38 42 {NULL} 39 43 }; … … 63 67 // empty psList struct with head=tail=NULL and n=0. Otherwise, it shall 64 68 // return a psList of one element (head=tail=data, n=1). 65 69 // Test requirement SDR-167 66 70 list = psListAlloc(NULL); 67 71 if (list == NULL) { … … 69 73 return 1; 70 74 } 71 72 75 if (list->head != NULL || list->tail != NULL) { 73 76 psError(PS_ERR_UNKNOWN, true,"head and/or tail was not NULL for empty list."); 74 77 return 2; 75 78 } 76 77 79 if (list->size != 0) { 78 80 psError(PS_ERR_UNKNOWN, true,"size of list wasn't zero for empty list."); … … 82 84 psFree(list); 83 85 86 // Test requirement SDR-165 84 87 list = psListAlloc(data); 85 88 if (list == NULL) { … … 109 112 } 110 113 111 112 psFree(list); 113 114 psFree(data); 114 psFree(list); 115 116 psFree(data); 117 118 return 0; 119 } 120 121 psS32 testListAddAfter(void) 122 { 123 psList* list = NULL; 124 psS32* data = NULL; 125 psS32* data1 = NULL; 126 psS32* data2 = NULL; 127 psListIterator *currentIterator = NULL; 128 129 data = psAlloc(sizeof(psS32)); 130 *data = 1; 131 data1 = psAlloc(sizeof(psS32)); 132 *data1 = 2; 133 data2 = psAlloc(sizeof(psS32)); 134 *data2 = 3; 135 136 list = psListAlloc(data); 137 currentIterator = psListIteratorAlloc(list,PS_LIST_HEAD); 138 139 // Add data after HEAD and verify data 140 // Test requirement SDR-755 141 if(!psListAddAfter(currentIterator,data1)) { 142 psError(PS_ERR_UNKNOWN,true,"psListAddAfter failed to add item"); 143 return 1; 144 } 145 if(*(psS32*)list->head->next->data != 2) { 146 psError(PS_ERR_UNKNOWN,true,"psListAddAfter did not add the item properly"); 147 return 2; 148 } 149 // Test requirement SDR-175 150 if (psMemGetRefCounter(data1) != 2) { 151 psError(PS_ERR_UNKNOWN, true,"psListAddAfter didn't increment the data reference count."); 152 return 20; 153 } 154 psFree(currentIterator); 155 156 currentIterator = psListIteratorAlloc(list,PS_LIST_TAIL); 157 158 // Add data after TAIL and verify data 159 if(!psListAddAfter(currentIterator,data2)) { 160 psError(PS_ERR_UNKNOWN,true,"psListAddAfter failed to add item"); 161 return 3; 162 } 163 if(*(psS32*)list->tail->data != 3) { 164 psError(PS_ERR_UNKNOWN,true,"psListAddAfter did not add the item properly"); 165 return 4; 166 } 167 // Test requirement SDR-175 168 if (psMemGetRefCounter(data2) != 2) { 169 psError(PS_ERR_UNKNOWN, true,"psListAddAfter didn't increment the data reference count."); 170 return 40; 171 } 172 173 // Verify error message generated with data pointer is NULL 174 psLogMsg(__func__,PS_LOG_INFO,"NULL data pointer should generate error message"); 175 if(psListAddAfter(currentIterator,NULL)) { 176 psError(PS_ERR_UNKNOWN,true,"psListAddAfter should have generated error."); 177 return 5; 178 } 179 180 // Verify error message generated with iterator NULL 181 psLogMsg(__func__,PS_LOG_INFO,"NULL iterator should generate error message"); 182 if(psListAddAfter(NULL,data2)) { 183 psError(PS_ERR_UNKNOWN,true,"psListAddAfter should have generated error."); 184 return 6; 185 } 186 187 psFree(data); 188 psFree(data1); 189 psFree(data2); 190 psFree(list); 191 192 return 0; 193 } 194 195 psS32 testListAddBefore(void) 196 { 197 psList* list = NULL; 198 psS32* data1 = NULL; 199 psS32* data2 = NULL; 200 psListIterator *currentIterator = NULL; 201 202 data1 = psAlloc(sizeof(psS32)); 203 *data1 = 2; 204 data2 = psAlloc(sizeof(psS32)); 205 *data2 = 3; 206 207 list = psListAlloc(NULL); 208 currentIterator = psListIteratorAlloc(list,PS_LIST_HEAD); 209 210 // Add data before HEAD and verify data 211 // Test requirement SDR-756 212 if(!psListAddBefore(currentIterator,data1)) { 213 psError(PS_ERR_UNKNOWN,true,"psListAddBefore failed to add item"); 214 return 1; 215 } 216 if(*(psS32*)list->head->data != 2) { 217 psError(PS_ERR_UNKNOWN,true,"psListAddBefore did not add the item properly"); 218 return 2; 219 } 220 // Test requirement SDR-175 221 if (psMemGetRefCounter(data1) != 2) { 222 psError(PS_ERR_UNKNOWN, true,"psListAddBefore didn't increment the data reference count."); 223 return 20; 224 } 225 psFree(currentIterator); 226 227 currentIterator = psListIteratorAlloc(list,PS_LIST_TAIL); 228 229 // Add data after TAIL and verify data 230 if(!psListAddBefore(currentIterator,data2)) { 231 psError(PS_ERR_UNKNOWN,true,"psListAddBefore failed to add item"); 232 return 3; 233 } 234 if(*(psS32*)list->tail->prev->data != 3) { 235 psError(PS_ERR_UNKNOWN,true,"psListAddBefore did not add the item properly"); 236 return 4; 237 } 238 // Test requirement SDR-175 239 if (psMemGetRefCounter(data2) != 2) { 240 psError(PS_ERR_UNKNOWN, true,"psListAddBefore didn't increment the data reference count."); 241 return 40; 242 } 243 244 // Verify error message generated with data pointer is NULL 245 psLogMsg(__func__,PS_LOG_INFO,"NULL data pointer should generate error message"); 246 if(psListAddBefore(currentIterator,NULL)) { 247 psError(PS_ERR_UNKNOWN,true,"psListAddBefore should have generated error."); 248 return 5; 249 } 250 251 // Verify error message generated with iterator NULL 252 psLogMsg(__func__,PS_LOG_INFO,"NULL iterator should generate error message"); 253 if(psListAddBefore(NULL,data2)) { 254 psError(PS_ERR_UNKNOWN,true,"psListAddBefore should have generated error."); 255 return 6; 256 } 257 258 psFree(data1); 259 psFree(data2); 260 psFree(list); 115 261 116 262 return 0; … … 167 313 return 21; 168 314 } 169 315 // Test requirement SDR-175 170 316 if (psMemGetRefCounter(data) != 2) { 171 317 psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count."); … … 192 338 return 21; 193 339 } 194 340 // Test requirement SDR-175 195 341 if (psMemGetRefCounter(data) != 2) { 196 342 psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count."); … … 226 372 return 30; 227 373 } 374 // Test requirement SDR-175 228 375 if (psMemGetRefCounter(data) != 1) { 229 376 psError(PS_ERR_UNKNOWN, true,"psListAdd incremented the data reference count."); … … 246 393 return 30; 247 394 } 248 395 // Test requirement SDR-175 249 396 if (psMemGetRefCounter(data) != 2) { 250 397 psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count."); … … 265 412 return 31; 266 413 } 414 // Test requirment SDR-175 267 415 if (psMemGetRefCounter(data) != 2) { 268 416 psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count."); … … 279 427 data = psAlloc(sizeof(psS32)); 280 428 *data = 7; 429 // Test requirment SDR-169 281 430 if ( ! psListAdd(list,2,data) ) { 282 431 psError(PS_ERR_UNKNOWN, true,"psListAdd failed to add data to 2 position."); 283 432 return 32; 284 433 } 434 // Test requirment SDR-175 285 435 if (psMemGetRefCounter(data) != 2) { 286 436 psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count."); … … 295 445 } 296 446 297 data = psAlloc(sizeof(psS32)); 298 *data = 7; 447 // Test requirement SDR-757 448 data = psAlloc(sizeof(psS32)); 449 *data = 8; 299 450 psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning."); 300 451 … … 303 454 return 30; 304 455 } 305 456 // Test requirment SDR-175 306 457 if (psMemGetRefCounter(data) != 2) { 307 458 psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count."); 308 459 return 29; 309 460 } 310 311 psFree(data); 312 313 // verify that the size incremented 314 if (list->size != 7) { 315 printListInt(list); 316 psError(PS_ERR_UNKNOWN, true,"psListAdd didn't insert to position #9."); 461 if(list->size != 7 || *(psS32 *)list->tail->data != 8) { 462 printListInt(list); 463 psError(PS_ERR_UNKNOWN,true,"psListAdd didn't place added item at tail."); 317 464 return 12; 318 465 } 466 467 psFree(data); 319 468 320 469 psFree(list);
Note:
See TracChangeset
for help on using the changeset viewer.
