diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qtest_gui.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h index 99b7700e3b..47ec8cf13e 100644 --- a/src/testlib/qtest_gui.h +++ b/src/testlib/qtest_gui.h @@ -59,6 +59,7 @@ #include <QtWidgets/qicon.h> #include <QtGui/qpixmap.h> +#include <QtGui/qimage.h> #if 0 // inform syncqt @@ -85,10 +86,71 @@ inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const } #endif +#ifndef QTEST_NO_SPECIALIZATIONS template<> +#endif +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" + " Actual (%s).isNull() : %d\n" + " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null); + return compare_helper(false, msg, file, line); + } + if (t1Null && t2Null) + return compare_helper(true, "COMPARE()", file, line); + if (t1.width() != t2.width() || t2.height() != t2.height()) { + qsnprintf(msg, 1024, "Compared QImages differ in size.\n" + " Actual (%s) : %dx%d\n" + " Expected (%s): %dx%d", + actual, t1.width(), t1.height(), + expected, t2.width(), t2.height()); + return compare_helper(false, msg, file, line); + } + if (t1.format() != t2.format()) { + qsnprintf(msg, 1024, "Compared QImages differ in format.\n" + " Actual (%s) : %d\n" + " Expected (%s): %d", + actual, t1.format(), expected, t2.format()); + return compare_helper(false, msg, file, line); + } + return (t1 == t2) + ? compare_helper(true, "COMPARE()", file, line) + : compare_helper(false, "Compared values are not the same", + toString(t1), toString(t2), actual, expected, file, line); +} + +#ifndef QTEST_NO_SPECIALIZATIONS +template<> +#endif inline bool qCompare(QPixmap const &t1, QPixmap 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 QPixmaps differ.\n" + " Actual (%s).isNull() : %d\n" + " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null); + return compare_helper(false, msg, file, line); + } + if (t1Null && t2Null) + return compare_helper(true, "COMPARE()", file, line); + if (t1.width() != t2.width() || t2.height() != t2.height()) { + qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n" + " Actual (%s) : %dx%d\n" + " Expected (%s): %dx%d", + actual, t1.width(), t1.height(), + expected, t2.width(), t2.height()); + return compare_helper(false, msg, file, line); + } return qCompare(t1.toImage(), t2.toImage(), actual, expected, file, line); } |