1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30#include <QtCore/QtMath>
31#include <QtCore/QtNumeric>
32
33/* Test QTest functions not covered by other parts of the selftest. Tests that
34 * involve crashing or exiting should be added as separate tests in their own
35 * right. Tests that form a coherent group on a related theme should also go in
36 * their own directory. Tests that fail in order to exercise QTest internals
37 * are fine.
38 */
39
40class tst_TestLib : public QObject
41{
42Q_OBJECT
43private slots:
44 void basics() const;
45 void delays() const;
46 void reals_data() const;
47 void reals() const;
48};
49
50void tst_TestLib::basics() const
51{
52 QVERIFY(QByteArray(QTest::currentAppName()).contains("testlib"));
53
54 QCOMPARE(QTest::testObject(), nullptr); // last, because it should fail
55}
56
57QT_BEGIN_NAMESPACE
58
59namespace QTest {
60 // Defined; not declared in the public header, but used by qtdeclarative.
61 int defaultKeyDelay();
62 int defaultMouseDelay();
63}
64
65QT_END_NAMESPACE
66
67void tst_TestLib::delays() const
68{
69 QVERIFY(QTest::defaultMouseDelay() >= 0);
70 QVERIFY(QTest::defaultKeyDelay() >= 0);
71}
72
73void tst_TestLib::reals_data() const
74{
75 QTest::addColumn<double>("actual");
76 QTest::addColumn<double>("expected");
77
78 QTest::newRow("zero") << 0.0 << 0.0;
79#define ADDROW(func) QTest::addRow("self-%s", #func) << func() << func()
80 ADDROW(qQNaN);
81 ADDROW(qInf);
82#undef ADDROW // Just used so as to exercise addRow()
83 QTest::newRow("infineg") << -qInf() << -qInf();
84 QTest::newRow("Sin(turn/4)") << qSin(9 * M_PI_2) << 1.0;
85 QTest::newRow("Cos(turn/2)") << qCos(15 * M_PI) << -1.0;
86}
87
88void tst_TestLib::reals() const
89{
90 QFETCH(double, actual);
91 QFETCH(double, expected);
92 QCOMPARE(actual, expected);
93}
94
95QTEST_APPLESS_MAIN(tst_TestLib)
96
97#include "tst_testlib.moc"
98