KUnitTest
runner.h
Go to the documentation of this file.00001
00028 #ifndef KUNITTEST_RUNNER_H
00029 #define KUNITTEST_RUNNER_H
00030
00031 #include <iostream>
00032 using namespace std;
00033
00034 #include <QtCore/QObject>
00035 #include <QtCore/QHash>
00036 #include <QtCore/QString>
00037
00038 #include "kunittest_export.h"
00039 #include "tester.h"
00040
00041
00042 namespace KUnitTest
00043 {
00049 #define KUNITTEST_SUITE(suite)\
00050 static const QString s_kunittest_suite = suite;
00051
00061 #define KUNITTEST_REGISTER_TESTER( tester )\
00062 static TesterAutoregister tester##Autoregister( QString(s_kunittest_suite + QString("::") + QString::fromLocal8Bit(#tester)).local8Bit() , new tester ())
00063
00064 #define KUNITTEST_REGISTER_NAMEDTESTER( name, tester )\
00065 static TesterAutoregister tester##Autoregister( QString(s_kunittest_suite + QString("::") + QString::fromLocal8Bit(name)).local8Bit() , new tester ())
00066
00068 typedef QHash<QByteArray, Tester*> Registry;
00069
00087 class KUNITTEST_EXPORT Runner : public QObject
00088 {
00089 Q_OBJECT
00090
00091 public:
00096 static void registerTester(const char *name, Tester *test);
00097
00100 Registry ®istry();
00101
00104 static Runner *self();
00105
00108 int numberOfTestCases();
00109
00114 static void loadModules(const QString &folder, const QString &query);
00115
00122 static void setDebugCapturingEnabled(bool enabled);
00123
00124 private:
00125 Registry m_registry;
00126 static Runner *s_self;
00127 static bool s_debugCapturingEnabled;
00128
00129 protected:
00130 Runner();
00131
00132 public:
00134 int numberOfTests() const;
00135
00137 int numberOfPassedTests() const;
00138
00140 int numberOfFailedTests() const;
00141
00143 int numberOfExpectedFailures() const;
00144
00146 int numberOfSkippedTests() const;
00147
00148 public Q_SLOTS:
00152 int runTests();
00153
00159 void runTest(const char *name);
00160
00164 void runMatchingTests(const QString &prefix);
00165
00168 void reset();
00169
00170 Q_SIGNALS:
00175 void finished(const char *name, Tester *test);
00176 void invoke();
00177
00178 private:
00179 void registerTests();
00180
00181 private:
00182 int globalSteps;
00183 int globalTests;
00184 int globalPasses;
00185 int globalFails;
00186 int globalXFails;
00187 int globalXPasses;
00188 int globalSkipped;
00189 };
00190
00194 class TesterAutoregister
00195 {
00196 public:
00200 TesterAutoregister(const char *name, Tester *test)
00201 {
00202 if ( test->objectName().isNull())
00203 test->setObjectName(QLatin1String(name));
00204 Runner::registerTester(name, test);
00205 }
00206 };
00207
00208 }
00209
00210 #endif