1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtTest module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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 |
|
---|
64 | QT_BEGIN_HEADER
|
---|
65 |
|
---|
66 | QT_BEGIN_NAMESPACE
|
---|
67 |
|
---|
68 | QT_MODULE(Test)
|
---|
69 |
|
---|
70 | namespace QTest
|
---|
71 | {
|
---|
72 |
|
---|
73 | template<> inline char *toString(const QLatin1String &str)
|
---|
74 | {
|
---|
75 | return qstrdup(str.latin1());
|
---|
76 | }
|
---|
77 |
|
---|
78 | template<> inline char *toString(const QString &str)
|
---|
79 | {
|
---|
80 | return qstrdup(str.toLatin1().constData());
|
---|
81 | }
|
---|
82 |
|
---|
83 | template<> inline char *toString(const QByteArray &ba)
|
---|
84 | {
|
---|
85 | return QTest::toHexRepresentation(ba.constData(), ba.length());
|
---|
86 | }
|
---|
87 |
|
---|
88 | template<> 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 |
|
---|
95 | template<> 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 |
|
---|
102 | template<> 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 |
|
---|
110 | template<> 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 |
|
---|
115 | template<> 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 |
|
---|
120 | template<> 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 |
|
---|
125 | template<> 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 |
|
---|
130 | template<> 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 |
|
---|
135 | template<> 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 |
|
---|
140 | template<> 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 |
|
---|
145 | template<> inline char *toString(const QUrl &uri)
|
---|
146 | {
|
---|
147 | return qstrdup(uri.toEncoded().constData());
|
---|
148 | }
|
---|
149 |
|
---|
150 | template<> 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(qVariantValue<QString>(v).toLatin1());
|
---|
163 | }
|
---|
164 | else {
|
---|
165 | vstring.append("<value not representable as string>");
|
---|
166 | }
|
---|
167 | }
|
---|
168 | }
|
---|
|
---|