...
 
Commits (2)
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") );
......@@ -91,7 +88,13 @@ IProject* ProjectsGenerator::GenerateSimpleProject()
createFile( file );
QTextStream stream( &file );
stream << "[Buildset]\n" <<
"BuildItems=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x1a\\x00S\\x00i\\x00m\\x00p\\x00l\\x00e\\x00P\\x00r\\x00o\\x00j\\x00e\\x00c\\x00t)\n" <<
"BuildItems=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x1a\\x00S\\x00i\\x00m\\x00p\\x00l\\x00e\\x00P\\x00r\\x00o\\x00j\\x00e\\x00c\\x00t)\n\n" <<
"[CustomBuildSystem]\n" <<
"CurrentConfiguration=BuildConfig0\n\n" <<
"[CustomBuildSystem][BuildConfig0]\n" <<
"BuildDir=file:///" << rootFolder.absolutePath() << "/build\n" <<
"Title=mainbuild\n\n" <<
"[CustomDefinesAndIncludes][ProjectPath0]\n" <<
"Path=/\n" <<
"[CustomDefinesAndIncludes][ProjectPath0][Defines]\n" <<
......@@ -102,20 +105,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") );
......@@ -140,7 +137,11 @@ IProject* ProjectsGenerator::GenerateMultiPathProject()
createFile( file );
QTextStream stream( &file );
stream << "[Buildset]\n" <<
"BuildItems=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00 \\x00M\\x00u\\x00l\\x00t\\x00i\\x00P\\x00a\\x00t\\x00h\\x00P\\x00r\\x00o\\x00j\\x00e\\x00c\\x00t)\n" <<
"BuildItems=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00 \\x00M\\x00u\\x00l\\x00t\\x00i\\x00P\\x00a\\x00t\\x00h\\x00P\\x00r\\x00o\\x00j\\x00e\\x00c\\x00t)\n\n" <<
"[CustomBuildSystem]\n" <<
"CurrentConfiguration=BuildConfig0\n\n" <<
"[CustomBuildSystem][BuildConfig0]\n" <<
"BuildDir=file:///" << rootFolder.absolutePath() << "/build\n" <<
"[CustomDefinesAndIncludes][ProjectPath0]\n" <<
"Path=.\n" <<
"[CustomDefinesAndIncludes][ProjectPath0][Defines]\n" <<
......@@ -161,7 +162,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 +176,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 +203,53 @@ 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"));
}
IProject* ProjectsGenerator::GenerateEmptyBuildDirProject()
{
const QString ebp = QStringLiteral( "emptybuilddirproject" );
auto rootFolder = QDir::temp();
QDir(rootFolder.absolutePath() + QStringLiteral( "/" ) + ebp).removeRecursively();
rootFolder.mkdir( ebp );
rootFolder.cd( ebp );
rootFolder.mkdir( QStringLiteral("src") );
rootFolder.mkdir( QStringLiteral(".kdev4") );
{
QFile file( rootFolder.filePath( QStringLiteral("emptybuilddirproject.kdev4") ) );
createFile( file );
QTextStream stream1( &file );
stream1 << "[Project]\nName=EmptyBuildDirProject\nManager=KDevCustomBuildSystem";
}
{
QFile file( rootFolder.filePath( QStringLiteral("src/main.cpp") ) );
createFile( file );
}
{
QFile file( rootFolder.filePath( QStringLiteral(".kdev4/emptybuilddirproject.kdev4") ) );
createFile( file );
QTextStream stream( &file );
stream << "[Buildset]\n" <<
"BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00(\x00E\x00m\x00p\x00t\x00y\x00B\x00u\x00i\x00l\x00d\x00d\x00i\x00r\x00P\x00r\x00o\x00j\x00e\x00c\x00t)\n\n" <<
"[CustomBuildSystem]\n" <<
"CurrentConfiguration=BuildConfig0\n\n" <<
"[CustomBuildSystem][BuildConfig0]\n" <<
"BuildDir=" <<
"Title=mainbuild\n\n" <<
"[CustomDefinesAndIncludes][ProjectPath0]\n" <<
"Path=/\n" <<
"[CustomDefinesAndIncludes][ProjectPath0][Defines]\n" <<
"_DEBUG=\n" <<
"VARIABLE=VALUE\n" <<
"[CustomDefinesAndIncludes][ProjectPath0][Includes]\n" <<
"1=" << QDir::rootPath() << "usr/include/mydir\n" <<
"[Project]\n" <<
"VersionControlSupport=\n";
}
return loadProject( QDir::tempPath() + QStringLiteral( "/simpleproject/simpleproject.kdev4" ), QStringLiteral("SimpleProject") );
}
} // KDevelop
......@@ -22,22 +22,70 @@
#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();
/**
* Generates a pointer to a project with the following directory structure:
* ./emptybuilddirproject.kdev4
* ./src/main.cpp
* ./.kdev4/emptybuilddirproject.kdev4
*
* Files are located in the OS temporary folder, subfolder 'emptybuilddirproject'
*/
IProject* GenerateEmptyBuildDirProject();
};
}
#endif // PROJECTSGENERATOR_H
add_definitions(-DTRANSLATION_DOMAIN=\"kdevcustombuildsystem\")
declare_qt_logging_category(custom_LOG_SRCS
TYPE PLUGIN
IDENTIFIER CUSTOMBUILDSYSTEM
......@@ -25,6 +24,7 @@ target_link_libraries(kdevcustombuildsystem
KDev::Interfaces
KDev::Util
KDev::OutputView
KDev::Tests
)
## Unittests
......
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
[CustomBuildSystem]
CurrentConfiguration=BuildConfig0
[CustomBuildSystem][BuildConfig0]
BuildDir=
Title=mainbuild
[CustomBuildSystem][BuildConfig0][ToolBuild]
Arguments=
Enabled=false
Environment=
Executable=
Type=0
[CustomBuildSystem][BuildConfig0][ToolClean]
Arguments=
Enabled=false
Environment=
Executable=
Type=3
[CustomBuildSystem][BuildConfig0][ToolConfigure]
Arguments=
Enabled=false
Environment=
Executable=
Type=1
[CustomBuildSystem][BuildConfig0][ToolInstall]
Arguments=
Enabled=false
Environment=
Executable=
Type=2
[CustomBuildSystem][BuildConfig0][ToolPrune]
Arguments=
Enabled=false
Environment=
Executable=
Type=4
[Defines And Includes][Compiler]
Name=GCC
Path=gcc
Type=GCC
[MakeBuilder]
Number Of Jobs=1
[Project]
VersionControlSupport=kdevgit
[Project]
Name=BuilddirProject
Manager=KDevCustomBuildSystem
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00 \x00M\x00u\x00l\x00t\x00i\x00P\x00a\x00t\x00h\x00P\x00r\x00o\x00j\x00e\x00c\x00t)
[CustomBuildSystem]
CurrentConfiguration=BuildConfig0
[CustomBuildSystem][BuildConfig0]
BuildDir=file:///home/andreas/projects/testcustom/build2
Title=main
[CustomBuildSystem][BuildConfig0][ToolBuild]
Arguments=
Enabled=false
Environment=
Executable=
Type=0
[CustomBuildSystem][BuildConfig0][ToolClean]
Arguments=
Enabled=false
Environment=
Executable=
Type=3
[CustomBuildSystem][BuildConfig0][ToolConfigure]
Arguments=
Enabled=false
Environment=
Executable=
Type=1
[CustomBuildSystem][BuildConfig0][ToolInstall]
Arguments=
Enabled=false
Environment=
Executable=
Type=2
[Defines And Includes][Compiler]
Name=GCC
Path=gcc
Type=GCC
[Project]
VersionControlSupport=
[Project]
Name=MultiPathProject
Manager=KDevCustomBuildSystem
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00S\x00i\x00m\x00p\x00l\x00e\x00P\x00r\x00o\x00j\x00e\x00c\x00t)
[CustomBuildSystem]
CurrentConfiguration=BuildConfig0
[CustomBuildSystem][BuildConfig0]
BuildDir=file:///home/andreas/projects/testcustom/build
Title=mainbuild
[CustomBuildSystem][BuildConfig0][ToolBuild]
Arguments=
Enabled=false
Environment=
Executable=
Type=0
[CustomBuildSystem][BuildConfig0][ToolClean]
Arguments=
Enabled=false
Environment=
Executable=
Type=3
[CustomBuildSystem][BuildConfig0][ToolConfigure]
Arguments=
Enabled=false
Environment=
Executable=
Type=1
[CustomBuildSystem][BuildConfig0][ToolInstall]
Arguments=
Enabled=false
Environment=
Executable=
Type=2
[Defines And Includes][Compiler]
Name=GCC
Path=gcc
Type=GCC
[Project]
VersionControlSupport=
#ifndef CONFIG_H
#define CONFIG_H
#define myvar
#endif
[Project]
Name=SimpleProject
Manager=KDevCustomBuildSystem
......@@ -25,6 +25,7 @@
#include <tests/autotestshell.h>
#include <tests/testcore.h>
#include <tests/kdevsignalspy.h>
#include <tests/projectsgenerator.h>
#include <shell/sessioncontroller.h>
#include <interfaces/iprojectcontroller.h>
#include <interfaces/isession.h>
......@@ -42,10 +43,16 @@ using KDevelop::IProject;
using KDevelop::TestCore;
using KDevelop::AutoTestShell;
using KDevelop::KDevSignalSpy;
using KDevelop::ProjectsGenerator;
using KDevelop::Path;
QTEST_MAIN(TestCustomBuildSystemPlugin)
void TestCustomBuildSystemPlugin::init()
{
m_projectGenerator = new ProjectsGenerator;
}
void TestCustomBuildSystemPlugin::cleanupTestCase()
{
TestCore::shutdown();
......@@ -56,49 +63,37 @@ void TestCustomBuildSystemPlugin::initTestCase()
TestCore::initialize();
}
void TestCustomBuildSystemPlugin::cleanup()
{
ICore::self()->projectController()->closeAllProjects( );
delete m_projectGenerator;
}
void TestCustomBuildSystemPlugin::loadSimpleProject()
{
QUrl projecturl = QUrl::fromLocalFile( PROJECTS_SOURCE_DIR"/simpleproject/simpleproject.kdev4" );
auto* projectSpy = new KDevSignalSpy( ICore::self()->projectController(), SIGNAL(projectOpened(KDevelop::IProject*)) );
ICore::self()->projectController()->openProject( projecturl );
// Wait for the project to be opened
QVERIFY(projectSpy->wait(10000));
IProject* project = ICore::self()->projectController()->findProjectByName( QStringLiteral("SimpleProject") );
QVERIFY( project );
QCOMPARE( project->buildSystemManager()->buildDirectory( project->projectItem() ),
Path( "file:///home/andreas/projects/testcustom/build/" ) );
m_currentProject = m_projectGenerator->GenerateSimpleProject();
QVERIFY( m_currentProject );
QCOMPARE( m_currentProject->buildSystemManager()->buildDirectory( m_currentProject->projectItem() ),
Path( QStringLiteral("file:///") + QDir::temp().absolutePath() + QStringLiteral("/simpleproject/build/") ) );
}
void TestCustomBuildSystemPlugin::buildDirProject()
{
QUrl projecturl = QUrl::fromLocalFile( PROJECTS_SOURCE_DIR"/builddirproject/builddirproject.kdev4" );
auto* projectSpy = new KDevSignalSpy( ICore::self()->projectController(), SIGNAL(projectOpened(KDevelop::IProject*)) );
ICore::self()->projectController()->openProject( projecturl );
// Wait for the project to be opened
QVERIFY(projectSpy->wait(10000));
IProject* project = ICore::self()->projectController()->findProjectByName( QStringLiteral("BuilddirProject") );
QVERIFY( project );
Path currentBuilddir = project->buildSystemManager()->buildDirectory( project->projectItem() );
QCOMPARE( currentBuilddir, Path( projecturl ).parent() );
m_currentProject = m_projectGenerator->GenerateEmptyBuildDirProject();
QVERIFY( m_currentProject );
QCOMPARE( m_currentProject->buildSystemManager()->buildDirectory( m_currentProject->projectItem() ),
Path( QStringLiteral("file:///") + QDir::temp().absolutePath() + QStringLiteral("/simpleproject/build/") ) );
}
void TestCustomBuildSystemPlugin::loadMultiPathProject()
{
QUrl projecturl = QUrl::fromLocalFile( PROJECTS_SOURCE_DIR"/multipathproject/multipathproject.kdev4" );
auto* projectSpy = new KDevSignalSpy( ICore::self()->projectController(), SIGNAL(projectOpened(KDevelop::IProject*)) );
ICore::self()->projectController()->openProject( projecturl );
// Wait for the project to be opened
QVERIFY(projectSpy->wait(10000));
IProject* project = ICore::self()->projectController()->findProjectByName( QStringLiteral("MultiPathProject") );
QVERIFY( project );
m_currentProject = m_projectGenerator->GenerateMultiPathProject();
QVERIFY( m_currentProject );
KDevelop::ProjectBaseItem* mainfile = nullptr;
const auto& files = project->fileSet();
const auto& files = m_currentProject->fileSet();
for (const auto& file : files) {
const auto& filesForPath = project->filesForPath(file);
const auto& filesForPath = m_currentProject->filesForPath(file);
for (auto i: filesForPath) {
if( i->text() == QLatin1String("main.cpp") ) {
mainfile = i;
......@@ -108,7 +103,7 @@ void TestCustomBuildSystemPlugin::loadMultiPathProject()
}
QVERIFY(mainfile);
QCOMPARE( project->buildSystemManager()->buildDirectory( mainfile ),
Path( "file:///home/andreas/projects/testcustom/build2/src" ) );
QCOMPARE( m_currentProject->buildSystemManager()->buildDirectory( mainfile ),
Path( QStringLiteral("file:///") + QDir::temp().absolutePath() + QStringLiteral("/multipathproject/build/src") ) );
}
......@@ -25,17 +25,24 @@
namespace KDevelop
{
class TestCore;
class IProject;
class ProjectsGenerator;
}
class TestCustomBuildSystemPlugin : public QObject
{
Q_OBJECT
private Q_SLOTS:
void init();
void initTestCase();
void cleanupTestCase();
void cleanup();
void loadSimpleProject();
void buildDirProject();
void loadMultiPathProject();
private:
KDevelop::IProject* m_currentProject = nullptr;
KDevelop::ProjectsGenerator* m_projectGenerator = nullptr;
};
#endif
......@@ -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