Ignore:
Timestamp:
Jan 28, 2006 2:05:44 PM (16 years ago)
Author:
dkearney
Message:

added adjustments for new rappture libray c api which returns error information describing function success or failure

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/src/RpLibraryC_test.c

    r142 r157  
    1010#include "RpLibraryCInterface.h"
    1111
    12 
     12int test_lib(RpLibrary** lib, const char* path);
    1313int test_element (RpLibrary* lib, const char* path );
    1414int test_get (RpLibrary* lib, const char* path );
     
    2626int test_childrenByType (RpLibrary* lib, const char* path, const char* type );
    2727
     28int test_lib (RpLibrary** lib, const char* path) {
     29
     30    int retVal = 0;
     31
     32    *lib = NULL;
     33    *lib = rpLibrary(path);
     34
     35    printf("TESTING LIBRARY: path = %s\n", path);
     36
     37    if (*lib != NULL) {
     38        printf("creation of library successful\n");
     39    }
     40    else {
     41        printf("creation of library failed\n");
     42        retVal += 1;
     43    }
     44
     45    printf ("lib = %x\n",(unsigned int)(*lib));
     46
     47    return retVal;
     48}
     49
    2850int test_element (RpLibrary* lib, const char* path )
    2951{
    30     int retVal = 1;
     52    int retVal = 0;
    3153    RpLibrary* searchEle = NULL;
    3254    const char* type = NULL;
     
    3759
    3860    searchEle = rpElement(lib,path);
    39     type = rpElementAsType(lib,path);
    40     comp = rpElementAsComp(lib,path);
    41     id = rpElementAsId(lib,path);
     61    retVal += rpElementAsType(lib,path,&type);
     62    retVal += rpElementAsComp(lib,path,&comp);
     63    retVal += rpElementAsId(lib,path,&id);
    4264
    4365    if (!searchEle) {
    4466        printf("searchEle is NULL\n");
    45         retVal = 1;
     67        retVal += 1;
    4668    }
    4769    else {
     
    5072        printf("searchEle type = :%s:\n", type);
    5173
    52         comp = rpNodeComp(searchEle);
    53         id   = rpNodeId(searchEle);
    54         type = rpNodeType(searchEle);
     74        retVal += rpNodeComp(searchEle,&comp);
     75        retVal += rpNodeId(searchEle,&id);
     76        retVal += rpNodeType(searchEle,&type);
    5577
    5678        printf("searchEle comp = :%s:\n", comp);
     
    5880        printf("searchEle type = :%s:\n", type);
    5981
    60         retVal = 0;
    6182    }
    6283
     
    6687int test_getString (RpLibrary* lib, const char* path )
    6788{
    68     int retVal = 1;
     89    int retVal = 0;
    6990    const char* searchVal = NULL;
    7091
    7192    printf("TESTING GET String: path = %s\n", path);
    7293
    73     searchVal = rpGetString(lib,path);
    74 
    75     if (!searchVal || *searchVal == '\0') {
     94    retVal += rpGetString(lib,path,&searchVal);
     95
     96    if ( (retVal) || !searchVal || *searchVal == '\0') {
    7697        printf("searchVal is EMPTY STRING\n");
    77         retVal = 1;
     98        retVal += 1;
    7899    }
    79100    else {
     
    87108int test_getDouble (RpLibrary* lib, const char* path )
    88109{
    89     int retVal = 1;
     110    int retVal = 0;
    90111    double searchVal = 0.0;
    91112
    92113    printf("TESTING GET Double: path = %s\n", path);
    93114
    94     searchVal = rpGetDouble(lib,path);
    95 
    96     printf("searchVal = :%f:\n", searchVal);
    97     retVal = 0;
     115    retVal = rpGetDouble(lib,path,&searchVal);
     116
     117    if (!retVal) {
     118        printf("searchVal = :%f:\n", searchVal);
     119    }
     120    else {
     121        printf("GET Double: FAILED\n");
     122    }
    98123
    99124    return retVal;
     
    102127int test_children (RpLibrary* lib, const char* path)
    103128{
    104     int retVal = 1;
     129    int retVal = 0;
    105130    RpLibrary* childEle = NULL;
    106131    const char* id = NULL;
     
    111136
    112137    while ( (childEle = rpChildren(lib,path,childEle)) ) {
    113         comp = rpNodeComp(childEle);
    114         id   = rpNodeId(childEle);
    115         type = rpNodeType(childEle);
     138        retVal += rpNodeComp(childEle,&comp);
     139        retVal += rpNodeId(childEle,&id);
     140        retVal += rpNodeType(childEle,&type);
    116141
    117142        printf("childEle comp = :%s:\n",comp);
    118143        printf("childEle   id = :%s:\n",id);
    119144        printf("childEle type = :%s:\n",type);
    120 
    121     }
    122 
    123     retVal = 0;
     145    }
    124146
    125147    return retVal;
     
    128150int test_childrenByType (RpLibrary* lib, const char* path, const char* searchType )
    129151{
    130     int retVal = 1;
     152    int retVal = 0;
    131153    RpLibrary* childEle = NULL;
    132154    const char* id = NULL;
     
    137159
    138160    while ( (childEle = rpChildrenByType(lib,path,childEle,searchType)) ) {
    139         comp = rpNodeComp(childEle);
    140         id   = rpNodeId(childEle);
    141         type = rpNodeType(childEle);
     161        retVal += rpNodeComp(childEle,&comp);
     162        retVal += rpNodeId(childEle,&id);
     163        retVal += rpNodeType(childEle,&type);
    142164
    143165        printf("childEle comp = :%s:\n",comp);
    144166        printf("childEle   id = :%s:\n",id);
    145167        printf("childEle type = :%s:\n",type);
    146 
    147     }
    148 
    149     retVal = 0;
     168    }
    150169
    151170    return retVal;
     
    154173int test_putString (RpLibrary* lib, const char* path, const char* value, int append)
    155174{
    156     int retVal = 1;
     175    int retVal = 0;
    157176    const char* searchVal = NULL;
    158177
    159178    printf("TESTING PUT String: path = %s\n", path);
    160179
    161     rpPutString(lib,path,value,append);
    162     searchVal = rpGetString(lib, path);
    163 
    164     if (!searchVal || *searchVal == '\0') {
    165         printf("searchVal is EMPTY STRING\n");
    166         retVal = 1;
     180    retVal += rpPutString(lib,path,value,append);
     181    if (!retVal) {
     182        retVal += rpGetString(lib, path, &searchVal);
     183    }
     184
     185    if (retVal || !searchVal || *searchVal == '\0') {
     186        printf("searchVal is EMPTY STRING, or there was an error\n");
    167187    }
    168188    else {
    169189        printf("searchVal = :%s:\n", searchVal);
    170         retVal = 0;
    171190    }
    172191
     
    176195int test_putDouble (RpLibrary* lib, const char* path, double value, int append)
    177196{
    178     int retVal = 1;
     197    int retVal = 0;
    179198    double searchVal = 0.0;
    180199
    181200    printf("TESTING PUT String: path = %s\n", path);
    182201
    183     rpPutDouble(lib,path,value,append);
    184     searchVal = rpGetDouble(lib, path);
    185     printf("searchVal = :%f:\n", searchVal);
    186     retVal = 0;
     202    retVal += rpPutDouble(lib,path,value,append);
     203    if (!retVal) {
     204        retVal += rpGetDouble(lib, path,&searchVal);
     205    }
     206
     207    if ( retVal ){
     208        printf("ERROR while retrieving searchVal\n");
     209    }
     210    else {
     211        printf("searchVal = :%f:\n", searchVal);
     212    }
    187213
    188214    return retVal;
     
    193219{
    194220    RpLibrary* lib = NULL;
     221    int err = 0;
     222    const char* retStr = NULL;
    195223
    196224    if (argc < 2)
     
    200228    }
    201229
    202     lib = rpLibrary(argv[1]);
     230    test_lib(&lib,argv[1]);
    203231
    204232    test_element(lib,"input.number(min)");
     
    225253    test_childrenByType(lib,"input.number(test)","preset");
    226254
    227     printf("XML = \n%s\n",rpXml(lib));
     255    err = rpXml(lib,&retStr);
     256
     257    if ( !err ) {
     258        printf("XML = \n%s\n",retStr);
     259    }
     260    else {
     261        printf("rpXML failed\n");
     262    }
    228263
    229264    rpFreeLibrary(&lib);
Note: See TracChangeset for help on using the changeset viewer.