How to read test tables from xml files
Many parameters needed for the configuration of the several tests and of the interfaces are currently being stored in
xml file which can be read to fill up the test tables used by the Test Supervisor application. The following piece of code shows how to read the a table stored in the example file
Test.xml.
This file contains two structures one inside the other. The main structure is defined in the
table_
node and contains a string, a flag and a sub-structure defined in the
aStructure_
node. This sub-structure contains an array of strings and a number. To define the "store" for this data one can proceed the following way:
1) Define the sub-structure by the following bag:
class Structure {
public:
void registerFields(xdata::Bag<Structure> *bag){
bag->addField("anArray_",&Array_);
bag->addField("aNumber_",&Number_);
}
xdata::Vector<xdata::String > Array_;
xdata::UnsignedLong Number_;
};
2) Define the table as the top structure that holds the Structure you defined before:
class Table {
public:
void registerFields(xdata::Bag<Structure> *bag){
bag->addField("aString_",&String_);
bag->addField("aFlag_",&Flag_);
bag->addField("aStructure_",&Structure_);
}
xdata::String String_;
xdata::Boolean Flag_;
xdata::Bag<Structure> Structure_;
};
3) Use the
IntegrationTests::BagUtils
to fill the Table structure from the file:
//instantiate a new table
xdata::Bag<Table> myTable_;
//define path to table file
string pathToTableFile_("/myPath/.../Test.xml");
try{
//parse table from file
IntegrationTests::BagUtils::readTableFromFile(&myTable_,pathToTableFile_);
}
catch(IntegrationTests::exception::Exception &ite_){
... handle exception ...
}
And the table is filled correctly and can be used from this point forward. The converse method (
writeTableToAFile
) is also implemented in the referred namespace.
--
PedroSilva - 24 Aug 2006