/****************************************************************************
**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the test suite of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtCore/qbytearray.h>
#include <QtCore/qcoreapplication.h>
#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();
}
*/
int QuickTestResult::passCount() const
{
- return QTestResult::passCount();
+ return QTestLog::passCount();
}
/*!
*/
int QuickTestResult::failCount() const
{
- return QTestResult::failCount();
+ return QTestLog::failCount();
}
/*!
*/
int QuickTestResult::skipCount() const
{
- return QTestResult::skipCount();
+ return QTestLog::skipCount();
}
/*!
{
// The program name is used for logging headers and footers if it
// is set. Otherwise the test case name is used.
- Q_D(QuickTestResult);
if (loggingStarted)
return;
QTestLog::startLogging();
Q_D(QuickTestResult);
delete d->table;
d->table = new QTestTable;
+ //qmltest does not really need the column for data driven test
+ //add this to avoid warnings.
+ d->table->addColumn(qMetaTypeId<QString>(), "qmltest_dummy_data_column");
}
void QuickTestResult::clearTestTable()
d->table = 0;
}
+void QuickTestResult::finishTestData()
+{
+ QTestResult::finishedCurrentTestData();
+}
+
+void QuickTestResult::finishTestDataCleanup()
+{
+ QTestResult::finishedCurrentTestDataCleanup();
+}
+
void QuickTestResult::finishTestFunction()
{
QTestResult::finishedCurrentTestFunction();
}
-static QString qtest_fixFile(const QString &file)
+static QString qtestFixUrl(const QUrl &location)
{
- if (file.startsWith(QLatin1String("file://")))
- return file.mid(7);
- else
- return file;
+ if (location.isLocalFile()) // Use QUrl's logic for Windows drive letters.
+ return QDir::toNativeSeparators(location.toLocalFile());
+ return location.toString();
}
void QuickTestResult::fail
- (const QString &message, const QString &file, int line)
+ (const QString &message, const QUrl &location, int line)
{
QTestResult::addFailure(message.toLatin1().constData(),
- qtest_fixFile(file).toLatin1().constData(), line);
+ qtestFixUrl(location).toLatin1().constData(), line);
}
bool QuickTestResult::verify
- (bool success, const QString &message, const QString &file, int line)
+ (bool success, const QString &message, const QUrl &location, int line)
{
if (!success && message.isEmpty()) {
return QTestResult::verify
(success, "verify()", "",
- qtest_fixFile(file).toLatin1().constData(), line);
+ qtestFixUrl(location).toLatin1().constData(), line);
} else {
return QTestResult::verify
(success, message.toLatin1().constData(), "",
- qtest_fixFile(file).toLatin1().constData(), line);
+ qtestFixUrl(location).toLatin1().constData(), line);
}
}
bool QuickTestResult::compare
(bool success, const QString &message,
const QString &val1, const QString &val2,
- const QString &file, int line)
+ const QUrl &location, int line)
{
- if (success) {
- return QTestResult::compare
- (success, message.toLocal8Bit().constData(),
- qtest_fixFile(file).toLatin1().constData(), line);
- } else {
- return QTestResult::compare
- (success, message.toLocal8Bit().constData(),
- QTest::toString(val1.toLatin1().constData()),
- QTest::toString(val2.toLatin1().constData()),
- "", "",
- qtest_fixFile(file).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::skipSingle
- (const QString &message, const QString &file, int line)
+void QuickTestResult::skip
+ (const QString &message, const QUrl &location, int line)
{
QTestResult::addSkip(message.toLatin1().constData(),
- qtest_fixFile(file).toLatin1().constData(), line);
-}
-
-void QuickTestResult::skipAll
- (const QString &message, const QString &file, int line)
-{
- QTestResult::addSkip(message.toLatin1().constData(),
- qtest_fixFile(file).toLatin1().constData(), line);
+ qtestFixUrl(location).toLatin1().constData(), line);
QTestResult::setSkipCurrentTest(true);
}
bool QuickTestResult::expectFail
- (const QString &tag, const QString &comment, const QString &file, int line)
+ (const QString &tag, const QString &comment, const QUrl &location, int line)
{
return QTestResult::expectFail
(tag.toLatin1().constData(),
QTest::toString(comment.toLatin1().constData()),
- QTest::Abort, qtest_fixFile(file).toLatin1().constData(), line);
+ QTest::Abort, qtestFixUrl(location).toLatin1().constData(), line);
}
bool QuickTestResult::expectFailContinue
- (const QString &tag, const QString &comment, const QString &file, int line)
+ (const QString &tag, const QString &comment, const QUrl &location, int line)
{
return QTestResult::expectFail
(tag.toLatin1().constData(),
QTest::toString(comment.toLatin1().constData()),
- QTest::Continue, qtest_fixFile(file).toLatin1().constData(), line);
+ QTest::Continue, qtestFixUrl(location).toLatin1().constData(), line);
}
-void QuickTestResult::warn(const QString &message)
+void QuickTestResult::warn(const QString &message, const QUrl &location, int line)
{
- QTestLog::warn(message.toLatin1().constData(), 0, 0);
+ QTestLog::warn(message.toLatin1().constData(), qtestFixUrl(location).toLatin1().constData(), line);
}
void QuickTestResult::ignoreWarning(const QString &message)
{
- QTestResult::ignoreMessage(QtWarningMsg, message.toLatin1().constData());
+ QTestLog::ignoreMessage(QtWarningMsg, message.toLatin1().constData());
}
void QuickTestResult::wait(int ms)
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)
#else
// make sure our exit code is never going above 127
// since that could wrap and indicate 0 test fails
- return qMin(QTestResult::failCount(), 127);
+ return qMin(QTestLog::failCount(), 127);
#endif
}
+#include "quicktestresult.moc"
+
QT_END_NAMESPACE