Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /** |
---|---|
2 | * Copyright (C) 2005 Jeroen Wijnhout <Jeroen.Wijnhout@kdemail.net> |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #ifndef KUNITTEST_MODULE_H |
27 | #define KUNITTEST_MODULE_H |
28 | |
29 | #include <QtCore/QString> |
30 | |
31 | #include <klibloader.h> |
32 | #include <kunittest/runner.h> |
33 | |
34 | namespace KUnitTest |
35 | { |
36 | /*! @def KUNITTEST_MODULE(library,suite) |
37 | * Use this macro if you are creating a KUnitTest module named library. |
38 | * This macro creates a module-class named a factory class. The module |
39 | * will appear under the name suite in the test runner. |
40 | * There is no need in calling the K_EXPORT_COMPONENT_FACTORY macro, |
41 | * this is taken care of automatically. |
42 | * |
43 | * @code KUNITTEST_MODULE(kunittest_samplemodule,"TestSuite") @endcode |
44 | */ |
45 | #define KUNITTEST_MODULE(library,suite) \ |
46 | static const QString s_kunittest_suite = QLatin1String(suite); \ |
47 | class library##Module : public QObject \ |
48 | { \ |
49 | public: \ |
50 | library##Module() \ |
51 | { \ |
52 | KUnitTest::Registry::const_iterator it = s_registry.constBegin(); \ |
53 | for( ; it != s_registry.constEnd(); ++it ) \ |
54 | KUnitTest::Runner::registerTester(it.key(), it.value()); \ |
55 | } \ |
56 | \ |
57 | static KUnitTest::Registry s_registry; \ |
58 | }; \ |
59 | \ |
60 | KUnitTest::Registry library##Module::s_registry; \ |
61 | \ |
62 | void kunittest_registerModuleTester(const char *name, KUnitTest::Tester *test) \ |
63 | { \ |
64 | library##Module::s_registry.insert(name, test); \ |
65 | } \ |
66 | \ |
67 | class module##Factory : public KLibFactory \ |
68 | { \ |
69 | public: \ |
70 | QObject *createObject (QObject *, const char *, const char *, const QStringList &) \ |
71 | { \ |
72 | return new library##Module(); \ |
73 | }; \ |
74 | }; \ |
75 | \ |
76 | K_EXPORT_COMPONENT_FACTORY( library, module##Factory ) |
77 | |
78 | /*! @def KUNITTEST_MODULE_REGISTER_TESTER(tester) |
79 | * Use this macro to add a tester class to your module. The name of the tester will |
80 | * be identical to the class name. |
81 | * |
82 | * @code KUNITTEST_MODULE_REGISTER_TESTER(SimpleSampleTester) @endcode |
83 | */ |
84 | #define KUNITTEST_MODULE_REGISTER_TESTER( tester) \ |
85 | static class tester##ModuleAutoregister \ |
86 | { \ |
87 | public: \ |
88 | tester##ModuleAutoregister() \ |
89 | { \ |
90 | KUnitTest::Tester *test = new tester(); \ |
91 | QString name = s_kunittest_suite + QLatin1String("::") + QString::fromLocal8Bit(#tester); \ |
92 | test->setName(name.local8Bit()); \ |
93 | kunittest_registerModuleTester(name.local8Bit(), test ); \ |
94 | } \ |
95 | } tester##ModuleAutoregisterInstance; |
96 | |
97 | /*! @def KUNITTEST_MODULE_REGISTER_NAMEDTESTER(name,tester) |
98 | * Use this macro to add a tester class, with specified name, to your module.. |
99 | * |
100 | * @code KUNITTEST_MODULE_REGISTER_TESTER("SubSuite::PrettyName",SimpleSampleTester) @endcode |
101 | */ |
102 | #define KUNITTEST_MODULE_REGISTER_NAMEDTESTER( name , tester) \ |
103 | static class tester##ModuleAutoregister \ |
104 | { \ |
105 | public: \ |
106 | tester##ModuleAutoregister() \ |
107 | { \ |
108 | QString fullName = s_kunittest_suite + QString("::") + QString::fromLocal8Bit(name); \ |
109 | KUnitTest::Tester *test = new tester(fullName.local8Bit()); \ |
110 | kunittest_registerModuleTester(fullName.local8Bit(), test); \ |
111 | } \ |
112 | } tester##ModuleAutoregisterInstance; |
113 | } |
114 | |
115 | #endif |
116 |
Warning: That file was not part of the compilation database. It may have many parsing errors.