diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2011-09-20 11:56:31 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-20 08:46:18 +0200 |
commit | 01ece201ab08804c4ab226a39f1e1885aeaae0bd (patch) | |
tree | 9df4c2416e4470f30b62d112f822d882f0fafc64 /tests/auto/testlib/selftests/subtest | |
parent | d60007744bbc1cd90dcf97461a5b2fb237a82d17 (diff) |
Split subtest selftest
This test was attempting to verify two completely unrelated things, so
this commit splits it into two tests.
Also, printf calls are replaced by qDebug so that the test does not
bypass the testlib loggers.
Change-Id: I1a202af38ce2c69690a32d93405ba604ec6cabee
Reviewed-on: http://codereview.qt-project.org/5178
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'tests/auto/testlib/selftests/subtest')
-rw-r--r-- | tests/auto/testlib/selftests/subtest/tst_subtest.cpp | 122 |
1 files changed, 32 insertions, 90 deletions
diff --git a/tests/auto/testlib/selftests/subtest/tst_subtest.cpp b/tests/auto/testlib/selftests/subtest/tst_subtest.cpp index 4404a5103f..7ccfc507d7 100644 --- a/tests/auto/testlib/selftests/subtest/tst_subtest.cpp +++ b/tests/auto/testlib/selftests/subtest/tst_subtest.cpp @@ -42,6 +42,7 @@ #include <QtCore> #include <QtTest/QtTest> +#include <QDebug> class tst_Subtest: public QObject { @@ -59,53 +60,49 @@ private slots: void test2(); void test3_data(); void test3(); - void floatComparisons() const; - void floatComparisons_data() const; - void compareFloatTests() const; - void compareFloatTests_data() const; }; void tst_Subtest::initTestCase() { - printf("initTestCase %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "initTestCase" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); } void tst_Subtest::cleanupTestCase() { - printf("cleanupTestCase %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "cleanupTestCase" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); } void tst_Subtest::init() { - printf("init %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "init" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); } void tst_Subtest::cleanup() { - printf("cleanup %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "cleanup" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); } void tst_Subtest::test1() { - printf("test1 %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "test1" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); } void tst_Subtest::test2_data() { - printf("test2_data %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "test2_data" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); QTest::addColumn<QString>("str"); @@ -113,28 +110,28 @@ void tst_Subtest::test2_data() QTest::newRow("data1") << QString("hello1"); QTest::newRow("data2") << QString("hello2"); - printf("test2_data end\n"); + qDebug() << "test2_data end"; } void tst_Subtest::test2() { - printf("test2 %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "test2" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); static int count = 0; QFETCH(QString, str); QCOMPARE(str, QString("hello%1").arg(count++)); - printf("test2 end\n"); + qDebug() << "test2 end"; } void tst_Subtest::test3_data() { - printf("test3_data %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "test3_data" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); QTest::addColumn<QString>("str"); @@ -142,76 +139,21 @@ void tst_Subtest::test3_data() QTest::newRow("data1") << QString("hello1"); QTest::newRow("data2") << QString("hello2"); - printf("test3_data end\n"); + qDebug() << "test3_data end"; } void tst_Subtest::test3() { - printf("test2 %s %s\n", - QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)", - QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); + qDebug() << "test2" + << (QTest::currentTestFunction() ? QTest::currentTestFunction() : "(null)") + << (QTest::currentDataTag() ? QTest::currentDataTag() : "(null)"); QFETCH(QString, str); // second and third time we call this it should FAIL QCOMPARE(str, QString("hello0")); - printf("test2 end\n"); -} - -void tst_Subtest::floatComparisons() const -{ - QFETCH(float, operandLeft); - QFETCH(float, operandRight); - - QCOMPARE(operandLeft, operandRight); -} - -void tst_Subtest::floatComparisons_data() const -{ - QTest::addColumn<float>("operandLeft"); - QTest::addColumn<float>("operandRight"); - - QTest::newRow("should SUCCEED") - << float(0) - << float(0); - - QTest::newRow("should FAIL") - << float(1.00000) - << float(3.00000); - - QTest::newRow("should FAIL") - << float(1.00000e-7f) - << float(3.00000e-7f); - - QTest::newRow("should FAIL") - << float(100001) - << float(100002); -} - -void tst_Subtest::compareFloatTests() const -{ - QFETCH(float, t1); - - // Create two more values - // t2 differs from t1 by 1 ppm (part per million) - // t3 differs from t1 by 200% - // we should consider that t1 == t2 and t1 != t3 - const float t2 = t1 + (t1 / 1e6); - const float t3 = 3 * t1; - - QCOMPARE(t1, t2); - - /* Should FAIL. */ - QCOMPARE(t1, t3); -} - -void tst_Subtest::compareFloatTests_data() const -{ - QTest::addColumn<float>("t1"); - QTest::newRow("1e0") << 1e0f; - QTest::newRow("1e-7") << 1e-7f; - QTest::newRow("1e+7") << 1e+7f; + qDebug() << "test2 end"; } QTEST_MAIN(tst_Subtest) |