Auto test for 'qmake -project' use case.
authorRafael Roquetto <rafael.roquetto@kdab.com>
Fri, 10 Aug 2012 15:21:30 +0000 (17:21 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 4 Sep 2012 08:30:33 +0000 (10:30 +0200)
Change-Id: Ifb6d64828ba1cb42fd64299438b7eec302112edf
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
tests/auto/tools/qmake/testcompiler.cpp
tests/auto/tools/qmake/testcompiler.h
tests/auto/tools/qmake/testdata/project/main.cpp [new file with mode: 0644]
tests/auto/tools/qmake/testdata/project/test.qrc [new file with mode: 0644]
tests/auto/tools/qmake/testdata/project/test_file.cpp [new file with mode: 0644]
tests/auto/tools/qmake/testdata/project/test_file.h [new file with mode: 0644]
tests/auto/tools/qmake/tst_qmake.cpp

index 3b77b1e..223f212 100644 (file)
@@ -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;
@@ -286,12 +302,24 @@ 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
index 8aed3a9..137ffc9 100644 (file)
@@ -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 (file)
index 0000000..356d217
--- /dev/null
@@ -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 <qguiapplication.h>
+
+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 (file)
index 0000000..decde3d
--- /dev/null
@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>test.qrc</file>
+    </qresource>
+</RCC>
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 (file)
index 0000000..cf67fb5
--- /dev/null
@@ -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 (file)
index 0000000..955486d
--- /dev/null
@@ -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 <qobject.h>
+
+class SomeObject : public QObject
+{
+    Q_OBJECT
+public:
+    SomeObject();
+signals:
+    void someSignal();
+};
index 3d1faf2..54032ad 100644 (file)
@@ -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"