Commit 31034870 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Tests: Move TestDataDir into plugintestutils.{h,cpp}

Change-Id: I76d5e421258eda85907e56762a59894ce7f84f13
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent f47e7f68
......@@ -237,8 +237,6 @@ else:unix {
OTHER_FILES += editormanager/BinFiles.mimetypes.xml
equals(TEST, 1) {
SOURCES += testdatadir.cpp \
plugintestutils.cpp
HEADERS += testdatadir.h \
plugintestutils.h
SOURCES += plugintestutils.cpp
HEADERS += plugintestutils.h
}
......@@ -183,8 +183,6 @@ QtcPlugin {
files: [
"plugintestutils.cpp",
"plugintestutils.h",
"testdatadir.cpp",
"testdatadir.h"
]
}
......
......@@ -34,6 +34,10 @@
#include "editormanager/ieditor.h"
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QString>
#include <QTest>
void Core::Tests::closeAndDeleteEditors(QList<IEditor *> editorsToClose)
{
......@@ -48,3 +52,35 @@ void Core::Tests::closeAndDeleteEditor(Core::IEditor *editor)
{
closeAndDeleteEditors(QList<IEditor *>() << editor);
}
static void maybeAppendSlash(QString *string)
{
const QChar slash = QLatin1Char('/');
if (!string->endsWith(slash))
string->append(slash);
}
Core::Tests::TestDataDir::TestDataDir(const QString &directory)
: m_directory(directory)
{
maybeAppendSlash(&m_directory);
QFileInfo fi(m_directory);
QVERIFY(fi.exists());
QVERIFY(fi.isDir());
}
QString Core::Tests::TestDataDir::file(const QString &fileName) const
{
return directory() + fileName;
}
QString Core::Tests::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;
}
......@@ -34,6 +34,7 @@
#include "core_global.h"
#include <QList>
#include <QString>
namespace Core {
......@@ -41,9 +42,24 @@ class IEditor;
namespace Tests {
/// Closing and deleting editors
void CORE_EXPORT closeAndDeleteEditor(Core::IEditor *editor);
void CORE_EXPORT closeAndDeleteEditors(QList<Core::IEditor *> editorsToClose);
/// Referencing test data
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 Core
......
/****************************************************************************
**
** 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;
}
/****************************************************************************
**
** 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
......@@ -30,7 +30,7 @@
#include "cpptoolsplugin.h"
#include "cpptoolsreuse.h"
#include <coreplugin/testdatadir.h>
#include <coreplugin/plugintestutils.h>
#include <QDir>
#include <QtTest>
......@@ -46,7 +46,7 @@ void CppToolsPlugin::test_headersource()
QFETCH(QString, headerFileName);
bool wasHeader;
Core::Internal::Tests::TestDataDir dataDir(
Core::Tests::TestDataDir dataDir(
_(SRCDIR "/../../../tests/cppheadersource/") + _(QTest::currentDataTag()));
const QString sourcePath = dataDir.file(sourceFileName);
......
......@@ -37,7 +37,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/plugintestutils.h>
#include <coreplugin/testdatadir.h>
#include <extensionsystem/pluginmanager.h>
#include <locator/locatorfiltertest.h>
#include <utils/fileutils.h>
......@@ -47,7 +46,6 @@
#include <QtTest>
using namespace Core;
using namespace Core::Internal::Tests;
using namespace CppTools::Internal;
using namespace ExtensionSystem;
using namespace Locator;
......@@ -59,7 +57,7 @@ Q_DECLARE_METATYPE(ILocatorFilter *)
namespace {
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
class MyTestDataDir : public Core::Tests::TestDataDir
{
public:
MyTestDataDir(const QString &testDataDirectory)
......
......@@ -34,7 +34,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/plugintestutils.h>
#include <coreplugin/testdatadir.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <utils/hostosinfo.h>
......@@ -61,7 +60,7 @@ Q_DECLARE_METATYPE(QList<ProjectFile>)
namespace {
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
class MyTestDataDir : public Core::Tests::TestDataDir
{
public:
MyTestDataDir(const QString &dir)
......
......@@ -33,7 +33,7 @@
#include "cppmodelmanager.h"
#include "searchsymbols.h"
#include <coreplugin/testdatadir.h>
#include <coreplugin/plugintestutils.h>
#include <utils/runextensions.h>
#include <QtTest>
......@@ -43,7 +43,7 @@ using namespace CppTools::Internal;
namespace {
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
class MyTestDataDir : public Core::Tests::TestDataDir
{
public:
MyTestDataDir(const QString &testDataDirectory)
......
......@@ -35,7 +35,6 @@
#include "formeditorw.h"
#include <coreplugin/plugintestutils.h>
#include <coreplugin/testdatadir.h>
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cppmodelmanager.h>
......@@ -48,7 +47,6 @@
#include <QtTest>
using namespace Core;
using namespace Core::Internal::Tests;
using namespace CppTools;
using namespace CPlusPlus;
using namespace Designer;
......@@ -56,7 +54,7 @@ using namespace Designer::Internal;
namespace {
class MyTestDataDir : public Core::Internal::Tests::TestDataDir {
class MyTestDataDir : public Core::Tests::TestDataDir {
public:
MyTestDataDir(const QString &dir)
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/designer/") + dir)
......
......@@ -33,7 +33,7 @@
#include "basefilefilter.h"
#include "locatorfiltertest.h"
#include <coreplugin/testdatadir.h>
#include <coreplugin/plugintestutils.h>
#include <utils/fileutils.h>
#include <QDir>
......@@ -44,7 +44,7 @@ using namespace Locator::Internal::Tests;
namespace {
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
class MyTestDataDir : public Core::Tests::TestDataDir
{
public:
MyTestDataDir(const QString &testDataDirectory)
......
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