Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:12:23

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QTEST_GUI_H
0005 #define QTEST_GUI_H
0006 
0007 // enable GUI features
0008 #ifndef QT_GUI_LIB
0009 #define QT_GUI_LIB
0010 #endif
0011 #if 0
0012 #pragma qt_class(QtTestGui)
0013 #endif
0014 
0015 #include <QtTest/qtestassert.h>
0016 #include <QtTest/qtest.h>
0017 #include <QtTest/qtestevent.h>
0018 #include <QtTest/qtestmouse.h>
0019 #include <QtTest/qtesttouch.h>
0020 #include <QtTest/qtestkeyboard.h>
0021 
0022 #include <QtGui/qcolor.h>
0023 #include <QtGui/qpixmap.h>
0024 #include <QtGui/qimage.h>
0025 #if QT_CONFIG(shortcut)
0026 #include <QtGui/qkeysequence.h>
0027 #endif
0028 #include <QtGui/qregion.h>
0029 #include <QtGui/qvector2d.h>
0030 #include <QtGui/qvector3d.h>
0031 #include <QtGui/qvector4d.h>
0032 #include <QtGui/qicon.h>
0033 
0034 #if 0
0035 // inform syncqt
0036 #pragma qt_no_master_include
0037 #endif
0038 
0039 QT_BEGIN_NAMESPACE
0040 
0041 
0042 namespace QTest
0043 {
0044 
0045 template<> inline char *toString(const QColor &color)
0046 {
0047     return qstrdup(color.name(QColor::HexArgb).toLocal8Bit().constData());
0048 }
0049 
0050 template<> inline char *toString(const QRegion &region)
0051 {
0052     QByteArray result = "QRegion(";
0053     if (region.isNull()) {
0054         result += "null";
0055     } else if (region.isEmpty()) {
0056         result += "empty";
0057     } else {
0058         const auto rects = region.begin();
0059         const int rectCount = region.rectCount();
0060         if (rectCount > 1) {
0061             result += QByteArray::number(rectCount);
0062             result += " rectangles, ";
0063         }
0064         for (int i = 0; i < rectCount; ++i) {
0065             if (i)
0066                 result += ", ";
0067             const QRect &r = rects[i];
0068             result += QByteArray::number(r.width());
0069             result += 'x';
0070             result += QByteArray::number(r.height());
0071             if (r.x() >= 0)
0072                 result += '+';
0073             result += QByteArray::number(r.x());
0074             if (r.y() >= 0)
0075                 result += '+';
0076             result += QByteArray::number(r.y());
0077         }
0078     }
0079     result += ')';
0080     return qstrdup(result.constData());
0081 }
0082 
0083 #if !defined(QT_NO_VECTOR2D) || defined(Q_QDOC)
0084 template<> inline char *toString(const QVector2D &v)
0085 {
0086     QByteArray result = "QVector2D(" + QByteArray::number(double(v.x())) + ", "
0087         + QByteArray::number(double(v.y())) + ')';
0088     return qstrdup(result.constData());
0089 }
0090 #endif // !QT_NO_VECTOR2D
0091 #if !defined(QT_NO_VECTOR3D) || defined(Q_QDOC)
0092 template<> inline char *toString(const QVector3D &v)
0093 {
0094     QByteArray result = "QVector3D(" + QByteArray::number(double(v.x())) + ", "
0095         + QByteArray::number(double(v.y())) + ", " + QByteArray::number(double(v.z())) + ')';
0096     return qstrdup(result.constData());
0097 }
0098 #endif // !QT_NO_VECTOR3D
0099 #if !defined(QT_NO_VECTOR4D) || defined(Q_QDOC)
0100 template<> inline char *toString(const QVector4D &v)
0101 {
0102     QByteArray result = "QVector4D(" + QByteArray::number(double(v.x())) + ", "
0103         + QByteArray::number(double(v.y())) + ", " + QByteArray::number(double(v.z()))
0104         + ", " + QByteArray::number(double(v.w())) + ')';
0105     return qstrdup(result.constData());
0106 }
0107 #endif // !QT_NO_VECTOR4D
0108 
0109 #if QT_CONFIG(shortcut)
0110 template<> inline char *toString(const QKeySequence &keySequence)
0111 {
0112     return toString(keySequence.toString());
0113 }
0114 #endif
0115 
0116 inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected,
0117                     const char *file, int line)
0118 {
0119     QTEST_ASSERT(sizeof(QIcon) == sizeof(void *));
0120     return qCompare(*reinterpret_cast<void * const *>(&t1),
0121                    *reinterpret_cast<void * const *>(&t2), actual, expected, file, line);
0122 }
0123 
0124 inline bool qCompare(QImage const &t1, QImage const &t2,
0125                      const char *actual, const char *expected, const char *file, int line)
0126 {
0127     char msg[1024];
0128     msg[0] = '\0';
0129     const bool t1Null = t1.isNull();
0130     const bool t2Null = t2.isNull();
0131     if (t1Null != t2Null) {
0132         qsnprintf(msg, 1024, "Compared QImages differ.\n"
0133                   "   Actual   (%s).isNull(): %d\n"
0134                   "   Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
0135         return compare_helper(false, msg, actual, expected, file, line);
0136     }
0137     if (t1Null && t2Null)
0138         return compare_helper(true, nullptr, actual, expected, file, line);
0139     if (!qFuzzyCompare(t1.devicePixelRatio(), t2.devicePixelRatio())) {
0140         qsnprintf(msg, 1024, "Compared QImages differ in device pixel ratio.\n"
0141                   "   Actual   (%s): %g\n"
0142                   "   Expected (%s): %g",
0143                   actual, t1.devicePixelRatio(),
0144                   expected, t2.devicePixelRatio());
0145         return compare_helper(false, msg, actual, expected, file, line);
0146     }
0147     if (t1.width() != t2.width() || t1.height() != t2.height()) {
0148         qsnprintf(msg, 1024, "Compared QImages differ in size.\n"
0149                   "   Actual   (%s): %dx%d\n"
0150                   "   Expected (%s): %dx%d",
0151                   actual, t1.width(), t1.height(),
0152                   expected, t2.width(), t2.height());
0153         return compare_helper(false, msg, actual, expected, file, line);
0154     }
0155     if (t1.format() != t2.format()) {
0156         qsnprintf(msg, 1024, "Compared QImages differ in format.\n"
0157                   "   Actual   (%s): %d\n"
0158                   "   Expected (%s): %d",
0159                   actual, t1.format(), expected, t2.format());
0160         return compare_helper(false, msg, actual, expected, file, line);
0161     }
0162     return compare_helper(t1 == t2, "Compared values are not the same",
0163                           actual, expected, file, line);
0164 }
0165 
0166 inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected,
0167                     const char *file, int line)
0168 {
0169     char msg[1024];
0170     msg[0] = '\0';
0171     const bool t1Null = t1.isNull();
0172     const bool t2Null = t2.isNull();
0173     if (t1Null != t2Null) {
0174         qsnprintf(msg, 1024, "Compared QPixmaps differ.\n"
0175                   "   Actual   (%s).isNull(): %d\n"
0176                   "   Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
0177         return compare_helper(false, msg, actual, expected, file, line);
0178     }
0179     if (t1Null && t2Null)
0180         return compare_helper(true, nullptr, actual, expected, file, line);
0181     if (!qFuzzyCompare(t1.devicePixelRatio(), t2.devicePixelRatio())) {
0182         qsnprintf(msg, 1024, "Compared QPixmaps differ in device pixel ratio.\n"
0183                   "   Actual   (%s): %g\n"
0184                   "   Expected (%s): %g",
0185                   actual, t1.devicePixelRatio(),
0186                   expected, t2.devicePixelRatio());
0187         return compare_helper(false, msg, actual, expected, file, line);
0188     }
0189     if (t1.width() != t2.width() || t1.height() != t2.height()) {
0190         qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
0191                   "   Actual   (%s): %dx%d\n"
0192                   "   Expected (%s): %dx%d",
0193                   actual, t1.width(), t1.height(),
0194                   expected, t2.width(), t2.height());
0195         return compare_helper(false, msg, actual, expected, file, line);
0196     }
0197     return qCompare(t1.toImage(), t2.toImage(), actual, expected, file, line);
0198 }
0199 
0200 }
0201 
0202 QT_END_NAMESPACE
0203 
0204 #endif