Commit e7cba5657ea877bd4e36d0ee972ea6bc93722503
1 parent
4624132d
add node access tests
Showing
1 changed file
with
71 additions
and
0 deletions
test/test_GXml.cpp
| ... | ... | @@ -349,6 +349,76 @@ void test_GXml_load(void) |
| 349 | 349 | |
| 350 | 350 | |
| 351 | 351 | /*************************************************************************** |
| 352 | + * Test: GXml element access * | |
| 353 | + ***************************************************************************/ | |
| 354 | +void test_GXml_access(void) | |
| 355 | +{ | |
| 356 | + // Dump header | |
| 357 | + std::cout << "Test XML element access: "; | |
| 358 | + | |
| 359 | + // Test root document access | |
| 360 | + try { | |
| 361 | + GXml xml; | |
| 362 | + xml.load(xml_file); | |
| 363 | + std::cout << "."; | |
| 364 | + if (xml.children() != 3) { | |
| 365 | + std::cout << std::endl | |
| 366 | + << "TEST ERROR: Unexpected number of children in document " | |
| 367 | + << xml.children() << std::endl; | |
| 368 | + throw; | |
| 369 | + } | |
| 370 | + std::cout << "."; | |
| 371 | + for (int i = 0; i < xml.children(); ++i) | |
| 372 | + GXmlNode* ptr = xml.child(i); | |
| 373 | + std::cout << "."; | |
| 374 | + if (xml.elements() != 1) { | |
| 375 | + std::cout << std::endl | |
| 376 | + << "TEST ERROR: Unexpected number of child elements in document " | |
| 377 | + << xml.elements() << std::endl; | |
| 378 | + throw; | |
| 379 | + } | |
| 380 | + std::cout << "."; | |
| 381 | + for (int i = 0; i < xml.elements(); ++i) | |
| 382 | + GXmlNode* ptr = xml.element(i); | |
| 383 | + std::cout << "."; | |
| 384 | + if (xml.elements("source_library") != 1) { | |
| 385 | + std::cout << std::endl | |
| 386 | + << "TEST ERROR: Unexpected number of child elements in document " | |
| 387 | + << xml.elements("source_library") << std::endl; | |
| 388 | + throw; | |
| 389 | + } | |
| 390 | + std::cout << "."; | |
| 391 | + for (int i = 0; i < xml.elements("source_library"); ++i) { | |
| 392 | + GXmlElement* ptr = xml.element("source_library", i); | |
| 393 | + if (ptr->name() != "source_library") { | |
| 394 | + std::cout << std::endl | |
| 395 | + << "TEST ERROR: Unexpected element name " | |
| 396 | + << ptr->name() << std::endl; | |
| 397 | + throw; | |
| 398 | + } | |
| 399 | + } | |
| 400 | + std::cout << "."; | |
| 401 | + //std::cout << xml.elements("source_library") << std::endl; | |
| 402 | + } | |
| 403 | + catch (std::exception &e) { | |
| 404 | + std::cout << std::endl | |
| 405 | + << "TEST ERROR: Unable to access XML elements." | |
| 406 | + << std::endl; | |
| 407 | + std::cout << e.what() << std::endl; | |
| 408 | + throw; | |
| 409 | + } | |
| 410 | + std::cout << "."; | |
| 411 | + | |
| 412 | + // Signal final test success | |
| 413 | + std::cout << " ok." << std::endl; | |
| 414 | + | |
| 415 | + // Exit test | |
| 416 | + return; | |
| 417 | + | |
| 418 | +} | |
| 419 | + | |
| 420 | + | |
| 421 | +/*************************************************************************** | |
| 352 | 422 | * Main test function * |
| 353 | 423 | ***************************************************************************/ |
| 354 | 424 | int main(void) |
| ... | ... | @@ -364,6 +434,7 @@ int main(void) |
| 364 | 434 | test_GXml_elements(); |
| 365 | 435 | test_GXml_construct(); |
| 366 | 436 | test_GXml_load(); |
| 437 | + test_GXml_access(); | |
| 367 | 438 | |
| 368 | 439 | // Return |
| 369 | 440 | return 0; | ... | ... |