IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 902


Ignore:
Timestamp:
Jun 7, 2004, 1:20:21 PM (22 years ago)
Author:
desonia
Message:

added tests according to testpoints.

File:
1 edited

Legend:

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

    r879 r902  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-04 23:50:23 $
     8 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-07 23:20:21 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515#include "pslib.h"
    1616
     17void printListInt(psDlist* list);
     18
     19
    1720static int testDlistAlloc(void);
     21static int testDlistAdd(void);
     22static int testDlistGet(void);
    1823
    1924testDescription tests[] = {
    2025                              {testDlistAlloc,"487-testDlistAlloc",0},
     26                              {testDlistAdd,"488-testDlistAdd",0},
     27                              {testDlistGet,"489-testDlistGet",0},
    2128                              {NULL}
    2229                          };
     
    2532{
    2633    psSetLogLevel(PS_LOG_INFO);
    27 
    28     testDlistAlloc();
    2934
    3035    if (! runTestSuite(stderr,"psDlist",tests)) {
     
    103108}
    104109
    105 int testpsDlistAdd(void)
    106 {
     110int testDlistAdd(void)
     111{
     112    int currentId = psMemGetId();
     113    psDlist* list = NULL;
     114    int* data;
    107115
    108116    psLogMsg(__func__,PS_LOG_INFO,"psDlistAdd shall add an element to list");
    109117
    110 
     118    /*
     119        psDlistAdd(list,data,where) should be tested in the instance where:
     120
     121        1. list is NULL (error)
     122        2. data is NULL (error, list should not grow)
     123        3. where is PS_DLIST_HEAD or PS_DLIST_TAIL
     124        4. where is not PS_DLIST_* but <0
     125        5. where is >0
     126    */
     127
     128    //  1. list is NULL (error)
     129    list = psDlistAdd(NULL,data,PS_DLIST_HEAD);
     130
     131    if (list != NULL) {
     132        psError(__func__,"psDlistAdd was given a NULL list, but returned a non-NULL list.");
     133        return 1;
     134    }
     135
     136    //  2. data is NULL (error, list should not grow)
     137    data = psAlloc(sizeof(int));
     138    *data = 1;
     139    list = psDlistAlloc(data);
     140    if (list->size != 1) {
     141        psError(__func__,"psDlistAlloc didn't create a list properly.");
     142        return 2;
     143    }
     144
     145    list = psDlistAdd(list, NULL,PS_DLIST_HEAD);
     146
     147    if (list->size != 1) {
     148        psError(__func__,"psDlistAdd with a NULL data element changed the list size.");
     149        return 3;
     150    }
     151
     152    //  3. where is PS_DLIST_HEAD or PS_DLIST_TAIL
     153    data = psAlloc(sizeof(int));
     154    *data = 2;
     155    list = psDlistAdd(list,data,PS_DLIST_HEAD);
     156
     157    // verify that the size incremented
     158    if (list->size != 2) {
     159        psError(__func__,"psDlistAdd didn't increment the size by one");
     160        return 4;
     161    }
     162
     163    // verify that the head is the inserted data item
     164    if (*(int*)list->head->data != 2) {
     165        psError(__func__,"psDlistAdd with PS_DLIST_HEAD didn't insert at the head.");
     166        return 5;
     167    }
     168
     169    data = psAlloc(sizeof(int));
     170    *data = 3;
     171    list = psDlistAdd(list,data,PS_DLIST_TAIL);
     172
     173    // verify that the size incremented
     174    if (list->size != 3) {
     175        psError(__func__,"psDlistAdd didn't increment the size by 1");
     176        return 6;
     177    }
     178
     179    // verify that the head is still the same
     180    if (*(int*)list->head->data != 2) {
     181        psError(__func__,"psDlistAdd with PS_DLIST_TAIL modified the head.");
     182        return 7;
     183    }
     184
     185    // verify that the tail is the data item inserted
     186    if (*(int*)list->tail->data != 3) {
     187        psError(__func__,"psDlistAdd with PS_DLIST_TAIL didn't insert at the tail.");
     188        return 8;
     189    }
     190
     191    // 4. where is not PS_DLIST_* but <0
     192
     193    data = psAlloc(sizeof(int));
     194    *data = 4;
     195
     196    psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location");
     197    list = psDlistAdd(list,data,-10);
     198    // verify that the size incremented
     199    if (list->size != 4 || *(int*)list->head->data != 4) {
     200        printListInt(list);
     201        psError(__func__,"psDlistAdd didn't insert to head when where was invalid.");
     202        return 9;
     203    }
     204
     205    // 5. where is >0
     206    data = psAlloc(sizeof(int));
     207    *data = 5;
     208    list = psDlistAdd(list,data,1);
     209    // verify that the size incremented
     210    if (list->size != 5 || *(int*)list->head->next->data != 5) {
     211        printListInt(list);
     212        psError(__func__,"psDlistAdd didn't insert to position #1.");
     213        return 9;
     214    }
     215
     216    data = psAlloc(sizeof(int));
     217    *data = 6;
     218    list = psDlistAdd(list,data,4);
     219    // verify that the size incremented
     220    if (list->size != 6  || *(int *)list->head->next->next->next->next->data != 6) {
     221        printListInt(list);
     222        psError(__func__,"psDlistAdd didn't insert to position #4.");
     223        return 9;
     224    }
     225
     226    data = psAlloc(sizeof(int));
     227    *data = 7;
     228    list = psDlistAdd(list,data,2);
     229    // verify that the size incremented
     230    if (list->size != 7  || *(int *)list->head->next->next->data != 7) {
     231        printListInt(list);
     232        psError(__func__,"psDlistAdd didn't insert to position #2.");
     233        return 9;
     234    }
     235
     236    data = psAlloc(sizeof(int));
     237    *data = 7;
     238    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
     239    list = psDlistAdd(list,data,9);
     240    // verify that the size incremented
     241    if (list->size != 8) {
     242        printListInt(list);
     243        psError(__func__,"psDlistAdd didn't insert to position #9.");
     244        return 9;
     245    }
     246
     247    psDlistFree(list, PS_FREE);
     248
     249    psMemCheckLeaks(currentId,NULL,NULL);
     250    psMemCheckCorruption(1);
    111251
    112252    return 0;
    113253}
     254
     255void printListInt(psDlist* list)
     256{
     257    int* data = NULL;
     258    bool first = true;
     259
     260    psDlistSetIterator(list,PS_DLIST_HEAD);
     261    data = psDlistGetCurrent(list);
     262
     263    while ( data != NULL ) {
     264        if (!first) {
     265            printf(", %d",*(int*)data);
     266        } else {
     267            printf("%d",*(int*)data);
     268            first = false;
     269        }
     270        data = psDlistGetNext(list);
     271    }
     272
     273    printf(".\n");
     274}
     275
     276
     277int testDlistGet(void)
     278{
     279    int currentId = psMemGetId();
     280    psDlist* list = NULL;
     281    int* data;
     282
     283    /*
     284     psDlistGet(list,which) shall be tested with the following instances
     285
     286        1. list is NULL.
     287        2. which>0 and which<list.n.
     288        3. which>list.n.
     289        4. which=PS_DLIST_HEAD
     290        5. which=PS_DLIST_NEXT
     291        6. which=PS_DLIST_TAIL
     292        7. which=PS_DLIST_PREV
     293        8. which<0 and not any PS_DLIST_* values
     294    */
     295
     296    psLogMsg(__func__,PS_LOG_INFO,"psDlistGet(list,which) shall be tested with "
     297             "the following instances");
     298
     299    //  1. list is NULL.
     300    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error");
     301    if (psDlistGet(list,PS_DLIST_HEAD) != NULL) {
     302        psError(__func__,"psDlistGet didn't return NULL given a NULL list.");
     303        return 1;
     304    };
     305
     306    // create a list
     307    data = psAlloc(sizeof(int));
     308    *data = 0;
     309    list = psDlistAlloc(data);
     310
     311    data = psAlloc(sizeof(int));
     312    *data = 1;
     313    list = psDlistAdd(list,data,PS_DLIST_TAIL);
     314
     315    data = psAlloc(sizeof(int));
     316    *data = 2;
     317    list = psDlistAdd(list,data,PS_DLIST_TAIL);
     318
     319    data = psAlloc(sizeof(int));
     320    *data = 3;
     321    list = psDlistAdd(list,data,PS_DLIST_TAIL);
     322
     323    //  2. which>0 and which<list.n.
     324    data = (int*)psDlistGet(list,3);
     325    if (data == NULL || *data != 3) {
     326        psError(__func__,"psDlistGet failed with which=3");
     327        return 2;
     328    }
     329    data = (int*)psDlistGet(list,1);
     330    if (data == NULL || *data != 1) {
     331        psError(__func__,"psDlistGet failed with which=1");
     332        return 3;
     333    }
     334
     335    //  3. which>=list.n.
     336    data = (int*)psDlistGet(list,5);
     337    if (data != NULL) {
     338        psError(__func__,"psDlistGet failed with which=5");
     339        return 4;
     340    }
     341    data = (int*)psDlistGet(list,4);
     342    if (data != NULL) {
     343        psError(__func__,"psDlistGet failed with which=4");
     344        return 5;
     345    }
     346
     347    //  4. which=PS_DLIST_HEAD
     348    data = (int*)psDlistGet(list,PS_DLIST_HEAD);
     349    if (data == NULL || *data != 0) {
     350        psError(__func__,"psDlistGet failed with which=PS_DLIST_HEAD");
     351        return 6;
     352    }
     353
     354    //  5. which=PS_DLIST_NEXT
     355    data = (int*)psDlistGet(list,PS_DLIST_NEXT);
     356    if (data == NULL || *data != 1) {
     357        psError(__func__,"psDlistGet failed with which=PS_DLIST_NEXT");
     358        return 7;
     359    }
     360
     361    //  6. which=PS_DLIST_TAIL
     362    data = (int*)psDlistGet(list,PS_DLIST_TAIL);
     363    if (data == NULL || *data != 3) {
     364        psError(__func__,"psDlistGet failed with which=PS_DLIST_TAIL");
     365        return 8;
     366    }
     367
     368    //  7. which=PS_DLIST_PREV
     369    data = (int*)psDlistGet(list,PS_DLIST_PREVIOUS);
     370    if (data == NULL || *data != 2) {
     371        psError(__func__,"psDlistGet failed with which=PS_DLIST_PREV");
     372        return 9;
     373    }
     374
     375    psDlistFree(list,PS_FREE);
     376
     377    psMemCheckLeaks(currentId,NULL,NULL);
     378    psMemCheckCorruption(1);
     379
     380    return 0;
     381}
Note: See TracChangeset for help on using the changeset viewer.