Add testlib selftest for counting of test results.

The test simply generates each possible pair of Pass, Fail and Skip
results.  At present the test simply serves to demonstrate the current
shortcomings of testlib's plain text logging, namely:

* If a test function passes for all data rows, that is counted as one
  pass, but each skipped or failed row counts as one skip or fail.

* Only skipped and failed rows are reported individually in the test
  output. Passed rows are not reported, so it is impossible to see how
  many rows were executed.

* A skip followed by a pass will be reported as an overall pass for the
  test function, but the same rows in reverse order will not report any
  overall result for the test function.

Future commits will attempt to correct these problems.

Task-number: QTBUG-22124
Change-Id: If8c7ea15fc43ba9a1bccd0e881c1efc18e705b25
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2012-01-31 14:07:58 +10:00 committed by Qt by Nokia
parent 835c53490b
commit 58c617c798
9 changed files with 466 additions and 1 deletions

View File

@ -0,0 +1,7 @@
SOURCES += tst_counting.cpp
QT = core testlib
mac:CONFIG -= app_bundle
CONFIG -= debug_and_release_target
TARGET = counting

View File

@ -0,0 +1,216 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** 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 <QtCore/QCoreApplication>
#include <QtTest/QtTest>
class tst_Counting : public QObject
{
Q_OBJECT
private slots:
void testPassPass_data();
void testPassPass();
void testPassSkip_data();
void testPassSkip();
void testPassFail_data();
void testPassFail();
void testSkipPass_data();
void testSkipPass();
void testSkipSkip_data();
void testSkipSkip();
void testSkipFail_data();
void testSkipFail();
void testFailPass_data();
void testFailPass();
void testFailSkip_data();
void testFailSkip();
void testFailFail_data();
void testFailFail();
private:
void helper();
};
enum TestResult
{
Pass,
Fail,
Skip
};
Q_DECLARE_METATYPE(TestResult);
void tst_Counting::helper()
{
QFETCH(TestResult, result);
switch (result) {
case Pass:
QVERIFY(true);
break;
case Fail:
QVERIFY(false);
break;
case Skip:
QSKIP("Skipping");
break;
}
}
void tst_Counting::testPassPass_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Pass;
QTest::newRow("row 2") << Pass;
}
void tst_Counting::testPassPass()
{
helper();
}
void tst_Counting::testPassSkip_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Pass;
QTest::newRow("row 2") << Skip;
}
void tst_Counting::testPassSkip()
{
helper();
}
void tst_Counting::testPassFail_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Pass;
QTest::newRow("row 2") << Fail;
}
void tst_Counting::testPassFail()
{
helper();
}
void tst_Counting::testSkipPass_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Skip;
QTest::newRow("row 2") << Pass;
}
void tst_Counting::testSkipPass()
{
helper();
}
void tst_Counting::testSkipSkip_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Skip;
QTest::newRow("row 2") << Skip;
}
void tst_Counting::testSkipSkip()
{
helper();
}
void tst_Counting::testSkipFail_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Skip;
QTest::newRow("row 2") << Fail;
}
void tst_Counting::testSkipFail()
{
helper();
}
void tst_Counting::testFailPass_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Fail;
QTest::newRow("row 2") << Pass;
}
void tst_Counting::testFailPass()
{
helper();
}
void tst_Counting::testFailSkip_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Fail;
QTest::newRow("row 2") << Skip;
}
void tst_Counting::testFailSkip()
{
helper();
}
void tst_Counting::testFailFail_data()
{
QTest::addColumn<TestResult>("result");
QTest::newRow("row 1") << Fail;
QTest::newRow("row 2") << Fail;
}
void tst_Counting::testFailFail()
{
helper();
}
QTEST_MAIN(tst_Counting)
#include "tst_counting.moc"

View File

@ -0,0 +1,78 @@
<Environment>
<QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion>
<QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion>
</Environment>
<TestFunction name="initTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="testPassPass">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="testPassSkip">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
</TestFunction>
<TestFunction name="testPassFail">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="testSkipPass">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="testSkipSkip">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
</TestFunction>
<TestFunction name="testSkipFail">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="testFailPass">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="testFailSkip">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
</TestFunction>
<TestFunction name="testFailFail">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>

View File

