1

函数中是否可以有可选列_data(),类似于函数的可选参数 - int foo(int a, int b=5)

就像是:

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);
    }
}

不幸QFETCH的是,如果可选列不可用,它将简单地断言。如果它不可用,我想为其分配一些默认值。

4

0 回答 0