...
 
Commits (1)
set(kdevtests_LIB_SRCS
autotestshell.cpp
kdevsignalspy.cpp
projectsgenerator.cpp
testcore.cpp
testproject.cpp
testfile.cpp
......@@ -32,6 +33,7 @@ PRIVATE
install(FILES
autotestshell.h
kdevsignalspy.h
projectsgenerator.h
modeltest.h
testcore.h
testproject.h
......
......@@ -28,6 +28,7 @@
#include <interfaces/iprojectcontroller.h>
#include <util/path.h>
#include <QString>
#include <QDir>
#include <QFile>
#include <QTextStream>
......@@ -61,16 +62,12 @@ void createFile( QFile& file )
}
}
namespace KDevelop {
IProject* ProjectsGenerator::GenerateSimpleProject()
{
// directory structure:
// ./simpleproject.kdev4
// ./src/main.cpp
// ./.kdev4/simpleproject.kdev4
const QString sp = QStringLiteral( "simpleproject" );
auto rootFolder = QDir::temp();
QDir(rootFolder.absolutePath() + "/" + sp).removeRecursively();
QDir(rootFolder.absolutePath() + QStringLiteral( "/" ) + sp).removeRecursively();
rootFolder.mkdir( sp );
rootFolder.cd( sp );
rootFolder.mkdir( QStringLiteral("src") );
......@@ -102,20 +99,14 @@ IProject* ProjectsGenerator::GenerateSimpleProject()
"[Project]\n" <<
"VersionControlSupport=\n";
}
return loadProject( QDir::tempPath() + "/simpleproject/simpleproject.kdev4", QStringLiteral("SimpleProject") );
return loadProject( QDir::tempPath() + QStringLiteral( "/simpleproject/simpleproject.kdev4" ), QStringLiteral("SimpleProject") );
}
IProject* ProjectsGenerator::GenerateMultiPathProject()
{
// directory structure:
// ./multipathproject.kdev4
// ./src/main.cpp
// ./anotherFolder/tst.h
// ./.kdev4/multipathproject.kdev4
const QString mp = QStringLiteral( "multipathproject" );
auto rootFolder = QDir::temp();
QDir(rootFolder.absolutePath() + "/" + mp).removeRecursively();
QDir(rootFolder.absolutePath() + QStringLiteral( "/" ) + mp).removeRecursively();
rootFolder.mkdir( mp );
rootFolder.cd( mp );
rootFolder.mkdir( QStringLiteral("src") );
......@@ -161,7 +152,7 @@ IProject* ProjectsGenerator::GenerateMultiPathProject()
"[Project]\n" <<
"VersionControlSupport=\n";
}
return loadProject( QDir::tempPath() + "/multipathproject/multipathproject.kdev4", QStringLiteral("MultiPathProject") );
return loadProject( QDir::tempPath() + QStringLiteral( "/multipathproject/multipathproject.kdev4" ), QStringLiteral("MultiPathProject") );
}
IProject* ProjectsGenerator::GenerateSimpleProjectWithOutOfProjectFiles()
......@@ -175,20 +166,16 @@ IProject* ProjectsGenerator::GenerateSimpleProjectWithOutOfProjectFiles()
QFile file(rootFolder.filePath(includePaths));
createFile(file);
QTextStream stream( &file );
stream << "." + QDir::separator() + "include1.h" << endl << rootFolder.canonicalPath() + QDir::separator() + "include2.h";
stream << QStringLiteral(".") + QDir::separator() + QStringLiteral("include1.h") << endl << rootFolder.canonicalPath() + QDir::separator() + QStringLiteral("include2.h");
return project;
}
IProject* ProjectsGenerator::GenerateEmptyProject()
{
// directory structure:
// ./emptyproject.kdev4
// ./.kdev4/emptyproject.kdev4
const QString ep = QStringLiteral("emptyproject");
auto rootFolder = QDir::temp();
QDir(rootFolder.absolutePath() + "/" + ep).removeRecursively();
QDir(rootFolder.absolutePath() + QStringLiteral("/") + ep).removeRecursively();
rootFolder.mkdir(ep);
rootFolder.cd(ep);
rootFolder.mkdir(QStringLiteral(".kdev4"));
......@@ -206,5 +193,6 @@ IProject* ProjectsGenerator::GenerateEmptyProject()
QTextStream stream(&file);
stream << "[Project]\n" << "VersionControlSupport=\n";
}
return loadProject(QDir::tempPath() + "/emptyproject/emptyproject.kdev4", QStringLiteral("EmptyProject"));
return loadProject(QDir::tempPath() + QStringLiteral( "/emptyproject/emptyproject.kdev4" ), QStringLiteral("EmptyProject"));
}
} // KDevelop
......@@ -22,22 +22,60 @@
#ifndef PROJECTSGENERATOR_H
#define PROJECTSGENERATOR_H
#include "testsexport.h"
namespace KDevelop
{
class IProject;
}
/// Simple class for generating projects at runtime for testing purposes.
class ProjectsGenerator
class KDEVPLATFORMTESTS_EXPORT ProjectsGenerator
{
public:
static KDevelop::IProject* GenerateSimpleProject();
/**
* Generates a pointer to a project with the following directory structure:
* ./simpleproject.kdev4
* ./src/main.cpp
* ./.kdev4/simpleproject.kdev4
*
* Files are located in the OS temporary folder, subfolder 'simpleproject'
*/
KDevelop::IProject* GenerateSimpleProject();
static KDevelop::IProject* GenerateSimpleProjectWithOutOfProjectFiles();
/**
* This actually does create the same directory structure as genereate simple project.
* However, the .kdev_include_paths file is also included in this project, so the structure
* becomes:
* ./simpleproject.kdev4
* ./.kdev_include_paths
* ./src/main.cpp
* ./.kdev4/simpleproject.kdev4
*
* Files are located in the OS temporary folder, subfolder 'simpleproject'
*/
KDevelop::IProject* GenerateSimpleProjectWithOutOfProjectFiles();
static KDevelop::IProject* GenerateMultiPathProject();
/**
* Generates a pointer to a project with the following directory structure:
* ./multipathproject.kdev4
* ./src/main.cpp
* ./anotherFolder/tst.h
* ./.kdev4/multipathproject.kdev4
*
* Files are located in the OS temporary folder, subfolder 'multipathproject'
*/
KDevelop::IProject* GenerateMultiPathProject();
static KDevelop::IProject* GenerateEmptyProject();
/**
* Generates a pointer to a project with the following directory structure:
* ./emptyproject.kdev4
* ./.kdev4/emptyproject.kdev4
*
* Files are located in the OS temporary folder, subfolder 'emptyproject'
*/
KDevelop::IProject* GenerateEmptyProject();
};
}
#endif // PROJECTSGENERATOR_H
......@@ -8,7 +8,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(test_compilerprovider_SRCS
test_compilerprovider.cpp
../../tests/projectsgenerator.cpp
)
ecm_add_test(${test_compilerprovider_SRCS}
......
......@@ -29,6 +29,7 @@
#include <tests/autotestshell.h>
#include <tests/testcore.h>
#include <tests/projectsgenerator.h>
#include <interfaces/iproject.h>
#include <interfaces/iprojectcontroller.h>
......@@ -40,7 +41,6 @@
#include "../compilerprovider.h"
#include "../settingsmanager.h"
#include "../tests/projectsgenerator.h"
using namespace KDevelop;
......@@ -204,7 +204,7 @@ void TestCompilerProvider::testStorageNewSystem()
void TestCompilerProvider::testCompilerIncludesAndDefinesForProject()
{
auto project = ProjectsGenerator::GenerateMultiPathProject();
auto project = m_projectGenerator->GenerateMultiPathProject();
Q_ASSERT(project);
auto settings = SettingsManager::globalInstance();
......
......@@ -26,6 +26,11 @@
#include <QObject>
namespace KDevelop
{
class ProjectsGenerator;
}
class TestCompilerProvider : public QObject
{
Q_OBJECT
......@@ -37,6 +42,8 @@ private Q_SLOTS:
void testStorageBackwardsCompatible();
void testCompilerIncludesAndDefinesForProject();
void testStorageNewSystem();
private:
KDevelop::ProjectsGenerator* m_projectGenerator = nullptr;
};
#endif
......@@ -8,7 +8,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
set(test_definesandincludes_SRCS
test_definesandincludes.cpp
projectsgenerator.cpp)
)
ecm_add_test(${test_definesandincludes_SRCS}
TEST_NAME test_definesandincludes
......
......@@ -18,7 +18,6 @@
************************************************************************/
#include "test_definesandincludes.h"
#include "projectsgenerator.h"
#include <QTest>
......@@ -28,12 +27,16 @@
#include <tests/autotestshell.h>
#include <tests/testcore.h>
#include <tests/testhelpers.h>
#include <tests/projectsgenerator.h>
#include "idefinesandincludesmanager.h"
using namespace KDevelop;
static IProject* s_currentProject = nullptr;
void TestDefinesAndIncludes::init()
{
m_projectGenerator = new ProjectsGenerator;
}
void TestDefinesAndIncludes::cleanupTestCase()
{
......@@ -48,18 +51,19 @@ void TestDefinesAndIncludes::initTestCase()
void TestDefinesAndIncludes::cleanup()
{
ICore::self()->projectController()->closeProject( s_currentProject );
ICore::self()->projectController()->closeProject( m_currentProject );
delete m_projectGenerator;
}
void TestDefinesAndIncludes::loadSimpleProject()
{
s_currentProject = ProjectsGenerator::GenerateSimpleProject();
QVERIFY( s_currentProject );
m_currentProject = m_projectGenerator->GenerateSimpleProject();
QVERIFY( m_currentProject );
auto manager = IDefinesAndIncludesManager::manager();
QVERIFY( manager );
const auto actualIncludes = manager->includes( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined );
const auto actualDefines = manager->defines( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined );
const auto actualIncludes = manager->includes( m_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined );
const auto actualDefines = manager->defines( m_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined );
qDebug() << actualDefines << actualIncludes;
......@@ -70,13 +74,13 @@ void TestDefinesAndIncludes::loadSimpleProject()
defines.insert( QStringLiteral("VARIABLE"), QStringLiteral("VALUE") );
QCOMPARE( actualDefines, defines );
QVERIFY(!manager->parserArguments(s_currentProject->path().path() + "/src/main.cpp").isEmpty());
QVERIFY(!manager->parserArguments(m_currentProject->path().path() + "/src/main.cpp").isEmpty());
}
void TestDefinesAndIncludes::loadMultiPathProject()
{
s_currentProject = ProjectsGenerator::GenerateMultiPathProject();
QVERIFY( s_currentProject );
m_currentProject = m_projectGenerator->GenerateMultiPathProject();
QVERIFY( m_currentProject );
auto manager = IDefinesAndIncludesManager::manager();
QVERIFY( manager );
......@@ -86,13 +90,13 @@ void TestDefinesAndIncludes::loadMultiPathProject()
defines.insert(QStringLiteral("SOURCE"), QStringLiteral("CONTENT"));
defines.insert(QStringLiteral("_COPY"), QString());
QCOMPARE( manager->includes( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), includes );
QCOMPARE( manager->defines( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), defines );
QCOMPARE( manager->includes( m_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), includes );
QCOMPARE( manager->defines( m_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), defines );
ProjectBaseItem* mainfile = nullptr;
const auto& fileSet = s_currentProject->fileSet();
const auto& fileSet = m_currentProject->fileSet();
for (const auto& file : fileSet) {
const auto& files = s_currentProject->filesForPath(file);
const auto& files = m_currentProject->filesForPath(file);
for (auto i: files) {
if( i->text() == QLatin1String("main.cpp") ) {
mainfile = i;
......@@ -113,36 +117,36 @@ void TestDefinesAndIncludes::loadMultiPathProject()
void TestDefinesAndIncludes::testNoProjectIncludeDirectories()
{
s_currentProject = ProjectsGenerator::GenerateSimpleProjectWithOutOfProjectFiles();
QVERIFY(s_currentProject);
m_currentProject = m_projectGenerator->GenerateSimpleProjectWithOutOfProjectFiles();
QVERIFY(m_currentProject);
auto manager = KDevelop::IDefinesAndIncludesManager::manager();
QVERIFY(manager);
auto projectIncludes = manager->includes(s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined);
auto projectIncludes = manager->includes(m_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined);
Path includePath1(s_currentProject->path().path() + QDir::separator() + "include1.h");
Path includePath2(s_currentProject->path().path() + QDir::separator() + "include2.h");
Path includePath1(m_currentProject->path().path() + QDir::separator() + "include1.h");
Path includePath2(m_currentProject->path().path() + QDir::separator() + "include2.h");
QVERIFY(!projectIncludes.contains(includePath1));
QVERIFY(!projectIncludes.contains(includePath2));
auto noProjectIncludes = manager->includes(s_currentProject->path().path() + "/src/main.cpp");
auto noProjectIncludes = manager->includes(m_currentProject->path().path() + "/src/main.cpp");
QVERIFY(noProjectIncludes.contains(includePath1));
QVERIFY(noProjectIncludes.contains(includePath2));
}
void TestDefinesAndIncludes::testEmptyProject()
{
s_currentProject = ProjectsGenerator::GenerateEmptyProject();
QVERIFY(s_currentProject);
m_currentProject = m_projectGenerator->GenerateEmptyProject();
QVERIFY(m_currentProject);
auto manager = KDevelop::IDefinesAndIncludesManager::manager();
QVERIFY(manager);
auto projectIncludes = manager->includes(s_currentProject->projectItem());
auto projectDefines = manager->defines(s_currentProject->projectItem());
auto parserArguments = manager->parserArguments(s_currentProject->projectItem());
auto projectIncludes = manager->includes(m_currentProject->projectItem());
auto projectDefines = manager->defines(m_currentProject->projectItem());
auto parserArguments = manager->parserArguments(m_currentProject->projectItem());
QVERIFY(projectIncludes.isEmpty());
QVERIFY(projectDefines.isEmpty());
......
......@@ -24,12 +24,15 @@
namespace KDevelop
{
class TestCore;
class IProject;
class ProjectsGenerator;
}
class TestDefinesAndIncludes : public QObject
{
Q_OBJECT
private Q_SLOTS:
void init();
void initTestCase();
void cleanupTestCase();
void cleanup();
......@@ -37,6 +40,9 @@ private Q_SLOTS:
void loadMultiPathProject();
void testNoProjectIncludeDirectories();
void testEmptyProject();
private:
KDevelop::IProject* m_currentProject = nullptr;
KDevelop::ProjectsGenerator* m_projectGenerator = nullptr;
};
#endif