File indexing completed on 2024-05-12 16:39:56

0001 /* This file is part of the KDE project
0002    Copyright (C) 2012-2013 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KEXITESTER_H
0021 #define KEXITESTER_H
0022 
0023 #include <QPointer>
0024 #include <kexiutils/kexiutils_export.h>
0025 #include <config-kexi.h>
0026 
0027 class QWidget;
0028 class KexiTestObject;
0029 
0030 //! Global object for setting up tests.
0031 class KEXIUTILS_EXPORT KexiTester : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     ~KexiTester();
0036 
0037     QObject *object(const QString &name) const;
0038 
0039     QWidget *widget(const QString &name) const;
0040 
0041     template <class W>
0042     W widget(const QString &name) const { return qobject_cast<W>(widget(name)); }
0043 
0044 protected:
0045     KexiTester();
0046 
0047     class Private;
0048     Private * const d;
0049 
0050 private:
0051     Q_DISABLE_COPY(KexiTester)
0052 };
0053 
0054 //! KexiTestObject is a container for object added for tests
0055 class KEXIUTILS_EXPORT KexiTestObject
0056 {
0057 public:
0058     explicit KexiTestObject(QObject *object, const QString &name = QString());
0059 private:
0060     QPointer<QObject> m_object;
0061     QString m_name;
0062 
0063     friend KEXIUTILS_EXPORT KexiTester& operator<<(KexiTester&, const KexiTestObject &);
0064 };
0065 
0066 //! @return global KexiTester object.
0067 KEXIUTILS_EXPORT KexiTester& kexiTester();
0068 
0069 //! Adds test object @a object to the tester.
0070 KEXIUTILS_EXPORT KexiTester& operator<<(KexiTester& tester, const KexiTestObject &object);
0071 
0072 #ifndef COMPILING_TESTS
0073 #define kexiTester while (false) kexiTester // Completely skip tester for final code
0074 #endif
0075 
0076 #endif // KEXITESTER_H