IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 923


Ignore:
Timestamp:
Jun 8, 2004, 9:39:28 AM (22 years ago)
Author:
desonia
Message:

added test for list iterators

File:
1 edited

Legend:

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

    r921 r923  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-08 19:12:05 $
     8 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-08 19:39:28 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    760760{
    761761    int currentId = psMemGetId();
     762    psList* list = NULL;
     763    int* data;
    762764
    763765    psLogMsg(__func__,PS_LOG_INFO," psListSetIterator/psListGetNext/psListGetPrev"
    764766             " shall move the list cursor to the specified location");
    765767
     768    /*
     769            psDlistSetIterator(list,where) shall:
     770
     771            1. output error message and do nothing if list=NULL
     772            2. set list.cursor to list.head if where=PS_LIST_HEAD
     773            3. set list.cursor to list.tail if where=PS_LIST_TAIL
     774            4. set list.cursor to list.cursor->next if where=PS_LIST_NEXT
     775            5. set list.cursor to list.cursor->prev if where=PS_LIST_PREV
     776            6. leave list.cursor untouched if where=PS_LIST_UNKNOWN or PS_LIST_CURRENT
     777
     778            psDlistGetNext(list) shall be functionally equivalent to
     779            psDlistSetIterator(list,PS_LIST_NEXT) but returns list.cursor.
     780
     781            psDlistGetPrev(list) shall be functionally equivalent to
     782            psDlistSetIterator(list,PS_LIST_PREV) but returns list.cursor.
     783    */
     784
     785    // create a list
     786    list = psListAlloc(NULL);
     787    for (int lcv=0;lcv<15;lcv++) {
     788        data = psAlloc(sizeof(int));
     789        *data = lcv;
     790        list = psListAdd(list,data,PS_LIST_TAIL);
     791        psMemDecrRefCounter(data);
     792    }
     793
     794
     795    // 1. output error message and do nothing if list=NULL
     796    psLogMsg(__func__,PS_LOG_INFO,"Following should error with "
     797             "'Unexpected null pointer'");
     798    psListSetIterator(NULL,PS_LIST_HEAD);
     799
     800    // 3. set list.cursor to list.tail if where=PS_LIST_TAIL
     801    psListSetIterator(list,PS_LIST_TAIL);
     802    if (*(int*)psListGetCurrent(list) != 14) {
     803        psError(__func__,"Didn't successfully move cursor to tail.");
     804        return 1;
     805    }
     806
     807    // 2. set list.cursor to list.head if where=PS_LIST_HEAD
     808    psListSetIterator(list,PS_LIST_HEAD);
     809    if (*(int*)psListGetCurrent(list) != 0) {
     810        psError(__func__,"Didn't successfully move cursor to head.");
     811        return 2;
     812    }
     813
     814    // 4. set list.cursor to list.cursor->next if where=PS_LIST_NEXT
     815    psListSetIterator(list,PS_LIST_NEXT);
     816    if (*(int*)psListGetCurrent(list) != 1) {
     817        psError(__func__,"Didn't successfully move cursor to next.");
     818        return 3;
     819    }
     820    psListSetIterator(list,PS_LIST_NEXT);
     821    if (*(int*)psListGetCurrent(list) != 2) {
     822        psError(__func__,"Didn't successfully move cursor to next twice.");
     823        return 4;
     824    }
     825
     826    // 5. set list.cursor to list.cursor->prev if where=PS_LIST_PREV
     827    psListSetIterator(list,PS_LIST_PREVIOUS);
     828    if (*(int*)psListGetCurrent(list) != 1) {
     829        psError(__func__,"Didn't successfully move cursor to previous.");
     830        return 5;
     831    }
     832    psListSetIterator(list,PS_LIST_PREVIOUS);
     833    if (*(int*)psListGetCurrent(list) != 0) {
     834        psError(__func__,"Didn't successfully move cursor to previous twice.");
     835        return 6;
     836    }
     837
     838    // 6. leave list.cursor untouched if where=PS_LIST_UNKNOWN or PS_LIST_CURRENT
     839    psListSetIterator(list,PS_LIST_NEXT);   // move off of head (works according to above)
     840    psLogMsg(__func__,PS_LOG_INFO,"Following should error with 'Can't move to an unknown position.'");
     841    psListSetIterator(list,PS_LIST_UNKNOWN);
     842    if (*(int*)psListGetCurrent(list) != 1) {
     843        psError(__func__,"PS_LIST_UNKNOWN moved cursor.");
     844        return 7;
     845    }
     846    psListSetIterator(list,PS_LIST_CURRENT);
     847    if (*(int*)psListGetCurrent(list) != 1) {
     848        psError(__func__,"PS_LIST_CURRENT moved cursor.");
     849        return 8;
     850    }
     851
     852    // test psListGetPrevious/Next
     853    if (*(int*)psListGetNext(list) != 2) {
     854        psError(__func__,"psListGetNext didn't move cursor to next.");
     855        return 9;
     856    }
     857    if (*(int*)psListGetNext(list) != 3) {
     858        psError(__func__,"psListGetNext didn't move cursor to next.");
     859        return 10;
     860    }
     861    if (*(int*)psListGetPrevious(list) != 2) {
     862        psError(__func__,"psListGetPrevious didn't move cursor to previous.");
     863        return 11;
     864    }
     865    if (*(int*)psListGetPrevious(list) != 1) {
     866        psError(__func__,"psListGetPrevious didn't move cursor to previous.");
     867        return 12;
     868    }
     869    if (*(int*)psListGetPrevious(list) != 0) {
     870        psError(__func__,"psListGetPrevious didn't move cursor to previous..");
     871        return 13;
     872    }
     873    if (psListGetPrevious(list) != NULL) {
     874        psError(__func__,"psListGetPrevious moved cursor beyond head.");
     875        return 14;
     876    }
     877
     878    psListSetIterator(list,PS_LIST_TAIL); // works according to an above test
     879    if (psListGetNext(list) != NULL) {
     880        psError(__func__,"psListGetNext moved cursor beyond tail.");
     881        return 15;
     882    }
     883
    766884    psMemCheckLeaks(currentId,NULL,NULL);
    767885    psMemCheckCorruption(1);
Note: See TracChangeset for help on using the changeset viewer.