37
|
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 DTMFService.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QtTest/QtTest>
|
74
|
19 |
#include <csmcmockcontext.h>
|
|
20 |
#include <smcdefaultvalue.h>
|
|
21 |
#include <msmcmockspecbuilder.h>
|
|
22 |
#include <smcobjecttotypemapper.h>
|
|
23 |
#include <mockservice.h>
|
37
|
24 |
#include "dtmfservice.h"
|
76
|
25 |
#include "phonetestmain.h"
|
37
|
26 |
|
74
|
27 |
typedef QSet<int> IntegerSet;
|
|
28 |
|
|
29 |
class TestDTMFService : public QObject, public MPECallControlIF, public MPECallSettersIF, public MockService
|
37
|
30 |
{
|
|
31 |
Q_OBJECT
|
|
32 |
public:
|
|
33 |
TestDTMFService();
|
|
34 |
virtual ~TestDTMFService();
|
|
35 |
|
|
36 |
public slots:
|
|
37 |
void initTestCase ();
|
|
38 |
void cleanupTestCase ();
|
|
39 |
void init ();
|
|
40 |
void cleanup ();
|
|
41 |
|
|
42 |
public:
|
|
43 |
void SetKeyCode( const TChar& aKeyCode );
|
|
44 |
void SetPhoneNumber( const TPEPhoneNumber& aPhoneNumber );
|
|
45 |
void SetCallTypeCommand( const TPECallType& aCallType );
|
|
46 |
TInt HandleDialServiceCall( const TBool aClientCall = EFalse );
|
|
47 |
void HandlePlayDTMFL();
|
|
48 |
TInt HandleEndDTMF();
|
|
49 |
void SetContactId2( const TInt aContactId );
|
|
50 |
void SetServiceIdCommand( TUint32 aServiceId );
|
|
51 |
|
|
52 |
private slots:
|
|
53 |
void testPlayDTMFTone ();
|
|
54 |
void testStopDTMFPlay ();
|
74
|
55 |
void testPlayDTMFTone_nocaps();
|
37
|
56 |
|
|
57 |
private:
|
|
58 |
DTMFService *m_dtmfService; // class under test
|
|
59 |
bool m_setPhoneNumberCalled;
|
|
60 |
bool m_setCallTypeCommandCalled;
|
|
61 |
bool m_handleDialCallCalled;
|
|
62 |
TPEPhoneNumber m_phoneNumber;
|
|
63 |
TPECallType m_callType;
|
|
64 |
bool m_clientCall;
|
|
65 |
int m_contactId;
|
|
66 |
bool m_setContactIdCalled;
|
|
67 |
bool m_handleEndDTMFCalled;
|
|
68 |
bool m_handlePlayDTMFLCalled;
|
|
69 |
bool m_setKeyCodeCalled;
|
|
70 |
bool m_handlePlayDtmfLeave;
|
|
71 |
ushort keyValue;
|
74
|
72 |
XQRequestInfo m_XQRequestInfoMock;
|
37
|
73 |
};
|
|
74 |
|
|
75 |
TestDTMFService::TestDTMFService ()
|
|
76 |
{
|
|
77 |
}
|
|
78 |
|
|
79 |
TestDTMFService::~TestDTMFService ()
|
|
80 |
{
|
|
81 |
}
|
|
82 |
|
|
83 |
void TestDTMFService::initTestCase ()
|
|
84 |
{
|
|
85 |
}
|
|
86 |
|
|
87 |
void TestDTMFService::cleanupTestCase ()
|
|
88 |
{
|
|
89 |
}
|
|
90 |
|
|
91 |
void TestDTMFService::init ()
|
|
92 |
{
|
74
|
93 |
initialize();
|
|
94 |
IntegerSet caps;
|
|
95 |
caps.insert(ECapabilityNetworkServices);
|
|
96 |
caps.insert(ECapabilityNetworkControl);
|
|
97 |
SmcDefaultValue<IntegerSet>::SetL(caps);
|
|
98 |
SmcDefaultValue<XQRequestInfo>::SetL(m_XQRequestInfoMock);
|
|
99 |
|
37
|
100 |
m_setPhoneNumberCalled = false;
|
|
101 |
m_setCallTypeCommandCalled = false;
|
|
102 |
m_handleDialCallCalled = false;
|
|
103 |
m_clientCall = false;
|
|
104 |
m_setContactIdCalled = false;
|
|
105 |
m_contactId = -1;
|
|
106 |
m_handleEndDTMFCalled = false;
|
|
107 |
m_handlePlayDTMFLCalled = false;
|
|
108 |
m_setKeyCodeCalled = false;
|
|
109 |
m_handlePlayDtmfLeave = false;
|
|
110 |
keyValue = -1;
|
|
111 |
m_dtmfService = new DTMFService (*this, *this, this);
|
|
112 |
}
|
|
113 |
|
|
114 |
void TestDTMFService::cleanup ()
|
|
115 |
{
|
74
|
116 |
SmcDefaultValue<IntegerSet>::Reset();
|
|
117 |
SmcDefaultValue<XQRequestInfo>::Reset();
|
|
118 |
reset();
|
37
|
119 |
delete m_dtmfService;
|
|
120 |
}
|
|
121 |
|
|
122 |
void TestDTMFService::SetKeyCode( const TChar& aKeyCode )
|
|
123 |
{
|
|
124 |
m_setKeyCodeCalled = true;
|
|
125 |
keyValue = aKeyCode;
|
|
126 |
}
|
|
127 |
|
|
128 |
void TestDTMFService::SetPhoneNumber( const TPEPhoneNumber& aPhoneNumber )
|
|
129 |
{
|
|
130 |
m_setPhoneNumberCalled = true;
|
|
131 |
m_phoneNumber = aPhoneNumber;
|
|
132 |
}
|
|
133 |
|
|
134 |
void TestDTMFService::SetCallTypeCommand( const TPECallType& aCallType )
|
|
135 |
{
|
|
136 |
m_setCallTypeCommandCalled = true;
|
|
137 |
m_callType = aCallType;
|
|
138 |
}
|
|
139 |
|
|
140 |
void TestDTMFService::HandlePlayDTMFL()
|
|
141 |
{
|
|
142 |
m_handlePlayDTMFLCalled = true;
|
|
143 |
|
|
144 |
if (m_handlePlayDtmfLeave)
|
|
145 |
User::Leave(KErrNotFound);
|
|
146 |
}
|
|
147 |
|
|
148 |
TInt TestDTMFService::HandleEndDTMF()
|
|
149 |
{
|
|
150 |
m_handleEndDTMFCalled = true;
|
|
151 |
return 0;
|
|
152 |
}
|
|
153 |
|
|
154 |
void TestDTMFService::SetContactId2( const TInt aContactId )
|
|
155 |
{
|
|
156 |
m_setContactIdCalled = true;
|
|
157 |
m_contactId = aContactId;
|
|
158 |
}
|
|
159 |
|
|
160 |
void TestDTMFService::SetServiceIdCommand( TUint32 aServiceId )
|
|
161 |
{
|
|
162 |
Q_UNUSED(aServiceId)
|
|
163 |
}
|
|
164 |
|
|
165 |
TInt TestDTMFService::HandleDialServiceCall( const TBool aClientCall )
|
|
166 |
{
|
|
167 |
m_handleDialCallCalled = true;
|
|
168 |
m_clientCall = aClientCall;
|
|
169 |
return KErrNone;
|
|
170 |
}
|
|
171 |
|
74
|
172 |
// Test cases
|
|
173 |
|
37
|
174 |
void TestDTMFService::testPlayDTMFTone()
|
|
175 |
{
|
|
176 |
QChar six('6');
|
|
177 |
m_dtmfService->playDTMFTone(six);
|
|
178 |
QVERIFY (m_setKeyCodeCalled == true);
|
|
179 |
QCOMPARE (keyValue, six.unicode());
|
|
180 |
QVERIFY (m_handlePlayDTMFLCalled == true);
|
|
181 |
|
|
182 |
m_handlePlayDtmfLeave = true;
|
|
183 |
|
|
184 |
TRAP_IGNORE(m_dtmfService->playDTMFTone(six));
|
|
185 |
|
|
186 |
m_handlePlayDtmfLeave = false;
|
|
187 |
}
|
|
188 |
|
|
189 |
void TestDTMFService::testStopDTMFPlay()
|
|
190 |
{
|
|
191 |
m_dtmfService->stopDTMFPlay();
|
|
192 |
QVERIFY (m_handleEndDTMFCalled == true);
|
|
193 |
}
|
|
194 |
|
74
|
195 |
void TestDTMFService::testPlayDTMFTone_nocaps()
|
|
196 |
{
|
|
197 |
QSet<int> caps;
|
|
198 |
expect( "XQRequestInfo::clientCapabilities" ).
|
|
199 |
returns(caps).
|
|
200 |
times(2);
|
|
201 |
QChar six('6');
|
|
202 |
int ret = m_dtmfService->playDTMFTone(six);
|
|
203 |
QVERIFY (ret == KErrPermissionDenied);
|
|
204 |
ret = m_dtmfService->stopDTMFPlay();
|
|
205 |
QVERIFY (ret == KErrPermissionDenied);
|
|
206 |
|
|
207 |
QVERIFY( verify() );
|
|
208 |
}
|
|
209 |
|
|
210 |
|
76
|
211 |
PHONE_TEST_MAIN(TestDTMFService)
|
37
|
212 |
#include "unit_tests.moc"
|
74
|
213 |
|