From f30296db1bc665ac7e77ce1c3feb245a16b0d5f1 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 22 Mar 2011 16:13:21 +0100 Subject: [PATCH] Modularized tst_bic and add some helper functions for global test --- qt3support/tests/global/global.cfg | 5 + qtbase/tests/global/global.cfg | 12 +++ qtdeclarative/tests/global/global.cfg | 5 + qtmultimedia/tests/global/global.cfg | 5 + qtphonon/tests/global/global.cfg | 5 + qtqa/tests/auto/bic/bic.pro | 1 + qtqa/tests/auto/bic/tst_bic.cpp | 66 ++++++------- qtqa/tests/shared/global.h | 174 +++++++++++++++++++++++++++++++++ qtscript/tests/global/global.cfg | 6 + qtsvg/tests/global/global.cfg | 5 + qttools/tests/global/global.cfg | 7 ++ qtxmlpatterns/tests/global/global.cfg | 5 + 12 files changed, 261 insertions(+), 35 deletions(-) create mode 100644 qt3support/tests/global/global.cfg create mode 100644 qtbase/tests/global/global.cfg create mode 100644 qtdeclarative/tests/global/global.cfg create mode 100644 qtmultimedia/tests/global/global.cfg create mode 100644 qtphonon/tests/global/global.cfg create mode 100644 qtqa/tests/shared/global.h create mode 100644 qtscript/tests/global/global.cfg create mode 100644 qtsvg/tests/global/global.cfg create mode 100644 qttools/tests/global/global.cfg create mode 100644 qtxmlpatterns/tests/global/global.cfg diff --git a/qt3support/tests/global/global.cfg b/qt3support/tests/global/global.cfg new file mode 100644 index 0000000..7eaa88b --- /dev/null +++ b/qt3support/tests/global/global.cfg @@ -0,0 +1,5 @@ + + + + + diff --git a/qtbase/tests/global/global.cfg b/qtbase/tests/global/global.cfg new file mode 100644 index 0000000..f39f4a0 --- /dev/null +++ b/qtbase/tests/global/global.cfg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/qtdeclarative/tests/global/global.cfg b/qtdeclarative/tests/global/global.cfg new file mode 100644 index 0000000..80e064a --- /dev/null +++ b/qtdeclarative/tests/global/global.cfg @@ -0,0 +1,5 @@ + + + + + diff --git a/qtmultimedia/tests/global/global.cfg b/qtmultimedia/tests/global/global.cfg new file mode 100644 index 0000000..90d89bf --- /dev/null +++ b/qtmultimedia/tests/global/global.cfg @@ -0,0 +1,5 @@ + + + + + diff --git a/qtphonon/tests/global/global.cfg b/qtphonon/tests/global/global.cfg new file mode 100644 index 0000000..a0dc50d --- /dev/null +++ b/qtphonon/tests/global/global.cfg @@ -0,0 +1,5 @@ + + + + + diff --git a/qtqa/tests/auto/bic/bic.pro b/qtqa/tests/auto/bic/bic.pro index 82711c9..6d085c8 100644 --- a/qtqa/tests/auto/bic/bic.pro +++ b/qtqa/tests/auto/bic/bic.pro @@ -1,4 +1,5 @@ load(qttest_p4) +INCLUDEPATH += ../../shared SOURCES += tst_bic.cpp qbic.cpp QT = core diff --git a/qtqa/tests/auto/bic/tst_bic.cpp b/qtqa/tests/auto/bic/tst_bic.cpp index 9ef2be1..4a4f379 100644 --- a/qtqa/tests/auto/bic/tst_bic.cpp +++ b/qtqa/tests/auto/bic/tst_bic.cpp @@ -49,6 +49,8 @@ QTEST_NOOP_MAIN #include "qbic.h" +#include "global.h" + #include class tst_Bic: public QObject @@ -62,14 +64,17 @@ public: QHash cachedCurrentInfo; private slots: - void initTestCase_data(); void initTestCase(); + void cleanupTestCase(); void sizesAndVTables_data(); void sizesAndVTables(); private: QBic bic; + QString qtModuleDir; + QHash modules; + QStringList incPaths; }; typedef QPair QStringPair; @@ -140,40 +145,35 @@ tst_Bic::tst_Bic() bic.addBlacklistedClass(QLatin1String("QDeclarativePrivate::RegisterType")); } -void tst_Bic::initTestCase_data() +void tst_Bic::initTestCase() { - QTest::addColumn("libName"); + QTest::qWarn("This test needs the correct qmake in PATH, we need it to generate INCPATH for qt modules."); - QTest::newRow("QtCore") << "QtCore"; - QTest::newRow("QtGui") << "QtGui"; + qtModuleDir = QString::fromLocal8Bit(qgetenv("QT_MODULE_TO_TEST")); + QVERIFY2(!qtModuleDir.isEmpty(), "This test needs $QT_MODULE_TO_TEST, we need it to search data and etc."); - QTest::newRow("Qt3Support") << "Qt3Support"; -#ifndef QT_NO_DBUS - QTest::newRow("QtDBus") << "QtDBus"; -#endif - QTest::newRow("QtDesigner") << "QtDesigner"; - QTest::newRow("QtDeclarative") << "QtDeclarative"; - QTest::newRow("QtMultimedia") << "QtMultimedia"; - QTest::newRow("QtNetwork") << "QtNetwork"; - QTest::newRow("QtOpenGL") << "QtOpenGL"; - QTest::newRow("QtScript") << "QtScript"; - QTest::newRow("QtScriptTools") << "QtScriptTools"; - QTest::newRow("QtSql") << "QtSql"; - QTest::newRow("QtSvg") << "QtSvg"; - QTest::newRow("QtTest") << "QtTest"; - QTest::newRow("QtWebKit") << "QtWebKit"; - QTest::newRow("QtXml") << "QtXml"; - QTest::newRow("QtXmlPatterns") << "QtXmlPatterns"; - QTest::newRow("phonon") << "phonon"; + if (qgetenv("PATH").contains("teambuilder")) + QTest::qWarn("This test might not work with teambuilder, consider switching it off."); + + QString configFile = qtModuleDir + "/tests/global/global.cfg"; + modules = qt_tests_shared_global_get_modules(configFile); + + QVERIFY2(modules.size() > 0, "Something is wrong in the global config file."); + + QString workDir = qtModuleDir + "/tests/global"; + incPaths = qt_tests_shared_global_get_include_paths(workDir, modules); + + QVERIFY2(incPaths.size() > 0, "Parse INCPATH failed."); + + QTest::addColumn("libName"); + + QStringList keys = modules.keys(); + for (int i = 0; i < keys.size(); ++i) + QTest::newRow(keys.at(i).toLatin1()) << keys.at(i); } -void tst_Bic::initTestCase() +void tst_Bic::cleanupTestCase() { - QString qtDir = QString::fromLocal8Bit(qgetenv("QTDIR")); - QVERIFY2(!qtDir.isEmpty(), "This test needs $QTDIR"); - - if (qgetenv("PATH").contains("teambuilder")) - QTest::qWarn("This test might not work with teambuilder, consider switching it off."); } void tst_Bic::sizesAndVTables_data() @@ -211,7 +211,7 @@ void tst_Bic::sizesAndVTables_data() for (int i = 0; i <= minor; ++i) { if (i != minor || patch) QTest::newRow("4." + QByteArray::number(i)) - << (QString(SRCDIR "data/%1.4.") + << (QString(qtModuleDir + "/tests/auto/bic/data/%1.4.") + QString::number(i) + QString(".0." FILESUFFIX ".txt")) << (i == minor && patch); @@ -233,15 +233,11 @@ QBic::Info tst_Bic::getCurrentInfo(const QString &libName) tmpQFile.write(tmpFileContents); tmpQFile.flush(); - QString qtDir = QString::fromLocal8Bit(qgetenv("QTDIR")); -#ifdef Q_OS_WIN - qtDir.replace('\\', '/'); -#endif QString compilerName = "g++"; QStringList args; args << "-c" - << "-I" + qtDir + "/include" + << incPaths #ifdef Q_OS_MAC << "-arch" << "i386" // Always use 32-bit data on Mac. #endif diff --git a/qtqa/tests/shared/global.h b/qtqa/tests/shared/global.h new file mode 100644 index 0000000..ae33bcc --- /dev/null +++ b/qtqa/tests/shared/global.h @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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$ +** +****************************************************************************/ +// Helper functions for global test cases. + +#ifndef QT_TESTS_SHARED_GLOBAL_H_INCLUDED +#define QT_TESTS_SHARED_GLOBAL_H_INCLUDED + +#include +#include + +QStringList qt_tests_shared_global_get_include_path(const QString &makeFile); +QHash qt_tests_shared_global_get_modules(const QString &configFile); +QStringList qt_tests_shared_global_get_include_paths(); + +QHash qt_tests_shared_global_get_modules(const QString &configFile) +{ + QHash modules; + + QFile file(configFile); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTest::qWarn("Can't open the config file for global.cfg."); + return modules; + } + + QXmlStreamReader xml; + xml.setDevice(&file); + + while (!xml.atEnd()) { + xml.readNext(); + if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == "config") { + xml.readNextStartElement(); + if (xml.name() == "modules") { + while (!xml.atEnd()) { + xml.readNextStartElement(); + QString modName; + QString qtModName; + if (xml.name() == "module") { + modName = xml.attributes().value("name").toString().simplified(); + qtModName = xml.attributes().value("qtname").toString().simplified(); + if (!modName.isEmpty() && !qtModName.isEmpty()) + modules[modName] = qtModName; + } + } + } + } + } + + file.close(); + + qDebug() << "modules keys:" << modules.keys(); + qDebug() << "modules values:" << modules.values(); + + return modules; +} + +QStringList qt_tests_shared_global_get_include_paths(const QString &workDir, QHash &modules) +{ + QString proFile = workDir + "/global.pro"; + QString makeFile = workDir + "/Makefile"; + + QStringList incPaths; + + QFile file(proFile); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QTest::qWarn("Can't open the pro file for global."); + return incPaths; + } + + QByteArray proLine = "QT += " + QStringList(modules.values()).join(" ").toLatin1() + "\n"; + file.write(proLine); + file.flush(); + file.close(); + + if (!QDir::setCurrent(workDir)) { + QTest::qWarn("Change working dir failed."); + return incPaths; + } + + QString qmakeApp = "qmake"; + + QStringList qmakeArgs; + qmakeArgs << "-o" + << "Makefile"; + + QProcess proc; + proc.start(qmakeApp, qmakeArgs, QIODevice::ReadOnly); + if (!proc.waitForFinished(6000000)) { + qWarning() << "qmake didn't finish" << proc.errorString(); + return incPaths; + } + if (proc.exitCode() != 0) { + qWarning() << "gcc returned with" << proc.exitCode(); + qDebug() << proc.readAllStandardError(); + return incPaths; + } + + QFile::remove(proFile); + + incPaths = qt_tests_shared_global_get_include_path(makeFile); + + QFile::remove(makeFile); + + return incPaths; +} + +QStringList qt_tests_shared_global_get_include_path(const QString &makeFile) +{ + QFile file(makeFile); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return QStringList(); + + QTextStream in(&file); + while (!in.atEnd()) { + QString line = in.readLine(); + if (line.contains("=") && line.contains("INCPATH")) { + QString relatives = line.mid(line.indexOf("=")+1); + QStringList list1 = relatives.split(" "); + QStringList list2; + for (int i = 0; i < list1.size(); ++i) { + if (!list1.at(i).startsWith("-I")) + continue; + QString rpath = list1.at(i).mid(2); + QString apath = "-I" + QDir(rpath).absolutePath(); +#ifdef Q_OS_WIN + apath.replace('\\', '/'); +#endif + list2 << apath; + } + return list2; + } + } + + return QStringList(); +} + +#endif // QT_TESTS_SHARED_GLOBAL_H_INCLUDED diff --git a/qtscript/tests/global/global.cfg b/qtscript/tests/global/global.cfg new file mode 100644 index 0000000..4bf7475 --- /dev/null +++ b/qtscript/tests/global/global.cfg @@ -0,0 +1,6 @@ + + + + + + diff --git a/qtsvg/tests/global/global.cfg b/qtsvg/tests/global/global.cfg new file mode 100644 index 0000000..c72fc2f --- /dev/null +++ b/qtsvg/tests/global/global.cfg @@ -0,0 +1,5 @@ + + + + + diff --git a/qttools/tests/global/global.cfg b/qttools/tests/global/global.cfg new file mode 100644 index 0000000..2dbbf38 --- /dev/null +++ b/qttools/tests/global/global.cfg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/qtxmlpatterns/tests/global/global.cfg b/qtxmlpatterns/tests/global/global.cfg new file mode 100644 index 0000000..fb1042d --- /dev/null +++ b/qtxmlpatterns/tests/global/global.cfg @@ -0,0 +1,5 @@ + + + + + -- 1.7.3.2.343.g7d43d