File indexing completed on 2024-05-12 04:40:57

0001 /*
0002     SPDX-FileCopyrightText: Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "quickopentestbase.h"
0008 
0009 #include <tests/autotestshell.h>
0010 #include <tests/testcore.h>
0011 #include <tests/testplugincontroller.h>
0012 #include <tests/testproject.h>
0013 #include <interfaces/idocumentcontroller.h>
0014 #include <language/interfaces/quickopenfilter.h>
0015 
0016 using namespace KDevelop;
0017 
0018 QuickOpenTestBase::QuickOpenTestBase(Core::Setup setup_, QObject* parent)
0019     : QObject(parent)
0020     , core(nullptr)
0021     , setup(setup_)
0022     , projectController(nullptr)
0023 {
0024     qRegisterMetaType<QModelIndex>("QModelIndex");
0025 }
0026 
0027 void QuickOpenTestBase::initTestCase()
0028 {
0029     AutoTestShell::init();
0030     core = new TestCore;
0031     auto* pluginController = new TestPluginController(core);
0032     core->setPluginController(pluginController);
0033     TestCore::initialize(setup);
0034     projectController = new TestProjectController(core);
0035     delete core->projectController();
0036     core->setProjectController(projectController);
0037 }
0038 
0039 void QuickOpenTestBase::cleanupTestCase()
0040 {
0041     TestCore::shutdown();
0042 }
0043 
0044 void QuickOpenTestBase::cleanup()
0045 {
0046     projectController->closeAllProjects();
0047     core->documentController()->closeAllDocuments();
0048 }
0049 
0050 TestProject* getProjectWithFiles(int files, const Path& path)
0051 {
0052     auto* project = new TestProject(path);
0053     auto* foo = createChild<ProjectFolderItem>(project->projectItem(), QStringLiteral("foo"));
0054     auto* bar = createChild<ProjectFolderItem>(foo, QStringLiteral("bar"));
0055     for (int i = 0; i < files; ++i) {
0056         createChild<ProjectFileItem>(bar, QString::number(i) + QLatin1String(".txt"));
0057     }
0058 
0059     return project;
0060 }
0061 
0062 QStringList items(const ProjectFileDataProvider& provider)
0063 {
0064     QStringList list;
0065     for (uint i = 0; i < provider.itemCount(); ++i) {
0066         list << provider.data(i)->text();
0067     }
0068 
0069     return list;
0070 }
0071 
0072 #include "moc_quickopentestbase.cpp"