| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the test suite of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
/* This file is part of the KDE project |
| 42 |
Copyright (C) 2007 Matthias Kretz <kretz@kde.org> |
| 43 |
|
| 44 |
This library is free software; you can redistribute it and/or |
| 45 |
modify it under the terms of the GNU Library General Public |
| 46 |
License version 2 as published by the Free Software Foundation. |
| 47 |
|
| 48 |
This library is distributed in the hope that it will be useful, |
| 49 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 50 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 51 |
Library General Public License for more details. |
| 52 |
|
| 53 |
You should have received a copy of the GNU Library General Public License |
| 54 |
along with this library; see the file COPYING.LIB. If not, write to |
| 55 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 56 |
Boston, MA 02110-1301, USA. |
| 57 |
|
| 58 |
*/ |
| 59 |
|
| 60 |
#ifndef QTESTHELPER_H |
| 61 |
#define QTESTHELPER_H |
| 62 |
|
| 63 |
#include <QtCore/QEventLoop> |
| 64 |
#include <QtCore/QTimer> |
| 65 |
#include <QtTest/QSignalSpy> |
| 66 |
#include <QtCore/QVariant> |
| 67 |
|
| 68 |
QT_BEGIN_NAMESPACE |
| 69 |
namespace QTest |
| 70 |
{ |
| 71 |
|
| 72 |
/** |
| 73 |
* Starts an event loop that runs until the given signal is received. Optionally the event loop |
| 74 |
* can return earlier on a timeout. |
| 75 |
* |
| 76 |
* \return \p true if the requested signal was received |
| 77 |
* \p false on timeout |
| 78 |
*/ |
| 79 |
bool waitForSignal(QObject *obj, const char *signal, int timeout = 0) |
| 80 |
{ |
| 81 |
QEventLoop loop; |
| 82 |
QObject::connect(obj, signal, &loop, SLOT(quit())); |
| 83 |
QTimer timer; |
| 84 |
QSignalSpy timeoutSpy(&timer, SIGNAL(timeout())); |
| 85 |
if (timeout > 0) { |
| 86 |
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); |
| 87 |
timer.setSingleShot(true); |
| 88 |
timer.start(timeout); |
| 89 |
} |
| 90 |
loop.exec(); |
| 91 |
return timeoutSpy.isEmpty(); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
// template<> |
| 96 |
char *toString(const Phonon::State &state) |
| 97 |
{ |
| 98 |
switch (state) { |
| 99 |
case Phonon::LoadingState: |
| 100 |
return qstrdup("LoadingState"); |
| 101 |
case Phonon::StoppedState: |
| 102 |
return qstrdup("StoppedState"); |
| 103 |
case Phonon::PlayingState: |
| 104 |
return qstrdup("PlayingState"); |
| 105 |
case Phonon::BufferingState: |
| 106 |
return qstrdup("BufferingState"); |
| 107 |
case Phonon::PausedState: |
| 108 |
return qstrdup("PausedState"); |
| 109 |
case Phonon::ErrorState: |
| 110 |
return qstrdup("ErrorState"); |
| 111 |
} |
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
// template<> |
| 116 |
char *toString(const QVariant::Type &type) |
| 117 |
{ |
| 118 |
switch (type) { |
| 119 |
case QVariant::Invalid: |
| 120 |
return qstrdup("QVariant::Invalid"); |
| 121 |
case QVariant::BitArray: |
| 122 |
return qstrdup("QVariant::BitArray"); |
| 123 |
case QVariant::Bitmap: |
| 124 |
return qstrdup("QVariant::Bitmap"); |
| 125 |
case QVariant::Bool: |
| 126 |
return qstrdup("QVariant::Bool"); |
| 127 |
case QVariant::Brush: |
| 128 |
return qstrdup("QVariant::Brush"); |
| 129 |
case QVariant::ByteArray: |
| 130 |
return qstrdup("QVariant::ByteArray"); |
| 131 |
case QVariant::Char: |
| 132 |
return qstrdup("QVariant::Char"); |
| 133 |
case QVariant::Color: |
| 134 |
return qstrdup("QVariant::Color"); |
| 135 |
case QVariant::Cursor: |
| 136 |
return qstrdup("QVariant::Cursor"); |
| 137 |
case QVariant::Date: |
| 138 |
return qstrdup("QVariant::Date"); |
| 139 |
case QVariant::DateTime: |
| 140 |
return qstrdup("QVariant::DateTime"); |
| 141 |
case QVariant::Double: |
| 142 |
return qstrdup("QVariant::Double"); |
| 143 |
case QVariant::Font: |
| 144 |
return qstrdup("QVariant::Font"); |
| 145 |
case QVariant::Icon: |
| 146 |
return qstrdup("QVariant::Icon"); |
| 147 |
case QVariant::Image: |
| 148 |
return qstrdup("QVariant::Image"); |
| 149 |
case QVariant::Int: |
| 150 |
return qstrdup("QVariant::Int"); |
| 151 |
case QVariant::KeySequence: |
| 152 |
return qstrdup("QVariant::KeySequence"); |
| 153 |
case QVariant::Line: |
| 154 |
return qstrdup("QVariant::Line"); |
| 155 |
case QVariant::LineF: |
| 156 |
return qstrdup("QVariant::LineF"); |
| 157 |
case QVariant::List: |
| 158 |
return qstrdup("QVariant::List"); |
| 159 |
case QVariant::Locale: |
| 160 |
return qstrdup("QVariant::Locale"); |
| 161 |
case QVariant::LongLong: |
| 162 |
return qstrdup("QVariant::LongLong"); |
| 163 |
case QVariant::Map: |
| 164 |
return qstrdup("QVariant::Map"); |
| 165 |
case QVariant::Matrix: |
| 166 |
return qstrdup("QVariant::Matrix"); |
| 167 |
case QVariant::Transform: |
| 168 |
return qstrdup("QVariant::Transform"); |
| 169 |
case QVariant::Palette: |
| 170 |
return qstrdup("QVariant::Palette"); |
| 171 |
case QVariant::Pen: |
| 172 |
return qstrdup("QVariant::Pen"); |
| 173 |
case QVariant::Pixmap: |
| 174 |
return qstrdup("QVariant::Pixmap"); |
| 175 |
case QVariant::Point: |
| 176 |
return qstrdup("QVariant::Point"); |
| 177 |
case QVariant::PointF: |
| 178 |
return qstrdup("QVariant::PointF"); |
| 179 |
case QVariant::Polygon: |
| 180 |
return qstrdup("QVariant::Polygon"); |
| 181 |
case QVariant::Rect: |
| 182 |
return qstrdup("QVariant::Rect"); |
| 183 |
case QVariant::RectF: |
| 184 |
return qstrdup("QVariant::RectF"); |
| 185 |
case QVariant::RegExp: |
| 186 |
return qstrdup("QVariant::RegExp"); |
| 187 |
case QVariant::Region: |
| 188 |
return qstrdup("QVariant::Region"); |
| 189 |
case QVariant::Size: |
| 190 |
return qstrdup("QVariant::Size"); |
| 191 |
case QVariant::SizeF: |
| 192 |
return qstrdup("QVariant::SizeF"); |
| 193 |
case QVariant::SizePolicy: |
| 194 |
return qstrdup("QVariant::SizePolicy"); |
| 195 |
case QVariant::String: |
| 196 |
return qstrdup("QVariant::String"); |
| 197 |
case QVariant::StringList: |
| 198 |
return qstrdup("QVariant::StringList"); |
| 199 |
case QVariant::TextFormat: |
| 200 |
return qstrdup("QVariant::TextFormat"); |
| 201 |
case QVariant::TextLength: |
| 202 |
return qstrdup("QVariant::TextLength"); |
| 203 |
case QVariant::Time: |
| 204 |
return qstrdup("QVariant::Time"); |
| 205 |
case QVariant::UInt: |
| 206 |
return qstrdup("QVariant::UInt"); |
| 207 |
case QVariant::ULongLong: |
| 208 |
return qstrdup("QVariant::ULongLong"); |
| 209 |
case QVariant::Url: |
| 210 |
return qstrdup("QVariant::Url"); |
| 211 |
case QVariant::UserType: |
| 212 |
return qstrdup("QVariant::UserType"); |
| 213 |
case QVariant::LastType: |
| 214 |
return qstrdup("QVariant::LastType"); |
| 215 |
default: |
| 216 |
return 0; |
| 217 |
} |
| 218 |
} |
| 219 |
} // namespace QTest |
| 220 |
QT_END_NAMESPACE |
| 221 |
|
| 222 |
#endif // QTESTHELPER_H |