1

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.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • I don't know if QTest supports that. Pass some nullable type instead (like `QVariant`)? – peppe Dec 15 '15 at 10:29
  • @peppe Right now I just declare a "defaultValue" variable and append it on each row unless I want to change it. – sashoalm Dec 15 '15 at 11:49

0 Answers0