|
1 /* * This file is part of conn-dui-settings-inet * |
|
2 * |
|
3 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * |
|
6 * Contact: Aapo Makela <aapo.makela@nokia.com> |
|
7 * |
|
8 * This software, including documentation, is protected by copyright |
|
9 * controlled by Nokia Corporation. All rights are reserved. Copying, |
|
10 * including reproducing, storing, adapting or translating, any or all of |
|
11 * this material requires the prior written consent of Nokia Corporation. |
|
12 * This material also contains confidential information which may not be |
|
13 * disclosed to others without the prior written consent of Nokia. |
|
14 */ |
|
15 |
|
16 #include <QtTest/QtTest> |
|
17 #include <QCoreApplication> |
|
18 #include <QEventLoop> |
|
19 #include <QDebug> |
|
20 #include <icd/dbus_api.h> |
|
21 |
|
22 #include <dbusdispatcher.h> |
|
23 |
|
24 class Ut_DBusDispatcher : public QObject |
|
25 { |
|
26 Q_OBJECT |
|
27 |
|
28 private Q_SLOTS: |
|
29 void init(); |
|
30 void cleanup(); |
|
31 void initTestCase(); |
|
32 void cleanupTestCase(); |
|
33 |
|
34 void simpleSignalReceived(const QString& interface, |
|
35 const QString& signal, |
|
36 const QList<QVariant>& args); |
|
37 void simpleCallReply(const QString& method, |
|
38 const QList<QVariant>& args, |
|
39 const QString& error); |
|
40 void simpleCall(); |
|
41 |
|
42 void complexCallReply(const QString& method, |
|
43 const QList<QVariant>& args, |
|
44 const QString& error); |
|
45 void complexCall(); |
|
46 |
|
47 private: |
|
48 Maemo::DBusDispatcher *mSubject; |
|
49 QProcess *icd_stub; |
|
50 |
|
51 QString mMethod; |
|
52 QString mInterface; |
|
53 QString mSignal; |
|
54 QList<QVariant> mArgs; |
|
55 }; |
|
56 |
|
57 void Ut_DBusDispatcher::init() |
|
58 { |
|
59 mSubject = new Maemo::DBusDispatcher("com.nokia.icd2", "/com/nokia/icd2", |
|
60 "com.nokia.icd2"); |
|
61 |
|
62 // Start icd2 stub |
|
63 icd_stub = new QProcess(this); |
|
64 icd_stub->start("/usr/bin/icd2_stub.py"); |
|
65 QTest::qWait(1000); |
|
66 } |
|
67 |
|
68 void Ut_DBusDispatcher::cleanup() |
|
69 { |
|
70 // Terminate icd2 stub |
|
71 icd_stub->terminate(); |
|
72 icd_stub->waitForFinished(); |
|
73 |
|
74 delete mSubject; |
|
75 mSubject = 0; |
|
76 } |
|
77 |
|
78 void Ut_DBusDispatcher::initTestCase() |
|
79 { |
|
80 } |
|
81 |
|
82 void Ut_DBusDispatcher::cleanupTestCase() |
|
83 { |
|
84 } |
|
85 |
|
86 void Ut_DBusDispatcher::simpleSignalReceived(const QString& interface, |
|
87 const QString& signal, |
|
88 const QList<QVariant>& args) |
|
89 { |
|
90 // Signal handler, which simply records what has been signalled |
|
91 mInterface = interface; |
|
92 mSignal = signal; |
|
93 mArgs = args; |
|
94 } |
|
95 |
|
96 void Ut_DBusDispatcher::simpleCallReply(const QString& method, |
|
97 const QList<QVariant>& args, |
|
98 const QString& error) |
|
99 { |
|
100 mMethod = method; |
|
101 |
|
102 // Check that method matches and at least WLAN_INFRA is returned |
|
103 QVERIFY(error.isEmpty()); |
|
104 QVERIFY(args[0].toStringList().contains("WLAN_INFRA")); |
|
105 } |
|
106 |
|
107 void Ut_DBusDispatcher::simpleCall() |
|
108 { |
|
109 uint flags = 0; |
|
110 QList<QVariant> reply; |
|
111 int idx = 0; |
|
112 QTimer timer; |
|
113 |
|
114 // Connect signals |
|
115 connect(mSubject, SIGNAL(signalReceived(const QString&, |
|
116 const QString&, |
|
117 const QList<QVariant>&)), |
|
118 this, SLOT(simpleSignalReceived(const QString&, |
|
119 const QString&, |
|
120 const QList<QVariant>&))); |
|
121 connect(mSubject, SIGNAL(callReply(const QString&, |
|
122 const QList<QVariant>&, |
|
123 const QString&)), |
|
124 this, SLOT(simpleCallReply(const QString&, |
|
125 const QList<QVariant>&, |
|
126 const QString&))); |
|
127 |
|
128 // Request scan and verify the call starts succesfully |
|
129 QVERIFY(mSubject->callAsynchronous("scan_req", flags)); |
|
130 |
|
131 // Wait 1st scan signal for 10 secs |
|
132 timer.setSingleShot(true); |
|
133 timer.start(10000); |
|
134 while (timer.isActive() && mInterface.isEmpty()) { |
|
135 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
136 idx++; |
|
137 } |
|
138 timer.stop(); |
|
139 |
|
140 // Sanity checks for the scan result |
|
141 QVERIFY(mInterface == "com.nokia.icd2"); // interface is icd2 |
|
142 QVERIFY(mMethod == "scan_req"); // method is scan_req |
|
143 QVERIFY(mSignal == "scan_result_sig"); // signal is scan result |
|
144 QVERIFY(mArgs[0] == QVariant(0) || |
|
145 mArgs[0] == QVariant(4)); // First argument is status |
|
146 // (0 == NEW, 4 == COMPLETED) |
|
147 //QVERIFY(mArgs.contains(QVariant("WLAN_INFRA"))); // WLAN scan result |
|
148 } |
|
149 |
|
150 void Ut_DBusDispatcher::complexCallReply(const QString& method, |
|
151 const QList<QVariant>& args, |
|
152 const QString& error) |
|
153 { |
|
154 mMethod = method; |
|
155 |
|
156 // Check that method has not return arguments and error is not set |
|
157 QVERIFY(error.isEmpty()); |
|
158 QVERIFY(args.isEmpty()); |
|
159 } |
|
160 |
|
161 void Ut_DBusDispatcher::complexCall() |
|
162 { |
|
163 uint flags = ICD_CONNECTION_FLAG_UI_EVENT; |
|
164 QList<QVariant> reply; |
|
165 QVariantList networks; |
|
166 QVariantList network1; |
|
167 |
|
168 network1 << "" << (uint)0 << "" << "WLAN_INFRA" << (uint)0x05000011 << QByteArray("osso@46@net"); |
|
169 networks << QVariant(network1); |
|
170 |
|
171 // Connect signal |
|
172 connect(mSubject, SIGNAL(callReply(const QString&, |
|
173 const QList<QVariant>&, |
|
174 const QString&)), |
|
175 this, SLOT(complexCallReply(const QString&, |
|
176 const QList<QVariant>&, |
|
177 const QString&))); |
|
178 |
|
179 // Request connect and verify the call starts succesfully |
|
180 QVERIFY(mSubject->callAsynchronous("connect_req", flags, networks)); |
|
181 |
|
182 QTest::qWait(1000); |
|
183 |
|
184 // Sanity checks for the scan result |
|
185 QVERIFY(mInterface == "com.nokia.icd2"); // interface is icd2 |
|
186 QVERIFY(mMethod == "connect_req"); // method connect_req |
|
187 } |
|
188 |
|
189 QTEST_MAIN(Ut_DBusDispatcher) |
|
190 |
|
191 #include "ut_dbusdispatcher.moc" |