Changeset 920
- Timestamp:
- Jun 8, 2004, 9:12:05 AM (22 years ago)
- Location:
- trunk/psLib/test/collections
- Files:
-
- 2 edited
-
Makefile (modified) (2 diffs)
-
tst_psDlist.c (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/collections/Makefile
r877 r920 3 3 ## Makefile: test/collections 4 4 ## 5 ## $Revision: 1.1 0$ $Name: not supported by cvs2svn $6 ## $Date: 2004-06-0 4 23:49:14$5 ## $Revision: 1.11 $ $Name: not supported by cvs2svn $ 6 ## $Date: 2004-06-08 19:12:05 $ 7 7 ## 8 8 ## Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 30 tst_psSort_04 \ 31 31 tst_psImage \ 32 tst_ps Dlist32 tst_psList 33 33 34 34 OBJS = $(addsuffix .o,$(TARGET)) -
trunk/psLib/test/collections/tst_psDlist.c
r917 r920 1 /** @file tst_ps Dlist.c1 /** @file tst_psList.c 2 2 * 3 * @brief Contains the tests for ps Dlist.[ch]3 * @brief Contains the tests for psList.[ch] 4 4 * 5 5 * 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-06-08 02:41:19$8 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-06-08 19:09:33 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 15 #include "pslib.h" 16 16 17 void printListInt(psDlist* list); 18 19 20 static int testDlistAlloc(void); 21 static int testDlistAdd(void); 22 static int testDlistGet(void); 23 static int testDlistRemove(void); 24 static int testDlistConvert(void); 17 void printListInt(psList* list); 18 19 20 static int testListAlloc(void); 21 static int testListAdd(void); 22 static int testListGet(void); 23 static int testListRemove(void); 24 static int testListConvert(void); 25 static int testListIterator(void); 25 26 26 27 testDescription tests[] = { 27 {testDlistAlloc,"487-testDlistAlloc",0}, 28 {testDlistAdd,"488-testDlistAdd",0}, 29 {testDlistGet,"489-testDlistGet",0}, 30 {testDlistRemove,"490-testDlistRemove",0}, 31 {testDlistConvert,"491-testDlistConvert",0}, 28 {testListAlloc,"487-testListAlloc",0}, 29 {testListAdd,"488-testListAdd",0}, 30 {testListGet,"489-testListGet",0}, 31 {testListRemove,"490-testListRemove",0}, 32 {testListConvert,"491-testListConvert",0}, 33 {testListIterator,"494-testListIterator",0}, 32 34 {NULL} 33 35 }; … … 37 39 psSetLogLevel(PS_LOG_INFO); 38 40 39 if (! runTestSuite(stderr,"ps Dlist",tests)) {41 if (! runTestSuite(stderr,"psList",tests)) { 40 42 psAbort(__FILE__,"One or more tests failed"); 41 43 } … … 43 45 } 44 46 45 int test DlistAlloc(void)47 int testListAlloc(void) 46 48 { 47 49 int currentId = psMemGetId(); 48 ps Dlist* list;50 psList* list; 49 51 int ref; 50 52 float* data; 51 53 52 psLogMsg(__func__,PS_LOG_INFO,"ps DlistAlloc shall create a psDlist with either 0 or 1 element.");54 psLogMsg(__func__,PS_LOG_INFO,"psListAlloc shall create a psList with either 0 or 1 element."); 53 55 54 56 data = psAlloc(sizeof(float)); 55 57 56 // if ps DlistAlloc is invoked with a NULL parameter, it shall return an57 // empty ps Dlist struct with head=tail=NULL and n=0. Otherwise, it shall58 // return a ps Dlist of one element (head=tail=data, n=1).59 60 list = ps DlistAlloc(NULL);58 // if psListAlloc is invoked with a NULL parameter, it shall return an 59 // empty psList struct with head=tail=NULL and n=0. Otherwise, it shall 60 // return a psList of one element (head=tail=data, n=1). 61 62 list = psListAlloc(NULL); 61 63 if (list == NULL) { 62 psError(__func__,"ps DlistAlloc failed to return a list.");64 psError(__func__,"psListAlloc failed to return a list."); 63 65 return 1; 64 66 } … … 74 76 } 75 77 76 ps DlistFree(list,NULL);77 78 list = ps DlistAlloc(data);78 psListFree(list,NULL); 79 80 list = psListAlloc(data); 79 81 if (list == NULL) { 80 psError(__func__,"ps DlistAlloc failed to return a list.");82 psError(__func__,"psListAlloc failed to return a list."); 81 83 return 4; 82 84 } … … 99 101 ref = psMemGetRefCounter(data); 100 102 if (ref != 2) { 101 psError(__func__,"ps Dlist didn't increment reference count of data (%d.",ref);103 psError(__func__,"psList didn't increment reference count of data (%d.",ref); 102 104 return 8; 103 105 } 104 106 105 107 106 ps DlistFree(list,PS_FREE);108 psListFree(list,PS_FREE); 107 109 108 110 psMemCheckLeaks(currentId,NULL,NULL); … … 112 114 } 113 115 114 int test DlistAdd(void)116 int testListAdd(void) 115 117 { 116 118 int currentId = psMemGetId(); 117 ps Dlist* list = NULL;119 psList* list = NULL; 118 120 int* data; 119 121 120 psLogMsg(__func__,PS_LOG_INFO,"ps DlistAdd shall add an element to list");122 psLogMsg(__func__,PS_LOG_INFO,"psListAdd shall add an element to list"); 121 123 122 124 /* 123 ps DlistAdd(list,data,where) should be tested in the instance where:125 psListAdd(list,data,where) should be tested in the instance where: 124 126 125 127 1. list is NULL (error) 126 128 2. data is NULL (error, list should not grow) 127 3. where is PS_ DLIST_HEAD or PS_DLIST_TAIL128 4. where is not PS_ DLIST_* but <0129 3. where is PS_LIST_HEAD or PS_LIST_TAIL 130 4. where is not PS_LIST_* but <0 129 131 5. where is >0 130 132 */ 131 133 132 134 // 1. list is NULL (error) 133 list = ps DlistAdd(NULL,data,PS_DLIST_HEAD);135 list = psListAdd(NULL,data,PS_LIST_HEAD); 134 136 135 137 if (list != NULL) { 136 psError(__func__,"ps DlistAdd was given a NULL list, but returned a non-NULL list.");138 psError(__func__,"psListAdd was given a NULL list, but returned a non-NULL list."); 137 139 return 1; 138 140 } … … 141 143 data = psAlloc(sizeof(int)); 142 144 *data = 1; 143 list = ps DlistAlloc(data);145 list = psListAlloc(data); 144 146 if (list->size != 1) { 145 psError(__func__,"ps DlistAlloc didn't create a list properly.");147 psError(__func__,"psListAlloc didn't create a list properly."); 146 148 return 2; 147 149 } 148 150 149 list = ps DlistAdd(list, NULL,PS_DLIST_HEAD);151 list = psListAdd(list, NULL,PS_LIST_HEAD); 150 152 151 153 if (list->size != 1) { 152 psError(__func__,"ps DlistAdd with a NULL data element changed the list size.");154 psError(__func__,"psListAdd with a NULL data element changed the list size."); 153 155 return 3; 154 156 } 155 157 156 // 3. where is PS_ DLIST_HEAD or PS_DLIST_TAIL158 // 3. where is PS_LIST_HEAD or PS_LIST_TAIL 157 159 data = psAlloc(sizeof(int)); 158 160 *data = 2; 159 list = ps DlistAdd(list,data,PS_DLIST_HEAD);161 list = psListAdd(list,data,PS_LIST_HEAD); 160 162 161 163 // verify that the size incremented 162 164 if (list->size != 2) { 163 psError(__func__,"ps DlistAdd didn't increment the size by one");165 psError(__func__,"psListAdd didn't increment the size by one"); 164 166 return 4; 165 167 } … … 167 169 // verify that the head is the inserted data item 168 170 if (*(int*)list->head->data != 2) { 169 psError(__func__,"ps DlistAdd with PS_DLIST_HEAD didn't insert at the head.");171 psError(__func__,"psListAdd with PS_LIST_HEAD didn't insert at the head."); 170 172 return 5; 171 173 } … … 173 175 data = psAlloc(sizeof(int)); 174 176 *data = 3; 175 list = ps DlistAdd(list,data,PS_DLIST_TAIL);177 list = psListAdd(list,data,PS_LIST_TAIL); 176 178 177 179 // verify that the size incremented 178 180 if (list->size != 3) { 179 psError(__func__,"ps DlistAdd didn't increment the size by 1");181 psError(__func__,"psListAdd didn't increment the size by 1"); 180 182 return 6; 181 183 } … … 183 185 // verify that the head is still the same 184 186 if (*(int*)list->head->data != 2) { 185 psError(__func__,"ps DlistAdd with PS_DLIST_TAIL modified the head.");187 psError(__func__,"psListAdd with PS_LIST_TAIL modified the head."); 186 188 return 7; 187 189 } … … 189 191 // verify that the tail is the data item inserted 190 192 if (*(int*)list->tail->data != 3) { 191 psError(__func__,"ps DlistAdd with PS_DLIST_TAIL didn't insert at the tail.");193 psError(__func__,"psListAdd with PS_LIST_TAIL didn't insert at the tail."); 192 194 return 8; 193 195 } 194 196 195 // 4. where is not PS_ DLIST_* but <0197 // 4. where is not PS_LIST_* but <0 196 198 197 199 data = psAlloc(sizeof(int)); … … 199 201 200 202 psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location"); 201 list = ps DlistAdd(list,data,-10);203 list = psListAdd(list,data,-10); 202 204 // verify that the size incremented 203 205 if (list->size != 4 || *(int*)list->head->data != 4) { 204 206 printListInt(list); 205 psError(__func__,"ps DlistAdd didn't insert to head when where was invalid.");207 psError(__func__,"psListAdd didn't insert to head when where was invalid."); 206 208 return 9; 207 209 } … … 210 212 data = psAlloc(sizeof(int)); 211 213 *data = 5; 212 list = ps DlistAdd(list,data,1);214 list = psListAdd(list,data,1); 213 215 // verify that the size incremented 214 216 if (list->size != 5 || *(int*)list->head->next->data != 5) { 215 217 printListInt(list); 216 psError(__func__,"ps DlistAdd didn't insert to position #1.");218 psError(__func__,"psListAdd didn't insert to position #1."); 217 219 return 9; 218 220 } … … 220 222 data = psAlloc(sizeof(int)); 221 223 *data = 6; 222 list = ps DlistAdd(list,data,4);224 list = psListAdd(list,data,4); 223 225 // verify that the size incremented 224 226 if (list->size != 6 || *(int *)list->head->next->next->next->next->data != 6) { 225 227 printListInt(list); 226 psError(__func__,"ps DlistAdd didn't insert to position #4.");228 psError(__func__,"psListAdd didn't insert to position #4."); 227 229 return 9; 228 230 } … … 230 232 data = psAlloc(sizeof(int)); 231 233 *data = 7; 232 list = ps DlistAdd(list,data,2);234 list = psListAdd(list,data,2); 233 235 // verify that the size incremented 234 236 if (list->size != 7 || *(int *)list->head->next->next->data != 7) { 235 237 printListInt(list); 236 psError(__func__,"ps DlistAdd didn't insert to position #2.");238 psError(__func__,"psListAdd didn't insert to position #2."); 237 239 return 9; 238 240 } … … 241 243 *data = 7; 242 244 psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning."); 243 list = ps DlistAdd(list,data,9);245 list = psListAdd(list,data,9); 244 246 // verify that the size incremented 245 247 if (list->size != 8) { 246 248 printListInt(list); 247 psError(__func__,"ps DlistAdd didn't insert to position #9.");249 psError(__func__,"psListAdd didn't insert to position #9."); 248 250 return 9; 249 251 } 250 252 251 ps DlistFree(list, PS_FREE);253 psListFree(list, PS_FREE); 252 254 253 255 psMemCheckLeaks(currentId,NULL,NULL); … … 257 259 } 258 260 259 void printListInt(ps Dlist* list)261 void printListInt(psList* list) 260 262 { 261 263 int* data = NULL; 262 264 bool first = true; 263 265 264 ps DlistSetIterator(list,PS_DLIST_HEAD);265 data = ps DlistGetCurrent(list);266 psListSetIterator(list,PS_LIST_HEAD); 267 data = psListGetCurrent(list); 266 268 267 269 while ( data != NULL ) { … … 272 274 first = false; 273 275 } 274 data = ps DlistGetNext(list);276 data = psListGetNext(list); 275 277 } 276 278 … … 279 281 280 282 281 int test DlistGet(void)283 int testListGet(void) 282 284 { 283 285 int currentId = psMemGetId(); 284 ps Dlist* list = NULL;286 psList* list = NULL; 285 287 int* data; 286 288 287 289 /* 288 ps DlistGet(list,which) shall be tested with the following instances290 psListGet(list,which) shall be tested with the following instances 289 291 290 292 1. list is NULL. 291 293 2. which>0 and which<list.n. 292 294 3. which>list.n. 293 4. which=PS_ DLIST_HEAD294 5. which=PS_ DLIST_NEXT295 6. which=PS_ DLIST_TAIL296 7. which=PS_ DLIST_PREV297 8. which<0 and not any PS_ DLIST_* values295 4. which=PS_LIST_HEAD 296 5. which=PS_LIST_NEXT 297 6. which=PS_LIST_TAIL 298 7. which=PS_LIST_PREV 299 8. which<0 and not any PS_LIST_* values 298 300 */ 299 301 300 302 // 1. list is NULL. 301 303 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error"); 302 if (ps DlistGet(list,PS_DLIST_HEAD) != NULL) {303 psError(__func__,"ps DlistGet didn't return NULL given a NULL list.");304 if (psListGet(list,PS_LIST_HEAD) != NULL) { 305 psError(__func__,"psListGet didn't return NULL given a NULL list."); 304 306 return 1; 305 307 }; … … 308 310 data = psAlloc(sizeof(int)); 309 311 *data = 0; 310 list = ps DlistAlloc(data);312 list = psListAlloc(data); 311 313 312 314 data = psAlloc(sizeof(int)); 313 315 *data = 1; 314 list = ps DlistAdd(list,data,PS_DLIST_TAIL);316 list = psListAdd(list,data,PS_LIST_TAIL); 315 317 316 318 data = psAlloc(sizeof(int)); 317 319 *data = 2; 318 list = ps DlistAdd(list,data,PS_DLIST_TAIL);320 list = psListAdd(list,data,PS_LIST_TAIL); 319 321 320 322 data = psAlloc(sizeof(int)); 321 323 *data = 3; 322 list = ps DlistAdd(list,data,PS_DLIST_TAIL);324 list = psListAdd(list,data,PS_LIST_TAIL); 323 325 324 326 // 2. which>0 and which<list.n. 325 data = (int*)ps DlistGet(list,3);327 data = (int*)psListGet(list,3); 326 328 if (data == NULL || *data != 3) { 327 psError(__func__,"ps DlistGet failed with which=3");329 psError(__func__,"psListGet failed with which=3"); 328 330 return 2; 329 331 } 330 data = (int*)ps DlistGet(list,1);332 data = (int*)psListGet(list,1); 331 333 if (data == NULL || *data != 1) { 332 psError(__func__,"ps DlistGet failed with which=1");334 psError(__func__,"psListGet failed with which=1"); 333 335 return 3; 334 336 } 335 337 336 338 // 3. which>=list.n. 337 data = (int*)ps DlistGet(list,5);339 data = (int*)psListGet(list,5); 338 340 if (data != NULL) { 339 psError(__func__,"ps DlistGet failed with which=5");341 psError(__func__,"psListGet failed with which=5"); 340 342 return 4; 341 343 } 342 data = (int*)ps DlistGet(list,4);344 data = (int*)psListGet(list,4); 343 345 if (data != NULL) { 344 psError(__func__,"ps DlistGet failed with which=4");346 psError(__func__,"psListGet failed with which=4"); 345 347 return 5; 346 348 } 347 349 348 // 4. which=PS_ DLIST_HEAD349 data = (int*)ps DlistGet(list,PS_DLIST_HEAD);350 // 4. which=PS_LIST_HEAD 351 data = (int*)psListGet(list,PS_LIST_HEAD); 350 352 if (data == NULL || *data != 0) { 351 psError(__func__,"ps DlistGet failed with which=PS_DLIST_HEAD");353 psError(__func__,"psListGet failed with which=PS_LIST_HEAD"); 352 354 return 6; 353 355 } 354 356 355 // 5. which=PS_ DLIST_NEXT356 data = (int*)ps DlistGet(list,PS_DLIST_NEXT);357 // 5. which=PS_LIST_NEXT 358 data = (int*)psListGet(list,PS_LIST_NEXT); 357 359 if (data == NULL || *data != 1) { 358 psError(__func__,"ps DlistGet failed with which=PS_DLIST_NEXT");360 psError(__func__,"psListGet failed with which=PS_LIST_NEXT"); 359 361 return 7; 360 362 } 361 363 362 // 6. which=PS_ DLIST_TAIL363 data = (int*)ps DlistGet(list,PS_DLIST_TAIL);364 // 6. which=PS_LIST_TAIL 365 data = (int*)psListGet(list,PS_LIST_TAIL); 364 366 if (data == NULL || *data != 3) { 365 psError(__func__,"ps DlistGet failed with which=PS_DLIST_TAIL");367 psError(__func__,"psListGet failed with which=PS_LIST_TAIL"); 366 368 return 8; 367 369 } 368 370 369 // 7. which=PS_ DLIST_PREV370 data = (int*)ps DlistGet(list,PS_DLIST_PREVIOUS);371 // 7. which=PS_LIST_PREV 372 data = (int*)psListGet(list,PS_LIST_PREVIOUS); 371 373 if (data == NULL || *data != 2) { 372 psError(__func__,"ps DlistGet failed with which=PS_DLIST_PREV");374 psError(__func__,"psListGet failed with which=PS_LIST_PREV"); 373 375 return 9; 374 376 } 375 377 376 ps DlistFree(list,PS_FREE);378 psListFree(list,PS_FREE); 377 379 378 380 psMemCheckLeaks(currentId,NULL,NULL); … … 382 384 } 383 385 384 int test DlistRemove(void)386 int testListRemove(void) 385 387 { 386 388 int currentId = psMemGetId(); 387 ps Dlist* list = NULL;389 psList* list = NULL; 388 390 int* data; 389 391 390 392 /* 391 ps DlistRemove(list,data,which) should be tested under the following conditions:393 psListRemove(list,data,which) should be tested under the following conditions: 392 394 393 395 1. list is NULL 394 2. which is PS_ DLIST_HEAD (remove first element of list)395 3. which is PS_ DLIST_TAIL (remove last element of list)396 4. which is PS_ DLIST_NEXT (element right of cursor [which should be head,tail, and neither])397 5. which is PS_ DLIST_PREV (element left of cursor [which should be head,tail, and neither])398 6. which is PS_ DLIST_UNKNOWN and data=NULL (error)399 7. which is PS_ DLIST_UNKNOWN and data=[head,tail,other list items]400 8. which is PS_ DLIST_UNKNOWN and data!=NULL and data!=any element in list396 2. which is PS_LIST_HEAD (remove first element of list) 397 3. which is PS_LIST_TAIL (remove last element of list) 398 4. which is PS_LIST_NEXT (element right of cursor [which should be head,tail, and neither]) 399 5. which is PS_LIST_PREV (element left of cursor [which should be head,tail, and neither]) 400 6. which is PS_LIST_UNKNOWN and data=NULL (error) 401 7. which is PS_LIST_UNKNOWN and data=[head,tail,other list items] 402 8. which is PS_LIST_UNKNOWN and data!=NULL and data!=any element in list 401 403 402 404 In all conditions that are not an error, list.n shall be decremented and only the specified element … … 407 409 // 1. list is NULL. 408 410 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error"); 409 if (ps DlistRemove(list,NULL,PS_DLIST_HEAD) != NULL) {410 psError(__func__,"ps DlistGet didn't return NULL given a NULL list.");411 if (psListRemove(list,NULL,PS_LIST_HEAD) != NULL) { 412 psError(__func__,"psListGet didn't return NULL given a NULL list."); 411 413 return 1; 412 414 }; 413 415 414 416 // create a list 415 list = ps DlistAlloc(NULL);417 list = psListAlloc(NULL); 416 418 417 419 for (int lcv=0;lcv<15;lcv++) { 418 420 data = psAlloc(sizeof(int)); 419 421 *data = lcv; 420 list = ps DlistAdd(list,data,PS_DLIST_TAIL);422 list = psListAdd(list,data,PS_LIST_TAIL); 421 423 psMemDecrRefCounter(data); 422 424 } 423 425 424 426 425 // 2. which is PS_ DLIST_HEAD (remove first element of list)426 data = ps DlistRemove(list,NULL,PS_DLIST_HEAD);427 // 2. which is PS_LIST_HEAD (remove first element of list) 428 data = psListRemove(list,NULL,PS_LIST_HEAD); 427 429 if (data == NULL || *data != 0) { 428 430 printListInt(list); 429 psError(__func__,"Failed to remove PS_ DLIST_HEAD");431 psError(__func__,"Failed to remove PS_LIST_HEAD"); 430 432 return 1; 431 433 } … … 437 439 } 438 440 439 // 3. which is PS_ DLIST_TAIL (remove last element of list)440 data = ps DlistRemove(list,NULL,PS_DLIST_TAIL);441 // 3. which is PS_LIST_TAIL (remove last element of list) 442 data = psListRemove(list,NULL,PS_LIST_TAIL); 441 443 if (data == NULL || *data != 14) { 442 444 printListInt(list); 443 psError(__func__,"Failed to remove PS_ DLIST_TAIL");445 psError(__func__,"Failed to remove PS_LIST_TAIL"); 444 446 return 1; 445 447 } … … 451 453 } 452 454 453 // 4. which is PS_ DLIST_NEXT (element right of cursor [which should be head,tail, and neither])454 ps DlistSetIterator(list,PS_DLIST_HEAD);455 data = ps DlistRemove(list,NULL,PS_DLIST_NEXT);455 // 4. which is PS_LIST_NEXT (element right of cursor [which should be head,tail, and neither]) 456 psListSetIterator(list,PS_LIST_HEAD); 457 data = psListRemove(list,NULL,PS_LIST_NEXT); 456 458 if (data == NULL || *data != 2) { 457 459 printListInt(list); 458 psError(__func__,"Failed to remove PS_ DLIST_NEXT @ PS_DLIST_HEAD");460 psError(__func__,"Failed to remove PS_LIST_NEXT @ PS_LIST_HEAD"); 459 461 return 1; 460 462 } … … 466 468 } 467 469 468 ps DlistSetIterator(list,PS_DLIST_TAIL);470 psListSetIterator(list,PS_LIST_TAIL); 469 471 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 470 data = ps DlistRemove(list,NULL,PS_DLIST_NEXT);472 data = psListRemove(list,NULL,PS_LIST_NEXT); 471 473 if (data != NULL) { 472 474 printListInt(list); 473 psError(__func__,"Removed something with PS_ DLIST_NEXT @ PS_DLIST_TAIL");474 return 1; 475 } 476 477 ps DlistSetIterator(list,2);478 data = ps DlistRemove(list,NULL,PS_DLIST_NEXT);475 psError(__func__,"Removed something with PS_LIST_NEXT @ PS_LIST_TAIL"); 476 return 1; 477 } 478 479 psListSetIterator(list,2); 480 data = psListRemove(list,NULL,PS_LIST_NEXT); 479 481 if (data == NULL || *data != 5) { 480 482 printListInt(list); 481 psError(__func__,"Failed to remove PS_ DLIST_NEXT @ which=2");483 psError(__func__,"Failed to remove PS_LIST_NEXT @ which=2"); 482 484 return 1; 483 485 } … … 489 491 } 490 492 491 // 5. which is PS_ DLIST_PREV (element left of cursor [which should be head,tail, and neither])492 ps DlistSetIterator(list,PS_DLIST_HEAD);493 // 5. which is PS_LIST_PREV (element left of cursor [which should be head,tail, and neither]) 494 psListSetIterator(list,PS_LIST_HEAD); 493 495 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 494 data = ps DlistRemove(list,NULL,PS_DLIST_PREVIOUS);496 data = psListRemove(list,NULL,PS_LIST_PREVIOUS); 495 497 if (data != NULL) { 496 498 printListInt(list); 497 psError(__func__,"removed something for PS_ DLIST_PREVIOUS @ PS_DLIST_HEAD");498 return 1; 499 } 500 501 ps DlistSetIterator(list,PS_DLIST_TAIL);502 data = ps DlistRemove(list,NULL,PS_DLIST_PREVIOUS);499 psError(__func__,"removed something for PS_LIST_PREVIOUS @ PS_LIST_HEAD"); 500 return 1; 501 } 502 503 psListSetIterator(list,PS_LIST_TAIL); 504 data = psListRemove(list,NULL,PS_LIST_PREVIOUS); 503 505 if (data == NULL || *data != 12) { 504 506 printListInt(list); 505 psError(__func__,"Failed to remove PS_ DLIST_PREVIOUS @ PS_DLIST_TAIL");507 psError(__func__,"Failed to remove PS_LIST_PREVIOUS @ PS_LIST_TAIL"); 506 508 return 1; 507 509 } … … 513 515 } 514 516 515 ps DlistSetIterator(list,2);516 data = ps DlistRemove(list,NULL,PS_DLIST_PREVIOUS);517 psListSetIterator(list,2); 518 data = psListRemove(list,NULL,PS_LIST_PREVIOUS); 517 519 if (data == NULL || *data != 3) { 518 520 printListInt(list); 519 psError(__func__,"Failed to remove PS_ DLIST_PREVIOUS @ which=2");521 psError(__func__,"Failed to remove PS_LIST_PREVIOUS @ which=2"); 520 522 return 1; 521 523 } … … 527 529 } 528 530 529 // 6. which is PS_ DLIST_UNKNOWN and data=NULL (error)531 // 6. which is PS_LIST_UNKNOWN and data=NULL (error) 530 532 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 531 data = ps DlistRemove(list,NULL,PS_DLIST_UNKNOWN);533 data = psListRemove(list,NULL,PS_LIST_UNKNOWN); 532 534 if (data != NULL) { 533 535 printListInt(list); 534 psError(__func__,"removed something for PS_ DLIST_UNKNOWN with data=NULL");535 return 1; 536 } 537 538 // 7. which is PS_ DLIST_UNKNOWN and data=[head,tail,other list items]539 data = ps DlistGet(list,PS_DLIST_HEAD);540 data = ps DlistRemove(list,data,PS_DLIST_UNKNOWN);536 psError(__func__,"removed something for PS_LIST_UNKNOWN with data=NULL"); 537 return 1; 538 } 539 540 // 7. which is PS_LIST_UNKNOWN and data=[head,tail,other list items] 541 data = psListGet(list,PS_LIST_HEAD); 542 data = psListRemove(list,data,PS_LIST_UNKNOWN); 541 543 if (data == NULL || *data != 1) { 542 544 printListInt(list); 543 psError(__func__,"Failed to remove PS_ DLIST_UNKNOWN @ PS_DLIST_HEAD");545 psError(__func__,"Failed to remove PS_LIST_UNKNOWN @ PS_LIST_HEAD"); 544 546 return 1; 545 547 } … … 551 553 } 552 554 553 data = ps DlistGet(list,PS_DLIST_TAIL);554 data = ps DlistRemove(list,data,PS_DLIST_UNKNOWN);555 data = psListGet(list,PS_LIST_TAIL); 556 data = psListRemove(list,data,PS_LIST_UNKNOWN); 555 557 if (data == NULL || *data != 13) { 556 558 printListInt(list); 557 psError(__func__,"Failed to remove PS_ DLIST_UNKNOWN @ PS_DLIST_TAIL");559 psError(__func__,"Failed to remove PS_LIST_UNKNOWN @ PS_LIST_TAIL"); 558 560 return 1; 559 561 } … … 565 567 } 566 568 567 ps DlistSetIterator(list,PS_DLIST_HEAD);568 data = ps DlistGet(list,PS_DLIST_NEXT);569 570 data = ps DlistRemove(list,data,PS_DLIST_UNKNOWN);569 psListSetIterator(list,PS_LIST_HEAD); 570 data = psListGet(list,PS_LIST_NEXT); 571 572 data = psListRemove(list,data,PS_LIST_UNKNOWN); 571 573 if (data == NULL || *data != 6) { 572 574 printListInt(list); 573 psError(__func__,"Failed to remove PS_ DLIST_UNKNOWN @ which=1");575 psError(__func__,"Failed to remove PS_LIST_UNKNOWN @ which=1"); 574 576 return 1; 575 577 } … … 581 583 } 582 584 583 // 8. which is PS_ DLIST_UNKNOWN and data!=NULL and data!=any element in list585 // 8. which is PS_LIST_UNKNOWN and data!=NULL and data!=any element in list 584 586 psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error"); 585 data = ps DlistRemove(list,data,PS_DLIST_UNKNOWN);587 data = psListRemove(list,data,PS_LIST_UNKNOWN); 586 588 if (data != NULL) { 587 589 printListInt(list); 588 psError(__func__,"removed something for PS_ DLIST_UNKNOWN with previously removed item");590 psError(__func__,"removed something for PS_LIST_UNKNOWN with previously removed item"); 589 591 return 1; 590 592 } 591 593 592 594 // clear out the list 593 psFree(ps DlistRemove(list,NULL,PS_DLIST_HEAD));594 psFree(ps DlistRemove(list,NULL,PS_DLIST_HEAD));595 psFree(ps DlistRemove(list,NULL,PS_DLIST_HEAD));596 psFree(ps DlistRemove(list,NULL,PS_DLIST_HEAD));597 psFree(ps DlistRemove(list,NULL,PS_DLIST_HEAD));598 599 data = ps DlistRemove(list,data,PS_DLIST_HEAD);595 psFree(psListRemove(list,NULL,PS_LIST_HEAD)); 596 psFree(psListRemove(list,NULL,PS_LIST_HEAD)); 597 psFree(psListRemove(list,NULL,PS_LIST_HEAD)); 598 psFree(psListRemove(list,NULL,PS_LIST_HEAD)); 599 psFree(psListRemove(list,NULL,PS_LIST_HEAD)); 600 601 data = psListRemove(list,data,PS_LIST_HEAD); 600 602 if (data == NULL || *data != 11) { 601 603 printListInt(list); … … 611 613 } 612 614 613 ps DlistFree(list,PS_FREE);615 psListFree(list,PS_FREE); 614 616 615 617 psMemCheckLeaks(currentId,NULL,NULL); … … 620 622 } 621 623 622 int test DlistConvert(void)624 int testListConvert(void) 623 625 { 624 626 625 627 int currentId = psMemGetId(); 626 ps Dlist* list = NULL;628 psList* list = NULL; 627 629 psVector* vec = NULL; 628 630 int* data; 629 631 630 632 /* 631 array=ps DlistToArray(list) shall take each element of the list, increment633 array=psListToArray(list) shall take each element of the list, increment 632 634 their reference, and insert them into the returned fresh void* array. 633 635 The list shall not be changed, except for the element reference increment. … … 637 639 638 640 // create a list 639 list = ps DlistAlloc(NULL);641 list = psListAlloc(NULL); 640 642 for (int lcv=0;lcv<15;lcv++) { 641 643 data = psAlloc(sizeof(int)); 642 644 *data = lcv; 643 list = ps DlistAdd(list,data,PS_DLIST_TAIL);645 list = psListAdd(list,data,PS_LIST_TAIL); 644 646 psMemDecrRefCounter(data); 645 647 } 646 648 647 vec = ps DlistToVector(list);649 vec = psListToVector(list); 648 650 649 651 if (vec->n != 15 || list->size != 15) { … … 657 659 return 1; 658 660 } 659 if (i != *(int*)ps DlistGet(list,i)) {661 if (i != *(int*)psListGet(list,i)) { 660 662 psError(__func__,"Element %d of list is incorrect (%d).", 661 663 i,*(int*)vec->data.PTR[i]); … … 670 672 671 673 psVectorFree(vec); 672 ps DlistFree(list,PS_FREE);674 psListFree(list,PS_FREE); 673 675 674 676 psMemCheckLeaks(currentId,NULL,NULL); … … 698 700 return 1; 699 701 } 700 if (i != *(int*)ps DlistGet(list,i)) {702 if (i != *(int*)psListGet(list,i)) { 701 703 psError(__func__,"Element %d of list is incorrect (%d).", 702 704 i,*(int*)vec->data.PTR[i]); … … 711 713 712 714 psVectorFree(vec); 713 ps DlistFree(list,PS_FREE);715 psListFree(list,PS_FREE); 714 716 715 717 // now, make sure if input vector/list is NULL, output is NULL 716 718 717 vec = ps DlistToVector(NULL);719 vec = psListToVector(NULL); 718 720 if (vec != NULL) { 719 psError(__func__,"ps DlistToVector didn't return NULL when given NULL");721 psError(__func__,"psListToVector didn't return NULL when given NULL"); 720 722 return 1; 721 723 } … … 732 734 list = psVectorToDlist(vec); 733 735 if (list == NULL) { 734 psError(__func__,"psVectorToDlist didn't create an empty list from an empty vector."); 736 psError(__func__,"psVectorToDlist didn't create an empty list from an " 737 "empty vector."); 735 738 return 1; 736 739 } 737 740 psVectorFree(vec); 738 ps DlistFree(list,PS_FREE);739 740 list = ps DlistAlloc(NULL);741 vec = ps DlistToVector(list);741 psListFree(list,PS_FREE); 742 743 list = psListAlloc(NULL); 744 vec = psListToVector(list); 742 745 if (vec == NULL) { 743 psError(__func__,"psVectorToDlist didn't create an empty vector from an empty list."); 746 psError(__func__,"psVectorToDlist didn't create an empty vector from an " 747 "empty list."); 744 748 return 1; 745 749 } 746 750 psVectorFree(vec); 747 ps DlistFree(list,PS_FREE);751 psListFree(list,PS_FREE); 748 752 749 753 psMemCheckLeaks(currentId,NULL,NULL); … … 752 756 return 0; 753 757 } 758 759 int testListIterator(void) 760 { 761 int currentId = psMemGetId(); 762 763 psLogMsg(__func__,PS_LOG_INFO," psListSetIterator/psListGetNext/psListGetPrev" 764 " shall move the list cursor to the specified location"); 765 766 psMemCheckLeaks(currentId,NULL,NULL); 767 psMemCheckCorruption(1); 768 769 return 0; 770 }
Note:
See TracChangeset
for help on using the changeset viewer.
