Changeset 1193 for trunk/psLib/test/collections/tst_psList.c
- Timestamp:
- Jul 7, 2004, 3:05:01 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/collections/tst_psList.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/collections/tst_psList.c
r1126 r1193 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-0 6-29 23:18:00$8 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-07-08 01:05:01 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 29 29 testDescription tests[] = { 30 {testListAlloc, "487-testListAlloc",0},31 {testListAdd, "488-testListAdd",0},32 {testListGet, "489-testListGet",0},33 {testListRemove, "490-testListRemove",0},34 {testListConvert, "491-testListConvert",0},35 {testListIterator, "494-testListIterator",0},36 {testListFree, "627-testListFree",0},37 {testListSort, "624-testListSort",0},30 {testListAlloc,487,"psListAlloc",0,false}, 31 {testListAdd,488,"psListAdd",0,false}, 32 {testListGet,489,"psListGet",0,false}, 33 {testListRemove,490,"psListRemove",0,false}, 34 {testListConvert,491,"psListConvert",0,false}, 35 {testListIterator,494,"psListIterator",0,false}, 36 {testListFree,627,"psListFree",0,false}, 37 {testListSort,624,"psListSort",0,false}, 38 38 {NULL} 39 39 }; 40 40 41 int main( )41 int main(int argc, char* argv[]) 42 42 { 43 43 psLogSetLevel(PS_LOG_INFO); 44 44 45 if (! runTestSuite(stderr,"psList",tests )) {45 if (! runTestSuite(stderr,"psList",tests,argc,argv) ) { 46 46 psError(__FILE__,"One or more tests failed"); 47 47 return 1; … … 138 138 139 139 // 1. list is NULL (error) 140 list = psListAdd(NULL,data,PS_LIST_HEAD); 141 142 if (list != NULL) { 143 psError(__func__,"psListAdd was given a NULL list, but returned a non-NULL list."); 144 return 1; 145 } 146 147 // 2. data is NULL (error, list should not grow) 140 if (psListAdd(NULL,data,PS_LIST_HEAD)) { 141 psError(__func__,"psListAdd was given a NULL list, but returned a true/success."); 142 return 1; 143 } 144 148 145 list = psListAlloc(data); 149 146 psFree(data); … … 153 150 } 154 151 155 list = psListAdd(list, NULL,PS_LIST_HEAD); 156 157 if (list->size != 1) { 158 psError(__func__,"psListAdd with a NULL data element changed the list size."); 152 // 2. data is NULL (error, list should not grow) 153 if (psListAdd(list, NULL,PS_LIST_HEAD)) { 154 psError(__func__,"psListAdd successfully added a NULL data item?"); 155 return 40; 156 } 157 if ( list->size != 1) { 158 psError(__func__,"psListAdd with a NULL data element changed the list size or returned success."); 159 159 return 3; 160 160 } … … 163 163 data = psAlloc(sizeof(int)); 164 164 *data = 2; 165 list = psListAdd(list,data,PS_LIST_HEAD); 165 if ( ! psListAdd(list,data,PS_LIST_HEAD) ) { 166 psError(__func__,"psListAdd failed to add a data item to head."); 167 return 21; 168 } 169 166 170 if (psMemGetRefCounter(data) != 2) { 167 171 psError(__func__,"psListAdd didn't increment the data reference count."); … … 169 173 } 170 174 psFree(data); 175 171 176 // verify that the size incremented 172 177 if (list->size != 2) { … … 183 188 data = psAlloc(sizeof(int)); 184 189 *data = 3; 185 list = psListAdd(list,data,PS_LIST_TAIL); 190 if ( ! psListAdd(list,data,PS_LIST_TAIL) ) { 191 psError(__func__,"psListAdd failed to add a data item to tail."); 192 return 21; 193 } 194 186 195 if (psMemGetRefCounter(data) != 2) { 187 196 psError(__func__,"psListAdd didn't increment the data reference count."); 188 return 2 0;197 return 22; 189 198 } 190 199 psFree(data); … … 211 220 data = psAlloc(sizeof(int)); 212 221 *data = 4; 213 psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location"); 214 list = psListAdd(list,data,-10); 215 if (psMemGetRefCounter(data) != 2) { 216 psError(__func__,"psListAdd didn't increment the data reference count."); 217 return 20; 218 } 219 psFree(data); 220 // verify that the size incremented 221 if (list->size != 4 || *(int*)list->head->data != 4) { 222 psLogMsg(__func__,PS_LOG_INFO,"Following should error with invalid insert location"); 223 224 if ( psListAdd(list,data,-10) ) { 225 psError(__func__,"psListAdd successfully added data to a -10 position?"); 226 return 30; 227 } 228 if (psMemGetRefCounter(data) != 1) { 229 psError(__func__,"psListAdd incremented the data reference count."); 230 return 24; 231 } 232 psFree(data); 233 // verify that the size wasn't incremented 234 if (list->size != 3) { 222 235 printListInt(list); 223 236 psError(__func__,"psListAdd didn't insert to head when where was invalid."); … … 228 241 data = psAlloc(sizeof(int)); 229 242 *data = 5; 230 list = psListAdd(list,data,1); 243 244 if ( ! psListAdd(list,data,1) ) { 245 psError(__func__,"psListAdd failed to add data to 1 position."); 246 return 30; 247 } 248 231 249 if (psMemGetRefCounter(data) != 2) { 232 250 psError(__func__,"psListAdd didn't increment the data reference count."); 233 return 2 0;251 return 25; 234 252 } 235 253 psFree(data); 236 254 // verify that the size incremented 237 if (list->size != 5|| *(int*)list->head->next->data != 5) {255 if (list->size != 4 || *(int*)list->head->next->data != 5) { 238 256 printListInt(list); 239 257 psError(__func__,"psListAdd didn't insert to position #1."); 240 return 9;258 return 10; 241 259 } 242 260 243 261 data = psAlloc(sizeof(int)); 244 262 *data = 6; 245 list = psListAdd(list,data,4); 263 if ( ! psListAdd(list,data,3) ) { 264 psError(__func__,"psListAdd failed to add data to 4 position."); 265 return 31; 266 } 246 267 if (psMemGetRefCounter(data) != 2) { 247 268 psError(__func__,"psListAdd didn't increment the data reference count."); 248 return 2 0;269 return 26; 249 270 } 250 271 psFree(data); 251 272 // verify that the size incremented 252 if (list->size != 6 || *(int *)list->head->next->next->next->next->data != 6) {273 if (list->size != 5 || *(int *)list->head->next->next->next->data != 6) { 253 274 printListInt(list); 254 275 psError(__func__,"psListAdd didn't insert to position #4."); 255 return 9;276 return 50; 256 277 } 257 278 258 279 data = psAlloc(sizeof(int)); 259 280 *data = 7; 260 list = psListAdd(list,data,2); 281 if ( ! psListAdd(list,data,2) ) { 282 psError(__func__,"psListAdd failed to add data to 2 position."); 283 return 32; 284 } 261 285 if (psMemGetRefCounter(data) != 2) { 262 286 psError(__func__,"psListAdd didn't increment the data reference count."); 263 return 2 0;287 return 28; 264 288 } 265 289 psFree(data); 266 290 // verify that the size incremented 267 if (list->size != 7|| *(int *)list->head->next->next->data != 7) {291 if (list->size != 6 || *(int *)list->head->next->next->data != 7) { 268 292 printListInt(list); 269 293 psError(__func__,"psListAdd didn't insert to position #2."); 270 return 9;294 return 11; 271 295 } 272 296 … … 274 298 *data = 7; 275 299 psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning."); 276 list = psListAdd(list,data,9); 300 301 if ( ! psListAdd(list,data,9) ) { 302 psError(__func__,"psListAdd failed to add data to a 9 position?"); 303 return 30; 304 } 305 277 306 if (psMemGetRefCounter(data) != 2) { 278 307 psError(__func__,"psListAdd didn't increment the data reference count."); 279 return 20; 280 } 281 psFree(data); 308 return 29; 309 } 310 311 psFree(data); 312 282 313 // verify that the size incremented 283 if (list->size != 8) {314 if (list->size != 7) { 284 315 printListInt(list); 285 316 psError(__func__,"psListAdd didn't insert to position #9."); 286 return 9;317 return 12; 287 318 } 288 319 … … 347 378 data = psAlloc(sizeof(int)); 348 379 *data = 1; 349 list =psListAdd(list,data,PS_LIST_TAIL);380 psListAdd(list,data,PS_LIST_TAIL); 350 381 psFree(data); 351 382 352 383 data = psAlloc(sizeof(int)); 353 384 *data = 2; 354 list =psListAdd(list,data,PS_LIST_TAIL);385 psListAdd(list,data,PS_LIST_TAIL); 355 386 psFree(data); 356 387 357 388 data = psAlloc(sizeof(int)); 358 389 *data = 3; 359 list =psListAdd(list,data,PS_LIST_TAIL);390 psListAdd(list,data,PS_LIST_TAIL); 360 391 psFree(data); 361 392 … … 452 483 data = psAlloc(sizeof(int)); 453 484 *data = lcv; 454 list =psListAdd(list,data,PS_LIST_TAIL);485 psListAdd(list,data,PS_LIST_TAIL); 455 486 psMemDecrRefCounter(data); 456 487 } … … 671 702 data = psAlloc(sizeof(int)); 672 703 *data = lcv; 673 list =psListAdd(list,data,PS_LIST_TAIL);704 psListAdd(list,data,PS_LIST_TAIL); 674 705 psMemDecrRefCounter(data); 675 706 } … … 809 840 data = psAlloc(sizeof(int)); 810 841 *data = lcv; 811 list =psListAdd(list,data,PS_LIST_TAIL);842 psListAdd(list,data,PS_LIST_TAIL); 812 843 psFree(data); 813 844 } … … 926 957 data[lcv] = psAlloc(sizeof(int)); 927 958 *data[lcv] = lcv; 928 list =psListAdd(list,data[lcv],PS_LIST_TAIL);959 psListAdd(list,data[lcv],PS_LIST_TAIL); 929 960 if (psMemGetRefCounter(data[lcv]) != 2) { 930 961 psError(__func__,"Reference counter for data was not incremented"); … … 980 1011 *data = lcv*2-12; 981 1012 } 982 list =psListAdd(list,data,PS_LIST_TAIL);1013 psListAdd(list,data,PS_LIST_TAIL); 983 1014 psFree(data); 984 1015 … … 1046 1077 *data = lcv*2-12; 1047 1078 } 1048 list =psListAdd(list,data,PS_LIST_TAIL);1079 psListAdd(list,data,PS_LIST_TAIL); 1049 1080 psFree(data); 1050 1081
Note:
See TracChangeset
for help on using the changeset viewer.
