source: trunk/src/testlib/qtest.h@ 345

Last change on this file since 345 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtTest module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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/qurl.h>
57
58#include <QtCore/qpoint.h>
59#include <QtCore/qsize.h>
60#include <QtCore/qrect.h>
61
62
63QT_BEGIN_HEADER
64
65QT_BEGIN_NAMESPACE
66
67QT_MODULE(Test)
68
69namespace QTest
70{
71
72template<> inline char *toString(const QLatin1String &str)
73{
74 return qstrdup(str.latin1());
75}
76
77template<> inline char *toString(const QString &str)
78{
79 return qstrdup(str.toLatin1().constData());
80}
81
82template<> inline char *toString(const QByteArray &ba)
83{
84 return QTest::toHexRepresentation(ba.constData(), ba.length());
85}
86
87template<> inline char *toString(const QTime &time)
88{
89 return time.isValid()
90 ? qstrdup(time.toString(QLatin1String("hh:mm:ss.zzz")).toLatin1())
91 : qstrdup("Invalid QTime");
92}
93
94template<> inline char *toString(const QDate &date)
95{
96 return date.isValid()
97 ? qstrdup(date.toString(QLatin1String("yyyy/MM/dd")).toLatin1())
98 : qstrdup("Invalid QDate");
99}
100
101template<> inline char *toString(const QDateTime &dateTime)
102{
103 return dateTime.isValid()
104 ? qstrdup((dateTime.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")) +
105 (dateTime.timeSpec() == Qt::LocalTime ? QLatin1String("[local time]") : QLatin1String("[UTC]"))).toLatin1())
106 : qstrdup("Invalid QDateTime");
107}
108
109template<> inline char *toString(const QChar &c)
110{
111 return qstrdup(QString::fromLatin1("QChar: '%1' (0x%2)").arg(c).arg(QString::number(static_cast<int>(c.unicode()), 16)).toLatin1().constData());
112}
113
114template<> inline char *toString(const QPoint &p)
115{
116 return qstrdup(QString::fromLatin1("QPoint(%1,%2)").arg(p.x()).arg(p.y()).toLatin1().constData());
117}
118
119template<> inline char *toString(const QSize &s)
120{
121 return qstrdup(QString::fromLatin1("QSize(%1x%2)").arg(s.width()).arg(s.height()).toLatin1().constData());
122}
123
124template<> inline char *toString(const QRect &s)
125{
126 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());
127}
128
129template<> inline char *toString(const QPointF &p)
130{
131 return qstrdup(QString::fromLatin1("QPointF(%1,%2)").arg(p.x()).arg(p.y()).toLatin1().constData());
132}
133
134template<> inline char *toString(const QSizeF &s)
135{
136 return qstrdup(QString::fromLatin1("QSizeF(%1x%2)").arg(s.width()).arg(s.height()).toLatin1().constData());
137}
138
139template<> inline char *toString(const QRectF &s)
140{
141 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());
142}
143
144template<> inline char *toString(const QUrl &uri)
145{
146 return qstrdup(uri.toEncoded().constData());
147}
148
149#ifndef QTEST_NO_SPECIALIZATIONS
150template<>
151#endif
152inline bool qCompare(QString const &t1, QLatin1String const &t2, const char *actual,
153 const char *expected, const char *file, int line)
154{
155 return qCompare<QString>(t1, QString(t2), actual, expected, file, line);
156}
157#ifndef QTEST_NO_SPECIALIZATIONS
158template<>
159#endif
160inline bool qCompare(QLatin1String const &t1, QString const &t2, const char *actual,
161 const char *expected, const char *file, int line)
162{
163 return qCompare<QString>(QString(t1), t2, actual, expected, file, line);
164}
165
166template<>
167inline bool qCompare(QStringList const &t1, QStringList const &t2,
168 const char *actual, const char *expected, const char *file, int line)
169{