|
1 /* |
|
2 * Copyright (c) 2010 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 test for satappmainhandler |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QTimer> |
|
19 #include <QAction> |
|
20 |
|
21 #include <hbmessagebox.h> |
|
22 |
|
23 #include "ut_satappconfirmprovider.h" |
|
24 #include "satappconfirmprovider.h" |
|
25 #include "satappaction.h" |
|
26 |
|
27 // -------------------------------------------------------- |
|
28 // The unit tests begin here |
|
29 // -------------------------------------------------------- |
|
30 |
|
31 Ut_SatAppConfirmProvider::Ut_SatAppConfirmProvider( |
|
32 QObject *parent) |
|
33 :QObject(parent) |
|
34 { |
|
35 } |
|
36 |
|
37 void Ut_SatAppConfirmProvider::testConfirmCommand_data() |
|
38 { |
|
39 QTest::addColumn<int>("commandId"); |
|
40 QTest::addColumn<int>("alphaIdStatus"); |
|
41 QTest::addColumn<QString>("text"); |
|
42 QTest::addColumn<QString>("additionText"); |
|
43 QTest::addColumn<bool>("userAccepted"); |
|
44 QTest::addColumn<bool>("expectRes"); |
|
45 |
|
46 |
|
47 QTest::newRow("t01") << (int)ESatOpenChannelQuery << (int)ESatAlphaIdNull |
|
48 << "comfrm" << "addition"<< false << false; |
|
49 QTest::newRow("t02") << (int)ESatOpenChannelQuery << (int)ESatAlphaIdNotProvided |
|
50 << "comfrm" << "addition"<< true << true; |
|
51 QTest::newRow("t03") << (int)ESatOpenChannelQuery << (int)ESatAlphaIdNotProvided |
|
52 << "" << "addition"<< true << true; |
|
53 QTest::newRow("t04") << (int)ESatOpenChannelQuery << (int)ESatAlphaIdNotProvided |
|
54 << "comfrm" << ""<< true << true; |
|
55 QTest::newRow("t05") << (int)ESatSSendSmQuery << (int)ESatAlphaIdNull |
|
56 << "comfrm" << "addition"<< true << true; |
|
57 QTest::newRow("t06") << (int)ESatSSetUpCallQuery << (int)ESatAlphaIdNull |
|
58 << "comfrm" << "addition"<< true << true; |
|
59 QTest::newRow("t07") << (int)ESatSSetUpCallQuery << (int)ESatAlphaIdNull |
|
60 << "" << "addition"<< true << true; |
|
61 QTest::newRow("t08") << (int)ESatSSetUpCallQuery << (int)ESatAlphaIdNull |
|
62 << "" << ""<< true << true; |
|
63 QTest::newRow("t09") << (int)ESatSLaunchBrowserQuery << (int)ESatAlphaIdNull |
|
64 << "" << ""<< true << true; |
|
65 QTest::newRow("t10") << (int)ESatSLaunchBrowserQuery << (int)ESatAlphaIdNotProvided |
|
66 << "" << ""<< true << true; |
|
67 QTest::newRow("t11") << (int)ESatSLaunchBrowserQuery << (int)ESatAlphaIdNull |
|
68 << "" << ""<< true << true; |
|
69 QTest::newRow("t12") << 10 << (int)ESatAlphaIdNull |
|
70 << "" << ""<< true << true; |
|
71 QTest::newRow("t05") << (int)ESatSSendUssdQuery << (int)ESatAlphaIdNull |
|
72 << "comfrm" << "addition"<< true << true; |
|
73 QTest::newRow("t05") << (int)ESatSSendSsQuery << (int)ESatAlphaIdNull |
|
74 << "comfrm" << "addition"<< true << true; |
|
75 QTest::newRow("t05") << (int)ESatSRefreshQuery << (int)ESatAlphaIdNull |
|
76 << "comfrm" << "addition"<< true << true; |
|
77 } |
|
78 |
|
79 |
|
80 void Ut_SatAppConfirmProvider::testConfirmCommand() |
|
81 { |
|
82 QFETCH(int, commandId); |
|
83 QFETCH(int, alphaIdStatus); |
|
84 QFETCH(QString, text); |
|
85 QFETCH(QString, additionText); |
|
86 QFETCH(bool, userAccepted); |
|
87 QFETCH(bool, expectRes); |
|
88 |
|
89 SatAppAction action(ESatConfirmAction); |
|
90 action.set(KeyQueryCommandId, commandId); |
|
91 action.set(KeyAlphaIdStatus, alphaIdStatus); |
|
92 action.set(KeyText, text); |
|
93 action.set(KeyAdditionalText, additionText); |
|
94 action.set(KeyActionAccepted, userAccepted); |
|
95 |
|
96 ConfirmProviderTest test; |
|
97 QTimer::singleShot(1000, &test, SLOT(simulateFirstActionClicked())); |
|
98 test.mConfirm->confirmCommand(action); |
|
99 QCOMPARE(userAccepted,expectRes); |
|
100 } |
|
101 |
|
102 void Ut_SatAppConfirmProvider::testConfirmFirstAction() |
|
103 { |
|
104 ConfirmProviderTest test; |
|
105 |
|
106 SatAppAction action(ESatConfirmAction); |
|
107 action.set(KeyQueryCommandId, ESatOpenChannelQuery); |
|
108 action.set(KeyAlphaIdStatus, ESatAlphaIdNull); |
|
109 action.set(KeyText, "OpenChannel"); |
|
110 action.set(KeyAdditionalText, "yes"); |
|
111 test.mConfirm->confirmCommand(action); |
|
112 QTimer::singleShot(1000, &test, SLOT(simulateFirstActionClicked())); |
|
113 action.waitUntilCompleted(); |
|
114 QCOMPARE(action.response(), ESatSuccess); |
|
115 } |
|
116 |
|
117 void Ut_SatAppConfirmProvider::testConfirmSecondAction() |
|
118 { |
|
119 ConfirmProviderTest test; |
|
120 |
|
121 SatAppAction action(ESatConfirmAction); |
|
122 action.set(KeyQueryCommandId, ESatOpenChannelQuery); |
|
123 action.set(KeyAlphaIdStatus, ESatAlphaIdNull); |
|
124 action.set(KeyText, "OpenChannel"); |
|
125 action.set(KeyAdditionalText, "No"); |
|
126 test.mConfirm->confirmCommand(action); |
|
127 QTimer::singleShot(1000, &test, SLOT(simulateSecondActionClicked())); |
|
128 action.waitUntilCompleted(); |
|
129 QCOMPARE(action.response(), ESatBackwardModeRequestedByUser); |
|
130 } |
|
131 |
|
132 |
|
133 void Ut_SatAppConfirmProvider::testConfirmAndClearScreen() |
|
134 { |
|
135 ConfirmProviderTest test; |
|
136 |
|
137 SatAppAction action(ESatConfirmAction); |
|
138 action.set(KeyQueryCommandId, ESatOpenChannelQuery); |
|
139 action.set(KeyAlphaIdStatus, ESatAlphaIdNull); |
|
140 action.set(KeyText, "OpenChannel"); |
|
141 action.set(KeyAdditionalText, "ClearScreen"); |
|
142 test.mConfirm->confirmCommand(action); |
|
143 QTimer::singleShot(1000, &test, SLOT(simulateClearScreen())); |
|
144 action.waitUntilCompleted(); |
|
145 QCOMPARE(action.response(), ESatNoResponseFromUser); |
|
146 |
|
147 action.set(KeyQueryCommandId, ESatSSetUpCallQuery); |
|
148 action.set(KeyText, "SetUpCall"); |
|
149 test.mConfirm->confirmCommand(action); |
|
150 QTimer::singleShot(1000, &test, SLOT(simulateClearScreen())); |
|
151 action.waitUntilCompleted(); |
|
152 QCOMPARE(action.response(), ESatNoResponseFromUser); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------- |
|
156 // internal helper class |
|
157 // --------------------------------------------------------------- |
|
158 |
|
159 ConfirmProviderTest::ConfirmProviderTest() |
|
160 { |
|
161 mConfirm = new SatAppConfirmProvider(this); |
|
162 } |
|
163 |
|
164 ConfirmProviderTest::~ConfirmProviderTest() |
|
165 { |
|
166 cleanup(); |
|
167 } |
|
168 |
|
169 void ConfirmProviderTest::simulateFirstActionClicked() |
|
170 { |
|
171 if (mConfirm->mConfirmQuery) |
|
172 mConfirm->mConfirmQuery->actions().at(0)->trigger(); |
|
173 } |
|
174 |
|
175 void ConfirmProviderTest::simulateSecondActionClicked() |
|
176 { |
|
177 if (mConfirm->mConfirmQuery) |
|
178 mConfirm->mConfirmQuery->actions().at(1)->trigger(); |
|
179 |
|
180 } |
|
181 |
|
182 void ConfirmProviderTest::simulateClearScreen() |
|
183 { |
|
184 if (mConfirm->mConfirmQuery) mConfirm->clearScreen(); |
|
185 } |
|
186 |
|
187 void ConfirmProviderTest::cleanup() |
|
188 { |
|
189 delete mConfirm; |
|
190 mConfirm = 0; |
|
191 } |
|
192 |
|
193 // End of file |