To get back to the original question... I'm trying to read my test cases from an XML file. There I wanted to define the columns and the rows. First case is checking if the program has the right name 
TDataLoader::fillData(meth) {
for(QDomElement col
=cols.
firstChildElement(tagColumn
);
!col.
isNull(); col
=col.
nextSiblingElement(tagColumn
)) { QString name
= col.
attribute(entryName
);
QString type
= col.
attribute(entryType
).
toLower();
// Simplifying: here is type checking
QTest::addColumn<QString>(name.toLatin1());
}
...
for(QDomElement row
=rows.
firstChildElement(tagRow
);
!row.
isNull(); row
=row.
nextSiblingElement(tagRow
)) { QString name
= row.
attribute(entryName
);
QTestData& values = QTest::newRow(name.toLatin1());
for(int i=0; i<attrs.count(); i++) {
// Simplifying: needs type casting
values << row.attribute(node.nodeName());
}
}
}
TDataLoader::fillData(meth) {
QDomElement m = m_Root.firstChildElement(meth);
QDomElement cols = m.firstChildElement(tagColumns);
for(QDomElement col=cols.firstChildElement(tagColumn); !col.isNull(); col=col.nextSiblingElement(tagColumn)) {
QString name = col.attribute(entryName);
QString type = col.attribute(entryType).toLower();
// Simplifying: here is type checking
QTest::addColumn<QString>(name.toLatin1());
}
...
QDomElement rows = m.firstChildElement(tagRows);
for(QDomElement row=rows.firstChildElement(tagRow); !row.isNull(); row=row.nextSiblingElement(tagRow)) {
QString name = row.attribute(entryName);
QTestData& values = QTest::newRow(name.toLatin1());
QDomNamedNodeMap attrs = row.attributes();
for(int i=0; i<attrs.count(); i++) {
QDomNode node = attrs.item(i);
// Simplifying: needs type casting
values << row.attribute(node.nodeName());
}
}
}
To copy to clipboard, switch view to plain text mode
In the test method, I call fillData with the method's name (m_Data is the instance of the data loader):
void TTestRunner::testProgram_data()
{
m_Data.fillData("testProgram");
}
void TTestRunner::testProgram()
{
}
void TTestRunner::testProgram_data()
{
m_Data.fillData("testProgram");
}
void TTestRunner::testProgram()
{
QFETCH(QString, title);
QCOMPARE(QCoreApplication::applicationName(), title);
}
To copy to clipboard, switch view to plain text mode
but what I get is an error:
QFETCH: Requested testdata 'title' not available, check your _data function.
QFETCH: Requested testdata 'title' not available, check your _data function.
To copy to clipboard, switch view to plain text mode
Is it wrong to add additional data to the QTestData reference or am I missing something? The XML file is read correctly:
<?xml version="1.0" encoding="utf-8" ?>
<Data>
<testProgram>
<columns>
<column name="title" type="QString" />
</columns>
<rows>
<row name="title" value="targs" />
</rows>
</testProgram>
</Data>
<?xml version="1.0" encoding="utf-8" ?>
<Data>
<testProgram>
<columns>
<column name="title" type="QString" />
</columns>
<rows>
<row name="title" value="targs" />
</rows>
</testProgram>
</Data>
To copy to clipboard, switch view to plain text mode
Bookmarks