From 3d4fc578bd5cc0b6d39d16638aa6f3577eb31f69 Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Fri, 10 Aug 2012 17:21:30 +0200 Subject: Auto test for 'qmake -project' use case. Change-Id: Ifb6d64828ba1cb42fd64299438b7eec302112edf Reviewed-by: Oswald Buddenhagen --- tests/auto/tools/qmake/testcompiler.cpp | 36 +++++++++++++-- tests/auto/tools/qmake/testcompiler.h | 6 +++ tests/auto/tools/qmake/testdata/project/main.cpp | 50 +++++++++++++++++++++ tests/auto/tools/qmake/testdata/project/test.qrc | 5 +++ .../tools/qmake/testdata/project/test_file.cpp | 46 +++++++++++++++++++ .../auto/tools/qmake/testdata/project/test_file.h | 51 ++++++++++++++++++++++ tests/auto/tools/qmake/tst_qmake.cpp | 15 +++++++ 7 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 tests/auto/tools/qmake/testdata/project/main.cpp create mode 100644 tests/auto/tools/qmake/testdata/project/test.qrc create mode 100644 tests/auto/tools/qmake/testdata/project/test_file.cpp create mode 100644 tests/auto/tools/qmake/testdata/project/test_file.h (limited to 'tests') diff --git a/tests/auto/tools/qmake/testcompiler.cpp b/tests/auto/tools/qmake/testcompiler.cpp index 3b77b1ec63..223f212141 100644 --- a/tests/auto/tools/qmake/testcompiler.cpp +++ b/tests/auto/tools/qmake/testcompiler.cpp @@ -244,6 +244,22 @@ bool TestCompiler::makeDistClean( const QString &workPath ) } +bool TestCompiler::qmakeProject( const QString &workDir, const QString &proName ) +{ + QDir D; + if (!D.exists(workDir)) { + testOutput_.append( "Directory '" + workDir + "' doesn't exist" ); + return errorOut(); + } + D.setCurrent(workDir); + + QString projectFile = proName; + if (!projectFile.endsWith(".pro")) + projectFile += ".pro"; + + return runCommand(qmakeCmd_ + " -project -o " + projectFile + " DESTDIR=./"); +} + bool TestCompiler::qmake( const QString &workDir, const QString &proName, const QString &buildDir ) { QDir D; @@ -285,13 +301,25 @@ bool TestCompiler::exists( const QString &destDir, const QString &exeName, Build } bool TestCompiler::removeMakefile( const QString &workPath ) +{ + return removeFile( workPath, "Makefile" ); +} + +bool TestCompiler::removeProject( const QString &workPath, const QString &project ) +{ + QString projectFile = project; + if (!projectFile.endsWith(".pro")) + projectFile += ".pro"; + + return removeFile( workPath, projectFile ); +} + +bool TestCompiler::removeFile( const QString &workPath, const QString &fileName ) { QDir D; D.setCurrent( workPath ); - if ( D.exists( "Makefile" ) ) - return D.remove( "Makefile" ); - else - return true; + + return ( D.exists( fileName ) ) ? D.remove( fileName ) : true; } QString TestCompiler::commandOutput() const diff --git a/tests/auto/tools/qmake/testcompiler.h b/tests/auto/tools/qmake/testcompiler.h index 8aed3a9987..137ffc9f54 100644 --- a/tests/auto/tools/qmake/testcompiler.h +++ b/tests/auto/tools/qmake/testcompiler.h @@ -66,6 +66,8 @@ public: bool makeClean( const QString &workPath ); // executes a make dist clean in the specified workPath bool makeDistClean( const QString &workPath ); + // executes a qmake -project on the specified workDir + bool qmakeProject( const QString &workDir, const QString &proName ); // executes a qmake on proName in the specified workDir, output goes to buildDir or workDir if it's null 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) @@ -74,6 +76,10 @@ public: bool exists( const QString &destDir, const QString &exeName, BuildType buildType, const QString &version ); // removes the makefile bool removeMakefile( const QString &workPath ); + // removes the project file specified by 'project' on the 'workPath' + bool removeProject( const QString &workPath, const QString &project ); + // removes the file specified by 'fileName' on the 'workPath' + bool removeFile( const QString &workPath, const QString &fileName ); // returns each line of stdout of the last command append with a "new line" character(s) to suit the platform QString commandOutput() const; // clear the results of storage of stdout for running previous commands diff --git a/tests/auto/tools/qmake/testdata/project/main.cpp b/tests/auto/tools/qmake/testdata/project/main.cpp new file mode 100644 index 0000000000..356d2176a4 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/project/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "test_file.h" +#include + +int main( int argc, char **argv ) +{ + QGuiApplication a(argc, argv); + SomeObject sc; + return a.exec(); +} diff --git a/tests/auto/tools/qmake/testdata/project/test.qrc b/tests/auto/tools/qmake/testdata/project/test.qrc new file mode 100644 index 0000000000..decde3dd24 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/project/test.qrc @@ -0,0 +1,5 @@ + + + test.qrc + + diff --git a/tests/auto/tools/qmake/testdata/project/test_file.cpp b/tests/auto/tools/qmake/testdata/project/test_file.cpp new file mode 100644 index 0000000000..cf67fb5767 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/project/test_file.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "test_file.h" + +SomeObject::SomeObject() : QObject() +{ +} diff --git a/tests/auto/tools/qmake/testdata/project/test_file.h b/tests/auto/tools/qmake/testdata/project/test_file.h new file mode 100644 index 0000000000..955486d67d --- /dev/null +++ b/tests/auto/tools/qmake/testdata/project/test_file.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +class SomeObject : public QObject +{ + Q_OBJECT +public: + SomeObject(); +signals: + void someSignal(); +}; diff --git a/tests/auto/tools/qmake/tst_qmake.cpp b/tests/auto/tools/qmake/tst_qmake.cpp index 3d1faf2aac..54032ad750 100644 --- a/tests/auto/tools/qmake/tst_qmake.cpp +++ b/tests/auto/tools/qmake/tst_qmake.cpp @@ -89,6 +89,7 @@ private slots: #endif void includefunction(); void substitutes(); + void project(); private: TestCompiler test_compiler; @@ -516,5 +517,19 @@ void tst_qmake::substitutes() QVERIFY( test_compiler.makeDistClean( buildDir )); } +void tst_qmake::project() +{ + QString workDir = base_path + "/testdata/project"; + + QVERIFY( test_compiler.qmakeProject( workDir, "project" )); + QVERIFY( test_compiler.exists( workDir, "project.pro", Plain, "" )); + QVERIFY( test_compiler.qmake( workDir, "project" )); + QVERIFY( test_compiler.exists( workDir, "Makefile", Plain, "" )); + QVERIFY( test_compiler.make( workDir )); + QVERIFY( test_compiler.exists( workDir, "project", Exe, "" )); + QVERIFY( test_compiler.makeDistClean( workDir )); + QVERIFY( test_compiler.removeProject( workDir, "project" )); +} + QTEST_MAIN(tst_qmake) #include "tst_qmake.moc" -- cgit v1.2.3