1 /*! |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Unit tests for ParserRecognizer. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 |
|
20 //#include <hbglobal_p.h> |
|
21 #include "xqservicerequest.h" |
|
22 #include "parserrecognizer.h" |
|
23 #include "pevirtualengine.h" |
|
24 |
|
25 QString apiString; |
|
26 QString methodString; |
|
27 bool sendCalled; |
|
28 bool gSendRequestResult = true; |
|
29 |
|
30 class TestParserRecognizer : public QObject |
|
31 { |
|
32 Q_OBJECT |
|
33 public: |
|
34 TestParserRecognizer(); |
|
35 virtual ~TestParserRecognizer(); |
|
36 |
|
37 public slots: |
|
38 void initTestCase (); |
|
39 void cleanupTestCase (); |
|
40 void init (); |
|
41 void cleanup (); |
|
42 |
|
43 private slots: |
|
44 void testActivateRfsDeep(); |
|
45 void testActivateRfsNormal(); |
|
46 void testActivateWarrantyMode(); |
|
47 void testShowBTDeviceAddress(); |
|
48 void testShowBTLoopback(); |
|
49 void testActivateBTDebugMode(); |
|
50 void testShowIMEI(); |
|
51 void testShowVersion(); |
|
52 void testShowWLANMacAddress(); |
|
53 void testSSRequestFailed(); |
|
54 void testSendRequestFail(); |
|
55 void testSimultaneousRequests(); |
|
56 |
|
57 private: |
|
58 ParserRecognizer *parserRecognizer; // class under test |
|
59 }; |
|
60 |
|
61 XQServiceRequest::XQServiceRequest(QString const& api, QString const& method, bool const& sync) |
|
62 { |
|
63 Q_UNUSED(sync); |
|
64 apiString = api; |
|
65 methodString = method; |
|
66 } |
|
67 |
|
68 bool XQServiceRequest::send() |
|
69 { |
|
70 sendCalled = true; |
|
71 return gSendRequestResult; |
|
72 } |
|
73 |
|
74 bool XQServiceRequest::send(QVariant& retValue) |
|
75 { |
|
76 Q_UNUSED(retValue); |
|
77 sendCalled = true; |
|
78 return gSendRequestResult; |
|
79 } |
|
80 |
|
81 void XQServiceRequest::setSynchronous(const bool &synchronous) |
|
82 { |
|
83 Q_UNUSED(synchronous); |
|
84 } |
|
85 |
|
86 XQServiceRequest::~XQServiceRequest() |
|
87 { |
|
88 } |
|
89 |
|
90 TestParserRecognizer::TestParserRecognizer () |
|
91 { |
|
92 } |
|
93 |
|
94 TestParserRecognizer::~TestParserRecognizer () |
|
95 { |
|
96 } |
|
97 |
|
98 void TestParserRecognizer::initTestCase () |
|
99 { |
|
100 } |
|
101 |
|
102 void TestParserRecognizer::cleanupTestCase () |
|
103 { |
|
104 } |
|
105 |
|
106 void TestParserRecognizer::init () |
|
107 { |
|
108 apiString = ""; |
|
109 methodString = ""; |
|
110 sendCalled = false; |
|
111 gSendRequestResult = true; |
|
112 parserRecognizer = new ParserRecognizer; |
|
113 } |
|
114 |
|
115 void TestParserRecognizer::cleanup () |
|
116 { |
|
117 delete parserRecognizer; |
|
118 } |
|
119 |
|
120 void TestParserRecognizer::testActivateRfsDeep() |
|
121 { |
|
122 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageActivateRfsDeep, 0); |
|
123 QCOMPARE(apiString, QString("com.nokia.services.telephony")); |
|
124 QCOMPARE(methodString, QString("activateDeepRestoreFactorySettings()")); |
|
125 QCOMPARE(sendCalled, true); |
|
126 } |
|
127 |
|
128 void TestParserRecognizer::testActivateRfsNormal() |
|
129 { |
|
130 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageActivateRfsNormal, 0); |
|
131 QCOMPARE(apiString, QString("com.nokia.services.telephony")); |
|
132 QCOMPARE(methodString, QString("activateNormalRestoreFactorySettings()")); |
|
133 QCOMPARE(sendCalled, true); |
|
134 } |
|
135 |
|
136 void TestParserRecognizer::testActivateWarrantyMode() |
|
137 { |
|
138 // Lifetimer is implemented by phone and should not be handled |
|
139 // by the recognizer. |
|
140 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageActivateWarrantyMode, 0); |
|
141 QCOMPARE(apiString, QString("")); |
|
142 QCOMPARE(methodString, QString("")); |
|
143 QCOMPARE(sendCalled, false); |
|
144 } |
|
145 |
|
146 void TestParserRecognizer::testShowBTDeviceAddress() |
|
147 { |
|
148 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowBTDeviceAddress, 0); |
|
149 QCOMPARE(apiString, QString("com.nokia.services.bluetooth")); |
|
150 QCOMPARE(methodString, QString("showBluetoothDeviceAddress()")); |
|
151 QCOMPARE(sendCalled, true); |
|
152 } |
|
153 |
|
154 void TestParserRecognizer::testShowBTLoopback() |
|
155 { |
|
156 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowBTLoopback, 0); |
|
157 QCOMPARE(apiString, QString("com.nokia.services.bluetooth")); |
|
158 QCOMPARE(methodString, QString("showBluetoothLoopback()")); |
|
159 QCOMPARE(sendCalled, true); |
|
160 } |
|
161 |
|
162 void TestParserRecognizer::testActivateBTDebugMode() |
|
163 { |
|
164 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageBTDebugMode, 0); |
|
165 QCOMPARE(apiString, QString("com.nokia.services.bluetooth")); |
|
166 QCOMPARE(methodString, QString("activateBluetoothDebugMode()")); |
|
167 QCOMPARE(sendCalled, true); |
|
168 } |
|
169 |
|
170 void TestParserRecognizer::testShowIMEI() |
|
171 { |
|
172 // IMEI code showing is implemented by phone and should not be handled |
|
173 // by the recognizer. |
|
174 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowIMEI, 0); |
|
175 QCOMPARE(apiString, QString("")); |
|
176 QCOMPARE(methodString, QString("")); |
|
177 QCOMPARE(sendCalled, false); |
|
178 } |
|
179 |
|
180 void TestParserRecognizer::testShowVersion() |
|
181 { |
|
182 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowVersion, 0); |
|
183 QCOMPARE(apiString, QString("com.nokia.services.devicemanager")); |
|
184 QCOMPARE(methodString, QString("showVersionNumber()")); |
|
185 QCOMPARE(sendCalled, true); |
|
186 } |
|
187 |
|
188 void TestParserRecognizer::testShowWLANMacAddress() |
|
189 { |
|
190 // WLAN address showing not supported currently (TB 10.1) |
|
191 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowWlanMacAddress, 0); |
|
192 QCOMPARE(apiString, QString("")); |
|
193 QCOMPARE(methodString, QString("")); |
|
194 QCOMPARE(sendCalled, false); |
|
195 } |
|
196 |
|
197 void TestParserRecognizer::testSSRequestFailed() |
|
198 { |
|
199 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageSSRequestFailed, 0); |
|
200 QCOMPARE(apiString, QString("com.nokia.services.telephony")); |
|
201 QCOMPARE(methodString, QString("supplementaryServiceRequestFailed()")); |
|
202 QCOMPARE(sendCalled, true); |
|
203 } |
|
204 |
|
205 void TestParserRecognizer::testSendRequestFail() |
|
206 { |
|
207 gSendRequestResult = false; |
|
208 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowVersion, 0); |
|
209 QCOMPARE(apiString, QString("com.nokia.services.devicemanager")); |
|
210 QCOMPARE(methodString, QString("showVersionNumber()")); |
|
211 QCOMPARE(sendCalled, true); |
|
212 } |
|
213 |
|
214 void TestParserRecognizer::testSimultaneousRequests() |
|
215 { |
|
216 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowVersion, 0); |
|
217 QCOMPARE(apiString, QString("com.nokia.services.devicemanager")); |
|
218 QCOMPARE(methodString, QString("showVersionNumber()")); |
|
219 QCOMPARE(sendCalled, true); |
|
220 |
|
221 sendCalled = false; |
|
222 parserRecognizer->sendMessage(MEngineMonitor::EPEMessageShowVersion, 0); |
|
223 QCOMPARE(sendCalled, false); |
|
224 } |
|
225 |
|
226 QTEST_MAIN(TestParserRecognizer) |
|
227 #include "unit_tests.moc" |
|