summaryrefslogtreecommitdiffstats
path: root/src/quicktestlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktestlib')
-rw-r--r--src/quicktestlib/qdeclarativetest.cpp61
-rw-r--r--src/quicktestlib/qdeclarativetestreport.cpp168
-rw-r--r--src/quicktestlib/qdeclarativetestreport_p.h77
-rw-r--r--src/quicktestlib/qdeclarativetestresult.cpp109
-rw-r--r--src/quicktestlib/qdeclarativetestresult_p.h11
-rw-r--r--src/quicktestlib/quicktestlib.pro2
6 files changed, 79 insertions, 349 deletions
diff --git a/src/quicktestlib/qdeclarativetest.cpp b/src/quicktestlib/qdeclarativetest.cpp
index 09a262f..67e8d70 100644
--- a/src/quicktestlib/qdeclarativetest.cpp
+++ b/src/quicktestlib/qdeclarativetest.cpp
@@ -40,7 +40,7 @@
****************************************************************************/
#include "qdeclarativetest.h"
-#include "qdeclarativetestreport_p.h"
+#include "qdeclarativetestresult_p.h"
#include <QApplication>
#include <QtDeclarative/qdeclarative.h>
#include <QtDeclarative/qdeclarativeview.h>
@@ -58,13 +58,6 @@
QT_BEGIN_NAMESPACE
-// Defined in qdeclarativetestreport.cpp.
-extern bool qtest_quick_xmlOutput;
-extern int qtest_quick_passed;
-extern int qtest_quick_failed;
-extern int qtest_quick_skipped;
-extern FILE *qtest_quick_stream;
-
class QTestQuitObject : public QObject
{
Q_OBJECT
@@ -82,14 +75,8 @@ int qtest_quick_main(int argc, char **argv, const char *name, const char *source
QApplication app(argc, argv);
// Parse the command-line arguments.
- const char *filename = 0;
- for (int index = 1; index < argc; ++index) {
- QString arg = QString::fromLocal8Bit(argv[index]);
- if (arg == QLatin1String("-xml"))
- qtest_quick_xmlOutput = true;
- else if (arg == QLatin1String("-o") && (index + 1) < argc)
- filename = argv[++index];
- }
+ QDeclarativeTestResult::parseArgs(argc, argv);
+ QDeclarativeTestResult::setProgramName(name);
// Determine where to look for the test data. On a device it will
// typically be necessary to set QTEST_QUICK_SOURCE_DIR.
@@ -109,31 +96,11 @@ int qtest_quick_main(int argc, char **argv, const char *name, const char *source
if (!entries.contains(QLatin1String(".")))
entries.append(QLatin1String("."));
- if (filename) {
- qtest_quick_stream = fopen(filename, "w");
- if (!qtest_quick_stream) {
- perror(filename);
- return 1;
- }
- } else {
- qtest_quick_stream = stdout;
- }
-
- if (qtest_quick_xmlOutput) {
- fprintf(qtest_quick_stream, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
- "<TestCase name=\"%s\">\n", name);
- fprintf(qtest_quick_stream, "<Environment>\n"
- " <QtVersion>%s</QtVersion>\n"
- " <QTestVersion>%s</QTestVersion>\n"
- "</Environment>\n", qVersion(), qVersion());
- } else {
- fprintf(qtest_quick_stream, "********* Start testing of %s *********\n", name);
- }
-
// Scan through all of the "tst_*.qml" files in the subdirectories
// and run each of them in turn with a QDeclarativeView.
QStringList filters;
filters += QLatin1String("tst_*.qml");
+ bool compileFail = false;
foreach (QString name, entries) {
QDir subdir(testPath + QDir::separator() + name);
QStringList files = subdir.entryList(filters, QDir::Files);
@@ -153,7 +120,7 @@ int qtest_quick_main(int argc, char **argv, const char *name, const char *source
view.setSource(QUrl::fromLocalFile(fi.absoluteFilePath()));
if (view.status() == QDeclarativeView::Error) {
// Error compiling the test - flag failure and continue.
- ++qtest_quick_failed;
+ compileFail = true;
continue;
}
if (!quitobj.hasQuit) {
@@ -168,18 +135,14 @@ int qtest_quick_main(int argc, char **argv, const char *name, const char *source
}
}
- if (qtest_quick_xmlOutput) {
- fprintf(qtest_quick_stream, "</TestCase>\n");
- } else {
- fprintf(qtest_quick_stream, "Totals: %d passed, %d failed, %d skipped\n",
- qtest_quick_passed, qtest_quick_failed, qtest_quick_skipped);
- fprintf(qtest_quick_stream, "********* Finished testing of %s *********\n", name);
- }
-
- if (filename)
- fclose(qtest_quick_stream);
+ // Flush the current logging stream.
+ QDeclarativeTestResult::setProgramName(0);
- return qtest_quick_failed != 0;
+ // Return the number of failures as the exit code.
+ int code = QDeclarativeTestResult::exitCode();
+ if (!code && compileFail)
+ ++code;
+ return code;
}
QT_END_NAMESPACE
diff --git a/src/quicktestlib/qdeclarativetestreport.cpp b/src/quicktestlib/qdeclarativetestreport.cpp
deleted file mode 100644
index df9605b..0000000
--- a/src/quicktestlib/qdeclarativetestreport.cpp
+++ /dev/null
@@ -1,168 +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 "qdeclarativetestreport_p.h"
-#include <QtGui/qtextdocument.h>
-#include <stdio.h>
-
-QT_BEGIN_NAMESPACE
-
-bool qtest_quick_xmlOutput = false;
-int qtest_quick_passed = 0;
-int qtest_quick_failed = 0;
-int qtest_quick_skipped = 0;
-FILE *qtest_quick_stream = 0;
-
-void QDeclarativeTestReport::report(int pass, int fail, int skip)
-{
- qtest_quick_passed += pass;
- qtest_quick_failed += fail;
- qtest_quick_skipped += skip;
-}
-
-void QDeclarativeTestReport::log_fail(const QString &testCase, const QString &message)
-{
- if (!qtest_quick_stream)
- qtest_quick_stream = stdout;
- if (qtest_quick_xmlOutput) {
- log_incident("fail", testCase, message);
- } else if (!message.isEmpty()) {
- fprintf(qtest_quick_stream, "FAIL! : %s %s\n",
- testCase.toLatin1().constData(),
- message.toLatin1().constData());
- } else {
- fprintf(qtest_quick_stream, "FAIL! : %s\n", testCase.toLatin1().constData());
- }
-}
-
-void QDeclarativeTestReport::log_expect_fail
- (const QString &testCase, const QString &message)
-{
- if (!qtest_quick_stream)
- qtest_quick_stream = stdout;
- if (qtest_quick_xmlOutput) {
- log_incident("xfail", testCase, message);
- } else if (!message.isEmpty()) {
- fprintf(qtest_quick_stream, "XFAIL : %s %s\n",
- testCase.toLatin1().constData(),
- message.toLatin1().constData());
- } else {
- fprintf(qtest_quick_stream, "XFAIL : %s\n", testCase.toLatin1().constData());
- }
-}
-
-void QDeclarativeTestReport::log_expect_fail_pass(const QString &testCase)
-{
- if (!qtest_quick_stream)
- qtest_quick_stream = stdout;
- if (qtest_quick_xmlOutput)
- log_incident("xpass", testCase, QString());
- else
- fprintf(qtest_quick_stream, "XPASS : %s\n", testCase.toLatin1().constData());
-}
-
-void QDeclarativeTestReport::log_skip(const QString &testCase, const QString &message)
-{
- if (!qtest_quick_stream)
- qtest_quick_stream = stdout;
- if (qtest_quick_xmlOutput) {
- log_incident("skip", testCase, message);
- } else if (!message.isEmpty()) {
- fprintf(qtest_quick_stream, "SKIP : %s %s\n",
- testCase.toLatin1().constData(),
- message.toLatin1().constData());
- } else {
- fprintf(qtest_quick_stream, "SKIP : %s\n", testCase.toLatin1().constData());
- }
-}
-
-void QDeclarativeTestReport::log_pass(const QString &testCase)
-{
- if (!qtest_quick_stream)
- qtest_quick_stream = stdout;
- if (qtest_quick_xmlOutput)
- log_incident("pass", testCase, QString());
- else
- fprintf(qtest_quick_stream, "PASS : %s\n", testCase.toLatin1().constData());
-}
-
-void QDeclarativeTestReport::log_message(const QString &message)
-{
- if (!qtest_quick_stream)
- qtest_quick_stream = stdout;
- if (!qtest_quick_xmlOutput)
- fprintf(qtest_quick_stream, "%s\n", message.toLatin1().constData());
-}
-
-void QDeclarativeTestReport::log_incident
- (const char *type, const QString &testCase, const QString &message)
-{
- QString name(testCase);
- QString tag;
- name.replace(QLatin1String("()"), QLatin1String(""));
- name.replace(QLatin1String("::"), QLatin1String("__"));
- int tagIndex = name.indexOf(QLatin1String(" ["));
- if (tagIndex >= 0) {
- tag = name.mid(tagIndex + 2);
- if (tag.endsWith(QLatin1String("]")))
- tag = tag.left(tag.length() - 1);
- name = name.left(tagIndex);
- }
- fprintf(qtest_quick_stream, "<TestFunction name=\"%s\">\n",
- Qt::escape(name).toLatin1().constData());
- if (message.isEmpty() && tag.isEmpty()) {
- fprintf(qtest_quick_stream, "<Incident type=\"%s\" file=\"\" line=\"0\" />\n", type);
- } else {
- fprintf(qtest_quick_stream, "<Incident type=\"%s\" file=\"\" line=\"0\">\n", type);
- if (!tag.isEmpty()) {
- fprintf(qtest_quick_stream, " <DataTag>%s</DataTag>\n",
- Qt::escape(tag).toLatin1().constData());
- }
- if (!message.isEmpty()) {
- fprintf(qtest_quick_stream, " <Description>%s</Description>\n",
- Qt::escape(message).toLatin1().constData());
- }
- fprintf(qtest_quick_stream, "</Incident>\n");
- }
- fprintf(qtest_quick_stream, "</TestFunction>\n");
-}
-
-QT_END_NAMESPACE
diff --git a/src/quicktestlib/qdeclarativetestreport_p.h b/src/quicktestlib/qdeclarativetestreport_p.h
deleted file mode 100644
index 9535184..0000000
--- a/src/quicktestlib/qdeclarativetestreport_p.h
+++ /dev/null
@@ -1,77 +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 QDECLARATIVETESTREPORT_P_H
-#define QDECLARATIVETESTREPORT_P_H
-
-#include "quicktestglobal.h"
-#include <QtCore/qobject.h>
-#include <QtCore/qstring.h>
-#include <QtDeclarative/qdeclarative.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_TEST_QUICK_EXPORT QDeclarativeTestReport : public QObject
-{
- Q_OBJECT
-public:
- QDeclarativeTestReport(QObject *parent = 0) : QObject(parent) {}
-
-public Q_SLOTS:
- void report(int pass, int fail, int skip);
- void log_fail(const QString &testCase, const QString &message);
- void log_expect_fail
- (const QString &testCase, const QString &message);
- void log_expect_fail_pass(const QString &testCase);
- void log_skip(const QString &testCase, const QString &message);
- void log_pass(const QString &testCase);
- void log_message(const QString &message);
-
-private:
- void log_incident(const char *type, const QString &testCase,
- const QString &message);
-};
-
-QML_DECLARE_TYPE(QDeclarativeTestReport)
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/quicktestlib/qdeclarativetestresult.cpp b/src/quicktestlib/qdeclarativetestresult.cpp
index 0cc68e9..691b4a9 100644
--- a/src/quicktestlib/qdeclarativetestresult.cpp
+++ b/src/quicktestlib/qdeclarativetestresult.cpp
@@ -51,6 +51,9 @@
QT_BEGIN_NAMESPACE
+static const char *globalProgramName = 0;
+static bool loggingStarted = false;
+
class QDeclarativeTestResultPrivate
{
public:
@@ -66,7 +69,6 @@ public:
QByteArray intern(const QString &str);
void updateTestObjectName();
- QString programName;
QString testCaseName;
QString functionName;
QSet<QByteArray> internedStrings;
@@ -88,21 +90,13 @@ void QDeclarativeTestResultPrivate::updateTestObjectName()
// functions as "testCase__function".
if (QTestLog::logMode() == QTestLog::Plain) {
if (testCaseName.isEmpty()) {
- if (programName.isEmpty()) {
- QTestResult::setCurrentTestObject(0);
- } else {
- QTestResult::setCurrentTestObject
- (intern(programName).constData());
- }
+ QTestResult::setCurrentTestObject(globalProgramName);
} else if (QTestLog::logMode() == QTestLog::Plain) {
QTestResult::setCurrentTestObject
(intern(testCaseName).constData());
}
- } else if (programName.isEmpty()) {
- QTestResult::setCurrentTestObject(0);
} else {
- QTestResult::setCurrentTestObject
- (intern(programName).constData());
+ QTestResult::setCurrentTestObject(globalProgramName);
}
}
@@ -116,37 +110,12 @@ QDeclarativeTestResult::~QDeclarativeTestResult()
}
/*!
- \qmlproperty string TestResult::programName
-
- This property defines the name of the test program that
- is running the test cases. If this string is set to empty,
- then all TestCase elements have been executed and the program
- is about to exit.
-
- \sa testCaseName, functionName
-*/
-QString QDeclarativeTestResult::programName() const
-{
- Q_D(const QDeclarativeTestResult);
- return d->programName;
-}
-
-void QDeclarativeTestResult::setProgramName(const QString &name)
-{
- Q_D(QDeclarativeTestResult);
- d->programName = name;
- d->updateTestObjectName();
- emit programNameChanged();
-}
-
-/*!
\qmlproperty string TestResult::testCaseName
This property defines the name of current TestCase element
- that is running test cases. If this string is empty, then
- programName will be used instead.
+ that is running test cases.
- \sa programName, functionName
+ \sa functionName
*/
QString QDeclarativeTestResult::testCaseName() const
{
@@ -169,7 +138,7 @@ void QDeclarativeTestResult::setTestCaseName(const QString &name)
within a TestCase element that is running. If this string is
empty, then no function is currently running.
- \sa programName, testCaseName
+ \sa testCaseName
*/
QString QDeclarativeTestResult::functionName() const
{
@@ -183,10 +152,9 @@ void QDeclarativeTestResult::setFunctionName(const QString &name)
if (!name.isEmpty()) {
// In plain logging mode, we use the function name directly.
// In XML logging mode, we use "testCase__functionName" as the
- // programName is acting as the class name.
+ // program name is acting as the class name.
if (QTestLog::logMode() == QTestLog::Plain ||
- d->testCaseName.isEmpty() ||
- d->testCaseName == d->programName) {
+ d->testCaseName.isEmpty()) {
QTestResult::setCurrentTestFunction
(d->intern(name).constData());
} else {
@@ -327,40 +295,51 @@ int QDeclarativeTestResult::skipCount() const
*/
void QDeclarativeTestResult::reset()
{
- QTestResult::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 for programName.
+ test header.
\sa stopLogging()
*/
void QDeclarativeTestResult::startLogging()
{
- // The program name is used for logging headers and footers.
+ // 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();
- QTestResult::setCurrentTestObject(d->intern(d->programName).constData());
+ 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 for programName to the test
- output stream and then stops logging.
+ 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->programName).constData());
+ QTestResult::setCurrentTestObject(d->intern(d->testCaseName).constData());
QTestLog::stopLogging();
QTestResult::setCurrentTestObject(saved);
}
@@ -446,4 +425,36 @@ void QDeclarativeTestResult::warn(const QString &message)
QTestLog::warn(message.toLatin1().constData());
}
+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
index c6720e0..3b0b592 100644
--- a/src/quicktestlib/qdeclarativetestresult_p.h
+++ b/src/quicktestlib/qdeclarativetestresult_p.h
@@ -55,7 +55,6 @@ class Q_TEST_QUICK_EXPORT QDeclarativeTestResult : public QObject
{
Q_OBJECT
Q_ENUMS(FunctionType)
- Q_PROPERTY(QString programName READ programName WRITE setProgramName NOTIFY programNameChanged)
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)
@@ -80,9 +79,6 @@ public:
CleanupFunc = 4
};
- QString programName() const;
- void setProgramName(const QString &name);
-
QString testCaseName() const;
void setTestCaseName(const QString &name);
@@ -126,6 +122,13 @@ public Q_SLOTS:
bool expectFailContinue(const QString &tag, const QString &comment);
void warn(const QString &message);
+
+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();
diff --git a/src/quicktestlib/quicktestlib.pro b/src/quicktestlib/quicktestlib.pro
index e57d34a..bd29bdf 100644
--- a/src/quicktestlib/quicktestlib.pro
+++ b/src/quicktestlib/quicktestlib.pro
@@ -26,13 +26,11 @@ symbian {
SOURCES += \
qdeclarativetest.cpp \
- qdeclarativetestreport.cpp \
qdeclarativetestresult.cpp
HEADERS += \
quicktestglobal.h \
qdeclarativetest.h
PRIVATE_HEADERS += \
- qdeclarativetestreport_p.h \
qdeclarativetestresult_p.h
PUBLIC_HEADERS += $$HEADERS