runner.h

Go to the documentation of this file.
00001 /*
00002  * kunittest.h
00003  *
00004  * Copyright (C)  2004  Zack Rusin <zack@kde.org>
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00020  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00021  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00022  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00023  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00025  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 &registry();
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
KDE Home | KDE Accessibility Home | Description of Access Keys