X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fqmltest%2Fquicktestresult.cpp;h=ff2cf05102b8e98be38d87c14b2708b868e9668c;hb=feb996e3ab44e68082c97102556ea396f5df3f44;hp=59fea965e823bbe407ee93f98c501c236f149185;hpb=3f5a0e123f662e39a10d598a8d7de12c7ff17f69;p=profile%2Fivi%2Fqtdeclarative.git diff --git a/src/qmltest/quicktestresult.cpp b/src/qmltest/quicktestresult.cpp index 59fea96..ff2cf05 100644 --- a/src/qmltest/quicktestresult.cpp +++ b/src/qmltest/quicktestresult.cpp @@ -1,34 +1,34 @@ /**************************************************************************** ** -** 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_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** ** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception +** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. ** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. ** ** ** @@ -53,6 +53,9 @@ #include #include #include +#include +#include +#include QT_BEGIN_NAMESPACE @@ -60,6 +63,57 @@ static const char *globalProgramName = 0; 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().red(); + } + + int green(int x, int y) const + { + return pixel(x, y).value().green(); + } + + int blue(int x, int y) const + { + return pixel(x, y).value().blue(); + } + + int alpha(int x, int y) const + { + return pixel(x, y).value().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(m_image.constScanLine(y)); + pixel += x; + return QColor::fromRgba(*pixel); + } +private: + QImage m_image; +}; + class QuickTestResultPrivate { public: @@ -78,7 +132,6 @@ public: } QByteArray intern(const QString &str); - void updateTestObjectName(); QString testCaseName; QString functionName; @@ -96,25 +149,6 @@ QByteArray QuickTestResultPrivate::intern(const QString &str) return *(internedStrings.insert(bstr)); } -void QuickTestResultPrivate::updateTestObjectName() -{ - // In plain logging mode we use the TestCase name as the - // class name so that multiple TestCase elements will report - // results with "testCase::function". In XML logging mode, - // we use the program name as the class name and report test - // functions as "testCase__function". - if (QTestLog::logMode() == QTestLog::Plain) { - if (testCaseName.isEmpty()) { - QTestResult::setCurrentTestObject(globalProgramName); - } else if (QTestLog::logMode() == QTestLog::Plain) { - QTestResult::setCurrentTestObject - (intern(testCaseName).constData()); - } - } else { - QTestResult::setCurrentTestObject(globalProgramName); - } -} - QuickTestResult::QuickTestResult(QObject *parent) : QObject(parent), d_ptr(new QuickTestResultPrivate) { @@ -144,7 +178,6 @@ void QuickTestResult::setTestCaseName(const QString &name) { Q_D(QuickTestResult); d->testCaseName = name; - d->updateTestObjectName(); emit testCaseNameChanged(); } @@ -167,15 +200,11 @@ void QuickTestResult::setFunctionName(const QString &name) { Q_D(QuickTestResult); if (!name.isEmpty()) { - // In plain logging mode, we use the function name directly. - // In XML logging mode, we use "testCase__functionName" as the - // program name is acting as the class name. - if (QTestLog::logMode() == QTestLog::Plain || - d->testCaseName.isEmpty()) { + if (d->testCaseName.isEmpty()) { QTestResult::setCurrentTestFunction (d->intern(name).constData()); } else { - QString fullName = d->testCaseName + QLatin1String("__") + name; + QString fullName = d->testCaseName + QLatin1String("::") + name; QTestResult::setCurrentTestFunction (d->intern(fullName).constData()); } @@ -186,17 +215,6 @@ void QuickTestResult::setFunctionName(const QString &name) 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 @@ -226,28 +244,15 @@ void QuickTestResult::setDataTag(const QString &tag) /*! \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(); } @@ -279,7 +284,7 @@ void QuickTestResult::setSkipped(bool skip) */ int QuickTestResult::passCount() const { - return QTestResult::passCount(); + return QTestLog::passCount(); } /*! @@ -291,7 +296,7 @@ int QuickTestResult::passCount() const */ int QuickTestResult::failCount() const { - return QTestResult::failCount(); + return QTestLog::failCount(); } /*! @@ -303,7 +308,7 @@ int QuickTestResult::failCount() const */ int QuickTestResult::skipCount() const { - return QTestResult::skipCount(); + return QTestLog::skipCount(); } /*! @@ -339,18 +344,9 @@ void QuickTestResult::startLogging() { // 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; - const char *saved = QTestResult::currentTestObjectName(); - if (globalProgramName) { - QTestResult::setCurrentTestObject(globalProgramName); - } else { - QTestResult::setCurrentTestObject - (d->intern(d->testCaseName).constData()); - } QTestLog::startLogging(); - QTestResult::setCurrentTestObject(saved); loggingStarted = true; } @@ -366,10 +362,8 @@ void QuickTestResult::stopLogging() Q_D(QuickTestResult); if (globalProgramName) return; // Logging will be stopped by setProgramName(0). - const char *saved = QTestResult::currentTestObjectName(); QTestResult::setCurrentTestObject(d->intern(d->testCaseName).constData()); QTestLog::stopLogging(); - QTestResult::setCurrentTestObject(saved); } void QuickTestResult::initTestTable() @@ -377,6 +371,9 @@ void QuickTestResult::initTestTable() 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(), "qmltest_dummy_data_column"); } void QuickTestResult::clearTestTable() @@ -386,100 +383,96 @@ 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) -{ - 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); - } -} - -void QuickTestResult::skipSingle - (const QString &message, const QString &file, int line) + const QUrl &location, int line) { - QTestResult::addSkip(message.toLatin1().constData(), QTest::SkipSingle, - 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::skipAll - (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::SkipAll, - qtest_fixFile(file).toLatin1().constData(), line); + QTestResult::addSkip(message.toLatin1().constData(), + 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()); + 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) @@ -593,6 +586,17 @@ void QuickTestResult::stopBenchmark() 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); }; @@ -614,6 +618,12 @@ void QuickTestResult::setProgramName(const char *name) QTestResult::setCurrentTestObject(0); } globalProgramName = name; + QTestResult::setCurrentTestObject(globalProgramName); +} + +void QuickTestResult::setCurrentAppname(const char *appname) +{ + QTestResult::setCurrentAppname(appname); } int QuickTestResult::exitCode() @@ -623,8 +633,10 @@ int QuickTestResult::exitCode() #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