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