From 01ece201ab08804c4ab226a39f1e1885aeaae0bd Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 20 Sep 2011 11:56:31 +1000 Subject: [PATCH] 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 --- .../testlib/selftests/expected_float.lightxml | 44 +++++ .../auto/testlib/selftests/expected_float.txt | 26 +++ .../auto/testlib/selftests/expected_float.xml | 47 ++++++ .../testlib/selftests/expected_float.xunitxml | 29 ++++ .../selftests/expected_subtest.lightxml | 144 ++++++++++++++--- .../testlib/selftests/expected_subtest.txt | 104 ++++-------- .../testlib/selftests/expected_subtest.xml | 153 +++++++++++++----- .../selftests/expected_subtest.xunitxml | 96 ++++++++--- tests/auto/testlib/selftests/float/float.pro | 12 ++ .../testlib/selftests/float/tst_float.cpp | 113 +++++++++++++ tests/auto/testlib/selftests/selftests.pro | 2 +- tests/auto/testlib/selftests/selftests.qrc | 4 + .../testlib/selftests/subtest/tst_subtest.cpp | 122 ++++---------- .../auto/testlib/selftests/tst_selftests.cpp | 5 +- 14 files changed, 655 insertions(+), 246 deletions(-) create mode 100644 tests/auto/testlib/selftests/expected_float.lightxml create mode 100644 tests/auto/testlib/selftests/expected_float.txt create mode 100644 tests/auto/testlib/selftests/expected_float.xml create mode 100644 tests/auto/testlib/selftests/expected_float.xunitxml create mode 100644 tests/auto/testlib/selftests/float/float.pro create mode 100644 tests/auto/testlib/selftests/float/tst_float.cpp diff --git a/tests/auto/testlib/selftests/expected_float.lightxml b/tests/auto/testlib/selftests/expected_float.lightxml new file mode 100644 index 0000000000..a34618cf02 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_float.lightxml @@ -0,0 +1,44 @@ + + @INSERT_QT_VERSION_HERE@ + @INSERT_QT_VERSION_HERE@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_float.txt b/tests/auto/testlib/selftests/expected_float.txt new file mode 100644 index 0000000000..322fc5ce44 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_float.txt @@ -0,0 +1,26 @@ +********* Start testing of tst_float ********* +Config: Using QTest library 5.0.0, Qt 5.0.0 +PASS : tst_float::initTestCase() +FAIL! : tst_float::floatComparisons(should FAIL) Compared floats are not the same (fuzzy compare) + Actual (operandLeft): 1 + Expected (operandRight): 3 + Loc: [/home/user/dev/qt5/tests/auto/testlib/selftests/float/tst_float.cpp(61)] +FAIL! : tst_float::floatComparisons(should FAIL) Compared floats are not the same (fuzzy compare) + Actual (operandLeft): 1e-07 + Expected (operandRight): 3e-07 + Loc: [/home/user/dev/qt5/tests/auto/testlib/selftests/float/tst_float.cpp(61)] +FAIL! : tst_float::compareFloatTests(1e0) Compared floats are not the same (fuzzy compare) + Actual (t1): 1 + Expected (t3): 3 + Loc: [/home/user/dev/qt5/tests/auto/testlib/selftests/float/tst_float.cpp(100)] +FAIL! : tst_float::compareFloatTests(1e-7) Compared floats are not the same (fuzzy compare) + Actual (t1): 1e-07 + Expected (t3): 3e-07 + Loc: [/home/user/dev/qt5/tests/auto/testlib/selftests/float/tst_float.cpp(100)] +FAIL! : tst_float::compareFloatTests(1e+7) Compared floats are not the same (fuzzy compare) + Actual (t1): 1e+07 + Expected (t3): 3e+07 + Loc: [/home/user/dev/qt5/tests/auto/testlib/selftests/float/tst_float.cpp(100)] +PASS : tst_float::cleanupTestCase() +Totals: 2 passed, 5 failed, 0 skipped +********* Finished testing of tst_float ********* diff --git a/tests/auto/testlib/selftests/expected_float.xml b/tests/auto/testlib/selftests/expected_float.xml new file mode 100644 index 0000000000..a9c7428250 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_float.xml @@ -0,0 +1,47 @@ + + + + @INSERT_QT_VERSION_HERE@ + @INSERT_QT_VERSION_HERE@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_float.xunitxml b/tests/auto/testlib/selftests/expected_float.xunitxml new file mode 100644 index 0000000000..f88e5e410e --- /dev/null +++ b/tests/auto/testlib/selftests/expected_float.xunitxml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_subtest.lightxml b/tests/auto/testlib/selftests/expected_subtest.lightxml index 00c1a992bd..d76ec131de 100644 --- a/tests/auto/testlib/selftests/expected_subtest.lightxml +++ b/tests/auto/testlib/selftests/expected_subtest.lightxml @@ -3,47 +3,143 @@ @INSERT_QT_VERSION_HERE@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_subtest.txt b/tests/auto/testlib/selftests/expected_subtest.txt index ec459c5b59..cf995887d0 100644 --- a/tests/auto/testlib/selftests/expected_subtest.txt +++ b/tests/auto/testlib/selftests/expected_subtest.txt @@ -1,81 +1,47 @@ ********* Start testing of tst_Subtest ********* -Config: Using QTest library 4.4.0, Qt 4.4.0 -initTestCase initTestCase (null) +Config: Using QTest library 5.0.0, Qt 5.0.0 +QDEBUG : tst_Subtest::initTestCase() initTestCase initTestCase (null) PASS : tst_Subtest::initTestCase() -init test1 (null) -test1 test1 (null) -cleanup test1 (null) +QDEBUG : tst_Subtest::test1() init test1 (null) +QDEBUG : tst_Subtest::test1() test1 test1 (null) +QDEBUG : tst_Subtest::test1() cleanup test1 (null) PASS : tst_Subtest::test1() -test2_data test2 (null) -test2_data end -init test2 data0 -test2 test2 data0 -test2 end -cleanup test2 data0 -init test2 data1 -test2 test2 data1 -test2 end -cleanup test2 data1 -init test2 data2 -test2 test2 data2 -test2 end -cleanup test2 data2 +QDEBUG : tst_Subtest::test2() test2_data test2 (null) +QDEBUG : tst_Subtest::test2() test2_data end +QDEBUG : tst_Subtest::test2(data0) init test2 data0 +QDEBUG : tst_Subtest::test2(data0) test2 test2 data0 +QDEBUG : tst_Subtest::test2(data0) test2 end +QDEBUG : tst_Subtest::test2(data0) cleanup test2 data0 +QDEBUG : tst_Subtest::test2(data1) init test2 data1 +QDEBUG : tst_Subtest::test2(data1) test2 test2 data1 +QDEBUG : tst_Subtest::test2(data1) test2 end +QDEBUG : tst_Subtest::test2(data1) cleanup test2 data1 +QDEBUG : tst_Subtest::test2(data2) init test2 data2 +QDEBUG : tst_Subtest::test2(data2) test2 test2 data2 +QDEBUG : tst_Subtest::test2(data2) test2 end +QDEBUG : tst_Subtest::test2(data2) cleanup test2 data2 PASS : tst_Subtest::test2() -test3_data test3 (null) -test3_data end -init test3 data0 -test2 test3 data0 -test2 end -cleanup test3 data0 -init test3 data1 -test2 test3 data1 +QDEBUG : tst_Subtest::test3() test3_data test3 (null) +QDEBUG : tst_Subtest::test3() test3_data end +QDEBUG : tst_Subtest::test3(data0) init test3 data0 +QDEBUG : tst_Subtest::test3(data0) test2 test3 data0 +QDEBUG : tst_Subtest::test3(data0) test2 end +QDEBUG : tst_Subtest::test3(data0) cleanup test3 data0 +QDEBUG : tst_Subtest::test3(data1) init test3 data1 +QDEBUG : tst_Subtest::test3(data1) test2 test3 data1 FAIL! : tst_Subtest::test3(data1) Compared values are not the same Actual (str): hello1 Expected (QString("hello0")): hello0 - Loc: [/home/fenglich/dev/qt-4.4/tests/auto/selftests/subtest/tst_subtest.cpp(124)] -cleanup test3 data1 -init test3 data2 -test2 test3 data2 + Loc: [/home/user/dev/qt5/tests/auto/testlib/selftests/subtest/tst_subtest.cpp(154)] +QDEBUG : tst_Subtest::test3(data1) cleanup test3 data1 +QDEBUG : tst_Subtest::test3(data2) init test3 data2 +QDEBUG : tst_Subtest::test3(data2) test2 test3 data2 FAIL! : tst_Subtest::test3(data2) Compared values are not the same Actual (str): hello2 Expected (QString("hello0")): hello0 - Loc: [/home/fenglich/dev/qt-4.4/tests/auto/selftests/subtest/tst_subtest.cpp(124)] -cleanup test3 data2 -init floatComparisons should SUCCEED -cleanup floatComparisons should SUCCEED -init floatComparisons should FAIL -FAIL! : tst_Subtest::floatComparisons(should FAIL) Compared floats are not the same (fuzzy compare) - Actual (operandLeft): 1 - Expected (operandRight): 3 - Loc: [/home/fenglich/dev/qt-4.4/tests/auto/selftests/subtest/tst_subtest.cpp(134)] -cleanup floatComparisons should FAIL -init floatComparisons should FAIL -FAIL! : tst_Subtest::floatComparisons(should FAIL) Compared floats are not the same (fuzzy compare) - Actual (operandLeft): 1e-07 - Expected (operandRight): 3e-07 - Loc: [/home/fenglich/dev/qt-4.4/tests/auto/selftests/subtest/tst_subtest.cpp(134)] -cleanup floatComparisons should FAIL -init floatComparisons should FAIL -cleanup floatComparisons should FAIL -init compareFloatTests 1e0 -FAIL! : tst_Subtest::compareFloatTests(1e0) Compared floats are not the same (fuzzy compare) - Actual (t1): 1 - Expected (t3): 3 - Loc: [/home/fenglich/dev/qt-4.4/tests/auto/selftests/subtest/tst_subtest.cpp(173)] -cleanup compareFloatTests 1e0 -init compareFloatTests 1e-7 -FAIL! : tst_Subtest::compareFloatTests(1e-7) Compared floats are not the same (fuzzy compare) - Actual (t1): 1e-07 - Expected (t3): 3e-07 - Loc: [/home/fenglich/dev/qt-4.4/tests/auto/selftests/subtest/tst_subtest.cpp(173)] -cleanup compareFloatTests 1e-7 -init compareFloatTests 1e+7 -FAIL! : tst_Subtest::compareFloatTests(1e+7) Compared floats are not the same (fuzzy compare) - Actual (t1): 1e+07 - Expected (t3): 3e+07 - Loc: [/home/fenglich/dev/qt-4.4/tests/auto/selftests/subtest/tst_subtest.cpp(173)] -cleanup compareFloatTests 1e+7 -cleanupTestCase cleanupTestCase (null) + Loc: [/home/user/dev/qt5/tests/auto/testlib/selftests/subtest/tst_subtest.cpp(154)] +QDEBUG : tst_Subtest::test3(data2) cleanup test3 data2 +QDEBUG : tst_Subtest::cleanupTestCase() cleanupTestCase cleanupTestCase (null) PASS : tst_Subtest::cleanupTestCase() -Totals: 4 passed, 7 failed, 0 skipped +Totals: 4 passed, 2 failed, 0 skipped ********* Finished testing of tst_Subtest ********* diff --git a/tests/auto/testlib/selftests/expected_subtest.xml b/tests/auto/testlib/selftests/expected_subtest.xml index 5ecb0a2e9f..d79242f061 100644 --- a/tests/auto/testlib/selftests/expected_subtest.xml +++ b/tests/auto/testlib/selftests/expected_subtest.xml @@ -5,63 +5,144 @@ @INSERT_QT_VERSION_HERE@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_subtest.xunitxml b/tests/auto/testlib/selftests/expected_subtest.xunitxml index a5f75fe73e..c228dc8f54 100644 --- a/tests/auto/testlib/selftests/expected_subtest.xunitxml +++ b/tests/auto/testlib/selftests/expected_subtest.xunitxml @@ -1,39 +1,87 @@ - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/float/float.pro b/tests/auto/testlib/selftests/float/float.pro new file mode 100644 index 0000000000..2c5ac3ebf7 --- /dev/null +++ b/tests/auto/testlib/selftests/float/float.pro @@ -0,0 +1,12 @@ +load(qttest_p4) + +# this is not a real testcase ('make check' should not run it) +CONFIG -= testcase + +SOURCES += tst_float.cpp +QT = core + +mac:CONFIG -= app_bundle +CONFIG -= debug_and_release_target + +TARGET = float diff --git a/tests/auto/testlib/selftests/float/tst_float.cpp b/tests/auto/testlib/selftests/float/tst_float.cpp new file mode 100644 index 0000000000..65bd3188cb --- /dev/null +++ b/tests/auto/testlib/selftests/float/tst_float.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class tst_float: public QObject +{ + Q_OBJECT +private slots: + void floatComparisons() const; + void floatComparisons_data() const; + void compareFloatTests() const; + void compareFloatTests_data() const; +}; + +void tst_float::floatComparisons() const +{ + QFETCH(float, operandLeft); + QFETCH(float, operandRight); + + QCOMPARE(operandLeft, operandRight); +} + +void tst_float::floatComparisons_data() const +{ + QTest::addColumn("operandLeft"); + QTest::addColumn("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_float::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_float::compareFloatTests_data() const +{ + QTest::addColumn("t1"); + QTest::newRow("1e0") << 1e0f; + QTest::newRow("1e-7") << 1e-7f; + QTest::newRow("1e+7") << 1e+7f; +} + +QTEST_MAIN(tst_float) + +#include "tst_float.moc" diff --git a/tests/auto/testlib/selftests/selftests.pro b/tests/auto/testlib/selftests/selftests.pro index 27a6d5d3f4..353e465961 100644 --- a/tests/auto/testlib/selftests/selftests.pro +++ b/tests/auto/testlib/selftests/selftests.pro @@ -5,7 +5,7 @@ SUBDIRS = subtest test warnings maxwarnings cmptest globaldata skipglobal skip \ skipinit skipinitdata datetime singleskip assert differentexec \ exceptionthrow qexecstringlist datatable commandlinedata\ benchlibwalltime benchlibcallgrind benchlibeventcounter benchlibtickcounter \ - benchliboptions xunit badxml longstring + benchliboptions xunit badxml longstring float INSTALLS = diff --git a/tests/auto/testlib/selftests/selftests.qrc b/tests/auto/testlib/selftests/selftests.qrc index 77b4d213c0..41fa7e0763 100644 --- a/tests/auto/testlib/selftests/selftests.qrc +++ b/tests/auto/testlib/selftests/selftests.qrc @@ -73,6 +73,10 @@ expected_fetchbogus.txt expected_fetchbogus.xml expected_fetchbogus.xunitxml + expected_float.lightxml + expected_float.txt + expected_float.xml + expected_float.xunitxml expected_globaldata.lightxml expected_globaldata.txt expected_globaldata.xml 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 #include +#include 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("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("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("operandLeft"); - QTest::addColumn("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("t1"); - QTest::newRow("1e0") << 1e0f; - QTest::newRow("1e-7") << 1e-7f; - QTest::newRow("1e+7") << 1e+7f; + qDebug() << "test2 end"; } QTEST_MAIN(tst_Subtest) diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 9c9d281478..bd0594dbcf 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -189,6 +189,7 @@ void tst_Selftests::runSubTest_data() << "maxwarnings" << "cmptest" // << "alive" // timer dependent + << "float" << "globaldata" << "skipglobal" << "skip" @@ -287,7 +288,7 @@ void tst_Selftests::runSubTest_data() } // this test prints out some floats in the testlog and the formatting is // platform-specific and hard to predict. - if (subtest == "subtest") { + if (subtest == "float") { continue; } } @@ -417,7 +418,7 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q if (expected.startsWith(QLatin1String("FAIL! : tst_Exception::throwException() Caught unhandled exce")) && expected != output) // On some platforms we compile without RTTI, and as a result we never throw an exception. QCOMPARE(output.simplified(), QString::fromLatin1("tst_Exception::throwException()").simplified()); - else if (output != expected && qstrcmp(QTest::currentDataTag(), "subtest") == 0) + else if (output != expected && qstrcmp(QTest::currentDataTag(), "float") == 0) // The floating point formatting differs between platforms, so let's just skip it. continue; else if (benchmark || line.startsWith("