2013-08-25 22:42:37 +03:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 Orgad Shaneh <orgads@gmail.com>.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2013-08-25 22:42:37 +03:00
|
|
|
**
|
|
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-08-25 22:42:37 +03:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2013-08-25 22:42:37 +03:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-08-25 22:42:37 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cpptoolsplugin.h"
|
|
|
|
|
#include "cpptoolsreuse.h"
|
2014-12-09 18:42:15 +01:00
|
|
|
#include "cpptoolstestcase.h"
|
2014-01-20 09:15:50 +02:00
|
|
|
#include "cppfilesettingspage.h"
|
2013-08-25 22:42:37 +03:00
|
|
|
|
2014-01-20 09:20:08 +02:00
|
|
|
#include <utils/fileutils.h>
|
2013-08-25 22:42:37 +03:00
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
|
|
|
|
|
|
2014-01-20 09:20:08 +02:00
|
|
|
static void createTempFile(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
QFile file(fileName);
|
|
|
|
|
QDir(QFileInfo(fileName).absolutePath()).mkpath(_("."));
|
|
|
|
|
file.open(QFile::WriteOnly);
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString baseTestDir()
|
|
|
|
|
{
|
|
|
|
|
return QDir::tempPath() + _("/qtc_cppheadersource/");
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 22:42:37 +03:00
|
|
|
namespace CppTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
void CppToolsPlugin::test_headersource()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QString, sourceFileName);
|
|
|
|
|
QFETCH(QString, headerFileName);
|
|
|
|
|
|
2014-12-09 18:42:15 +01:00
|
|
|
Tests::TemporaryDir temporaryDir;
|
|
|
|
|
QVERIFY(temporaryDir.isValid());
|
2013-08-25 22:42:37 +03:00
|
|
|
|
2014-12-09 18:42:15 +01:00
|
|
|
const QDir path = QDir(temporaryDir.path() + QLatin1Char('/') + _(QTest::currentDataTag()));
|
2014-01-20 09:20:08 +02:00
|
|
|
const QString sourcePath = path.absoluteFilePath(sourceFileName);
|
|
|
|
|
const QString headerPath = path.absoluteFilePath(headerFileName);
|
|
|
|
|
createTempFile(sourcePath);
|
|
|
|
|
createTempFile(headerPath);
|
2013-08-25 22:42:37 +03:00
|
|
|
|
2014-12-09 18:42:15 +01:00
|
|
|
bool wasHeader;
|
2013-08-25 22:42:37 +03:00
|
|
|
clearHeaderSourceCache();
|
|
|
|
|
QCOMPARE(correspondingHeaderOrSource(sourcePath, &wasHeader), headerPath);
|
|
|
|
|
QVERIFY(!wasHeader);
|
|
|
|
|
clearHeaderSourceCache();
|
|
|
|
|
QCOMPARE(correspondingHeaderOrSource(headerPath, &wasHeader), sourcePath);
|
|
|
|
|
QVERIFY(wasHeader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppToolsPlugin::test_headersource_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QString>("sourceFileName");
|
|
|
|
|
QTest::addColumn<QString>("headerFileName");
|
|
|
|
|
QTest::newRow("samedir") << _("foo.cpp") << _("foo.h");
|
|
|
|
|
QTest::newRow("includesub") << _("foo.cpp") << _("include/foo.h");
|
2014-01-20 09:15:50 +02:00
|
|
|
QTest::newRow("headerprefix") << _("foo.cpp") << _("testh_foo.h");
|
|
|
|
|
QTest::newRow("sourceprefixwsub") << _("testc_foo.cpp") << _("include/foo.h");
|
|
|
|
|
QTest::newRow("sourceAndHeaderPrefixWithBothsub") << _("src/testc_foo.cpp") << _("include/testh_foo.h");
|
2013-08-25 22:42:37 +03:00
|
|
|
}
|
|
|
|
|
|
2014-01-20 09:20:08 +02:00
|
|
|
void CppToolsPlugin::initTestCase()
|
|
|
|
|
{
|
|
|
|
|
QDir(baseTestDir()).mkpath(_("."));
|
2014-01-20 09:15:50 +02:00
|
|
|
m_fileSettings->headerSearchPaths.append(QLatin1String("include"));
|
|
|
|
|
m_fileSettings->headerSearchPaths.append(QLatin1String("../include"));
|
|
|
|
|
m_fileSettings->sourceSearchPaths.append(QLatin1String("src"));
|
|
|
|
|
m_fileSettings->sourceSearchPaths.append(QLatin1String("../src"));
|
|
|
|
|
m_fileSettings->headerPrefixes.append(QLatin1String("testh_"));
|
|
|
|
|
m_fileSettings->sourcePrefixes.append(QLatin1String("testc_"));
|
2014-01-20 09:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppToolsPlugin::cleanupTestCase()
|
|
|
|
|
{
|
|
|
|
|
Utils::FileUtils::removeRecursively(Utils::FileName::fromString(baseTestDir()));
|
2014-01-20 09:15:50 +02:00
|
|
|
m_fileSettings->headerSearchPaths.removeLast();
|
|
|
|
|
m_fileSettings->headerSearchPaths.removeLast();
|
|
|
|
|
m_fileSettings->sourceSearchPaths.removeLast();
|
|
|
|
|
m_fileSettings->sourceSearchPaths.removeLast();
|
|
|
|
|
m_fileSettings->headerPrefixes.removeLast();
|
|
|
|
|
m_fileSettings->sourcePrefixes.removeLast();
|
2014-01-20 09:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-25 22:42:37 +03:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CppTools
|