Avoid senseless duplication of code in a testlib selftest
Delegate repeated tasks to functions - DRY ! Change-Id: I8973d2b9cd1f7d0fe94a9ae4aebcff434821e210 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>bb10
parent
a6a3b1e79c
commit
e3d5d363f7
|
|
@ -49,64 +49,62 @@ private slots:
|
|||
void test3();
|
||||
|
||||
void multiFail();
|
||||
private:
|
||||
void logNames(const char *caller);
|
||||
void table_data();
|
||||
};
|
||||
|
||||
void tst_Subtest::logNames(const char *caller)
|
||||
{
|
||||
auto orNull = [](const char *s) { return s ? s : "(null)"; };
|
||||
qDebug("%s %s %s", caller, orNull(QTest::currentTestFunction()),
|
||||
orNull(QTest::currentDataTag()));
|
||||
}
|
||||
|
||||
void tst_Subtest::initTestCase()
|
||||
{
|
||||
qDebug() << "initTestCase"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
logNames("initTestCase");
|
||||
}
|
||||
|
||||
void tst_Subtest::cleanupTestCase()
|
||||
{
|
||||
qDebug() << "cleanupTestCase"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
logNames("cleanupTestCase");
|
||||
}
|
||||
|
||||
void tst_Subtest::init()
|
||||
{
|
||||
qDebug() << "init"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
logNames("init");
|
||||
}
|
||||
|
||||
void tst_Subtest::cleanup()
|
||||
{
|
||||
qDebug() << "cleanup"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
logNames("cleanup");
|
||||
}
|
||||
|
||||
void tst_Subtest::test1()
|
||||
{
|
||||
qDebug() << "test1"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
logNames("test1");
|
||||
}
|
||||
|
||||
void tst_Subtest::test2_data()
|
||||
void tst_Subtest::table_data()
|
||||
{
|
||||
qDebug() << "test2_data"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
|
||||
QTest::addColumn<QString>("str");
|
||||
|
||||
QTest::newRow("data0") << QString("hello0");
|
||||
QTest::newRow("data1") << QString("hello1");
|
||||
QTest::newRow("data2") << QString("hello2");
|
||||
}
|
||||
|
||||
void tst_Subtest::test2_data()
|
||||
{
|
||||
logNames("test2_data");
|
||||
table_data();
|
||||
qDebug() << "test2_data end";
|
||||
}
|
||||
|
||||
void tst_Subtest::test2()
|
||||
{
|
||||
qDebug() << "test2"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
logNames("test2");
|
||||
|
||||
static int count = 0;
|
||||
|
||||
|
|
@ -118,24 +116,14 @@ void tst_Subtest::test2()
|
|||
|
||||
void tst_Subtest::test3_data()
|
||||
{
|
||||
qDebug() << "test3_data"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
|
||||
QTest::addColumn<QString>("str");
|
||||
|
||||
QTest::newRow("data0") << QString("hello0");
|
||||
QTest::newRow("data1") << QString("hello1");
|
||||
QTest::newRow("data2") << QString("hello2");
|
||||
|
||||
logNames("test3_data");
|
||||
table_data();
|
||||
qDebug() << "test3_data end";
|
||||
}
|
||||
|
||||
void tst_Subtest::test3()
|
||||
{
|
||||
qDebug() << "test3"
|
||||
<< (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)")
|
||||
<< (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)");
|
||||
logNames("test3");
|
||||
|
||||
QFETCH(QString, str);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue