From 2085b06b3fbedf08243c5ed1f3b5f9f7d8b347f1 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 16 Dec 2010 10:53:18 +1000 Subject: Store test function names from the command-line --- src/quicktestlib/quicktestresult.cpp | 4 +- src/quicktestlib/testlib/qtestcase.cpp | 42 +++++++++++++++++-- src/quicktestlib/testlib/qtestoptions_p.h | 67 +++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/quicktestlib/testlib/qtestoptions_p.h diff --git a/src/quicktestlib/quicktestresult.cpp b/src/quicktestlib/quicktestresult.cpp index 46b3453..53f0070 100644 --- a/src/quicktestlib/quicktestresult.cpp +++ b/src/quicktestlib/quicktestresult.cpp @@ -583,14 +583,14 @@ void QuickTestResult::stopBenchmark() } namespace QTest { - void qtest_qParseArgs(int argc, char *argv[]); + void qtest_qParseArgs(int argc, char *argv[], bool qml); }; void QuickTestResult::parseArgs(int argc, char *argv[]) { if (!QBenchmarkGlobalData::current) QBenchmarkGlobalData::current = &globalBenchmarkData; - QTest::qtest_qParseArgs(argc, argv); + QTest::qtest_qParseArgs(argc, argv, true); } void QuickTestResult::setProgramName(const char *name) diff --git a/src/quicktestlib/testlib/qtestcase.cpp b/src/quicktestlib/testlib/qtestcase.cpp index c66ed8d..093da04 100644 --- a/src/quicktestlib/testlib/qtestcase.cpp +++ b/src/quicktestlib/testlib/qtestcase.cpp @@ -952,6 +952,10 @@ static bool isValidSlot(const QMetaMethod &sl) return true; } +bool printAvailableFunctions = false; +QStringList testFunctions; +QStringList testTags; + static void qPrintTestSlots() { for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { @@ -972,7 +976,7 @@ static int qToInt(char *str) return l; } -void qtest_qParseArgs(int argc, char *argv[]) +void qtest_qParseArgs(int argc, char *argv[], bool qml) { lastTestFuncIdx = -1; @@ -1021,8 +1025,12 @@ void qtest_qParseArgs(int argc, char *argv[]) "%s", argv[0], testOptions); exit(0); } else if (strcmp(argv[i], "-functions") == 0) { - qPrintTestSlots(); - exit(0); + if (qml) { + QTest::printAvailableFunctions = true; + } else { + qPrintTestSlots(); + exit(0); + } } else if(strcmp(argv[i], "-xunitxml") == 0){ QTestLog::setLogMode(QTestLog::XunitXML); } else if (strcmp(argv[i], "-xml") == 0) { @@ -1142,6 +1150,32 @@ void qtest_qParseArgs(int argc, char *argv[]) } else if (argv[i][0] == '-') { printf("Unknown option: '%s'\n\n%s", argv[i], testOptions); exit(1); + } else if (qml) { + // We can't check the availability of test functions until + // we load the QML files. So just store the data for now. + int colon = -1; + int off; + for(off = 0; *(argv[i]+off); ++off) { + if (*(argv[i]+off) == ':') { + if (*(argv[i]+off+1) == ':') { + // "::" is used as a test name separator. + // e.g. "ClickTests::test_click:row1". + ++off; + } else { + colon = off; + break; + } + } + } + if (colon == -1) { + QTest::testFunctions += QString::fromLatin1(argv[i]); + QTest::testTags += QString(); + } else { + QTest::testFunctions += + QString::fromLatin1(argv[i], colon); + QTest::testTags += + QString::fromLatin1(argv[i] + colon + 1); + } } else { int colon = -1; char buf[512], *data=0; @@ -1691,7 +1725,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) QTEST_ASSERT(metaObject); QTestResult::setCurrentTestObject(metaObject->className()); - qtest_qParseArgs(argc, argv); + qtest_qParseArgs(argc, argv, false); #ifdef QTESTLIB_USE_VALGRIND if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) { const QStringList origAppArgs(QCoreApplication::arguments()); diff --git a/src/quicktestlib/testlib/qtestoptions_p.h b/src/quicktestlib/testlib/qtestoptions_p.h new file mode 100644 index 0000000..2af40ef --- /dev/null +++ b/src/quicktestlib/testlib/qtestoptions_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 QtTest module 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 QTESTOPTIONS_P_H +#define QTESTOPTIONS_P_H + +#include "qtest_global.h" + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Test) + +namespace QTest +{ + extern Q_TESTLIB_EXPORT bool printAvailableFunctions; + extern Q_TESTLIB_EXPORT QStringList testFunctions; + extern Q_TESTLIB_EXPORT QStringList testTags; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif -- cgit v1.2.3