Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:11:36

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