runner.hGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00033 #ifndef KUNITTEST_RUNNER_H
00034 #define KUNITTEST_RUNNER_H
00035
00036 #include <iostream>
00037 using namespace std;
00038
00039 #include <qobject.h>
00040 #include <qasciidict.h>
00041 #include <qstring.h>
00042
00043 #include <kdelibs_export.h>
00044
00045 #include "tester.h"
00046
00047 class QSocketNotifier;
00048
00049 namespace KUnitTest
00050 {
00056 #define KUNITTEST_SUITE(suite)\
00057 static const QString s_kunittest_suite = suite;
00058
00068 #define KUNITTEST_REGISTER_TESTER( tester )\
00069 static TesterAutoregister tester##Autoregister( QString(s_kunittest_suite + QString("::") + QString::fromLocal8Bit(#tester)).local8Bit() , new tester ())
00070
00071 #define KUNITTEST_REGISTER_NAMEDTESTER( name, tester )\
00072 static TesterAutoregister tester##Autoregister( QString(s_kunittest_suite + QString("::") + QString::fromLocal8Bit(name)).local8Bit() , new tester ())
00073
00075 typedef QAsciiDict<Tester> RegistryType;
00076
00078 typedef QAsciiDictIterator<Tester> RegistryIteratorType;
00079
00097 class KUNITTEST_EXPORT Runner : public QObject
00098 {
00099 Q_OBJECT
00100
00101 public:
00106 static void registerTester(const char *name, Tester *test);
00107
00110 RegistryType ®istry();
00111
00114 static Runner *self();
00115
00118 int numberOfTestCases();
00119
00124 static void loadModules(const QString &folder, const QString &query);
00125
00132 static void setDebugCapturingEnabled(bool enabled);
00133
00134 private:
00135 RegistryType m_registry;
00136 static Runner *s_self;
00137 static bool s_debugCapturingEnabled;
00138
00139 protected:
00140 Runner();
00141
00142 public:
00144 int numberOfTests() const;
00145
00147 int numberOfPassedTests() const;
00148
00150 int numberOfFailedTests() const;
00151
00153 int numberOfExpectedFailures() const;
00154
00156 int numberOfSkippedTests() const;
00157
00158 public slots:
00162 int runTests();
00163
00169 void runTest(const char *name);
00170
00174 void runMatchingTests(const QString &prefix);
00175
00178 void reset();
00179
00180 signals:
00185 void finished(const char *name, Tester *test);
00186 void invoke();
00187
00188 private:
00189 void registerTests();
00190
00191 private:
00192 int globalSteps;
00193 int globalTests;
00194 int globalPasses;
00195 int globalFails;
00196 int globalXFails;
00197 int globalXPasses;
00198 int globalSkipped;
00199 };
00200
00204 class TesterAutoregister
00205 {
00206 public:
00210 TesterAutoregister(const char *name, Tester *test)
00211 {
00212 if ( test->name() == 0L ) test->setName(name);
00213 Runner::registerTester(name, test);
00214 }
00215 };
00216
00217 }
00218
00219 #endif
|