1 /*
2     SPDX-FileCopyrightText: 2010 Andreas Pakulat <apaku@gmx.de>
3 
4     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-or-later
5 */
6 
7 #include "test_custombuildsystemplugin.h"
8 
9 #include <QTest>
10 #include <QDebug>
11 
12 #include <tests/autotestshell.h>
13 #include <tests/testcore.h>
14 #include <tests/kdevsignalspy.h>
15 #include <tests/projectsgenerator.h>
16 #include <shell/sessioncontroller.h>
17 #include <interfaces/iprojectcontroller.h>
18 #include <interfaces/isession.h>
19 #include <interfaces/iproject.h>
20 #include <project/interfaces/ibuildsystemmanager.h>
21 #include <project/projectmodel.h>
22 
23 #include <serialization/indexedstring.h>
24 
25 #include "testconfig.h"
26 
27 using KDevelop::Core;
28 using KDevelop::ICore;
29 using KDevelop::IProject;
30 using KDevelop::TestCore;
31 using KDevelop::AutoTestShell;
32 using KDevelop::KDevSignalSpy;
33 using KDevelop::ProjectsGenerator;
34 using KDevelop::Path;
35 
QTEST_MAIN(TestCustomBuildSystemPlugin)36 QTEST_MAIN(TestCustomBuildSystemPlugin)
37 
38 void TestCustomBuildSystemPlugin::cleanupTestCase()
39 {
40     TestCore::shutdown();
41 }
initTestCase()42 void TestCustomBuildSystemPlugin::initTestCase()
43 {
44     AutoTestShell::init({"KDevCustomBuildSystem", "KDevStandardOutputView"});
45     TestCore::initialize();
46 }
47 
cleanup()48 void TestCustomBuildSystemPlugin::cleanup()
49 {
50     ICore::self()->projectController()->closeAllProjects( );
51 }
52 
loadSimpleProject()53 void TestCustomBuildSystemPlugin::loadSimpleProject()
54 {
55     m_currentProject = ProjectsGenerator::GenerateSimpleProject();
56     QVERIFY( m_currentProject );
57     QCOMPARE( m_currentProject->buildSystemManager()->buildDirectory( m_currentProject->projectItem() ),
58               Path( QStringLiteral("file:///") + QDir::temp().absolutePath() + QStringLiteral("/simpleproject/build/") ) );
59 }
60 
buildDirProject()61 void TestCustomBuildSystemPlugin::buildDirProject()
62 {
63     m_currentProject = ProjectsGenerator::GenerateEmptyBuildDirProject();
64     QVERIFY( m_currentProject );
65     QCOMPARE( m_currentProject->buildSystemManager()->buildDirectory( m_currentProject->projectItem() ),
66               Path( QStringLiteral("file:///") + QDir::temp().absolutePath() + QStringLiteral("/simpleproject/build/") ) );
67 }
68 
loadMultiPathProject()69 void TestCustomBuildSystemPlugin::loadMultiPathProject()
70 {
71     m_currentProject = ProjectsGenerator::GenerateMultiPathProject();
72     QVERIFY( m_currentProject );
73 
74     KDevelop::ProjectBaseItem* mainfile = nullptr;
75     const auto& files = m_currentProject->fileSet();
76     for (const auto& file : files) {
77         const auto& filesForPath = m_currentProject->filesForPath(file);
78         for (auto i: filesForPath) {
79             if( i->text() == QLatin1String("main.cpp") ) {
80                 mainfile = i;
81                 break;
82             }
83         }
84     }
85     QVERIFY(mainfile);
86 
87     QCOMPARE( m_currentProject->buildSystemManager()->buildDirectory( mainfile ),
88               Path( QStringLiteral("file:///") + QDir::temp().absolutePath() + QStringLiteral("/multipathproject/build/src") ) );
89 }
90 
91