Changeset 1022
- Timestamp:
- Jun 8, 2008, 6:35:41 PM (16 years ago)
- Location:
- trunk/test/src
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/src/RpLibrary_test.cc
r495 r1022 14 14 #include "RpLibrary.h" 15 15 #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 19 using namespace std; 20 21 int test_element (RpLibrary* lib, string path); 22 int test_parent (RpLibrary* lib, string path); 23 int test_get (RpLibrary* lib, string path); 24 int test_getString (RpLibrary* lib, string path); 25 int test_getDouble (RpLibrary* lib, string path); 26 int test_getInt (RpLibrary* lib, string path); 27 int test_getBool (RpLibrary* lib, string path); 28 int test_putObj (RpLibrary* fromLib, string fromPath, 29 RpLibrary* toLib, string toPath); 30 int test_copy (RpLibrary* fromLib, string fromPath, 31 RpLibrary* toLib, string toPath); 32 int test_remove (RpLibrary* lib, string path); 33 34 int test_element (RpLibrary* lib, string path) 31 35 { 32 36 int retVal = 1; 33 37 RpLibrary* searchEle = lib->element(path); 34 38 35 std::cout << "TESTING ELEMENT: path = " << path << std::endl;39 cout << "TESTING ELEMENT: path = " << path << endl; 36 40 37 41 if (!searchEle) { 38 std::cout << "searchEle is NULL" << std::endl;42 cout << "searchEle is NULL" << endl; 39 43 retVal = 1; 40 44 } 41 45 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, st d::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 56 int test_parent (RpLibrary* lib, string path) 53 57 { 54 58 int retVal = 1; 55 59 RpLibrary* searchEle = lib->parent(path); 56 60 57 std::cout << "TESTING PARENT: path = " << path << std::endl;61 cout << "TESTING PARENT: path = " << path << endl; 58 62 59 63 if (!searchEle) { 60 std::cout << "searchEle is NULL" << std::endl;64 cout << "searchEle is NULL" << endl; 61 65 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 77 int 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; 62 87 } 63 88 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 96 int 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; 80 102 81 103 if (searchVal.empty()) { 82 std::cout << "searchVal is EMPTY STRING" << std::endl;104 cout << "searchVal is EMPTY STRING" << endl; 83 105 retVal = 1; 84 106 } 85 107 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 115 int test_getDouble (RpLibrary* lib, string path) 113 116 { 114 117 int retVal = 1; 115 118 double searchVal = lib->getDouble(path); 116 119 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; 120 123 retVal = 0; 121 124 … … 123 126 } 124 127 125 int test_getInt (RpLibrary* lib, st d::string path)128 int test_getInt (RpLibrary* lib, string path) 126 129 { 127 130 int retVal = 1; 128 131 int searchVal = lib->getInt(path); 129 132 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; 133 136 retVal = 0; 134 137 … … 136 139 } 137 140 138 int test_getBool (RpLibrary* lib, std::string path ) 141 int 142 test_getBool (RpLibrary* lib, string path) 139 143 { 140 144 int retVal = 1; 141 145 bool searchVal = lib->getBool(path); 142 146 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; 146 150 retVal = 0; 147 151 … … 149 153 } 150 154 151 int test_putObj ( RpLibrary* fromLib, std::string fromPath, 152 RpLibrary* toLib, std::string toPath) 155 int 156 test_putObj ( RpLibrary* fromLib, string fromPath, 157 RpLibrary* toLib, string toPath) 153 158 { 154 159 int retVal = 1; 155 160 RpLibrary* fromEle = fromLib->element(fromPath); 156 161 RpLibrary* foundEle = NULL; 157 st d::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; 162 167 163 168 // put the element into the new library/xmltree … … 169 174 // grab the element 170 175 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, st d::string fromPath,179 RpLibrary* toLib, st d::string toPath)176 cout << "SUCCESS: foundEle was found" << endl; 177 retVal = 0; 178 } 179 180 return retVal; 181 } 182 183 int test_copy ( RpLibrary* fromLib, string fromPath, 184 RpLibrary* toLib, string toPath) 180 185 { 181 186 int retVal = 1; 182 187 RpLibrary* fromEle = fromLib->element(fromPath); 183 188 RpLibrary* foundEle = NULL; 184 st d::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; 189 194 190 195 // put the element into the new library/xmltree … … 196 201 // grab the element 197 202 if ((foundEle = toLib->element(newNodeName))){ 198 std::cout << "SUCCESS: foundEle was found" << std::endl;203 cout << "SUCCESS: foundEle was found" << endl; 199 204 retVal = 0; 200 205 } 201 206 else { 202 std::cout << "FAILURE: foundEle WAS NOT found" << std::endl;203 } 204 205 return retVal; 206 } 207 208 int test_remove (RpLibrary* lib, st d::string path)207 cout << "FAILURE: foundEle WAS NOT found" << endl; 208 } 209 210 return retVal; 211 } 212 213 int test_remove (RpLibrary* lib, string path) 209 214 { 210 215 RpLibrary* getRslt = NULL; 211 216 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; 214 219 if (lib) { 215 220 lib->remove(path); … … 217 222 getRslt = lib->element(path); 218 223 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; 221 226 } 222 227 else { 223 std::cout << "SUCCESS: " << path << " removed" << std::endl;228 cout << "SUCCESS: " << path << " removed" << endl; 224 229 retVal = 0; 225 230 } … … 232 237 int test_entities (RpLibrary* lib) 233 238 { 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(); 236 241 237 242 iter = elist.begin(); 238 243 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; 241 246 242 247 while (iter != elist.end() ) { 243 std::cout << *iter << std::endl;248 cout << *iter << endl; 244 249 iter++; 245 250 } 246 251 247 std::cout << "TESTING ENTITIES END" << std::endl;252 cout << "TESTING ENTITIES END" << endl; 248 253 249 254 return 0; … … 252 257 int test_diff (RpLibrary* lib1, RpLibrary* lib2) 253 258 { 254 std::list<std::string>::iterator iter;255 std::list<std::string> elist;259 list<string>::iterator iter; 260 list<string> elist; 256 261 257 262 elist = lib1->diff(lib2,"input"); … … 259 264 iter = elist.begin(); 260 265 261 std::cout << "TESTING DIFF BEGIN" << std::endl;266 cout << "TESTING DIFF BEGIN" << endl; 262 267 263 268 int count = 0; 264 269 while (iter != elist.end() ) { 265 std::cout << *iter << " ";270 cout << *iter << " "; 266 271 iter++; 267 272 count++; 268 273 if (count == 4) { 269 std::cout << std::endl;274 cout << endl; 270 275 count = 0; 271 276 } … … 273 278 } 274 279 275 std::cout << "TESTING DIFF END" << std::endl;280 cout << "TESTING DIFF END" << endl; 276 281 277 282 return 0; … … 279 284 280 285 /* 281 int test_children (RpLibrary* lib, st d::string path, std::string type )286 int test_children (RpLibrary* lib, string path, string type ) 282 287 { 283 288 int retVal = 1; 284 289 int childNum = -1; 285 290 286 std::cout << "TESTING CHILDREN: path = " << path << std::endl;291 cout << "TESTING CHILDREN: path = " << path << endl; 287 292 RpLibrary** searchEle = lib->children(path,"",type); 288 293 289 294 if (!searchEle || !*searchEle) { 290 std::cout << "searchEle is NULL -> NO CHILDREN" << std::endl;295 cout << "searchEle is NULL -> NO CHILDREN" << endl; 291 296 retVal = 1; 292 297 } … … 294 299 295 300 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; 302 307 delete (searchEle[childNum]); 303 308 searchEle[childNum] = NULL; … … 314 319 */ 315 320 316 int test_children (RpLibrary* lib, st d::string path, std::string type )321 int test_children (RpLibrary* lib, string path, string type ) 317 322 { 318 323 int retVal = 1; 319 324 RpLibrary* childEle = NULL; 320 325 321 std::cout << "TESTING CHILDREN: path = " << path << std::endl;326 cout << "TESTING CHILDREN: path = " << path << endl; 322 327 323 328 while ( (childEle = lib->children(path,childEle,type)) ) { 324 329 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; 333 338 334 339 retVal = 0; … … 337 342 338 343 if (!childEle) { 339 std::cout << "No more children" << std::endl;344 cout << "No more children" << endl; 340 345 } 341 346 … … 355 360 } 356 361 357 lib = new RpLibrary(st d::string(argv[1]));362 lib = new RpLibrary(string(argv[1])); 358 363 359 364 test_element(lib,""); … … 424 429 test_children(lib,"input","number"); 425 430 426 std::cout << lib->xml() << std::endl;431 cout << lib->xml() << endl; 427 432 428 433 RpLibrary* remEle = lib->element("input.test.(min)"); … … 431 436 test_remove(lib, "input.test.(min)"); 432 437 test_remove(lib, "input.test.(max)"); 433 std::cout << lib->xml() << std::endl;438 cout << lib->xml() << endl; 434 439 435 440 RpLibrary* libInput = lib->element("input"); … … 438 443 439 444 /* 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; 444 449 */ 445 450 446 RpLibrary* dlib1 = new RpLibrary(st d::string(argv[1]));447 RpLibrary* dlib2 = new RpLibrary(st d::string(argv[1]));451 RpLibrary* dlib1 = new RpLibrary(string(argv[1])); 452 RpLibrary* dlib2 = new RpLibrary(string(argv[1])); 448 453 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; 453 458 dlib1 = lib; 454 459 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; 459 464 460 465 … … 484 489 485 490 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; 490 495 491 496 lib2.result(); 492 497 493 498 494 std::cout << "testing with <number>" << std::endl;499 cout << "testing with <number>" << endl; 495 500 lib2.put("input.dsk.test", "slkdjfs slkdfj lks <number> sdlkfj sdlkjf","",1); 496 std::cout << lib2.xml() << std::endl;497 std::cout << "testing get <number>" << 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 <number>" << endl; 503 cout << lib2.get("input.dsk.test") << endl; 504 cout << "testing with <number>" << endl; 500 505 lib2.put("input.dsk.test2", "slkdjfs slkdfj lks <number> sdlkfj sdlkjf","",1); 501 std::cout << lib2.xml() << std::endl;506 cout << lib2.xml() << endl; 502 507 503 508 /* … … 505 510 RpLibrary* childEle2 = NULL; 506 511 while ( (childEle = lib2.children("input",childEle)) ) { 507 std::cout << "childEle path = :" << childEle->nodePath() << ":" << std::endl;512 cout << "childEle path = :" << childEle->nodePath() << ":" << endl; 508 513 while ( (childEle2 = childEle->children("",childEle2)) ) { 509 std::cout << "childEle2 path = :" << childEle2->nodePath() << ":" << std::endl;514 cout << "childEle2 path = :" << childEle2->nodePath() << ":" << endl; 510 515 } 511 516 childEle2 = NULL; 512 517 if (!childEle) { 513 std::cout << "childEle Not null" << std::endl;518 cout << "childEle Not null" << endl; 514 519 } 515 520 }
Note: See TracChangeset
for help on using the changeset viewer.