@ -0,0 +1,32 @@
********* Start testing of tst_Counting *********
Config: Using QTest library @INSERT_QT_VERSION_HERE@, Qt @INSERT_QT_VERSION_HERE@
PASS : tst_Counting::initTestCase()
PASS : tst_Counting::testPassPass()
SKIP : tst_Counting::testPassSkip(row 2) Skipping
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(102)]
FAIL! : tst_Counting::testPassFail(row 2) 'false' returned FALSE. ()
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(99)]
SKIP : tst_Counting::testSkipPass(row 1) Skipping
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(102)]
PASS : tst_Counting::testSkipPass()
SKIP : tst_Counting::testSkipSkip(row 1) Skipping
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(102)]
SKIP : tst_Counting::testSkipSkip(row 2) Skipping
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(102)]
SKIP : tst_Counting::testSkipFail(row 1) Skipping
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(102)]
FAIL! : tst_Counting::testSkipFail(row 2) 'false' returned FALSE. ()
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(99)]
FAIL! : tst_Counting::testFailPass(row 1) 'false' returned FALSE. ()
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(99)]
FAIL! : tst_Counting::testFailSkip(row 1) 'false' returned FALSE. ()
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(99)]
SKIP : tst_Counting::testFailSkip(row 2) Skipping
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(102)]
FAIL! : tst_Counting::testFailFail(row 1) 'false' returned FALSE. ()
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(99)]
FAIL! : tst_Counting::testFailFail(row 2) 'false' returned FALSE. ()
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp(99)]
PASS : tst_Counting::cleanupTestCase()
Totals: 4 passed, 6 failed, 6 skipped
********* Finished testing of tst_Counting *********

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<TestCase name="tst_Counting">
<Environment>
<QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion>
<QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion>
</Environment>
<TestFunction name="initTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="testPassPass">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="testPassSkip">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
</TestFunction>
<TestFunction name="testPassFail">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="testSkipPass">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="testSkipSkip">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
</TestFunction>
<TestFunction name="testSkipFail">
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="testFailPass">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="testFailSkip">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
<Message type="skip" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="102">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA[Skipping]]></Description>
</Message>
</TestFunction>
<TestFunction name="testFailFail">
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 1]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
<Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/counting/tst_counting.cpp" line="99">
<DataTag><![CDATA[row 2]]></DataTag>
<Description><![CDATA['false' returned FALSE. ()]]></Description>
</Incident>
</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>
</TestCase>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite errors="6" failures="6" tests="11" name="tst_Counting">
<properties>
<property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/>
<property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/>
</properties>
<testcase result="pass" name="initTestCase"/>
<testcase result="pass" name="testPassPass"/>
<testcase name="testPassSkip">
<!-- tag="row 2" message="Skipping" type="skip" -->
</testcase>
<testcase result="fail" name="testPassFail">
<failure tag="row 2" message="&apos;false&apos; returned FALSE. ()" result="fail"/>
</testcase>
<testcase result="pass" name="testSkipPass">
<!-- tag="row 1" message="Skipping" type="skip" -->
</testcase>
<testcase name="testSkipSkip">
<!-- tag="row 1" message="Skipping" type="skip" -->
<!-- tag="row 2" message="Skipping" type="skip" -->
</testcase>
<testcase result="fail" name="testSkipFail">
<!-- tag="row 1" message="Skipping" type="skip" -->
<failure tag="row 2" message="&apos;false&apos; returned FALSE. ()" result="fail"/>
</testcase>
<testcase result="fail" name="testFailPass">
<failure tag="row 1" message="&apos;false&apos; returned FALSE. ()" result="fail"/>
</testcase>
<testcase result="fail" name="testFailSkip">
<failure tag="row 1" message="&apos;false&apos; returned FALSE. ()" result="fail"/>
<!-- tag="row 2" message="Skipping" type="skip" -->
</testcase>
<testcase result="fail" name="testFailFail">
<failure tag="row 1" message="&apos;false&apos; returned FALSE. ()" result="fail"/>
<failure tag="row 2" message="&apos;false&apos; returned FALSE. ()" result="fail"/>
</testcase>
<testcase result="pass" name="cleanupTestCase"/>
<system-err>
<![CDATA[Skipping]]>
<![CDATA[Skipping]]>
<![CDATA[Skipping]]>
<![CDATA[Skipping]]>
<![CDATA[Skipping]]>
<![CDATA[Skipping]]>
</system-err>
</testsuite>

View File

@ -4,4 +4,4 @@ SUBPROGRAMS = subtest warnings maxwarnings cmptest globaldata skip \
exceptionthrow qexecstringlist datatable commandlinedata\
benchlibwalltime benchlibcallgrind benchlibeventcounter benchlibtickcounter \
benchliboptions xunit badxml longstring float printdatatags \
printdatatagswithglobaltags findtestdata
printdatatagswithglobaltags findtestdata counting

View File

@ -37,6 +37,10 @@
<file>expected_commandlinedata.txt</file>
<file>expected_commandlinedata.xml</file>
<file>expected_commandlinedata.xunitxml</file>
<file>expected_counting.lightxml</file>
<file>expected_counting.txt</file>
<file>expected_counting.xml</file>
<file>expected_counting.xunitxml</file>
<file>expected_crashes.lightxml</file>
<file>expected_crashes.xml</file>
<file>expected_crashes.xunitxml</file>

View File

@ -327,6 +327,7 @@ void tst_Selftests::runSubTest_data()
<< "benchliboptions"
<< "cmptest"
<< "commandlinedata"
<< "counting"
<< "crashes"
<< "datatable"
<< "datetime"