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
|
/* KDevelop CMake Support
*
* Copyright 2006 Matt Rogers <mattr@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "cmakeloadprojecttest.h"
#include "cmake-test-paths.h"
#include <language/duchain/duchainlock.h>
#include <language/duchain/duchain.h>
#include <language/duchain/topducontext.h>
#include "cmListFileLexer.h"
#include "cmakelistsparser.h"
#include "cmakeprojectvisitor.h"
#include "cmakeast.h"
#include <cmakeparserutils.h>
#include <tests/autotestshell.h>
#include <cmakeprojectdata.h>
QTEST_MAIN( CMakeLoadProjectTest )
using namespace KDevelop;
CMakeLoadProjectTest::CMakeLoadProjectTest()
{
AutoTestShell::init();
KDevelop::Core::initialize(0, KDevelop::Core::NoUi);
}
CMakeLoadProjectTest::~CMakeLoadProjectTest()
{
}
void CMakeLoadProjectTest::testTinyCMakeProject()
{
CMakeProjectVisitor v = parseProject( QString(CMAKE_TESTS_PROJECTS_DIR)+"/tiny_project" );
QCOMPARE(v.targets().count(), 1);
QCOMPARE(v.targets().at( 0 ).name, QString("foo") );
QCOMPARE(v.targets().at( 0 ).files, QStringList() << "foo.cpp" );
}
void CMakeLoadProjectTest::testSmallQt4Project()
{
CMakeProjectVisitor v = parseProject(CMAKE_TESTS_PROJECTS_DIR "/qt4app");
QCOMPARE(v.targets().count(), 1);
QCOMPARE(v.projectName(), QString("qt4app"));
QCOMPARE(v.targets().at( 0 ).name, QString("qt4app") );
QCOMPARE(v.targets().at( 0 ).files, QStringList() << "qt4app.cpp" << "main.cpp" );
}
void CMakeLoadProjectTest::testSmallKDE4Project()
{
CMakeProjectVisitor v = parseProject(CMAKE_TESTS_PROJECTS_DIR "/kde4app");
QCOMPARE(v.targets().count(), 2);
QCOMPARE(v.projectName(), QString("kde4app"));
QCOMPARE(v.targets().at( 0 ).name, QString("kde4app") );
QCOMPARE(v.targets().at( 0 ).files, QStringList() << "kde4app.cpp" << "main.cpp" << "kde4appview.cpp"
<< CMAKE_TESTS_PROJECTS_DIR "/kde4app/ui_kde4appview_base.h"
<< CMAKE_TESTS_PROJECTS_DIR "/kde4app/ui_prefs_base.h"
<< CMAKE_TESTS_PROJECTS_DIR "/kde4app/settings.cpp"
<< CMAKE_TESTS_PROJECTS_DIR "/kde4app/settings.h" );
// QCOMPARE(v.targets().at( 1 ).name, QString("kde4app_automoc") );
QCOMPARE(v.targets().at( 1 ).name, QString("uninstall") );
}
CMakeProjectVisitor CMakeLoadProjectTest::parseProject( const QString& sourcedir )
{
QString projectfile = sourcedir+"/CMakeLists.txt";
CMakeFileContent code=CMakeListsParser::readCMakeFile(projectfile);
QPair<VariableMap,QStringList> initials = CMakeParserUtils::initialVariables();
CMakeProjectData data;
data.vm = initials.first;
data.vm.insert("CMAKE_SOURCE_DIR", QStringList(sourcedir));
KDevelop::ReferencedTopDUContext buildstrapContext=new TopDUContext(IndexedString("buildstrap"), RangeInRevision(0,0, 0,0));
DUChain::self()->addDocumentChain(buildstrapContext);
ReferencedTopDUContext ref=buildstrapContext;
QStringList modulesPath = data.vm["CMAKE_MODULE_PATH"];
foreach(const QString& script, initials.second)
{
ref = CMakeParserUtils::includeScript(CMakeProjectVisitor::findFile(script, modulesPath, QStringList()), ref, &data, sourcedir, QMap<QString,QString>());
}
data.vm.insert("CMAKE_CURRENT_BINARY_DIR", QStringList(sourcedir));
data.vm.insert("CMAKE_CURRENT_LIST_FILE", QStringList(projectfile));
data.vm.insert("CMAKE_CURRENT_SOURCE_DIR", QStringList(sourcedir));
CMakeProjectVisitor v(projectfile, ref);
v.setVariableMap(&data.vm);
v.setMacroMap(&data.mm);
v.setCacheValues(&data.cache);
v.setModulePath(modulesPath);
v.walk(code, 0);
ReferencedTopDUContext ctx=v.context();
return v;
}
#include "cmakeloadprojecttest.moc"
|