IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 7, 2004, 4:17:49 PM (22 years ago)
Author:
desonia
Message:

Added tests to the vector<->list conversion routines.

File:
1 edited

Legend:

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

    r903 r911  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-08 00:58:39 $
     8 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-08 02:17:49 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222static int testDlistGet(void);
    2323static int testDlistRemove(void);
     24static int testDlistConvert(void);
    2425
    2526testDescription tests[] = {
     
    2829                              {testDlistGet,"489-testDlistGet",0},
    2930                              {testDlistRemove,"490-testDlistRemove",0},
     31                              {testDlistConvert,"491-testDlistConvert",0},
    3032                              {NULL}
    3133                          };
     
    417419        *data = lcv;
    418420        list = psDlistAdd(list,data,PS_DLIST_TAIL);
     421        psMemDecrRefCounter(data);
    419422    }
    420423
     
    616619
    617620}
     621
     622int testDlistConvert(void)
     623{
     624
     625    int currentId = psMemGetId();
     626    psDlist* list = NULL;
     627    psVector* vec = NULL;
     628    int* data;
     629
     630    /*
     631        array=psDlistToArray(list) shall take each element of the list, increment
     632        their reference, and insert them into the returned fresh void* array.
     633        The list shall not be changed, except for the element reference increment.
     634    */
     635
     636    // test dlist -> vector
     637
     638    // create a list
     639    list = psDlistAlloc(NULL);
     640    for (int lcv=0;lcv<15;lcv++) {
     641        data = psAlloc(sizeof(int));
     642        *data = lcv;
     643        list = psDlistAdd(list,data,PS_DLIST_TAIL);
     644        psMemDecrRefCounter(data);
     645    }
     646
     647    vec = psDlistToVector(list);
     648
     649    if (vec->n != 15 || list->size != 15) {
     650        psError(__func__,"The created vector didn't have the proper size");
     651        return 1;
     652    }
     653    for (int i=0;i<vec->n;i++) {
     654        if (i != *(int*)vec->data.PTR[i]) {
     655            psError(__func__,"Element %d of vector is incorrect (%d).",
     656                    i,*(int*)vec->data.PTR[i]);
     657            return 1;
     658        }
     659        if (i != *(int*)psDlistGet(list,i)) {
     660            psError(__func__,"Element %d of list is incorrect (%d).",
     661                    i,*(int*)vec->data.PTR[i]);
     662            return 1;
     663        }
     664        if (psMemGetRefCounter(vec->data.PTR[i]) != 2) {
     665            psError(__func__,"Element %d had wrong reference count (%d).",
     666                    i,psMemGetRefCounter(vec->data.PTR[i]));
     667            return 1;
     668        }
     669    }
     670
     671    psVectorFree(vec);
     672    psDlistFree(list,PS_FREE);
     673
     674    psMemCheckLeaks(currentId,NULL,NULL);
     675    psMemCheckCorruption(1);
     676
     677    // test vector -> dlist
     678
     679    // create a vector
     680    vec = psVectorAlloc(15,PS_TYPE_PTR);
     681    vec->n = vec->nalloc;
     682    for (int lcv=0;lcv<15;lcv++) {
     683        data = psAlloc(sizeof(int));
     684        *data = lcv;
     685        vec->data.PTR[lcv] = data;
     686    }
     687
     688    list = psVectorToDlist(vec);
     689
     690    if (vec->n != 15 || list->size != 15) {
     691        psError(__func__,"The created vector didn't have the proper size");
     692        return 1;
     693    }
     694    for (int i=0;i<vec->n;i++) {
     695        if (i != *(int*)vec->data.PTR[i]) {
     696            psError(__func__,"Element %d of vector is incorrect (%d).",
     697                    i,*(int*)vec->data.PTR[i]);
     698            return 1;
     699        }
     700        if (i != *(int*)psDlistGet(list,i)) {
     701            psError(__func__,"Element %d of list is incorrect (%d).",
     702                    i,*(int*)vec->data.PTR[i]);
     703            return 1;
     704        }
     705        if (psMemGetRefCounter(vec->data.PTR[i]) != 2) {
     706            psError(__func__,"Element %d had wrong reference count (%d).",
     707                    i,psMemGetRefCounter(vec->data.PTR[i]));
     708            return 1;
     709        }
     710    }
     711
     712    psVectorFree(vec);
     713    psDlistFree(list,PS_FREE);
     714
     715    // now, make sure if input vector/list is NULL, output is NULL
     716
     717    vec = psDlistToVector(NULL);
     718    if (vec != NULL) {
     719        psError(__func__,"psDlistToVector didn't return NULL when given NULL");
     720        return 1;
     721    }
     722
     723    list = psVectorToDlist(NULL);
     724    if (list != NULL) {
     725        psError(__func__,"psVectorToDlist didn't return NULL when given NULL");
     726        return 1;
     727    }
     728
     729    psMemCheckLeaks(currentId,NULL,NULL);
     730    psMemCheckCorruption(1);
     731
     732    return 0;
     733}
Note: See TracChangeset for help on using the changeset viewer.