Skip to content
Snippets Groups Projects
Commit 0cac83af authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

C++: add unittest for modelmanager path cleaning.


Change-Id: I30815b191654cba5eedf92a9afd2ed1b48af8b87
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 682e17ca
No related branches found
No related tags found
No related merge requests found
...@@ -168,6 +168,9 @@ public: ...@@ -168,6 +168,9 @@ public:
QHashIterator<QString, QPair<QString, unsigned> > iterator() const QHashIterator<QString, QPair<QString, unsigned> > iterator() const
{ return QHashIterator<QString, QPair<QString, unsigned> >(_elements); } { return QHashIterator<QString, QPair<QString, unsigned> >(_elements); }
int size() const
{ return _elements.size(); }
private: private:
typedef QHash<QString, QPair<QString, unsigned> > Table; typedef QHash<QString, QPair<QString, unsigned> > Table;
Table _elements; Table _elements;
......
/****************************************************************************
**
** Copyright (C) 2012 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 "cpptoolsplugin.h"
#include "cppmodelmanager.h"
#include "modelmanagertesthelper.h"
#include <QtTest>
#include <QDebug>
using namespace CppTools::Internal;
typedef CPlusPlus::CppModelManagerInterface::ProjectInfo ProjectInfo;
typedef CPlusPlus::CppModelManagerInterface::ProjectPart ProjectPart;
typedef ProjectExplorer::Project Project;
namespace {
QString testDataDir(const QString& subdir, bool cleaned = true)
{
QString path = QLatin1String(SRCDIR "/../../../tests/cppmodelmanager/testdata");
if (!subdir.isEmpty())
path += QLatin1String("/") + subdir;
if (cleaned)
return CppPreprocessor::cleanPath(path);
else
return path;
}
QString testIncludeDir(bool cleaned = true)
{
return testDataDir(QLatin1String("include"), cleaned);
}
QString testFrameworksDir(bool cleaned = true)
{
return testDataDir(QLatin1String("frameworks"), cleaned);
}
} // anonymous namespace
void CppToolsPlugin::test_modelmanager_paths()
{
ModelManagerTestHelper helper;
CppModelManager *mm = CppModelManager::instance();
Project *project = helper.createProject(QLatin1String("test_modelmanager_paths"));
ProjectInfo pi = mm->projectInfo(project);
QCOMPARE(pi.project().data(), project);
ProjectPart::Ptr part(new ProjectPart);
pi.appendProjectPart(part);
part->language = ProjectPart::CXX;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths = QStringList() << testIncludeDir(false);
part->frameworkPaths = QStringList() << testFrameworksDir(false);
mm->updateProjectInfo(pi);
QStringList includePaths = mm->includePaths();
QCOMPARE(includePaths.size(), 1);
QVERIFY(includePaths.contains(testIncludeDir()));
QStringList frameworkPaths = mm->frameworkPaths();
QCOMPARE(frameworkPaths.size(), 1);
QVERIFY(frameworkPaths.contains(testFrameworksDir()));
}
...@@ -98,5 +98,12 @@ FORMS += completionsettingspage.ui \ ...@@ -98,5 +98,12 @@ FORMS += completionsettingspage.ui \
equals(TEST, 1) { equals(TEST, 1) {
SOURCES += \ SOURCES += \
cppcodegen_test.cpp \ cppcodegen_test.cpp \
cppcompletion_test.cpp cppcompletion_test.cpp \
cppmodelmanager_test.cpp \
modelmanagertesthelper.cpp
HEADERS += \
modelmanagertesthelper.h
DEFINES += SRCDIR=\\\"$$PWD\\\"
} }
...@@ -113,6 +113,8 @@ private slots: ...@@ -113,6 +113,8 @@ private slots:
void test_completion_instantiate_nested_class_when_enclosing_is_template(); void test_completion_instantiate_nested_class_when_enclosing_is_template();
void test_completion_instantiate_nested_of_nested_class_when_enclosing_is_template(); void test_completion_instantiate_nested_of_nested_class_when_enclosing_is_template();
void test_modelmanager_paths();
private: private:
void test_completion(); void test_completion();
#endif #endif
......
/****************************************************************************
**
** Copyright (C) 2012 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 "modelmanagertesthelper.h"
#include <QtTest>
#include <cassert>
using namespace CppTools::Internal;
TestProject::TestProject(const QString &name, QObject *parent)
: m_name (name)
{
setParent(parent);
}
TestProject::~TestProject()
{
}
ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent) :
QObject(parent)
{
CppModelManager *mm = CppModelManager::instance();
assert(mm);
connect(this, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)), mm, SLOT(onAboutToRemoveProject(ProjectExplorer::Project*)));
connect(this, SIGNAL(projectAdded(ProjectExplorer::Project*)), mm, SLOT(onProjectAdded(ProjectExplorer::Project*)));
cleanup();
verifyClean();
}
ModelManagerTestHelper::~ModelManagerTestHelper()
{
cleanup();
verifyClean();
}
void ModelManagerTestHelper::cleanup()
{
CppModelManager *mm = CppModelManager::instance();
assert(mm);
QList<ProjectInfo> pies = mm->projectInfos();
foreach (const ProjectInfo &pie, pies)
emit aboutToRemoveProject(pie.project().data());
}
void ModelManagerTestHelper::verifyClean()
{
CppModelManager *mm = CppModelManager::instance();
assert(mm);
QVERIFY(mm->projectInfos().isEmpty());
QVERIFY(mm->includePaths().isEmpty());
QVERIFY(mm->frameworkPaths().isEmpty());
QVERIFY(mm->definedMacros().isEmpty());
QVERIFY(mm->projectFiles().isEmpty());
QVERIFY(mm->snapshot().isEmpty());
QCOMPARE(mm->workingCopy().size(), 1);
QVERIFY(mm->workingCopy().contains(mm->configurationFileName()));
}
ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject(const QString &name)
{
TestProject *tp = new TestProject(name, this);
emit projectAdded(tp);
return tp;
}
/****************************************************************************
**
** Copyright (C) 2012 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 CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H
#define CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H
#include "cppmodelmanager.h"
#include <QObject>
namespace CppTools {
namespace Internal {
class TestProject: public ProjectExplorer::Project
{
Q_OBJECT
public:
TestProject(const QString &name, QObject *parent);
virtual ~TestProject();
virtual QString displayName() const
{ return m_name; }
virtual Core::Id id() const
{ return Core::Id(m_name); }
virtual Core::IDocument *document() const
{ return 0; }
virtual ProjectExplorer::IProjectManager *projectManager() const
{ return 0; }
virtual ProjectExplorer::ProjectNode *rootProjectNode() const
{ return 0; }
virtual QStringList files(FilesMode fileMode) const
{ Q_UNUSED(fileMode); return QStringList(); }
private:
QString m_name;
};
class ModelManagerTestHelper: public QObject
{
Q_OBJECT
public:
typedef CPlusPlus::CppModelManagerInterface::ProjectInfo ProjectInfo;
typedef ProjectExplorer::Project Project;
explicit ModelManagerTestHelper(QObject *parent = 0);
~ModelManagerTestHelper();
void cleanup();
void verifyClean();
Project *createProject(const QString &name);
signals:
void aboutToRemoveProject(ProjectExplorer::Project *project);
void projectAdded(ProjectExplorer::Project*);
};
} // namespace Internal
} // namespace CppTools
#endif // CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment