2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtTest module of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 07:08:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-15 07:08:27 +00:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QTEST_GUI_H
|
|
|
|
#define QTEST_GUI_H
|
|
|
|
|
|
|
|
// enable GUI features
|
|
|
|
#ifndef QT_GUI_LIB
|
|
|
|
#define QT_GUI_LIB
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
#pragma qt_class(QtTestGui)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <QtTest/qtestassert.h>
|
|
|
|
#include <QtTest/qtest.h>
|
|
|
|
#include <QtTest/qtestevent.h>
|
|
|
|
#include <QtTest/qtestmouse.h>
|
|
|
|
#include <QtTest/qtesttouch.h>
|
|
|
|
#include <QtTest/qtestkeyboard.h>
|
|
|
|
|
2016-03-17 09:01:55 +00:00
|
|
|
#include <QtGui/qcolor.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtGui/qpixmap.h>
|
2011-12-19 10:33:07 +00:00
|
|
|
#include <QtGui/qimage.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-01-12 13:24:39 +00:00
|
|
|
#ifdef QT_WIDGETS_LIB
|
2012-05-14 16:02:16 +00:00
|
|
|
#include <QtGui/qicon.h>
|
2012-01-12 13:24:39 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#if 0
|
|
|
|
// inform syncqt
|
|
|
|
#pragma qt_no_master_include
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
|
|
|
namespace QTest
|
|
|
|
{
|
|
|
|
|
2016-04-11 11:47:51 +00:00
|
|
|
/*!
|
|
|
|
\internal
|
|
|
|
*/
|
2016-03-17 09:01:55 +00:00
|
|
|
template<> inline char *toString(const QColor &color)
|
|
|
|
{
|
|
|
|
return qstrdup(color.name().toLocal8Bit().constData());
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected,
|
|
|
|
const char *file, int line)
|
|
|
|
{
|
|
|
|
QTEST_ASSERT(sizeof(QIcon) == sizeof(void *));
|
2012-09-20 14:36:51 +00:00
|
|
|
return qCompare(*reinterpret_cast<void * const *>(&t1),
|
2011-04-27 10:05:43 +00:00
|
|
|
*reinterpret_cast<void * const *>(&t2), actual, expected, file, line);
|
|
|
|
}
|
|
|
|
|
2011-12-19 10:33:07 +00:00
|
|
|
inline bool qCompare(QImage const &t1, QImage const &t2,
|
|
|
|
const char *actual, const char *expected, const char *file, int line)
|
|
|
|
{
|
|
|
|
char msg[1024];
|
|
|
|
msg[0] = '\0';
|
|
|
|
const bool t1Null = t1.isNull();
|
|
|
|
const bool t2Null = t2.isNull();
|
|
|
|
if (t1Null != t2Null) {
|
|
|
|
qsnprintf(msg, 1024, "Compared QImages differ.\n"
|
2012-03-08 01:30:10 +00:00
|
|
|
" Actual (%s).isNull(): %d\n"
|
2011-12-19 10:33:07 +00:00
|
|
|
" Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
|
2015-06-30 20:11:15 +00:00
|
|
|
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
|
2011-12-19 10:33:07 +00:00
|
|
|
}
|
|
|
|
if (t1Null && t2Null)
|
2015-06-30 20:11:15 +00:00
|
|
|
return compare_helper(true, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
|
2014-04-23 06:33:33 +00:00
|
|
|
if (t1.width() != t2.width() || t1.height() != t2.height()) {
|
2011-12-19 10:33:07 +00:00
|
|
|
qsnprintf(msg, 1024, "Compared QImages differ in size.\n"
|
2012-03-08 01:30:10 +00:00
|
|
|
" Actual (%s): %dx%d\n"
|
2011-12-19 10:33:07 +00:00
|
|
|
" Expected (%s): %dx%d",
|
|
|
|
actual, t1.width(), t1.height(),
|
|
|
|
expected, t2.width(), t2.height());
|
2015-06-30 20:11:15 +00:00
|
|
|
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
|
2011-12-19 10:33:07 +00:00
|
|
|
}
|
|
|
|
if (t1.format() != t2.format()) {
|
|
|
|
qsnprintf(msg, 1024, "Compared QImages differ in format.\n"
|
2012-03-08 01:30:10 +00:00
|
|
|
" Actual (%s): %d\n"
|
2011-12-19 10:33:07 +00:00
|
|
|
" Expected (%s): %d",
|
|
|
|
actual, t1.format(), expected, t2.format());
|
2015-06-30 20:11:15 +00:00
|
|
|
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
|
2011-12-19 10:33:07 +00:00
|
|
|
}
|
2012-02-29 05:43:42 +00:00
|
|
|
return compare_helper(t1 == t2, "Compared values are not the same",
|
|
|
|
toString(t1), toString(t2), actual, expected, file, line);
|
2011-12-19 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected,
|
|
|
|
const char *file, int line)
|
|
|
|
{
|
2011-12-19 10:33:07 +00:00
|
|
|
char msg[1024];
|
|
|
|
msg[0] = '\0';
|
|
|
|
const bool t1Null = t1.isNull();
|
|
|
|
const bool t2Null = t2.isNull();
|
|
|
|
if (t1Null != t2Null) {
|
|
|
|
qsnprintf(msg, 1024, "Compared QPixmaps differ.\n"
|
2012-03-08 01:30:10 +00:00
|
|
|
" Actual (%s).isNull(): %d\n"
|
2011-12-19 10:33:07 +00:00
|
|
|
" Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
|
2015-06-30 20:11:15 +00:00
|
|
|
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
|
2011-12-19 10:33:07 +00:00
|
|
|
}
|
|
|
|
if (t1Null && t2Null)
|
2015-06-30 20:11:15 +00:00
|
|
|
return compare_helper(true, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
|
2014-04-23 06:33:33 +00:00
|
|
|
if (t1.width() != t2.width() || t1.height() != t2.height()) {
|
2011-12-19 10:33:07 +00:00
|
|
|
qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
|
2012-03-08 01:30:10 +00:00
|
|
|
" Actual (%s): %dx%d\n"
|
2011-12-19 10:33:07 +00:00
|
|
|
" Expected (%s): %dx%d",
|
|
|
|
actual, t1.width(), t1.height(),
|
|
|
|
expected, t2.width(), t2.height());
|
2015-06-30 20:11:15 +00:00
|
|
|
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
|
2011-12-19 10:33:07 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
return qCompare(t1.toImage(), t2.toImage(), actual, expected, file, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|