Unit tests for OnlinePollerThread
authorJari Jarvi <t7jaja00@students.oamk.fi>
Wed, 14 Jul 2010 11:32:31 +0000 (14:32 +0300)
committerJari Jarvi <t7jaja00@students.oamk.fi>
Wed, 14 Jul 2010 11:32:31 +0000 (14:32 +0300)
ut/ut_onlinepollerthread/ut_onlinepollerthread.cpp [new file with mode: 0644]
ut/ut_onlinepollerthread/ut_onlinepollerthread.h [new file with mode: 0644]
ut/ut_onlinepollerthread/ut_onlinepollerthread.pro [new file with mode: 0644]

diff --git a/ut/ut_onlinepollerthread/ut_onlinepollerthread.cpp b/ut/ut_onlinepollerthread/ut_onlinepollerthread.cpp
new file mode 100644 (file)
index 0000000..3b82321
--- /dev/null
@@ -0,0 +1,63 @@
+#include "ut_onlinepollerthread.h"
+#include "onlinepollerthread.h"
+
+// stubs
+#include <QNetworkConfigurationManager>
+#include <QDBusConnection>
+
+#include <QtTest>
+#include <QSignalSpy>
+
+
+void Ut_OnlinePollerThread::initTestCase()
+{
+}
+
+void Ut_OnlinePollerThread::cleanupTestCase()
+{
+}
+
+void init()
+{
+    QDBusConnection::sentMessages.clear();
+}
+
+void Ut_OnlinePollerThread::testRunOnline()
+{
+    OnlinePollerThread thread;
+    QNetworkConfigurationManager::online = true;
+    QSignalSpy spy(&thread, SIGNAL(online()));
+    thread.start();
+    QTest::qWait(500);
+    thread.stop();
+    
+    QCOMPARE(spy.count(), 1);
+    QCOMPARE(QDBusConnection::sentMessages.size(), 0);
+}
+
+void Ut_OnlinePollerThread::testRunOffline()
+{
+    OnlinePollerThread thread;
+    QNetworkConfigurationManager::online = false;
+    QSignalSpy spy(&thread, SIGNAL(online()));
+    thread.start();
+    QTest::qWait(500);
+    thread.stop();
+
+    QCOMPARE(spy.count(), 0);
+    QCOMPARE(QDBusConnection::sentMessages.size(), 1);
+
+    QCOMPARE(QDBusConnection::sentMessages[0].service(),
+            QString("com.nokia.icd_ui"));
+    QCOMPARE(QDBusConnection::sentMessages[0].path(),
+            QString("/com/nokia/icd_ui"));
+    QCOMPARE(QDBusConnection::sentMessages[0].interface(),
+            QString("com.nokia.icd_ui"));
+    QCOMPARE(QDBusConnection::sentMessages[0].member(),
+            QString("show_conn_dlg"));
+
+    QCOMPARE(QDBusConnection::sentMessages[0].arguments().size(), 1);
+}
+
+QTEST_MAIN(Ut_OnlinePollerThread)
+
diff --git a/ut/ut_onlinepollerthread/ut_onlinepollerthread.h b/ut/ut_onlinepollerthread/ut_onlinepollerthread.h
new file mode 100644 (file)
index 0000000..f18342a
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef _UT_ONLINEPOLLERTHREAD_H_
+#define _UT_ONLINEPOLLERTHREAD_H_
+
+#include <QObject>
+
+class OnlinePollerThread;
+
+class Ut_OnlinePollerThread: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void initTestCase();
+    void cleanupTestCase();
+    void testRunOnline();
+    void testRunOffline();
+};
+
+#endif // _UT_ONLINEPOLLERTHREAD_H_
+
+
+
diff --git a/ut/ut_onlinepollerthread/ut_onlinepollerthread.pro b/ut/ut_onlinepollerthread/ut_onlinepollerthread.pro
new file mode 100644 (file)
index 0000000..ed38fe1
--- /dev/null
@@ -0,0 +1,17 @@
+!include( ../ut.pri ) {
+    error( Could not find the ut.pri file )
+}
+
+
+HEADERS += ut_onlinepollerthread.h
+HEADERS += onlinepollerthread.h
+HEADERS += qdbusconnection.h
+HEADERS += qdbusmessage.h
+HEADERS += qnetworkconfigurationmanager.h
+
+SOURCES += ut_onlinepollerthread.cpp
+SOURCES += onlinepollerthread.cpp
+SOURCES += qdbusconnection.cpp
+SOURCES += qdbusmessage.cpp
+SOURCES += qnetworkconfigurationmanager.cpp
+