custombuildsystemplugintest.cpp 6.43 KB
Newer Older
1 2 3 4 5 6 7
/************************************************************************
 * KDevelop4 Custom Buildsystem Support                                 *
 *                                                                      *
 * Copyright 2010 Andreas Pakulat <apaku@gmx.de>                        *
 *                                                                      *
 * 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 *
8
 * the Free Software Foundation; either version 2 or version 3 of the License, or    *
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 * (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, see <http://www.gnu.org/licenses/>. *
 ************************************************************************/

#include "custombuildsystemplugintest.h"

#include <QtTest/QtTest>

#include <qtest_kde.h>

#include <tests/autotestshell.h>
#include <tests/testcore.h>
#include <tests/kdevsignalspy.h>
29 30
#include <shell/sessioncontroller.h>
#include <kio/netaccess.h>
31
#include <interfaces/iprojectcontroller.h>
32
#include <interfaces/isession.h>
33 34 35 36
#include <KDebug>
#include <interfaces/iproject.h>
#include <project/interfaces/ibuildsystemmanager.h>
#include <project/projectmodel.h>
37
#include <kconfiggroup.h>
38 39 40 41 42 43 44 45

using KDevelop::Core;
using KDevelop::ICore;
using KDevelop::IProject;
using KDevelop::TestCore;
using KDevelop::AutoTestShell;
using KDevelop::KDevSignalSpy;

46 47 48 49 50 51 52 53 54 55 56 57
void deleteDir( QDir dir )
{
    foreach( const QString& f, dir.entryList( QDir::NoDotAndDotDot | QDir::AllEntries ) ) {
        if( QFileInfo( f ).isDir() ) {
            deleteDir( QDir( dir.absoluteFilePath( f ) ) );
            dir.rmdir( f );
        } else {
            dir.remove( f );
        }
    }
}

58 59
void CustomBuildSystemPluginTest::cleanupTestCase()
{
60 61
    QDir sessiondir( KDevelop::SessionController::sessionDirectory() );
    QString sessionid = m_core->activeSession()->id().toString();
62 63
    m_core->cleanup();
    delete m_core;
64 65 66 67 68 69

    // Delete the session dir and remove the default session entry from the config.
    deleteDir( sessiondir.absoluteFilePath( sessionid ) );
    sessiondir.rmdir( sessionid );
    KGlobal::config()->group( KDevelop::SessionController::cfgSessionGroup() ).deleteEntry( KDevelop::SessionController::cfgActiveSessionEntry() );
    KGlobal::config()->sync();
70 71
}
void CustomBuildSystemPluginTest::initTestCase()
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
{
    AutoTestShell::init();
    m_core = new KDevelop::TestCore();
    m_core->initialize( Core::Default );
}

void CustomBuildSystemPluginTest::loadSimpleProject()
{
    KUrl projecturl( PROJECTS_SOURCE_DIR"/simpleproject/simpleproject.kdev4" );
    KDevSignalSpy* projectSpy = new KDevSignalSpy( ICore::self()->projectController(), SIGNAL( projectOpened( KDevelop::IProject* ) ) );
    ICore::self()->projectController()->openProject( projecturl );
    // Wait for the project to be opened
    if( !projectSpy->wait( 20000 ) ) {
        kFatal() << "Expected project to be loaded within 20 seconds, but this didn't happen";
    }
87 88
    IProject* project = ICore::self()->projectController()->findProjectByName( "SimpleProject" );
    QVERIFY( project );
89
    KUrl::List includes = project->buildSystemManager()->includeDirectories( project->projectItem() );
90 91 92 93
    
    QHash<QString,QString> defines;
    defines.insert( "_DEBUG", "" );
    defines.insert( "VARIABLE", "VALUE" );
94
    QCOMPARE( includes, KUrl::List( QStringList() << "/usr/include/mydir" ) );
95
    QCOMPARE( project->buildSystemManager()->defines( project->projectItem() ), defines );
Andreas Pakulat's avatar
Andreas Pakulat committed
96
    QCOMPARE( project->buildSystemManager()->buildDirectory( project->projectItem() ), KUrl( "file:///home/andreas/projects/testcustom/build/" ) );
97 98
}

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
void CustomBuildSystemPluginTest::buildDirProject()
{
    KUrl projecturl( PROJECTS_SOURCE_DIR"/builddirproject/builddirproject.kdev4" );
    KDevSignalSpy* projectSpy = new KDevSignalSpy( ICore::self()->projectController(), SIGNAL( projectOpened( KDevelop::IProject* ) ) );
    ICore::self()->projectController()->openProject( projecturl );
    // Wait for the project to be opened
    if( !projectSpy->wait( 20000 ) ) {
        kFatal() << "Expected project to be loaded within 20 seconds, but this didn't happen";
    }
    IProject* project = ICore::self()->projectController()->findProjectByName( "BuilddirProject" );
    QVERIFY( project );
   
    KUrl currentBuilddir = project->buildSystemManager()->buildDirectory( project->projectItem() );

    QCOMPARE( currentBuilddir, KUrl( projecturl.directory(KUrl::AppendTrailingSlash) ) );
}


117 118 119 120 121 122 123 124 125 126 127
void CustomBuildSystemPluginTest::loadMultiPathProject()
{
    KUrl projecturl( PROJECTS_SOURCE_DIR"/multipathproject/multipathproject.kdev4" );
    KDevSignalSpy* projectSpy = new KDevSignalSpy( ICore::self()->projectController(), SIGNAL( projectOpened( KDevelop::IProject* ) ) );
    ICore::self()->projectController()->openProject( projecturl );
    // Wait for the project to be opened
    if( !projectSpy->wait( 20000 ) ) {
        kFatal() << "Expected project to be loaded within 20 seconds, but this didn't happen";
    }
    IProject* project = ICore::self()->projectController()->findProjectByName( "MultiPathProject" );
    QVERIFY( project );
Andreas Pakulat's avatar
Andreas Pakulat committed
128
    KDevelop::ProjectBaseItem* mainfile = 0;
129 130 131 132 133 134 135 136 137 138 139 140
    foreach( KDevelop::ProjectBaseItem* i, project->files() ) {
        if( i->text() == "main.cpp" ) {
            mainfile = i;
            break;
        }
    }
    QVERIFY(mainfile);
    KUrl::List includes = project->buildSystemManager()->includeDirectories( mainfile );

    QHash<QString,QString> defines;
    defines.insert( "BUILD", "debug" );
    QCOMPARE( includes, KUrl::List( QStringList() << "/usr/local/include/mydir" ) );
141
    QCOMPARE( project->buildSystemManager()->defines( mainfile ), defines );
142
    QCOMPARE( project->buildSystemManager()->buildDirectory( mainfile ).url(KUrl::RemoveTrailingSlash), KUrl( "file:///home/andreas/projects/testcustom/build2/src" ).url() );
143 144
}

145 146 147
QTEST_KDEMAIN(CustomBuildSystemPluginTest, GUI)

#include "custombuildsystemplugintest.moc"