diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2014-08-11 15:59:09 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2014-08-14 11:16:34 +0200 |
commit | 09d9ce2c265450d786052100bedb059870dddc23 (patch) | |
tree | 3e811fa1a328a8d19ddbffec5a94d2c61add84fc /tests/auto/api/testdata/transformers | |
parent | 4e7f1023b0fc1349047357cf8926fa68761cc546 (diff) |
Turn some blackbox tests into API tests.
Different test executables can run in parallel, whereas the functions
within one test executable cannot. This means that tst_blackbox is
currently a bottleneck, as it takes an order of magnitude longer
than all other tests combined. We therefore turn a number of blackbox
tests into API tests (most tests work equally well in either).
The run-time of these two test executables is now about the same, and as
a result, the time it takes to run "make check" has almost halved.
Change-Id: I55ef43a60588f86a8438bdecb7795aca0880efd0
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests/auto/api/testdata/transformers')
-rw-r--r-- | tests/auto/api/testdata/transformers/main.cpp | 71 | ||||
-rw-r--r-- | tests/auto/api/testdata/transformers/transformers.qbs | 86 |
2 files changed, 157 insertions, 0 deletions
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; + } + } + } +} + |