aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/buildgraph
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2017-06-20 15:48:59 -0700
committerJake Petroules <jake.petroules@qt.io>2017-06-22 09:02:49 +0000
commit16432be9afc39372b7c35a4fb2929b5835c067e0 (patch)
treee1a7231c6e6abc267e898105fdb67e84ab0040ee /tests/auto/buildgraph
parentdfe13cd2180db68877eb9f72f8115d54b9efa644 (diff)
Move the buildgraph, language and tools tests into the proper locations
Also export necessary symbols that they need. Change-Id: I3023893a3da82cf0d86b0d08df38943db867cf3a Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto/buildgraph')
-rw-r--r--tests/auto/buildgraph/buildgraph.pro1
-rw-r--r--tests/auto/buildgraph/buildgraph.qbs5
-rw-r--r--tests/auto/buildgraph/tst_buildgraph.cpp123
-rw-r--r--tests/auto/buildgraph/tst_buildgraph.h70
4 files changed, 190 insertions, 9 deletions
diff --git a/tests/auto/buildgraph/buildgraph.pro b/tests/auto/buildgraph/buildgraph.pro
index 4388aac1e..10f8c071b 100644
--- a/tests/auto/buildgraph/buildgraph.pro
+++ b/tests/auto/buildgraph/buildgraph.pro
@@ -1,6 +1,7 @@
TARGET = tst_buildgraph
SOURCES = tst_buildgraph.cpp
+HEADERS = tst_buildgraph.h
include(../auto.pri)
include(../../../src/app/shared/logging/logging.pri)
diff --git a/tests/auto/buildgraph/buildgraph.qbs b/tests/auto/buildgraph/buildgraph.qbs
index f6c1cd1f7..aa3cdc3f0 100644
--- a/tests/auto/buildgraph/buildgraph.qbs
+++ b/tests/auto/buildgraph/buildgraph.qbs
@@ -3,5 +3,8 @@ import qbs
QbsAutotest {
testName: "buildgraph"
condition: qbsbuildconfig.enableUnitTests
- files: "tst_buildgraph.cpp"
+ files: [
+ "tst_buildgraph.cpp",
+ "tst_buildgraph.h"
+ ]
}
diff --git a/tests/auto/buildgraph/tst_buildgraph.cpp b/tests/auto/buildgraph/tst_buildgraph.cpp
index be45f5f03..04d32c1fd 100644
--- a/tests/auto/buildgraph/tst_buildgraph.cpp
+++ b/tests/auto/buildgraph/tst_buildgraph.cpp
@@ -5,7 +5,7 @@
**
** This file is part of Qbs.
**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
@@ -14,26 +14,133 @@
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <app/shared/logging/consolelogger.h>
-#include <buildgraph/tst_buildgraph.h>
+#include "tst_buildgraph.h"
+
+#include <buildgraph/artifact.h>
+#include <buildgraph/buildgraph.h>
+#include <buildgraph/cycledetector.h>
+#include <buildgraph/productbuilddata.h>
+#include <buildgraph/projectbuilddata.h>
+#include <language/language.h>
+#include <logging/logger.h>
+#include <tools/error.h>
+
+#include "../shared/logging/consolelogger.h"
-#include <QtCore/qcoreapplication.h>
#include <QtTest/qtest.h>
+using namespace qbs;
+using namespace qbs::Internal;
+
+const TopLevelProjectPtr project = TopLevelProject::create();
+
+TestBuildGraph::TestBuildGraph(ILogSink *logSink) : m_logSink(logSink)
+{
+ project->buildData.reset(new ProjectBuildData);
+}
+
+void TestBuildGraph::initTestCase()
+{
+}
+
+void TestBuildGraph::cleanupTestCase()
+{
+}
+
+
+bool TestBuildGraph::cycleDetected(const ResolvedProductConstPtr &product)
+{
+ try {
+ CycleDetector(Logger(m_logSink)).visitProduct(product);
+ return false;
+ } catch (const ErrorInfo &) {
+ return true;
+ }
+}
+
+ResolvedProductConstPtr TestBuildGraph::productWithDirectCycle()
+{
+ const ResolvedProductPtr product = ResolvedProduct::create();
+ product->project = project;
+ product->buildData.reset(new ProductBuildData);
+ Artifact * const root = new Artifact;
+ root->product = product;
+ Artifact * const child = new Artifact;
+ child->product = product;
+ product->buildData->roots.insert(root);
+ product->buildData->nodes << root << child;
+ qbs::Internal::connect(root, child);
+ qbs::Internal::connect(child, root);
+ return product;
+}
+
+ResolvedProductConstPtr TestBuildGraph::productWithLessDirectCycle()
+{
+ const ResolvedProductPtr product = ResolvedProduct::create();
+ product->project = project;
+ product->buildData.reset(new ProductBuildData);
+ Artifact * const root = new Artifact;
+ Artifact * const child = new Artifact;
+ Artifact * const grandchild = new Artifact;
+ root->product = product;
+ child->product = product;
+ grandchild->product = product;
+ product->buildData->roots << root;
+ product->buildData->nodes << root << child << grandchild;
+ qbs::Internal::connect(root, child);
+ qbs::Internal::connect(child, grandchild);
+ qbs::Internal::connect(grandchild, root);
+ return product;
+}
+
+// root appears as a child, but in a different tree
+ResolvedProductConstPtr TestBuildGraph::productWithNoCycle()
+{
+ const ResolvedProductPtr product = ResolvedProduct::create();
+ product->project = project;
+ product->buildData.reset(new ProductBuildData);
+ Artifact * const root = new Artifact;
+ Artifact * const root2 = new Artifact;
+ root->product = product;
+ root2->product = product;
+ product->buildData->roots << root << root2;
+ product->buildData->nodes << root << root2;
+ qbs::Internal::connect(root2, root);
+ return product;
+}
+
+void TestBuildGraph::testCycle()
+{
+ QVERIFY(cycleDetected(productWithDirectCycle()));
+ QVERIFY(cycleDetected(productWithLessDirectCycle()));
+ QVERIFY(!cycleDetected(productWithNoCycle()));
+}
+
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
- qbs::Internal::TestBuildGraph tbg(ConsoleLogger::instance().logSink());
+ TestBuildGraph tbg(ConsoleLogger::instance().logSink());
return QTest::qExec(&tbg, argc, argv);
}
diff --git a/tests/auto/buildgraph/tst_buildgraph.h b/tests/auto/buildgraph/tst_buildgraph.h
new file mode 100644
index 000000000..756be2f0a
--- /dev/null
+++ b/tests/auto/buildgraph/tst_buildgraph.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qbs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef TST_BUILDGRAPH_H
+#define TST_BUILDGRAPH_H
+
+#include <buildgraph/forward_decls.h>
+#include <language/forward_decls.h>
+#include <logging/ilogsink.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qobject.h>
+
+class TestBuildGraph : public QObject
+{
+ Q_OBJECT
+public:
+ TestBuildGraph(qbs::ILogSink *logSink);
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void testCycle();
+
+private:
+ qbs::Internal::ResolvedProductConstPtr productWithDirectCycle();
+ qbs::Internal::ResolvedProductConstPtr productWithLessDirectCycle();
+ qbs::Internal::ResolvedProductConstPtr productWithNoCycle();
+ bool cycleDetected(const qbs::Internal::ResolvedProductConstPtr &product);
+
+ qbs::ILogSink * const m_logSink;
+};
+
+#endif // TST_BUILDGRAPH_H
+