1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
/* This file is part of KDevelop
Copyright 2010 Esben Mose Hansen<kde@mosehansen.dk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cmakemanagertest.h"
#include "cmake-test-paths.h"
#include <icmakemanager.h>
#include <cmakebuilddirchooser.h>
#include <qtest.h>
#include <qtest_kde.h>
#include <interfaces/iplugincontroller.h>
#include <interfaces/icore.h>
#include <project/interfaces/iprojectfilemanager.h>
#include <project/interfaces/ibuildsystemmanager.h>
#include <tests/autotestshell.h>
#include <tests/testproject.h>
#include <tests/testcore.h>
QTEST_KDEMAIN(CMakeManagerTest, GUI )
#define WAIT_FOR_OPEN_SIGNAL \
{\
bool gotSignal = QTest::kWaitForSignal(ICore::self()->projectController(), SIGNAL(projectOpened(KDevelop::IProject*)), 30000);\
QVERIFY2(gotSignal, "Timeout while waiting for opened signal");\
} void(0)
static QString currentBuildDirKey = "CurrentBuildDir";
static QString currentCMakeBinaryKey = "Current CMake Binary";
static QString currentBuildTypeKey = "CurrentBuildType";
static QString currentInstallDirKey = "CurrentInstallDir";
static QString currentExtraArgumentsKey = "Extra Arguments";
static QString projectRootRelativeKey = "ProjectRootRelative";
static QString projectBuildDirs = "BuildDirs";
struct TestProjectPaths {
// foo/
KUrl sourceDir;
// foo/foo.kdev4
KUrl projectFile;
// foo/.kdev4/foo.kdev4
KUrl configFile;
};
TestProjectPaths projectPaths(const QString& project, QString name = QString())
{
if (name.isEmpty()) {
name = project;
}
TestProjectPaths paths;
QFileInfo info(CMAKE_TESTS_PROJECTS_DIR "/" + project);
Q_ASSERT(info.exists());
paths.sourceDir = info.canonicalFilePath();
paths.sourceDir.adjustPath(KUrl::AddTrailingSlash);
paths.projectFile = paths.sourceDir;
paths.projectFile.addPath(name + ".kdev4");
Q_ASSERT(QFile::exists(paths.projectFile.toLocalFile()));
paths.configFile = paths.sourceDir;
paths.configFile.addPath(".kdev4/" + name + ".kdev4");
return paths;
}
/**
* apply default configuration to project in @p sourceDir called @p projectName
*
* this prevents the dialog to popup asking for user interaction
* which should never happen in an automated unit test
*/
void defaultConfigure(const TestProjectPaths& paths)
{
KConfig config(paths.configFile.toLocalFile());
// clear config
config.deleteGroup("CMake");
// apply default configuration
CMakeBuildDirChooser bd;
bd.setSourceFolder(paths.sourceDir);
// we don't want to execute, just pick the defaults from the dialog
KConfigGroup cmakeGrp = config.group("CMake");
{
QDir buildFolder( bd.buildFolder().toLocalFile() );
if ( !buildFolder.exists() ) {
if ( !buildFolder.mkpath( buildFolder.absolutePath() ) ) {
QFAIL("The build directory did not exist and could not be created.");
}
}
}
cmakeGrp.writeEntry( currentBuildDirKey, bd.buildFolder() );
cmakeGrp.writeEntry( currentCMakeBinaryKey, bd.cmakeBinary() );
cmakeGrp.writeEntry( currentInstallDirKey, bd.installPrefix() );
cmakeGrp.writeEntry( currentExtraArgumentsKey, bd.extraArguments() );
cmakeGrp.writeEntry( currentBuildTypeKey, bd.buildType() );
cmakeGrp.writeEntry( projectBuildDirs, QStringList() << bd.buildFolder().toLocalFile());
config.sync();
}
using namespace KDevelop;
void CMakeManagerTest::initTestCase()
{
AutoTestShell::init();
TestCore::initialize();
cleanup();
}
void CMakeManagerTest::cleanupTestCase()
{
TestCore::shutdown();
}
void CMakeManagerTest::cleanup()
{
foreach(IProject* p, ICore::self()->projectController()->projects()) {
ICore::self()->projectController()->closeProject(p);
}
QVERIFY(ICore::self()->projectController()->projects().isEmpty());
}
void CMakeManagerTest::testWithBuildDirProject()
{
const TestProjectPaths paths = projectPaths("with_build_dir");
defaultConfigure(paths);
// Import project
ICore::self()->projectController()->openProject(paths.projectFile);
WAIT_FOR_OPEN_SIGNAL;
IProject* project = ICore::self()->projectController()->findProjectByName("with_build_dir");
QCOMPARE(paths.projectFile, project->projectFileUrl());
QCOMPARE(paths.sourceDir, project->folder());
}
void CMakeManagerTest::testIncludePaths()
{
const TestProjectPaths paths = projectPaths("single_subdirectory");
defaultConfigure(paths);
ICore::self()->projectController()->openProject(paths.projectFile);
WAIT_FOR_OPEN_SIGNAL;
IProject* project = ICore::self()->projectController()->findProjectByName("single_subdirectory");
QVERIFY(project->buildSystemManager());
QCOMPARE(paths.projectFile, project->projectFileUrl());
QCOMPARE(paths.sourceDir, project->folder());
KUrl fooCpp(paths.sourceDir, "subdir/foo.cpp");
QVERIFY(QFile::exists(fooCpp.toLocalFile()));
QList< ProjectBaseItem* > items = project->itemsForUrl(fooCpp);
QCOMPARE(items.size(), 2); // once the target, once the plain file
ProjectBaseItem* fooCppItem = items.first();
KUrl::List _includeDirs = project->buildSystemManager()->includeDirectories(fooCppItem);
QSet<KUrl> includeDirs;
foreach(KUrl url, _includeDirs) {
url.cleanPath(KUrl::SimplifyDirSeparators);
url.adjustPath(KUrl::AddTrailingSlash);
includeDirs << url;
}
QCOMPARE(includeDirs.size(), _includeDirs.size());
KUrl buildDir(paths.sourceDir, "build/");
QVERIFY(includeDirs.contains(buildDir));
KUrl subBuildDir(paths.sourceDir, "build/subdir/");
QVERIFY(includeDirs.contains(subBuildDir));
KUrl subDir(paths.sourceDir, "subdir/");
QVERIFY(includeDirs.contains(subDir));
}
void CMakeManagerTest::testRelativePaths()
{
const TestProjectPaths paths = projectPaths("relative_paths/out", "relative_paths");
defaultConfigure(paths);
ICore::self()->projectController()->openProject(paths.projectFile);
WAIT_FOR_OPEN_SIGNAL;
IProject* project = ICore::self()->projectController()->findProjectByName("relative_paths");
QVERIFY(project);
QVERIFY(project->buildSystemManager());
QCOMPARE(paths.projectFile, project->projectFileUrl());
QCOMPARE(paths.sourceDir, project->folder());
KUrl codeCpp(paths.sourceDir, "../src/code.cpp");
codeCpp.cleanPath();
QVERIFY(QFile::exists( codeCpp.toLocalFile()));
QList< ProjectBaseItem* > items = project->itemsForUrl( codeCpp );
QCOMPARE(items.size(), 1); // once in the target
ProjectBaseItem* fooCppItem = items.first();
KUrl::List _includeDirs = project->buildSystemManager()->includeDirectories(fooCppItem);
QSet<KUrl> includeDirs;
foreach(KUrl url, _includeDirs) {
url.cleanPath(KUrl::SimplifyDirSeparators);
url.adjustPath(KUrl::AddTrailingSlash);
includeDirs << url;
}
QCOMPARE(includeDirs.size(), _includeDirs.size());
KUrl incDir(paths.sourceDir, "../inc/");
incDir.cleanPath();
QVERIFY(includeDirs.contains( incDir ));
}
|