Commit 15bc092ed640c643998dcd805a78b44feaf53bc4
1 parent
9a22683e
add load/save testing
Showing
1 changed file
with
63 additions
and
2 deletions
test/test_GXml.cpp
| ... | ... | @@ -30,7 +30,7 @@ const std::string xml_file = "data/test.xml"; |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | /*************************************************************************** |
| 33 | - * Test: GXml_construct * | |
| 33 | + * Test: GXml constructors * | |
| 34 | 34 | ***************************************************************************/ |
| 35 | 35 | void test_GXml_construct(void) |
| 36 | 36 | { |
| ... | ... | @@ -53,7 +53,6 @@ void test_GXml_construct(void) |
| 53 | 53 | // Test load constructor |
| 54 | 54 | try { |
| 55 | 55 | GXml xml(xml_file); |
| 56 | - std::cout << xml << std::endl; | |
| 57 | 56 | } |
| 58 | 57 | catch (std::exception &e) { |
| 59 | 58 | std::cout << std::endl |
| ... | ... | @@ -88,6 +87,67 @@ void test_GXml_construct(void) |
| 88 | 87 | |
| 89 | 88 | |
| 90 | 89 | /*************************************************************************** |
| 90 | + * Test: GXml loading/saving * | |
| 91 | + ***************************************************************************/ | |
| 92 | +void test_GXml_load(void) | |
| 93 | +{ | |
| 94 | + // Dump header | |
| 95 | + std::cout << "Test XML loading and saving: "; | |
| 96 | + | |
| 97 | + // Test loading | |
| 98 | + try { | |
| 99 | + GXml xml; | |
| 100 | + xml.load(xml_file); | |
| 101 | + } | |
| 102 | + catch (std::exception &e) { | |
| 103 | + std::cout << std::endl | |
| 104 | + << "TEST ERROR: Unable to load XML document." | |
| 105 | + << std::endl; | |
| 106 | + std::cout << e.what() << std::endl; | |
| 107 | + throw; | |
| 108 | + } | |
| 109 | + std::cout << "."; | |
| 110 | + | |
| 111 | + // Test saving | |
| 112 | + try { | |
| 113 | + GXml xml; | |
| 114 | + xml.load(xml_file); | |
| 115 | + xml.save("test.xml"); | |
| 116 | + xml.load("test.xml"); | |
| 117 | + } | |
| 118 | + catch (std::exception &e) { | |
| 119 | + std::cout << std::endl | |
| 120 | + << "TEST ERROR: Unable to save XML document." | |
| 121 | + << std::endl; | |
| 122 | + std::cout << e.what() << std::endl; | |
| 123 | + throw; | |
| 124 | + } | |
| 125 | + std::cout << "."; | |
| 126 | + | |
| 127 | + // Test loading of saved XML document | |
| 128 | + try { | |
| 129 | + GXml xml; | |
| 130 | + xml.load("test.xml"); | |
| 131 | + } | |
| 132 | + catch (std::exception &e) { | |
| 133 | + std::cout << std::endl | |
| 134 | + << "TEST ERROR: Unable to load previously saved XML document." | |
| 135 | + << std::endl; | |
| 136 | + std::cout << e.what() << std::endl; | |
| 137 | + throw; | |
| 138 | + } | |
| 139 | + std::cout << "."; | |
| 140 | + | |
| 141 | + // Signal final test success | |
| 142 | + std::cout << " ok." << std::endl; | |
| 143 | + | |
| 144 | + // Exit test | |
| 145 | + return; | |
| 146 | + | |
| 147 | +} | |
| 148 | + | |
| 149 | + | |
| 150 | +/*************************************************************************** | |
| 91 | 151 | * Main test function * |
| 92 | 152 | ***************************************************************************/ |
| 93 | 153 | int main(void) |
| ... | ... | @@ -100,6 +160,7 @@ int main(void) |
| 100 | 160 | |
| 101 | 161 | // Execute XML tests |
| 102 | 162 | test_GXml_construct(); |
| 163 | + test_GXml_load(); | |
| 103 | 164 | |
| 104 | 165 | // Return |
| 105 | 166 | return 0; | ... | ... |