#include <QtCore/qdebug.h>
#include <QtCore/QUrl>
#include <QtCore/QDir>
+#include <QtQuick/qquickwindow.h>
QT_BEGIN_NAMESPACE
static bool loggingStarted = false;
static QBenchmarkGlobalData globalBenchmarkData;
+class Q_QUICK_TEST_EXPORT QuickTestImageObject : public QObject
+{
+ Q_OBJECT
+public:
+ QuickTestImageObject(const QImage& img, QObject *parent = 0)
+ : QObject(parent)
+ , m_image(img)
+ {
+ }
+
+ ~QuickTestImageObject() {}
+
+public Q_SLOTS:
+ int red(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().red();
+ }
+
+ int green(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().green();
+ }
+
+ int blue(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().blue();
+ }
+
+ int alpha(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().alpha();
+ }
+
+ QVariant pixel(int x, int y) const
+ {
+ if (m_image.isNull()
+ || x >= m_image.width()
+ || y >= m_image.height()
+ || x < 0
+ || y < 0
+ || x * y >= m_image.width() * m_image.height())
+ return QVariant();
+
+ const QRgb* pixel = reinterpret_cast<const QRgb*>(m_image.constScanLine(y));
+ pixel += x;
+ return QColor::fromRgba(*pixel);
+ }
+private:
+ QImage m_image;
+};
+
class QuickTestResultPrivate
{
public:
emit functionNameChanged();
}
-QuickTestResult::FunctionType QuickTestResult::functionType() const
-{
- return FunctionType(QTestResult::currentTestLocation());
-}
-
-void QuickTestResult::setFunctionType(FunctionType type)
-{
- QTestResult::setCurrentTestLocation(QTestResult::TestLocation(type));
- emit functionTypeChanged();
-}
-
/*!
\qmlproperty string TestResult::dataTag
/*!
\qmlproperty bool TestResult::failed
- This property returns true if the current test function has
- failed; false otherwise. The fail state is reset when
- functionName is changed or finishTestFunction() is called.
+ This property returns true if the current test function (or
+ current test data row for a data-driven test) has failed;
+ false otherwise. The fail state is reset when functionName
+ is changed or finishTestDataCleanup() is called.
- \sa skipped, dataFailed
+ \sa skipped
*/
bool QuickTestResult::isFailed() const
{
- return QTestResult::testFailed();
-}
-
-/*!
- \qmlproperty bool TestResult::dataFailed
-
- This property returns true if the current data function has
- failed; false otherwise. The fail state is reset when
- functionName is changed or finishTestFunction() is called.
-
- \sa failed
-*/
-bool QuickTestResult::isDataFailed() const
-{
return QTestResult::currentTestFailed();
}
d->table = 0;
}
+void QuickTestResult::finishTestData()
+{
+ QTestResult::finishedCurrentTestData();
+}
+
+void QuickTestResult::finishTestDataCleanup()
+{
+ QTestResult::finishedCurrentTestDataCleanup();
+}
+
void QuickTestResult::finishTestFunction()
{
QTestResult::finishedCurrentTestFunction();
const QString &val1, const QString &val2,
const QUrl &location, int line)
{
- if (success) {
- return QTestResult::compare
- (success, message.toLocal8Bit().constData(),
- qtestFixUrl(location).toLatin1().constData(), line);
- } else {
- return QTestResult::compare
- (success, message.toLocal8Bit().constData(),
- QTest::toString(val1.toLatin1().constData()),
- QTest::toString(val2.toLatin1().constData()),
- "", "",
- qtestFixUrl(location).toLatin1().constData(), line);
- }
+ return QTestResult::compare
+ (success, message.toLocal8Bit().constData(),
+ QTest::toString(val1.toLatin1().constData()),
+ QTest::toString(val2.toLatin1().constData()),
+ "", "",
+ qtestFixUrl(location).toLatin1().constData(), line);
}
void QuickTestResult::skip
d->benchmarkIter = 0;
}
+QObject *QuickTestResult::grabImage(QQuickItem *item)
+{
+ if (item) {
+ QQuickWindow *window = item->window();
+ QImage grabbed = window->grabWindow();
+ QRectF rf(item->x(), item->y(), item->width(), item->height());
+ rf = rf.intersected(QRectF(0, 0, grabbed.width(), grabbed.height()));
+ return new QuickTestImageObject(grabbed.copy(rf.toAlignedRect()));
+ }
+ return 0;
+}
namespace QTest {
void qtest_qParseArgs(int argc, char *argv[], bool qml);
};
QTestResult::setCurrentTestObject(globalProgramName);
}
+void QuickTestResult::setCurrentAppname(const char *appname)
+{
+ QTestResult::setCurrentAppname(appname);
+}
+
int QuickTestResult::exitCode()
{
#if defined(QTEST_NOEXITCODE)
#endif
}
+#include "quicktestresult.moc"
+
QT_END_NAMESPACE