Changeset 2204 for trunk/psLib/test/collections/tst_psList.c
- Timestamp:
- Oct 26, 2004, 2:57:34 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/collections/tst_psList.c (modified) (49 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/collections/tst_psList.c
r1749 r2204 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2004- 09-09 02:24:59$8 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-27 00:57:33 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 19 19 20 static inttestListAlloc(void);21 static inttestListAdd(void);22 static inttestListGet(void);23 static inttestListRemove(void);24 static inttestListConvert(void);25 static inttestListIterator(void);26 static inttestListFree(void);27 static inttestListSort(void);20 static psS32 testListAlloc(void); 21 static psS32 testListAdd(void); 22 static psS32 testListGet(void); 23 static psS32 testListRemove(void); 24 static psS32 testListConvert(void); 25 static psS32 testListIterator(void); 26 static psS32 testListFree(void); 27 static psS32 testListSort(void); 28 28 29 29 testDescription tests[] = { … … 39 39 }; 40 40 41 int main(intargc, char* argv[])41 psS32 main(psS32 argc, char* argv[]) 42 42 { 43 43 psLogSetLevel(PS_LOG_INFO); … … 50 50 } 51 51 52 inttestListAlloc(void)52 psS32 testListAlloc(void) 53 53 { 54 54 psList* list; 55 intref;55 psS32 ref; 56 56 float* data; 57 57 … … 117 117 } 118 118 119 inttestListAdd(void)119 psS32 testListAdd(void) 120 120 { 121 121 psList* list = NULL; 122 int* data = NULL;122 psS32* data = NULL; 123 123 124 124 psLogMsg(__func__,PS_LOG_INFO,"psListAdd shall add an element to list"); … … 134 134 */ 135 135 136 data = psAlloc(sizeof( int));136 data = psAlloc(sizeof(psS32)); 137 137 *data = 1; 138 138 … … 161 161 162 162 // 3. where is PS_LIST_HEAD or PS_LIST_TAIL 163 data = psAlloc(sizeof( int));163 data = psAlloc(sizeof(psS32)); 164 164 *data = 2; 165 165 if ( ! psListAdd(list,PS_LIST_HEAD,data) ) { … … 181 181 182 182 // verify that the head is the inserted data item 183 if (*( int*)list->head->data != 2) {183 if (*(psS32*)list->head->data != 2) { 184 184 psError(__func__,"psListAdd with PS_LIST_HEAD didn't insert at the head."); 185 185 return 5; 186 186 } 187 187 188 data = psAlloc(sizeof( int));188 data = psAlloc(sizeof(psS32)); 189 189 *data = 3; 190 190 if ( ! psListAdd(list,PS_LIST_TAIL,data) ) { … … 205 205 206 206 // verify that the head is still the same 207 if (*( int*)list->head->data != 2) {207 if (*(psS32*)list->head->data != 2) { 208 208 psError(__func__,"psListAdd with PS_LIST_TAIL modified the head."); 209 209 return 7; … … 211 211 212 212 // verify that the tail is the data item inserted 213 if (*( int*)list->tail->data != 3) {213 if (*(psS32*)list->tail->data != 3) { 214 214 psError(__func__,"psListAdd with PS_LIST_TAIL didn't insert at the tail."); 215 215 return 8; … … 218 218 // 4. where is not PS_LIST_* but <0 219 219 220 data = psAlloc(sizeof( int));220 data = psAlloc(sizeof(psS32)); 221 221 *data = 4; 222 222 psLogMsg(__func__,PS_LOG_INFO,"Following should error with invalid insert location"); … … 239 239 240 240 // 5. where is >0 241 data = psAlloc(sizeof( int));241 data = psAlloc(sizeof(psS32)); 242 242 *data = 5; 243 243 … … 253 253 psFree(data); 254 254 // verify that the size incremented 255 if (list->size != 4 || *( int*)list->head->next->data != 5) {255 if (list->size != 4 || *(psS32*)list->head->next->data != 5) { 256 256 printListInt(list); 257 257 psError(__func__,"psListAdd didn't insert to position #1."); … … 259 259 } 260 260 261 data = psAlloc(sizeof( int));261 data = psAlloc(sizeof(psS32)); 262 262 *data = 6; 263 263 if ( ! psListAdd(list,3,data) ) { … … 271 271 psFree(data); 272 272 // verify that the size incremented 273 if (list->size != 5 || *( int*)list->head->next->next->next->data != 6) {273 if (list->size != 5 || *(psS32 *)list->head->next->next->next->data != 6) { 274 274 printListInt(list); 275 275 psError(__func__,"psListAdd didn't insert to position #4."); … … 277 277 } 278 278 279 data = psAlloc(sizeof( int));279 data = psAlloc(sizeof(psS32)); 280 280 *data = 7; 281 281 if ( ! psListAdd(list,2,data) ) { … … 289 289 psFree(data); 290 290 // verify that the size incremented 291 if (list->size != 6 || *( int*)list->head->next->next->data != 7) {291 if (list->size != 6 || *(psS32 *)list->head->next->next->data != 7) { 292 292 printListInt(list); 293 293 psError(__func__,"psListAdd didn't insert to position #2."); … … 295 295 } 296 296 297 data = psAlloc(sizeof( int));297 data = psAlloc(sizeof(psS32)); 298 298 *data = 7; 299 299 psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning."); … … 325 325 void printListInt(psList* list) 326 326 { 327 int* data = NULL;328 bool first = true;327 psS32* data = NULL; 328 psBool first = true; 329 329 330 330 psListSetIterator(list,PS_LIST_HEAD); … … 333 333 while ( data != NULL ) { 334 334 if (!first) { 335 printf(", %d",*( int*)data);335 printf(", %d",*(psS32*)data); 336 336 } else { 337 printf("%d",*( int*)data);337 printf("%d",*(psS32*)data); 338 338 first = false; 339 339 } … … 345 345 346 346 347 inttestListGet(void)347 psS32 testListGet(void) 348 348 { 349 349 psList* list = NULL; 350 int* data;350 psS32* data; 351 351 352 352 /* … … 371 371 372 372 // create a list 373 data = psAlloc(sizeof( int));373 data = psAlloc(sizeof(psS32)); 374 374 *data = 0; 375 375 list = psListAlloc(data); 376 376 psFree(data); 377 377 378 data = psAlloc(sizeof( int));378 data = psAlloc(sizeof(psS32)); 379 379 *data = 1; 380 380 psListAdd(list,PS_LIST_TAIL,data); 381 381 psFree(data); 382 382 383 data = psAlloc(sizeof( int));383 data = psAlloc(sizeof(psS32)); 384 384 *data = 2; 385 385 psListAdd(list,PS_LIST_TAIL,data); 386 386 psFree(data); 387 387 388 data = psAlloc(sizeof( int));388 data = psAlloc(sizeof(psS32)); 389 389 *data = 3; 390 390 psListAdd(list,PS_LIST_TAIL,data); … … 392 392 393 393 // 2. which>0 and which<list.n. 394 data = ( int*)psListGet(list,3);394 data = (psS32*)psListGet(list,3); 395 395 if (data == NULL || *data != 3) { 396 396 psError(__func__,"psListGet failed with which=3"); 397 397 return 2; 398 398 } 399 data = ( int*)psListGet(list,1);399 data = (psS32*)psListGet(list,1); 400 400 if (data == NULL || *data != 1) { 401 401 psError(__func__,"psListGet failed with which=1"); … … 404 404 405 405 // 3. which>=list.n. 406 data = ( int*)psListGet(list,5);406 data = (psS32*)psListGet(list,5); 407 407 if (data != NULL) { 408 408 psError(__func__,"psListGet failed with which=5"); 409 409 return 4; 410 410 } 411 data = ( int*)psListGet(list,4);411 data = (psS32*)psListGet(list,4); 412 412 if (data != NULL) { 413 413 psError(__func__,"psListGet failed with which=4"); … … 416 416 417 417 // 4. which=PS_LIST_HEAD 418 data = ( int*)psListGet(list,PS_LIST_HEAD);418 data = (psS32*)psListGet(list,PS_LIST_HEAD); 419 419 if (data == NULL || *data != 0) { 420 420 psError(__func__,"psListGet failed with which=PS_LIST_HEAD"); … … 423 423 424 424 // 5. which=PS_LIST_NEXT 425 data = ( int*)psListGet(list,PS_LIST_NEXT);425 data = (psS32*)psListGet(list,PS_LIST_NEXT); 426 426 if (data == NULL || *data != 1) { 427 427 psError(__func__,"psListGet failed with which=PS_LIST_NEXT"); … … 430 430 431 431 // 6. which=PS_LIST_TAIL 432 data = ( int*)psListGet(list,PS_LIST_TAIL);432 data = (psS32*)psListGet(list,PS_LIST_TAIL); 433 433 if (data == NULL || *data != 3) { 434 434 psError(__func__,"psListGet failed with which=PS_LIST_TAIL"); … … 437 437 438 438 // 7. which=PS_LIST_PREV 439 data = ( int*)psListGet(list,PS_LIST_PREVIOUS);439 data = (psS32*)psListGet(list,PS_LIST_PREVIOUS); 440 440 if (data == NULL || *data != 2) { 441 441 psError(__func__,"psListGet failed with which=PS_LIST_PREV"); … … 448 448 } 449 449 450 inttestListRemove(void)450 psS32 testListRemove(void) 451 451 { 452 452 psList* list = NULL; 453 int* data;453 psS32* data; 454 454 455 455 /* … … 480 480 list = psListAlloc(NULL); 481 481 482 for ( intlcv=0;lcv<15;lcv++) {483 data = psAlloc(sizeof( int));482 for (psS32 lcv=0;lcv<15;lcv++) { 483 data = psAlloc(sizeof(psS32)); 484 484 *data = lcv; 485 485 psListAdd(list,PS_LIST_TAIL,data); … … 682 682 } 683 683 684 inttestListConvert(void)684 psS32 testListConvert(void) 685 685 { 686 686 687 687 psList* list = NULL; 688 688 psArray* arr = NULL; 689 int* data;689 psS32* data; 690 690 691 691 /* 692 692 array=psListToArray(list) shall take each element of the list, increment 693 their reference, and insert them into the returned fresh void*array.693 their reference, and insert them into the returned fresh psPtr array. 694 694 The list shall not be changed, except for the element reference increment. 695 695 */ … … 699 699 // create a list 700 700 list = psListAlloc(NULL); 701 for ( intlcv=0;lcv<15;lcv++) {702 data = psAlloc(sizeof( int));701 for (psS32 lcv=0;lcv<15;lcv++) { 702 data = psAlloc(sizeof(psS32)); 703 703 *data = lcv; 704 704 psListAdd(list,PS_LIST_TAIL,data); … … 712 712 return 1; 713 713 } 714 for ( inti=0;i<arr->n;i++) {715 if (i != *( int*)arr->data[i]) {714 for (psS32 i=0;i<arr->n;i++) { 715 if (i != *(psS32*)arr->data[i]) { 716 716 psError(__func__,"Element %d of array is incorrect (%d).", 717 i,*( int*)arr->data[i]);717 i,*(psS32*)arr->data[i]); 718 718 return 1; 719 719 } 720 if (i != *( int*)psListGet(list,i)) {720 if (i != *(psS32*)psListGet(list,i)) { 721 721 psError(__func__,"Element %d of list is incorrect (%d).", 722 i,*( int*)arr->data[i]);722 i,*(psS32*)arr->data[i]); 723 723 return 1; 724 724 } … … 738 738 arr = psArrayAlloc(15); 739 739 arr->n = arr->nalloc; 740 for ( intlcv=0;lcv<15;lcv++) {741 data = psAlloc(sizeof( int));740 for (psS32 lcv=0;lcv<15;lcv++) { 741 data = psAlloc(sizeof(psS32)); 742 742 *data = lcv; 743 743 arr->data[lcv] = data; … … 750 750 return 1; 751 751 } 752 for ( inti=0;i<arr->n;i++) {753 if (i != *( int*)arr->data[i]) {752 for (psS32 i=0;i<arr->n;i++) { 753 if (i != *(psS32*)arr->data[i]) { 754 754 psError(__func__,"Element %d of array is incorrect (%d).", 755 i,*( int*)arr->data[i]);755 i,*(psS32*)arr->data[i]); 756 756 return 1; 757 757 } 758 if (i != *( int*)psListGet(list,i)) {758 if (i != *(psS32*)psListGet(list,i)) { 759 759 psError(__func__,"Element %d of list is incorrect (%d).", 760 i,*( int*)arr->data[i]);760 i,*(psS32*)arr->data[i]); 761 761 return 1; 762 762 } … … 810 810 } 811 811 812 inttestListIterator(void)812 psS32 testListIterator(void) 813 813 { 814 814 psList* list = NULL; 815 int* data;815 psS32* data; 816 816 817 817 psLogMsg(__func__,PS_LOG_INFO," psListSetIterator/psListGetNext/psListGetPrev" … … 837 837 // create a list 838 838 list = psListAlloc(NULL); 839 for ( intlcv=0;lcv<15;lcv++) {840 data = psAlloc(sizeof( int));839 for (psS32 lcv=0;lcv<15;lcv++) { 840 data = psAlloc(sizeof(psS32)); 841 841 *data = lcv; 842 842 psListAdd(list,PS_LIST_TAIL,data); … … 852 852 // 3. set list.cursor to list.tail if where=PS_LIST_TAIL 853 853 psListSetIterator(list,PS_LIST_TAIL); 854 if (*( int*)psListGetCurrent(list) != 14) {854 if (*(psS32*)psListGetCurrent(list) != 14) { 855 855 psError(__func__,"Didn't successfully move cursor to tail."); 856 856 return 1; … … 859 859 // 2. set list.cursor to list.head if where=PS_LIST_HEAD 860 860 psListSetIterator(list,PS_LIST_HEAD); 861 if (*( int*)psListGetCurrent(list) != 0) {861 if (*(psS32*)psListGetCurrent(list) != 0) { 862 862 psError(__func__,"Didn't successfully move cursor to head."); 863 863 return 2; … … 866 866 // 4. set list.cursor to list.cursor->next if where=PS_LIST_NEXT 867 867 psListSetIterator(list,PS_LIST_NEXT); 868 if (*( int*)psListGetCurrent(list) != 1) {868 if (*(psS32*)psListGetCurrent(list) != 1) { 869 869 psError(__func__,"Didn't successfully move cursor to next."); 870 870 return 3; 871 871 } 872 872 psListSetIterator(list,PS_LIST_NEXT); 873 if (*( int*)psListGetCurrent(list) != 2) {873 if (*(psS32*)psListGetCurrent(list) != 2) { 874 874 psError(__func__,"Didn't successfully move cursor to next twice."); 875 875 return 4; … … 878 878 // 5. set list.cursor to list.cursor->prev if where=PS_LIST_PREV 879 879 psListSetIterator(list,PS_LIST_PREVIOUS); 880 if (*( int*)psListGetCurrent(list) != 1) {880 if (*(psS32*)psListGetCurrent(list) != 1) { 881 881 psError(__func__,"Didn't successfully move cursor to previous."); 882 882 return 5; 883 883 } 884 884 psListSetIterator(list,PS_LIST_PREVIOUS); 885 if (*( int*)psListGetCurrent(list) != 0) {885 if (*(psS32*)psListGetCurrent(list) != 0) { 886 886 psError(__func__,"Didn't successfully move cursor to previous twice."); 887 887 return 6; … … 892 892 psLogMsg(__func__,PS_LOG_INFO,"Following should error with 'Can't move to an unknown position.'"); 893 893 psListSetIterator(list,PS_LIST_UNKNOWN); 894 if (*( int*)psListGetCurrent(list) != 1) {894 if (*(psS32*)psListGetCurrent(list) != 1) { 895 895 psError(__func__,"PS_LIST_UNKNOWN moved cursor."); 896 896 return 7; 897 897 } 898 898 psListSetIterator(list,PS_LIST_CURRENT); 899 if (*( int*)psListGetCurrent(list) != 1) {899 if (*(psS32*)psListGetCurrent(list) != 1) { 900 900 psError(__func__,"PS_LIST_CURRENT moved cursor."); 901 901 return 8; … … 903 903 904 904 // test psListGetPrevious/Next 905 if (*( int*)psListGetNext(list) != 2) {905 if (*(psS32*)psListGetNext(list) != 2) { 906 906 psError(__func__,"psListGetNext didn't move cursor to next."); 907 907 return 9; 908 908 } 909 if (*( int*)psListGetNext(list) != 3) {909 if (*(psS32*)psListGetNext(list) != 3) { 910 910 psError(__func__,"psListGetNext didn't move cursor to next."); 911 911 return 10; 912 912 } 913 if (*( int*)psListGetPrevious(list) != 2) {913 if (*(psS32*)psListGetPrevious(list) != 2) { 914 914 psError(__func__,"psListGetPrevious didn't move cursor to previous."); 915 915 return 11; 916 916 } 917 if (*( int*)psListGetPrevious(list) != 1) {917 if (*(psS32*)psListGetPrevious(list) != 1) { 918 918 psError(__func__,"psListGetPrevious didn't move cursor to previous."); 919 919 return 12; 920 920 } 921 if (*( int*)psListGetPrevious(list) != 0) {921 if (*(psS32*)psListGetPrevious(list) != 0) { 922 922 psError(__func__,"psListGetPrevious didn't move cursor to previous.."); 923 923 return 13; … … 939 939 } 940 940 941 inttestListFree(void)941 psS32 testListFree(void) 942 942 { 943 943 float* data[15]; … … 954 954 955 955 list = psListAlloc(NULL); 956 for ( intlcv=0;lcv<15;lcv++) {957 data[lcv] = psAlloc(sizeof( int));956 for (psS32 lcv=0;lcv<15;lcv++) { 957 data[lcv] = psAlloc(sizeof(psS32)); 958 958 *data[lcv] = lcv; 959 959 psListAdd(list,PS_LIST_TAIL,data[lcv]); … … 987 987 */ 988 988 989 for ( inti=0;i<15;i++) {989 for (psS32 i=0;i<15;i++) { 990 990 if (psMemGetRefCounter(data[i]) != 1) { 991 991 psError(__func__,"pslistFree didn't decrement the data item's reference counter"); … … 998 998 } 999 999 1000 inttestListSort(void)1000 psS32 testListSort(void) 1001 1001 { 1002 1002 psList* list; … … 1004 1004 list = psListAlloc(NULL); 1005 1005 1006 for ( intlcv=0;lcv<15;lcv++) {1007 float* data = psAlloc(sizeof( int));1006 for (psS32 lcv=0;lcv<15;lcv++) { 1007 float* data = psAlloc(sizeof(psS32)); 1008 1008 if (lcv < 7) { 1009 1009 *data = 13-lcv*2; … … 1070 1070 list = psListAlloc(NULL); 1071 1071 1072 for ( intlcv=0;lcv<15;lcv++) {1073 psU32* data = psAlloc(sizeof( int));1072 for (psS32 lcv=0;lcv<15;lcv++) { 1073 psU32* data = psAlloc(sizeof(psS32)); 1074 1074 if (lcv < 7) { 1075 1075 *data = 13-lcv*2;
Note:
See TracChangeset
for help on using the changeset viewer.
