File indexing completed on 2024-03-24 16:41:28
0001 /************************************************************************************* 0002 Copyright (C) 2004 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net) 0003 2012-2022 by Michel Ludwig (michel.ludwig@kdemail.net) 0004 *************************************************************************************/ 0005 0006 /*************************************************************************** 0007 * * 0008 * This program is free software; you can redistribute it and/or modify * 0009 * it under the terms of the GNU General Public License as published by * 0010 * the Free Software Foundation; either version 2 of the License, or * 0011 * (at your option) any later version. * 0012 * * 0013 ***************************************************************************/ 0014 0015 #ifndef CONFIGTESTER_H 0016 #define CONFIGTESTER_H 0017 0018 #include <QObject> 0019 #include <QMap> 0020 #include <QProcess> 0021 0022 #include <QUrl> 0023 0024 class KJob; 0025 class QTemporaryDir; 0026 class KProcess; 0027 0028 class KileInfo; 0029 0030 namespace KileDocument 0031 { 0032 class TextInfo; 0033 } 0034 0035 namespace KileTool 0036 { 0037 class Base; 0038 } 0039 0040 class ConfigTest : public QObject 0041 { 0042 Q_OBJECT 0043 0044 public: 0045 enum Status { Success = 2, Failure = 1, NotRun = 0 }; 0046 0047 ConfigTest(const QString& testGroup, const QString &name, bool isCritical); 0048 virtual ~ConfigTest(); 0049 0050 int status() const; 0051 0052 virtual void call() = 0; 0053 0054 QString resultText() const; 0055 QString name() const; 0056 QString testGroup() const; 0057 0058 void addDependency(ConfigTest *test); 0059 bool allDependenciesSucceeded() const; 0060 0061 bool isCritical() const; 0062 0063 bool isSilent() const; 0064 void setSilent(bool b); 0065 0066 Q_SIGNALS: 0067 void testComplete(ConfigTest *test); 0068 0069 private: 0070 QString m_testGroup, m_name; 0071 bool m_isCritical, m_isSilent; 0072 std::list<ConfigTest*> m_dependencyTestList; 0073 0074 protected: 0075 Status m_status; 0076 QString m_resultText; 0077 0078 void setName(const QString& name); 0079 }; 0080 0081 class OkularVersionTest : public ConfigTest 0082 { 0083 Q_OBJECT 0084 public: 0085 OkularVersionTest(const QString& testGroup, bool isCritical); 0086 ~OkularVersionTest(); 0087 0088 virtual void call() override; 0089 0090 bool isViewerModeSupported() const; 0091 0092 private: 0093 bool m_isViewerModeSupported; 0094 }; 0095 0096 class FindProgramTest : public ConfigTest 0097 { 0098 Q_OBJECT 0099 public: 0100 FindProgramTest(const QString& testGroup, const QString& programName, bool isCritical); 0101 ~FindProgramTest(); 0102 0103 virtual void call() override; 0104 0105 void setAdditionalFailureMessage(const QString& s); 0106 0107 protected: 0108 QString m_programName; 0109 QString m_additionalFailureMessage; 0110 }; 0111 0112 class TestToolInKileTest : public ConfigTest 0113 { 0114 Q_OBJECT 0115 public: 0116 TestToolInKileTest(const QString& testGroup, KileInfo *kileInfo, const QString& toolName, const QString& filePath, bool isCritical); 0117 ~TestToolInKileTest(); 0118 0119 virtual void call() override; 0120 0121 protected Q_SLOTS: 0122 void handleToolExit(KileTool::Base *tool, int status, bool childToolSpawned); 0123 0124 void reportSuccess(); 0125 void reportFailure(); 0126 0127 protected: 0128 KileInfo *m_ki; 0129 QString m_toolName; 0130 QString m_filePath; 0131 QUrl m_documentUrl; 0132 }; 0133 0134 class ProgramTest : public ConfigTest 0135 { 0136 Q_OBJECT 0137 public: 0138 ProgramTest(const QString& testGroup, const QString& programName, const QString& workingDir, 0139 const QString& arg0, 0140 const QString& arg1, 0141 const QString& arg2 = "", 0142 bool isCritical = false); 0143 ~ProgramTest(); 0144 0145 virtual void call() override; 0146 0147 protected Q_SLOTS: 0148 virtual void handleTestProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); 0149 virtual void handleTestProcessError(QProcess::ProcessError error); 0150 0151 virtual void reportSuccess(); 0152 virtual void reportFailure(); 0153 0154 protected: 0155 KProcess *m_testProcess; 0156 QString m_programName; 0157 QString m_workingDir; 0158 QString m_arg0, m_arg1, m_arg2; 0159 0160 virtual void processFinishedSuccessfully(); 0161 }; 0162 0163 class LaTeXSrcSpecialsSupportTest : public ProgramTest 0164 { 0165 Q_OBJECT 0166 public: 0167 LaTeXSrcSpecialsSupportTest(const QString& testGroup, const QString& workingDir, 0168 const QString& fileBaseName); 0169 ~LaTeXSrcSpecialsSupportTest(); 0170 0171 protected: 0172 QString m_fileBaseName; 0173 0174 virtual void reportSuccess() override; 0175 virtual void reportFailure() override; 0176 virtual void processFinishedSuccessfully() override; 0177 }; 0178 0179 class SyncTeXSupportTest : public ProgramTest 0180 { 0181 Q_OBJECT 0182 public: 0183 SyncTeXSupportTest(const QString& testGroup, const QString& toolName, const QString& workingDir, 0184 const QString& fileBaseName); 0185 ~SyncTeXSupportTest(); 0186 0187 protected: 0188 QString m_fileBaseName; 0189 0190 virtual void reportSuccess() override; 0191 virtual void reportFailure() override; 0192 virtual void processFinishedSuccessfully() override; 0193 }; 0194 0195 class Tester : public QObject 0196 { 0197 Q_OBJECT 0198 0199 public: 0200 explicit Tester(KileInfo *kileInfo, QObject *parent = 0); 0201 ~Tester(); 0202 0203 QStringList testGroups(); 0204 QList<ConfigTest*> resultForGroup(const QString &); 0205 int statusForGroup(const QString &testGroup, bool *isCritical = Q_NULLPTR); 0206 0207 bool isSyncTeXSupportedForPDFLaTeX(); 0208 bool isViewerModeSupportedInOkular(); 0209 bool areSrcSpecialsSupportedForLaTeX(); 0210 0211 public Q_SLOTS: 0212 void runTests(); 0213 0214 Q_SIGNALS: 0215 void started(); 0216 void percentageDone(int); 0217 void finished(bool); 0218 0219 private Q_SLOTS: 0220 void addResult(const QString &tool, ConfigTest* testResult); 0221 0222 void startNextTest(); 0223 0224 void handleFileCopyResult(KJob* job); 0225 void handleTestComplete(ConfigTest *test); 0226 0227 private: 0228 KileInfo *m_ki; 0229 QMap<QString, QList<ConfigTest*> > m_results; 0230 QTemporaryDir *m_tempDir; 0231 ConfigTest *m_currentTest; 0232 std::list<ConfigTest*> m_testList; 0233 std::list<ConfigTest*>::iterator m_nextTestIterator; 0234 int m_testsDone; 0235 ConfigTest *m_pdfLaTeXSyncTeXSupportTest, *m_laTeXSrcSpecialsSupportTest; 0236 OkularVersionTest *m_okularVersionTest; 0237 0238 QString m_runningTestGroup; 0239 QUrl m_runningToolTestUrl; 0240 bool m_runningTestCritical; 0241 0242 void setupTests(); 0243 void installConsecutivelyDependentTests(ConfigTest *t1, ConfigTest *t2 = Q_NULLPTR, 0244 ConfigTest *t3 = Q_NULLPTR, 0245 ConfigTest *t4 = Q_NULLPTR); 0246 }; 0247 0248 #endif