File indexing completed on 2024-04-28 04:37:34
0001 /* 0002 SPDX-FileCopyrightText: 2008 Manuel Breugelmans <mbr.nxi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_KDEVSIGNALSPY_H 0008 #define KDEVPLATFORM_KDEVSIGNALSPY_H 0009 0010 #include <QObject> 0011 #include "testsexport.h" 0012 0013 class QEventLoop; 0014 class QTimer; 0015 0016 namespace KDevelop { 0017 /*! A signal spy which exits the event loop when the signal is called, 0018 * and remembers that the signal was emitted. 0019 * adapted version of kdelibs/kdecore/utils/qtest_kde.cpp */ 0020 class KDEVPLATFORMTESTS_EXPORT KDevSignalSpy 0021 : public QObject 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 /*! Constructor. @p obj the object that is expected to emit @p signal. */ 0027 KDevSignalSpy(QObject* obj, const char* signal, 0028 Qt::ConnectionType ct = Qt::AutoConnection); 0029 0030 /*! Blocks until either the expected signal has been emitted or 0031 * @p timeout milliseconds have passed. */ 0032 bool wait(int timeout); 0033 0034 private Q_SLOTS: 0035 void signalEmitted(); 0036 0037 private: 0038 QObject* m_obj; 0039 bool m_emitted; 0040 QEventLoop* m_loop; 0041 QTimer* m_timer; 0042 }; 0043 } // KDevelop 0044 0045 #endif