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 #ifndef KDEVPLATFORM_PLUGIN_QUICKOPENTESTBASE_H 0008 #define KDEVPLATFORM_PLUGIN_QUICKOPENTESTBASE_H 0009 0010 #include <QObject> 0011 0012 #include <language/interfaces/quickopenfilter.h> 0013 0014 #include <tests/testcore.h> 0015 #include <tests/testproject.h> 0016 0017 #include <project/projectmodel.h> 0018 0019 #include "../duchainitemquickopen.h" 0020 #include "../projectfilequickopen.h" 0021 0022 #include <utility> 0023 0024 using KDevelop::TestProjectUtils::createChild; 0025 0026 class QuickOpenTestBase 0027 : public QObject 0028 { 0029 Q_OBJECT 0030 public: 0031 explicit QuickOpenTestBase(KDevelop::TestCore::Setup setup, QObject* parent = nullptr); 0032 private Q_SLOTS: 0033 void initTestCase(); 0034 void cleanupTestCase(); 0035 0036 void cleanup(); 0037 protected: 0038 KDevelop::TestCore* core; 0039 KDevelop::TestCore::Setup setup; 0040 KDevelop::TestProjectController* projectController; 0041 }; 0042 0043 class PathTestFilter 0044 : public KDevelop::PathFilter<QString, PathTestFilter> 0045 { 0046 public: 0047 void setItems(QVector<QString> data) 0048 { 0049 updateItems([&data](QVector<QString>& oldData) { 0050 oldData = std::move(data); 0051 }); 0052 } 0053 0054 KDevelop::Path itemPath(const QString& data) const 0055 { 0056 return KDevelop::Path(data); 0057 } 0058 KDevelop::Path itemPrefixPath(const QString& /*data*/) const 0059 { 0060 return KDevelop::Path(QStringLiteral("/home/user/project")); 0061 } 0062 }; 0063 0064 KDevelop::TestProject* getProjectWithFiles(int files, const KDevelop::Path& path = {}); 0065 0066 QStringList items(const ProjectFileDataProvider& provider); 0067 0068 class TestFilter 0069 : public KDevelop::Filter<DUChainItem> 0070 { 0071 public: 0072 QString itemText(const DUChainItem& data) const override 0073 { 0074 return data.m_text; 0075 }; 0076 }; 0077 0078 Q_DECLARE_METATYPE(QVector<DUChainItem>) 0079 0080 #endif // KDEVPLATFORM_PLUGIN_QUICKOPENTESTBASE_H