1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtTest module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
45 // enable GUI features
50 #pragma qt_class(QtTestGui)
53 #include <QtTest/qtestassert.h>
54 #include <QtTest/qtest.h>
55 #include <QtTest/qtestevent.h>
56 #include <QtTest/qtestmouse.h>
57 #include <QtTest/qtesttouch.h>
58 #include <QtTest/qtestkeyboard.h>
60 #include <QtGui/qpixmap.h>
61 #include <QtGui/qimage.h>
64 #include <QtGui/qicon.h>
69 #pragma qt_no_master_include
80 inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected,
81 const char *file, int line)
83 QTEST_ASSERT(sizeof(QIcon) == sizeof(void *));
84 return qCompare(*reinterpret_cast<void * const *>(&t1),
85 *reinterpret_cast<void * const *>(&t2), actual, expected, file, line);
88 inline bool qCompare(QImage const &t1, QImage const &t2,
89 const char *actual, const char *expected, const char *file, int line)
93 const bool t1Null = t1.isNull();
94 const bool t2Null = t2.isNull();
95 if (t1Null != t2Null) {
96 qsnprintf(msg, 1024, "Compared QImages differ.\n"
97 " Actual (%s).isNull(): %d\n"
98 " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
99 return compare_helper(false, msg, 0, 0, actual, expected, file, line);
101 if (t1Null && t2Null)
102 return compare_helper(true, 0, 0, 0, actual, expected, file, line);
103 if (t1.width() != t2.width() || t2.height() != t2.height()) {
104 qsnprintf(msg, 1024, "Compared QImages differ in size.\n"
105 " Actual (%s): %dx%d\n"
106 " Expected (%s): %dx%d",
107 actual, t1.width(), t1.height(),
108 expected, t2.width(), t2.height());
109 return compare_helper(false, msg, 0, 0, actual, expected, file, line);
111 if (t1.format() != t2.format()) {
112 qsnprintf(msg, 1024, "Compared QImages differ in format.\n"
114 " Expected (%s): %d",
115 actual, t1.format(), expected, t2.format());
116 return compare_helper(false, msg, 0, 0, actual, expected, file, line);
118 return compare_helper(t1 == t2, "Compared values are not the same",
119 toString(t1), toString(t2), actual, expected, file, line);
122 inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected,
123 const char *file, int line)
127 const bool t1Null = t1.isNull();
128 const bool t2Null = t2.isNull();
129 if (t1Null != t2Null) {
130 qsnprintf(msg, 1024, "Compared QPixmaps differ.\n"
131 " Actual (%s).isNull(): %d\n"
132 " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
133 return compare_helper(false, msg, 0, 0, actual, expected, file, line);
135 if (t1Null && t2Null)
136 return compare_helper(true, 0, 0, 0, actual, expected, file, line);
137 if (t1.width() != t2.width() || t2.height() != t2.height()) {
138 qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
139 " Actual (%s): %dx%d\n"
140 " Expected (%s): %dx%d",
141 actual, t1.width(), t1.height(),
142 expected, t2.width(), t2.height());
143 return compare_helper(false, msg, 0, 0, actual, expected, file, line);
145 return qCompare(t1.toImage(), t2.toImage(), actual, expected, file, line);