|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtGui> |
|
19 #include <QtTest/QtTest> |
|
20 #include <hbdevicemessagebox.h> |
|
21 #include <centralrepository.h> |
|
22 #include <etel.h> |
|
23 #include <etelmm.h> |
|
24 #include <rmmcustomapi.h> |
|
25 #include <mmtsy_names.h> |
|
26 #include "ut_lifetimerkeysequencehandler.h" |
|
27 #include "lifetimerkeysequencehandler.h" |
|
28 #include "keysequencerecognitionservicedefs.h" |
|
29 #include "telservicesinternalcrkeys.h" |
|
30 #include "telservicesvariant.hrh" |
|
31 #include "qtestmains60.h" |
|
32 |
|
33 void generateLeaveL() |
|
34 { |
|
35 User::Leave(KErrUnknown); |
|
36 } |
|
37 |
|
38 UT_LifeTimerKeySequenceHandler::UT_LifeTimerKeySequenceHandler() |
|
39 : |
|
40 m_handler(0) |
|
41 { |
|
42 |
|
43 } |
|
44 |
|
45 |
|
46 UT_LifeTimerKeySequenceHandler::~UT_LifeTimerKeySequenceHandler() |
|
47 { |
|
48 delete m_handler; |
|
49 } |
|
50 |
|
51 |
|
52 void UT_LifeTimerKeySequenceHandler::setLifeTimerData( |
|
53 TUint32 aKey, |
|
54 TInt & aValue ) |
|
55 { |
|
56 if (KTelSrvVariationFlags == aKey) { |
|
57 aValue = KTelSrvLVFlagLifeTimer; |
|
58 } |
|
59 } |
|
60 |
|
61 |
|
62 void UT_LifeTimerKeySequenceHandler::setLifeTimeData( |
|
63 TDes8& aLifeTimeInfo) |
|
64 { |
|
65 RMmCustomAPI::TLifeTimeDataPckg &pckg = |
|
66 reinterpret_cast<RMmCustomAPI::TLifeTimeDataPckg&>(aLifeTimeInfo); |
|
67 pckg.Copy(aLifeTimeInfo); |
|
68 pckg().iHours = 999; |
|
69 pckg().iMinutes = 59; |
|
70 } |
|
71 |
|
72 |
|
73 void UT_LifeTimerKeySequenceHandler::init() |
|
74 { |
|
75 initialize(); |
|
76 |
|
77 m_handler = new LifeTimerKeySequenceHandler(); |
|
78 } |
|
79 |
|
80 |
|
81 void UT_LifeTimerKeySequenceHandler::cleanup() |
|
82 { |
|
83 reset(); |
|
84 |
|
85 delete m_handler; |
|
86 m_handler = 0; |
|
87 } |
|
88 |
|
89 |
|
90 void UT_LifeTimerKeySequenceHandler::t_constructionFails() |
|
91 { |
|
92 EXPECT(CRepository::NewL).willOnce(invoke(generateLeaveL)); |
|
93 |
|
94 int result = 0; |
|
95 QT_TRYCATCH_ERROR(result, |
|
96 QScopedPointer<LifeTimerKeySequenceHandler> handler( |
|
97 new LifeTimerKeySequenceHandler()) |
|
98 ) |
|
99 QVERIFY(0 != result); |
|
100 } |
|
101 |
|
102 |
|
103 void UT_LifeTimerKeySequenceHandler::t_keySequenceValidator() |
|
104 { |
|
105 // life timer feature enabled scenario |
|
106 EXPECT(CRepository::Get) |
|
107 .willOnce(invoke(this, setLifeTimerData)) |
|
108 .returns(KErrNone); |
|
109 expect("KeySequenceHandler::setKeySequenceValidator") |
|
110 .with(QRegExp::escape(KCodeLifeTimer)); |
|
111 |
|
112 QScopedPointer<LifeTimerKeySequenceHandler> handler1( |
|
113 new LifeTimerKeySequenceHandler()); |
|
114 |
|
115 QVERIFY(verify()); |
|
116 |
|
117 // life timer feature not enabled scenario |
|
118 EXPECT(CRepository::Get).returns(KErrNotFound); |
|
119 expect("KeySequenceHandler::setKeySequenceValidator").times(0); |
|
120 |
|
121 QScopedPointer<LifeTimerKeySequenceHandler> handler2( |
|
122 new LifeTimerKeySequenceHandler()); |
|
123 |
|
124 QVERIFY(verify()); |
|
125 } |
|
126 |
|
127 |
|
128 void UT_LifeTimerKeySequenceHandler::t_executeValidKeySequence() |
|
129 { |
|
130 EXPECT(CRepository::Get) |
|
131 .willOnce(invoke(this, setLifeTimerData)) |
|
132 .returns(KErrNone); |
|
133 EXPECT(RMmCustomAPI::GetLifeTime) |
|
134 .willOnce(invoke(this, setLifeTimeData)); |
|
135 |
|
136 EXPECT(HbDeviceMessageBox::setTimeout).with(HbPopup::NoTimeout); |
|
137 EXPECT(HbDeviceMessageBox::show); |
|
138 bool handled = m_handler->executeKeySequence(KCodeLifeTimer); |
|
139 QCOMPARE(handled, true); |
|
140 |
|
141 QVERIFY(verify()); |
|
142 } |
|
143 |
|
144 |
|
145 void UT_LifeTimerKeySequenceHandler::t_executeInvalidKeySequence() |
|
146 { |
|
147 const QString KUnknownSequence("123"); |
|
148 bool handled = m_handler->executeKeySequence(KUnknownSequence); |
|
149 QCOMPARE(handled, false); |
|
150 } |
|
151 |
|
152 |
|
153 void UT_LifeTimerKeySequenceHandler::t_executeKeySequenceEtelConnectionCreationFails() |
|
154 { |
|
155 EXPECT(CRepository::Get) |
|
156 .willOnce(invoke(this, setLifeTimerData)) |
|
157 .returns(KErrNone); |
|
158 EXPECT(RTelServer::Connect).willOnce(invoke(generateLeaveL)); |
|
159 |
|
160 int result = 0; |
|
161 QT_TRYCATCH_ERROR(result, m_handler->executeKeySequence(KCodeLifeTimer)); |
|
162 |
|
163 QVERIFY(0 != result); |
|
164 QVERIFY(verify()); |
|
165 } |
|
166 |
|
167 |
|
168 void UT_LifeTimerKeySequenceHandler::t_executeKeySequenceLifeTimeDataQueryFails() |
|
169 { |
|
170 EXPECT(CRepository::Get) |
|
171 .willOnce(invoke(this, setLifeTimerData)) |
|
172 .returns(KErrNone); |
|
173 EXPECT(RMmCustomAPI::GetLifeTime).returns(KErrArgument); |
|
174 |
|
175 bool handled = m_handler->executeKeySequence(KCodeLifeTimer); |
|
176 |
|
177 QCOMPARE(handled, true); |
|
178 QVERIFY(verify()); |
|
179 } |
|
180 |
|
181 QTEST_MAIN_S60(UT_LifeTimerKeySequenceHandler) |