Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtTest module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QTEST_H
43#define QTEST_H
44
45#include <QtTest/qtest_global.h>
46#include <QtTest/qtestcase.h>
47#include <QtTest/qtestdata.h>
48#include <QtTest/qtestdata.h>
49#include <QtTest/qbenchmark.h>
50
51#include <QtCore/qbytearray.h>
52#include <QtCore/qstring.h>
53#include <QtCore/qstringlist.h>
54#include <QtCore/qdatetime.h>
55#include <QtCore/qobject.h>
56#include <QtCore/qvariant.h>
57#include <QtCore/qurl.h>
58
59#include <QtCore/qpoint.h>
60#include <QtCore/qsize.h>
61#include <QtCore/qrect.h>
62
63
64QT_BEGIN_HEADER
65
66QT_BEGIN_NAMESPACE
67
68QT_MODULE(Test)
69
70namespace QTest
71{
72
73template<> inline char *toString(const QLatin1String &str)
74{
75 return qstrdup(str.latin1());
76}
77
78template<> inline char *toString(const QString &str)
79{
80 return qstrdup(str.toLatin1().constData());
81}
82
83template<> inline char *toString(const QByteArray &ba)
84{
85 return QTest::toHexRepresentation(ba.constData(), ba.length());
86}
87
88template<> inline char *toString(const QTime &time)
89{
90 return time.isValid()
91 ? qstrdup(time.toString(QLatin1String("hh:mm:ss.zzz")).toLatin1().constData())
92 : qstrdup("Invalid QTime");
93}
94
95template<> inline char *toString(const QDate &date)
96{
97 return date.isValid()
98 ? qstrdup(date.toString(QLatin1String("yyyy/MM/dd")).toLatin1().constData())
99 : qstrdup("Invalid QDate");
100}
101
102template<> inline char *toString(const QDateTime &dateTime)
103{
104 return dateTime.isValid()
105 ? qstrdup((dateTime.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")) +
106 (dateTime.timeSpec() == Qt::LocalTime ? QLatin1String("[local time]") : QLatin1String("[UTC]"))).toLatin1().constData())
107 : qstrdup("Invalid QDateTime");
108}
109
110template<> inline char *toString(const QChar &c)
111{
112 return qstrdup(QString::fromLatin1("QChar: '%1' (0x%2)").arg(c).arg(QString::number(static_cast<int>(c.unicode()), 16)).toLatin1().constData());
113}
114
115template<> inline char *toString(const QPoint &p)
116{
117 return qstrdup(QString::fromLatin1("QPoint(%1,%2)").arg(p.x()).arg(p.y()).toLatin1().constData());
118}
119
120template<> inline char *toString(const QSize &s)
121{
122 return qstrdup(QString::fromLatin1("QSize(%1x%2)").arg(s.width()).arg(s.height()).toLatin1().constData());
123}
124
125template<> inline char *toString(const QRect &s)
126{
127 return qstrdup(QString::fromLatin1("QRect(%1,%2 %5x%6) (bottomright %3,%4)").arg(s.left()).arg(s.top()).arg(s.right()).arg(s.bottom()).arg(s.width()).arg(s.height()).toLatin1().constData());
128}
129
130template<> inline char *toString(const QPointF &p)
131{
132 return qstrdup(QString::fromLatin1("QPointF(%1,%2)").arg(p.x()).arg(p.y()).toLatin1().constData());
133}
134
135template<> inline char *toString(const QSizeF &s)
136{
137 return qstrdup(QString::fromLatin1("QSizeF(%1x%2)").arg(s.width()).arg(s.height()).toLatin1().constData());
138}
139
140template<> inline char *toString(const QRectF &s)
141{
142 return qstrdup(QString::fromLatin1("QRectF(%1,%2 %5x%6) (bottomright %3,%4)").arg(s.left()).arg(s.top()).arg(s.right()).arg(s.bottom()).arg(s.width()).arg(s.height()).toLatin1().constData());
143}
144
145template<> inline char *toString(const QUrl &uri)
146{
147 return qstrdup(uri.toEncoded().constData());
148}
149
150template<> inline char *toString(const QVariant &v)
151{
152 QByteArray vstring("QVariant(");
153 if (v.isValid()) {
154 QByteArray type(v.typeName());
155 if (type.isEmpty()) {
156 type = QByteArray::number(v.userType());
157 }
158 vstring.append(type);
159 if (!v.isNull()) {
160 vstring.append(',');
161 if (v.canConvert(QVariant::String)) {
162 vstring.append(qvariant_cast<QString>(v).toLatin1());
163 }
164 else {
165 vstring.append("<value not representable as string>");
166 }
167 }
168 }
169 vstring.append(')');
170
171 return qstrdup(vstring.constData());
172}
173
174#ifndef QTEST_NO_SPECIALIZATIONS
175template<>
176#endif
177inline bool qCompare(QString const &t1, QLatin1String const &t2, const char *actual,
178 const char *expected, const char *file, int line)
179{
180 return qCompare<QString>(t1, QString(t2), actual, expected, file, line);
181}
182#ifndef QTEST_NO_SPECIALIZATIONS
183template<>
184#endif
185inline bool qCompare(QLatin1String const &t1, QString const &t2, const char *actual,
186 const char *expected, const char *file, int line)
187{
188 return qCompare<QString>(QString(t1), t2, actual, expected, file, line);
189}
190
191template<>
192inline bool qCompare(QStringList const &t1, QStringList const &t2,
193 const char *actual, const char *expected, const char *file, int line)
194{
195 char msg[1024];
196 msg[0] = '\0';
197 bool isOk = true;
198 if (t1.count() != t2.count()) {
199 qt_snprintf(msg, 1024, "Compared QStringLists have different sizes.\n"
200 " Actual (%s) size : '%d'\n"
201 " Expected (%s) size: '%d'", actual, t1.count(), expected, t2.count());
202 isOk = false;
203 }
204 const int min = qMin(t1.count(), t2.count());
205 for (int i = 0; isOk && i < min; ++i) {
206 if (t1.at(i) != t2.at(i)) {
207 qt_snprintf(msg, 1024, "Compared QStringLists differ at index %d.\n"
208 " Actual (%s) : '%s'\n"
209 " Expected (%s) : '%s'", i, actual, t1.at(i).toLatin1().constData(),
210 expected, t2.at(i).toLatin1().constData());
211 isOk = false;
212 }
213 }
214 return compare_helper(isOk, msg, file, line);
215}
216
217template <typename T>
218inline bool qCompare(QFlags<T> const &t1, T const &t2, const char *actual, const char *expected,
219 const char *file, int line)
220{
221 return qCompare(int(t1), int(t2), actual, expected, file, line);
222}
223
224template <typename T>
225inline bool qCompare(QFlags<T> const &t1, int const &t2, const char *actual, const char *expected,
226 const char *file, int line)
227{
228 return qCompare(int(t1), t2, actual, expected, file, line);
229}
230
231}
232QT_END_NAMESPACE
233
234#define QTEST_APPLESS_MAIN(TestObject) \
235int main(int argc, char *argv[]) \
236{ \
237 TestObject tc; \
238 return QTest::qExec(&tc, argc, argv); \
239}
240
241#define QTEST_NOOP_MAIN \
242int main(int argc, char *argv[]) \
243{ \
244 QObject tc; \
245 return QTest::qExec(&tc, argc, argv); \
246}
247
248#include <QtTest/qtestsystem.h>
249
250#ifdef QT_GUI_LIB
251
252#include <QtTest/qtest_gui.h>
253
254#ifdef QT_KEYPAD_NAVIGATION
255# define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeNone);
256#else
257# define QTEST_DISABLE_KEYPAD_NAVIGATION
258#endif
259
260#define QTEST_MAIN(TestObject) \
261int main(int argc, char *argv[]) \
262{ \
263 QApplication app(argc, argv); \
264 QTEST_DISABLE_KEYPAD_NAVIGATION \
265 TestObject tc; \
266 return QTest::qExec(&tc, argc, argv); \
267}
268
269#else
270
271#define QTEST_MAIN(TestObject) \
272int main(int argc, char *argv[]) \
273{ \
274 QCoreApplication app(argc, argv); \
275 TestObject tc; \
276 return QTest::qExec(&tc, argc, argv); \
277}
278
279#endif // QT_GUI_LIB
280
281QT_END_HEADER
282
283#endif
284

Warning: That file was not part of the compilation database. It may have many parsing errors.