Newer
Older
Martin Killenberg
committed
#define BOOST_TEST_MODULE DoocsProcessArrayTest
// Only after defining the name include the unit test header.
#include <boost/test/included/unit_test.hpp>
//#include <boost/test/test_case_template.hpp>
Martin Killenberg
committed
#include "VariableMapper.h"
using namespace ChimeraTK;
Martin Killenberg
committed
BOOST_AUTO_TEST_CASE( testCreation ){
VariableMapper & vm = VariableMapper::getInstance();
Martin Killenberg
committed
VariableMapper & vm2 = VariableMapper::getInstance();
BOOST_CHECK( &vm == &vm2 );
Martin Killenberg
committed
}
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/** Here is the example tree on which the examples and tests are based:
*\verbatim
/
├── A
│ ├── a
│ │ ├── di
│ │ └── do
│ └── b
├── B
│ ├── a
│ │ └── dr
│ └── c
│ ├── de
│ └── gne
├── C
│ ├── a
│ │ └── da
│ ├── b
│ │ └── ge
│ └── c
│ ├── be
│ └── de
└── DIRECT
├── DOUBLE
├── DOUBLE_ARRAY
├── INT
└── INT_ARRAY
*\endverbatim
*/
std::set< std::string > generateInputVariables(){
std::set< std::string > inputVariables;
inputVariables.insert("/A/a/di");
inputVariables.insert("/A/a/do");
inputVariables.insert("/A/b");
inputVariables.insert("/B/a/dr");
inputVariables.insert("/B/c/de");
inputVariables.insert("/B/c/gne");
inputVariables.insert("/C/a/da");
inputVariables.insert("/C/b/ge");
inputVariables.insert("/C/c/be");
inputVariables.insert("/C/c/de"); // there also is a c/de in B
inputVariables.insert("/DIRECT/DOUBLE");
inputVariables.insert("/DIRECT/DOUBLE_ARRAY");
inputVariables.insert("/DIRECT/INT");
inputVariables.insert("/DIRECT/INT_ARRAY");
return inputVariables;
}
Martin Killenberg
committed
template <typename Map>
bool mapCompare (Map const &lhs, Map const &rhs) {
// No predicate needed because there is operator== for pairs already.
std::cout << "Map size comparison failed: lhs.size() " << lhs.size() << ", rhs.size() " << rhs.size() << std::endl;// LCOV_EXCL_LINE
return false;// LCOV_EXCL_LINE
}
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
Martin Killenberg
committed
}
void testXmlParsing(std::string xmlFile, std::map< std::string, VariableMapper::PropertyDescription > propertyMap){
VariableMapper & vm = VariableMapper::getInstance();
vm.prepareOutput(xmlFile, generateInputVariables());
Martin Killenberg
committed
// vm.print();
Martin Killenberg
committed
BOOST_CHECK( mapCompare( vm.getAllProperties(), propertyMap) );
}
Martin Killenberg
committed
BOOST_AUTO_TEST_CASE( testEvaluateBool ){
// typo/ invalid syntax
try{
VariableMapper::evaluateBool("fale");
BOOST_ERROR("testEvaluateBool did not throw as expected"); // LCOV_EXCL_LINE
}catch(std::logic_error & e){
std::cout << "For manually checking the exception message for invalid bool syntax:\n"
<< e.what() << std::endl;
}
BOOST_CHECK( VariableMapper::evaluateBool("false") == false);
BOOST_CHECK( VariableMapper::evaluateBool("False") == false);
BOOST_CHECK( VariableMapper::evaluateBool("FALSE") == false);
BOOST_CHECK( VariableMapper::evaluateBool("true"));
BOOST_CHECK( VariableMapper::evaluateBool("True"));
BOOST_CHECK( VariableMapper::evaluateBool("TRUE"));
BOOST_CHECK( VariableMapper::evaluateBool("0") == false);
BOOST_CHECK( VariableMapper::evaluateBool("1"));
}
BOOST_AUTO_TEST_CASE( testRename ){
Martin Killenberg
committed
testXmlParsing("variableTreeXml/rename.xml", { {"/A/b/do",{"DIRECT","LOLO"}},
{"/DIRECT/INT",{"DIRECT","TEMP"}}
} );
}
BOOST_AUTO_TEST_CASE( testImportLocation ){
testXmlParsing("variableTreeXml/importLocation.xml", { {"/A/a/di", {"B","a.di"}},
{"/A/a/do", {"B","a.do"}},
Martin Killenberg
committed
{"/A/b", {"B","b"}}
});
}
BOOST_AUTO_TEST_CASE( testImportAll ){
std::map< std::string, VariableMapper::PropertyDescription > propertyMap(
{ {"/A/a/di", {"A","a.di"}},
Martin Killenberg
committed
{"/A/b", {"A","b"}},
{"/B/a/dr", {"B","a.dr"}},
{"/B/c/de", {"B","c.de"}},
{"/B/c/gne", {"B","c.gne"}},
{"/C/a/da", {"C","a.da"}},
{"/C/b/ge", {"C","b.ge"}},
{"/C/c/be", {"C","c.be"}},
{"/C/c/de", {"C","c.de"}},
Martin Killenberg
committed
{"/DIRECT/DOUBLE", {"DIRECT","DOUBLE"}},
{"/DIRECT/DOUBLE_ARRAY", {"DIRECT","DOUBLE_ARRAY"}},
Martin Killenberg
committed
{"/DIRECT/INT", {"DIRECT","INT"}},
{"/DIRECT/INT_ARRAY", {"DIRECT","INT_ARRAY"}}
Martin Killenberg
committed
});
testXmlParsing("variableTreeXml/importAll.xml", propertyMap);
// test direct mapping without xml
VariableMapper & vm = VariableMapper::getInstance();
Martin Killenberg
committed
vm.clear();
BOOST_CHECK( vm.getAllProperties().empty() );
vm.directImport( generateInputVariables());
BOOST_CHECK( mapCompare( vm.getAllProperties(), propertyMap) );
// modify the expected property map for the renaming case
propertyMap["/DIRECT/DOUBLE"]= VariableMapper::PropertyDescription("DIRECT","BAR");
propertyMap["/DIRECT/INT"]= VariableMapper::PropertyDescription("DIRECT","FOO");
testXmlParsing("variableTreeXml/globalImportAndRename.xml", propertyMap);
}
Martin Killenberg
committed
BOOST_AUTO_TEST_CASE( testGetPropertiesInLocation ){
// same input as for testAll, so we know the overall output is OK due to the separate test.
VariableMapper & vm = VariableMapper::getInstance();
vm.prepareOutput("variableTreeXml/importAll.xml", generateInputVariables());
BOOST_CHECK( mapCompare( vm.getPropertiesInLocation("A"), { {"/A/a/di", {"A","a.di"}},
{"/A/a/do", {"A","a.do"}},
{"/A/b", {"A","b"}}
} ) );
BOOST_CHECK( mapCompare( vm.getPropertiesInLocation("B"), { {"/B/a/dr", {"B","a.dr"}},
{"/B/c/de", {"B","c.de"}},
{"/B/c/gne", {"B","c.gne"}}
} ) );
}
Martin Killenberg
committed
BOOST_AUTO_TEST_CASE( testImportIntoLocation ){
std::map< std::string, VariableMapper::PropertyDescription > propertyMap(
{ {"/A/a/di", {"MASTER","A.a.di"}},
{"/A/a/do", {"MASTER","A.a.do"}},
{"/A/b", {"MASTER","A.b"}},
{"/B/a/dr", {"MASTER","B.a.dr"}},
{"/B/c/de", {"MASTER","B.c.de"}},
{"/B/c/gne", {"MASTER","B.c.gne"}},
{"/C/a/da", {"MASTER","C.a.da"}},
{"/C/b/ge", {"MASTER","C.b.ge"}},
{"/C/c/be", {"MASTER","C.c.be"}},
{"/C/c/de", {"MASTER","C.c.de"}},
{"/DIRECT/DOUBLE", {"MASTER","DIRECT.DOUBLE"}},
{"/DIRECT/DOUBLE_ARRAY", {"MASTER","DIRECT.DOUBLE_ARRAY"}},
{"/DIRECT/INT", {"MASTER","DIRECT.INT"}},
{"/DIRECT/INT_ARRAY", {"MASTER","DIRECT.INT_ARRAY"}}
});
testXmlParsing("variableTreeXml/importAllIntoLocation.xml", propertyMap);
}
BOOST_AUTO_TEST_CASE( testImportWithDirectory ){
std::map< std::string, VariableMapper::PropertyDescription > propertyMap(
{ {"/A/a/di", {"MASTER","myStuff.a.di"}},
{"/A/a/do", {"MASTER","myStuff.a.do"}},
{"/A/b", {"MASTER","myStuff.b"}},
{"/B/a/dr", {"DOT_REMOVER","stuffWithDot.a.dr"}},
{"/B/c/de", {"DOT_REMOVER","stuffWithDot.c.de"}},
{"/B/c/gne", {"DOT_REMOVER","stuffWithDot.c.gne"}}
});
testXmlParsing("variableTreeXml/importWithDirectory.xml", propertyMap);
}
BOOST_AUTO_TEST_CASE( testWrongGlobalDirectory ){
// directory is not allowed in global imports, only when importing inside a location
try{
testXmlParsing("variableTreeXml/wrongGlobalDirectory.xml", {});
BOOST_ERROR("testWrongGlobalDirectory did not throw as expected.");// LCOV_EXCL_LINE
}catch(std::logic_error & e){
std::cout << "For manually checking the exception message for directory in global import:\n"
<< e.what() << std::endl;
}
}
try{
testXmlParsing("variableTreeXml/globalImportPartTooShort.xml", {});
BOOST_ERROR("testImportTooShort did not throw as expected.");// LCOV_EXCL_LINE
}catch(std::logic_error & e){
std::cout << "For manually checking the exception message for too short tree depth:\n"
<< e.what() << std::endl;
}
}
BOOST_AUTO_TEST_CASE( testGlobalImportPart ){
testXmlParsing("variableTreeXml/globalImportPart.xml", { {"/B/a/dr", {"a","dr"}},
{"/B/c/de", {"c","de"}},
{"/B/c/gne", {"c","gne"}} });
}
BOOST_AUTO_TEST_CASE( testImportAndRename ){
Martin Killenberg
committed
testXmlParsing("variableTreeXml/importAndRename.xml", { {"/DIRECT/DOUBLE", {"DIRECT","BAR"}},
{"/DIRECT/DOUBLE_ARRAY", {"DIRECT","DOUBLE_ARRAY"}},
{"/DIRECT/INT", {"DIRECT","FOO"}},
{"/DIRECT/INT_ARRAY", {"DIRECT","INT_ARRAY"}}
});
BOOST_AUTO_TEST_CASE( testCherryPicking ){
testXmlParsing("variableTreeXml/cherryPick.xml", { {"/A/b/do", {"DIRECT","A.b.do"}},
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
BOOST_AUTO_TEST_CASE( testDuplicateSource ){
try{
testXmlParsing("variableTreeXml/duplicateSource.xml", {});
BOOST_ERROR("testDuplicateSource did not throw as expected"); // LCOV_EXCL_LINE
}catch(std::logic_error & e){
std::cout << "For manually checking the exception message for duplicate sources:\n"
<< e.what() << std::endl;
}
}
BOOST_AUTO_TEST_CASE( testUnknownMainNode ){
try{
testXmlParsing("variableTreeXml/unknownMainNode.xml", {});
BOOST_ERROR("testUnknownMainNode did not throw as expected"); // LCOV_EXCL_LINE
}catch(std::logic_error & e){
std::cout << "For manually checking the exception message for unknown main node:\n"
<< e.what() << std::endl;
}
}
BOOST_AUTO_TEST_CASE( testUnkownLocationNode ){
try{
testXmlParsing("variableTreeXml/unknownLocationNode.xml", {});
BOOST_ERROR("testUnknownLocationNode did not throw as expected"); // LCOV_EXCL_LINE
}catch(std::logic_error & e){
std::cout << "For manually checking the exception message for unknown location node:\n"
<< e.what() << std::endl;
}
}
BOOST_AUTO_TEST_CASE( testLocationTurnOffOn ){
Martin Killenberg
committed
testXmlParsing("variableTreeXml/locationTurnOffOn.xml", { {"/A/a/di", {"DUMMY_LOCATION","a.di",false}},
{"/A/a/do", {"DUMMY_LOCATION","A.a.do",true}},
Martin Killenberg
committed
{"/A/b", {"DUMMY_LOCATION","b",true}},
{"/B/a/dr", {"ANOTHER_LOCATION","a.dr",true}},
{"/B/c/de", {"ANOTHER_LOCATION","c.de",true}},
Martin Killenberg
committed
{"/B/c/gne", {"ANOTHER_LOCATION","WRITE_ME"}},