diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2009-04-02 16:56:04 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-04-02 16:56:04 (GMT) |
commit | 87d9469e428296a2fb8d0f266900cdfe816eaf0a (patch) | |
tree | f8219cadd57c0013f619030b44068adc009e2058 /tests | |
parent | ceb253c234f840f7aeec10fa4450e840c6b242f4 (diff) | |
parent | 7c09fda559760b8488d3130a5932fee04b2f6979 (diff) | |
download | Qt-87d9469e428296a2fb8d0f266900cdfe816eaf0a.zip Qt-87d9469e428296a2fb8d0f266900cdfe816eaf0a.tar.gz Qt-87d9469e428296a2fb8d0f266900cdfe816eaf0a.tar.bz2 |
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts:
tools/linguist/shared/profileevaluator.cpp
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qmake/qmake.pro | 2 | ||||
-rw-r--r-- | tests/auto/qmake/testcompiler.cpp | 305 | ||||
-rw-r--r-- | tests/auto/qmake/testcompiler.h | 49 | ||||
-rw-r--r-- | tests/auto/qmake/testdata/shadow_files_build/README | 2 | ||||
-rw-r--r-- | tests/auto/qmake/tst_qmake.cpp | 34 |
5 files changed, 116 insertions, 276 deletions
diff --git a/tests/auto/qmake/qmake.pro b/tests/auto/qmake/qmake.pro index 59cc2be..8cae6be 100644 --- a/tests/auto/qmake/qmake.pro +++ b/tests/auto/qmake/qmake.pro @@ -2,8 +2,6 @@ load(qttest_p4) HEADERS += testcompiler.h SOURCES += tst_qmake.cpp testcompiler.cpp -contains(QT_CONFIG, qt3support): QT += qt3support - cross_compile: DEFINES += QMAKE_CROSS_COMPILED diff --git a/tests/auto/qmake/testcompiler.cpp b/tests/auto/qmake/testcompiler.cpp index bfc8905..122a2b8 100644 --- a/tests/auto/qmake/testcompiler.cpp +++ b/tests/auto/qmake/testcompiler.cpp @@ -39,49 +39,37 @@ ** ****************************************************************************/ - #include "testcompiler.h" -#include <stdlib.h> -#include <qapplication.h> - -#ifdef QT3_SUPPORT - -#include <q3process.h> -#include <qtimer.h> -#ifdef Q_OS_WIN32 -# include <windows.h> -#endif -#include <QtTest/QtTest> +#include <QProcess> +#include <QDir> -#undef SHOW_QDEBUG -#undef SHOW_COMPLETENESS - -QString targetName( BuildType buildMode, const QString& target, const QString& version ) +static QString targetName( BuildType buildMode, const QString& target, const QString& version ) { + Q_UNUSED(version); QString targetName = target; #if defined (Q_OS_WIN32) switch (buildMode) { case Exe: // app - targetName.append(".exe"); - break; + targetName.append(".exe"); + break; case Dll: // dll - if (version != "") { - QStringList ver = QStringList::split(".", version); - targetName.append(ver.first()); - } + if (version != "") { + QStringList ver = QStringList::split(".", version); + targetName.append(ver.first()); + } targetName.append(".dll"); - break; + break; case Lib: // lib #ifdef Q_CC_GNU targetName.prepend("lib"); targetName.append(".a"); #else - targetName.append(".lib"); + targetName.append(".lib"); #endif - break; + break; case Plain: // no conversion break; @@ -90,16 +78,16 @@ QString targetName( BuildType buildMode, const QString& target, const QString& v switch (buildMode) { case Exe: // app - targetName += ".app/Contents/MacOS/" + target.section('/', -1); - break; + targetName += ".app/Contents/MacOS/" + target.section('/', -1); + break; case Dll: // dll - targetName.prepend("lib"); + targetName.prepend("lib"); targetName.append("." + version + ".dylib"); - break; + break; case Lib: // lib - targetName.prepend("lib"); - targetName.append(".a"); - break; + targetName.prepend("lib"); + targetName.append(".a"); + break; case Plain: // no conversion break; @@ -108,9 +96,9 @@ QString targetName( BuildType buildMode, const QString& target, const QString& v switch (buildMode) { case Exe: // app - break; + break; case Dll: // dll - targetName.prepend("lib"); + targetName.prepend("lib"); #if defined (Q_OS_HPUX) && !defined (__ia64) targetName.append(".sl"); #elif defined (Q_OS_AIX) @@ -118,11 +106,11 @@ QString targetName( BuildType buildMode, const QString& target, const QString& v #else targetName.append(".so"); #endif - break; + break; case Lib: // lib - targetName.prepend("lib"); - targetName.append(".a"); - break; + targetName.prepend("lib"); + targetName.append(".a"); + break; case Plain: // no conversion break; @@ -131,223 +119,119 @@ QString targetName( BuildType buildMode, const QString& target, const QString& v return targetName; } - - TestCompiler::TestCompiler() { - exit_ok = FALSE; - childProc = 0; - setBaseCommands( "", "", FALSE ); + setBaseCommands( "", "" ); } TestCompiler::~TestCompiler() { - if (childProc) - delete childProc; } -bool TestCompiler::runChild( bool showOutput, QStringList argList, QStringList *envList ) +bool TestCompiler::runCommand( QString cmdline ) { - //qDebug() << "executing" << argList; - exit_ok = FALSE; - if (childProc) - delete childProc; + testOutput_.append("Running command: " + cmdline); - child_show = showOutput; - if ( showOutput ) { + QProcess child; + if (!environment_.empty()) + child.setEnvironment(QProcess::systemEnvironment() + environment_); - QString S = argList.join(" "); - addMakeResult( S ); + child.start(cmdline); + if (!child.waitForStarted(-1)) { + testOutput_.append( "Unable to start child process." ); + return false; } - childProc = new Q3Process(argList, this, argList.join(" ").latin1()); - Q_ASSERT(childProc); - - connect(childProc,SIGNAL(readyReadStdout()),this,SLOT(childHasData())); - connect(childProc,SIGNAL(processExited()),this,SLOT(childReady())); - - if (!childProc->start( envList )) { - - addMakeResult( "Error executing '" + argList[0] + "'." ); - childReady(); - return FALSE; + bool failed = false; + child.setReadChannel(QProcess::StandardError); + while (QProcess::Running == child.state()) { + if (child.waitForReadyRead(1000)) { + QString output = child.readAllStandardError(); + testOutput_.append(output); + + output.prepend('\n'); + if (output.contains("\nProject MESSAGE: FAILED")) + failed = true; + } } - while (childProc != 0 && childProc->isRunning()) { - qApp->processEvents(); - } - - childReady(); - - return exit_ok; -} + child.waitForFinished(-1); -void TestCompiler::childReady() -{ - if (childProc != 0) { - childHasData(); - - QString S; - int pos; - while (childProc->canReadLineStderr()) { - S = childProc->readLineStderr(); - do { - pos = S.find("\t"); - if (pos >= 0) { - S.remove(pos,1); - S.insert(pos," "); - } - } while (pos >= 0); - - if (child_show) - addMakeResult( S ); - } - - exit_ok = childProc->normalExit() && childProc->exitStatus() == 0; - delete childProc; - } - childProc = 0; + return failed + ? false + : (child.exitStatus() == QProcess::NormalExit) + && (child.exitCode() == 0); } -void TestCompiler::childHasData() +void TestCompiler::setBaseCommands( QString makeCmd, QString qmakeCmd ) { - QString S; - int pos; - while (childProc->canReadLineStderr()) { - - S = childProc->readLineStderr(); - do { - pos = S.find("\t"); - if (pos >= 0) { - S.remove(pos,1); - S.insert(pos," "); - } - - } while (pos >= 0); - - if ( S.startsWith("Project MESSAGE: FAILED") ) - QTest::qFail( S, __FILE__, __LINE__ ); - else if ( S.startsWith("Project MESSAGE: SKIPPED") ) - QTest::qSkip( S, QTest::SkipSingle, __FILE__, __LINE__ ); - else if (child_show) - addMakeResult( S ); - } + makeCmd_ = makeCmd; + qmakeCmd_ = qmakeCmd; } -void TestCompiler::setBaseCommands( QString makeCmd, QString qmakeCmd, bool qwsMode ) +void TestCompiler::resetEnvironment() { - qws_mode = qwsMode; - make_cmd = makeCmd; - - // not sure if i need this, but it doesn't hurt - if (make_cmd.startsWith("\"")) - make_cmd = make_cmd.remove(0,1); - if (make_cmd.endsWith("\"")) - make_cmd = make_cmd.remove(make_cmd.length()-1,1); - - qmake_cmd = qmakeCmd; - // also not sure if i need this, but it doesn't hurt... - if(qmake_cmd.length() >= 2 && (qmake_cmd.at(0) == '"' || qmake_cmd.at(0) == '\'') && qmake_cmd.at(qmake_cmd.length()-1) == qmake_cmd.at(0)) - qmake_cmd = qmake_cmd.mid(1, qmake_cmd.length()-2); + environment_.clear(); } -bool TestCompiler::cleanAll( const QString &workPath, const QString &destPath, const QString &exeName, const QString &exeExt ) +void TestCompiler::addToEnvironment( QString varAssignment ) { - QDir D(workPath); - if (!D.exists()) { - - addMakeResult( "Directory '" + workPath + "' doesn't exist" ); - return FALSE; - } - - D.setCurrent(workPath); - // must delete at least the executable file to be able to easily and safely - // verify that the compilation was a success. - D.remove( destPath + "/" + exeName + exeExt ); - D.remove( workPath + "/Makefile"); - QFileInfo Fi( workPath + "/Makefile"); - if (Fi.exists()) { - - // Run make clean - QStringList args; - args = QStringList::split( " ", make_cmd ); - args.append("clean"); - - return runChild( FALSE, args, 0 ); - } - - return TRUE; + environment_.push_back(varAssignment); } bool TestCompiler::makeClean( const QString &workPath ) { QDir D; if (!D.exists(workPath)) { - - addMakeResult( "Directory '" + workPath + "' doesn't exist" ); - return FALSE; + testOutput_.append( "Directory '" + workPath + "' doesn't exist" ); + return false; } D.setCurrent(workPath); QFileInfo Fi( workPath + "/Makefile"); - if (Fi.exists()) { - - // Run make clean - QStringList args; - args = QStringList::split( " ", make_cmd ); - args.append("clean"); + if (Fi.exists()) + // Run make clean + return runCommand( makeCmd_ + " clean" ); - return runChild( FALSE, args, 0 ); - } - - return TRUE; + return true; } bool TestCompiler::makeDistClean( const QString &workPath ) { QDir D; if (!D.exists(workPath)) { - addMakeResult( "Directory '" + workPath + "' doesn't exist" ); - return FALSE; + testOutput_.append( "Directory '" + workPath + "' doesn't exist" ); + return false; } D.setCurrent(workPath); QFileInfo Fi( workPath + "/Makefile"); - if (Fi.exists()) { - // Run make distclean - QStringList args; - args = QStringList::split( " ", make_cmd ); - args.append("distclean"); - - return runChild( FALSE, args, 0 ); - } + if (Fi.exists()) + // Run make distclean + return runCommand( makeCmd_ + " distclean" ); - return TRUE; + return true; } bool TestCompiler::qmake( const QString &workDir, const QString &proName, const QString &buildDir ) { - // Now start qmake and generate the makefile - - QDir D( workDir ); - // Make sure we start in the right directory + QDir D; D.setCurrent( workDir ); if (D.exists("Makefile")) - D.remove("Makefile"); - - QStringList args; - args = QStringList::split( " ", qmake_cmd ); + D.remove("Makefile"); - QString project_fname = workDir + "/" + proName + ".pro"; - QString makefile_fname = (buildDir.isNull()?QString():(buildDir + "/")) + "Makefile"; + QString projectFile = proName; + QString makeFile = buildDir; + if (!projectFile.endsWith(".pro")) + projectFile += ".pro"; + if (!makeFile.isEmpty() && !makeFile.endsWith('/')) + makeFile += '/'; + makeFile += "Makefile"; - args.append( project_fname ); - args.append( "-o" ); - args.append( makefile_fname ); - - return runChild( TRUE, args, 0 ); + // Now start qmake and generate the makefile + return runCommand( qmakeCmd_ + " " + projectFile + " -o " + makeFile ); } bool TestCompiler::make( const QString &workPath, const QString &target ) @@ -355,14 +239,13 @@ bool TestCompiler::make( const QString &workPath, const QString &target ) QDir D; D.setCurrent( workPath ); - QStringList args; - args = QStringList::split( " ", make_cmd ); - if ( make_cmd.lower().find("nmake") >= 0) - args.append("/NOLOGO"); - if ( !target.isNull() ) - args.append(target); + QString cmdline = makeCmd_; + if ( cmdline.contains("nmake", Qt::CaseInsensitive) ) + cmdline.append(" /NOLOGO"); + if ( !target.isEmpty() ) + cmdline += " " + target; - return runChild( TRUE, args, 0 ); + return runCommand( cmdline ); } bool TestCompiler::exists( const QString &destDir, const QString &exeName, BuildType buildType, const QString &version ) @@ -371,20 +254,12 @@ bool TestCompiler::exists( const QString &destDir, const QString &exeName, Build return f.exists(); } -void TestCompiler::addMakeResult( const QString &result ) -{ - make_result.append( result ); -} - bool TestCompiler::removeMakefile( const QString &workPath ) { QDir D; D.setCurrent( workPath ); if ( D.exists( "Makefile" ) ) - return D.remove( "Makefile" ); + return D.remove( "Makefile" ); else - return TRUE; + return true; } - -#endif //QT3_SUPPORT - diff --git a/tests/auto/qmake/testcompiler.h b/tests/auto/qmake/testcompiler.h index 597d440..41e5177 100644 --- a/tests/auto/qmake/testcompiler.h +++ b/tests/auto/qmake/testcompiler.h @@ -41,33 +41,22 @@ #ifndef TESTCOMPILER_H #define TESTCOMPILER_H - -#ifdef QT3_SUPPORT - -#include <qobject.h> -#include <qstringlist.h> - -QT_FORWARD_DECLARE_CLASS(Q3Process) - -#define COMPILE_ERROR "Compile error" -#define COMPILE_SUCCESS "Compile successfull" -#define COMPILE_NOT_AVAIL "Binary not available for testing" -#define SELF_TEST "self-test" +#include <QObject> +#include <QStringList> enum BuildType { Exe, Dll, Lib, Plain }; class TestCompiler : public QObject { -Q_OBJECT + Q_OBJECT public: TestCompiler(); virtual ~TestCompiler(); - void setBaseCommands( QString makeCmd, QString qmakeCmd, bool qwsMode ); - - // builds a complete project, e.g. qmake, make clean, make and exists. - bool buildProject( const QString &project, BuildType buildType, const QString &targetName, const QString &destPath, const QString &version ); + void setBaseCommands( QString makeCmd, QString qmakeCmd ); + void resetEnvironment(); + void addToEnvironment( QString varAssignment ); // executes a make clean in the specified workPath bool makeClean( const QString &workPath ); @@ -77,34 +66,20 @@ public: bool qmake( const QString &workDir, const QString &proName, const QString &buildDir = QString() ); // executes a make in the specified workPath, with an optional target (eg. install) bool make( const QString &workPath, const QString &target = QString() ); - // executes a make clean and then deletes the makefile in workpath + deletes the executable - // in destPath. - bool cleanAll( const QString &workPath, const QString &destPath, const QString &exeName, const QString &exeExt ); // checks if the executable exists in destDir bool exists( const QString &destDir, const QString &exeName, BuildType buildType, const QString &version ); // removes the makefile bool removeMakefile( const QString &workPath ); private: - QString make_cmd; - QString qmake_cmd; - - Q3Process *childProc; - QStringList env_list; + bool runCommand( QString cmdLine ); - bool child_show; - bool qws_mode; - bool exit_ok; - -private: - bool runChild( bool showOutput, QStringList argList, QStringList *envList ); - void addMakeResult( const QString &result ); - QStringList make_result; + QString makeCmd_; + QString qmakeCmd_; + QStringList environment_; -private slots: - void childReady(); - void childHasData(); + // need to make this available somewhere + QStringList testOutput_; }; -#endif // QT3_SUPPORT #endif // TESTCOMPILER_H diff --git a/tests/auto/qmake/testdata/shadow_files_build/README b/tests/auto/qmake/testdata/shadow_files_build/README index 46017fc..15e48c0 100644 --- a/tests/auto/qmake/testdata/shadow_files_build/README +++ b/tests/auto/qmake/testdata/shadow_files_build/README @@ -1 +1 @@ -Here to ensure include_dir_build exists +Here to ensure shadow_files_build exists, used by the shadow_files test. diff --git a/tests/auto/qmake/tst_qmake.cpp b/tests/auto/qmake/tst_qmake.cpp index facf0bb..70f1f3c 100644 --- a/tests/auto/qmake/tst_qmake.cpp +++ b/tests/auto/qmake/tst_qmake.cpp @@ -39,21 +39,13 @@ ** ****************************************************************************/ - -#include <QtTest/QtTest> - -#if !defined(QMAKE_CROSS_COMPILED) && defined(QT3_SUPPORT) - -#include <qdir.h> -#include <qprocess.h> - +#if !defined(QMAKE_CROSS_COMPILED) #include "testcompiler.h" -#include <stdlib.h> - -//TESTED_CLASS= -//TESTED_FILES=corelib/tools/qlocale.h corelib/tools/qlocale.cpp +#include <QObject> +#include <QDir> +#include <QtTest/QtTest> class tst_qmake : public QObject { @@ -63,12 +55,12 @@ public: tst_qmake(); virtual ~tst_qmake(); - public slots: void initTestCase(); void cleanupTestCase(); void init(); void cleanup(); + private slots: void simple_app(); void simple_lib(); @@ -104,16 +96,16 @@ tst_qmake::tst_qmake() { QString cmd = QString("qmake \"QT_VERSION=%1\"").arg(QT_VERSION); #ifdef Q_CC_MSVC - test_compiler.setBaseCommands( "nmake", cmd, FALSE ); + test_compiler.setBaseCommands( "nmake", cmd ); #elif defined(Q_CC_MINGW) - test_compiler.setBaseCommands( "mingw32-make", cmd, FALSE ); + test_compiler.setBaseCommands( "mingw32-make", cmd ); #elif defined(Q_OS_WIN) && defined(Q_CC_GNU) - test_compiler.setBaseCommands( "mmmake", cmd, FALSE ); + test_compiler.setBaseCommands( "mmmake", cmd ); #else - test_compiler.setBaseCommands( "make", cmd, FALSE ); + test_compiler.setBaseCommands( "make", cmd ); #endif QDir dir; - base_path = dir.currentDirPath(); + base_path = dir.currentPath(); } tst_qmake::~tst_qmake() @@ -255,10 +247,10 @@ void tst_qmake::duplicateLibraryEntries() void tst_qmake::export_across_file_boundaries() { // This relies on features so we need to set the QMAKEFEATURES environment variable - putenv("QMAKEFEATURES=."); + test_compiler.addToEnvironment("QMAKEFEATURES=."); QString workDir = base_path + "/testdata/export_across_file_boundaries"; QVERIFY( test_compiler.qmake( workDir, "foo" )); - putenv("QMAKEFEATURES="); + test_compiler.resetEnvironment(); } void tst_qmake::include_dir() @@ -406,7 +398,7 @@ void tst_qmake::bundle_spaces() // make (-n). TestCompiler local_tc; - local_tc.setBaseCommands("make -n", "qmake -macx -spec macx-g++", FALSE); + local_tc.setBaseCommands("make -n", "qmake -macx -spec macx-g++"); QVERIFY( local_tc.qmake(workDir, "bundle-spaces") ); |