IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3063


Ignore:
Timestamp:
Jan 19, 2005, 2:30:05 PM (22 years ago)
Author:
evanalst
Message:

Add new test points for psListAddAfter and psListAddBefore functions.

File:
1 edited

Legend:

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

    r2699 r3063  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-12-11 01:24:15 $
     8 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-01-20 00:30:05 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626static psS32 testListFree(void);
    2727static psS32 testListSort(void);
     28static psS32 testListAddAfter(void);
     29static psS32 testListAddBefore(void);
    2830
    2931testDescription tests[] = {
     
    3638                              {testListFree,627,"psListFree",0,false},
    3739                              {testListSort,624,"psListSort",0,false},
     40                              {testListAddAfter,811,"psListAddAfter",0,false},
     41                              {testListAddBefore,811,"psListAddBefore",0,false},
    3842                              {NULL}
    3943                          };
     
    6367    // empty psList struct with head=tail=NULL and n=0. Otherwise, it shall
    6468    // return a psList of one element (head=tail=data, n=1).
    65 
     69    // Test requirement SDR-167
    6670    list = psListAlloc(NULL);
    6771    if (list == NULL) {
     
    6973        return 1;
    7074    }
    71 
    7275    if (list->head != NULL || list->tail != NULL) {
    7376        psError(PS_ERR_UNKNOWN, true,"head and/or tail was not NULL for empty list.");
    7477        return 2;
    7578    }
    76 
    7779    if (list->size != 0) {
    7880        psError(PS_ERR_UNKNOWN, true,"size of list wasn't zero for empty list.");
     
    8284    psFree(list);
    8385
     86    // Test requirement SDR-165
    8487    list = psListAlloc(data);
    8588    if (list == NULL) {
     
    109112    }
    110113
    111 
    112     psFree(list);
    113 
    114     psFree(data);
     114    psFree(list);
     115
     116    psFree(data);
     117
     118    return 0;
     119}
     120
     121psS32 testListAddAfter(void)
     122{
     123    psList* list = NULL;
     124    psS32*  data = NULL;
     125    psS32*  data1 = NULL;
     126    psS32*  data2 = NULL;
     127    psListIterator *currentIterator = NULL;
     128
     129    data = psAlloc(sizeof(psS32));
     130    *data = 1;
     131    data1 = psAlloc(sizeof(psS32));
     132    *data1 = 2;
     133    data2 = psAlloc(sizeof(psS32));
     134    *data2 = 3;
     135
     136    list = psListAlloc(data);
     137    currentIterator = psListIteratorAlloc(list,PS_LIST_HEAD);
     138
     139    // Add data after HEAD and verify data
     140    // Test requirement SDR-755
     141    if(!psListAddAfter(currentIterator,data1)) {
     142        psError(PS_ERR_UNKNOWN,true,"psListAddAfter failed to add item");
     143        return 1;
     144    }
     145    if(*(psS32*)list->head->next->data != 2) {
     146        psError(PS_ERR_UNKNOWN,true,"psListAddAfter did not add the item properly");
     147        return 2;
     148    }
     149    // Test requirement SDR-175
     150    if (psMemGetRefCounter(data1) != 2) {
     151        psError(PS_ERR_UNKNOWN, true,"psListAddAfter didn't increment the data reference count.");
     152        return 20;
     153    }
     154    psFree(currentIterator);
     155
     156    currentIterator = psListIteratorAlloc(list,PS_LIST_TAIL);
     157
     158    // Add data after TAIL and verify data
     159    if(!psListAddAfter(currentIterator,data2)) {
     160        psError(PS_ERR_UNKNOWN,true,"psListAddAfter failed to add item");
     161        return 3;
     162    }
     163    if(*(psS32*)list->tail->data != 3) {
     164        psError(PS_ERR_UNKNOWN,true,"psListAddAfter did not add the item properly");
     165        return 4;
     166    }
     167    // Test requirement SDR-175
     168    if (psMemGetRefCounter(data2) != 2) {
     169        psError(PS_ERR_UNKNOWN, true,"psListAddAfter didn't increment the data reference count.");
     170        return 40;
     171    }
     172
     173    // Verify error message generated with data pointer is NULL
     174    psLogMsg(__func__,PS_LOG_INFO,"NULL data pointer should generate error message");
     175    if(psListAddAfter(currentIterator,NULL)) {
     176        psError(PS_ERR_UNKNOWN,true,"psListAddAfter should have generated error.");
     177        return 5;
     178    }
     179
     180    // Verify error message generated with iterator NULL
     181    psLogMsg(__func__,PS_LOG_INFO,"NULL iterator should generate error message");
     182    if(psListAddAfter(NULL,data2)) {
     183        psError(PS_ERR_UNKNOWN,true,"psListAddAfter should have generated error.");
     184        return 6;
     185    }
     186
     187    psFree(data);
     188    psFree(data1);
     189    psFree(data2);
     190    psFree(list);
     191
     192    return 0;
     193}
     194
     195psS32 testListAddBefore(void)
     196{
     197    psList* list = NULL;
     198    psS32*  data1 = NULL;
     199    psS32*  data2 = NULL;
     200    psListIterator *currentIterator = NULL;
     201
     202    data1 = psAlloc(sizeof(psS32));
     203    *data1 = 2;
     204    data2 = psAlloc(sizeof(psS32));
     205    *data2 = 3;
     206
     207    list = psListAlloc(NULL);
     208    currentIterator = psListIteratorAlloc(list,PS_LIST_HEAD);
     209
     210    // Add data before HEAD and verify data
     211    // Test requirement SDR-756
     212    if(!psListAddBefore(currentIterator,data1)) {
     213        psError(PS_ERR_UNKNOWN,true,"psListAddBefore failed to add item");
     214        return 1;
     215    }
     216    if(*(psS32*)list->head->data != 2) {
     217        psError(PS_ERR_UNKNOWN,true,"psListAddBefore did not add the item properly");
     218        return 2;
     219    }
     220    // Test requirement SDR-175
     221    if (psMemGetRefCounter(data1) != 2) {
     222        psError(PS_ERR_UNKNOWN, true,"psListAddBefore didn't increment the data reference count.");
     223        return 20;
     224    }
     225    psFree(currentIterator);
     226
     227    currentIterator = psListIteratorAlloc(list,PS_LIST_TAIL);
     228
     229    // Add data after TAIL and verify data
     230    if(!psListAddBefore(currentIterator,data2)) {
     231        psError(PS_ERR_UNKNOWN,true,"psListAddBefore failed to add item");
     232        return 3;
     233    }
     234    if(*(psS32*)list->tail->prev->data != 3) {
     235        psError(PS_ERR_UNKNOWN,true,"psListAddBefore did not add the item properly");
     236        return 4;
     237    }
     238    // Test requirement SDR-175
     239    if (psMemGetRefCounter(data2) != 2) {
     240        psError(PS_ERR_UNKNOWN, true,"psListAddBefore didn't increment the data reference count.");
     241        return 40;
     242    }
     243
     244    // Verify error message generated with data pointer is NULL
     245    psLogMsg(__func__,PS_LOG_INFO,"NULL data pointer should generate error message");
     246    if(psListAddBefore(currentIterator,NULL)) {
     247        psError(PS_ERR_UNKNOWN,true,"psListAddBefore should have generated error.");
     248        return 5;
     249    }
     250
     251    // Verify error message generated with iterator NULL
     252    psLogMsg(__func__,PS_LOG_INFO,"NULL iterator should generate error message");
     253    if(psListAddBefore(NULL,data2)) {
     254        psError(PS_ERR_UNKNOWN,true,"psListAddBefore should have generated error.");
     255        return 6;
     256    }
     257
     258    psFree(data1);
     259    psFree(data2);
     260    psFree(list);
    115261
    116262    return 0;
     
    167313        return 21;
    168314    }
    169 
     315    // Test requirement SDR-175
    170316    if (psMemGetRefCounter(data) != 2) {
    171317        psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
     
    192338        return 21;
    193339    }
    194 
     340    // Test requirement SDR-175
    195341    if (psMemGetRefCounter(data) != 2) {
    196342        psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
     
    226372        return 30;
    227373    }
     374    // Test requirement SDR-175
    228375    if (psMemGetRefCounter(data) != 1) {
    229376        psError(PS_ERR_UNKNOWN, true,"psListAdd incremented the data reference count.");
     
    246393        return 30;
    247394    }
    248 
     395    // Test requirement SDR-175
    249396    if (psMemGetRefCounter(data) != 2) {
    250397        psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
     
    265412        return 31;
    266413    }
     414    // Test requirment SDR-175
    267415    if (psMemGetRefCounter(data) != 2) {
    268416        psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
     
    279427    data = psAlloc(sizeof(psS32));
    280428    *data = 7;
     429    // Test requirment SDR-169
    281430    if ( ! psListAdd(list,2,data) ) {
    282431        psError(PS_ERR_UNKNOWN, true,"psListAdd failed to add data to 2 position.");
    283432        return 32;
    284433    }
     434    // Test requirment SDR-175
    285435    if (psMemGetRefCounter(data) != 2) {
    286436        psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
     
    295445    }
    296446
    297     data = psAlloc(sizeof(psS32));
    298     *data = 7;
     447    // Test requirement SDR-757
     448    data = psAlloc(sizeof(psS32));
     449    *data = 8;
    299450    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
    300451
     
    303454        return 30;
    304455    }
    305 
     456    // Test requirment SDR-175
    306457    if (psMemGetRefCounter(data) != 2) {
    307458        psError(PS_ERR_UNKNOWN, true,"psListAdd didn't increment the data reference count.");
    308459        return 29;
    309460    }
    310 
    311     psFree(data);
    312 
    313     // verify that the size incremented
    314     if (list->size != 7) {
    315         printListInt(list);
    316         psError(PS_ERR_UNKNOWN, true,"psListAdd didn't insert to position #9.");
     461    if(list->size != 7 || *(psS32 *)list->tail->data != 8) {
     462        printListInt(list);
     463        psError(PS_ERR_UNKNOWN,true,"psListAdd didn't place added item at tail.");
    317464        return 12;
    318465    }
     466
     467    psFree(data);
    319468
    320469    psFree(list);
Note: See TracChangeset for help on using the changeset viewer.