|
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 "UT_SimControlKeySequenceHandler.h" |
|
21 #include "simcontrolkeysequencehandler.h" |
|
22 #include "keysequencerecognitionservicedefs.h" |
|
23 #include "qtestmains60.h" |
|
24 |
|
25 _LIT(KOldPinCode, "1234"); |
|
26 _LIT(KPukCode, "11111111"); |
|
27 _LIT(KNewPinCode, "4321"); |
|
28 _LIT(KVerifyNewPinCode, "4321"); |
|
29 |
|
30 |
|
31 void generateLeaveL() |
|
32 { |
|
33 User::Leave(KErrUnknown); |
|
34 } |
|
35 |
|
36 |
|
37 UT_SimControlKeySequenceHandler::UT_SimControlKeySequenceHandler() |
|
38 : |
|
39 m_handler(0) |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 |
|
45 UT_SimControlKeySequenceHandler::~UT_SimControlKeySequenceHandler() |
|
46 { |
|
47 delete m_handler; |
|
48 } |
|
49 |
|
50 |
|
51 void UT_SimControlKeySequenceHandler::init() |
|
52 { |
|
53 initialize(); |
|
54 |
|
55 m_handler = new SimControlKeySequenceHandler(); |
|
56 } |
|
57 |
|
58 |
|
59 void UT_SimControlKeySequenceHandler::cleanup() |
|
60 { |
|
61 reset(); |
|
62 |
|
63 delete m_handler; |
|
64 m_handler = 0; |
|
65 } |
|
66 |
|
67 void UT_SimControlKeySequenceHandler::t_constructionFails() |
|
68 { |
|
69 EXPECT( CManualSecuritySettings::NewL() ).willOnce(invokeWithoutArguments(generateLeaveL)); |
|
70 |
|
71 int result = 0; |
|
72 QT_TRYCATCH_ERROR(result, |
|
73 QScopedPointer<SimControlKeySequenceHandler> handler( |
|
74 new SimControlKeySequenceHandler()) |
|
75 ) |
|
76 QVERIFY(0 != result); |
|
77 } |
|
78 |
|
79 |
|
80 void UT_SimControlKeySequenceHandler::t_changePin1() |
|
81 { |
|
82 const QString KChangePin1KeySequence( "**04*1234*4321*4321*" ); |
|
83 |
|
84 EXPECT(CManualSecuritySettings::ChangePinL) |
|
85 .with(CManualSecuritySettings::EPin1, KOldPinCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
86 |
|
87 m_handler->executeKeySequence( KChangePin1KeySequence ); |
|
88 |
|
89 QVERIFY(verify()); |
|
90 |
|
91 |
|
92 // leave handling |
|
93 EXPECT( CManualSecuritySettings::ChangePinL ).willOnce(invokeWithoutArguments(generateLeaveL)) |
|
94 .with(CManualSecuritySettings::EPin1, KOldPinCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
95 int result = 0; |
|
96 QT_TRYCATCH_ERROR(result, |
|
97 m_handler->executeKeySequence(KChangePin1KeySequence) ) |
|
98 |
|
99 QVERIFY(0 != result); |
|
100 } |
|
101 |
|
102 void UT_SimControlKeySequenceHandler::t_changePin2() |
|
103 { |
|
104 const QString KChangePin2KeySequence( "**042*1234*4321*4321*" ); |
|
105 |
|
106 EXPECT(CManualSecuritySettings::ChangePinL) |
|
107 .with(CManualSecuritySettings::EPin2, KOldPinCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
108 |
|
109 m_handler->executeKeySequence(KChangePin2KeySequence); |
|
110 |
|
111 QVERIFY(verify()); |
|
112 |
|
113 |
|
114 //leave handling |
|
115 EXPECT( CManualSecuritySettings::ChangePinL ).willOnce(invokeWithoutArguments(generateLeaveL)) |
|
116 .with(CManualSecuritySettings::EPin2, KOldPinCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
117 |
|
118 int result = 0; |
|
119 QT_TRYCATCH_ERROR(result, |
|
120 m_handler->executeKeySequence(KChangePin2KeySequence) ) |
|
121 |
|
122 QVERIFY(0 != result); |
|
123 } |
|
124 |
|
125 void UT_SimControlKeySequenceHandler::t_unblockPin1() |
|
126 { |
|
127 const QString KUnblockPin1KeySequence( "**05*11111111*4321*4321*" ); |
|
128 |
|
129 EXPECT(CManualSecuritySettings::UnblockPinL) |
|
130 .with(CManualSecuritySettings::EPin1, KPukCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
131 |
|
132 m_handler->executeKeySequence(KUnblockPin1KeySequence); |
|
133 |
|
134 QVERIFY(verify()); |
|
135 |
|
136 |
|
137 //leave handling |
|
138 EXPECT( CManualSecuritySettings::UnblockPinL ).willOnce(invokeWithoutArguments(generateLeaveL)) |
|
139 .with(CManualSecuritySettings::EPin1, KPukCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
140 |
|
141 int result = 0; |
|
142 QT_TRYCATCH_ERROR(result, |
|
143 m_handler->executeKeySequence(KUnblockPin1KeySequence) ) |
|
144 |
|
145 QVERIFY(0 != result); |
|
146 } |
|
147 |
|
148 |
|
149 void UT_SimControlKeySequenceHandler::t_unblockPin2() |
|
150 { |
|
151 const QString KUnblockPin2KeySequence( "**052*11111111*4321*4321*" ); |
|
152 |
|
153 EXPECT(CManualSecuritySettings::UnblockPinL) |
|
154 .with(CManualSecuritySettings::EPin2, KPukCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
155 |
|
156 m_handler->executeKeySequence(KUnblockPin2KeySequence); |
|
157 |
|
158 QVERIFY(verify()); |
|
159 |
|
160 |
|
161 //leave handling |
|
162 EXPECT( CManualSecuritySettings::UnblockPinL ).willOnce(invokeWithoutArguments(generateLeaveL)) |
|
163 .with(CManualSecuritySettings::EPin2, KPukCode(), KNewPinCode(), KVerifyNewPinCode()); |
|
164 |
|
165 int result = 0; |
|
166 QT_TRYCATCH_ERROR(result, |
|
167 m_handler->executeKeySequence(KUnblockPin2KeySequence) ) |
|
168 |
|
169 QVERIFY(0 != result); |
|
170 } |
|
171 |
|
172 |
|
173 void UT_SimControlKeySequenceHandler::t_keySequenceValidator() |
|
174 { |
|
175 QString expectedValidator = |
|
176 QRegExp::escape(KCodeChangePin1) + "|" + |
|
177 QRegExp::escape(KCodeChangePin2) + "|" + |
|
178 QRegExp::escape(KCodeUnblockPin1) + "|" + |
|
179 QRegExp::escape(KCodeUnblockPin2); |
|
180 |
|
181 expect("KeySequenceHandler::setKeySequenceValidator") |
|
182 .with(expectedValidator); |
|
183 |
|
184 QScopedPointer<SimControlKeySequenceHandler> handler( |
|
185 new SimControlKeySequenceHandler()); |
|
186 |
|
187 QVERIFY(verify()); |
|
188 } |
|
189 |
|
190 QTEST_MAIN_S60(UT_SimControlKeySequenceHandler) |