Changeset View
Changeset View
Standalone View
Standalone View
plugins/custom-definesandincludes/tests/test_definesandincludes.cpp
Show All 29 Lines | |||||
30 | #include <tests/testhelpers.h> | 30 | #include <tests/testhelpers.h> | ||
31 | 31 | | |||
32 | #include "idefinesandincludesmanager.h" | 32 | #include "idefinesandincludesmanager.h" | ||
33 | 33 | | |||
34 | using namespace KDevelop; | 34 | using namespace KDevelop; | ||
35 | 35 | | |||
36 | static IProject* s_currentProject = nullptr; | 36 | static IProject* s_currentProject = nullptr; | ||
37 | 37 | | |||
38 | | ||||
38 | void TestDefinesAndIncludes::cleanupTestCase() | 39 | void TestDefinesAndIncludes::cleanupTestCase() | ||
39 | { | 40 | { | ||
40 | TestCore::shutdown(); | 41 | TestCore::shutdown(); | ||
41 | } | 42 | } | ||
42 | 43 | | |||
43 | void TestDefinesAndIncludes::initTestCase() | 44 | void TestDefinesAndIncludes::initTestCase() | ||
44 | { | 45 | { | ||
45 | AutoTestShell::init({QStringLiteral("kdevdefinesandincludesmanager"), QStringLiteral("KDevCustomBuildSystem"), QStringLiteral("KDevStandardOutputView")}); | 46 | AutoTestShell::init({QStringLiteral("kdevdefinesandincludesmanager"), QStringLiteral("KDevCustomBuildSystem"), QStringLiteral("KDevStandardOutputView")}); | ||
Show All 12 Lines | 56 | { | |||
58 | 59 | | |||
59 | auto manager = IDefinesAndIncludesManager::manager(); | 60 | auto manager = IDefinesAndIncludesManager::manager(); | ||
60 | QVERIFY( manager ); | 61 | QVERIFY( manager ); | ||
61 | const auto actualIncludes = manager->includes( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ); | 62 | const auto actualIncludes = manager->includes( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ); | ||
62 | const auto actualDefines = manager->defines( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ); | 63 | const auto actualDefines = manager->defines( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ); | ||
63 | 64 | | |||
64 | qDebug() << actualDefines << actualIncludes; | 65 | qDebug() << actualDefines << actualIncludes; | ||
65 | 66 | | |||
66 | QCOMPARE( actualIncludes, Path::List() << Path( "/usr/include/mydir") ); | 67 | QCOMPARE( actualIncludes, Path::List() << Path( QDir::rootPath() + QStringLiteral("usr/include/mydir") ) ); | ||
67 | 68 | | |||
68 | Defines defines; | 69 | Defines defines; | ||
69 | defines.insert( QStringLiteral("_DEBUG"), QString() ); | 70 | defines.insert( QStringLiteral("_DEBUG"), QString() ); | ||
70 | defines.insert( QStringLiteral("VARIABLE"), QStringLiteral("VALUE") ); | 71 | defines.insert( QStringLiteral("VARIABLE"), QStringLiteral("VALUE") ); | ||
71 | QCOMPARE( actualDefines, defines ); | 72 | QCOMPARE( actualDefines, defines ); | ||
72 | 73 | | |||
73 | QVERIFY(!manager->parserArguments(s_currentProject->path().path() + "/src/main.cpp").isEmpty()); | 74 | QVERIFY(!manager->parserArguments(s_currentProject->path().path() + "/src/main.cpp").isEmpty()); | ||
74 | } | 75 | } | ||
75 | 76 | | |||
76 | void TestDefinesAndIncludes::loadMultiPathProject() | 77 | void TestDefinesAndIncludes::loadMultiPathProject() | ||
77 | { | 78 | { | ||
78 | s_currentProject = ProjectsGenerator::GenerateMultiPathProject(); | 79 | s_currentProject = ProjectsGenerator::GenerateMultiPathProject(); | ||
79 | QVERIFY( s_currentProject ); | 80 | QVERIFY( s_currentProject ); | ||
80 | 81 | | |||
81 | auto manager = IDefinesAndIncludesManager::manager(); | 82 | auto manager = IDefinesAndIncludesManager::manager(); | ||
82 | QVERIFY( manager ); | 83 | QVERIFY( manager ); | ||
83 | Path::List includes = Path::List() << Path(QStringLiteral("/usr/include/otherdir")); | 84 | Path::List includes = Path::List() << Path( QDir::rootPath() + QStringLiteral("usr/include/otherdir") ); | ||
84 | 85 | | |||
85 | QHash<QString,QString> defines; | 86 | QHash<QString,QString> defines; | ||
86 | defines.insert(QStringLiteral("SOURCE"), QStringLiteral("CONTENT")); | 87 | defines.insert(QStringLiteral("SOURCE"), QStringLiteral("CONTENT")); | ||
87 | defines.insert(QStringLiteral("_COPY"), QString()); | 88 | defines.insert(QStringLiteral("_COPY"), QString()); | ||
88 | 89 | | |||
89 | QCOMPARE( manager->includes( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), includes ); | 90 | QCOMPARE( manager->includes( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), includes ); | ||
90 | QCOMPARE( manager->defines( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), defines ); | 91 | QCOMPARE( manager->defines( s_currentProject->projectItem(), IDefinesAndIncludesManager::UserDefined ), defines ); | ||
91 | 92 | | |||
92 | ProjectBaseItem* mainfile = nullptr; | 93 | ProjectBaseItem* mainfile = nullptr; | ||
93 | const auto& fileSet = s_currentProject->fileSet(); | 94 | const auto& fileSet = s_currentProject->fileSet(); | ||
94 | for (const auto& file : fileSet) { | 95 | for (const auto& file : fileSet) { | ||
95 | const auto& files = s_currentProject->filesForPath(file); | 96 | const auto& files = s_currentProject->filesForPath(file); | ||
96 | for (auto i: files) { | 97 | for (auto i: files) { | ||
97 | if( i->text() == QLatin1String("main.cpp") ) { | 98 | if( i->text() == QLatin1String("main.cpp") ) { | ||
98 | mainfile = i; | 99 | mainfile = i; | ||
99 | break; | 100 | break; | ||
100 | } | 101 | } | ||
101 | } | 102 | } | ||
102 | } | 103 | } | ||
103 | QVERIFY(mainfile); | 104 | QVERIFY(mainfile); | ||
104 | 105 | | |||
105 | includes.prepend(Path(QStringLiteral("/usr/local/include/mydir"))); | 106 | includes.prepend(Path(QDir::rootPath() + QStringLiteral("usr/local/include/mydir"))); | ||
106 | defines.insert(QStringLiteral("BUILD"), QStringLiteral("debug")); | 107 | defines.insert(QStringLiteral("BUILD"), QStringLiteral("debug")); | ||
107 | qDebug() << includes << "VS" << manager->includes( mainfile, IDefinesAndIncludesManager::UserDefined ); | 108 | qDebug() << includes << "VS" << manager->includes( mainfile, IDefinesAndIncludesManager::UserDefined ); | ||
108 | qDebug() << mainfile << mainfile->path(); | 109 | qDebug() << mainfile << mainfile->path(); | ||
109 | QCOMPARE(manager->includes( mainfile, IDefinesAndIncludesManager::UserDefined ), includes); | 110 | QCOMPARE(manager->includes( mainfile, IDefinesAndIncludesManager::UserDefined ), includes); | ||
110 | QCOMPARE(defines, manager->defines( mainfile, IDefinesAndIncludesManager::UserDefined )); | 111 | QCOMPARE(defines, manager->defines( mainfile, IDefinesAndIncludesManager::UserDefined )); | ||
111 | QVERIFY(!manager->parserArguments(mainfile).isEmpty()); | 112 | QVERIFY(!manager->parserArguments(mainfile).isEmpty()); | ||
112 | } | 113 | } | ||
113 | 114 | | |||
Show All 39 Lines |