Is it possible to have optional columns in a _data()
function, similar to optional arguments for functions - int foo(int a, int b=5)
.
Something like:
void Test1::testCase1_data()
{
QTest::addColumn<QString>("requiredCol");
QTest::addColumn<QString>("optionalCol");
// This row doesn't have the optionalCol:
QTest::newRow("1") << "23";
// But this row does:
QTest::newRow("2") << "34" << "56";
}
void Test1::testCase1()
{
QFETCH(QString, requiredCol);
if (optionalCol doesn't exist) {
optionalCol = "some defaultValue";
} else {
QFETCH(QString, optionalCol);
}
}
Unfortunately, QFETCH
will simply assert if the optional column is not available. I want to instead assign some default value to it if it's not available.