From 2b3d1477069b73f592f206b2ee8f2293c317f87e Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 9 Dec 2010 10:34:28 +1000 Subject: QDeclarative -> QuickTest for the test classes --- src/imports/testlib/main.cpp | 6 +- src/quicktestlib/qdeclarativetest.cpp | 192 ----------- src/quicktestlib/qdeclarativetest.h | 97 ------ src/quicktestlib/qdeclarativetestresult.cpp | 485 ---------------------------- src/quicktestlib/qdeclarativetestresult_p.h | 157 --------- src/quicktestlib/quicktest.cpp | 192 +++++++++++ src/quicktestlib/quicktest.h | 97 ++++++ src/quicktestlib/quicktestlib.pro | 8 +- src/quicktestlib/quicktestresult.cpp | 485 ++++++++++++++++++++++++++++ src/quicktestlib/quicktestresult_p.h | 157 +++++++++ tests/qmlauto/tst_qmlauto.cpp | 2 +- tests/qmlexample/tst_qmlexample.cpp | 2 +- 12 files changed, 940 insertions(+), 940 deletions(-) delete mode 100644 src/quicktestlib/qdeclarativetest.cpp delete mode 100644 src/quicktestlib/qdeclarativetest.h delete mode 100644 src/quicktestlib/qdeclarativetestresult.cpp delete mode 100644 src/quicktestlib/qdeclarativetestresult_p.h create mode 100644 src/quicktestlib/quicktest.cpp create mode 100644 src/quicktestlib/quicktest.h create mode 100644 src/quicktestlib/quicktestresult.cpp create mode 100644 src/quicktestlib/quicktestresult_p.h diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp index d04bccf..c91decd 100644 --- a/src/imports/testlib/main.cpp +++ b/src/imports/testlib/main.cpp @@ -45,11 +45,11 @@ #include #include #include -#include "qdeclarativetestresult_p.h" +#include "quicktestresult_p.h" QT_BEGIN_NAMESPACE -QML_DECLARE_TYPE(QDeclarativeTestResult) +QML_DECLARE_TYPE(QuickTestResult) // Copied from qdeclarativedebughelper_p.h in Qt, to avoid a dependency // on a private header from Qt. @@ -104,7 +104,7 @@ public: virtual void registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuickTest")); - qmlRegisterType(uri,1,0,"TestResult"); + qmlRegisterType(uri,1,0,"TestResult"); } void initializeEngine(QDeclarativeEngine *engine, const char *) { diff --git a/src/quicktestlib/qdeclarativetest.cpp b/src/quicktestlib/qdeclarativetest.cpp deleted file mode 100644 index ed0f12e..0000000 --- a/src/quicktestlib/qdeclarativetest.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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. -** -** In addition, as a special exception, Nokia gives you certain additional -** 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. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativetest.h" -#include "qdeclarativetestresult_p.h" -#include "qtestsystem.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -// Copied from qdeclarativedebughelper_p.h in Qt, to avoid a dependency -// on a private header from Qt. -class Q_DECLARATIVE_EXPORT QDeclarativeDebugHelper -{ -public: - static QScriptEngine *getScriptEngine(QDeclarativeEngine *engine); - static void setAnimationSlowDownFactor(qreal factor); - static void enableDebugging(); -}; - -class QTestRootObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool windowShown READ windowShown NOTIFY windowShownChanged) -public: - QTestRootObject(QObject *parent = 0) - : QObject(parent), hasQuit(false), m_windowShown(false) {} - - bool hasQuit; - - bool windowShown() const { return m_windowShown; } - void setWindowShown(bool value) { m_windowShown = value; emit windowShownChanged(); } - -Q_SIGNALS: - void windowShownChanged(); - -private Q_SLOTS: - void quit() { hasQuit = true; } - -private: - bool m_windowShown; -}; - -int qtest_quick_main(int argc, char **argv, const char *name, qtest_create_viewport createViewport, const char *sourceDir) -{ - QApplication app(argc, argv); - - // Determine where to look for the test data. If QTEST_QUICK_SOURCE_DIR - // is set, then use that. Otherwise scan the application's resources. - QString testPath = QString::fromLocal8Bit(qgetenv("QTEST_QUICK_SOURCE_DIR")); - if (testPath.isEmpty() && sourceDir) - testPath = QString::fromLocal8Bit(sourceDir); - if (testPath.isEmpty()) - testPath = QLatin1String(":/"); - - // Scan the test data directory recursively, looking for "tst_*.qml" files. - QStringList filters; - filters += QLatin1String("tst_*.qml"); - QStringList files; - QDirIterator iter(testPath, filters, QDir::Files, - QDirIterator::Subdirectories | - QDirIterator::FollowSymlinks); - while (iter.hasNext()) - files += iter.next(); - files.sort(); - - // Bail out if we didn't find any test cases. - if (files.isEmpty()) { - qWarning() << argv[0] << ": could not find any test cases under" - << testPath; - return 1; - } - - // Parse the command-line arguments. - QDeclarativeTestResult::parseArgs(argc, argv); - QDeclarativeTestResult::setProgramName(name); - - // Scan through all of the "tst_*.qml" files and run each of them - // in turn with a QDeclarativeView. - bool compileFail = false; - foreach (QString file, files) { - QFileInfo fi(file); - if (!fi.exists()) - continue; - QDeclarativeView view; - QTestRootObject rootobj; - QEventLoop eventLoop; - QObject::connect(view.engine(), SIGNAL(quit()), - &rootobj, SLOT(quit())); - QObject::connect(view.engine(), SIGNAL(quit()), - &eventLoop, SLOT(quit())); - if (createViewport) - view.setViewport((*createViewport)()); - view.rootContext()->setContextProperty - (QLatin1String("qtest"), &rootobj); - QScriptEngine *engine; - engine = QDeclarativeDebugHelper::getScriptEngine(view.engine()); - QScriptValue qtObject - = engine->globalObject().property(QLatin1String("Qt")); - qtObject.setProperty - (QLatin1String("qtest_wrapper"), engine->newVariant(true)); - QString path = fi.absoluteFilePath(); - if (path.startsWith(QLatin1String(":/"))) - view.setSource(QUrl(QLatin1String("qrc:") + path.mid(2))); - else - view.setSource(QUrl::fromLocalFile(path)); - if (view.status() == QDeclarativeView::Error) { - // Error compiling the test - flag failure and continue. - compileFail = true; - continue; - } - if (!rootobj.hasQuit) { - // If the test already quit, then it was performed - // synchronously during setSource(). Otherwise it is - // an asynchronous test and we need to show the window - // and wait for the quit indication. - view.show(); - QTest::qWaitForWindowShown(&view); - rootobj.setWindowShown(true); - if (!rootobj.hasQuit) - eventLoop.exec(); - } - } - - // Flush the current logging stream. - QDeclarativeTestResult::setProgramName(0); - - // Return the number of failures as the exit code. - int code = QDeclarativeTestResult::exitCode(); - if (!code && compileFail) - ++code; - return code; -} - -QT_END_NAMESPACE - -#include "qdeclarativetest.moc" diff --git a/src/quicktestlib/qdeclarativetest.h b/src/quicktestlib/qdeclarativetest.h deleted file mode 100644 index f89868d..0000000 --- a/src/quicktestlib/qdeclarativetest.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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. -** -** In addition, as a special exception, Nokia gives you certain additional -** 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. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVETEST_H -#define QDECLARATIVETEST_H - -#include "quicktestglobal.h" -#include -#ifdef QT_OPENGL_LIB -#include -#endif - -QT_BEGIN_NAMESPACE - -typedef QWidget *(*qtest_create_viewport)(); - -Q_QUICK_TEST_EXPORT int qtest_quick_main(int argc, char **argv, const char *name, qtest_create_viewport createViewport, const char *sourceDir); - -#ifdef QTEST_QUICK_SOURCE_DIR - -#define QTEST_QUICK_MAIN(name) \ - int main(int argc, char **argv) \ - { \ - return qtest_quick_main(argc, argv, #name, 0, QTEST_QUICK_SOURCE_DIR); \ - } - -#define QTEST_QUICK_OPENGL_MAIN(name) \ - static QWidget *name##_create_viewport() \ - { \ - return new QGLWidget(); \ - } \ - int main(int argc, char **argv) \ - { \ - return qtest_quick_main(argc, argv, #name, name##_create_viewport, QTEST_QUICK_SOURCE_DIR); \ - } - -#else - -#define QTEST_QUICK_MAIN(name) \ - int main(int argc, char **argv) \ - { \ - return qtest_quick_main(argc, argv, #name, 0, 0); \ - } - -#define QTEST_QUICK_OPENGL_MAIN(name) \ - static QWidget *name##_create_viewport() \ - { \ - return new QGLWidget(); \ - } \ - int main(int argc, char **argv) \ - { \ - return qtest_quick_main(argc, argv, #name, name##_create_viewport, 0); \ - } - -#endif - -QT_END_NAMESPACE - -#endif diff --git a/src/quicktestlib/qdeclarativetestresult.cpp b/src/quicktestlib/qdeclarativetestresult.cpp deleted file mode 100644 index e5e8a70..0000000 --- a/src/quicktestlib/qdeclarativetestresult.cpp +++ /dev/null @@ -1,485 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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. -** -** In addition, as a special exception, Nokia gives you certain additional -** 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. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativetestresult_p.h" -#include "qtestcase.h" -#include "qtestsystem.h" -#include "qtestresult_p.h" -#include "qtesttable_p.h" -#include "qtestlog_p.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const char *globalProgramName = 0; -static bool loggingStarted = false; - -class QDeclarativeTestResultPrivate -{ -public: - QDeclarativeTestResultPrivate() - : table(0) - { - } - ~QDeclarativeTestResultPrivate() - { - delete table; - } - - QByteArray intern(const QString &str); - void updateTestObjectName(); - - QString testCaseName; - QString functionName; - QSet internedStrings; - QTestTable *table; -}; - -QByteArray QDeclarativeTestResultPrivate::intern(const QString &str) -{ - QByteArray bstr = str.toUtf8(); - return *(internedStrings.insert(bstr)); -} - -void QDeclarativeTestResultPrivate::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); - } -} - -QDeclarativeTestResult::QDeclarativeTestResult(QObject *parent) - : QObject(parent), d_ptr(new QDeclarativeTestResultPrivate) -{ -} - -QDeclarativeTestResult::~QDeclarativeTestResult() -{ -} - -/*! - \qmlproperty string TestResult::testCaseName - - This property defines the name of current TestCase element - that is running test cases. - - \sa functionName -*/ -QString QDeclarativeTestResult::testCaseName() const -{ - Q_D(const QDeclarativeTestResult); - return d->testCaseName; -} - -void QDeclarativeTestResult::setTestCaseName(const QString &name) -{ - Q_D(QDeclarativeTestResult); - d->testCaseName = name; - d->updateTestObjectName(); - emit testCaseNameChanged(); -} - -/*! - \qmlproperty string TestResult::functionName - - This property defines the name of current test function - within a TestCase element that is running. If this string is - empty, then no function is currently running. - - \sa testCaseName -*/ -QString QDeclarativeTestResult::functionName() const -{ - Q_D(const QDeclarativeTestResult); - return d->functionName; -} - -void QDeclarativeTestResult::setFunctionName(const QString &name) -{ - Q_D(QDeclarativeTestResult); - 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()) { - QTestResult::setCurrentTestFunction - (d->intern(name).constData()); - } else { - QString fullName = d->testCaseName + QLatin1String("__") + name; - QTestResult::setCurrentTestFunction - (d->intern(fullName).constData()); - } - } else { - QTestResult::setCurrentTestFunction(0); - } - emit functionNameChanged(); -} - -QDeclarativeTestResult::FunctionType QDeclarativeTestResult::functionType() const -{ - return FunctionType(QTestResult::currentTestLocation()); -} - -void QDeclarativeTestResult::setFunctionType(FunctionType type) -{ - QTestResult::setCurrentTestLocation(QTestResult::TestLocation(type)); - emit functionTypeChanged(); -} - -/*! - \qmlproperty string TestResult::dataTag - - This property defines the tag for the current row in a - data-driven test, or an empty string if not a data-driven test. -*/ -QString QDeclarativeTestResult::dataTag() const -{ - const char *tag = QTestResult::currentDataTag(); - if (tag) - return QString::fromUtf8(tag); - else - return QString(); -} - -void QDeclarativeTestResult::setDataTag(const QString &tag) -{ - if (!tag.isEmpty()) { - QTestData *data = &(QTest::newRow(tag.toUtf8().constData())); - QTestResult::setCurrentTestData(data); - emit dataTagChanged(); - } else { - QTestResult::setCurrentTestData(0); - } -} - -/*! - \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. - - \sa skipped, dataFailed -*/ -bool QDeclarativeTestResult::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 QDeclarativeTestResult::isDataFailed() const -{ - return QTestResult::currentTestFailed(); -} - -/*! - \qmlproperty bool TestResult::skipped - - This property returns true if the current test function was - marked as skipped; false otherwise. - - \sa failed -*/ -bool QDeclarativeTestResult::isSkipped() const -{ - return QTestResult::skipCurrentTest(); -} - -void QDeclarativeTestResult::setSkipped(bool skip) -{ - QTestResult::setSkipCurrentTest(skip); - emit skippedChanged(); -} - -/*! - \qmlproperty int TestResult::passCount - - This property returns the number of tests that have passed. - - \sa failCount, skipCount -*/ -int QDeclarativeTestResult::passCount() const -{ - return QTestResult::passCount(); -} - -/*! - \qmlproperty int TestResult::failCount - - This property returns the number of tests that have failed. - - \sa passCount, skipCount -*/ -int QDeclarativeTestResult::failCount() const -{ - return QTestResult::failCount(); -} - -/*! - \qmlproperty int TestResult::skipCount - - This property returns the number of tests that have been skipped. - - \sa passCount, failCount -*/ -int QDeclarativeTestResult::skipCount() const -{ - return QTestResult::skipCount(); -} - -/*! - \qmlmethod TestResult::reset() - - Resets all pass/fail/skip counters and prepare for testing. -*/ -void QDeclarativeTestResult::reset() -{ - if (!globalProgramName) // Only if run via qmlviewer. - QTestResult::reset(); -} - -/*! - \qmlmethod TestResult::startLogging() - - Starts logging to the test output stream and writes the - test header. - - \sa stopLogging() -*/ -void QDeclarativeTestResult::startLogging() -{ - // The program name is used for logging headers and footers if it - // is set. Otherwise the test case name is used. - Q_D(QDeclarativeTestResult); - 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; -} - -/*! - \qmlmethod TestResult::stopLogging() - - Writes the test footer to the test output stream and then stops logging. - - \sa startLogging() -*/ -void QDeclarativeTestResult::stopLogging() -{ - Q_D(QDeclarativeTestResult); - 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 QDeclarativeTestResult::initTestTable() -{ - Q_D(QDeclarativeTestResult); - delete d->table; - d->table = new QTestTable; -} - -void QDeclarativeTestResult::clearTestTable() -{ - Q_D(QDeclarativeTestResult); - delete d->table; - d->table = 0; -} - -void QDeclarativeTestResult::finishTestFunction() -{ - QTestResult::finishedCurrentTestFunction(); -} - -void QDeclarativeTestResult::fail - (const QString &message, const QString &file, int line) -{ - QTestResult::addFailure(message.toLatin1().constData(), - file.toLatin1().constData(), line); -} - -bool QDeclarativeTestResult::verify - (bool success, const QString &message, const QString &file, int line) -{ - if (message.isEmpty()) { - return QTestResult::verify - (success, "verify()", "", file.toLatin1().constData(), line); - } else { - return QTestResult::verify - (success, message.toLatin1().constData(), "", - file.toLatin1().constData(), line); - } -} - -bool QDeclarativeTestResult::compare - (bool success, const QString &message, - const QString &val1, const QString &val2, - const QString &file, int line) -{ - return QTestResult::compare - (success, message.toLocal8Bit().constData(), - QTest::toString(val1.toLatin1().constData()), - QTest::toString(val2.toLatin1().constData()), - "", "", - file.toLatin1().constData(), line); -} - -void QDeclarativeTestResult::skipSingle - (const QString &message, const QString &file, int line) -{ - QTestResult::addSkip(message.toLatin1().constData(), - QTest::SkipSingle, file.toLatin1().constData(), line); -} - -void QDeclarativeTestResult::skipAll - (const QString &message, const QString &file, int line) -{ - QTestResult::addSkip(message.toLatin1().constData(), - QTest::SkipAll, file.toLatin1().constData(), line); - QTestResult::setSkipCurrentTest(true); -} - -bool QDeclarativeTestResult::expectFail - (const QString &tag, const QString &comment, const QString &file, int line) -{ - return QTestResult::expectFail - (tag.toLatin1().constData(), - QTest::toString(comment.toLatin1().constData()), - QTest::Abort, file.toLatin1().constData(), line); -} - -bool QDeclarativeTestResult::expectFailContinue - (const QString &tag, const QString &comment, const QString &file, int line) -{ - return QTestResult::expectFail - (tag.toLatin1().constData(), - QTest::toString(comment.toLatin1().constData()), - QTest::Continue, file.toLatin1().constData(), line); -} - -void QDeclarativeTestResult::warn(const QString &message) -{ - QTestLog::warn(message.toLatin1().constData()); -} - -void QDeclarativeTestResult::ignoreWarning(const QString &message) -{ - QTestResult::ignoreMessage(QtWarningMsg, message.toLatin1().constData()); -} - -void QDeclarativeTestResult::wait(int ms) -{ - QTest::qWait(ms); -} - -void QDeclarativeTestResult::sleep(int ms) -{ - QTest::qSleep(ms); -} - -namespace QTest { - void qtest_qParseArgs(int argc, char *argv[]); -}; - -void QDeclarativeTestResult::parseArgs(int argc, char *argv[]) -{ - QTest::qtest_qParseArgs(argc, argv); -} - -void QDeclarativeTestResult::setProgramName(const char *name) -{ - if (name) { - QTestResult::reset(); - } else if (!name && loggingStarted) { - QTestResult::setCurrentTestObject(globalProgramName); - QTestLog::stopLogging(); - QTestResult::setCurrentTestObject(0); - } - globalProgramName = name; -} - -int QDeclarativeTestResult::exitCode() -{ -#if defined(QTEST_NOEXITCODE) - return 0; -#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); -#endif -} - -QT_END_NAMESPACE diff --git a/src/quicktestlib/qdeclarativetestresult_p.h b/src/quicktestlib/qdeclarativetestresult_p.h deleted file mode 100644 index 776a77a..0000000 --- a/src/quicktestlib/qdeclarativetestresult_p.h +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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. -** -** In addition, as a special exception, Nokia gives you certain additional -** 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. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVETESTRESULT_P_H -#define QDECLARATIVETESTRESULT_P_H - -#include "quicktestglobal.h" -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeTestResultPrivate; - -class Q_QUICK_TEST_EXPORT QDeclarativeTestResult : public QObject -{ - Q_OBJECT - Q_ENUMS(FunctionType) - Q_PROPERTY(QString testCaseName READ testCaseName WRITE setTestCaseName NOTIFY testCaseNameChanged) - Q_PROPERTY(QString functionName READ functionName WRITE setFunctionName NOTIFY functionNameChanged) - Q_PROPERTY(FunctionType functionType READ functionType WRITE setFunctionType NOTIFY functionTypeChanged) - Q_PROPERTY(QString dataTag READ dataTag WRITE setDataTag NOTIFY dataTagChanged) - Q_PROPERTY(bool failed READ isFailed) - Q_PROPERTY(bool dataFailed READ isDataFailed) - Q_PROPERTY(bool skipped READ isSkipped WRITE setSkipped NOTIFY skippedChanged) - Q_PROPERTY(int passCount READ passCount) - Q_PROPERTY(int failCount READ failCount) - Q_PROPERTY(int skipCount READ skipCount) -public: - QDeclarativeTestResult(QObject *parent = 0); - ~QDeclarativeTestResult(); - - // Values must match QTestResult::TestLocation. - enum FunctionType - { - NoWhere = 0, - DataFunc = 1, - InitFunc = 2, - Func = 3, - CleanupFunc = 4 - }; - - QString testCaseName() const; - void setTestCaseName(const QString &name); - - QString functionName() const; - void setFunctionName(const QString &name); - - FunctionType functionType() const; - void setFunctionType(FunctionType type); - - QString dataTag() const; - void setDataTag(const QString &tag); - - bool isFailed() const; - bool isDataFailed() const; - - bool isSkipped() const; - void setSkipped(bool skip); - - int passCount() const; - int failCount() const; - int skipCount() const; - -public Q_SLOTS: - void reset(); - - void startLogging(); - void stopLogging(); - - void initTestTable(); - void clearTestTable(); - - void finishTestFunction(); - - void fail(const QString &message, const QString &file, int line); - bool verify(bool success, const QString &message, - const QString &file, int line); - bool compare(bool success, const QString &message, - const QString &val1, const QString &val2, - const QString &file, int line); - void skipSingle(const QString &message, const QString &file, int line); - void skipAll(const QString &message, const QString &file, int line); - bool expectFail(const QString &tag, const QString &comment, - const QString &file, int line); - bool expectFailContinue(const QString &tag, const QString &comment, - const QString &file, int line); - void warn(const QString &message); - - void ignoreWarning(const QString &message); - - void wait(int ms); - void sleep(int ms); - -public: - // Helper functions for the C++ main() shell. - static void parseArgs(int argc, char *argv[]); - static void setProgramName(const char *name); - static int exitCode(); - -Q_SIGNALS: - void programNameChanged(); - void testCaseNameChanged(); - void functionNameChanged(); - void functionTypeChanged(); - void dataTagChanged(); - void skippedChanged(); - -private: - QScopedPointer d_ptr; - - Q_DECLARE_PRIVATE(QDeclarativeTestResult) - Q_DISABLE_COPY(QDeclarativeTestResult) -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/quicktestlib/quicktest.cpp b/src/quicktestlib/quicktest.cpp new file mode 100644 index 0000000..f1afc0a --- /dev/null +++ b/src/quicktestlib/quicktest.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** 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. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quicktest.h" +#include "quicktestresult_p.h" +#include "qtestsystem.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +// Copied from qdeclarativedebughelper_p.h in Qt, to avoid a dependency +// on a private header from Qt. +class Q_DECLARATIVE_EXPORT QDeclarativeDebugHelper +{ +public: + static QScriptEngine *getScriptEngine(QDeclarativeEngine *engine); + static void setAnimationSlowDownFactor(qreal factor); + static void enableDebugging(); +}; + +class QTestRootObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool windowShown READ windowShown NOTIFY windowShownChanged) +public: + QTestRootObject(QObject *parent = 0) + : QObject(parent), hasQuit(false), m_windowShown(false) {} + + bool hasQuit; + + bool windowShown() const { return m_windowShown; } + void setWindowShown(bool value) { m_windowShown = value; emit windowShownChanged(); } + +Q_SIGNALS: + void windowShownChanged(); + +private Q_SLOTS: + void quit() { hasQuit = true; } + +private: + bool m_windowShown; +}; + +int qtest_quick_main(int argc, char **argv, const char *name, qtest_create_viewport createViewport, const char *sourceDir) +{ + QApplication app(argc, argv); + + // Determine where to look for the test data. If QTEST_QUICK_SOURCE_DIR + // is set, then use that. Otherwise scan the application's resources. + QString testPath = QString::fromLocal8Bit(qgetenv("QTEST_QUICK_SOURCE_DIR")); + if (testPath.isEmpty() && sourceDir) + testPath = QString::fromLocal8Bit(sourceDir); + if (testPath.isEmpty()) + testPath = QLatin1String(":/"); + + // Scan the test data directory recursively, looking for "tst_*.qml" files. + QStringList filters; + filters += QLatin1String("tst_*.qml"); + QStringList files; + QDirIterator iter(testPath, filters, QDir::Files, + QDirIterator::Subdirectories | + QDirIterator::FollowSymlinks); + while (iter.hasNext()) + files += iter.next(); + files.sort(); + + // Bail out if we didn't find any test cases. + if (files.isEmpty()) { + qWarning() << argv[0] << ": could not find any test cases under" + << testPath; + return 1; + } + + // Parse the command-line arguments. + QuickTestResult::parseArgs(argc, argv); + QuickTestResult::setProgramName(name); + + // Scan through all of the "tst_*.qml" files and run each of them + // in turn with a QDeclarativeView. + bool compileFail = false; + foreach (QString file, files) { + QFileInfo fi(file); + if (!fi.exists()) + continue; + QDeclarativeView view; + QTestRootObject rootobj; + QEventLoop eventLoop; + QObject::connect(view.engine(), SIGNAL(quit()), + &rootobj, SLOT(quit())); + QObject::connect(view.engine(), SIGNAL(quit()), + &eventLoop, SLOT(quit())); + if (createViewport) + view.setViewport((*createViewport)()); + view.rootContext()->setContextProperty + (QLatin1String("qtest"), &rootobj); + QScriptEngine *engine; + engine = QDeclarativeDebugHelper::getScriptEngine(view.engine()); + QScriptValue qtObject + = engine->globalObject().property(QLatin1String("Qt")); + qtObject.setProperty + (QLatin1String("qtest_wrapper"), engine->newVariant(true)); + QString path = fi.absoluteFilePath(); + if (path.startsWith(QLatin1String(":/"))) + view.setSource(QUrl(QLatin1String("qrc:") + path.mid(2))); + else + view.setSource(QUrl::fromLocalFile(path)); + if (view.status() == QDeclarativeView::Error) { + // Error compiling the test - flag failure and continue. + compileFail = true; + continue; + } + if (!rootobj.hasQuit) { + // If the test already quit, then it was performed + // synchronously during setSource(). Otherwise it is + // an asynchronous test and we need to show the window + // and wait for the quit indication. + view.show(); + QTest::qWaitForWindowShown(&view); + rootobj.setWindowShown(true); + if (!rootobj.hasQuit) + eventLoop.exec(); + } + } + + // Flush the current logging stream. + QuickTestResult::setProgramName(0); + + // Return the number of failures as the exit code. + int code = QuickTestResult::exitCode(); + if (!code && compileFail) + ++code; + return code; +} + +QT_END_NAMESPACE + +#include "quicktest.moc" diff --git a/src/quicktestlib/quicktest.h b/src/quicktestlib/quicktest.h new file mode 100644 index 0000000..4cf64be --- /dev/null +++ b/src/quicktestlib/quicktest.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** 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. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QUICKTEST_H +#define QUICKTEST_H + +#include "quicktestglobal.h" +#include +#ifdef QT_OPENGL_LIB +#include +#endif + +QT_BEGIN_NAMESPACE + +typedef QWidget *(*qtest_create_viewport)(); + +Q_QUICK_TEST_EXPORT int qtest_quick_main(int argc, char **argv, const char *name, qtest_create_viewport createViewport, const char *sourceDir); + +#ifdef QTEST_QUICK_SOURCE_DIR + +#define QTEST_QUICK_MAIN(name) \ + int main(int argc, char **argv) \ + { \ + return qtest_quick_main(argc, argv, #name, 0, QTEST_QUICK_SOURCE_DIR); \ + } + +#define QTEST_QUICK_OPENGL_MAIN(name) \ + static QWidget *name##_create_viewport() \ + { \ + return new QGLWidget(); \ + } \ + int main(int argc, char **argv) \ + { \ + return qtest_quick_main(argc, argv, #name, name##_create_viewport, QTEST_QUICK_SOURCE_DIR); \ + } + +#else + +#define QTEST_QUICK_MAIN(name) \ + int main(int argc, char **argv) \ + { \ + return qtest_quick_main(argc, argv, #name, 0, 0); \ + } + +#define QTEST_QUICK_OPENGL_MAIN(name) \ + static QWidget *name##_create_viewport() \ + { \ + return new QGLWidget(); \ + } \ + int main(int argc, char **argv) \ + { \ + return qtest_quick_main(argc, argv, #name, name##_create_viewport, 0); \ + } + +#endif + +QT_END_NAMESPACE + +#endif diff --git a/src/quicktestlib/quicktestlib.pro b/src/quicktestlib/quicktestlib.pro index 1ca306e..e319c56 100644 --- a/src/quicktestlib/quicktestlib.pro +++ b/src/quicktestlib/quicktestlib.pro @@ -25,13 +25,13 @@ symbian { } SOURCES += \ - qdeclarativetest.cpp \ - qdeclarativetestresult.cpp + quicktest.cpp \ + quicktestresult.cpp HEADERS += \ quicktestglobal.h \ - qdeclarativetest.h + quicktest.h PRIVATE_HEADERS += \ - qdeclarativetestresult_p.h + quicktestresult_p.h PUBLIC_HEADERS += $$HEADERS HEADERS += $$PRIVATE_HEADERS diff --git a/src/quicktestlib/quicktestresult.cpp b/src/quicktestlib/quicktestresult.cpp new file mode 100644 index 0000000..b54f64f --- /dev/null +++ b/src/quicktestlib/quicktestresult.cpp @@ -0,0 +1,485 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** 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. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quicktestresult_p.h" +#include "qtestcase.h" +#include "qtestsystem.h" +#include "qtestresult_p.h" +#include "qtesttable_p.h" +#include "qtestlog_p.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const char *globalProgramName = 0; +static bool loggingStarted = false; + +class QuickTestResultPrivate +{ +public: + QuickTestResultPrivate() + : table(0) + { + } + ~QuickTestResultPrivate() + { + delete table; + } + + QByteArray intern(const QString &str); + void updateTestObjectName(); + + QString testCaseName; + QString functionName; + QSet internedStrings; + QTestTable *table; +}; + +QByteArray QuickTestResultPrivate::intern(const QString &str) +{ + QByteArray bstr = str.toUtf8(); + 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) +{ +} + +QuickTestResult::~QuickTestResult() +{ +} + +/*! + \qmlproperty string TestResult::testCaseName + + This property defines the name of current TestCase element + that is running test cases. + + \sa functionName +*/ +QString QuickTestResult::testCaseName() const +{ + Q_D(const QuickTestResult); + return d->testCaseName; +} + +void QuickTestResult::setTestCaseName(const QString &name) +{ + Q_D(QuickTestResult); + d->testCaseName = name; + d->updateTestObjectName(); + emit testCaseNameChanged(); +} + +/*! + \qmlproperty string TestResult::functionName + + This property defines the name of current test function + within a TestCase element that is running. If this string is + empty, then no function is currently running. + + \sa testCaseName +*/ +QString QuickTestResult::functionName() const +{ + Q_D(const QuickTestResult); + return d->functionName; +} + +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()) { + QTestResult::setCurrentTestFunction + (d->intern(name).constData()); + } else { + QString fullName = d->testCaseName + QLatin1String("__") + name; + QTestResult::setCurrentTestFunction + (d->intern(fullName).constData()); + } + } else { + QTestResult::setCurrentTestFunction(0); + } + 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 + + This property defines the tag for the current row in a + data-driven test, or an empty string if not a data-driven test. +*/ +QString QuickTestResult::dataTag() const +{ + const char *tag = QTestResult::currentDataTag(); + if (tag) + return QString::fromUtf8(tag); + else + return QString(); +} + +void QuickTestResult::setDataTag(const QString &tag) +{ + if (!tag.isEmpty()) { + QTestData *data = &(QTest::newRow(tag.toUtf8().constData())); + QTestResult::setCurrentTestData(data); + emit dataTagChanged(); + } else { + QTestResult::setCurrentTestData(0); + } +} + +/*! + \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. + + \sa skipped, dataFailed +*/ +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(); +} + +/*! + \qmlproperty bool TestResult::skipped + + This property returns true if the current test function was + marked as skipped; false otherwise. + + \sa failed +*/ +bool QuickTestResult::isSkipped() const +{ + return QTestResult::skipCurrentTest(); +} + +void QuickTestResult::setSkipped(bool skip) +{ + QTestResult::setSkipCurrentTest(skip); + emit skippedChanged(); +} + +/*! + \qmlproperty int TestResult::passCount + + This property returns the number of tests that have passed. + + \sa failCount, skipCount +*/ +int QuickTestResult::passCount() const +{ + return QTestResult::passCount(); +} + +/*! + \qmlproperty int TestResult::failCount + + This property returns the number of tests that have failed. + + \sa passCount, skipCount +*/ +int QuickTestResult::failCount() const +{ + return QTestResult::failCount(); +} + +/*! + \qmlproperty int TestResult::skipCount + + This property returns the number of tests that have been skipped. + + \sa passCount, failCount +*/ +int QuickTestResult::skipCount() const +{ + return QTestResult::skipCount(); +} + +/*! + \qmlmethod TestResult::reset() + + Resets all pass/fail/skip counters and prepare for testing. +*/ +void QuickTestResult::reset() +{ + if (!globalProgramName) // Only if run via qmlviewer. + QTestResult::reset(); +} + +/*! + \qmlmethod TestResult::startLogging() + + Starts logging to the test output stream and writes the + test header. + + \sa stopLogging() +*/ +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; +} + +/*! + \qmlmethod TestResult::stopLogging() + + Writes the test footer to the test output stream and then stops logging. + + \sa startLogging() +*/ +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() +{ + Q_D(QuickTestResult); + delete d->table; + d->table = new QTestTable; +} + +void QuickTestResult::clearTestTable() +{ + Q_D(QuickTestResult); + delete d->table; + d->table = 0; +} + +void QuickTestResult::finishTestFunction() +{ + QTestResult::finishedCurrentTestFunction(); +} + +void QuickTestResult::fail + (const QString &message, const QString &file, int line) +{ + QTestResult::addFailure(message.toLatin1().constData(), + file.toLatin1().constData(), line); +} + +bool QuickTestResult::verify + (bool success, const QString &message, const QString &file, int line) +{ + if (message.isEmpty()) { + return QTestResult::verify + (success, "verify()", "", file.toLatin1().constData(), line); + } else { + return QTestResult::verify + (success, message.toLatin1().constData(), "", + file.toLatin1().constData(), line); + } +} + +bool QuickTestResult::compare + (bool success, const QString &message, + const QString &val1, const QString &val2, + const QString &file, int line) +{ + return QTestResult::compare + (success, message.toLocal8Bit().constData(), + QTest::toString(val1.toLatin1().constData()), + QTest::toString(val2.toLatin1().constData()), + "", "", + file.toLatin1().constData(), line); +} + +void QuickTestResult::skipSingle + (const QString &message, const QString &file, int line) +{ + QTestResult::addSkip(message.toLatin1().constData(), + QTest::SkipSingle, file.toLatin1().constData(), line); +} + +void QuickTestResult::skipAll + (const QString &message, const QString &file, int line) +{ + QTestResult::addSkip(message.toLatin1().constData(), + QTest::SkipAll, file.toLatin1().constData(), line); + QTestResult::setSkipCurrentTest(true); +} + +bool QuickTestResult::expectFail + (const QString &tag, const QString &comment, const QString &file, int line) +{ + return QTestResult::expectFail + (tag.toLatin1().constData(), + QTest::toString(comment.toLatin1().constData()), + QTest::Abort, file.toLatin1().constData(), line); +} + +bool QuickTestResult::expectFailContinue + (const QString &tag, const QString &comment, const QString &file, int line) +{ + return QTestResult::expectFail + (tag.toLatin1().constData(), + QTest::toString(comment.toLatin1().constData()), + QTest::Continue, file.toLatin1().constData(), line); +} + +void QuickTestResult::warn(const QString &message) +{ + QTestLog::warn(message.toLatin1().constData()); +} + +void QuickTestResult::ignoreWarning(const QString &message) +{ + QTestResult::ignoreMessage(QtWarningMsg, message.toLatin1().constData()); +} + +void QuickTestResult::wait(int ms) +{ + QTest::qWait(ms); +} + +void QuickTestResult::sleep(int ms) +{ + QTest::qSleep(ms); +} + +namespace QTest { + void qtest_qParseArgs(int argc, char *argv[]); +}; + +void QuickTestResult::parseArgs(int argc, char *argv[]) +{ + QTest::qtest_qParseArgs(argc, argv); +} + +void QuickTestResult::setProgramName(const char *name) +{ + if (name) { + QTestResult::reset(); + } else if (!name && loggingStarted) { + QTestResult::setCurrentTestObject(globalProgramName); + QTestLog::stopLogging(); + QTestResult::setCurrentTestObject(0); + } + globalProgramName = name; +} + +int QuickTestResult::exitCode() +{ +#if defined(QTEST_NOEXITCODE) + return 0; +#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); +#endif +} + +QT_END_NAMESPACE diff --git a/src/quicktestlib/quicktestresult_p.h b/src/quicktestlib/quicktestresult_p.h new file mode 100644 index 0000000..4896b01 --- /dev/null +++ b/src/quicktestlib/quicktestresult_p.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** 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. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QUICKTESTRESULT_P_H +#define QUICKTESTRESULT_P_H + +#include "quicktestglobal.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QuickTestResultPrivate; + +class Q_QUICK_TEST_EXPORT QuickTestResult : public QObject +{ + Q_OBJECT + Q_ENUMS(FunctionType) + Q_PROPERTY(QString testCaseName READ testCaseName WRITE setTestCaseName NOTIFY testCaseNameChanged) + Q_PROPERTY(QString functionName READ functionName WRITE setFunctionName NOTIFY functionNameChanged) + Q_PROPERTY(FunctionType functionType READ functionType WRITE setFunctionType NOTIFY functionTypeChanged) + Q_PROPERTY(QString dataTag READ dataTag WRITE setDataTag NOTIFY dataTagChanged) + Q_PROPERTY(bool failed READ isFailed) + Q_PROPERTY(bool dataFailed READ isDataFailed) + Q_PROPERTY(bool skipped READ isSkipped WRITE setSkipped NOTIFY skippedChanged) + Q_PROPERTY(int passCount READ passCount) + Q_PROPERTY(int failCount READ failCount) + Q_PROPERTY(int skipCount READ skipCount) +public: + QuickTestResult(QObject *parent = 0); + ~QuickTestResult(); + + // Values must match QTestResult::TestLocation. + enum FunctionType + { + NoWhere = 0, + DataFunc = 1, + InitFunc = 2, + Func = 3, + CleanupFunc = 4 + }; + + QString testCaseName() const; + void setTestCaseName(const QString &name); + + QString functionName() const; + void setFunctionName(const QString &name); + + FunctionType functionType() const; + void setFunctionType(FunctionType type); + + QString dataTag() const; + void setDataTag(const QString &tag); + + bool isFailed() const; + bool isDataFailed() const; + + bool isSkipped() const; + void setSkipped(bool skip); + + int passCount() const; + int failCount() const; + int skipCount() const; + +public Q_SLOTS: + void reset(); + + void startLogging(); + void stopLogging(); + + void initTestTable(); + void clearTestTable(); + + void finishTestFunction(); + + void fail(const QString &message, const QString &file, int line); + bool verify(bool success, const QString &message, + const QString &file, int line); + bool compare(bool success, const QString &message, + const QString &val1, const QString &val2, + const QString &file, int line); + void skipSingle(const QString &message, const QString &file, int line); + void skipAll(const QString &message, const QString &file, int line); + bool expectFail(const QString &tag, const QString &comment, + const QString &file, int line); + bool expectFailContinue(const QString &tag, const QString &comment, + const QString &file, int line); + void warn(const QString &message); + + void ignoreWarning(const QString &message); + + void wait(int ms); + void sleep(int ms); + +public: + // Helper functions for the C++ main() shell. + static void parseArgs(int argc, char *argv[]); + static void setProgramName(const char *name); + static int exitCode(); + +Q_SIGNALS: + void programNameChanged(); + void testCaseNameChanged(); + void functionNameChanged(); + void functionTypeChanged(); + void dataTagChanged(); + void skippedChanged(); + +private: + QScopedPointer d_ptr; + + Q_DECLARE_PRIVATE(QuickTestResult) + Q_DISABLE_COPY(QuickTestResult) +}; + +QT_END_NAMESPACE + +#endif diff --git a/tests/qmlauto/tst_qmlauto.cpp b/tests/qmlauto/tst_qmlauto.cpp index d5d85b6..0e1bd7a 100644 --- a/tests/qmlauto/tst_qmlauto.cpp +++ b/tests/qmlauto/tst_qmlauto.cpp @@ -39,6 +39,6 @@ ** ****************************************************************************/ -#include "qdeclarativetest.h" +#include "quicktest.h" QTEST_QUICK_MAIN(qmlauto) diff --git a/tests/qmlexample/tst_qmlexample.cpp b/tests/qmlexample/tst_qmlexample.cpp index 3c8aed5..4d9cc40 100644 --- a/tests/qmlexample/tst_qmlexample.cpp +++ b/tests/qmlexample/tst_qmlexample.cpp @@ -39,6 +39,6 @@ ** ****************************************************************************/ -#include "qdeclarativetest.h" +#include "quicktest.h" QTEST_QUICK_MAIN(qmlexample) -- cgit v1.2.3