IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 7, 2004, 3:05:01 PM (22 years ago)
Author:
desonia
Message:

rewrote psImageCopy so that macro need not be expanded.

File:
1 edited

Legend:

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

    r1126 r1193  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-29 23:18:00 $
     8 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-08 01:05:01 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828
    2929testDescription tests[] = {
    30                               {testListAlloc,"487-testListAlloc",0},
    31                               {testListAdd,"488-testListAdd",0},
    32                               {testListGet,"489-testListGet",0},
    33                               {testListRemove,"490-testListRemove",0},
    34                               {testListConvert,"491-testListConvert",0},
    35                               {testListIterator,"494-testListIterator",0},
    36                               {testListFree,"627-testListFree",0},
    37                               {testListSort,"624-testListSort",0},
     30                              {testListAlloc,487,"psListAlloc",0,false},
     31                              {testListAdd,488,"psListAdd",0,false},
     32                              {testListGet,489,"psListGet",0,false},
     33                              {testListRemove,490,"psListRemove",0,false},
     34                              {testListConvert,491,"psListConvert",0,false},
     35                              {testListIterator,494,"psListIterator",0,false},
     36                              {testListFree,627,"psListFree",0,false},
     37                              {testListSort,624,"psListSort",0,false},
    3838                              {NULL}
    3939                          };
    4040
    41 int main()
     41int main(int argc, char* argv[])
    4242{
    4343    psLogSetLevel(PS_LOG_INFO);
    4444
    45     if (! runTestSuite(stderr,"psList",tests)) {
     45    if (! runTestSuite(stderr,"psList",tests,argc,argv) ) {
    4646        psError(__FILE__,"One or more tests failed");
    4747        return 1;
     
    138138
    139139    //  1. list is NULL (error)
    140     list = psListAdd(NULL,data,PS_LIST_HEAD);
    141 
    142     if (list != NULL) {
    143         psError(__func__,"psListAdd was given a NULL list, but returned a non-NULL list.");
    144         return 1;
    145     }
    146 
    147     //  2. data is NULL (error, list should not grow)
     140    if (psListAdd(NULL,data,PS_LIST_HEAD)) {
     141        psError(__func__,"psListAdd was given a NULL list, but returned a true/success.");
     142        return 1;
     143    }
     144
    148145    list = psListAlloc(data);
    149146    psFree(data);
     
    153150    }
    154151
    155     list = psListAdd(list, NULL,PS_LIST_HEAD);
    156 
    157     if (list->size != 1) {
    158         psError(__func__,"psListAdd with a NULL data element changed the list size.");
     152    //  2. data is NULL (error, list should not grow)
     153    if (psListAdd(list, NULL,PS_LIST_HEAD)) {
     154        psError(__func__,"psListAdd successfully added a NULL data item?");
     155        return 40;
     156    }
     157    if ( list->size != 1) {
     158        psError(__func__,"psListAdd with a NULL data element changed the list size or returned success.");
    159159        return 3;
    160160    }
     
    163163    data = psAlloc(sizeof(int));
    164164    *data = 2;
    165     list = psListAdd(list,data,PS_LIST_HEAD);
     165    if ( ! psListAdd(list,data,PS_LIST_HEAD) ) {
     166        psError(__func__,"psListAdd failed to add a data item to head.");
     167        return 21;
     168    }
     169
    166170    if (psMemGetRefCounter(data) != 2) {
    167171        psError(__func__,"psListAdd didn't increment the data reference count.");
     
    169173    }
    170174    psFree(data);
     175
    171176    // verify that the size incremented
    172177    if (list->size != 2) {
     
    183188    data = psAlloc(sizeof(int));
    184189    *data = 3;
    185     list = psListAdd(list,data,PS_LIST_TAIL);
     190    if ( ! psListAdd(list,data,PS_LIST_TAIL) ) {
     191        psError(__func__,"psListAdd failed to add a data item to tail.");
     192        return 21;
     193    }
     194
    186195    if (psMemGetRefCounter(data) != 2) {
    187196        psError(__func__,"psListAdd didn't increment the data reference count.");
    188         return 20;
     197        return 22;
    189198    }
    190199    psFree(data);
     
    211220    data = psAlloc(sizeof(int));
    212221    *data = 4;
    213     psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location");
    214     list = psListAdd(list,data,-10);
    215     if (psMemGetRefCounter(data) != 2) {
    216         psError(__func__,"psListAdd didn't increment the data reference count.");
    217         return 20;
    218     }
    219     psFree(data);
    220     // verify that the size incremented
    221     if (list->size != 4 || *(int*)list->head->data != 4) {
     222    psLogMsg(__func__,PS_LOG_INFO,"Following should error with invalid insert location");
     223
     224    if ( psListAdd(list,data,-10) ) {
     225        psError(__func__,"psListAdd successfully added data to a -10 position?");
     226        return 30;
     227    }
     228    if (psMemGetRefCounter(data) != 1) {
     229        psError(__func__,"psListAdd incremented the data reference count.");
     230        return 24;
     231    }
     232    psFree(data);
     233    // verify that the size wasn't incremented
     234    if (list->size != 3) {
    222235        printListInt(list);
    223236        psError(__func__,"psListAdd didn't insert to head when where was invalid.");
     
    228241    data = psAlloc(sizeof(int));
    229242    *data = 5;
    230     list = psListAdd(list,data,1);
     243
     244    if ( ! psListAdd(list,data,1) ) {
     245        psError(__func__,"psListAdd failed to add data to 1 position.");
     246        return 30;
     247    }
     248
    231249    if (psMemGetRefCounter(data) != 2) {
    232250        psError(__func__,"psListAdd didn't increment the data reference count.");
    233         return 20;
     251        return 25;
    234252    }
    235253    psFree(data);
    236254    // verify that the size incremented
    237     if (list->size != 5 || *(int*)list->head->next->data != 5) {
     255    if (list->size != 4 || *(int*)list->head->next->data != 5) {
    238256        printListInt(list);
    239257        psError(__func__,"psListAdd didn't insert to position #1.");
    240         return 9;
     258        return 10;
    241259    }
    242260
    243261    data = psAlloc(sizeof(int));
    244262    *data = 6;
    245     list = psListAdd(list,data,4);
     263    if ( ! psListAdd(list,data,3) ) {
     264        psError(__func__,"psListAdd failed to add data to 4 position.");
     265        return 31;
     266    }
    246267    if (psMemGetRefCounter(data) != 2) {
    247268        psError(__func__,"psListAdd didn't increment the data reference count.");
    248         return 20;
     269        return 26;
    249270    }
    250271    psFree(data);
    251272    // verify that the size incremented
    252     if (list->size != 6  || *(int *)list->head->next->next->next->next->data != 6) {
     273    if (list->size != 5  || *(int *)list->head->next->next->next->data != 6) {
    253274        printListInt(list);
    254275        psError(__func__,"psListAdd didn't insert to position #4.");
    255         return 9;
     276        return 50;
    256277    }
    257278
    258279    data = psAlloc(sizeof(int));
    259280    *data = 7;
    260     list = psListAdd(list,data,2);
     281    if ( ! psListAdd(list,data,2) ) {
     282        psError(__func__,"psListAdd failed to add data to 2 position.");
     283        return 32;
     284    }
    261285    if (psMemGetRefCounter(data) != 2) {
    262286        psError(__func__,"psListAdd didn't increment the data reference count.");
    263         return 20;
     287        return 28;
    264288    }
    265289    psFree(data);
    266290    // verify that the size incremented
    267     if (list->size != 7  || *(int *)list->head->next->next->data != 7) {
     291    if (list->size != 6  || *(int *)list->head->next->next->data != 7) {
    268292        printListInt(list);
    269293        psError(__func__,"psListAdd didn't insert to position #2.");
    270         return 9;
     294        return 11;
    271295    }
    272296
     
    274298    *data = 7;
    275299    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
    276     list = psListAdd(list,data,9);
     300
     301    if ( ! psListAdd(list,data,9) ) {
     302        psError(__func__,"psListAdd failed to add data to a 9 position?");
     303        return 30;
     304    }
     305
    277306    if (psMemGetRefCounter(data) != 2) {
    278307        psError(__func__,"psListAdd didn't increment the data reference count.");
    279         return 20;
    280     }
    281     psFree(data);
     308        return 29;
     309    }
     310
     311    psFree(data);
     312
    282313    // verify that the size incremented
    283     if (list->size != 8) {
     314    if (list->size != 7) {
    284315        printListInt(list);
    285316        psError(__func__,"psListAdd didn't insert to position #9.");
    286         return 9;
     317        return 12;
    287318    }
    288319
     
    347378    data = psAlloc(sizeof(int));
    348379    *data = 1;
    349     list = psListAdd(list,data,PS_LIST_TAIL);
     380    psListAdd(list,data,PS_LIST_TAIL);
    350381    psFree(data);
    351382
    352383    data = psAlloc(sizeof(int));
    353384    *data = 2;
    354     list = psListAdd(list,data,PS_LIST_TAIL);
     385    psListAdd(list,data,PS_LIST_TAIL);
    355386    psFree(data);
    356387
    357388    data = psAlloc(sizeof(int));
    358389    *data = 3;
    359     list = psListAdd(list,data,PS_LIST_TAIL);
     390    psListAdd(list,data,PS_LIST_TAIL);
    360391    psFree(data);
    361392
     
    452483        data = psAlloc(sizeof(int));
    453484        *data = lcv;
    454         list = psListAdd(list,data,PS_LIST_TAIL);
     485        psListAdd(list,data,PS_LIST_TAIL);
    455486        psMemDecrRefCounter(data);
    456487    }
     
    671702        data = psAlloc(sizeof(int));
    672703        *data = lcv;
    673         list = psListAdd(list,data,PS_LIST_TAIL);
     704        psListAdd(list,data,PS_LIST_TAIL);
    674705        psMemDecrRefCounter(data);
    675706    }
     
    809840        data = psAlloc(sizeof(int));
    810841        *data = lcv;
    811         list = psListAdd(list,data,PS_LIST_TAIL);
     842        psListAdd(list,data,PS_LIST_TAIL);
    812843        psFree(data);
    813844    }
     
    926957        data[lcv] = psAlloc(sizeof(int));
    927958        *data[lcv] = lcv;
    928         list = psListAdd(list,data[lcv],PS_LIST_TAIL);
     959        psListAdd(list,data[lcv],PS_LIST_TAIL);
    929960        if (psMemGetRefCounter(data[lcv]) != 2) {
    930961            psError(__func__,"Reference counter for data was not incremented");
     
    9801011            *data = lcv*2-12;
    9811012        }
    982         list = psListAdd(list,data,PS_LIST_TAIL);
     1013        psListAdd(list,data,PS_LIST_TAIL);
    9831014        psFree(data);
    9841015
     
    10461077            *data = lcv*2-12;
    10471078        }
    1048         list = psListAdd(list,data,PS_LIST_TAIL);
     1079        psListAdd(list,data,PS_LIST_TAIL);
    10491080        psFree(data);
    10501081
Note: See TracChangeset for help on using the changeset viewer.