diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2011-12-19 11:33:07 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-21 22:59:28 +0100 |
commit | bc8f25c7e6ab73441c46ea41362a054843b42ec3 (patch) | |
tree | bdb3157531f5471be1e319af6ab4a0bda9df0678 /src/testlib | |
parent | 5d4acbab0e243aa944f9b365fb6d72073bb1da70 (diff) |
QTestlib: Make QImage comparison more verbose.
Introduce a specialization for qCompare(QImage,QImage) that
checks isNull, size and format and outputs verbose messages.
Check isNull, size similarly for QPixmap.
Add an autotest:
- Add test to cmptest and make it a GUI application since
QImage requires QGuiApplication.
- Make testlib/selftests capable of running X11-GUI applications
by passing DISPLAY.
- Ignore stderr output for cmptest
- Add test data
Change-Id: I2b29c7822fbeedf2b22c90889739ed7ff859ce92
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Diffstat (limited to 'src/testlib')
-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); } |