IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

changed psDlist to psList.

File:
1 edited

Legend:

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

    r917 r920  
    1 /** @file  tst_psDlist.c
     1/** @file  tst_psList.c
    22 *
    3  *  @brief Contains the tests for psDlist.[ch]
     3 *  @brief Contains the tests for psList.[ch]
    44 *
    55 *
    66 *  @author Robert DeSonia, MHPCC
    77 *
    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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515#include "pslib.h"
    1616
    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);
     17void printListInt(psList* list);
     18
     19
     20static int testListAlloc(void);
     21static int testListAdd(void);
     22static int testListGet(void);
     23static int testListRemove(void);
     24static int testListConvert(void);
     25static int testListIterator(void);
    2526
    2627testDescription 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},
    3234                              {NULL}
    3335                          };
     
    3739    psSetLogLevel(PS_LOG_INFO);
    3840
    39     if (! runTestSuite(stderr,"psDlist",tests)) {
     41    if (! runTestSuite(stderr,"psList",tests)) {
    4042        psAbort(__FILE__,"One or more tests failed");
    4143    }
     
    4345}
    4446
    45 int testDlistAlloc(void)
     47int testListAlloc(void)
    4648{
    4749    int currentId = psMemGetId();
    48     psDlist* list;
     50    psList* list;
    4951    int ref;
    5052    float* data;
    5153
    52     psLogMsg(__func__,PS_LOG_INFO,"psDlistAlloc 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.");
    5355
    5456    data = psAlloc(sizeof(float));
    5557
    56     // if psDlistAlloc is invoked with a NULL parameter, it shall return an
    57     // empty psDlist struct with head=tail=NULL and n=0. Otherwise, it shall
    58     // return a psDlist of one element (head=tail=data, n=1).
    59 
    60     list = psDlistAlloc(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);
    6163    if (list == NULL) {
    62         psError(__func__,"psDlistAlloc failed to return a list.");
     64        psError(__func__,"psListAlloc failed to return a list.");
    6365        return 1;
    6466    }
     
    7476    }
    7577
    76     psDlistFree(list,NULL);
    77 
    78     list = psDlistAlloc(data);
     78    psListFree(list,NULL);
     79
     80    list = psListAlloc(data);
    7981    if (list == NULL) {
    80         psError(__func__,"psDlistAlloc failed to return a list.");
     82        psError(__func__,"psListAlloc failed to return a list.");
    8183        return 4;
    8284    }
     
    99101    ref = psMemGetRefCounter(data);
    100102    if (ref != 2) {
    101         psError(__func__,"psDlist didn't increment reference count of data (%d.",ref);
     103        psError(__func__,"psList didn't increment reference count of data (%d.",ref);
    102104        return 8;
    103105    }
    104106
    105107
    106     psDlistFree(list,PS_FREE);
     108    psListFree(list,PS_FREE);
    107109
    108110    psMemCheckLeaks(currentId,NULL,NULL);
     
    112114}
    113115
    114 int testDlistAdd(void)
     116int testListAdd(void)
    115117{
    116118    int currentId = psMemGetId();
    117     psDlist* list = NULL;
     119    psList* list = NULL;
    118120    int* data;
    119121
    120     psLogMsg(__func__,PS_LOG_INFO,"psDlistAdd shall add an element to list");
     122    psLogMsg(__func__,PS_LOG_INFO,"psListAdd shall add an element to list");
    121123
    122124    /*
    123         psDlistAdd(list,data,where) should be tested in the instance where:
     125        psListAdd(list,data,where) should be tested in the instance where:
    124126
    125127        1. list is NULL (error)
    126128        2. data is NULL (error, list should not grow)
    127         3. where is PS_DLIST_HEAD or PS_DLIST_TAIL
    128         4. where is not PS_DLIST_* but <0
     129        3. where is PS_LIST_HEAD or PS_LIST_TAIL
     130        4. where is not PS_LIST_* but <0
    129131        5. where is >0
    130132    */
    131133
    132134    //  1. list is NULL (error)
    133     list = psDlistAdd(NULL,data,PS_DLIST_HEAD);
     135    list = psListAdd(NULL,data,PS_LIST_HEAD);
    134136
    135137    if (list != NULL) {
    136         psError(__func__,"psDlistAdd 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.");
    137139        return 1;
    138140    }
     
    141143    data = psAlloc(sizeof(int));
    142144    *data = 1;
    143     list = psDlistAlloc(data);
     145    list = psListAlloc(data);
    144146    if (list->size != 1) {
    145         psError(__func__,"psDlistAlloc didn't create a list properly.");
     147        psError(__func__,"psListAlloc didn't create a list properly.");
    146148        return 2;
    147149    }
    148150
    149     list = psDlistAdd(list, NULL,PS_DLIST_HEAD);
     151    list = psListAdd(list, NULL,PS_LIST_HEAD);
    150152
    151153    if (list->size != 1) {
    152         psError(__func__,"psDlistAdd with a NULL data element changed the list size.");
     154        psError(__func__,"psListAdd with a NULL data element changed the list size.");
    153155        return 3;
    154156    }
    155157
    156     //  3. where is PS_DLIST_HEAD or PS_DLIST_TAIL
     158    //  3. where is PS_LIST_HEAD or PS_LIST_TAIL
    157159    data = psAlloc(sizeof(int));
    158160    *data = 2;
    159     list = psDlistAdd(list,data,PS_DLIST_HEAD);
     161    list = psListAdd(list,data,PS_LIST_HEAD);
    160162
    161163    // verify that the size incremented
    162164    if (list->size != 2) {
    163         psError(__func__,"psDlistAdd didn't increment the size by one");
     165        psError(__func__,"psListAdd didn't increment the size by one");
    164166        return 4;
    165167    }
     
    167169    // verify that the head is the inserted data item
    168170    if (*(int*)list->head->data != 2) {
    169         psError(__func__,"psDlistAdd with PS_DLIST_HEAD didn't insert at the head.");
     171        psError(__func__,"psListAdd with PS_LIST_HEAD didn't insert at the head.");
    170172        return 5;
    171173    }
     
    173175    data = psAlloc(sizeof(int));
    174176    *data = 3;
    175     list = psDlistAdd(list,data,PS_DLIST_TAIL);
     177    list = psListAdd(list,data,PS_LIST_TAIL);
    176178
    177179    // verify that the size incremented
    178180    if (list->size != 3) {
    179         psError(__func__,"psDlistAdd didn't increment the size by 1");
     181        psError(__func__,"psListAdd didn't increment the size by 1");
    180182        return 6;
    181183    }
     
    183185    // verify that the head is still the same
    184186    if (*(int*)list->head->data != 2) {
    185         psError(__func__,"psDlistAdd with PS_DLIST_TAIL modified the head.");
     187        psError(__func__,"psListAdd with PS_LIST_TAIL modified the head.");
    186188        return 7;
    187189    }
     
    189191    // verify that the tail is the data item inserted
    190192    if (*(int*)list->tail->data != 3) {
    191         psError(__func__,"psDlistAdd with PS_DLIST_TAIL didn't insert at the tail.");
     193        psError(__func__,"psListAdd with PS_LIST_TAIL didn't insert at the tail.");
    192194        return 8;
    193195    }
    194196
    195     // 4. where is not PS_DLIST_* but <0
     197    // 4. where is not PS_LIST_* but <0
    196198
    197199    data = psAlloc(sizeof(int));
     
    199201
    200202    psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location");
    201     list = psDlistAdd(list,data,-10);
     203    list = psListAdd(list,data,-10);
    202204    // verify that the size incremented
    203205    if (list->size != 4 || *(int*)list->head->data != 4) {
    204206        printListInt(list);
    205         psError(__func__,"psDlistAdd didn't insert to head when where was invalid.");
     207        psError(__func__,"psListAdd didn't insert to head when where was invalid.");
    206208        return 9;
    207209    }
     
    210212    data = psAlloc(sizeof(int));
    211213    *data = 5;
    212     list = psDlistAdd(list,data,1);
     214    list = psListAdd(list,data,1);
    213215    // verify that the size incremented
    214216    if (list->size != 5 || *(int*)list->head->next->data != 5) {
    215217        printListInt(list);
    216         psError(__func__,"psDlistAdd didn't insert to position #1.");
     218        psError(__func__,"psListAdd didn't insert to position #1.");
    217219        return 9;
    218220    }
     
    220222    data = psAlloc(sizeof(int));
    221223    *data = 6;
    222     list = psDlistAdd(list,data,4);
     224    list = psListAdd(list,data,4);
    223225    // verify that the size incremented
    224226    if (list->size != 6  || *(int *)list->head->next->next->next->next->data != 6) {
    225227        printListInt(list);
    226         psError(__func__,"psDlistAdd didn't insert to position #4.");
     228        psError(__func__,"psListAdd didn't insert to position #4.");
    227229        return 9;
    228230    }
     
    230232    data = psAlloc(sizeof(int));
    231233    *data = 7;
    232     list = psDlistAdd(list,data,2);
     234    list = psListAdd(list,data,2);
    233235    // verify that the size incremented
    234236    if (list->size != 7  || *(int *)list->head->next->next->data != 7) {
    235237        printListInt(list);
    236         psError(__func__,"psDlistAdd didn't insert to position #2.");
     238        psError(__func__,"psListAdd didn't insert to position #2.");
    237239        return 9;
    238240    }
     
    241243    *data = 7;
    242244    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
    243     list = psDlistAdd(list,data,9);
     245    list = psListAdd(list,data,9);
    244246    // verify that the size incremented
    245247    if (list->size != 8) {
    246248        printListInt(list);
    247         psError(__func__,"psDlistAdd didn't insert to position #9.");
     249        psError(__func__,"psListAdd didn't insert to position #9.");
    248250        return 9;
    249251    }
    250252
    251     psDlistFree(list, PS_FREE);
     253    psListFree(list, PS_FREE);
    252254
    253255    psMemCheckLeaks(currentId,NULL,NULL);
     
    257259}
    258260
    259 void printListInt(psDlist* list)
     261void printListInt(psList* list)
    260262{
    261263    int* data = NULL;
    262264    bool first = true;
    263265
    264     psDlistSetIterator(list,PS_DLIST_HEAD);
    265     data = psDlistGetCurrent(list);
     266    psListSetIterator(list,PS_LIST_HEAD);
     267    data = psListGetCurrent(list);
    266268
    267269    while ( data != NULL ) {
     
    272274            first = false;
    273275        }
    274         data = psDlistGetNext(list);
     276        data = psListGetNext(list);
    275277    }
    276278
     
    279281
    280282
    281 int testDlistGet(void)
     283int testListGet(void)
    282284{
    283285    int currentId = psMemGetId();
    284     psDlist* list = NULL;
     286    psList* list = NULL;
    285287    int* data;
    286288
    287289    /*
    288      psDlistGet(list,which) shall be tested with the following instances
     290     psListGet(list,which) shall be tested with the following instances
    289291
    290292        1. list is NULL.
    291293        2. which>0 and which<list.n.
    292294        3. which>list.n.
    293         4. which=PS_DLIST_HEAD
    294         5. which=PS_DLIST_NEXT
    295         6. which=PS_DLIST_TAIL
    296         7. which=PS_DLIST_PREV
    297         8. which<0 and not any PS_DLIST_* values
     295        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
    298300    */
    299301
    300302    //  1. list is NULL.
    301303    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error");
    302     if (psDlistGet(list,PS_DLIST_HEAD) != NULL) {
    303         psError(__func__,"psDlistGet 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.");
    304306        return 1;
    305307    };
     
    308310    data = psAlloc(sizeof(int));
    309311    *data = 0;
    310     list = psDlistAlloc(data);
     312    list = psListAlloc(data);
    311313
    312314    data = psAlloc(sizeof(int));
    313315    *data = 1;
    314     list = psDlistAdd(list,data,PS_DLIST_TAIL);
     316    list = psListAdd(list,data,PS_LIST_TAIL);
    315317
    316318    data = psAlloc(sizeof(int));
    317319    *data = 2;
    318     list = psDlistAdd(list,data,PS_DLIST_TAIL);
     320    list = psListAdd(list,data,PS_LIST_TAIL);
    319321
    320322    data = psAlloc(sizeof(int));
    321323    *data = 3;
    322     list = psDlistAdd(list,data,PS_DLIST_TAIL);
     324    list = psListAdd(list,data,PS_LIST_TAIL);
    323325
    324326    //  2. which>0 and which<list.n.
    325     data = (int*)psDlistGet(list,3);
     327    data = (int*)psListGet(list,3);
    326328    if (data == NULL || *data != 3) {
    327         psError(__func__,"psDlistGet failed with which=3");
     329        psError(__func__,"psListGet failed with which=3");
    328330        return 2;
    329331    }
    330     data = (int*)psDlistGet(list,1);
     332    data = (int*)psListGet(list,1);
    331333    if (data == NULL || *data != 1) {
    332         psError(__func__,"psDlistGet failed with which=1");
     334        psError(__func__,"psListGet failed with which=1");
    333335        return 3;
    334336    }
    335337
    336338    //  3. which>=list.n.
    337     data = (int*)psDlistGet(list,5);
     339    data = (int*)psListGet(list,5);
    338340    if (data != NULL) {
    339         psError(__func__,"psDlistGet failed with which=5");
     341        psError(__func__,"psListGet failed with which=5");
    340342        return 4;
    341343    }
    342     data = (int*)psDlistGet(list,4);
     344    data = (int*)psListGet(list,4);
    343345    if (data != NULL) {
    344         psError(__func__,"psDlistGet failed with which=4");
     346        psError(__func__,"psListGet failed with which=4");
    345347        return 5;
    346348    }
    347349
    348     //  4. which=PS_DLIST_HEAD
    349     data = (int*)psDlistGet(list,PS_DLIST_HEAD);
     350    //  4. which=PS_LIST_HEAD
     351    data = (int*)psListGet(list,PS_LIST_HEAD);
    350352    if (data == NULL || *data != 0) {
    351         psError(__func__,"psDlistGet failed with which=PS_DLIST_HEAD");
     353        psError(__func__,"psListGet failed with which=PS_LIST_HEAD");
    352354        return 6;
    353355    }
    354356
    355     //  5. which=PS_DLIST_NEXT
    356     data = (int*)psDlistGet(list,PS_DLIST_NEXT);
     357    //  5. which=PS_LIST_NEXT
     358    data = (int*)psListGet(list,PS_LIST_NEXT);
    357359    if (data == NULL || *data != 1) {
    358         psError(__func__,"psDlistGet failed with which=PS_DLIST_NEXT");
     360        psError(__func__,"psListGet failed with which=PS_LIST_NEXT");
    359361        return 7;
    360362    }
    361363
    362     //  6. which=PS_DLIST_TAIL
    363     data = (int*)psDlistGet(list,PS_DLIST_TAIL);
     364    //  6. which=PS_LIST_TAIL
     365    data = (int*)psListGet(list,PS_LIST_TAIL);
    364366    if (data == NULL || *data != 3) {
    365         psError(__func__,"psDlistGet failed with which=PS_DLIST_TAIL");
     367        psError(__func__,"psListGet failed with which=PS_LIST_TAIL");
    366368        return 8;
    367369    }
    368370
    369     //  7. which=PS_DLIST_PREV
    370     data = (int*)psDlistGet(list,PS_DLIST_PREVIOUS);
     371    //  7. which=PS_LIST_PREV
     372    data = (int*)psListGet(list,PS_LIST_PREVIOUS);
    371373    if (data == NULL || *data != 2) {
    372         psError(__func__,"psDlistGet failed with which=PS_DLIST_PREV");
     374        psError(__func__,"psListGet failed with which=PS_LIST_PREV");
    373375        return 9;
    374376    }
    375377
    376     psDlistFree(list,PS_FREE);
     378    psListFree(list,PS_FREE);
    377379
    378380    psMemCheckLeaks(currentId,NULL,NULL);
     
    382384}
    383385
    384 int testDlistRemove(void)
     386int testListRemove(void)
    385387{
    386388    int currentId = psMemGetId();
    387     psDlist* list = NULL;
     389    psList* list = NULL;
    388390    int* data;
    389391
    390392    /*
    391         psDlistRemove(list,data,which) should be tested under the following conditions:
     393        psListRemove(list,data,which) should be tested under the following conditions:
    392394
    393395        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 list
     396        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
    401403
    402404        In all conditions that are not an error, list.n shall be decremented and only the specified element
     
    407409    //  1. list is NULL.
    408410    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error");
    409     if (psDlistRemove(list,NULL,PS_DLIST_HEAD) != NULL) {
    410         psError(__func__,"psDlistGet 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.");
    411413        return 1;
    412414    };
    413415
    414416    // create a list
    415     list = psDlistAlloc(NULL);
     417    list = psListAlloc(NULL);
    416418
    417419    for (int lcv=0;lcv<15;lcv++) {
    418420        data = psAlloc(sizeof(int));
    419421        *data = lcv;
    420         list = psDlistAdd(list,data,PS_DLIST_TAIL);
     422        list = psListAdd(list,data,PS_LIST_TAIL);
    421423        psMemDecrRefCounter(data);
    422424    }
    423425
    424426
    425     // 2. which is PS_DLIST_HEAD (remove first element of list)
    426     data = psDlistRemove(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);
    427429    if (data == NULL || *data != 0) {
    428430        printListInt(list);
    429         psError(__func__,"Failed to remove PS_DLIST_HEAD");
     431        psError(__func__,"Failed to remove PS_LIST_HEAD");
    430432        return 1;
    431433    }
     
    437439    }
    438440
    439     // 3. which is PS_DLIST_TAIL (remove last element of list)
    440     data = psDlistRemove(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);
    441443    if (data == NULL || *data != 14) {
    442444        printListInt(list);
    443         psError(__func__,"Failed to remove PS_DLIST_TAIL");
     445        psError(__func__,"Failed to remove PS_LIST_TAIL");
    444446        return 1;
    445447    }
     
    451453    }
    452454
    453     // 4. which is PS_DLIST_NEXT (element right of cursor [which should be head,tail, and neither])
    454     psDlistSetIterator(list,PS_DLIST_HEAD);
    455     data = psDlistRemove(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);
    456458    if (data == NULL || *data != 2) {
    457459        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");
    459461        return 1;
    460462    }
     
    466468    }
    467469
    468     psDlistSetIterator(list,PS_DLIST_TAIL);
     470    psListSetIterator(list,PS_LIST_TAIL);
    469471    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
    470     data = psDlistRemove(list,NULL,PS_DLIST_NEXT);
     472    data = psListRemove(list,NULL,PS_LIST_NEXT);
    471473    if (data != NULL) {
    472474        printListInt(list);
    473         psError(__func__,"Removed something with PS_DLIST_NEXT @ PS_DLIST_TAIL");
    474         return 1;
    475     }
    476 
    477     psDlistSetIterator(list,2);
    478     data = psDlistRemove(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);
    479481    if (data == NULL || *data != 5) {
    480482        printListInt(list);
    481         psError(__func__,"Failed to remove PS_DLIST_NEXT @ which=2");
     483        psError(__func__,"Failed to remove PS_LIST_NEXT @ which=2");
    482484        return 1;
    483485    }
     
    489491    }
    490492
    491     // 5. which is PS_DLIST_PREV (element left of cursor [which should be head,tail, and neither])
    492     psDlistSetIterator(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);
    493495    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
    494     data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS);
     496    data = psListRemove(list,NULL,PS_LIST_PREVIOUS);
    495497    if (data != NULL) {
    496498        printListInt(list);
    497         psError(__func__,"removed something for PS_DLIST_PREVIOUS @ PS_DLIST_HEAD");
    498         return 1;
    499     }
    500 
    501     psDlistSetIterator(list,PS_DLIST_TAIL);
    502     data = psDlistRemove(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);
    503505    if (data == NULL || *data != 12) {
    504506        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");
    506508        return 1;
    507509    }
     
    513515    }
    514516
    515     psDlistSetIterator(list,2);
    516     data = psDlistRemove(list,NULL,PS_DLIST_PREVIOUS);
     517    psListSetIterator(list,2);
     518    data = psListRemove(list,NULL,PS_LIST_PREVIOUS);
    517519    if (data == NULL || *data != 3) {
    518520        printListInt(list);
    519         psError(__func__,"Failed to remove PS_DLIST_PREVIOUS @ which=2");
     521        psError(__func__,"Failed to remove PS_LIST_PREVIOUS @ which=2");
    520522        return 1;
    521523    }
     
    527529    }
    528530
    529     // 6. which is PS_DLIST_UNKNOWN and data=NULL (error)
     531    // 6. which is PS_LIST_UNKNOWN and data=NULL (error)
    530532    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
    531     data = psDlistRemove(list,NULL,PS_DLIST_UNKNOWN);
     533    data = psListRemove(list,NULL,PS_LIST_UNKNOWN);
    532534    if (data != NULL) {
    533535        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 = psDlistGet(list,PS_DLIST_HEAD);
    540     data = psDlistRemove(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);
    541543    if (data == NULL || *data != 1) {
    542544        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");
    544546        return 1;
    545547    }
     
    551553    }
    552554
    553     data = psDlistGet(list,PS_DLIST_TAIL);
    554     data = psDlistRemove(list,data,PS_DLIST_UNKNOWN);
     555    data = psListGet(list,PS_LIST_TAIL);
     556    data = psListRemove(list,data,PS_LIST_UNKNOWN);
    555557    if (data == NULL || *data != 13) {
    556558        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");
    558560        return 1;
    559561    }
     
    565567    }
    566568
    567     psDlistSetIterator(list,PS_DLIST_HEAD);
    568     data = psDlistGet(list,PS_DLIST_NEXT);
    569 
    570     data = psDlistRemove(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);
    571573    if (data == NULL || *data != 6) {
    572574        printListInt(list);
    573         psError(__func__,"Failed to remove PS_DLIST_UNKNOWN @ which=1");
     575        psError(__func__,"Failed to remove PS_LIST_UNKNOWN @ which=1");
    574576        return 1;
    575577    }
     
    581583    }
    582584
    583     // 8. which is PS_DLIST_UNKNOWN and data!=NULL and data!=any element in list
     585    // 8. which is PS_LIST_UNKNOWN and data!=NULL and data!=any element in list
    584586    psLogMsg(__func__,PS_LOG_INFO,"Next message should be an error");
    585     data = psDlistRemove(list,data,PS_DLIST_UNKNOWN);
     587    data = psListRemove(list,data,PS_LIST_UNKNOWN);
    586588    if (data != NULL) {
    587589        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");
    589591        return 1;
    590592    }
    591593
    592594    // clear out the list
    593     psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
    594     psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
    595     psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
    596     psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
    597     psFree(psDlistRemove(list,NULL,PS_DLIST_HEAD));
    598 
    599     data = psDlistRemove(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);
    600602    if (data == NULL || *data != 11) {
    601603        printListInt(list);
     
    611613    }
    612614
    613     psDlistFree(list,PS_FREE);
     615    psListFree(list,PS_FREE);
    614616
    615617    psMemCheckLeaks(currentId,NULL,NULL);
     
    620622}
    621623
    622 int testDlistConvert(void)
     624int testListConvert(void)
    623625{
    624626
    625627    int currentId = psMemGetId();
    626     psDlist* list = NULL;
     628    psList* list = NULL;
    627629    psVector* vec = NULL;
    628630    int* data;
    629631
    630632    /*
    631         array=psDlistToArray(list) shall take each element of the list, increment
     633        array=psListToArray(list) shall take each element of the list, increment
    632634        their reference, and insert them into the returned fresh void* array.
    633635        The list shall not be changed, except for the element reference increment.
     
    637639
    638640    // create a list
    639     list = psDlistAlloc(NULL);
     641    list = psListAlloc(NULL);
    640642    for (int lcv=0;lcv<15;lcv++) {
    641643        data = psAlloc(sizeof(int));
    642644        *data = lcv;
    643         list = psDlistAdd(list,data,PS_DLIST_TAIL);
     645        list = psListAdd(list,data,PS_LIST_TAIL);
    644646        psMemDecrRefCounter(data);
    645647    }
    646648
    647     vec = psDlistToVector(list);
     649    vec = psListToVector(list);
    648650
    649651    if (vec->n != 15 || list->size != 15) {
     
    657659            return 1;
    658660        }
    659         if (i != *(int*)psDlistGet(list,i)) {
     661        if (i != *(int*)psListGet(list,i)) {
    660662            psError(__func__,"Element %d of list is incorrect (%d).",
    661663                    i,*(int*)vec->data.PTR[i]);
     
    670672
    671673    psVectorFree(vec);
    672     psDlistFree(list,PS_FREE);
     674    psListFree(list,PS_FREE);
    673675
    674676    psMemCheckLeaks(currentId,NULL,NULL);
     
    698700            return 1;
    699701        }
    700         if (i != *(int*)psDlistGet(list,i)) {
     702        if (i != *(int*)psListGet(list,i)) {
    701703            psError(__func__,"Element %d of list is incorrect (%d).",
    702704                    i,*(int*)vec->data.PTR[i]);
     
    711713
    712714    psVectorFree(vec);
    713     psDlistFree(list,PS_FREE);
     715    psListFree(list,PS_FREE);
    714716
    715717    // now, make sure if input vector/list is NULL, output is NULL
    716718
    717     vec = psDlistToVector(NULL);
     719    vec = psListToVector(NULL);
    718720    if (vec != NULL) {
    719         psError(__func__,"psDlistToVector didn't return NULL when given NULL");
     721        psError(__func__,"psListToVector didn't return NULL when given NULL");
    720722        return 1;
    721723    }
     
    732734    list = psVectorToDlist(vec);
    733735    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.");
    735738        return 1;
    736739    }
    737740    psVectorFree(vec);
    738     psDlistFree(list,PS_FREE);
    739 
    740     list = psDlistAlloc(NULL);
    741     vec = psDlistToVector(list);
     741    psListFree(list,PS_FREE);
     742
     743    list = psListAlloc(NULL);
     744    vec = psListToVector(list);
    742745    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.");
    744748        return 1;
    745749    }
    746750    psVectorFree(vec);
    747     psDlistFree(list,PS_FREE);
     751    psListFree(list,PS_FREE);
    748752
    749753    psMemCheckLeaks(currentId,NULL,NULL);
     
    752756    return 0;
    753757}
     758
     759int 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.