IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 960


Ignore:
Timestamp:
Jun 9, 2004, 11:46:38 AM (22 years ago)
Author:
desonia
Message:

added test for psListFree.

Location:
trunk/psLib/test/collections
Files:
2 edited

Legend:

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

    r953 r960  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-09 21:20:53 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-09 21:46:37 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2424static int testListConvert(void);
    2525static int testListIterator(void);
     26static int testListFree(void);
    2627
    2728testDescription tests[] = {
     
    3233                              {testListConvert,"491-testListConvert",0},
    3334                              {testListIterator,"494-testListIterator",0},
     35                              {testListFree,"627-testListFree",0},
    3436                              {NULL}
    3537                          };
     
    899901int testListFree(void)
    900902{
     903    float* data[15];
     904    psList* list;
    901905
    902906    /*
    903     Call psDlistAlloc to create a doubly linked list. Create several data items and add them to the list.
    904     Verify    items are within the list. Verify the data item's reference counter are incremented after adding
    905     to    the list.    Call psDlistFree with NULL specified as the elemFree function. Verify the list is
    906     deallocated but    not the data    items. Verify the data item's reference counters are decremented by one
    907     compared to when added    to the list.
     907    Call psDlistAlloc to create a doubly linked list.
     908
     909    Create several data items and add them to the list.
     910
     911    Verify the data item's reference counter are incremented after adding to the list.
     912    (not really needed, as psListAdd is tested elsewhere)
    908913    */
     914
     915    list = psListAlloc(NULL);
     916    for (int lcv=0;lcv<15;lcv++) {
     917        data[lcv] = psAlloc(sizeof(int));
     918        *data[lcv] = lcv;
     919        list = psListAdd(list,data[lcv],PS_LIST_TAIL);
     920        if (psMemGetRefCounter(data[lcv]) != 2) {
     921            psError(__func__,"Reference counter for data was not incremented");
     922            return 1;
     923        }
     924    }
     925
     926    /*
     927    Verify items are within the list.
     928    (not needed, as psListAdd is tested elsewhere, but check anyway.)
     929    */
     930    if (list->size != 15) {
     931        psError(__func__,"List wasn't populated as expected?");
     932        return 2;
     933    }
     934
     935    /*
     936    Call psDlistFree with NULL specified as the elemFree function.
     937    */
     938
     939    psListFree(list,NULL);
     940
     941    /*
     942    Verify the list is deallocated but not the data items.
     943    (accomplished by checking for memory leaks)
     944
     945    Verify the data item's reference counters are decremented by one compared to when added to the list.
     946    (technically, this could be accomplished by checking memory leaks too, but I checked anyway)
     947    */
     948
     949    for (int i=0;i<15;i++) {
     950        if (psMemGetRefCounter(data[i]) != 1) {
     951            psError(__func__,"pslistFree didn't decrement the data item's reference counter");
     952            return 3;
     953        }
     954        psFree(data[i]);
     955    }
    909956
    910957    return 0;
  • trunk/psLib/test/collections/verified/tst_psList.stderr

    r953 r960  
    4747 <DATE> <TIME> <HOST> |E|psListRemove   |Couldn't position to given index (-2) to remove element from list.
    4848 <DATE> <TIME> <HOST> |I|testListRemove |Next message should be an error
    49  <DATE> <TIME> <HOST> |E|psListRemove   |Failed to find 0x0 on psList 0x6d7f30 in psListRemove.
     49 <DATE> <TIME> <HOST> |E|psListRemove   |Failed to find 0x0 on psList 0x6d8b90 in psListRemove.
    5050 <DATE> <TIME> <HOST> |I|testListRemove |Next message should be an error
    51  <DATE> <TIME> <HOST> |E|psListRemove   |Failed to find 0x6d8840 on psList 0x6d7f30 in psListRemove.
     51 <DATE> <TIME> <HOST> |E|psListRemove   |Failed to find 0x6d94a0 on psList 0x6d8b90 in psListRemove.
    5252
    5353---> TESTPOINT PASSED (psList{490-testListRemove} | tst_psList.c)
     
    7676---> TESTPOINT PASSED (psList{494-testListIterator} | tst_psList.c)
    7777
     78/----------------------------- TESTPOINT ------------------------------------------\
     79|             TestFile: tst_psList.c                                               |
     80|            TestPoint: psList{627-testListFree}                                   |
     81|             TestType: Positive                                                   |
     82\----------------------------------------------------------------------------------/
     83
     84
     85---> TESTPOINT PASSED (psList{627-testListFree} | tst_psList.c)
     86
Note: See TracChangeset for help on using the changeset viewer.