2 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
19 // Functions and macros that really need to be in QTestLib
25 #if !defined(TESTS_SOURCE_DIR)
26 #define TESTS_SOURCE_DIR ""
30 * Starts an event loop that runs until the given signal is received.
31 * Optionally the event loop
32 * can return earlier on a timeout.
34 * \return \p true if the requested signal was received
37 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000)
40 QObject::connect(obj, signal, &loop, SLOT(quit()));
42 QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
44 QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
45 timer.setSingleShot(true);
49 return timeoutSpy.isEmpty();
52 // Will try to wait for the condition while allowing event processing
53 #define QTRY_VERIFY(__expr) \
55 const int __step = 50; \
56 const int __timeout = 5000; \
60 for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
61 QTest::qWait(__step); \
66 // Will try to wait for the condition while allowing event processing
67 #define QTRY_COMPARE(__expr, __expected) \
69 const int __step = 50; \
70 const int __timeout = 5000; \
71 if ((__expr) != (__expected)) { \
74 for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
75 QTest::qWait(__step); \
77 QCOMPARE(__expr, __expected); \