module.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C)  2005  Jeroen Wijnhout <Jeroen.Wijnhout@kdemail.net>
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *   notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *   notice, this list of conditions and the following disclaimer in the
00012  *   documentation and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 
00031 #ifndef KUNITTEST_MODULE_H
00032 #define KUNITTEST_MODULE_H
00033 
00034 #include <qstring.h>
00035 
00036 #include <klibloader.h>
00037 #include <kunittest/runner.h>
00038 
00039 namespace KUnitTest
00040 {
00050     #define KUNITTEST_MODULE(library,suite)                                                 \
00051     static const QString s_kunittest_suite  = QString::fromLatin1(suite);                   \
00052     class library##Module : public QObject                                                  \
00053     {                                                                                       \
00054     public:                                                                                 \
00055         library##Module()                                                                   \
00056         {                                                                                   \
00057             KUnitTest::RegistryIteratorType it(s_registry);                                 \
00058             for( ; it.current(); ++it )                                                     \
00059                 KUnitTest::Runner::registerTester(it.currentKey(), it.current());           \
00060         }                                                                                   \
00061                                                                                             \
00062         static KUnitTest::RegistryType s_registry;                                          \
00063     };                                                                                      \
00064                                                                                             \
00065     KUnitTest::RegistryType library##Module::s_registry;                                    \
00066                                                                                             \
00067     void kunittest_registerModuleTester(const char *name, KUnitTest::Tester *test)          \
00068     {                                                                                       \
00069         library##Module::s_registry.insert(name, test);                                     \
00070     }                                                                                       \
00071                                                                                             \
00072     class module##Factory : public KLibFactory                                              \
00073     {                                                                                       \
00074     public:                                                                                 \
00075         QObject *createObject (QObject *, const char *, const char *, const QStringList &)  \
00076         {                                                                                   \
00077             return new library##Module();                                                   \
00078         };                                                                                  \
00079     };                                                                                      \
00080                                                                                             \
00081     K_EXPORT_COMPONENT_FACTORY( library, module##Factory )
00082 
00089     #define KUNITTEST_MODULE_REGISTER_TESTER( tester)                                           \
00090     static class tester##ModuleAutoregister                                                     \
00091     {                                                                                           \
00092     public:                                                                                     \
00093         tester##ModuleAutoregister()                                                            \
00094         {                                                                                       \
00095             KUnitTest::Tester *test = new tester();                                             \
00096             QString name = s_kunittest_suite + QString::fromLatin1("::") + QString::fromLocal8Bit(#tester); \
00097             test->setName(name.local8Bit());                                                    \
00098             kunittest_registerModuleTester(name.local8Bit(), test );                            \
00099         }                                                                                       \
00100     } tester##ModuleAutoregisterInstance;
00101 
00107     #define KUNITTEST_MODULE_REGISTER_NAMEDTESTER( name , tester)                             \
00108     static class tester##ModuleAutoregister                                                   \
00109     {                                                                                         \
00110     public:                                                                                   \
00111         tester##ModuleAutoregister()                                                          \
00112         {                                                                                     \
00113             QString fullName = s_kunittest_suite + QString("::") + QString::fromLocal8Bit(name); \
00114             KUnitTest::Tester *test = new tester(fullName.local8Bit());                       \
00115             kunittest_registerModuleTester(fullName.local8Bit(), test);                       \
00116         }                                                                                     \
00117     } tester##ModuleAutoregisterInstance;
00118 }
00119 
00120 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys