diff options
Diffstat (limited to 'tests/auto/api')
144 files changed, 3408 insertions, 50 deletions
diff --git a/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/main.cpp b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/main.cpp new file mode 100644 index 000000000..940a7628d --- /dev/null +++ b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/main.cpp @@ -0,0 +1,7 @@ +#include "object.h" + +int main() +{ + Object o; + o.f(); +} diff --git a/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/object.cpp b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/object.cpp new file mode 100644 index 000000000..aab24f6c0 --- /dev/null +++ b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/object.cpp @@ -0,0 +1,13 @@ +#include "object.h" + +#include <QObject> + +// class InternalClass : public QObject +// { +// Q_OBJECT +// }; + +void Object::f() { } + + +// #include "object.moc" diff --git a/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/object.h b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/object.h new file mode 100644 index 000000000..37070b494 --- /dev/null +++ b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/object.h @@ -0,0 +1,4 @@ +class Object { +public: + void f(); +}; diff --git a/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/project.qbs b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/project.qbs new file mode 100644 index 000000000..40c5395ef --- /dev/null +++ b/tests/auto/api/testdata/add-qobject-macro-to-cpp-file/project.qbs @@ -0,0 +1,6 @@ +import qbs + +QtApplication { + files: ["main.cpp", "object.h", "object.cpp"] +} + diff --git a/tests/auto/api/testdata/added-file-persistent/file.cpp b/tests/auto/api/testdata/added-file-persistent/file.cpp new file mode 100644 index 000000000..8101b05dc --- /dev/null +++ b/tests/auto/api/testdata/added-file-persistent/file.cpp @@ -0,0 +1 @@ +void f() { } diff --git a/tests/auto/api/testdata/added-file-persistent/main.cpp b/tests/auto/api/testdata/added-file-persistent/main.cpp new file mode 100644 index 000000000..1921f1feb --- /dev/null +++ b/tests/auto/api/testdata/added-file-persistent/main.cpp @@ -0,0 +1,3 @@ +void f(); + +int main() { f(); } diff --git a/tests/auto/api/testdata/added-file-persistent/project.qbs b/tests/auto/api/testdata/added-file-persistent/project.qbs new file mode 100644 index 000000000..672886646 --- /dev/null +++ b/tests/auto/api/testdata/added-file-persistent/project.qbs @@ -0,0 +1,8 @@ +import qbs + +CppApplication { + files: [ + 'main.cpp', + /* 'file.cpp' */ + ] +} diff --git a/tests/auto/api/testdata/app-without-sources/a.c b/tests/auto/api/testdata/app-without-sources/a.c new file mode 100644 index 000000000..bf7759e11 --- /dev/null +++ b/tests/auto/api/testdata/app-without-sources/a.c @@ -0,0 +1 @@ +int foo() { return 42; } diff --git a/tests/auto/api/testdata/app-without-sources/b.c b/tests/auto/api/testdata/app-without-sources/b.c new file mode 100644 index 000000000..e3841fa32 --- /dev/null +++ b/tests/auto/api/testdata/app-without-sources/b.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int foo(); // defined in a.cpp + +int main() +{ + printf("The answer is %d.\n", foo()); + return 0; +} + diff --git a/tests/auto/api/testdata/app-without-sources/project.qbs b/tests/auto/api/testdata/app-without-sources/project.qbs new file mode 100644 index 000000000..dca195e29 --- /dev/null +++ b/tests/auto/api/testdata/app-without-sources/project.qbs @@ -0,0 +1,33 @@ +import qbs 1.0 + +Project { + StaticLibrary { + name: "a" + + Depends { name: "cpp" } + + files: [ + "a.c", + ] + } + + StaticLibrary { + name: "b" + + Depends { name: "a" } + Depends { name: "cpp" } + + files: [ + "b.c", + ] + } + + CppApplication { + name: "appWithoutSources" + type: ["application"] + cpp.entryPoint: "main" + + Depends { name: "a" } + Depends { name: "b" } + } +} diff --git a/tests/auto/api/testdata/base-properties/imports/Bar.qbs b/tests/auto/api/testdata/base-properties/imports/Bar.qbs new file mode 100644 index 000000000..07ab724e4 --- /dev/null +++ b/tests/auto/api/testdata/base-properties/imports/Bar.qbs @@ -0,0 +1,6 @@ +import qbs 1.0 + +Product { + Depends { name: "cpp" } + cpp.defines: ["FROM_BAR"] +} diff --git a/tests/auto/api/testdata/base-properties/imports/Foo.qbs b/tests/auto/api/testdata/base-properties/imports/Foo.qbs new file mode 100644 index 000000000..563992434 --- /dev/null +++ b/tests/auto/api/testdata/base-properties/imports/Foo.qbs @@ -0,0 +1,7 @@ +import qbs 1.0 + +Bar { + type: "application" + cpp.defines: base.concat(["FROM_FOO"]) +} + diff --git a/tests/auto/api/testdata/base-properties/main.cpp b/tests/auto/api/testdata/base-properties/main.cpp new file mode 100644 index 000000000..069cf9cb3 --- /dev/null +++ b/tests/auto/api/testdata/base-properties/main.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#ifndef FROM_FOO +#error FROM_FOO missing! +#endif +#ifndef FROM_BAR +#error FROM_BAR missing! +#endif +#ifndef FROM_PRJ +#error FROM_PRJ missing! +#endif + +int main() +{ + return 0; +} + diff --git a/tests/auto/api/testdata/base-properties/prj.qbs b/tests/auto/api/testdata/base-properties/prj.qbs new file mode 100644 index 000000000..a43b930dc --- /dev/null +++ b/tests/auto/api/testdata/base-properties/prj.qbs @@ -0,0 +1,10 @@ +import qbs 1.0 +import "imports/Foo.qbs" as Foo + +Project { + Foo { + cpp.defines: base.concat(["FROM_PRJ"]); + files: "main.cpp" + } +} + diff --git a/tests/auto/api/testdata/build-properties-source/main.cpp b/tests/auto/api/testdata/build-properties-source/main.cpp new file mode 100644 index 000000000..a5992a691 --- /dev/null +++ b/tests/auto/api/testdata/build-properties-source/main.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#ifndef WORLD +# error WORLD is not defined +#endif + +int main() +{ + puts("Hello " WORLD "!"); +} diff --git a/tests/auto/api/testdata/build-properties-source/project.qbs b/tests/auto/api/testdata/build-properties-source/project.qbs new file mode 100644 index 000000000..df7649625 --- /dev/null +++ b/tests/auto/api/testdata/build-properties-source/project.qbs @@ -0,0 +1,16 @@ +import qbs 1.0 + +Project { + Product { + type: "application" + name: "HelloWorld" + + Depends { name: 'cpp' } + + Group { + cpp.defines: ['WORLD="BANANA"'] + files : [ "main.cpp" ] + } + } +} + diff --git a/tests/auto/api/testdata/change-dependent-lib/change-dependent-lib.qbs b/tests/auto/api/testdata/change-dependent-lib/change-dependent-lib.qbs new file mode 100644 index 000000000..ac5778134 --- /dev/null +++ b/tests/auto/api/testdata/change-dependent-lib/change-dependent-lib.qbs @@ -0,0 +1,23 @@ +import qbs 1.0 + +Project { + Application { + name : "HelloWorld" + Group { + files : [ "main.cpp" ] + } + Depends { name: "cpp" } + Depends { name: "mylib" } + } + + DynamicLibrary { + name : "mylib" + version: "1.2.3" + Group { + files : [ "mylib.cpp" ] + } + Depends { name: "cpp" } + cpp.defines: ["XXXX"] + } +} + diff --git a/tests/auto/api/testdata/change-dependent-lib/main.cpp b/tests/auto/api/testdata/change-dependent-lib/main.cpp new file mode 100644 index 000000000..d5ade08e2 --- /dev/null +++ b/tests/auto/api/testdata/change-dependent-lib/main.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT +# define IMPORT +#endif + +IMPORT int mylib_hello(); + +int main() +{ + puts("application says hello!"); + return mylib_hello(); +} + diff --git a/tests/auto/api/testdata/change-dependent-lib/mylib.cpp b/tests/auto/api/testdata/change-dependent-lib/mylib.cpp new file mode 100644 index 000000000..fc4a504d4 --- /dev/null +++ b/tests/auto/api/testdata/change-dependent-lib/mylib.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT +# define IMPORT +#endif + +EXPORT int mylib_hello() +{ + puts("mylib says hello!"); + return 0; +} diff --git a/tests/auto/api/testdata/codegen/foo.txt b/tests/auto/api/testdata/codegen/foo.txt new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/tests/auto/api/testdata/codegen/foo.txt @@ -0,0 +1 @@ +Hello World diff --git a/tests/auto/api/testdata/codegen/project.qbs b/tests/auto/api/testdata/codegen/project.qbs new file mode 100644 index 000000000..4b440fc51 --- /dev/null +++ b/tests/auto/api/testdata/codegen/project.qbs @@ -0,0 +1,72 @@ +import qbs 1.0 +import qbs.FileInfo + +Project { + property string name: 'codegen' + property string osSpecificName: name.toUpperCase() + '_' + qbs.targetOS[0].toUpperCase() + + Product { + type: 'application' + name: project.name + property var replacements: ({ + NUMBERTYPE: "int", + STRINGTYPE: "char **", + FUNCTIONNAME: "main" + }) + Group { + files: 'foo.txt' + fileTags: ['text'] + } + Depends { name: 'cpp' } + Depends { name: 'Qt.core' } + } + + Rule { + inputs: ['text'] + Artifact { + fileTags: ['cpp'] + filePath: input.baseName + '.cpp' + } + prepare: { + function expandMacros(str, table) + { + var rex = /\$\w+/; + var m = rex.exec(str); + while (m != null) { + str = str.substr(0, m.index) + + table[m[0].substr(1)] + + str.substr(m.index + m[0].length); + m = rex.exec(str); + } + return str; + } + + // check whether multipart module name translation is working + var actual = product.moduleProperty("Qt.core", "mocName"); + if (!actual || !actual.contains("moc")) + throw "multipart module name translation is broken"; + + // check whether we can access project properties here + var expected = "CODEGEN_" + product.moduleProperty("qbs", "targetOS")[0].toUpperCase(); + if (project.osSpecificName !== expected) + throw "Wrong project property value: " + project.osSpecificName + + "\nexpected: " + expected; + + var code = '$NUMBERTYPE $FUNCTIONNAME($NUMBERTYPE, $STRINGTYPE) { return 0; }'; + code = expandMacros(code, product.replacements); + var args = ['echo ' + code + '>' + output.filePath] + var cmd + if (product.moduleProperty("qbs", "hostOS").contains('windows')) { + cmd = new Command('cmd.exe', ['/C'].concat(args)); + } else { + args[0] = args[0].replace(/\(/g, '\\(') + args[0] = args[0].replace(/\)/g, '\\)') + args[0] = args[0].replace(/;/g, '\\;') + cmd = new Command('/bin/sh', ['-c'].concat(args)) + } + cmd.description = 'generate\t' + FileInfo.fileName(output.filePath); + cmd.highlight = 'codegen'; + return cmd; + } + } +} diff --git a/tests/auto/api/testdata/disable-product/project.qbs b/tests/auto/api/testdata/disable-product/project.qbs new file mode 100644 index 000000000..3aa7afd50 --- /dev/null +++ b/tests/auto/api/testdata/disable-product/project.qbs @@ -0,0 +1,5 @@ +import qbs + +Product { + // condition: false +} diff --git a/tests/auto/api/testdata/disabled-product/disabledProduct.qbs b/tests/auto/api/testdata/disabled-product/disabledProduct.qbs new file mode 100644 index 000000000..0c44995c7 --- /dev/null +++ b/tests/auto/api/testdata/disabled-product/disabledProduct.qbs @@ -0,0 +1,6 @@ +import qbs + +CppApplication { + condition: false + files: "main.cpp" +} diff --git a/tests/auto/api/testdata/disabled-product/main.cpp b/tests/auto/api/testdata/disabled-product/main.cpp new file mode 100644 index 000000000..1f5a432df --- /dev/null +++ b/tests/auto/api/testdata/disabled-product/main.cpp @@ -0,0 +1 @@ +thiswillnotcompile diff --git a/tests/auto/api/testdata/disabled-project/disabled_project.qbs b/tests/auto/api/testdata/disabled-project/disabled_project.qbs new file mode 100644 index 000000000..1461b70ad --- /dev/null +++ b/tests/auto/api/testdata/disabled-project/disabled_project.qbs @@ -0,0 +1,7 @@ +import qbs +import qbs.File + +Project { + condition: File.exists("blubb"); + references: "blubb/nosuchfile.qbs" +} diff --git a/tests/auto/api/testdata/duplicate-product-names/explicit.qbs b/tests/auto/api/testdata/duplicate-product-names/explicit.qbs new file mode 100644 index 000000000..0183b411c --- /dev/null +++ b/tests/auto/api/testdata/duplicate-product-names/explicit.qbs @@ -0,0 +1,7 @@ +import qbs + +Project { + Product { name: "blubb" } + Product { name: "blubb" } + Product { name: "blubb" } +} diff --git a/tests/auto/api/testdata/duplicate-product-names/implicit-indirect.qbs b/tests/auto/api/testdata/duplicate-product-names/implicit-indirect.qbs new file mode 100644 index 000000000..7164aa1c5 --- /dev/null +++ b/tests/auto/api/testdata/duplicate-product-names/implicit-indirect.qbs @@ -0,0 +1,5 @@ +import qbs + +Project { + references: ["subdir1/subproject.qbs", "subdir2/subproject.qbs"] +} diff --git a/tests/auto/api/testdata/duplicate-product-names/implicit.qbs b/tests/auto/api/testdata/duplicate-product-names/implicit.qbs new file mode 100644 index 000000000..f39f80626 --- /dev/null +++ b/tests/auto/api/testdata/duplicate-product-names/implicit.qbs @@ -0,0 +1,7 @@ +import qbs + +Project { + Product { } + Product { } + Product { } +} diff --git a/tests/auto/api/testdata/duplicate-product-names/subdir1/subproject.qbs b/tests/auto/api/testdata/duplicate-product-names/subdir1/subproject.qbs new file mode 100644 index 000000000..6d16a3c53 --- /dev/null +++ b/tests/auto/api/testdata/duplicate-product-names/subdir1/subproject.qbs @@ -0,0 +1,3 @@ +import qbs + +Product { } diff --git a/tests/auto/api/testdata/duplicate-product-names/subdir2/subproject.qbs b/tests/auto/api/testdata/duplicate-product-names/subdir2/subproject.qbs new file mode 100644 index 000000000..6d16a3c53 --- /dev/null +++ b/tests/auto/api/testdata/duplicate-product-names/subdir2/subproject.qbs @@ -0,0 +1,3 @@ +import qbs + +Product { } diff --git a/tests/auto/api/testdata/dynamic-libs/lib1.cpp b/tests/auto/api/testdata/dynamic-libs/lib1.cpp new file mode 100644 index 000000000..c47b0cfb1 --- /dev/null +++ b/tests/auto/api/testdata/dynamic-libs/lib1.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT +# define IMPORT +#endif + +IMPORT void lib2_hello(); + +EXPORT int lib1_hello() +{ + puts("lib1 says hello!"); + lib2_hello(); + return 0; +} diff --git a/tests/auto/api/testdata/dynamic-libs/lib2.cpp b/tests/auto/api/testdata/dynamic-libs/lib2.cpp new file mode 100644 index 000000000..3c8b6dc6c --- /dev/null +++ b/tests/auto/api/testdata/dynamic-libs/lib2.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT __attribute__((visibility("default"))) +# define IMPORT +#endif + +IMPORT void lib3_hello(); + +EXPORT void lib2_hello() +{ + puts("lib2 says hello!"); + lib3_hello(); +} + diff --git a/tests/auto/api/testdata/dynamic-libs/lib3.cpp b/tests/auto/api/testdata/dynamic-libs/lib3.cpp new file mode 100644 index 000000000..f25d8e883 --- /dev/null +++ b/tests/auto/api/testdata/dynamic-libs/lib3.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT __attribute__((visibility("default"))) +# define IMPORT +#endif + +EXPORT void lib3_hello() +{ + puts("lib3 says hello!"); +} + +EXPORT char* lib3_greeting() +{ + static char greeting[] = "hello"; + return greeting; +} + diff --git a/tests/auto/api/testdata/dynamic-libs/lib4.cpp b/tests/auto/api/testdata/dynamic-libs/lib4.cpp new file mode 100644 index 000000000..c0ead4721 --- /dev/null +++ b/tests/auto/api/testdata/dynamic-libs/lib4.cpp @@ -0,0 +1,15 @@ +#include "lib4.h" + +TestMe::TestMe() +{ +} + +void TestMe::hello1() const +{ + puts("lib4 says hello!"); +} + +void TestMe::hello2Impl() const +{ + puts("lib4 says hello inline!"); +} diff --git a/tests/auto/api/testdata/dynamic-libs/lib4.h b/tests/auto/api/testdata/dynamic-libs/lib4.h new file mode 100644 index 000000000..689e8d146 --- /dev/null +++ b/tests/auto/api/testdata/dynamic-libs/lib4.h @@ -0,0 +1,26 @@ +#ifndef LIB4_H +#define LIB4_H +#include <stdio.h> + +#ifdef TEST_LIB +# if defined(_WIN32) || defined(WIN32) +# define LIB_EXPORT __declspec(dllexport) +# define LIB_NO_EXPORT +# else +# define LIB_EXPORT __attribute__((visibility("default"))) +# endif +#else +# define LIB_EXPORT +#endif + +class LIB_EXPORT TestMe +{ +public: + TestMe(); + void hello1() const; + inline void hello2() const { hello2Impl(); } +private: + void hello2Impl() const; +}; + +#endif // LIB4_H diff --git a/tests/auto/api/testdata/dynamic-libs/link_dynamiclib.qbs b/tests/auto/api/testdata/dynamic-libs/link_dynamiclib.qbs new file mode 100644 index 000000000..53cebc4a9 --- /dev/null +++ b/tests/auto/api/testdata/dynamic-libs/link_dynamiclib.qbs @@ -0,0 +1,62 @@ +import qbs 1.0 + +Project { + Application { + name : "HelloWorld" + destinationDirectory: "bin" + Group { + files : [ "main.cpp" ] + } + Depends { name: "cpp" } + Depends { name: "lib1" } + Depends { name: "lib4" } + } + + DynamicLibrary { + name : "lib1" + destinationDirectory: "bin" + Group { + files : [ "lib1.cpp" ] + } + Depends { name: "cpp" } + Depends { name: "lib2" } + } + + DynamicLibrary { + name : "lib2" + destinationDirectory: "bin" + cpp.visibility: 'default' + Group { + files : [ "lib2.cpp" ] + } + Depends { name: "cpp" } + Depends { name: "lib3" } + } + + DynamicLibrary { + name : "lib3" + destinationDirectory: "bin" + cpp.visibility: 'hidden' + Group { + files : [ "lib3.cpp" ] + } + Depends { name: "cpp" } + } + + DynamicLibrary { + name : "lib4" + destinationDirectory: "bin" + cpp.visibility: 'hiddenInlines' + cpp.defines: "TEST_LIB" + Group { + files : [ "lib4.h", "lib4.cpp" ] + } + Depends { name: "cpp" } + + Export { + Depends { name: "cpp" } + cpp.includePaths: ['.'] + } + } +} + diff --git a/tests/auto/api/testdata/dynamic-libs/main.cpp b/tests/auto/api/testdata/dynamic-libs/main.cpp new file mode 100644 index 000000000..ef6df12e3 --- /dev/null +++ b/tests/auto/api/testdata/dynamic-libs/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> +#include <lib4.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT +# define IMPORT +#endif + +IMPORT int lib1_hello(); + +int main() +{ + puts("application says hello!"); + TestMe test; + test.hello1(); + test.hello2(); + return lib1_hello(); +} + diff --git a/tests/auto/api/testdata/empty-filetag-list/dontcompilethis.cpp b/tests/auto/api/testdata/empty-filetag-list/dontcompilethis.cpp new file mode 100644 index 000000000..bac3b631d --- /dev/null +++ b/tests/auto/api/testdata/empty-filetag-list/dontcompilethis.cpp @@ -0,0 +1 @@ +This is not C++. diff --git a/tests/auto/api/testdata/empty-filetag-list/project.qbs b/tests/auto/api/testdata/empty-filetag-list/project.qbs new file mode 100644 index 000000000..294616124 --- /dev/null +++ b/tests/auto/api/testdata/empty-filetag-list/project.qbs @@ -0,0 +1,8 @@ +import qbs + +CppApplication { + Group { + files: "dontcompilethis.cpp" + fileTags: [] + } +} diff --git a/tests/auto/api/testdata/empty-submodules-list/project.qbs b/tests/auto/api/testdata/empty-submodules-list/project.qbs new file mode 100644 index 000000000..88b5e3177 --- /dev/null +++ b/tests/auto/api/testdata/empty-submodules-list/project.qbs @@ -0,0 +1,8 @@ +import qbs + +CppApplication { + Depends { + name: "dummy" + submodules: [] + } +} diff --git a/tests/auto/api/testdata/explicitly-depends-on/dependency.txt b/tests/auto/api/testdata/explicitly-depends-on/dependency.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/explicitly-depends-on/dependency.txt diff --git a/tests/auto/api/testdata/explicitly-depends-on/project.qbs b/tests/auto/api/testdata/explicitly-depends-on/project.qbs new file mode 100644 index 000000000..3db802717 --- /dev/null +++ b/tests/auto/api/testdata/explicitly-depends-on/project.qbs @@ -0,0 +1,29 @@ +import qbs +import qbs.TextFile + +Product { + type: "mytype" + files: "dependency.txt" + FileTagger { + patterns: "*.txt" + fileTags: ["txt"] + } + Transformer { + explicitlyDependsOn: "txt" + Artifact { + filePath: "test.mytype" + fileTags: product.type + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "Creating output artifact"; + cmd.highlight = "codegen"; + cmd.sourceCode = function() { + var file = new TextFile(output.filePath, TextFile.WriteOnly); + file.truncate(); + file.close(); + } + return cmd; + } + } +} diff --git a/tests/auto/api/testdata/export-simple/lib1.cpp b/tests/auto/api/testdata/export-simple/lib1.cpp new file mode 100644 index 000000000..c3102139d --- /dev/null +++ b/tests/auto/api/testdata/export-simple/lib1.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT +# define IMPORT +#endif + +EXPORT int lib1_hello() +{ + puts("lib1 says hello!"); + return 0; +} diff --git a/tests/auto/api/testdata/export-simple/main.cpp b/tests/auto/api/testdata/export-simple/main.cpp new file mode 100644 index 000000000..6557bf8f1 --- /dev/null +++ b/tests/auto/api/testdata/export-simple/main.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(_WIN32) || defined(WIN32) +# define EXPORT __declspec(dllexport) +# define IMPORT __declspec(dllimport) +#else +# define EXPORT +# define IMPORT +#endif + +IMPORT int lib1_hello(); + +int main() +{ + puts("application says hello!"); + return lib1_hello(); +} + diff --git a/tests/auto/api/testdata/export-simple/project.qbs b/tests/auto/api/testdata/export-simple/project.qbs new file mode 100644 index 000000000..96244671a --- /dev/null +++ b/tests/auto/api/testdata/export-simple/project.qbs @@ -0,0 +1,49 @@ +import qbs 1.0 + +Project { + Application { + name : "HelloWorld" + destinationDirectory: "bin" + Group { + files : [ "main.cpp" ] + } + Depends { name: "cpp" } + Depends { name: 'dummy' } + } + + Product { + name: 'dummy' + Group { + files: 'main.cpp' + qbs.install: true + } + Export { + Depends { name: 'dummy2' } + Properties { // QBS-550 + condition: false + qbs.optimization: "ludicrous speed" + } + } + } + + Product { + name: 'dummy2' + Group { + files: 'lib1.cpp' + qbs.install: true + } + Export { + Depends { name: 'lib1' } + } + } + + DynamicLibrary { + name : "lib1" + destinationDirectory: "bin" + Group { + files : [ "lib1.cpp" ] + } + Depends { name: "cpp" } + } +} + diff --git a/tests/auto/api/testdata/export-with-recursive-depends/main1.cpp b/tests/auto/api/testdata/export-with-recursive-depends/main1.cpp new file mode 100644 index 000000000..237c8ce18 --- /dev/null +++ b/tests/auto/api/testdata/export-with-recursive-depends/main1.cpp @@ -0,0 +1 @@ +int main() {} diff --git a/tests/auto/api/testdata/export-with-recursive-depends/main2.cpp b/tests/auto/api/testdata/export-with-recursive-depends/main2.cpp new file mode 100644 index 000000000..c7f2e65ab --- /dev/null +++ b/tests/auto/api/testdata/export-with-recursive-depends/main2.cpp @@ -0,0 +1,6 @@ +int main() +{ +#ifndef HAS_FOO + blubb(); +#endif +} diff --git a/tests/auto/api/testdata/export-with-recursive-depends/project.qbs b/tests/auto/api/testdata/export-with-recursive-depends/project.qbs new file mode 100644 index 000000000..045e65133 --- /dev/null +++ b/tests/auto/api/testdata/export-with-recursive-depends/project.qbs @@ -0,0 +1,16 @@ +import qbs + +Project { + CppApplication { + name: "app1" + files: "main1.cpp" + Export { Depends { name: "module1" } } + } + + CppApplication { + name: "app2" + Depends { name: "app1" } + files: "main2.cpp" + } + qbsSearchPaths: "qbs" +} diff --git a/tests/auto/api/testdata/export-with-recursive-depends/qbs/modules/module1/module1.qbs b/tests/auto/api/testdata/export-with-recursive-depends/qbs/modules/module1/module1.qbs new file mode 100644 index 000000000..c1c4ad358 --- /dev/null +++ b/tests/auto/api/testdata/export-with-recursive-depends/qbs/modules/module1/module1.qbs @@ -0,0 +1,5 @@ +import qbs + +Module { + Depends { name: "module2" } +} diff --git a/tests/auto/api/testdata/export-with-recursive-depends/qbs/modules/module2/module2.qbs b/tests/auto/api/testdata/export-with-recursive-depends/qbs/modules/module2/module2.qbs new file mode 100644 index 000000000..75a274631 --- /dev/null +++ b/tests/auto/api/testdata/export-with-recursive-depends/qbs/modules/module2/module2.qbs @@ -0,0 +1,6 @@ +import qbs + +Module { + Depends { name: "cpp" } + cpp.defines: ["HAS_FOO"] +} diff --git a/tests/auto/api/testdata/file-tagger/bla.txt b/tests/auto/api/testdata/file-tagger/bla.txt new file mode 100644 index 000000000..26185684a --- /dev/null +++ b/tests/auto/api/testdata/file-tagger/bla.txt @@ -0,0 +1,15 @@ +#include <QObject> + +class MyObject : public QObject +{ + Q_OBJECT +}; + +int main() +{ + MyObject obj; + return 0; +} + +#include "bla.moc" + diff --git a/tests/auto/api/testdata/file-tagger/moc_cpp.qbs b/tests/auto/api/testdata/file-tagger/moc_cpp.qbs new file mode 100644 index 000000000..ce7970f20 --- /dev/null +++ b/tests/auto/api/testdata/file-tagger/moc_cpp.qbs @@ -0,0 +1,42 @@ +import qbs 1.0 +import qbs.TextFile +import qbs.FileInfo + +Project { + Product { + type: "application" + name: "moc_cpp" + + Depends { + name: "Qt.core" + } + + Group { + files: 'bla.txt' + fileTags: ['text'] + } + } + + Rule { + inputs: ['text'] + Artifact { + fileTags: ['cpp'] + filePath: input.baseName + '.cpp' + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.sourceCode = function () { + var file = new TextFile(input.filePath, TextFile.ReadOnly); + var text = file.readAll(); + file.close(); + file = new TextFile(output.filePath, TextFile.WriteOnly); + file.truncate(); + file.write(text); + file.close(); + } + cmd.description = 'generating ' + FileInfo.fileName(output.filePath); + cmd.highlight = 'codegen'; + return cmd; + } + } +} diff --git a/tests/auto/api/testdata/inherit-qbs-search-paths/imports/Foo.qbs b/tests/auto/api/testdata/inherit-qbs-search-paths/imports/Foo.qbs new file mode 100644 index 000000000..f6c1733b5 --- /dev/null +++ b/tests/auto/api/testdata/inherit-qbs-search-paths/imports/Foo.qbs @@ -0,0 +1,7 @@ +import qbs 1.0 + +Product { + type: "application" + Depends { name: 'bli' } +} + diff --git a/tests/auto/api/testdata/inherit-qbs-search-paths/main.cpp b/tests/auto/api/testdata/inherit-qbs-search-paths/main.cpp new file mode 100644 index 000000000..7382cd2dd --- /dev/null +++ b/tests/auto/api/testdata/inherit-qbs-search-paths/main.cpp @@ -0,0 +1,9 @@ +#ifndef HAVE_BLI +#error HAVE_BLI missing! +#endif + +int main() +{ + return 0; +} + diff --git a/tests/auto/api/testdata/inherit-qbs-search-paths/prj.qbs b/tests/auto/api/testdata/inherit-qbs-search-paths/prj.qbs new file mode 100644 index 000000000..ba8284f4f --- /dev/null +++ b/tests/auto/api/testdata/inherit-qbs-search-paths/prj.qbs @@ -0,0 +1,10 @@ +import qbs 1.0 +import "imports/Foo.qbs" as Foo + +Project { + qbsSearchPaths: "subdir" + Foo { + files: "main.cpp" + } +} + diff --git a/tests/auto/api/testdata/inherit-qbs-search-paths/subdir/modules/bli/m.qbs b/tests/auto/api/testdata/inherit-qbs-search-paths/subdir/modules/bli/m.qbs new file mode 100644 index 000000000..b4b93678a --- /dev/null +++ b/tests/auto/api/testdata/inherit-qbs-search-paths/subdir/modules/bli/m.qbs @@ -0,0 +1,7 @@ +import qbs 1.0 + +Module { + Depends {name : "cpp" } + cpp.defines: ["HAVE_BLI"] +} + diff --git a/tests/auto/api/testdata/lib-same-source/main.cpp b/tests/auto/api/testdata/lib-same-source/main.cpp new file mode 100644 index 000000000..32de334c8 --- /dev/null +++ b/tests/auto/api/testdata/lib-same-source/main.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +int main() +{ + puts("Hello WOrld!"); +} diff --git a/tests/auto/api/testdata/lib-same-source/project.qbs b/tests/auto/api/testdata/lib-same-source/project.qbs new file mode 100644 index 000000000..063684b40 --- /dev/null +++ b/tests/auto/api/testdata/lib-same-source/project.qbs @@ -0,0 +1,22 @@ +import qbs 1.0 + +Project { + Product { + type: "application" + name : "HelloWorldApp" + Depends { name: 'cpp' } + Group { + files : [ "main.cpp" ] + } + } + + Product { + type: "staticlibrary" + name : "HelloWorldLib" + Depends { name: 'cpp' } + Group { + files : [ "main.cpp" ] + } + } +} + diff --git a/tests/auto/api/testdata/link-static-lib/helper1/helper1.cpp b/tests/auto/api/testdata/link-static-lib/helper1/helper1.cpp new file mode 100644 index 000000000..4ae0068d7 --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/helper1/helper1.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#include "helper1.h" +#include <helper2.h> + +int getSomeNumber() +{ + return 12 * getOddNumber(); +} + diff --git a/tests/auto/api/testdata/link-static-lib/helper1/helper1.h b/tests/auto/api/testdata/link-static-lib/helper1/helper1.h new file mode 100644 index 000000000..8ca6e5acf --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/helper1/helper1.h @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#ifndef HELPER1_H +#define HELPER1_H + +extern int getSomeNumber(); + +#endif + diff --git a/tests/auto/api/testdata/link-static-lib/helper2/helper2.cpp b/tests/auto/api/testdata/link-static-lib/helper2/helper2.cpp new file mode 100644 index 000000000..7a70aef5d --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/helper2/helper2.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#include "helper2.h" + +int getOddNumber() +{ + return 13; +} + diff --git a/tests/auto/api/testdata/link-static-lib/helper2/helper2.h b/tests/auto/api/testdata/link-static-lib/helper2/helper2.h new file mode 100644 index 000000000..9306d8576 --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/helper2/helper2.h @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#ifndef HELPER2_H +#define HELPER2_H + +extern int getOddNumber(); + +#endif + diff --git a/tests/auto/api/testdata/link-static-lib/main.cpp b/tests/auto/api/testdata/link-static-lib/main.cpp new file mode 100644 index 000000000..cc0453ad6 --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/main.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +int bla(); + +int main() +{ + return bla(); +} + diff --git a/tests/auto/api/testdata/link-static-lib/mystaticlib.cpp b/tests/auto/api/testdata/link-static-lib/mystaticlib.cpp new file mode 100644 index 000000000..aa3138692 --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/mystaticlib.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> +#include <helper1.h> + +int bla() +{ + int n = getSomeNumber(); + printf("Hello World! The magic number is %d.", n); + return n; +} diff --git a/tests/auto/api/testdata/link-static-lib/mystaticlibhelper.cpp b/tests/auto/api/testdata/link-static-lib/mystaticlibhelper.cpp new file mode 100644 index 000000000..76a6a38e9 --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/mystaticlibhelper.cpp @@ -0,0 +1,5 @@ +int helper_function() +{ + return 156; +} + diff --git a/tests/auto/api/testdata/link-static-lib/project.qbs b/tests/auto/api/testdata/link-static-lib/project.qbs new file mode 100644 index 000000000..be12e01aa --- /dev/null +++ b/tests/auto/api/testdata/link-static-lib/project.qbs @@ -0,0 +1,46 @@ +import qbs 1.0 + +Project { + Product { + type: "application" + name: "HelloWorld" + files : [ "main.cpp" ] + Depends { name: "cpp" } + Depends { name: "mystaticlib" } + } + + StaticLibrary { + name : "mystaticlib" + files : [ "mystaticlib.cpp" ] + Depends { name: "cpp" } + Depends { name: "helper1" } + } + + StaticLibrary { + name : "helper1" + files : [ + "helper1/helper1.h", + "helper1/helper1.cpp" + ] + Depends { name: "cpp" } + Depends { name: "helper2" } + Export { + Depends { name: "cpp" } + cpp.includePaths: ['helper1'] + } + } + + StaticLibrary { + name : "helper2" + files : [ + "helper2/helper2.h", + "helper2/helper2.cpp" + ] + Depends { name: "cpp" } + Export { + Depends { name: "cpp" } + cpp.includePaths: ['helper2'] + } + } +} + diff --git a/tests/auto/api/testdata/lots-of-dots/dotty.matrix.ui b/tests/auto/api/testdata/lots-of-dots/dotty.matrix.ui new file mode 100644 index 000000000..4b7d6a45f --- /dev/null +++ b/tests/auto/api/testdata/lots-of-dots/dotty.matrix.ui @@ -0,0 +1,21 @@ +<ui version="4.0" > + <author></author> + <comment></comment> + <exportmacro></exportmacro> + <class>Form</class> + <widget class="QWidget" name="Form" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle" > + <string>Form</string> + </property> + </widget> + <pixmapfunction></pixmapfunction> + <connections/> +</ui> diff --git a/tests/auto/api/testdata/lots-of-dots/m.a.i.n.cpp b/tests/auto/api/testdata/lots-of-dots/m.a.i.n.cpp new file mode 100644 index 000000000..4975bc680 --- /dev/null +++ b/tests/auto/api/testdata/lots-of-dots/m.a.i.n.cpp @@ -0,0 +1,10 @@ +#include "object.narf.h" +#include <ui_dotty.matrix.h> +#include <cstdio> + +int main() +{ + ObjectNarf obj; + puts("..."); +} + diff --git a/tests/auto/api/testdata/lots-of-dots/object.narf.cpp b/tests/auto/api/testdata/lots-of-dots/object.narf.cpp new file mode 100644 index 000000000..a8761e53b --- /dev/null +++ b/tests/auto/api/testdata/lots-of-dots/object.narf.cpp @@ -0,0 +1,7 @@ +#include "object.narf.h" +#include <cstdio> + +ObjectNarf::ObjectNarf(QObject *parent) + : QObject(parent) +{} + diff --git a/tests/auto/api/testdata/lots-of-dots/object.narf.h b/tests/auto/api/testdata/lots-of-dots/object.narf.h new file mode 100644 index 000000000..bb1868cc0 --- /dev/null +++ b/tests/auto/api/testdata/lots-of-dots/object.narf.h @@ -0,0 +1,13 @@ +#ifndef OBJECT_H +#define OBJECT_H +#include <QObject> + +class ObjectNarf : public QObject +{ + Q_OBJECT +public: + ObjectNarf(QObject *parent = 0); +}; + +#endif + diff --git a/tests/auto/api/testdata/lots-of-dots/polka.dots.qrc b/tests/auto/api/testdata/lots-of-dots/polka.dots.qrc new file mode 100644 index 000000000..815b11002 --- /dev/null +++ b/tests/auto/api/testdata/lots-of-dots/polka.dots.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/bernadotte"> + <file>m.a.i.n.cpp</file> + </qresource> +</RCC> diff --git a/tests/auto/api/testdata/lots-of-dots/project.qbs b/tests/auto/api/testdata/lots-of-dots/project.qbs new file mode 100644 index 000000000..9654100fc --- /dev/null +++ b/tests/auto/api/testdata/lots-of-dots/project.qbs @@ -0,0 +1,17 @@ +import qbs 1.0 + +Project { + QtGuiApplication { + type: "application" + name: "lots.of.dots" + + files : [ + "m.a.i.n.cpp", + "object.narf.h", + "object.narf.cpp", + "polka.dots.qrc", + "dotty.matrix.ui" + ] + } +} + diff --git a/tests/auto/api/testdata/missing-qobject-header/main.cpp b/tests/auto/api/testdata/missing-qobject-header/main.cpp new file mode 100644 index 000000000..191b3b316 --- /dev/null +++ b/tests/auto/api/testdata/missing-qobject-header/main.cpp @@ -0,0 +1,6 @@ +#include "myobject.h" + +int main() +{ + MyObject().func(); +} diff --git a/tests/auto/api/testdata/missing-qobject-header/myobject.cpp b/tests/auto/api/testdata/missing-qobject-header/myobject.cpp new file mode 100644 index 000000000..249e198ad --- /dev/null +++ b/tests/auto/api/testdata/missing-qobject-header/myobject.cpp @@ -0,0 +1,5 @@ +#include "myobject.h" + +void MyObject::func() +{ +} diff --git a/tests/auto/api/testdata/missing-qobject-header/myobject.h b/tests/auto/api/testdata/missing-qobject-header/myobject.h new file mode 100644 index 000000000..46353c30e --- /dev/null +++ b/tests/auto/api/testdata/missing-qobject-header/myobject.h @@ -0,0 +1,10 @@ +#include <QObject> + +class MyObject : public QObject +{ + Q_OBJECT + +public: + void func(); + +}; diff --git a/tests/auto/api/testdata/moc-cpp/bla.cpp b/tests/auto/api/testdata/moc-cpp/bla.cpp new file mode 100644 index 000000000..26185684a --- /dev/null +++ b/tests/auto/api/testdata/moc-cpp/bla.cpp @@ -0,0 +1,15 @@ +#include <QObject> + +class MyObject : public QObject +{ + Q_OBJECT +}; + +int main() +{ + MyObject obj; + return 0; +} + +#include "bla.moc" + diff --git a/tests/auto/api/testdata/moc-cpp/project.qbs b/tests/auto/api/testdata/moc-cpp/project.qbs new file mode 100644 index 000000000..311d7c490 --- /dev/null +++ b/tests/auto/api/testdata/moc-cpp/project.qbs @@ -0,0 +1,14 @@ +import qbs 1.0 + +Project { + Product { + type: "application" + name: "moc_cpp" + + Depends { + name: "Qt.core" + } + + files: ["bla.cpp"] + } +} diff --git a/tests/auto/api/testdata/moc-hpp-included/object.cpp b/tests/auto/api/testdata/moc-hpp-included/object.cpp new file mode 100644 index 000000000..ef0b32417 --- /dev/null +++ b/tests/auto/api/testdata/moc-hpp-included/object.cpp @@ -0,0 +1,15 @@ +#include "object.h" + +Object::Object(QObject *parent) + : QObject(parent) +{} + +#include "moc_object.cpp" +#include <cstdio> + +int main() +{ + Object obj; + printf("Hello World\n"); +} + diff --git a/tests/auto/api/testdata/moc-hpp-included/object.h b/tests/auto/api/testdata/moc-hpp-included/object.h new file mode 100644 index 000000000..7d8f59c6c --- /dev/null +++ b/tests/auto/api/testdata/moc-hpp-included/object.h @@ -0,0 +1,13 @@ +#ifndef OBJECT_H +#define OBJECT_H +#include <QObject> + +class Object : public QObject +{ + Q_OBJECT +public: + Object(QObject *parent = 0); +}; + +#endif + diff --git a/tests/auto/api/testdata/moc-hpp-included/project.qbs b/tests/auto/api/testdata/moc-hpp-included/project.qbs new file mode 100644 index 000000000..b144fb672 --- /dev/null +++ b/tests/auto/api/testdata/moc-hpp-included/project.qbs @@ -0,0 +1,18 @@ +import qbs 1.0 + +Project { + Product { + type: "application" + name: "moc_hpp_included" + + Depends { name: "Qt.core" } + + files : [ "object.cpp" ] + + Group { + files : [ "object.h" ] + fileTags: [ "hpp" ] + } + } +} + diff --git a/tests/auto/api/testdata/moc-hpp/object.cpp b/tests/auto/api/testdata/moc-hpp/object.cpp new file mode 100644 index 000000000..8c091c58c --- /dev/null +++ b/tests/auto/api/testdata/moc-hpp/object.cpp @@ -0,0 +1,13 @@ +#include "object.h" +#include <cstdio> + +Object::Object(QObject *parent) + : QObject(parent) +{} + +int main() +{ + Object obj; + printf("Hello World\n"); +} + diff --git a/tests/auto/api/testdata/moc-hpp/object.h b/tests/auto/api/testdata/moc-hpp/object.h new file mode 100644 index 000000000..7d8f59c6c --- /dev/null +++ b/tests/auto/api/testdata/moc-hpp/object.h @@ -0,0 +1,13 @@ +#ifndef OBJECT_H +#define OBJECT_H +#include <QObject> + +class Object : public QObject +{ + Q_OBJECT +public: + Object(QObject *parent = 0); +}; + +#endif + diff --git a/tests/auto/api/testdata/moc-hpp/project.qbs b/tests/auto/api/testdata/moc-hpp/project.qbs new file mode 100644 index 000000000..87ddfc335 --- /dev/null +++ b/tests/auto/api/testdata/moc-hpp/project.qbs @@ -0,0 +1,16 @@ +import qbs 1.0 + +Project { + Product { + type: "application" + name: "moc_hpp" + + Depends { name: "Qt.core" } + + files : [ + "object.h", + "object.cpp" + ] + } +} + diff --git a/tests/auto/api/testdata/new-output-artifact-in-dependency/lib.cpp b/tests/auto/api/testdata/new-output-artifact-in-dependency/lib.cpp new file mode 100644 index 000000000..7fd25b792 --- /dev/null +++ b/tests/auto/api/testdata/new-output-artifact-in-dependency/lib.cpp @@ -0,0 +1,3 @@ +#include <QtGlobal> + +Q_DECL_EXPORT void f() {} diff --git a/tests/auto/api/testdata/new-output-artifact-in-dependency/main.cpp b/tests/auto/api/testdata/new-output-artifact-in-dependency/main.cpp new file mode 100644 index 000000000..b44adf42f --- /dev/null +++ b/tests/auto/api/testdata/new-output-artifact-in-dependency/main.cpp @@ -0,0 +1,6 @@ +//void f(); + +int main() +{ +// f(); +} diff --git a/tests/auto/api/testdata/new-output-artifact-in-dependency/project.qbs b/tests/auto/api/testdata/new-output-artifact-in-dependency/project.qbs new file mode 100644 index 000000000..2fc85e9a9 --- /dev/null +++ b/tests/auto/api/testdata/new-output-artifact-in-dependency/project.qbs @@ -0,0 +1,16 @@ +import qbs + +Project { + DynamicLibrary { + //Depends { name: "cpp" } + //Depends { name: "Qt.core" } + name: "lib" + files: "lib.cpp" + } + + CppApplication { + name: "app" + files: "main.cpp" + Depends { name: "lib" } + } +} diff --git a/tests/auto/api/testdata/new-pattern-match/project.qbs b/tests/auto/api/testdata/new-pattern-match/project.qbs new file mode 100644 index 000000000..18975da75 --- /dev/null +++ b/tests/auto/api/testdata/new-pattern-match/project.qbs @@ -0,0 +1,5 @@ +import qbs + +Product { + files: "*.txt" +} diff --git a/tests/auto/api/testdata/objc/main.mm b/tests/auto/api/testdata/objc/main.mm new file mode 100644 index 000000000..49b4f3915 --- /dev/null +++ b/tests/auto/api/testdata/objc/main.mm @@ -0,0 +1,14 @@ +#import <Foundation/Foundation.h> +#include <QCoreApplication> + +int main(int argc, char **argv) +{ + // We support both C++ + QCoreApplication app(argc, argv); + Q_UNUSED(app); + // And Objective-C + NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; + NSString *productVersion = [version objectForKey:@"ProductVersion"]; + NSLog(@"Hello, OS X %@!", productVersion); + // So it's Objective-C++ +} diff --git a/tests/auto/api/testdata/objc/objc.qbs b/tests/auto/api/testdata/objc/objc.qbs new file mode 100644 index 000000000..c069c5032 --- /dev/null +++ b/tests/auto/api/testdata/objc/objc.qbs @@ -0,0 +1,9 @@ +import qbs 1.0 + +Project { + QtApplication { + condition: qbs.targetOS.contains("osx") + files: "main.mm" + cpp.frameworks: [ "Foundation" ] + } +} diff --git a/tests/auto/api/testdata/precompiled-header/main.cpp b/tests/auto/api/testdata/precompiled-header/main.cpp new file mode 100644 index 000000000..400762bc6 --- /dev/null +++ b/tests/auto/api/testdata/precompiled-header/main.cpp @@ -0,0 +1,27 @@ +#include "myobject.h" +#include <algorithm> +#include <iostream> +#include <list> + +using namespace std; + +int main() +{ + MyObject obj; + list<int> lst; + lst.push_back(1); + lst.push_back(2); + lst.push_back(3); + lst.push_back(4); + lst.push_back(5); + lst.push_back(6); + lst.push_back(7); + lst.push_back(8); + lst.push_back(9); + reverse(lst.begin(), lst.end()); + for (list<int>::iterator it=lst.begin(); it != lst.end(); ++it) + cout << *it << ", "; + cout << endl; + return 0; +} + diff --git a/tests/auto/api/testdata/precompiled-header/myobject.cpp b/tests/auto/api/testdata/precompiled-header/myobject.cpp new file mode 100644 index 000000000..9f3f93740 --- /dev/null +++ b/tests/auto/api/testdata/precompiled-header/myobject.cpp @@ -0,0 +1,13 @@ +#include <iostream> +#include "myobject.h" + +MyObject::MyObject() +{ + std::cout << "MyObject::MyObject()\n"; +} + +MyObject::~MyObject() +{ + std::cout << "MyObject::~MyObject()" << std::endl; +} + diff --git a/tests/auto/api/testdata/precompiled-header/myobject.h b/tests/auto/api/testdata/precompiled-header/myobject.h new file mode 100644 index 000000000..376f0da66 --- /dev/null +++ b/tests/auto/api/testdata/precompiled-header/myobject.h @@ -0,0 +1,15 @@ +#ifndef MYOBJECT_H +#define MYOBJECT_H + +#include <QtCore/QObject> + +class MyObject : public QObject +{ + Q_OBJECT +public: + MyObject(); + ~MyObject(); +}; + +#endif + diff --git a/tests/auto/api/testdata/precompiled-header/project.qbs b/tests/auto/api/testdata/precompiled-header/project.qbs new file mode 100644 index 000000000..de65b9330 --- /dev/null +++ b/tests/auto/api/testdata/precompiled-header/project.qbs @@ -0,0 +1,14 @@ +import qbs 1.0 + +Product { + type: "application" + name: "MyApp" + files: ["stable.h", + "myobject.h", + "main.cpp", + "myobject.cpp"] + Depends { name: "cpp" } + cpp.precompiledHeader: "stable.h" + Depends { name: "Qt.core" } +} + diff --git a/tests/auto/api/testdata/precompiled-header/stable.h b/tests/auto/api/testdata/precompiled-header/stable.h new file mode 100644 index 000000000..93ce3cb29 --- /dev/null +++ b/tests/auto/api/testdata/precompiled-header/stable.h @@ -0,0 +1,9 @@ +/* Add C includes here */ + +#if defined __cplusplus +/* Add C++ includes here */ + +# include <iostream> +# include <algorithm> +#endif + diff --git a/tests/auto/api/testdata/project-with-properties-item/project.qbs b/tests/auto/api/testdata/project-with-properties-item/project.qbs new file mode 100644 index 000000000..d59a26a94 --- /dev/null +++ b/tests/auto/api/testdata/project-with-properties-item/project.qbs @@ -0,0 +1,12 @@ +import qbs 1.0 + +Project { + property string binPath: "/usr/bin" + property string libPath: "/usr/lib" + + Properties { + condition: qbs.targetOS.contains("osx") + binPath: "/Users/boo" + libPath: "/Libraries/foo" + } +} diff --git a/tests/auto/api/testdata/properties-blocks/main.cpp b/tests/auto/api/testdata/properties-blocks/main.cpp new file mode 100644 index 000000000..c2304641c --- /dev/null +++ b/tests/auto/api/testdata/properties-blocks/main.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <stdio.h> + +#ifndef HAVE_MAIN_CPP +# error missing define HAVE_MAIN_CPP +#endif +#ifndef DEFINE_IN_PROPERTIES +# error missing define DEFINE_IN_PROPERTIES +#endif + +int main() +{ +#ifdef _DEBUG + puts("Hello World! (debug version)"); +#else + puts("Hello World! (release version)"); +#endif +} + diff --git a/tests/auto/api/testdata/properties-blocks/propertiesblocks.qbs b/tests/auto/api/testdata/properties-blocks/propertiesblocks.qbs new file mode 100644 index 000000000..5fe02a103 --- /dev/null +++ b/tests/auto/api/testdata/properties-blocks/propertiesblocks.qbs @@ -0,0 +1,28 @@ +import qbs 1.0 + +Product { + Depends { name: 'cpp' } + + Properties { + condition: true + type: 'application' + name: 'HelloWorld' + } + + Properties { + condition: name == 'HelloWorld' + cpp.defines: ['DEFINE_IN_PROPERTIES'] + } + + Properties { + condition: qbs.targetOS.contains("weird") + cpp.staticLibraries: "abc" + } + + Group { + cpp.defines: outer.concat(['HAVE_MAIN_CPP', cpp.debugInformation ? '_DEBUG' : '_RELEASE']) + files: ['main.cpp'] + } +} + + diff --git a/tests/auto/api/testdata/qt5-plugin/echointerface.h b/tests/auto/api/testdata/qt5-plugin/echointerface.h new file mode 100644 index 000000000..228a911e6 --- /dev/null +++ b/tests/auto/api/testdata/qt5-plugin/echointerface.h @@ -0,0 +1,24 @@ + +#ifndef ECHOINTERFACE_H +#define ECHOINTERFACE_H + +#include <QString> + +//! [0] +class EchoInterface +{ +public: + virtual ~EchoInterface() {} + virtual QString echo(const QString &message) = 0; +}; + + +QT_BEGIN_NAMESPACE + +#define EchoInterface_iid "org.qt-project.Qt.Examples.EchoInterface" + +Q_DECLARE_INTERFACE(EchoInterface, EchoInterface_iid) +QT_END_NAMESPACE + +//! [0] +#endif diff --git a/tests/auto/api/testdata/qt5-plugin/echoplugin.cpp b/tests/auto/api/testdata/qt5-plugin/echoplugin.cpp new file mode 100644 index 000000000..b6747a82b --- /dev/null +++ b/tests/auto/api/testdata/qt5-plugin/echoplugin.cpp @@ -0,0 +1,6 @@ +#include "echoplugin.h" + +QString EchoPlugin::echo(const QString &message) +{ + return message; +} diff --git a/tests/auto/api/testdata/qt5-plugin/echoplugin.h b/tests/auto/api/testdata/qt5-plugin/echoplugin.h new file mode 100644 index 000000000..9f8d71c5c --- /dev/null +++ b/tests/auto/api/testdata/qt5-plugin/echoplugin.h @@ -0,0 +1,19 @@ + +#ifndef ECHOPLUGIN_H +#define ECHOPLUGIN_H + +#include <QObject> +#include <QtPlugin> +#include "echointerface.h" + +class EchoPlugin : public QObject, EchoInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.EchoInterface" FILE "echoplugin.json") + Q_INTERFACES(EchoInterface) + +public: + QString echo(const QString &message); +}; + +#endif diff --git a/tests/auto/api/testdata/qt5-plugin/echoplugin.json.source b/tests/auto/api/testdata/qt5-plugin/echoplugin.json.source new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/auto/api/testdata/qt5-plugin/echoplugin.json.source @@ -0,0 +1 @@ +{} diff --git a/tests/auto/api/testdata/qt5-plugin/echoplugin_dummy.cpp b/tests/auto/api/testdata/qt5-plugin/echoplugin_dummy.cpp new file mode 100644 index 000000000..baa060d28 --- /dev/null +++ b/tests/auto/api/testdata/qt5-plugin/echoplugin_dummy.cpp @@ -0,0 +1 @@ +void dummyFunc() {} diff --git a/tests/auto/api/testdata/qt5-plugin/project.qbs b/tests/auto/api/testdata/qt5-plugin/project.qbs new file mode 100644 index 000000000..2944198f3 --- /dev/null +++ b/tests/auto/api/testdata/qt5-plugin/project.qbs @@ -0,0 +1,42 @@ +import qbs.base +import qbs.File +import qbs.FileInfo + +DynamicLibrary { + name: "echoplugin" + + Depends { name: "Qt.core" } + Depends { name: "cpp" } + + Group { + condition: Qt.core.versionMajor >= 5 + files: [ + "echoplugin.h", + "echoplugin.cpp", + "echoplugin.json.source" + ] + } + Group { + condition: Qt.core.versionMajor < 5 + files: "echoplugin_dummy.cpp" + } + + cpp.includePaths: buildDirectory + + Transformer { + condition: Qt.core.versionMajor >= 5 + inputs: ["echoplugin.json.source"] + Artifact { + filePath: "echoplugin.json" + fileTags: ["qt_plugin_metadata"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating " + FileInfo.fileName(output.filePath); + cmd.sourceCode = function() { + File.copy(input.filePath, output.filePath); + } + return cmd; + } + } +} diff --git a/tests/auto/api/testdata/rc/main.cpp b/tests/auto/api/testdata/rc/main.cpp new file mode 100644 index 000000000..6ea3f271f --- /dev/null +++ b/tests/auto/api/testdata/rc/main.cpp @@ -0,0 +1,33 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +int main() +{ + return 0; +} diff --git a/tests/auto/api/testdata/rc/rc.qbs b/tests/auto/api/testdata/rc/rc.qbs new file mode 100644 index 000000000..75502cf88 --- /dev/null +++ b/tests/auto/api/testdata/rc/rc.qbs @@ -0,0 +1,14 @@ +import qbs 1.0 + +Application { + type: "application" + name: "rc" + + Depends { name: 'cpp' } + + files: [ + "main.cpp", + "test.rc" + ] +} + diff --git a/tests/auto/api/testdata/rc/test.rc b/tests/auto/api/testdata/rc/test.rc new file mode 100644 index 000000000..a8e5fd39b --- /dev/null +++ b/tests/auto/api/testdata/rc/test.rc @@ -0,0 +1,22 @@ +#define IDR_VERSION1 1 + +IDR_VERSION1 VERSIONINFO +FILEVERSION 1,0,0,0 +PRODUCTVERSION 1,0,0,0 +FILEOS 0x00000004 +FILETYPE 0x00000000 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "FFFF0000" + BEGIN + VALUE "FileVersion", "1.0.0.0\0" + VALUE "ProductVersion", "1.0.0.0\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0xFFFF, 0x0000 + END +END + diff --git a/tests/auto/api/testdata/remove-file-dependency/main.cpp b/tests/auto/api/testdata/remove-file-dependency/main.cpp new file mode 100644 index 000000000..77727cf42 --- /dev/null +++ b/tests/auto/api/testdata/remove-file-dependency/main.cpp @@ -0,0 +1,9 @@ +#include "someheader.h" +#include <cstdio> + +int main() +{ + printf("The magic value is %d.\n", magicValue()); + return 0; +} + diff --git a/tests/auto/api/testdata/remove-file-dependency/removeFileDependency.qbs b/tests/auto/api/testdata/remove-file-dependency/removeFileDependency.qbs new file mode 100644 index 000000000..8ed927761 --- /dev/null +++ b/tests/auto/api/testdata/remove-file-dependency/removeFileDependency.qbs @@ -0,0 +1,7 @@ +import qbs + +CppApplication { + files: ["main.cpp"] + // Do not reference header files here to force them to be FileDependency objects. +} + diff --git a/tests/auto/api/testdata/remove-file-dependency/someheader.h b/tests/auto/api/testdata/remove-file-dependency/someheader.h new file mode 100644 index 000000000..b895e465c --- /dev/null +++ b/tests/auto/api/testdata/remove-file-dependency/someheader.h @@ -0,0 +1 @@ +inline int magicValue() { return 156; } diff --git a/tests/auto/api/testdata/rename-product/lib.cpp b/tests/auto/api/testdata/rename-product/lib.cpp new file mode 100644 index 000000000..47ce43bc9 --- /dev/null +++ b/tests/auto/api/testdata/rename-product/lib.cpp @@ -0,0 +1,3 @@ +#include <QtGlobal> + +MY_EXPORT void f() { } diff --git a/tests/auto/api/testdata/rename-product/main.cpp b/tests/auto/api/testdata/rename-product/main.cpp new file mode 100644 index 000000000..6a0bac9f1 --- /dev/null +++ b/tests/auto/api/testdata/rename-product/main.cpp @@ -0,0 +1,6 @@ +void f(); + +int main() +{ + f(); +} diff --git a/tests/auto/api/testdata/rename-product/rename.qbs b/tests/auto/api/testdata/rename-product/rename.qbs new file mode 100644 index 000000000..a2fe2e22f --- /dev/null +++ b/tests/auto/api/testdata/rename-product/rename.qbs @@ -0,0 +1,17 @@ +import qbs + +Project { + CppApplication { + Depends { name: "TheLib" } + cpp.defines: "MY_EXPORT=" + files: "main.cpp" + } + + DynamicLibrary { + name: "TheLib" + Depends { name: "cpp" } + Depends { name: "Qt.core" } + cpp.defines: "MY_EXPORT=Q_DECL_EXPORT" + files: "lib.cpp" + } +} diff --git a/tests/auto/api/testdata/rename-target-artifact/lib.cpp b/tests/auto/api/testdata/rename-target-artifact/lib.cpp new file mode 100644 index 000000000..47ce43bc9 --- /dev/null +++ b/tests/auto/api/testdata/rename-target-artifact/lib.cpp @@ -0,0 +1,3 @@ +#include <QtGlobal> + +MY_EXPORT void f() { } diff --git a/tests/auto/api/testdata/rename-target-artifact/main.cpp b/tests/auto/api/testdata/rename-target-artifact/main.cpp new file mode 100644 index 000000000..6a0bac9f1 --- /dev/null +++ b/tests/auto/api/testdata/rename-target-artifact/main.cpp @@ -0,0 +1,6 @@ +void f(); + +int main() +{ + f(); +} diff --git a/tests/auto/api/testdata/rename-target-artifact/rename.qbs b/tests/auto/api/testdata/rename-target-artifact/rename.qbs new file mode 100644 index 000000000..5a8c765e4 --- /dev/null +++ b/tests/auto/api/testdata/rename-target-artifact/rename.qbs @@ -0,0 +1,18 @@ +import qbs + +Project { + CppApplication { + Depends { name: "TheLib" } + cpp.defines: "MY_EXPORT=" + files: "main.cpp" + } + + DynamicLibrary { + name: "TheLib" + targetName: "the_lib" + Depends { name: "cpp" } + Depends { name: "Qt.core" } + cpp.defines: "MY_EXPORT=Q_DECL_EXPORT" + files: "lib.cpp" + } +} diff --git a/tests/auto/api/testdata/same-base-name/lib.c b/tests/auto/api/testdata/same-base-name/lib.c new file mode 100644 index 000000000..6055ed681 --- /dev/null +++ b/tests/auto/api/testdata/same-base-name/lib.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +extern void printHelloC() +{ + printf("Hello from C in " __FILE__ "\n"); +} diff --git a/tests/auto/api/testdata/same-base-name/lib.cpp b/tests/auto/api/testdata/same-base-name/lib.cpp new file mode 100644 index 000000000..933fa8036 --- /dev/null +++ b/tests/auto/api/testdata/same-base-name/lib.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +extern "C" void printHelloCpp() +{ + std::cout << "Hello from C++ in " << __FILE__ << std::endl; +} diff --git a/tests/auto/api/testdata/same-base-name/lib.m b/tests/auto/api/testdata/same-base-name/lib.m new file mode 100644 index 000000000..17cd2dceb --- /dev/null +++ b/tests/auto/api/testdata/same-base-name/lib.m @@ -0,0 +1,6 @@ +#import <Foundation/Foundation.h> + +extern void printHelloObjc() +{ + NSLog(@"Hello from Objective-C in " __FILE__); +} diff --git a/tests/auto/api/testdata/same-base-name/lib.mm b/tests/auto/api/testdata/same-base-name/lib.mm new file mode 100644 index 000000000..ee284b080 --- /dev/null +++ b/tests/auto/api/testdata/same-base-name/lib.mm @@ -0,0 +1,8 @@ +#include <iostream> +#import <Foundation/Foundation.h> + +extern "C" void printHelloObjcpp() +{ + NSLog(@"Hello from Objective-C++..."); + std::cout << "...in " __FILE__ << std::endl; +} diff --git a/tests/auto/api/testdata/same-base-name/main.c b/tests/auto/api/testdata/same-base-name/main.c new file mode 100644 index 000000000..07da20307 --- /dev/null +++ b/tests/auto/api/testdata/same-base-name/main.c @@ -0,0 +1,18 @@ +extern void printHelloC(); +extern void printHelloCpp(); + +#ifdef __APPLE__ +extern void printHelloObjc(); +extern void printHelloObjcpp(); +#endif + +int main() +{ + printHelloC(); + printHelloCpp(); +#ifdef __APPLE__ + printHelloObjc(); + printHelloObjcpp(); +#endif + return 0; +} diff --git a/tests/auto/api/testdata/same-base-name/project.qbs b/tests/auto/api/testdata/same-base-name/project.qbs new file mode 100644 index 000000000..e9b4ba7a6 --- /dev/null +++ b/tests/auto/api/testdata/same-base-name/project.qbs @@ -0,0 +1,32 @@ +import qbs 1.0 + +Project { + CppApplication { + type: "application" + Depends { name: "basenamelib" } + name: "basename" + files: "main.c" + } + + StaticLibrary { + Depends { name: "cpp" } + name: "basenamelib" + files: [ + "lib.c", + "lib.cpp" + ] + + Group { + condition: qbs.targetOS.contains("darwin") + files: [ + "lib.m", + "lib.mm" + ] + } + + Export { + Depends { name: "cpp" } + cpp.frameworks: qbs.targetOS.contains("darwin") ? "Foundation" : undefined + } + } +} diff --git a/tests/auto/api/testdata/simple-probe/main.cpp b/tests/auto/api/testdata/simple-probe/main.cpp new file mode 100644 index 000000000..76e819701 --- /dev/null +++ b/tests/auto/api/testdata/simple-probe/main.cpp @@ -0,0 +1 @@ +int main() { return 0; } diff --git a/tests/auto/api/testdata/simple-probe/project.qbs b/tests/auto/api/testdata/simple-probe/project.qbs new file mode 100644 index 000000000..b409c7cc6 --- /dev/null +++ b/tests/auto/api/testdata/simple-probe/project.qbs @@ -0,0 +1,31 @@ +import qbs 1.0 +import qbs.Probes + +CppApplication { + Probe { + id: probe1 + property string someString + configure: { + someString = "one"; + found = true; + } + } + Probe { + id: probe2 + configure: { + found = false; + } + } + name: "MyApp" + type: { + if (!probe1.found) + throw "probe1 not found"; + if (probe2.found) + throw "probe2 unexpectedly found"; + if (probe1.someString !== "one") + throw "probe1.someString expected to be \"one\"." + return "application" + } + files: ["main.cpp"] +} + diff --git a/tests/auto/api/testdata/soft-dependency/main.cpp b/tests/auto/api/testdata/soft-dependency/main.cpp new file mode 100644 index 000000000..5f3248c7f --- /dev/null +++ b/tests/auto/api/testdata/soft-dependency/main.cpp @@ -0,0 +1,4 @@ +int main() +{ + thisShouldNotLink(); +} diff --git a/tests/auto/api/testdata/soft-dependency/project.qbs b/tests/auto/api/testdata/soft-dependency/project.qbs new file mode 100644 index 000000000..bbf37fda8 --- /dev/null +++ b/tests/auto/api/testdata/soft-dependency/project.qbs @@ -0,0 +1,14 @@ +import qbs + +Application { + Depends { + name: "nosuchmodule" + required: false + } + Depends { + name: "cpp" + condition: nosuchmodule.present + } + + files: "main.cpp" +} diff --git a/tests/auto/api/testdata/static-lib-deps/a1.cpp b/tests/auto/api/testdata/static-lib-deps/a1.cpp new file mode 100644 index 000000000..862d76783 --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/a1.cpp @@ -0,0 +1,7 @@ +#include <iostream> + +void a1() +{ + std::cout << "a1" << std::endl; +} + diff --git a/tests/auto/api/testdata/static-lib-deps/a2.cpp b/tests/auto/api/testdata/static-lib-deps/a2.cpp new file mode 100644 index 000000000..d1f41731c --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/a2.cpp @@ -0,0 +1,7 @@ +#include <iostream> + +void a2() +{ + std::cout << "a2" << std::endl; +} + diff --git a/tests/auto/api/testdata/static-lib-deps/b.cpp b/tests/auto/api/testdata/static-lib-deps/b.cpp new file mode 100644 index 000000000..a88cc9d90 --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/b.cpp @@ -0,0 +1,7 @@ +void a1(); + +void b() +{ + a1(); +} + diff --git a/tests/auto/api/testdata/static-lib-deps/c.cpp b/tests/auto/api/testdata/static-lib-deps/c.cpp new file mode 100644 index 000000000..264db582a --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/c.cpp @@ -0,0 +1,7 @@ +void a2(); + +void c() +{ + a2(); +} + diff --git a/tests/auto/api/testdata/static-lib-deps/d.cpp b/tests/auto/api/testdata/static-lib-deps/d.cpp new file mode 100644 index 000000000..a7a2b9f85 --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/d.cpp @@ -0,0 +1,9 @@ +void b(); +void c(); + +void d() +{ + b(); + c(); +} + diff --git a/tests/auto/api/testdata/static-lib-deps/e.cpp b/tests/auto/api/testdata/static-lib-deps/e.cpp new file mode 100644 index 000000000..af7d24682 --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/e.cpp @@ -0,0 +1,7 @@ +void d(); + +void e() +{ + d(); +} + diff --git a/tests/auto/api/testdata/static-lib-deps/main.cpp b/tests/auto/api/testdata/static-lib-deps/main.cpp new file mode 100644 index 000000000..3753dd5cb --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/main.cpp @@ -0,0 +1,10 @@ +#include <cstdlib> + +void e(); + +int main() +{ + e(); + return EXIT_SUCCESS; +} + diff --git a/tests/auto/api/testdata/static-lib-deps/project.qbs b/tests/auto/api/testdata/static-lib-deps/project.qbs new file mode 100644 index 000000000..f7d4a98b0 --- /dev/null +++ b/tests/auto/api/testdata/static-lib-deps/project.qbs @@ -0,0 +1,69 @@ +import qbs 1.0 + +Project { + StaticLibrary { + name: "a" + + Depends { name: "cpp" } + + files: [ + "a1.cpp", + "a2.cpp", + ] + } + StaticLibrary { + name: "b" + + Depends { name: "cpp" } + + Depends { name: "a" } + + files: [ + "b.cpp", + ] + } + StaticLibrary { + name: "c" + + Depends { name: "cpp" } + + Depends { name: "a" } + + files: [ + "c.cpp", + ] + } + StaticLibrary { + name: "d" + + Depends { name: "cpp" } + + Depends { name: "b" } + Depends { name: "c" } + + files: [ + "d.cpp", + ] + } + StaticLibrary { + name: "e" + + Depends { name: "cpp" } + + Depends { name: "d" } + + files: [ + "e.cpp", + ] + } + CppApplication { + name: "staticLibDeps" + type: "application" + + Depends { name: "e" } + + files: [ + "main.cpp", + ] + } +} diff --git a/tests/auto/api/testdata/transformers/main.cpp b/tests/auto/api/testdata/transformers/main.cpp new file mode 100644 index 000000000..c0d920a9d --- /dev/null +++ b/tests/auto/api/testdata/transformers/main.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <string> +#include <iostream> +#include <fstream> + +using namespace std; + +bool displayTextFile(const string &dirPath, const string &fileName) +{ + string fullPath = dirPath + fileName; + ifstream istream(fullPath.c_str()); + if (!istream.is_open()) { + cout << "Cannot open " << fileName << endl; + return false; + } + cout << "---" << fileName << "---" << endl; + char buf[256]; + unsigned int i = 1; + while (istream.good()) { + istream.getline(buf, sizeof(buf)); + cout << i++ << ": " << buf << endl; + } + return true; +} + +int main(int, char **argv) +{ + string appPath(argv[0]); + size_t i = appPath.find_last_of('/'); + if (i == string::npos) + i = appPath.find_last_of('\\'); + if (i == string::npos) // No path, plain executable was called + appPath.clear(); + else + appPath.resize(i + 1); + if (!displayTextFile(appPath, "foo.txt")) + return 1; + if (!displayTextFile(appPath, "bar.txt")) + return 2; + cout << "-------------" << endl; + return 0; +} + diff --git a/tests/auto/api/testdata/transformers/transformers.qbs b/tests/auto/api/testdata/transformers/transformers.qbs new file mode 100644 index 000000000..a0b1d70b0 --- /dev/null +++ b/tests/auto/api/testdata/transformers/transformers.qbs @@ -0,0 +1,86 @@ +import qbs 1.0 +import qbs.File +import qbs.TextFile +import qbs.Xml +import qbs.FileInfo + +Project { + Product { + name: "HelloWorld" + type: "application" + files: ["main.cpp"] + + Depends { name: "cpp" } + + Transformer { + // no inputs -> just a generator + Artifact { + filePath: "foo.txt" + fileTags: "text" + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating foo.txt"; + cmd.highlight = "linker"; + cmd.sourceCode = function () { + File.remove(output.filePath); + var f = new TextFile(output.filePath, TextFile.WriteOnly); + f.write("Dear Sir/Madam,\n\n"); + f.write("this is a generated file.\n\n\n"); + f.write("Best Regards and Mellow Greetings,\nYour Build Tool.\n"); + f.close(); + } + return cmd; + } + } + + Transformer { + // no inputs -> just a generator + Artifact { + filePath: "foo.xml" + fileTags: "xml" + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating foo.xml"; + cmd.highlight = "linker"; + cmd.sourceCode = function () { + File.remove(output.filePath); + var doc = new XmlDomDocument(); + var root = doc.createElement("root"); + doc.appendChild(root); + + var tag = doc.createElement("Greeting"); + root.appendChild(tag); + tag.appendChild(doc.createTextNode("text node")); + doc.save(output.filePath); + } + return cmd; + } + } + + Transformer { + inputs: ["main.cpp"] // will be taken from the source dir + Artifact { + filePath: "bar.txt" + fileTags: "text" + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating bar.txt"; + cmd.highlight = "linker"; + cmd.inputFileName = input.filePath; + cmd.sourceCode = function() { + File.remove(output.filePath); + var f = new TextFile(output.filePath, TextFile.WriteOnly); + f.write("Dear Sir/Madam,\n\n"); + f.write("this file was generated from " + inputFileName + ".\n\n\n"); + f.write("Best Regards and Mellow Greetings,\nYour Build Tool.\n"); + f.close(); + } + return cmd; + } + } + } +} + diff --git a/tests/auto/api/testdata/type-change/main.cpp b/tests/auto/api/testdata/type-change/main.cpp new file mode 100644 index 000000000..237c8ce18 --- /dev/null +++ b/tests/auto/api/testdata/type-change/main.cpp @@ -0,0 +1 @@ +int main() {} diff --git a/tests/auto/api/testdata/type-change/project.qbs b/tests/auto/api/testdata/type-change/project.qbs new file mode 100644 index 000000000..7661aa305 --- /dev/null +++ b/tests/auto/api/testdata/type-change/project.qbs @@ -0,0 +1,7 @@ +import qbs + +Product { + files: "main.cpp" + Depends { name: "cpp" } + // type: "application" +} diff --git a/tests/auto/api/testdata/uic/bla.cpp b/tests/auto/api/testdata/uic/bla.cpp new file mode 100644 index 000000000..0f53e98a7 --- /dev/null +++ b/tests/auto/api/testdata/uic/bla.cpp @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "bla.h" + +int main() +{ + Ui::MainWindow mainWindow; + Q_UNUSED(mainWindow); +} + diff --git a/tests/auto/api/testdata/uic/bla.h b/tests/auto/api/testdata/uic/bla.h new file mode 100644 index 000000000..952d25b7d --- /dev/null +++ b/tests/auto/api/testdata/uic/bla.h @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ui.h" diff --git a/tests/auto/api/testdata/uic/ui.h b/tests/auto/api/testdata/uic/ui.h new file mode 100644 index 000000000..b186b58f8 --- /dev/null +++ b/tests/auto/api/testdata/uic/ui.h @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ui_ui.h" diff --git a/tests/auto/api/testdata/uic/ui.ui b/tests/auto/api/testdata/uic/ui.ui new file mode 100644 index 000000000..b07f62d05 --- /dev/null +++ b/tests/auto/api/testdata/uic/ui.ui @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"/> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>25</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/api/testdata/uic/uic.qbs b/tests/auto/api/testdata/uic/uic.qbs new file mode 100644 index 000000000..a216b86a9 --- /dev/null +++ b/tests/auto/api/testdata/uic/uic.qbs @@ -0,0 +1,15 @@ +import qbs 1.0 + +Project { + QtGuiApplication { + type: "application" + name: "ui" + + files: [ + "bla.cpp", + "bla.h", + "ui.ui", + "ui.h" + ] + } +} diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp index 6cdb3279a..35dd15842 100644 --- a/tests/auto/api/tst_api.cpp +++ b/tests/auto/api/tst_api.cpp @@ -31,18 +31,9 @@ #include "../shared.h" -#include <api/jobs.h> -#include <api/project.h> -#include <api/projectdata.h> -#include <logging/ilogsink.h> -#include <tools/buildoptions.h> +#include <qbs.h> #include <tools/fileinfo.h> #include <tools/hostosinfo.h> -#include <tools/installoptions.h> -#include <tools/preferences.h> -#include <tools/profile.h> -#include <tools/settings.h> -#include <tools/setupprojectparameters.h> #include <QCoreApplication> #include <QDir> @@ -54,12 +45,20 @@ #include <QTest> #include <QTimer> +#define VERIFY_NO_ERROR(errorInfo) \ + QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())) + class LogSink: public qbs::ILogSink { +public: + QString output; + void doPrintWarning(const qbs::ErrorInfo &error) { qDebug("%s", qPrintable(error.toString())); } - void doPrintMessage(qbs::LoggerLevel, const QString &, const QString &) { } + void doPrintMessage(qbs::LoggerLevel, const QString &message, const QString &) { + output += message; + } }; class BuildDescriptionReceiver : public QObject @@ -74,25 +73,29 @@ private slots: } }; -TestApi::TestApi() - : m_logSink(new LogSink) - , m_sourceDataDir(QDir::cleanPath(SRCDIR "/testdata")) - , m_workingDataDir(QCoreApplication::applicationDirPath() + "/../tests/auto/api/testWorkDir") +class ProcessResultReceiver : public QObject { -} + Q_OBJECT +public: + QString output; -TestApi::~TestApi() -{ - delete m_logSink; -} +private slots: + void handleProcessResult(const qbs::ProcessResult &result) { + output += result.stdErr().join(QLatin1String("\n")); + output += result.stdOut().join(QLatin1String("\n")); + } +}; -void TestApi::initTestCase() +class TaskReceiver : public QObject { - QString errorMessage; - qbs::Internal::removeDirectoryWithContents(m_workingDataDir, &errorMessage); - QVERIFY2(qbs::Internal::copyFileRecursion(m_sourceDataDir, - m_workingDataDir, false, &errorMessage), qPrintable(errorMessage)); -} + Q_OBJECT +public: + QString taskDescriptions; + +private slots: + void handleTaskStart(const QString &task) { taskDescriptions += task; } +}; + static void removeBuildDir(const qbs::SetupProjectParameters ¶ms) { @@ -119,8 +122,7 @@ static bool waitForFinished(qbs::AbstractJob *job, int timeout = 0) return true; } - -void printProjectData(const qbs::ProjectData &project) +static void printProjectData(const qbs::ProjectData &project) { foreach (const qbs::ProductData &p, project.products()) { qDebug(" Product '%s' at %s", qPrintable(p.name()), qPrintable(p.location().toString())); @@ -131,6 +133,113 @@ void printProjectData(const qbs::ProjectData &project) } } + +TestApi::TestApi() + : m_logSink(new LogSink) + , m_sourceDataDir(QDir::cleanPath(SRCDIR "/testdata")) + , m_workingDataDir(QCoreApplication::applicationDirPath() + "/../tests/auto/api/testWorkDir") +{ +} + +TestApi::~TestApi() +{ + delete m_logSink; +} + +void TestApi::initTestCase() +{ + QString errorMessage; + qbs::Internal::removeDirectoryWithContents(m_workingDataDir, &errorMessage); + QVERIFY2(qbs::Internal::copyFileRecursion(m_sourceDataDir, + m_workingDataDir, false, &errorMessage), qPrintable(errorMessage)); +} + +void TestApi::addQObjectMacroToCppFile() +{ + BuildDescriptionReceiver receiver; + qbs::ErrorInfo errorInfo = doBuildProject("add-qobject-macro-to-cpp-file/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(!receiver.descriptions.contains("moc"), qPrintable(receiver.descriptions)); + receiver.descriptions.clear(); + + waitForNewTimestamp(); + QFile cppFile("object.cpp"); + QVERIFY2(cppFile.open(QIODevice::ReadWrite), qPrintable(cppFile.errorString())); + QByteArray contents = cppFile.readAll(); + contents.replace("// ", ""); + cppFile.resize(0); + cppFile.write(contents); + cppFile.close(); + errorInfo = doBuildProject("add-qobject-macro-to-cpp-file/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(receiver.descriptions.contains("moc"), qPrintable(receiver.descriptions)); +} + +static bool isAboutUndefinedSymbols(const QString &_message) +{ + const QString message = _message.toLower(); + return message.contains("undefined") || message.contains("unresolved"); +} + +void TestApi::addedFilePersistent() +{ + // On the initial run, linking will fail. + const QString relProjectFilePath = "added-file-persistent/project.qbs"; + ProcessResultReceiver receiver; + qbs::ErrorInfo errorInfo = doBuildProject(relProjectFilePath, 0, &receiver); + QVERIFY(errorInfo.hasError()); + QVERIFY2(isAboutUndefinedSymbols(receiver.output), qPrintable((receiver.output))); + receiver.output.clear(); + + // Add a file. qbs must schedule it for rule application on the next build. + waitForNewTimestamp(); + const qbs::SetupProjectParameters params = defaultSetupParameters(relProjectFilePath); + QFile projectFile(params.projectFilePath()); + QVERIFY2(projectFile.open(QIODevice::ReadWrite), qPrintable(projectFile.errorString())); + const QByteArray originalContent = projectFile.readAll(); + QByteArray addedFileContent = originalContent; + addedFileContent.replace("/* 'file.cpp' */", "'file.cpp'"); + projectFile.resize(0); + projectFile.write(addedFileContent); + projectFile.flush(); + QScopedPointer<qbs::SetupProjectJob> setupJob(qbs::Project().setupProject(params, m_logSink, + 0)); + waitForFinished(setupJob.data()); + QVERIFY2(!setupJob->error().hasError(), qPrintable(setupJob->error().toString())); + setupJob.reset(0); + + // Remove the file again. qbs must unschedule the rule application again. + // Consequently, the linking step must fail as in the initial run. + waitForNewTimestamp(); + projectFile.resize(0); + projectFile.write(originalContent); + projectFile.flush(); + errorInfo = doBuildProject(relProjectFilePath, 0, &receiver); + QVERIFY(errorInfo.hasError()); + QVERIFY2(isAboutUndefinedSymbols(receiver.output), qPrintable((receiver.output))); + + // Add the file again. qbs must schedule it for rule application on the next build. + waitForNewTimestamp(); + projectFile.resize(0); + projectFile.write(addedFileContent); + projectFile.close(); + setupJob.reset(qbs::Project().setupProject(params, m_logSink, 0)); + waitForFinished(setupJob.data()); + QVERIFY2(!setupJob->error().hasError(), qPrintable(setupJob->error().toString())); + setupJob.reset(0); + + // qbs must remember that a file was scheduled for rule application. The build must then + // succeed, as now all necessary symbols are linked in. + errorInfo = doBuildProject(relProjectFilePath); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::baseProperties() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("base-properties/prj.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + void TestApi::buildGraphLocking() { qbs::SetupProjectParameters setupParams @@ -151,6 +260,97 @@ void TestApi::buildGraphLocking() qPrintable(setupJob->error().toString())); } +void TestApi::buildProject() +{ + QFETCH(QString, projectSubDir); + QFETCH(QString, productFileName); + qbs::SetupProjectParameters params = defaultSetupParameters(projectSubDir + "/project.qbs"); + removeBuildDir(params); + qbs::ErrorInfo errorInfo = doBuildProject(projectSubDir + "/project.qbs"); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(regularFileExists(productFileName), qPrintable(productFileName)); + QVERIFY(regularFileExists(relativeBuildGraphFilePath())); + + QVERIFY2(QFile::remove(productFileName), qPrintable(productFileName)); + waitForNewTimestamp(); + qbs::BuildOptions options; + options.setForceTimestampCheck(true); + errorInfo = doBuildProject(projectSubDir + "/project.qbs", 0, 0, 0, options); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(regularFileExists(productFileName), qPrintable(productFileName)); + QVERIFY(regularFileExists(relativeBuildGraphFilePath())); +} + +void TestApi::buildProject_data() +{ + QTest::addColumn<QString>("projectSubDir"); + QTest::addColumn<QString>("productFileName"); + QTest::newRow("BPs in Sources") + << QString("build-properties-source") + << relativeExecutableFilePath("HelloWorld"); + QTest::newRow("code generator") + << QString("codegen") + << relativeExecutableFilePath("codegen"); + QTest::newRow("link static libs") + << QString("link-static-lib") + << relativeExecutableFilePath("HelloWorld"); + QTest::newRow("precompiled header") + << QString("precompiled-header") + << relativeExecutableFilePath("MyApp"); + QTest::newRow("lots of dots") + << QString("lots-of-dots") + << relativeExecutableFilePath("lots.of.dots"); + QTest::newRow("Qt5 plugin") + << QString("qt5-plugin") + << relativeProductBuildDir("echoplugin") + '/' + + qbs::Internal::HostOsInfo::dynamicLibraryName("echoplugin"); + QTest::newRow("Q_OBJECT in source") + << QString("moc-cpp") + << relativeExecutableFilePath("moc_cpp"); + QTest::newRow("Q_OBJECT in header") + << QString("moc-hpp") + << relativeExecutableFilePath("moc_hpp"); + QTest::newRow("Q_OBJECT in header, moc_XXX.cpp included") + << QString("moc-hpp-included") + << relativeExecutableFilePath("moc_hpp_included"); + QTest::newRow("app and lib with same source file") + << QString("lib-same-source") + << relativeExecutableFilePath("HelloWorldApp"); + QTest::newRow("source files with the same base name but different extensions") + << QString("same-base-name") + << relativeExecutableFilePath("basename"); + QTest::newRow("static library dependencies") + << QString("static-lib-deps") + << relativeExecutableFilePath("staticLibDeps"); + QTest::newRow("simple probes") + << QString("simple-probe") + << relativeExecutableFilePath("MyApp"); + QTest::newRow("application without sources") + << QString("app-without-sources") + << relativeExecutableFilePath("appWithoutSources"); +} + +void TestApi::buildProjectDryRun() +{ + QFETCH(QString, projectSubDir); + QFETCH(QString, productFileName); + qbs::SetupProjectParameters params = defaultSetupParameters(projectSubDir + "/project.qbs"); + removeBuildDir(params); + qbs::BuildOptions options; + options.setDryRun(true); + const qbs::ErrorInfo errorInfo + = doBuildProject(projectSubDir + "/project.qbs", 0, 0, 0, options); + VERIFY_NO_ERROR(errorInfo); + const QStringList &buildDirContents + = QDir(relativeBuildDir()).entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); + QVERIFY2(buildDirContents.isEmpty(), qPrintable(buildDirContents.join(" "))); +} + +void TestApi::buildProjectDryRun_data() +{ + return buildProject_data(); +} + void TestApi::buildSingleFile() { qbs::SetupProjectParameters setupParams @@ -210,10 +410,10 @@ void TestApi::changeContent() QVERIFY(errorInfo.toString().contains("empty")); errorInfo = project.addGroup(product, "New Group 1"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); errorInfo = project.addGroup(product, "New Group 2"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Error handling: Group already inserted. errorInfo = project.addGroup(product, "New Group 1"); @@ -234,7 +434,7 @@ void TestApi::changeContent() qbs::GroupData group = findGroup(product, "New Group 1"); QVERIFY(group.isValid()); errorInfo = project.addFiles(product, group, QStringList() << "file.h" << "file.cpp"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Error handling: Add the same file again. projectData = project.projectData(); @@ -249,7 +449,7 @@ void TestApi::changeContent() // Remove one of the newly added files again. errorInfo = project.removeFiles(product, group, QStringList("file.h")); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Error handling: Try to remove the same file again. projectData = project.projectData(); @@ -271,7 +471,7 @@ void TestApi::changeContent() // Remove file from product's 'files' binding. errorInfo = project.removeFiles(product, qbs::GroupData(), QStringList("main.cpp")); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Add file to non-empty array literal. projectData = project.projectData(); @@ -280,14 +480,14 @@ void TestApi::changeContent() group = findGroup(product, "Existing Group 1"); QVERIFY(group.isValid()); errorInfo = project.addFiles(product, group, QStringList() << "newfile1.txt"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Add files to list represented as a single string. projectData = project.projectData(); QVERIFY(projectData.products().count() == 1); product = projectData.products().first(); errorInfo = project.addFiles(product, qbs::GroupData(), QStringList() << "newfile2.txt"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Add files to list represented as an identifier. projectData = project.projectData(); @@ -296,7 +496,7 @@ void TestApi::changeContent() group = findGroup(product, "Existing Group 2"); QVERIFY(group.isValid()); errorInfo = project.addFiles(product, group, QStringList() << "newfile3.txt"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Add files to list represented as a block of code (not yet implemented). projectData = project.projectData(); @@ -315,7 +515,7 @@ void TestApi::changeContent() group = findGroup(product, "Existing Group 4"); QVERIFY(group.isValid()); errorInfo = project.addFiles(product, group, QStringList() << "file.txt"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); // Error handling: Add file to group with non-directory prefix. projectData = project.projectData(); @@ -334,7 +534,7 @@ void TestApi::changeContent() group = findGroup(product, "Existing Group 5"); QVERIFY(group.isValid()); errorInfo = project.removeGroup(product, group); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); projectData = project.projectData(); QVERIFY(projectData.products().count() == 1); QCOMPARE(projectData.products().first().groups().count(), 9); @@ -354,7 +554,7 @@ void TestApi::changeContent() QVERIFY2(newFile.open(QIODevice::WriteOnly), qPrintable(newFile.errorString())); newFile.close(); errorInfo = project.addFiles(product, group, QStringList() << newFile.fileName()); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); projectData = project.projectData(); QVERIFY(projectData.products().count() == 1); product = projectData.products().first(); @@ -426,9 +626,11 @@ void TestApi::changeContent() QVERIFY2(errorInfo.toString().contains("in process"), qPrintable(errorInfo.toString())); waitForFinished(buildJob.data()); errorInfo = project.addGroup(newProjectData.products().first(), "blubb"); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); project = qbs::Project(); + job.reset(0); + buildJob.reset(0); removeBuildDir(setupParams); // Add a file to the top level of a product that does not have a "files" binding yet. setupParams.setProjectFilePath(QDir::cleanPath(m_workingDataDir + @@ -442,7 +644,7 @@ void TestApi::changeContent() QCOMPARE(projectData.allProducts().count(), 1); product = projectData.allProducts().first(); errorInfo = project.addFiles(product, qbs::GroupData(), QStringList("main.cpp")); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); projectData = project.projectData(); rcvr.descriptions.clear(); buildJob.reset(project.buildAllProducts(buildOptions, this)); @@ -467,8 +669,29 @@ void TestApi::changeContent() } QVERIFY(projectDataMatches); } + #endif // QBS_ENABLE_PROJECT_FILE_UPDATES +void TestApi::changeDependentLib() +{ + qbs::ErrorInfo errorInfo = doBuildProject("change-dependent-lib/change-dependent-lib.qbs"); + VERIFY_NO_ERROR(errorInfo); + + waitForNewTimestamp(); + const QString qbsFileName("change-dependent-lib.qbs"); + QFile qbsFile(qbsFileName); + QVERIFY(qbsFile.open(QIODevice::ReadWrite)); + const QByteArray content1 = qbsFile.readAll(); + QByteArray content2 = content1; + content2.replace("cpp.defines: [\"XXXX\"]", "cpp.defines: [\"ABCD\"]"); + QVERIFY(content1 != content2); + qbsFile.seek(0); + qbsFile.write(content2); + qbsFile.close(); + errorInfo = doBuildProject("change-dependent-lib/change-dependent-lib.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + static qbs::ErrorInfo forceRuleEvaluation(const qbs::Project project) { qbs::BuildOptions buildOptions; @@ -489,7 +712,7 @@ void TestApi::disabledInstallGroup() const qbs::Project project = job->project(); const qbs::ErrorInfo errorInfo = forceRuleEvaluation(project); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); qbs::ProjectData projectData = project.projectData(); QCOMPARE(projectData.allProducts().count(), 1); @@ -503,6 +726,111 @@ void TestApi::disabledInstallGroup() QCOMPARE(project.targetExecutable(product, qbs::InstallOptions()), targets.first().filePath()); } +void TestApi::disabledProduct() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("disabled-product/disabledProduct.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::disabledProject() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("disabled-project/disabled_project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::disableProduct() +{ + qbs::ErrorInfo errorInfo = doBuildProject("disable-product/project.qbs"); + VERIFY_NO_ERROR(errorInfo); + + waitForNewTimestamp(); + QFile projectFile("project.qbs"); + QVERIFY(projectFile.open(QIODevice::ReadWrite)); + QByteArray content = projectFile.readAll(); + content.replace("// condition: false", "condition: false"); + projectFile.resize(0); + projectFile.write(content); + projectFile.close(); + errorInfo = doBuildProject("disable-product/project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::duplicateProductNames() +{ + QFETCH(QString, projectFileName); + const qbs::ErrorInfo errorInfo = doBuildProject("duplicate-product-names/" + projectFileName); + QVERIFY(errorInfo.hasError()); + QVERIFY2(errorInfo.toString().contains("Duplicate product name"), + qPrintable(errorInfo.toString())); +} + +void TestApi::duplicateProductNames_data() +{ + QTest::addColumn<QString>("projectFileName"); + QTest::newRow("Names explicitly set") << QString("explicit.qbs"); + QTest::newRow("Unnamed products in same file") << QString("implicit.qbs"); + QTest::newRow("Unnamed products in files of the same name") << QString("implicit-indirect.qbs"); + +} + +void TestApi::dynamicLibs() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("dynamic-libs/link_dynamiclib.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::emptyFileTagList() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("empty-filetag-list/project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::emptySubmodulesList() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("empty-submodules-list/project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::explicitlyDependsOn() +{ + BuildDescriptionReceiver receiver; + qbs::ErrorInfo errorInfo = doBuildProject("explicitly-depends-on/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(receiver.descriptions.contains("Creating output artifact")); + receiver.descriptions.clear(); + + errorInfo = doBuildProject("explicitly-depends-on/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(!receiver.descriptions.contains("Creating output artifact")); + + waitForNewTimestamp(); + touch("dependency.txt"); + errorInfo = doBuildProject("explicitly-depends-on/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(receiver.descriptions.contains("Creating output artifact")); +} + +void TestApi::exportSimple() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("export-simple/project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::exportWithRecursiveDepends() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("export-with-recursive-depends/project.qbs"); + QEXPECT_FAIL("", "currently broken", Abort); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::fileTagger() +{ + BuildDescriptionReceiver receiver; + const qbs::ErrorInfo errorInfo = doBuildProject("file-tagger/moc_cpp.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(receiver.descriptions.contains("moc bla.cpp"), qPrintable(receiver.descriptions)); +} + void TestApi::fileTagsFilterOverride() { qbs::SetupProjectParameters setupParams @@ -514,7 +842,7 @@ void TestApi::fileTagsFilterOverride() qbs::Project project = job->project(); const qbs::ErrorInfo errorInfo = forceRuleEvaluation(project); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); qbs::ProjectData projectData = project.projectData(); QCOMPARE(projectData.allProducts().count(), 1); @@ -559,6 +887,12 @@ void TestApi::infiniteLoopResolving() qPrintable(setupJob->error().toString())); } +void TestApi::inheritQbsSearchPaths() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("inherit-qbs-search-paths/prj.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + void TestApi::installableFiles() { qbs::SetupProjectParameters setupParams @@ -570,7 +904,7 @@ void TestApi::installableFiles() qbs::Project project = job->project(); const qbs::ErrorInfo errorInfo = forceRuleEvaluation(project); - QVERIFY2(!errorInfo.hasError(), qPrintable(errorInfo.toString())); + VERIFY_NO_ERROR(errorInfo); qbs::ProjectData projectData = project.projectData(); QCOMPARE(projectData.allProducts().count(), 1); @@ -641,6 +975,33 @@ void TestApi::listBuildSystemFiles() + "/subproject2/subproject3/subproject3.qbs")); } +void TestApi::mocCppIncluded() +{ + // Initial build. + qbs::ErrorInfo errorInfo = doBuildProject("moc-hpp-included/project.qbs"); + VERIFY_NO_ERROR(errorInfo); + + // Touch header and try again. + waitForNewTimestamp(); + QFile headerFile("object.h"); + QVERIFY2(headerFile.open(QIODevice::WriteOnly | QIODevice::Append), + qPrintable(headerFile.errorString())); + headerFile.write("\n"); + headerFile.close(); + errorInfo = doBuildProject("moc-hpp-included/project.qbs"); + VERIFY_NO_ERROR(errorInfo); + + // Touch cpp file and try again. + waitForNewTimestamp(); + QFile cppFile("object.cpp"); + QVERIFY2(cppFile.open(QIODevice::WriteOnly | QIODevice::Append), + qPrintable(cppFile.errorString())); + cppFile.write("\n"); + cppFile.close(); + errorInfo = doBuildProject("moc-hpp-included/project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + void TestApi::multiArch() { qbs::SetupProjectParameters setupParams = defaultSetupParameters("multi-arch/project.qbs"); @@ -660,7 +1021,7 @@ void TestApi::multiArch() waitForFinished(setupJob.data()); QVERIFY2(!setupJob->error().hasError(), qPrintable(setupJob->error().toString())); qbs::Project project = setupJob->project(); - QCOMPARE(project.profile(), QLatin1String("qbs_autotests")); + QCOMPARE(project.profile(), profileName()); const QList<qbs::ProductData> &products = project.projectData().products(); QCOMPARE(products.count(), 3); QList<qbs::ProductData> hostProducts; @@ -721,6 +1082,62 @@ void TestApi::multiArch() qPrintable(setupJob->error().toString())); } +void TestApi::newOutputArtifactInDependency() +{ + BuildDescriptionReceiver receiver; + qbs::ErrorInfo errorInfo + = doBuildProject("new-output-artifact-in-dependency/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(receiver.descriptions.contains("linking app")); + const QByteArray linkingLibString = QByteArray("linking ") + + qbs::Internal::HostOsInfo::dynamicLibraryName("lib").toLatin1(); + QVERIFY(!receiver.descriptions.contains(linkingLibString)); + receiver.descriptions.clear(); + + waitForNewTimestamp(); + QFile projectFile("project.qbs"); + QVERIFY2(projectFile.open(QIODevice::ReadWrite), qPrintable(projectFile.errorString())); + QByteArray contents = projectFile.readAll(); + contents.replace("//Depends", "Depends"); + projectFile.resize(0); + projectFile.write(contents); + projectFile.close(); + errorInfo = doBuildProject("new-output-artifact-in-dependency/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(receiver.descriptions.contains("linking app")); + QVERIFY(receiver.descriptions.contains(linkingLibString)); +} + +void TestApi::newPatternMatch() +{ + TaskReceiver receiver; + qbs::ErrorInfo errorInfo = doBuildProject("new-pattern-match/project.qbs", 0, 0, &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(receiver.taskDescriptions.contains("Resolving"), qPrintable(m_logSink->output)); + receiver.taskDescriptions.clear(); + + errorInfo = doBuildProject("new-pattern-match/project.qbs", 0, 0, &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(!receiver.taskDescriptions.contains("Resolving")); + + QFile f("test.txt"); + QVERIFY2(f.open(QIODevice::WriteOnly), qPrintable(f.errorString())); + f.close(); + errorInfo = doBuildProject("new-pattern-match/project.qbs", 0, 0, &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(receiver.taskDescriptions.contains("Resolving")); + receiver.taskDescriptions.clear(); + + errorInfo = doBuildProject("new-pattern-match/project.qbs", 0, 0, &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(!receiver.taskDescriptions.contains("Resolving")); + + f.remove(); + errorInfo = doBuildProject("new-pattern-match/project.qbs", 0, 0, &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY(receiver.taskDescriptions.contains("Resolving")); +} + void TestApi::nonexistingProjectPropertyFromProduct() { qbs::SetupProjectParameters setupParams @@ -750,6 +1167,12 @@ void TestApi::nonexistingProjectPropertyFromCommandLine() qPrintable(job->error().toString())); } +void TestApi::objC() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("objc/objc.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + void TestApi::projectInvalidation() { qbs::SetupProjectParameters setupParams @@ -795,6 +1218,27 @@ void TestApi::projectLocking() QVERIFY2(!setupJob->error().hasError(), qPrintable(setupJob->error().toString())); } +void TestApi::projectWithPropertiesItem() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("project-with-properties-item/project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::propertiesBlocks() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("properties-blocks/propertiesblocks.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::rc() +{ + BuildDescriptionReceiver receiver; + const qbs::ErrorInfo errorInfo = doBuildProject("rc/rc.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + const bool rcFileWasCompiled = receiver.descriptions.contains("compiling test.rc"); + QCOMPARE(rcFileWasCompiled, qbs::Internal::HostOsInfo::isWindowsHost()); +} + qbs::SetupProjectParameters TestApi::defaultSetupParameters(const QString &projectFilePath) const { qbs::SetupProjectParameters setupParams; @@ -807,11 +1251,10 @@ qbs::SetupProjectParameters TestApi::defaultSetupParameters(const QString &proje const QString qbsRootPath = QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String("/../")); qbs::Settings settings((QString())); - const QString profileName = QLatin1String("qbs_autotests"); - const qbs::Preferences prefs(&settings, profileName); + const qbs::Preferences prefs(&settings, profileName()); setupParams.setSearchPaths(prefs.searchPaths(qbsRootPath)); setupParams.setPluginPaths(prefs.pluginPaths(qbsRootPath + QLatin1String("/lib"))); - setupParams.setTopLevelProfile(profileName); + setupParams.setTopLevelProfile(profileName()); setupParams.setBuildVariant(QLatin1String("debug")); return setupParams; } @@ -845,6 +1288,125 @@ void TestApi::references() QCOMPARE(subProjectFileName, QString("p.qbs")); } +void TestApi::renameProduct() +{ + // Initial run. + qbs::ErrorInfo errorInfo = doBuildProject("rename-product/rename.qbs"); + VERIFY_NO_ERROR(errorInfo); + + // Rename lib and adapt Depends item. + waitForNewTimestamp(); + QFile f("rename.qbs"); + QVERIFY(f.open(QIODevice::ReadWrite)); + QByteArray contents = f.readAll(); + contents.replace("TheLib", "thelib"); + f.resize(0); + f.write(contents); + f.close(); + errorInfo = doBuildProject("rename-product/rename.qbs"); + VERIFY_NO_ERROR(errorInfo); + + // Rename lib and don't adapt Depends item. + waitForNewTimestamp(); + QVERIFY(f.open(QIODevice::ReadWrite)); + contents = f.readAll(); + const int libNameIndex = contents.lastIndexOf("thelib"); + QVERIFY(libNameIndex != -1); + contents.replace(libNameIndex, 6, "TheLib"); + f.resize(0); + f.write(contents); + f.close(); + errorInfo = doBuildProject("rename-product/rename.qbs"); + QVERIFY(errorInfo.hasError()); + QVERIFY2(errorInfo.toString().contains("Product dependency 'thelib' not found"), + qPrintable(errorInfo.toString())); +} + +void TestApi::renameTargetArtifact() +{ + // Initial run. + BuildDescriptionReceiver receiver; + qbs::ErrorInfo errorInfo = doBuildProject("rename-target-artifact/rename.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(receiver.descriptions.contains("compiling"), qPrintable(receiver.descriptions)); + QCOMPARE(receiver.descriptions.count("linking"), 2); + receiver.descriptions.clear(); + + // Rename library file name. + waitForNewTimestamp(); + QFile f("rename.qbs"); + QVERIFY(f.open(QIODevice::ReadWrite)); + QByteArray contents = f.readAll(); + contents.replace("the_lib", "TheLib"); + f.resize(0); + f.write(contents); + f.close(); + errorInfo = doBuildProject("rename-target-artifact/rename.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(!receiver.descriptions.contains("compiling"), qPrintable(receiver.descriptions)); + QCOMPARE(receiver.descriptions.count("linking"), 2); +} + +void TestApi::removeFileDependency() +{ + qbs::ErrorInfo errorInfo = doBuildProject("remove-file-dependency/removeFileDependency.qbs"); + VERIFY_NO_ERROR(errorInfo); + + QFile::remove("someheader.h"); + ProcessResultReceiver receiver; + errorInfo = doBuildProject("remove-file-dependency/removeFileDependency.qbs", 0, &receiver); + QVERIFY(errorInfo.hasError()); + QVERIFY2(receiver.output.contains("someheader.h"), qPrintable(receiver.output)); +} + +void TestApi::resolveProject() +{ + QFETCH(QString, projectSubDir); + QFETCH(QString, productFileName); + + const qbs::SetupProjectParameters params + = defaultSetupParameters(projectSubDir + "/project.qbs"); + removeBuildDir(params); + const QScopedPointer<qbs::SetupProjectJob> setupJob(qbs::Project().setupProject(params, + m_logSink, 0)); + waitForFinished(setupJob.data()); + VERIFY_NO_ERROR(setupJob->error()); + QVERIFY2(!QFile::exists(productFileName), qPrintable(productFileName)); + QVERIFY(regularFileExists(relativeBuildGraphFilePath())); +} + +void TestApi::resolveProject_data() +{ + return buildProject_data(); +} + +void TestApi::resolveProjectDryRun() +{ + QFETCH(QString, projectSubDir); + QFETCH(QString, productFileName); + + qbs::SetupProjectParameters params = defaultSetupParameters(projectSubDir + "/project.qbs"); + params.setDryRun(true); + removeBuildDir(params); + const QScopedPointer<qbs::SetupProjectJob> setupJob(qbs::Project().setupProject(params, + m_logSink, 0)); + waitForFinished(setupJob.data()); + VERIFY_NO_ERROR(setupJob->error()); + QVERIFY2(!QFile::exists(productFileName), qPrintable(productFileName)); + QVERIFY(!regularFileExists(relativeBuildGraphFilePath())); +} + +void TestApi::resolveProjectDryRun_data() +{ + return resolveProject_data(); +} + +void TestApi::softDependency() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("soft-dependency/project.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + void TestApi::sourceFileInBuildDir() { qbs::SetupProjectParameters setupParams @@ -856,12 +1418,167 @@ void TestApi::sourceFileInBuildDir() const qbs::ProjectData projectData = job->project().projectData(); QCOMPARE(projectData.allProducts().count(), 1); const qbs::ProductData product = projectData.allProducts().first(); - QCOMPARE(product.profile(), QLatin1String("qbs_autotests")); + QCOMPARE(product.profile(), profileName()); QCOMPARE(product.groups().count(), 1); const qbs::GroupData group = product.groups().first(); QCOMPARE(group.allFilePaths().count(), 1); } +void TestApi::subProjects() +{ + const qbs::SetupProjectParameters params + = defaultSetupParameters("subprojects/toplevelproject.qbs"); + removeBuildDir(params); + + // Check all three types of subproject creation, plus property overrides. + qbs::ErrorInfo errorInfo = doBuildProject("subprojects/toplevelproject.qbs"); + VERIFY_NO_ERROR(errorInfo); + + // Disabling both the project with the dependency and the one with the dependent + // should not cause an error. + waitForNewTimestamp(); + QFile f(params.projectFilePath()); + QVERIFY(f.open(QIODevice::ReadWrite)); + QByteArray contents = f.readAll(); + contents.replace("condition: true", "condition: false"); + f.resize(0); + f.write(contents); + f.close(); + f.setFileName(params.buildRoot() + "/subproject2/subproject2.qbs"); + QVERIFY(f.open(QIODevice::ReadWrite)); + contents = f.readAll(); + contents.replace("condition: true", "condition: false"); + f.resize(0); + f.write(contents); + f.close(); + errorInfo = doBuildProject("subprojects/toplevelproject.qbs"); + VERIFY_NO_ERROR(errorInfo); + + // Disabling the project with the dependency only is an error. + // This tests also whether changes in sub-projects are detected. + waitForNewTimestamp(); + f.setFileName(params.projectFilePath()); + QVERIFY(f.open(QIODevice::ReadWrite)); + contents = f.readAll(); + contents.replace("condition: false", "condition: true"); + f.resize(0); + f.write(contents); + f.close(); + errorInfo = doBuildProject("subprojects/toplevelproject.qbs"); + QVERIFY(errorInfo.hasError()); + QVERIFY2(errorInfo.toString().contains("Product dependency 'testLib' not found"), + qPrintable(errorInfo.toString())); +} + +void TestApi::trackAddQObjectHeader() +{ + const qbs::SetupProjectParameters params + = defaultSetupParameters("missing-qobject-header/missingheader.qbs"); + QFile qbsFile(params.projectFilePath()); + QVERIFY(qbsFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); + qbsFile.write("import qbs.base 1.0\nCppApplication {\n Depends { name: 'Qt.core' }\n" + " files: ['main.cpp', 'myobject.cpp']\n}"); + qbsFile.close(); + ProcessResultReceiver receiver; + qbs::ErrorInfo errorInfo + = doBuildProject("missing-qobject-header/missingheader.qbs", 0, &receiver); + QVERIFY(errorInfo.hasError()); + QVERIFY2(isAboutUndefinedSymbols(receiver.output), qPrintable(receiver.output)); + + waitForNewTimestamp(); + QVERIFY(qbsFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); + qbsFile.write("import qbs.base 1.0\nCppApplication {\n Depends { name: 'Qt.core' }\n" + " files: ['main.cpp', 'myobject.cpp','myobject.h']\n}"); + qbsFile.close(); + errorInfo = doBuildProject("missing-qobject-header/missingheader.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::trackRemoveQObjectHeader() +{ + const qbs::SetupProjectParameters params + = defaultSetupParameters("missing-qobject-header/missingheader.qbs"); + removeBuildDir(params); + QFile qbsFile(params.projectFilePath()); + QVERIFY(qbsFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); + qbsFile.write("import qbs.base 1.0\nCppApplication {\n Depends { name: 'Qt.core' }\n" + " files: ['main.cpp', 'myobject.cpp','myobject.h']\n}"); + qbsFile.close(); + qbs::ErrorInfo errorInfo = doBuildProject("missing-qobject-header/missingheader.qbs"); + VERIFY_NO_ERROR(errorInfo); + + waitForNewTimestamp(); + QVERIFY(qbsFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); + qbsFile.write("import qbs.base 1.0\nCppApplication {\n Depends { name: 'Qt.core' }\n" + " files: ['main.cpp', 'myobject.cpp']\n}"); + qbsFile.close(); + ProcessResultReceiver receiver; + errorInfo = doBuildProject("missing-qobject-header/missingheader.qbs", 0, &receiver); + QVERIFY(errorInfo.hasError()); + QVERIFY2(isAboutUndefinedSymbols(receiver.output), qPrintable(receiver.output)); +} + +void TestApi::transformers() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("transformers/transformers.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + +void TestApi::typeChange() +{ + BuildDescriptionReceiver receiver; + qbs::ErrorInfo errorInfo = doBuildProject("type-change/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(!receiver.descriptions.contains("compiling"), qPrintable(receiver.descriptions)); + + waitForNewTimestamp(); + QFile projectFile("project.qbs"); + QVERIFY2(projectFile.open(QIODevice::ReadWrite), qPrintable(projectFile.errorString())); + QByteArray content = projectFile.readAll(); + content.replace("//", ""); + projectFile.resize(0); + projectFile.write(content); + projectFile.close(); + errorInfo = doBuildProject("type-change/project.qbs", &receiver); + VERIFY_NO_ERROR(errorInfo); + QVERIFY2(receiver.descriptions.contains("compiling"), qPrintable(receiver.descriptions)); +} + +void TestApi::uic() +{ + const qbs::ErrorInfo errorInfo = doBuildProject("uic/uic.qbs"); + VERIFY_NO_ERROR(errorInfo); +} + + +qbs::ErrorInfo TestApi::doBuildProject(const QString &projectFilePath, + QObject *buildDescriptionReceiver, QObject *procResultReceiver, QObject *taskReceiver, + const qbs::BuildOptions &options) +{ + qbs::SetupProjectParameters params = defaultSetupParameters(projectFilePath); + params.setDryRun(options.dryRun()); + const QScopedPointer<qbs::SetupProjectJob> setupJob(qbs::Project().setupProject(params, + m_logSink, 0)); + if (taskReceiver) { + connect(setupJob.data(), SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)), taskReceiver, + SLOT(handleTaskStart(QString))); + } + waitForFinished(setupJob.data()); + if (setupJob->error().hasError()) + return setupJob->error(); + const QScopedPointer<qbs::BuildJob> buildJob(setupJob->project().buildAllProducts(options)); + if (buildDescriptionReceiver) { + connect(buildJob.data(), SIGNAL(reportCommandDescription(QString,QString)), + buildDescriptionReceiver, SLOT(handleDescription(QString,QString))); + } + if (procResultReceiver) { + connect(buildJob.data(), SIGNAL(reportProcessResult(qbs::ProcessResult)), + procResultReceiver, SLOT(handleProcessResult(qbs::ProcessResult))); + } + waitForFinished(buildJob.data()); + return buildJob->error(); +} + QTEST_MAIN(TestApi) #include "tst_api.moc" diff --git a/tests/auto/api/tst_api.h b/tests/auto/api/tst_api.h index 3160c6bf4..098bbf0ed 100644 --- a/tests/auto/api/tst_api.h +++ b/tests/auto/api/tst_api.h @@ -30,9 +30,14 @@ #ifndef QBS_TST_API_H #define QBS_TST_API_H +#include <tools/buildoptions.h> + #include <QObject> -namespace qbs { class SetupProjectParameters; } +namespace qbs { +class ErrorInfo; +class SetupProjectParameters; +} class LogSink; @@ -47,29 +52,76 @@ public: private slots: void initTestCase(); + void addQObjectMacroToCppFile(); + void addedFilePersistent(); + void baseProperties(); void buildGraphLocking(); + void buildProject(); + void buildProject_data(); + void buildProjectDryRun(); + void buildProjectDryRun_data(); void buildSingleFile(); #ifdef QBS_ENABLE_PROJECT_FILE_UPDATES void changeContent(); #endif + void changeDependentLib(); void disabledInstallGroup(); + void disabledProduct(); + void disabledProject(); + void disableProduct(); + void duplicateProductNames(); + void duplicateProductNames_data(); + void dynamicLibs(); + void emptyFileTagList(); + void emptySubmodulesList(); + void explicitlyDependsOn(); + void exportSimple(); + void exportWithRecursiveDepends(); + void fileTagger(); void fileTagsFilterOverride(); void infiniteLoopBuilding(); void infiniteLoopBuilding_data(); void infiniteLoopResolving(); + void inheritQbsSearchPaths(); void installableFiles(); void isRunnable(); void listBuildSystemFiles(); + void mocCppIncluded(); void multiArch(); + void newOutputArtifactInDependency(); + void newPatternMatch(); void nonexistingProjectPropertyFromProduct(); void nonexistingProjectPropertyFromCommandLine(); + void objC(); void projectInvalidation(); void projectLocking(); + void projectWithPropertiesItem(); + void propertiesBlocks(); + void rc(); void references(); + void renameProduct(); + void renameTargetArtifact(); + void removeFileDependency(); + void resolveProject(); + void resolveProject_data(); + void resolveProjectDryRun(); + void resolveProjectDryRun_data(); + void softDependency(); void sourceFileInBuildDir(); + void subProjects(); + void trackAddQObjectHeader(); + void trackRemoveQObjectHeader(); + void transformers(); + void typeChange(); + void uic(); private: qbs::SetupProjectParameters defaultSetupParameters(const QString &projectFilePath) const; + qbs::ErrorInfo doBuildProject(const QString &projectFilePath, + QObject *buildDescriptionReceiver = 0, + QObject *procResultReceiver = 0, + QObject *taskReceiver = 0, + const qbs::BuildOptions &options = qbs::BuildOptions()); LogSink * const m_logSink; const QString m_sourceDataDir; |