diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2014-06-17 16:18:42 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-07-07 10:56:21 +0200 |
commit | 922c330bccd6b30ad85e847f505a68ddbca4c5f1 (patch) | |
tree | 53cca2427748c2077bbb784f817a6f8aeb78d8d7 | |
parent | 62aea4728f6200e5e1659cc4c185e1e1bf3e50ed (diff) |
GenericProject: add simple test.
Change-Id: Idce9c44caf0b963fa9750b8abc7fc8aab6ab8227
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
12 files changed, 293 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 75cc619019..d98edd09bd 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ Thumbs.db # qtcreator generated files *.pro.user* +*.creator.user* *.qbs.user* *.qmlproject.user* *.pluginspec diff --git a/src/plugins/genericprojectmanager/cppmodelmanagerhelper.cpp b/src/plugins/genericprojectmanager/cppmodelmanagerhelper.cpp new file mode 100644 index 0000000000..33621345b2 --- /dev/null +++ b/src/plugins/genericprojectmanager/cppmodelmanagerhelper.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** 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 "cppmodelmanagerhelper.h" + +#include <QCoreApplication> +#include <QSignalSpy> +#include <QTest> +#include <QThread> + +using namespace CppTools; +using namespace GenericProjectManager::Internal::Tests; + +CppModelManagerHelper::CppModelManagerHelper(QObject *parent) : + QObject(parent) +{ + connect(cppModelManager(), SIGNAL(sourceFilesRefreshed(const QStringList &)), + this, SLOT(onSourceFilesRefreshed(const QStringList &))); +} + + +CppModelManagerInterface *CppModelManagerHelper::cppModelManager() +{ + return CppModelManagerInterface::instance(); +} + +void CppModelManagerHelper::waitForSourceFilesRefreshed(const QString &file, int timeOut) +{ + waitForSourceFilesRefreshed(QStringList() << file, timeOut); +} + +void CppModelManagerHelper::waitForSourceFilesRefreshed(const QStringList &files, int timeOut) +{ + QTime t; + t.start(); + QSignalSpy spy(cppModelManager(), SIGNAL(sourceFilesRefreshed(const QStringList &))); + + foreach (const QString &file, files) { + while (!m_refreshedSourceFiles.contains(file)) { +#if QT_VERSION >= 0x050000 + QVERIFY(spy.wait()); +#else // Qt 4.x + class MyThread: public QThread + { + public: + static void Zzzzz() + { + QThread::msleep(50); + } + }; + + MyThread::Zzzzz(); + QCoreApplication::processEvents(); +#endif + } + QVERIFY(t.elapsed() <= timeOut); + } +} + +void CppModelManagerHelper::onSourceFilesRefreshed(const QStringList &files) +{ + m_refreshedSourceFiles += files; +} diff --git a/src/plugins/genericprojectmanager/cppmodelmanagerhelper.h b/src/plugins/genericprojectmanager/cppmodelmanagerhelper.h new file mode 100644 index 0000000000..e854c73c88 --- /dev/null +++ b/src/plugins/genericprojectmanager/cppmodelmanagerhelper.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** 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 CPPMODELMANAGERHELPER_H +#define CPPMODELMANAGERHELPER_H + +#include <cpptools/cppmodelmanagerinterface.h> + +#include <QObject> + +namespace GenericProjectManager { +namespace Internal { +namespace Tests { + +class CppModelManagerHelper : public QObject +{ + Q_OBJECT +public: + explicit CppModelManagerHelper(QObject *parent = 0); + + static CppTools::CppModelManagerInterface *cppModelManager(); + + enum { defaultTimeOut = 30 * 1000 }; // 30 secs + void waitForSourceFilesRefreshed(const QString &file = QString(), int timeOut = defaultTimeOut); + void waitForSourceFilesRefreshed(const QStringList &files, int timeOut = defaultTimeOut); + +private slots: + void onSourceFilesRefreshed(const QStringList &files); + +private: + QStringList m_refreshedSourceFiles; +}; + +} // Tests namespace +} // Internal namespace +} // GenericProjectManager namespace + +#endif // CPPMODELMANAGERHELPER_H diff --git a/src/plugins/genericprojectmanager/genericprojectmanager.pro b/src/plugins/genericprojectmanager/genericprojectmanager.pro index 3ccecd9f86..a822f5b240 100644 --- a/src/plugins/genericprojectmanager/genericprojectmanager.pro +++ b/src/plugins/genericprojectmanager/genericprojectmanager.pro @@ -23,3 +23,9 @@ SOURCES = genericproject.cpp \ filesselectionwizardpage.cpp RESOURCES += genericproject.qrc FORMS += genericmakestep.ui + +equals(TEST, 1) { + SOURCES += genericprojectplugin_test.cpp cppmodelmanagerhelper.cpp + HEADERS += cppmodelmanagerhelper.h + DEFINES += SRCDIR=\\\"$$PWD\\\" +} diff --git a/src/plugins/genericprojectmanager/genericprojectmanager.qbs b/src/plugins/genericprojectmanager/genericprojectmanager.qbs index 5e345dd8f8..f3d5ec50ae 100644 --- a/src/plugins/genericprojectmanager/genericprojectmanager.qbs +++ b/src/plugins/genericprojectmanager/genericprojectmanager.qbs @@ -1,4 +1,5 @@ import qbs 1.0 +import qbs.FileInfo import QtcPlugin @@ -39,4 +40,15 @@ QtcPlugin { "pkgconfigtool.cpp", "pkgconfigtool.h", ] + + Group { + name: "Tests" + condition: project.testsEnabled + files: [ + "cppmodelmanagerhelper.cpp", "cppmodelmanagerhelper.h", + "genericprojectplugin_test.cpp", + ] + + cpp.defines: outer.concat(['SRCDIR="' + FileInfo.path(filePath) + '"']) + } } diff --git a/src/plugins/genericprojectmanager/genericprojectplugin.h b/src/plugins/genericprojectmanager/genericprojectplugin.h index 0fe8790544..97279bc13b 100644 --- a/src/plugins/genericprojectmanager/genericprojectplugin.h +++ b/src/plugins/genericprojectmanager/genericprojectplugin.h @@ -61,6 +61,11 @@ private slots: void updateContextMenu(ProjectExplorer::Project *, ProjectExplorer::Node *); void editFiles(); +#ifdef WITH_TESTS +private slots: + void test_simple(); +#endif // WITH_TESTS + private: ProjectFilesFactory *m_projectFilesEditorFactory; QAction *m_editFilesAction; diff --git a/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp b/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp new file mode 100644 index 0000000000..2f21b67364 --- /dev/null +++ b/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** 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 "cppmodelmanagerhelper.h" +#include "genericprojectplugin.h" + +#include <projectexplorer/project.h> +#include <projectexplorer/projectexplorer.h> +#include <projectexplorer/session.h> + +#include <QFileInfo> +#include <QTest> + +using namespace CppTools; +using namespace GenericProjectManager; +using namespace GenericProjectManager::Internal; +using namespace GenericProjectManager::Internal::Tests; +using namespace ProjectExplorer; + +inline static QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } +inline static QString projectFilePath(const QString &project) +{ + const QString fileName(_(SRCDIR "/../../../tests/genericprojectmanager/") + project); + return QFileInfo(fileName).absoluteFilePath(); +} + +namespace { +class ProjectExplorerHelper +{ +public: + static ProjectExplorerPlugin *getInstance() + { return ProjectExplorerPlugin::instance(); } + + ProjectExplorerHelper() + { + QVERIFY(!SessionManager::hasProjects()); + } + + ~ProjectExplorerHelper() + { + foreach (Project *project, m_openProjects) + getInstance()->unloadProject(project); + } + + Project *openProject(const QString &projectFile) + { + QString error; + Project *project = getInstance()->openProject(projectFile, &error); + if (!error.isEmpty()) + qWarning() << error; + if (!project) + return 0; + m_openProjects.append(project); + return project; + } + +private: + QList<Project *> m_openProjects; +}; +} // anonymous namespace + +void GenericProjectPlugin::test_simple() +{ + CppModelManagerHelper cppHelper; + + QString projectFile = _("testdata_simpleproject/simpleproject.creator"); + ProjectExplorerHelper pHelper; + Project *project = pHelper.openProject(projectFilePath(projectFile)); + QVERIFY(project); + + QString mainFile = projectFilePath(_("testdata_simpleproject/main.cpp")); + cppHelper.waitForSourceFilesRefreshed(mainFile); + + CppModelManagerInterface *mm = cppHelper.cppModelManager(); + CppModelManagerInterface::ProjectInfo pInfo = mm->projectInfo(project); + + QCOMPARE(pInfo.projectParts().size(), 1); + + ProjectPart::Ptr pPart = pInfo.projectParts().first(); + QVERIFY(pPart); + QCOMPARE(pPart->files.size(), 1); + QCOMPARE(pPart->files.first().path, mainFile); + QCOMPARE(pPart->files.first().kind, ProjectFile::CXXSource); +} diff --git a/tests/genericprojectmanager/testdata_simpleproject/main.cpp b/tests/genericprojectmanager/testdata_simpleproject/main.cpp new file mode 100644 index 0000000000..5047a34e39 --- /dev/null +++ b/tests/genericprojectmanager/testdata_simpleproject/main.cpp @@ -0,0 +1,3 @@ +int main() +{ +} diff --git a/tests/genericprojectmanager/testdata_simpleproject/simpleproject.config b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.config new file mode 100644 index 0000000000..9dcf447363 --- /dev/null +++ b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.config @@ -0,0 +1 @@ +// Nothing to be seen, move along. diff --git a/tests/genericprojectmanager/testdata_simpleproject/simpleproject.creator b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.creator new file mode 100644 index 0000000000..e94cbbd302 --- /dev/null +++ b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.creator @@ -0,0 +1 @@ +[General] diff --git a/tests/genericprojectmanager/testdata_simpleproject/simpleproject.files b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.files new file mode 100644 index 0000000000..f0ce4404d8 --- /dev/null +++ b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.files @@ -0,0 +1 @@ +main.cpp diff --git a/tests/genericprojectmanager/testdata_simpleproject/simpleproject.includes b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.includes new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/genericprojectmanager/testdata_simpleproject/simpleproject.includes |