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 DialService. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 |
|
20 #include "mpekeysequencerecognitionif.h" |
|
21 #include "keysequencerecognitionservice.h" |
|
22 |
|
23 class UT_KeySequenceRecognitionService |
|
24 : |
|
25 public QObject, public MPEKeySequenceRecognitionIF |
|
26 { |
|
27 Q_OBJECT |
|
28 |
|
29 public: |
|
30 UT_KeySequenceRecognitionService(); |
|
31 virtual ~UT_KeySequenceRecognitionService(); |
|
32 |
|
33 public: |
|
34 TBool ExecuteKeySequenceL(const TDesC16& aSequence); |
|
35 |
|
36 private slots: |
|
37 void init(); |
|
38 void cleanup(); |
|
39 void t_executeKeySequence(); |
|
40 void t_notRecognizedKeySequence(); |
|
41 void t_leaveDuringExecuteKeySequence(); |
|
42 |
|
43 private: |
|
44 KeySequenceRecognitionService *m_RecognitionService; |
|
45 TBool m_keySequenceExecutionResult; |
|
46 TPtrC16 m_keySequencePtr; |
|
47 int m_leaveSimulationCode; |
|
48 }; |
|
49 |
|
50 UT_KeySequenceRecognitionService::UT_KeySequenceRecognitionService() |
|
51 : |
|
52 m_RecognitionService(NULL), |
|
53 m_keySequenceExecutionResult(ETrue), |
|
54 m_leaveSimulationCode(KErrNone) |
|
55 { |
|
56 } |
|
57 |
|
58 UT_KeySequenceRecognitionService::~UT_KeySequenceRecognitionService() |
|
59 { |
|
60 delete m_RecognitionService; |
|
61 } |
|
62 |
|
63 TBool UT_KeySequenceRecognitionService::ExecuteKeySequenceL( |
|
64 const TDesC16& aSequence) |
|
65 { |
|
66 Q_UNUSED(aSequence) |
|
67 User::LeaveIfError(m_leaveSimulationCode); |
|
68 |
|
69 m_keySequencePtr.Set(aSequence.Ptr()); |
|
70 return m_keySequenceExecutionResult; |
|
71 } |
|
72 |
|
73 void UT_KeySequenceRecognitionService::init() |
|
74 { |
|
75 m_RecognitionService = new KeySequenceRecognitionService(*this); |
|
76 m_keySequenceExecutionResult = ETrue; |
|
77 m_keySequencePtr.Set(NULL, 0); |
|
78 m_leaveSimulationCode = KErrNone; |
|
79 } |
|
80 |
|
81 void UT_KeySequenceRecognitionService::cleanup() |
|
82 { |
|
83 delete m_RecognitionService; |
|
84 m_RecognitionService = NULL; |
|
85 } |
|
86 |
|
87 void UT_KeySequenceRecognitionService::t_executeKeySequence() |
|
88 { |
|
89 QString sequence("*#06#"); |
|
90 bool result = m_RecognitionService->executeKeySequence(sequence); |
|
91 QCOMPARE(result, true); |
|
92 QVERIFY( |
|
93 m_keySequencePtr == TPtrC16(reinterpret_cast<const TUint16*>(sequence.utf16()))); |
|
94 } |
|
95 |
|
96 void UT_KeySequenceRecognitionService::t_notRecognizedKeySequence() |
|
97 { |
|
98 m_keySequenceExecutionResult = EFalse; |
|
99 QString sequence("*#abc#"); |
|
100 bool result = m_RecognitionService->executeKeySequence(sequence); |
|
101 QCOMPARE(result, false); |
|
102 } |
|
103 |
|
104 void UT_KeySequenceRecognitionService::t_leaveDuringExecuteKeySequence() |
|
105 { |
|
106 m_leaveSimulationCode = KErrArgument; |
|
107 QString sequence("abc"); |
|
108 bool result = m_RecognitionService->executeKeySequence(sequence); |
|
109 QCOMPARE(result, false); |
|
110 } |
|
111 |
|
112 QTEST_MAIN(UT_KeySequenceRecognitionService) |
|
113 #include "unit_tests.moc" |
|