IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 26, 2004, 2:57:34 PM (22 years ago)
Author:
desonia
Message:

converted native C types to ps Types, where practical.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/collections/tst_psList.c

    r1749 r2204  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.16 $ $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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818
    1919
    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);
    26 static int testListFree(void);
    27 static int testListSort(void);
     20static psS32 testListAlloc(void);
     21static psS32 testListAdd(void);
     22static psS32 testListGet(void);
     23static psS32 testListRemove(void);
     24static psS32 testListConvert(void);
     25static psS32 testListIterator(void);
     26static psS32 testListFree(void);
     27static psS32 testListSort(void);
    2828
    2929testDescription tests[] = {
     
    3939                          };
    4040
    41 int main(int argc, char* argv[])
     41psS32 main(psS32 argc, char* argv[])
    4242{
    4343    psLogSetLevel(PS_LOG_INFO);
     
    5050}
    5151
    52 int testListAlloc(void)
     52psS32 testListAlloc(void)
    5353{
    5454    psList* list;
    55     int ref;
     55    psS32 ref;
    5656    float* data;
    5757
     
    117117}
    118118
    119 int testListAdd(void)
     119psS32 testListAdd(void)
    120120{
    121121    psList* list = NULL;
    122     int* data = NULL;
     122    psS32* data = NULL;
    123123
    124124    psLogMsg(__func__,PS_LOG_INFO,"psListAdd shall add an element to list");
     
    134134    */
    135135
    136     data = psAlloc(sizeof(int));
     136    data = psAlloc(sizeof(psS32));
    137137    *data = 1;
    138138
     
    161161
    162162    //  3. where is PS_LIST_HEAD or PS_LIST_TAIL
    163     data = psAlloc(sizeof(int));
     163    data = psAlloc(sizeof(psS32));
    164164    *data = 2;
    165165    if ( ! psListAdd(list,PS_LIST_HEAD,data) ) {
     
    181181
    182182    // verify that the head is the inserted data item
    183     if (*(int*)list->head->data != 2) {
     183    if (*(psS32*)list->head->data != 2) {
    184184        psError(__func__,"psListAdd with PS_LIST_HEAD didn't insert at the head.");
    185185        return 5;
    186186    }
    187187
    188     data = psAlloc(sizeof(int));
     188    data = psAlloc(sizeof(psS32));
    189189    *data = 3;
    190190    if ( ! psListAdd(list,PS_LIST_TAIL,data) ) {
     
    205205
    206206    // verify that the head is still the same
    207     if (*(int*)list->head->data != 2) {
     207    if (*(psS32*)list->head->data != 2) {
    208208        psError(__func__,"psListAdd with PS_LIST_TAIL modified the head.");
    209209        return 7;
     
    211211
    212212    // verify that the tail is the data item inserted
    213     if (*(int*)list->tail->data != 3) {
     213    if (*(psS32*)list->tail->data != 3) {
    214214        psError(__func__,"psListAdd with PS_LIST_TAIL didn't insert at the tail.");
    215215        return 8;
     
    218218    // 4. where is not PS_LIST_* but <0
    219219
    220     data = psAlloc(sizeof(int));
     220    data = psAlloc(sizeof(psS32));
    221221    *data = 4;
    222222    psLogMsg(__func__,PS_LOG_INFO,"Following should error with invalid insert location");
     
    239239
    240240    // 5. where is >0
    241     data = psAlloc(sizeof(int));
     241    data = psAlloc(sizeof(psS32));
    242242    *data = 5;
    243243
     
    253253    psFree(data);
    254254    // 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) {
    256256        printListInt(list);
    257257        psError(__func__,"psListAdd didn't insert to position #1.");
     
    259259    }
    260260
    261     data = psAlloc(sizeof(int));
     261    data = psAlloc(sizeof(psS32));
    262262    *data = 6;
    263263    if ( ! psListAdd(list,3,data) ) {
     
    271271    psFree(data);
    272272    // 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) {
    274274        printListInt(list);
    275275        psError(__func__,"psListAdd didn't insert to position #4.");
     
    277277    }
    278278
    279     data = psAlloc(sizeof(int));
     279    data = psAlloc(sizeof(psS32));
    280280    *data = 7;
    281281    if ( ! psListAdd(list,2,data) ) {
     
    289289    psFree(data);
    290290    // 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) {
    292292        printListInt(list);
    293293        psError(__func__,"psListAdd didn't insert to position #2.");
     
    295295    }
    296296
    297     data = psAlloc(sizeof(int));
     297    data = psAlloc(sizeof(psS32));
    298298    *data = 7;
    299299    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
     
    325325void printListInt(psList* list)
    326326{
    327     int* data = NULL;
    328     bool first = true;
     327    psS32* data = NULL;
     328    psBool first = true;
    329329
    330330    psListSetIterator(list,PS_LIST_HEAD);
     
    333333    while ( data != NULL ) {
    334334        if (!first) {
    335             printf(", %d",*(int*)data);
     335            printf(", %d",*(psS32*)data);
    336336        } else {
    337             printf("%d",*(int*)data);
     337            printf("%d",*(psS32*)data);
    338338            first = false;
    339339        }
     
    345345
    346346
    347 int testListGet(void)
     347psS32 testListGet(void)
    348348{
    349349    psList* list = NULL;
    350     int* data;
     350    psS32* data;
    351351
    352352    /*
     
    371371
    372372    // create a list
    373     data = psAlloc(sizeof(int));
     373    data = psAlloc(sizeof(psS32));
    374374    *data = 0;
    375375    list = psListAlloc(data);
    376376    psFree(data);
    377377
    378     data = psAlloc(sizeof(int));
     378    data = psAlloc(sizeof(psS32));
    379379    *data = 1;
    380380    psListAdd(list,PS_LIST_TAIL,data);
    381381    psFree(data);
    382382
    383     data = psAlloc(sizeof(int));
     383    data = psAlloc(sizeof(psS32));
    384384    *data = 2;
    385385    psListAdd(list,PS_LIST_TAIL,data);
    386386    psFree(data);
    387387
    388     data = psAlloc(sizeof(int));
     388    data = psAlloc(sizeof(psS32));
    389389    *data = 3;
    390390    psListAdd(list,PS_LIST_TAIL,data);
     
    392392
    393393    //  2. which>0 and which<list.n.
    394     data = (int*)psListGet(list,3);
     394    data = (psS32*)psListGet(list,3);
    395395    if (data == NULL || *data != 3) {
    396396        psError(__func__,"psListGet failed with which=3");
    397397        return 2;
    398398    }
    399     data = (int*)psListGet(list,1);
     399    data = (psS32*)psListGet(list,1);
    400400    if (data == NULL || *data != 1) {
    401401        psError(__func__,"psListGet failed with which=1");
     
    404404
    405405    //  3. which>=list.n.
    406     data = (int*)psListGet(list,5);
     406    data = (psS32*)psListGet(list,5);
    407407    if (data != NULL) {
    408408        psError(__func__,"psListGet failed with which=5");
    409409        return 4;
    410410    }
    411     data = (int*)psListGet(list,4);
     411    data = (psS32*)psListGet(list,4);
    412412    if (data != NULL) {
    413413        psError(__func__,"psListGet failed with which=4");
     
    416416
    417417    //  4. which=PS_LIST_HEAD
    418     data = (int*)psListGet(list,PS_LIST_HEAD);
     418    data = (psS32*)psListGet(list,PS_LIST_HEAD);
    419419    if (data == NULL || *data != 0) {
    420420        psError(__func__,"psListGet failed with which=PS_LIST_HEAD");
     
    423423
    424424    //  5. which=PS_LIST_NEXT
    425     data = (int*)psListGet(list,PS_LIST_NEXT);
     425    data = (psS32*)psListGet(list,PS_LIST_NEXT);
    426426    if (data == NULL || *data != 1) {
    427427        psError(__func__,"psListGet failed with which=PS_LIST_NEXT");
     
    430430
    431431    //  6. which=PS_LIST_TAIL
    432     data = (int*)psListGet(list,PS_LIST_TAIL);
     432    data = (psS32*)psListGet(list,PS_LIST_TAIL);
    433433    if (data == NULL || *data != 3) {
    434434        psError(__func__,"psListGet failed with which=PS_LIST_TAIL");
     
    437437
    438438    //  7. which=PS_LIST_PREV
    439     data = (int*)psListGet(list,PS_LIST_PREVIOUS);
     439    data = (psS32*)psListGet(list,PS_LIST_PREVIOUS);
    440440    if (data == NULL || *data != 2) {
    441441        psError(__func__,"psListGet failed with which=PS_LIST_PREV");
     
    448448}
    449449
    450 int testListRemove(void)
     450psS32 testListRemove(void)
    451451{
    452452    psList* list = NULL;
    453     int* data;
     453    psS32* data;
    454454
    455455    /*
     
    480480    list = psListAlloc(NULL);
    481481
    482     for (int lcv=0;lcv<15;lcv++) {
    483         data = psAlloc(sizeof(int));
     482    for (psS32 lcv=0;lcv<15;lcv++) {
     483        data = psAlloc(sizeof(psS32));
    484484        *data = lcv;
    485485        psListAdd(list,PS_LIST_TAIL,data);
     
    682682}
    683683
    684 int testListConvert(void)
     684psS32 testListConvert(void)
    685685{
    686686
    687687    psList* list = NULL;
    688688    psArray* arr = NULL;
    689     int* data;
     689    psS32* data;
    690690
    691691    /*
    692692        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.
    694694        The list shall not be changed, except for the element reference increment.
    695695    */
     
    699699    // create a list
    700700    list = psListAlloc(NULL);
    701     for (int lcv=0;lcv<15;lcv++) {
    702         data = psAlloc(sizeof(int));
     701    for (psS32 lcv=0;lcv<15;lcv++) {
     702        data = psAlloc(sizeof(psS32));
    703703        *data = lcv;
    704704        psListAdd(list,PS_LIST_TAIL,data);
     
    712712        return 1;
    713713    }
    714     for (int i=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]) {
    716716            psError(__func__,"Element %d of array is incorrect (%d).",
    717                     i,*(int*)arr->data[i]);
     717                    i,*(psS32*)arr->data[i]);
    718718            return 1;
    719719        }
    720         if (i != *(int*)psListGet(list,i)) {
     720        if (i != *(psS32*)psListGet(list,i)) {
    721721            psError(__func__,"Element %d of list is incorrect (%d).",
    722                     i,*(int*)arr->data[i]);
     722                    i,*(psS32*)arr->data[i]);
    723723            return 1;
    724724        }
     
    738738    arr = psArrayAlloc(15);
    739739    arr->n = arr->nalloc;
    740     for (int lcv=0;lcv<15;lcv++) {
    741         data = psAlloc(sizeof(int));
     740    for (psS32 lcv=0;lcv<15;lcv++) {
     741        data = psAlloc(sizeof(psS32));
    742742        *data = lcv;
    743743        arr->data[lcv] = data;
     
    750750        return 1;
    751751    }
    752     for (int i=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]) {
    754754            psError(__func__,"Element %d of array is incorrect (%d).",
    755                     i,*(int*)arr->data[i]);
     755                    i,*(psS32*)arr->data[i]);
    756756            return 1;
    757757        }
    758         if (i != *(int*)psListGet(list,i)) {
     758        if (i != *(psS32*)psListGet(list,i)) {
    759759            psError(__func__,"Element %d of list is incorrect (%d).",
    760                     i,*(int*)arr->data[i]);
     760                    i,*(psS32*)arr->data[i]);
    761761            return 1;
    762762        }
     
    810810}
    811811
    812 int testListIterator(void)
     812psS32 testListIterator(void)
    813813{
    814814    psList* list = NULL;
    815     int* data;
     815    psS32* data;
    816816
    817817    psLogMsg(__func__,PS_LOG_INFO," psListSetIterator/psListGetNext/psListGetPrev"
     
    837837    // create a list
    838838    list = psListAlloc(NULL);
    839     for (int lcv=0;lcv<15;lcv++) {
    840         data = psAlloc(sizeof(int));
     839    for (psS32 lcv=0;lcv<15;lcv++) {
     840        data = psAlloc(sizeof(psS32));
    841841        *data = lcv;
    842842        psListAdd(list,PS_LIST_TAIL,data);
     
    852852    // 3. set list.cursor to list.tail if where=PS_LIST_TAIL
    853853    psListSetIterator(list,PS_LIST_TAIL);
    854     if (*(int*)psListGetCurrent(list) != 14) {
     854    if (*(psS32*)psListGetCurrent(list) != 14) {
    855855        psError(__func__,"Didn't successfully move cursor to tail.");
    856856        return 1;
     
    859859    // 2. set list.cursor to list.head if where=PS_LIST_HEAD
    860860    psListSetIterator(list,PS_LIST_HEAD);
    861     if (*(int*)psListGetCurrent(list) != 0) {
     861    if (*(psS32*)psListGetCurrent(list) != 0) {
    862862        psError(__func__,"Didn't successfully move cursor to head.");
    863863        return 2;
     
    866866    // 4. set list.cursor to list.cursor->next if where=PS_LIST_NEXT
    867867    psListSetIterator(list,PS_LIST_NEXT);
    868     if (*(int*)psListGetCurrent(list) != 1) {
     868    if (*(psS32*)psListGetCurrent(list) != 1) {
    869869        psError(__func__,"Didn't successfully move cursor to next.");
    870870        return 3;
    871871    }
    872872    psListSetIterator(list,PS_LIST_NEXT);
    873     if (*(int*)psListGetCurrent(list) != 2) {
     873    if (*(psS32*)psListGetCurrent(list) != 2) {
    874874        psError(__func__,"Didn't successfully move cursor to next twice.");
    875875        return 4;
     
    878878    // 5. set list.cursor to list.cursor->prev if where=PS_LIST_PREV
    879879    psListSetIterator(list,PS_LIST_PREVIOUS);
    880     if (*(int*)psListGetCurrent(list) != 1) {
     880    if (*(psS32*)psListGetCurrent(list) != 1) {
    881881        psError(__func__,"Didn't successfully move cursor to previous.");
    882882        return 5;
    883883    }
    884884    psListSetIterator(list,PS_LIST_PREVIOUS);
    885     if (*(int*)psListGetCurrent(list) != 0) {
     885    if (*(psS32*)psListGetCurrent(list) != 0) {
    886886        psError(__func__,"Didn't successfully move cursor to previous twice.");
    887887        return 6;
     
    892892    psLogMsg(__func__,PS_LOG_INFO,"Following should error with 'Can't move to an unknown position.'");
    893893    psListSetIterator(list,PS_LIST_UNKNOWN);
    894     if (*(int*)psListGetCurrent(list) != 1) {
     894    if (*(psS32*)psListGetCurrent(list) != 1) {
    895895        psError(__func__,"PS_LIST_UNKNOWN moved cursor.");
    896896        return 7;
    897897    }
    898898    psListSetIterator(list,PS_LIST_CURRENT);
    899     if (*(int*)psListGetCurrent(list) != 1) {
     899    if (*(psS32*)psListGetCurrent(list) != 1) {
    900900        psError(__func__,"PS_LIST_CURRENT moved cursor.");
    901901        return 8;
     
    903903
    904904    // test psListGetPrevious/Next
    905     if (*(int*)psListGetNext(list) != 2) {
     905    if (*(psS32*)psListGetNext(list) != 2) {
    906906        psError(__func__,"psListGetNext didn't move cursor to next.");
    907907        return 9;
    908908    }
    909     if (*(int*)psListGetNext(list) != 3) {
     909    if (*(psS32*)psListGetNext(list) != 3) {
    910910        psError(__func__,"psListGetNext didn't move cursor to next.");
    911911        return 10;
    912912    }
    913     if (*(int*)psListGetPrevious(list) != 2) {
     913    if (*(psS32*)psListGetPrevious(list) != 2) {
    914914        psError(__func__,"psListGetPrevious didn't move cursor to previous.");
    915915        return 11;
    916916    }
    917     if (*(int*)psListGetPrevious(list) != 1) {
     917    if (*(psS32*)psListGetPrevious(list) != 1) {
    918918        psError(__func__,"psListGetPrevious didn't move cursor to previous.");
    919919        return 12;
    920920    }
    921     if (*(int*)psListGetPrevious(list) != 0) {
     921    if (*(psS32*)psListGetPrevious(list) != 0) {
    922922        psError(__func__,"psListGetPrevious didn't move cursor to previous..");
    923923        return 13;
     
    939939}
    940940
    941 int testListFree(void)
     941psS32 testListFree(void)
    942942{
    943943    float* data[15];
     
    954954
    955955    list = psListAlloc(NULL);
    956     for (int lcv=0;lcv<15;lcv++) {
    957         data[lcv] = psAlloc(sizeof(int));
     956    for (psS32 lcv=0;lcv<15;lcv++) {
     957        data[lcv] = psAlloc(sizeof(psS32));
    958958        *data[lcv] = lcv;
    959959        psListAdd(list,PS_LIST_TAIL,data[lcv]);
     
    987987    */
    988988
    989     for (int i=0;i<15;i++) {
     989    for (psS32 i=0;i<15;i++) {
    990990        if (psMemGetRefCounter(data[i]) != 1) {
    991991            psError(__func__,"pslistFree didn't decrement the data item's reference counter");
     
    998998}
    999999
    1000 int testListSort(void)
     1000psS32 testListSort(void)
    10011001{
    10021002    psList* list;
     
    10041004    list = psListAlloc(NULL);
    10051005
    1006     for (int lcv=0;lcv<15;lcv++) {
    1007         float* data = psAlloc(sizeof(int));
     1006    for (psS32 lcv=0;lcv<15;lcv++) {
     1007        float* data = psAlloc(sizeof(psS32));
    10081008        if (lcv < 7) {
    10091009            *data = 13-lcv*2;
     
    10701070    list = psListAlloc(NULL);
    10711071
    1072     for (int lcv=0;lcv<15;lcv++) {
    1073         psU32* data = psAlloc(sizeof(int));
     1072    for (psS32 lcv=0;lcv<15;lcv++) {
     1073        psU32* data = psAlloc(sizeof(psS32));
    10741074        if (lcv < 7) {
    10751075            *data = 13-lcv*2;
Note: See TracChangeset for help on using the changeset viewer.