Changeset 1022


Ignore:
Timestamp:
Jun 8, 2008 6:35:41 PM (13 years ago)
Author:
gah
Message:

added missing Makefiles

Location:
trunk/test/src
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/src/RpLibrary_test.cc

    r495 r1022  
    1414#include "RpLibrary.h"
    1515#include <list>
    16 
    17 int test_element (RpLibrary* lib, std::string path );
    18 int test_parent (RpLibrary* lib, std::string path );
    19 int test_get (RpLibrary* lib, std::string path );
    20 int test_getString (RpLibrary* lib, std::string path );
    21 int test_getDouble (RpLibrary* lib, std::string path );
    22 int test_getInt (RpLibrary* lib, std::string path );
    23 int test_getBool (RpLibrary* lib, std::string path );
    24 int test_putObj (RpLibrary* fromLib, std::string fromPath,
    25                  RpLibrary* toLib, std::string toPath);
    26 int test_copy (RpLibrary* fromLib, std::string fromPath,
    27                RpLibrary* toLib, std::string toPath);
    28 int test_remove (RpLibrary* lib, std::string path);
    29 
    30 int test_element (RpLibrary* lib, std::string path )
     16#include <string>
     17#include <iostream>
     18
     19using namespace std;
     20
     21int test_element (RpLibrary* lib, string path);
     22int test_parent (RpLibrary* lib, string path);
     23int test_get (RpLibrary* lib, string path);
     24int test_getString (RpLibrary* lib, string path);
     25int test_getDouble (RpLibrary* lib, string path);
     26int test_getInt (RpLibrary* lib, string path);
     27int test_getBool (RpLibrary* lib, string path);
     28int test_putObj (RpLibrary* fromLib, string fromPath,
     29                 RpLibrary* toLib, string toPath);
     30int test_copy (RpLibrary* fromLib, string fromPath,
     31               RpLibrary* toLib, string toPath);
     32int test_remove (RpLibrary* lib, string path);
     33
     34int test_element (RpLibrary* lib, string path)
    3135{
    3236    int retVal = 1;
    3337    RpLibrary* searchEle = lib->element(path);
    3438
    35     std::cout << "TESTING ELEMENT: path = " << path << std::endl;
     39    cout << "TESTING ELEMENT: path = " << path << endl;
    3640
    3741    if (!searchEle) {
    38         std::cout << "searchEle is NULL" << std::endl;
     42        cout << "searchEle is NULL" << endl;
    3943        retVal = 1;
    4044    }
    4145    else {
    42         std::cout << "searchEle path = :" << searchEle->nodePath() << ":" << std::endl;
    43         std::cout << "searchEle comp = :" << searchEle->nodeComp() << ":" << std::endl;
    44         std::cout << "searchEle   id = :" << searchEle->nodeId()   << ":" << std::endl;
    45         std::cout << "searchEle type = :" << searchEle->nodeType() << ":" << std::endl;
    46         retVal = 0;
    47     }
    48 
    49     return retVal;
    50 }
    51 
    52 int test_parent (RpLibrary* lib, std::string path )
     46        cout << "searchEle path = :" << searchEle->nodePath() << ":" << endl;
     47        cout << "searchEle comp = :" << searchEle->nodeComp() << ":" << endl;
     48        cout << "searchEle   id = :" << searchEle->nodeId()   << ":" << endl;
     49        cout << "searchEle type = :" << searchEle->nodeType() << ":" << endl;
     50        retVal = 0;
     51    }
     52
     53    return retVal;
     54}
     55
     56int test_parent (RpLibrary* lib, string path)
    5357{
    5458    int retVal = 1;
    5559    RpLibrary* searchEle = lib->parent(path);
    5660
    57     std::cout << "TESTING PARENT: path = " << path << std::endl;
     61    cout << "TESTING PARENT: path = " << path << endl;
    5862
    5963    if (!searchEle) {
    60         std::cout << "searchEle is NULL" << std::endl;
     64        cout << "searchEle is NULL" << endl;
    6165        retVal = 1;
     66    } else {
     67        cout << "searchParent path = :" << searchEle->nodePath() << ":" << endl;
     68        cout << "searchParent comp = :" << searchEle->nodeComp() << ":" << endl;
     69        cout << "searchParent   id = :" << searchEle->nodeId()   << ":" << endl;
     70        cout << "searchParent type = :" << searchEle->nodeType() << ":" << endl;
     71        retVal = 0;
     72    }
     73
     74    return retVal;
     75}
     76
     77int test_get (RpLibrary* lib, string path)
     78{
     79    int retVal = 1;
     80    string searchVal = lib->get(path);
     81
     82    cout << "TESTING GET       : path = " << path << endl;
     83
     84    if (searchVal.empty()) {
     85        cout << "searchVal is EMPTY STRING" << endl;
     86        retVal = 1;
    6287    }
    6388    else {
    64         std::cout << "searchParent path = :" << searchEle->nodePath() << ":" << std::endl;
    65         std::cout << "searchParent comp = :" << searchEle->nodeComp() << ":" << std::endl;
    66         std::cout << "searchParent   id = :" << searchEle->nodeId()   << ":" << std::endl;
    67         std::cout << "searchParent type = :" << searchEle->nodeType() << ":" << std::endl;
    68         retVal = 0;
    69     }
    70 
    71     return retVal;
    72 }
    73 
    74 int test_get (RpLibrary* lib, std::string path )
    75 {
    76     int retVal = 1;
    77     std::string searchVal = lib->get(path);
    78 
    79     std::cout << "TESTING GET       : path = " << path << std::endl;
     89        cout << "searchVal = :" << searchVal << ":" << endl;
     90        retVal = 0;
     91    }
     92
     93    return retVal;
     94}
     95
     96int test_getString (RpLibrary* lib, string path)
     97{
     98    int retVal = 1;
     99    string searchVal = lib->getString(path);
     100
     101    cout << "TESTING GET String: path = " << path << endl;
    80102
    81103    if (searchVal.empty()) {
    82         std::cout << "searchVal is EMPTY STRING" << std::endl;
     104        cout << "searchVal is EMPTY STRING" << endl;
    83105        retVal = 1;
    84106    }
    85107    else {
    86         std::cout << "searchVal = :" << searchVal << ":" << std::endl;
    87         retVal = 0;
    88     }
    89 
    90     return retVal;
    91 }
    92 
    93 int test_getString (RpLibrary* lib, std::string path )
    94 {
    95     int retVal = 1;
    96     std::string searchVal = lib->getString(path);
    97 
    98     std::cout << "TESTING GET String: path = " << path << std::endl;
    99 
    100     if (searchVal.empty()) {
    101         std::cout << "searchVal is EMPTY STRING" << std::endl;
    102         retVal = 1;
    103     }
    104     else {
    105         std::cout << "searchVal = :" << searchVal << ":" << std::endl;
    106         retVal = 0;
    107     }
    108 
    109     return retVal;
    110 }
    111 
    112 int test_getDouble (RpLibrary* lib, std::string path )
     108        cout << "searchVal = :" << searchVal << ":" << endl;
     109        retVal = 0;
     110    }
     111
     112    return retVal;
     113}
     114
     115int test_getDouble (RpLibrary* lib, string path)
    113116{
    114117    int retVal = 1;
    115118    double searchVal = lib->getDouble(path);
    116119
    117     std::cout << "TESTING GET Double: path = " << path << std::endl;
    118 
    119     std::cout << "searchVal = :" << searchVal << ":" << std::endl;
     120    cout << "TESTING GET Double: path = " << path << endl;
     121
     122    cout << "searchVal = :" << searchVal << ":" << endl;
    120123    retVal = 0;
    121124
     
    123126}
    124127
    125 int test_getInt (RpLibrary* lib, std::string path )
     128int test_getInt (RpLibrary* lib, string path)
    126129{
    127130    int retVal = 1;
    128131    int searchVal = lib->getInt(path);
    129132
    130     std::cout << "TESTING GET INT: path = " << path << std::endl;
    131 
    132     std::cout << "searchVal = :" << searchVal << ":" << std::endl;
     133    cout << "TESTING GET INT: path = " << path << endl;
     134
     135    cout << "searchVal = :" << searchVal << ":" << endl;
    133136    retVal = 0;
    134137
     
    136139}
    137140
    138 int test_getBool (RpLibrary* lib, std::string path )
     141int
     142test_getBool (RpLibrary* lib, string path)
    139143{
    140144    int retVal = 1;
    141145    bool searchVal = lib->getBool(path);
    142146
    143     std::cout << "TESTING GET Bool: path = " << path << std::endl;
    144 
    145     std::cout << "searchVal = :" << searchVal << ":" << std::endl;
     147    cout << "TESTING GET Bool: path = " << path << endl;
     148
     149    cout << "searchVal = :" << searchVal << ":" << endl;
    146150    retVal = 0;
    147151
     
    149153}
    150154
    151 int test_putObj (   RpLibrary* fromLib, std::string fromPath,
    152                     RpLibrary* toLib, std::string toPath)
     155int
     156test_putObj (   RpLibrary* fromLib, string fromPath,
     157                    RpLibrary* toLib, string toPath)
    153158{
    154159    int retVal = 1;
    155160    RpLibrary* fromEle = fromLib->element(fromPath);
    156161    RpLibrary* foundEle = NULL;
    157     std::string newNodeName = "";
    158 
    159     std::cout << "TESTING PUT Object:" << std::endl;
    160     std::cout << "fromPath = " << fromPath << std::endl;
    161     std::cout << "toPath = " << toPath << std::endl;
     162    string newNodeName = "";
     163
     164    cout << "TESTING PUT Object:" << endl;
     165    cout << "fromPath = " << fromPath << endl;
     166    cout << "toPath = " << toPath << endl;
    162167
    163168    // put the element into the new library/xmltree
     
    169174    // grab the element
    170175    if ((foundEle = toLib->element(newNodeName))){
    171         std::cout << "SUCCESS: foundEle was found" << std::endl;
    172         retVal = 0;
    173     }
    174 
    175     return retVal;
    176 }
    177 
    178 int test_copy (   RpLibrary* fromLib, std::string fromPath,
    179                     RpLibrary* toLib, std::string toPath)
     176        cout << "SUCCESS: foundEle was found" << endl;
     177        retVal = 0;
     178    }
     179
     180    return retVal;
     181}
     182
     183int test_copy (   RpLibrary* fromLib, string fromPath,
     184                    RpLibrary* toLib, string toPath)
    180185{
    181186    int retVal = 1;
    182187    RpLibrary* fromEle = fromLib->element(fromPath);
    183188    RpLibrary* foundEle = NULL;
    184     std::string newNodeName = "";
    185 
    186     std::cout << "TESTING COPY:" << std::endl;
    187     std::cout << "fromPath = " << fromPath << std::endl;
    188     std::cout << "toPath = " << toPath << std::endl;
     189    string newNodeName = "";
     190
     191    cout << "TESTING COPY:" << endl;
     192    cout << "fromPath = " << fromPath << endl;
     193    cout << "toPath = " << toPath << endl;
    189194
    190195    // put the element into the new library/xmltree
     
    196201    // grab the element
    197202    if ((foundEle = toLib->element(newNodeName))){
    198         std::cout << "SUCCESS: foundEle was found" << std::endl;
     203        cout << "SUCCESS: foundEle was found" << endl;
    199204        retVal = 0;
    200205    }
    201206    else {
    202         std::cout << "FAILURE: foundEle WAS NOT found" << std::endl;
    203     }
    204 
    205     return retVal;
    206 }
    207 
    208 int test_remove (RpLibrary* lib, std::string path)
     207        cout << "FAILURE: foundEle WAS NOT found" << endl;
     208    }
     209
     210    return retVal;
     211}
     212
     213int test_remove (RpLibrary* lib, string path)
    209214{
    210215    RpLibrary* getRslt = NULL;
    211216    int retVal = 1;
    212     std::cout << "TESTING REMOVE:" << std::endl;
    213     // std::cout << "lib's xml:" << std::endl << lib->xml() << std::endl;
     217    cout << "TESTING REMOVE:" << endl;
     218    // cout << "lib's xml:" << endl << lib->xml() << endl;
    214219    if (lib) {
    215220        lib->remove(path);
     
    217222            getRslt = lib->element(path);
    218223            if (getRslt) {
    219                 std::cout << "FAILURE: " << path << " not removed" << std::endl;
    220                 std::cout << "lib's xml:" << std::endl << lib->xml() << std::endl;
     224                cout << "FAILURE: " << path << " not removed" << endl;
     225                cout << "lib's xml:" << endl << lib->xml() << endl;
    221226            }
    222227            else {
    223                 std::cout << "SUCCESS: " << path << " removed" << std::endl;
     228                cout << "SUCCESS: " << path << " removed" << endl;
    224229                retVal = 0;
    225230            }
     
    232237int test_entities (RpLibrary* lib)
    233238{
    234     std::list<std::string>::iterator iter;
    235     std::list<std::string> elist = lib->entities();
     239    list<string>::iterator iter;
     240    list<string> elist = lib->entities();
    236241
    237242    iter = elist.begin();
    238243
    239     std::cout << "TESTING ENTITIES BEGIN" << std::endl;
    240     std::cout << "path = "<< lib->nodePath() << std::endl;
     244    cout << "TESTING ENTITIES BEGIN" << endl;
     245    cout << "path = "<< lib->nodePath() << endl;
    241246
    242247    while (iter != elist.end() ) {
    243         std::cout << *iter << std::endl;
     248        cout << *iter << endl;
    244249        iter++;
    245250    }
    246251
    247     std::cout << "TESTING ENTITIES END" << std::endl;
     252    cout << "TESTING ENTITIES END" << endl;
    248253
    249254    return 0;
     
    252257int test_diff (RpLibrary* lib1, RpLibrary* lib2)
    253258{
    254     std::list<std::string>::iterator iter;
    255     std::list<std::string> elist;
     259    list<string>::iterator iter;
     260    list<string> elist;
    256261
    257262    elist = lib1->diff(lib2,"input");
     
    259264    iter = elist.begin();
    260265
    261     std::cout << "TESTING DIFF BEGIN" << std::endl;
     266    cout << "TESTING DIFF BEGIN" << endl;
    262267
    263268    int count = 0;
    264269    while (iter != elist.end() ) {
    265         std::cout << *iter << " ";
     270        cout << *iter << " ";
    266271        iter++;
    267272        count++;
    268273        if (count == 4) {
    269             std::cout << std::endl;
     274            cout << endl;
    270275            count = 0;
    271276        }
     
    273278    }
    274279
    275     std::cout << "TESTING DIFF END" << std::endl;
     280    cout << "TESTING DIFF END" << endl;
    276281
    277282    return 0;
     
    279284
    280285/*
    281 int test_children (RpLibrary* lib, std::string path, std::string type )
     286int test_children (RpLibrary* lib, string path, string type )
    282287{
    283288    int retVal = 1;
    284289    int childNum = -1;
    285290
    286     std::cout << "TESTING CHILDREN: path = " << path << std::endl;
     291    cout << "TESTING CHILDREN: path = " << path << endl;
    287292    RpLibrary** searchEle = lib->children(path,"",type);
    288293
    289294    if (!searchEle || !*searchEle) {
    290         std::cout << "searchEle is NULL -> NO CHILDREN" << std::endl;
     295        cout << "searchEle is NULL -> NO CHILDREN" << endl;
    291296        retVal = 1;
    292297    }
     
    294299
    295300        while (searchEle[++childNum]) {
    296             std::cout << "searchEle comp = :" << searchEle[childNum]->nodeComp()
    297                 << ":" << std::endl;
    298             std::cout << "searchEle   id = :" << searchEle[childNum]->nodeId()   
    299                 << ":" << std::endl;
    300             std::cout << "searchEle type = :" << searchEle[childNum]->nodeType()
    301                 << ":" << std::endl;
     301            cout << "searchEle comp = :" << searchEle[childNum]->nodeComp()
     302                << ":" << endl;
     303            cout << "searchEle   id = :" << searchEle[childNum]->nodeId()   
     304                << ":" << endl;
     305            cout << "searchEle type = :" << searchEle[childNum]->nodeType()
     306                << ":" << endl;
    302307            delete (searchEle[childNum]);
    303308            searchEle[childNum] = NULL;
     
    314319*/
    315320
    316 int test_children (RpLibrary* lib, std::string path, std::string type )
     321int test_children (RpLibrary* lib, string path, string type )
    317322{
    318323    int retVal = 1;
    319324    RpLibrary* childEle = NULL;
    320325
    321     std::cout << "TESTING CHILDREN: path = " << path << std::endl;
     326    cout << "TESTING CHILDREN: path = " << path << endl;
    322327
    323328    while ( (childEle = lib->children(path,childEle,type)) ) {
    324329
    325         std::cout << "childEle path = :" << childEle->nodePath()
    326             << ":" << std::endl;
    327         std::cout << "childEle comp = :" << childEle->nodeComp()
    328             << ":" << std::endl;
    329         std::cout << "childEle   id = :" << childEle->nodeId()   
    330             << ":" << std::endl;
    331         std::cout << "childEle type = :" << childEle->nodeType()
    332             << ":" << std::endl;
     330        cout << "childEle path = :" << childEle->nodePath()
     331            << ":" << endl;
     332        cout << "childEle comp = :" << childEle->nodeComp()
     333            << ":" << endl;
     334        cout << "childEle   id = :" << childEle->nodeId()   
     335            << ":" << endl;
     336        cout << "childEle type = :" << childEle->nodeType()
     337            << ":" << endl;
    333338
    334339        retVal = 0;
     
    337342
    338343    if (!childEle) {
    339         std::cout << "No more children" << std::endl;
     344        cout << "No more children" << endl;
    340345    }
    341346
     
    355360    }
    356361
    357     lib = new RpLibrary(std::string(argv[1]));
     362    lib = new RpLibrary(string(argv[1]));
    358363
    359364    test_element(lib,"");
     
    424429    test_children(lib,"input","number");
    425430
    426     std::cout << lib->xml() << std::endl;
     431    cout << lib->xml() << endl;
    427432
    428433    RpLibrary* remEle = lib->element("input.test.(min)");
     
    431436    test_remove(lib, "input.test.(min)");
    432437    test_remove(lib, "input.test.(max)");
    433     std::cout << lib->xml() << std::endl;
     438    cout << lib->xml() << endl;
    434439
    435440    RpLibrary* libInput = lib->element("input");
     
    438443
    439444    /*
    440     std::list<std::string> l1 = lib->value("input.number(min)");
    441     std::list<std::string> l2 = lib->value("input.number(max)");
    442     std::cout << "l1 = " << l1.front() << " " << l1.back() << std::endl;
    443     std::cout << "l2 = " << l2.front() << " " << l2.back() << std::endl;
     445    list<string> l1 = lib->value("input.number(min)");
     446    list<string> l2 = lib->value("input.number(max)");
     447    cout << "l1 = " << l1.front() << " " << l1.back() << endl;
     448    cout << "l2 = " << l2.front() << " " << l2.back() << endl;
    444449    */
    445450
    446     RpLibrary* dlib1 = new RpLibrary(std::string(argv[1]));
    447     RpLibrary* dlib2 = new RpLibrary(std::string(argv[1]));
     451    RpLibrary* dlib1 = new RpLibrary(string(argv[1]));
     452    RpLibrary* dlib2 = new RpLibrary(string(argv[1]));
    448453    test_diff(dlib1,dlib2);
    449     std::cout << "dlib1-------------------------------------" << std::endl;
    450     std::cout << dlib1->xml() << std::endl;
    451     std::cout << "dlib2-------------------------------------" << std::endl;
    452     std::cout << dlib1->xml() << std::endl;
     454    cout << "dlib1-------------------------------------" << endl;
     455    cout << dlib1->xml() << endl;
     456    cout << "dlib2-------------------------------------" << endl;
     457    cout << dlib1->xml() << endl;
    453458    dlib1 = lib;
    454459    test_diff(dlib1,dlib2);
    455     std::cout << "dlib1-------------------------------------" << std::endl;
    456     std::cout << dlib1->xml() << std::endl;
    457     std::cout << "dlib2-------------------------------------" << std::endl;
    458     std::cout << dlib2->xml() << std::endl;
     460    cout << "dlib1-------------------------------------" << endl;
     461    cout << dlib1->xml() << endl;
     462    cout << "dlib2-------------------------------------" << endl;
     463    cout << dlib2->xml() << endl;
    459464
    460465
     
    484489
    485490
    486     std::cout << "//////////////////// LIB 2 ////////////////////" << std::endl;
    487     std::cout << lib2.xml() << std::endl;
    488     std::cout << "//////////////////// LIB 3 ////////////////////" << std::endl;
    489     std::cout << lib3.xml() << std::endl;
     491    cout << "//////////////////// LIB 2 ////////////////////" << endl;
     492    cout << lib2.xml() << endl;
     493    cout << "//////////////////// LIB 3 ////////////////////" << endl;
     494    cout << lib3.xml() << endl;
    490495
    491496    lib2.result();
    492497
    493498
    494     std::cout << "testing with &lt;number&gt;" << std::endl;
     499    cout << "testing with &lt;number&gt;" << endl;
    495500    lib2.put("input.dsk.test", "slkdjfs slkdfj lks &lt;number&gt; sdlkfj sdlkjf","",1);
    496     std::cout << lib2.xml() << std::endl;
    497     std::cout << "testing get &lt;number&gt;" << std::endl;
    498     std::cout << lib2.get("input.dsk.test") << std::endl;
    499     std::cout << "testing with <number>" << std::endl;
     501    cout << lib2.xml() << endl;
     502    cout << "testing get &lt;number&gt;" << endl;
     503    cout << lib2.get("input.dsk.test") << endl;
     504    cout << "testing with <number>" << endl;
    500505    lib2.put("input.dsk.test2", "slkdjfs slkdfj lks <number> sdlkfj sdlkjf","",1);
    501     std::cout << lib2.xml() << std::endl;
     506    cout << lib2.xml() << endl;
    502507
    503508    /*
     
    505510    RpLibrary* childEle2 = NULL;
    506511    while ( (childEle = lib2.children("input",childEle)) ) {
    507         std::cout << "childEle path = :" << childEle->nodePath() << ":" << std::endl;
     512        cout << "childEle path = :" << childEle->nodePath() << ":" << endl;
    508513        while ( (childEle2 = childEle->children("",childEle2)) ) {
    509             std::cout << "childEle2 path = :" << childEle2->nodePath() << ":" << std::endl;
     514            cout << "childEle2 path = :" << childEle2->nodePath() << ":" << endl;
    510515        }
    511516        childEle2 = NULL;
    512517        if (!childEle) {
    513             std::cout << "childEle Not null" << std::endl;
     518            cout << "childEle Not null" << endl;
    514519        }
    515520    }
Note: See TracChangeset for help on using the changeset viewer.