Skip to content
Snippets Groups Projects
Commit f506104f authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

CppTools: Cleanup header/source test


Dynamically create data files in tempPath and clean them up when
finished.

Change-Id: Ie78f557b185b264acc0d0f5814646c203d8a93f4
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 0f4e3c35
No related branches found
No related tags found
No related merge requests found
...@@ -30,13 +30,26 @@ ...@@ -30,13 +30,26 @@
#include "cpptoolsplugin.h" #include "cpptoolsplugin.h"
#include "cpptoolsreuse.h" #include "cpptoolsreuse.h"
#include <coreplugin/testdatadir.h> #include <utils/fileutils.h>
#include <QDir> #include <QDir>
#include <QtTest> #include <QtTest>
static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
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/");
}
namespace CppTools { namespace CppTools {
namespace Internal { namespace Internal {
...@@ -46,11 +59,13 @@ void CppToolsPlugin::test_headersource() ...@@ -46,11 +59,13 @@ void CppToolsPlugin::test_headersource()
QFETCH(QString, headerFileName); QFETCH(QString, headerFileName);
bool wasHeader; bool wasHeader;
Core::Tests::TestDataDir dataDir(_(SRCDIR "/../../../tests/cppheadersource/") const QString baseDir = baseTestDir();
+ _(QTest::currentDataTag())); QDir path = QDir(baseDir + _(QTest::currentDataTag()));
const QString sourcePath = dataDir.file(sourceFileName); const QString sourcePath = path.absoluteFilePath(sourceFileName);
const QString headerPath = dataDir.file(headerFileName); const QString headerPath = path.absoluteFilePath(headerFileName);
createTempFile(sourcePath);
createTempFile(headerPath);
clearHeaderSourceCache(); clearHeaderSourceCache();
QCOMPARE(correspondingHeaderOrSource(sourcePath, &wasHeader), headerPath); QCOMPARE(correspondingHeaderOrSource(sourcePath, &wasHeader), headerPath);
...@@ -68,5 +83,15 @@ void CppToolsPlugin::test_headersource_data() ...@@ -68,5 +83,15 @@ void CppToolsPlugin::test_headersource_data()
QTest::newRow("includesub") << _("foo.cpp") << _("include/foo.h"); QTest::newRow("includesub") << _("foo.cpp") << _("include/foo.h");
} }
void CppToolsPlugin::initTestCase()
{
QDir(baseTestDir()).mkpath(_("."));
}
void CppToolsPlugin::cleanupTestCase()
{
Utils::FileUtils::removeRecursively(Utils::FileName::fromString(baseTestDir()));
}
} // namespace Internal } // namespace Internal
} // namespace CppTools } // namespace CppTools
...@@ -77,6 +77,10 @@ public slots: ...@@ -77,6 +77,10 @@ public slots:
private slots: private slots:
#ifdef WITH_TESTS #ifdef WITH_TESTS
// Init/Cleanup methods implemented in cppheadersource_test.cpp
void initTestCase();
void cleanupTestCase();
void test_codegen_public_in_empty_class(); void test_codegen_public_in_empty_class();
void test_codegen_public_in_nonempty_class(); void test_codegen_public_in_nonempty_class();
void test_codegen_public_before_protected(); void test_codegen_public_before_protected();
......
// Comment
// Comment
// Comment
// Comment
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