1/****************************************************************************
2**
3** Copyright (C) 2016 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
30#include <QtCore/QCoreApplication>
31#include <QtTest/QtTest>
32
33/* Custom event dispatcher to ensure we don't receive any spontaneous events */
34class TestEventDispatcher : public QAbstractEventDispatcher
35{
36 Q_OBJECT
37
38public:
39 TestEventDispatcher(QObject* parent =0)
40 : QAbstractEventDispatcher(parent)
41 {}
42 void flush() {}
43 bool hasPendingEvents() { return false; }
44 void interrupt() {}
45 bool processEvents(QEventLoop::ProcessEventsFlags) { return false; }
46 void registerSocketNotifier(QSocketNotifier*) {}
47 void registerTimer(int,int,Qt::TimerType,QObject*) {}
48 QList<TimerInfo> registeredTimers(QObject*) const { return QList<TimerInfo>(); }
49 void unregisterSocketNotifier(QSocketNotifier*) {}
50 bool unregisterTimer(int) { return false; }
51 bool unregisterTimers(QObject*) { return false; }
52 int remainingTime(int) { return 0; }
53 void wakeUp() {}
54
55#ifdef Q_OS_WIN
56 bool registerEventNotifier(QWinEventNotifier *) { return false; }
57 void unregisterEventNotifier(QWinEventNotifier *) { }
58#endif
59};
60
61class tst_BenchlibOptions: public QObject
62{
63 Q_OBJECT
64
65private slots:
66 void threeEvents();
67};
68
69class tst_BenchlibFifteenIterations : public tst_BenchlibOptions
70{ Q_OBJECT };
71class tst_BenchlibOneHundredMinimum : public tst_BenchlibOptions
72{ Q_OBJECT };
73
74void tst_BenchlibOptions::threeEvents()
75{
76 QAbstractEventDispatcher* ed = QAbstractEventDispatcher::instance();
77 QBENCHMARK {
78 ed->filterNativeEvent(eventType: "", message: 0, result: 0);
79 ed->filterNativeEvent(eventType: "", message: 0, result: 0);
80 ed->filterNativeEvent(eventType: "", message: 0, result: 0);
81 }
82}
83
84int main(int argc, char** argv)
85{
86 std::vector<const char*> args(argv, argv + argc);
87 args.push_back(x: "-eventcounter");
88
89 int ret = 0;
90
91 TestEventDispatcher dispatcher;
92 QCoreApplication app(argc, argv);
93
94 /* Run with no special arguments. */
95 {
96 tst_BenchlibOptions test;
97 ret += QTest::qExec(testObject: &test, argc: args.size(), argv: const_cast<char**>(&args[0]));
98 }
99
100 /* Run with an exact number of iterations. */
101 {
102 auto extraArgs = args;
103 extraArgs.push_back(x: "-iterations");
104 extraArgs.push_back(x: "15");
105 tst_BenchlibFifteenIterations test;
106 ret += QTest::qExec(testObject: &test, argc: extraArgs.size(), argv: const_cast<char**>(&extraArgs[0]));
107 }
108
109 /*
110 Run until getting a value of at least 100.
111 */
112 {
113 auto extraArgs = args;
114 extraArgs.push_back(x: "-minimumvalue");
115 extraArgs.push_back(x: "100");
116 tst_BenchlibOneHundredMinimum test;
117 ret += QTest::qExec(testObject: &test, argc: extraArgs.size(), argv: const_cast<char**>(&extraArgs[0]));
118 }
119
120 return ret;
121}
122
123#include "tst_benchliboptions.moc"
124

source code of qtbase/tests/auto/testlib/selftests/benchliboptions/tst_benchliboptions.cpp