KDECore
qtest_kde.cpp
Go to the documentation of this file.00001 #include "qtest_kde.h"
00002
00003
00004
00005 class KDESignalSpy : public QObject
00006 {
00007 Q_OBJECT
00008 public:
00009 KDESignalSpy(QObject *obj, const char *signal, int timeout)
00010 : QObject(0), m_obj(obj), m_emitted(false)
00011 {
00012 connect(obj, signal, this, SLOT(slotSignalEmitted()));
00013 if (timeout > 0) {
00014 QObject::connect(&m_timer, SIGNAL(timeout()), &m_loop, SLOT(quit()));
00015 m_timer.setSingleShot(true);
00016 m_timer.start(timeout);
00017 }
00018 m_loop.exec();
00019 }
00020 bool signalEmitted() const { return m_emitted; }
00021
00022 private Q_SLOTS:
00023 void slotSignalEmitted()
00024 {
00025 m_emitted = true;
00026 disconnect(m_obj, 0, this, 0);
00027 m_timer.stop();
00028 m_loop.quit();
00029 }
00030 private:
00031 QObject* m_obj;
00032 bool m_emitted;
00033 QEventLoop m_loop;
00034 QTimer m_timer;
00035 };
00036
00037
00038
00039 bool QTest::kWaitForSignal(QObject *obj, const char *signal, int timeout )
00040 {
00041 KDESignalSpy spy(obj, signal, timeout);
00042 return spy.signalEmitted();
00043 }
00044
00045 #include "qtest_kde.moc"