File indexing completed on 2024-05-12 04:39:14
0001 /* 0002 SPDX-FileCopyrightText: 2014 David Stevens <dgedstevens@gmail.com> 0003 SPDX-FileCopyrightText: 2014 Kevin Funk <kfunk@kde.org> 0004 SPDX-FileCopyrightText: 2015 Milian Wolff <mail@milianw.de> 0005 SPDX-FileCopyrightText: 2015 Sergey Kalinichev <kalinichev.so.0@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0008 */ 0009 0010 #include "codecompletiontestbase.h" 0011 0012 #include <tests/testcore.h> 0013 #include <tests/autotestshell.h> 0014 #include <tests/testproject.h> 0015 0016 #include <interfaces/idocumentcontroller.h> 0017 0018 #include "clangsettings/clangsettingsmanager.h" 0019 0020 #include <language/codecompletion/codecompletiontesthelper.h> 0021 0022 #include <KTextEditor/Editor> 0023 #include <KTextEditor/Document> 0024 #include <KTextEditor/View> 0025 0026 #include <QLoggingCategory> 0027 0028 void DeleteDocument::operator()(KTextEditor::View* view) const 0029 { 0030 // explicitly close the document when all references are valid, otherwise we have problems during cleanup 0031 const auto url = view->document()->url(); 0032 ICore::self()->documentController()->documentForUrl(url)->close(IDocument::Discard); 0033 } 0034 0035 std::unique_ptr<KTextEditor::View, DeleteDocument> CodeCompletionTestBase::createView(const QUrl& url) const 0036 { 0037 auto doc = KDevelop::ICore::self() 0038 ->documentController() 0039 ->openDocument(url, KTextEditor::Range::invalid(), KDevelop::IDocumentController::DoNotActivate) 0040 ->textDocument(); 0041 Q_ASSERT(doc); 0042 0043 auto view = doc->views().first(); 0044 Q_ASSERT(view); 0045 return std::unique_ptr<KTextEditor::View, DeleteDocument>(view); 0046 } 0047 0048 void CodeCompletionTestBase::initTestCase() 0049 { 0050 QStandardPaths::setTestModeEnabled(true); 0051 0052 QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevelop.plugins.clang.debug=true\n")); 0053 QVERIFY(qputenv("KDEV_CLANG_DISPLAY_DIAGS", "1")); 0054 AutoTestShell::init({QStringLiteral("kdevclangsupport")}); 0055 auto core = TestCore::initialize(); 0056 delete core->projectController(); 0057 m_projectController = new TestProjectController(core); 0058 core->setProjectController(m_projectController); 0059 ICore::self()->documentController()->closeAllDocuments(); 0060 0061 ClangSettingsManager::self()->m_enableTesting = true; 0062 } 0063 0064 void CodeCompletionTestBase::cleanupTestCase() 0065 { 0066 TestCore::shutdown(); 0067 } 0068 0069 void CodeCompletionTestBase::init() 0070 { 0071 m_projectController->closeAllProjects(); 0072 } 0073 0074 #include "moc_codecompletiontestbase.cpp"