1 | /* |
2 | Copyright (c) 2009 Volker Krause <vkrause@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "test.h" |
21 | #include "resource.h" |
22 | #include "global.h" |
23 | |
24 | #include <KDebug> |
25 | #include <KMessageBox> |
26 | #include <stdlib.h> |
27 | |
28 | Test* Test::mSelf = 0; |
29 | |
30 | Test::Test(QObject* parent) : |
31 | QObject( parent ) |
32 | { |
33 | } |
34 | |
35 | void Test::verify(bool value) |
36 | { |
37 | if ( !value ) |
38 | fail( "Assertion failed." ); |
39 | } |
40 | |
41 | void Test::verify( QObject* object, const QString &slot ) |
42 | { |
43 | kDebug() << object << slot; |
44 | bool result = false; |
45 | if ( !QMetaObject::invokeMethod( object, slot.toLatin1(), Q_RETURN_ARG( bool, result ) ) ) |
46 | fail( "Unable to call method " + slot ); |
47 | |
48 | if ( result ) |
49 | return; |
50 | |
51 | QString lastError = QString( "Call to method " + slot + " returned false." ); |
52 | QMetaObject::invokeMethod( object, "lastError" , Q_RETURN_ARG( QString, lastError ) ); |
53 | fail( lastError ); |
54 | } |
55 | |
56 | void Test::fail(const QString& error) |
57 | { |
58 | kError() << error; |
59 | abort(); |
60 | } |
61 | |
62 | void Test::abort() |
63 | { |
64 | Global::cleanup(); |
65 | exit( -1 ); |
66 | } |
67 | |
68 | void Test::alert(const QString& msg) |
69 | { |
70 | KMessageBox::information( 0, msg ); |
71 | } |
72 | |
73 | Test* Test::instance() |
74 | { |
75 | if ( !mSelf ) |
76 | mSelf = new Test( Global::parent() ); |
77 | return mSelf; |
78 | } |
79 | |
80 | |
81 | |