Commit 922c330b authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

GenericProject: add simple test.

Change-Id: Idce9c44caf0b963fa9750b8abc7fc8aab6ab8227
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 62aea472
......@@ -37,6 +37,7 @@ Thumbs.db
# qtcreator generated files
*.pro.user*
*.creator.user*
*.qbs.user*
*.qmlproject.user*
*.pluginspec
......
/****************************************************************************
**
** 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;
}
/****************************************************************************
**
** 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
......@@ -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\\\"
}
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) + '"'])
}
}
......@@ -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;
......
/****************************************************************************
**
** 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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment