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 */ |
34 | class TestEventDispatcher : public QAbstractEventDispatcher |
35 | { |
36 | Q_OBJECT |
37 | |
38 | public: |
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 | |
61 | class tst_BenchlibEventCounter: public QObject |
62 | { |
63 | Q_OBJECT |
64 | |
65 | private slots: |
66 | void events(); |
67 | void events_data(); |
68 | }; |
69 | |
70 | void tst_BenchlibEventCounter::events() |
71 | { |
72 | QFETCH(int, eventCount); |
73 | |
74 | QAbstractEventDispatcher* ed = QAbstractEventDispatcher::instance(); |
75 | QBENCHMARK { |
76 | for (int i = 0; i < eventCount; ++i) { |
77 | ed->filterNativeEvent(eventType: "" , message: 0, result: 0); |
78 | } |
79 | } |
80 | } |
81 | |
82 | void tst_BenchlibEventCounter::events_data() |
83 | { |
84 | QTest::addColumn<int>(name: "eventCount" ); |
85 | |
86 | QTest::newRow(dataTag: "0" ) << 0; |
87 | QTest::newRow(dataTag: "1" ) << 1; |
88 | QTest::newRow(dataTag: "10" ) << 10; |
89 | QTest::newRow(dataTag: "100" ) << 100; |
90 | QTest::newRow(dataTag: "500" ) << 500; |
91 | QTest::newRow(dataTag: "5000" ) << 5000; |
92 | QTest::newRow(dataTag: "100000" ) << 100000; |
93 | } |
94 | |
95 | int main(int argc, char** argv) |
96 | { |
97 | std::vector<const char*> args(argv, argv + argc); |
98 | args.push_back(x: "-eventcounter" ); |
99 | argc = args.size(); |
100 | argv = const_cast<char**>(&args[0]); |
101 | |
102 | TestEventDispatcher dispatcher; |
103 | QCoreApplication app(argc, argv); |
104 | tst_BenchlibEventCounter test; |
105 | return QTest::qExec(testObject: &test, argc, argv); |
106 | } |
107 | |
108 | #include "tst_benchlibeventcounter.moc" |
109 | |