forked from qt-creator/qt-creator
Tests: Extract TestDataDir to the coreplugin
Change-Id: Ie290c07c07c13134a57f328e9ae876b2af6974db Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -238,3 +238,8 @@ else:unix {
|
||||
}
|
||||
}
|
||||
OTHER_FILES += editormanager/BinFiles.mimetypes.xml
|
||||
|
||||
equals(TEST, 1) {
|
||||
SOURCES += testdatadir.cpp
|
||||
HEADERS += testdatadir.h
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import qbs.base 1.0
|
||||
import "../QtcPlugin.qbs" as QtcPlugin
|
||||
import "../../../qbs/defaults.js" as Defaults
|
||||
|
||||
QtcPlugin {
|
||||
name: "Core"
|
||||
@@ -255,6 +256,15 @@ QtcPlugin {
|
||||
]
|
||||
}
|
||||
|
||||
Group {
|
||||
name: "Tests"
|
||||
condition: Defaults.testsEnabled(qbs)
|
||||
files: [
|
||||
"testdatadir.cpp",
|
||||
"testdatadir.h"
|
||||
]
|
||||
}
|
||||
|
||||
Export {
|
||||
Depends { name: "Aggregation" }
|
||||
Depends { name: "Utils" }
|
||||
|
||||
70
src/plugins/coreplugin/testdatadir.cpp
Normal file
70
src/plugins/coreplugin/testdatadir.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 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 "testdatadir.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QString>
|
||||
#include <QTest>
|
||||
|
||||
using namespace Core::Internal::Tests;
|
||||
|
||||
static void maybeAppendSlash(QString *string)
|
||||
{
|
||||
const QChar slash = QLatin1Char('/');
|
||||
if (!string->endsWith(slash))
|
||||
string->append(slash);
|
||||
}
|
||||
|
||||
TestDataDir::TestDataDir(const QString &directory)
|
||||
: m_directory(directory)
|
||||
{
|
||||
maybeAppendSlash(&m_directory);
|
||||
QFileInfo fi(m_directory);
|
||||
QVERIFY(fi.exists());
|
||||
QVERIFY(fi.isDir());
|
||||
}
|
||||
|
||||
QString TestDataDir::file(const QString &fileName) const
|
||||
{
|
||||
return directory() + fileName;
|
||||
}
|
||||
|
||||
QString TestDataDir::directory(const QString &subdir, bool clean) const
|
||||
{
|
||||
QString path = m_directory;
|
||||
if (!subdir.isEmpty())
|
||||
path += QLatin1String("/") + subdir;
|
||||
if (clean)
|
||||
path = QDir::cleanPath(path);
|
||||
maybeAppendSlash(&path);
|
||||
return path;
|
||||
}
|
||||
59
src/plugins/coreplugin/testdatadir.h
Normal file
59
src/plugins/coreplugin/testdatadir.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 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 TESTDATADIR_H
|
||||
#define TESTDATADIR_H
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
namespace Tests {
|
||||
|
||||
class CORE_EXPORT TestDataDir
|
||||
{
|
||||
public:
|
||||
TestDataDir(const QString &directory);
|
||||
QString file(const QString &fileName) const;
|
||||
|
||||
protected:
|
||||
QString directory(const QString &subdir = QString(), bool clean = true) const;
|
||||
|
||||
private:
|
||||
QString m_directory;
|
||||
};
|
||||
|
||||
} // namespace Tests
|
||||
} // namespace Internal
|
||||
} // namespace Core
|
||||
|
||||
#endif // TESTDATADIR_H
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "cppmodelmanager.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/testdatadir.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <locator/locatorfiltertest.h>
|
||||
#include <utils/fileutils.h>
|
||||
@@ -45,6 +46,7 @@
|
||||
#include <QtTest>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Core::Internal::Tests;
|
||||
using namespace CppTools::Internal;
|
||||
using namespace ExtensionSystem;
|
||||
using namespace Locator;
|
||||
@@ -56,46 +58,11 @@ Q_DECLARE_METATYPE(ILocatorFilter *)
|
||||
|
||||
namespace {
|
||||
|
||||
class TestDataDirectory
|
||||
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
|
||||
{
|
||||
public:
|
||||
TestDataDirectory(const QString &testDataDirectory)
|
||||
: m_testDataDirectory(QLatin1String(SRCDIR "/../../../tests/cpplocators/")
|
||||
+ testDataDirectory)
|
||||
{
|
||||
maybeAppendSlash(&m_testDataDirectory);
|
||||
QFileInfo testDataDir(m_testDataDirectory);
|
||||
QVERIFY(testDataDir.exists());
|
||||
QVERIFY(testDataDir.isDir());
|
||||
}
|
||||
|
||||
/// File from the test data directory (top level)
|
||||
QString file(const QString &fileName) const
|
||||
{
|
||||
return testDataDir() + fileName;
|
||||
}
|
||||
|
||||
private:
|
||||
QString testDataDir(const QString& subdir = QString(), bool clean = true) const
|
||||
{
|
||||
QString path = m_testDataDirectory;
|
||||
if (!subdir.isEmpty())
|
||||
path += QLatin1String("/") + subdir;
|
||||
if (clean)
|
||||
path = QDir::cleanPath(path);
|
||||
maybeAppendSlash(&path);
|
||||
return path;
|
||||
}
|
||||
|
||||
static void maybeAppendSlash(QString *string)
|
||||
{
|
||||
const QChar slash = QLatin1Char('/');
|
||||
if (!string->endsWith(slash))
|
||||
string->append(slash);
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_testDataDirectory;
|
||||
MyTestDataDir(const QString &testDataDirectory)
|
||||
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/cpplocators/") + testDataDirectory) {}
|
||||
};
|
||||
|
||||
class CppLocatorFilterTest : public BasicLocatorFilterTest
|
||||
@@ -199,7 +166,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
|
||||
ILocatorFilter *cppClassesFilter = PluginManager::getObject<CppClassesFilter>();
|
||||
ILocatorFilter *cppLocatorFilter = PluginManager::getObject<CppLocatorFilter>();
|
||||
|
||||
TestDataDirectory testDirectory(QLatin1String("testdata_basic"));
|
||||
MyTestDataDir testDirectory(QLatin1String("testdata_basic"));
|
||||
const QString testFile = testDirectory.file(QLatin1String("file1.cpp"));
|
||||
const QString testFileShort = FileUtils::shortNativePath(FileName::fromString(testFile));
|
||||
|
||||
@@ -242,7 +209,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
|
||||
|
||||
void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
|
||||
{
|
||||
TestDataDirectory testDirectory(QLatin1String("testdata_basic"));
|
||||
MyTestDataDir testDirectory(QLatin1String("testdata_basic"));
|
||||
const QString testFile = testDirectory.file(QLatin1String("file1.cpp"));
|
||||
|
||||
QList<ResultData> expectedResults = QList<ResultData>()
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "modelmanagertesthelper.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/testdatadir.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -59,57 +60,23 @@ Q_DECLARE_METATYPE(QList<ProjectFile>)
|
||||
|
||||
namespace {
|
||||
|
||||
class TestDataDirectory
|
||||
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
|
||||
{
|
||||
public:
|
||||
TestDataDirectory(const QString &testDataDirectory)
|
||||
: m_testDataDirectory(QLatin1String(SRCDIR "/../../../tests/cppmodelmanager/")
|
||||
+ testDataDirectory)
|
||||
{
|
||||
QFileInfo testDataDir(m_testDataDirectory);
|
||||
QVERIFY(testDataDir.exists());
|
||||
QVERIFY(testDataDir.isDir());
|
||||
}
|
||||
|
||||
MyTestDataDir(const QString &dir)
|
||||
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/cppmodelmanager/") + dir)
|
||||
{}
|
||||
|
||||
QString includeDir(bool cleaned = true) const
|
||||
{
|
||||
return testDataDir(QLatin1String("include"), cleaned);
|
||||
}
|
||||
{ return directory(QLatin1String("include"), cleaned); }
|
||||
|
||||
QString frameworksDir(bool cleaned = true) const
|
||||
{
|
||||
return testDataDir(QLatin1String("frameworks"), cleaned);
|
||||
}
|
||||
{ return directory(QLatin1String("frameworks"), cleaned); }
|
||||
|
||||
QString fileFromSourcesDir(const QString &fileName) const
|
||||
{
|
||||
return testDataDir(QLatin1String("sources")) + fileName;
|
||||
}
|
||||
|
||||
/// File from the test data directory (top leve)
|
||||
QString file(const QString &fileName) const
|
||||
{
|
||||
return testDataDir(QString()) + fileName;
|
||||
}
|
||||
|
||||
private:
|
||||
QString testDataDir(const QString& subdir, bool cleaned = true) const
|
||||
{
|
||||
QString path = m_testDataDirectory;
|
||||
if (!subdir.isEmpty())
|
||||
path += QLatin1String("/") + subdir;
|
||||
if (cleaned)
|
||||
return CppPreprocessor::cleanPath(path);
|
||||
else
|
||||
return path;
|
||||
}
|
||||
|
||||
private:
|
||||
const QString m_testDataDirectory;
|
||||
{ return directory(QLatin1String("sources")) + fileName; }
|
||||
};
|
||||
|
||||
|
||||
// TODO: When possible, use this helper class in all tests
|
||||
class ProjectCreator
|
||||
{
|
||||
@@ -121,7 +88,7 @@ public:
|
||||
/// 'files' is expected to be a list of file names that reside in 'dir'.
|
||||
void create(const QString &name, const QString &dir, const QStringList files)
|
||||
{
|
||||
const TestDataDirectory projectDir(dir);
|
||||
const MyTestDataDir projectDir(dir);
|
||||
foreach (const QString &file, files)
|
||||
projectFiles << projectDir.file(file);
|
||||
|
||||
@@ -239,7 +206,7 @@ void CppToolsPlugin::test_modelmanager_paths_are_clean()
|
||||
ModelManagerTestHelper helper;
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
const TestDataDirectory testDataDir(QLatin1String("testdata"));
|
||||
const MyTestDataDir testDataDir(QLatin1String("testdata"));
|
||||
|
||||
Project *project = helper.createProject(QLatin1String("test_modelmanager_paths_are_clean"));
|
||||
ProjectInfo pi = mm->projectInfo(project);
|
||||
@@ -273,7 +240,7 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
|
||||
ModelManagerTestHelper helper;
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
const TestDataDirectory testDataDir(QLatin1String("testdata"));
|
||||
const MyTestDataDir testDataDir(QLatin1String("testdata"));
|
||||
|
||||
Project *project = helper.createProject(QLatin1String("test_modelmanager_framework_headers"));
|
||||
ProjectInfo pi = mm->projectInfo(project);
|
||||
@@ -318,7 +285,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
|
||||
ModelManagerTestHelper helper;
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
const TestDataDirectory testDataDir(QLatin1String("testdata"));
|
||||
const MyTestDataDir testDataDir(QLatin1String("testdata"));
|
||||
|
||||
const QString testCpp(testDataDir.fileFromSourcesDir(
|
||||
QLatin1String("test_modelmanager_refresh.cpp")));
|
||||
@@ -381,7 +348,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times()
|
||||
ModelManagerTestHelper helper;
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
const TestDataDirectory testDataDir(QLatin1String("testdata_refresh"));
|
||||
const MyTestDataDir testDataDir(QLatin1String("testdata_refresh"));
|
||||
|
||||
const QString testHeader1(testDataDir.file(QLatin1String("defines.h")));
|
||||
const QString testHeader2(testDataDir.file(QLatin1String("header.h")));
|
||||
@@ -452,7 +419,7 @@ void CppToolsPlugin::test_modelmanager_refresh_test_for_changes()
|
||||
ModelManagerTestHelper helper;
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
const TestDataDirectory testDataDir(QLatin1String("testdata_refresh"));
|
||||
const MyTestDataDir testDataDir(QLatin1String("testdata_refresh"));
|
||||
const QString testCpp(testDataDir.file(QLatin1String("source.cpp")));
|
||||
|
||||
Project *project = helper.createProject(QLatin1String("test_modelmanager_refresh_2"));
|
||||
@@ -484,7 +451,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed()
|
||||
ModelManagerTestHelper helper;
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
const TestDataDirectory testDataDir(QLatin1String("testdata_refresh"));
|
||||
const MyTestDataDir testDataDir(QLatin1String("testdata_refresh"));
|
||||
|
||||
const QString testHeader1(testDataDir.file(QLatin1String("header.h")));
|
||||
const QString testHeader2(testDataDir.file(QLatin1String("defines.h")));
|
||||
@@ -618,7 +585,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
|
||||
QTest::addColumn<QList<ProjectFile> >("initialProjectFiles");
|
||||
QTest::addColumn<QList<ProjectFile> >("finalProjectFiles");
|
||||
|
||||
const TestDataDirectory testDataDir(QLatin1String("testdata_refresh2"));
|
||||
const MyTestDataDir testDataDir(QLatin1String("testdata_refresh2"));
|
||||
const QString testCpp(testDataDir.file(QLatin1String("source.cpp")));
|
||||
const QString testCpp2(testDataDir.file(QLatin1String("source2.cpp")));
|
||||
|
||||
@@ -690,7 +657,7 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
||||
{
|
||||
ModelManagerTestHelper helper;
|
||||
|
||||
TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
MyTestDataDir testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
const QString projectFile = testDataDirectory.file(QLatin1String("testdata_guiproject1.pro"));
|
||||
|
||||
// Open project with *.ui file
|
||||
@@ -742,7 +709,7 @@ void CppToolsPlugin::test_modelmanager_gc_if_last_cppeditor_closed()
|
||||
{
|
||||
ModelManagerTestHelper helper;
|
||||
|
||||
TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
MyTestDataDir testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
const QString file = testDataDirectory.file(QLatin1String("main.cpp"));
|
||||
|
||||
Core::EditorManager *em = Core::EditorManager::instance();
|
||||
@@ -773,7 +740,7 @@ void CppToolsPlugin::test_modelmanager_dont_gc_opened_files()
|
||||
{
|
||||
ModelManagerTestHelper helper;
|
||||
|
||||
TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
MyTestDataDir testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
const QString file = testDataDirectory.file(QLatin1String("main.cpp"));
|
||||
|
||||
Core::EditorManager *em = Core::EditorManager::instance();
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "cppmodelmanager.h"
|
||||
#include "searchsymbols.h"
|
||||
|
||||
#include <coreplugin/testdatadir.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QtTest>
|
||||
@@ -42,46 +43,13 @@ using namespace CppTools::Internal;
|
||||
|
||||
namespace {
|
||||
|
||||
class TestDataDirectory
|
||||
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
|
||||
{
|
||||
public:
|
||||
TestDataDirectory(const QString &testDataDirectory)
|
||||
: m_testDataDirectory(QLatin1String(SRCDIR "/../../../tests/cppsymbolsearcher/")
|
||||
+ testDataDirectory)
|
||||
{
|
||||
maybeAppendSlash(&m_testDataDirectory);
|
||||
QFileInfo testDataDir(m_testDataDirectory);
|
||||
QVERIFY(testDataDir.exists());
|
||||
QVERIFY(testDataDir.isDir());
|
||||
}
|
||||
|
||||
/// File from the test data directory (top level)
|
||||
QString file(const QString &fileName) const
|
||||
{
|
||||
return testDataDir() + fileName;
|
||||
}
|
||||
|
||||
private:
|
||||
QString testDataDir(const QString &subdir = QString(), bool clean = true) const
|
||||
{
|
||||
QString path = m_testDataDirectory;
|
||||
if (!subdir.isEmpty())
|
||||
path += QLatin1String("/") + subdir;
|
||||
if (clean)
|
||||
path = QDir::cleanPath(path);
|
||||
maybeAppendSlash(&path);
|
||||
return path;
|
||||
}
|
||||
|
||||
static void maybeAppendSlash(QString *string)
|
||||
{
|
||||
const QChar slash = QLatin1Char('/');
|
||||
if (!string->endsWith(slash))
|
||||
string->append(slash);
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_testDataDirectory;
|
||||
MyTestDataDir(const QString &testDataDirectory)
|
||||
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/cppsymbolsearcher/")
|
||||
+ testDataDirectory)
|
||||
{}
|
||||
};
|
||||
|
||||
class ResultData
|
||||
@@ -194,7 +162,7 @@ void CppToolsPlugin::test_builtinsymbolsearcher_data()
|
||||
QTest::addColumn<SymbolSearcher::Parameters>("searchParameters");
|
||||
QTest::addColumn<ResultDataList>("expectedResults");
|
||||
|
||||
TestDataDirectory testDirectory(QLatin1String("testdata_basic"));
|
||||
MyTestDataDir testDirectory(QLatin1String("testdata_basic"));
|
||||
const QString testFile = testDirectory.file(QLatin1String("file1.cpp"));
|
||||
|
||||
QScopedPointer<CppIndexingSupport> builtinIndexingSupport(new BuiltinIndexingSupport);
|
||||
|
||||
Reference in New Issue
Block a user