File indexing completed on 2024-04-28 04:36:31

0001 /*
0002     SPDX-FileCopyrightText: 2012 Miha Čančula <miha@noughmad.eu>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_ITESTCONTROLLER_H
0008 #define KDEVPLATFORM_ITESTCONTROLLER_H
0009 
0010 #include "interfacesexport.h"
0011 
0012 #include <QList>
0013 #include <QObject>
0014 #include <QHash>
0015 #include <QString>
0016 
0017 class QStringList;
0018 
0019 namespace KDevelop {
0020 
0021 struct TestResult;
0022 
0023 class IProject;
0024 class ITestSuite;
0025 
0026 
0027 /**
0028  * The result of a single unit test run
0029  **/
0030 struct KDEVPLATFORMINTERFACES_EXPORT TestResult
0031 {
0032     /**
0033      * Enumeration of possible test case results
0034      **/
0035     enum TestCaseResult
0036     {
0037         NotRun, ///< The test case was not selected for running.
0038         Skipped, ///< The test case was skipped.
0039         Passed, ///< The test case was run and passed.
0040         Failed, ///< The test case was run and failed.
0041         ExpectedFail, ///< The test case was expected to fail, and did.
0042         UnexpectedPass, ///< The test case was expected to fail, but passed.
0043         Error, ///< There was an error while trying to run the test case.
0044     };
0045 
0046     /**
0047      * The individual results of all test cases.
0048      **/
0049     QHash<QString, TestCaseResult> testCaseResults;
0050 
0051     /**
0052      * The total result of the entire suite.
0053      *
0054      * This is usually the worst outcome of the individual test cases,
0055      * but can be different especially when dealing with errors.
0056      */
0057     TestCaseResult suiteResult;
0058 };
0059 
0060 class KDEVPLATFORMINTERFACES_EXPORT ITestController : public QObject
0061 {
0062     Q_OBJECT
0063 public:
0064     explicit ITestController(QObject* parent = nullptr);
0065     ~ITestController() override;
0066 
0067     /**
0068      * Add a new test suite.
0069      *
0070      * No ownership is taken, the caller stays responsible for the suite.
0071      *
0072      * If a suite with the same project and same name exists, the old one will be removed and deleted.
0073      */
0074     virtual void addTestSuite(ITestSuite* suite) = 0;
0075     /**
0076      * Remove a test suite from the controller.
0077      *
0078      * This does not delete the test suite.
0079      */
0080     virtual void removeTestSuite(ITestSuite* suite) = 0;
0081 
0082     /**
0083      * Returns the list of all known test suites.
0084      */
0085     virtual QList<ITestSuite*> testSuites() const = 0;
0086     /**
0087      * Find a test suite in @p project with @p name.
0088      */
0089     virtual ITestSuite* findTestSuite(IProject* project, const QString& name) const = 0;
0090     /**
0091      * Return the list of all test suites in @p project.
0092      */
0093     virtual QList<ITestSuite*> testSuitesForProject(IProject* project) const = 0;
0094 
0095     /**
0096      * Notify the controller that a test run for @p suite was finished with result @p result
0097      */
0098     virtual void notifyTestRunFinished(ITestSuite* suite, const KDevelop::TestResult& result) = 0;
0099 
0100     /**
0101      * Notify the controller that a test run for @p suite was started
0102      */
0103     virtual void notifyTestRunStarted(KDevelop::ITestSuite* suite, const QStringList& test_cases) = 0;
0104 
0105 Q_SIGNALS:
0106     /**
0107      * Emitted whenever a new test suite gets added.
0108      */
0109     void testSuiteAdded(KDevelop::ITestSuite* suite);
0110     /**
0111      * Emitted whenever a test suite gets removed.
0112      */
0113     void testSuiteRemoved(KDevelop::ITestSuite* suite);
0114     /**
0115      * Emitted after a test suite was run.
0116      */
0117     void testRunFinished(KDevelop::ITestSuite* suite, const KDevelop::TestResult& result);
0118      /**
0119      * Emitted when a test suite starts.
0120      */
0121     void testRunStarted(KDevelop::ITestSuite* suite, const QStringList& test_cases);
0122 };
0123 
0124 }
0125 
0126 Q_DECLARE_INTERFACE( KDevelop::ITestController, "org.kdevelop.ITestController")
0127 
0128 #endif // KDEVPLATFORM_ITESTCONTROLLER_H