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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32svr.h> |
|
19 #include <profile.hrh> |
|
20 #include <eunitmacros.h> |
|
21 #include <eunitdecorators.h> |
|
22 #include <csmcmockcontext.h> |
|
23 #include <msmcmockspecbuilder.h> |
|
24 #include <smcobjecttotypemapper.h> |
|
25 #include "ut_cphoneringingtonecontroller.h" |
|
26 #include "cphoneringingtonecontroller.h" |
|
27 #include "tphonecmdparamringtone.h" |
|
28 #include "cphoneringingtone.h" |
|
29 #include "cphonecenrepproxy.h" |
|
30 |
|
31 _LIT(KNokiatune, "Z:\\Data\\Sounds\\Digital\\Nokia tune.aac"); |
|
32 |
|
33 |
|
34 |
|
35 // custom comparison method for matching expected and items |
|
36 TBool operator==( const CPhoneRingingTone& aData1, |
|
37 const CPhoneRingingTone& aData2 ) |
|
38 { |
|
39 return ( aData1.FileName() == aData2.FileName()&& |
|
40 aData1.Volume() == aData2.Volume() && |
|
41 aData1.RingingType() == aData2.RingingType()&& |
|
42 aData1.TtsToneToBePlayed() == aData2.TtsToneToBePlayed()); |
|
43 } |
|
44 |
|
45 // - Construction ----------------------------------------------------------- |
|
46 |
|
47 ut_cphoneringingtonecontroller* ut_cphoneringingtonecontroller::NewL() |
|
48 { |
|
49 ut_cphoneringingtonecontroller* self = ut_cphoneringingtonecontroller::NewLC(); |
|
50 CleanupStack::Pop(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 ut_cphoneringingtonecontroller* ut_cphoneringingtonecontroller::NewLC() |
|
55 { |
|
56 ut_cphoneringingtonecontroller* self = new( ELeave ) ut_cphoneringingtonecontroller(); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 ut_cphoneringingtonecontroller::~ut_cphoneringingtonecontroller() |
|
63 { |
|
64 CSmcMockContext::Release(); |
|
65 } |
|
66 |
|
67 ut_cphoneringingtonecontroller::ut_cphoneringingtonecontroller() |
|
68 { |
|
69 } |
|
70 |
|
71 void ut_cphoneringingtonecontroller::ConstructL() |
|
72 { |
|
73 CEUnitTestSuiteClass::ConstructL(); |
|
74 iMockContext = CSmcMockContext::InstanceL(); |
|
75 } |
|
76 |
|
77 // - Test methods ----------------------------------------------------------- |
|
78 |
|
79 |
|
80 |
|
81 void ut_cphoneringingtonecontroller::SetupL( ) |
|
82 { |
|
83 iMockContext->InitializeL(); |
|
84 // need to be created here otherwise memory leak can be detected. |
|
85 iPhoneCenRepProxy = CPhoneCenRepProxy::Instance(); |
|
86 iRingingtoneplayer = CPhoneRingingToneController::NewL(); |
|
87 } |
|
88 |
|
89 |
|
90 void ut_cphoneringingtonecontroller::Teardown( ) |
|
91 { |
|
92 delete CPhoneCenRepProxy::Instance(); |
|
93 UserSvr::DllFreeTls(KUidCenRepProxySingleton.iUid); |
|
94 |
|
95 delete iRingingtoneplayer; |
|
96 iRingingtoneplayer = NULL; |
|
97 iMockContext->Reset(); |
|
98 } |
|
99 |
|
100 |
|
101 void ut_cphoneringingtonecontroller::T_PlayRingingtoneRinging( ) |
|
102 { |
|
103 // Expected data |
|
104 TBuf<50> ringingtone(KNokiatune); |
|
105 _LIT8( KMethod, "CPhoneRingingtonePlayer::PlayProfileBasedTone" ); |
|
106 CPhoneRingingTone* aAudioVideoRingingTone = CPhoneRingingTone::NewL(ringingtone); |
|
107 aAudioVideoRingingTone->SetRingingType(EProfileRingingTypeRinging); |
|
108 aAudioVideoRingingTone->SetTtsToneToBePlayed(EFalse); |
|
109 aAudioVideoRingingTone->SetVolume(5); |
|
110 iMockContext->ExpectCallL( KMethod() ).WithL(aAudioVideoRingingTone); |
|
111 |
|
112 TPhoneCmdParamRingTone ringToneParam; |
|
113 ringToneParam.SetVolume(5); |
|
114 ringToneParam.SetRingingType(EProfileRingingTypeRinging); |
|
115 // Set the profile ring tone |
|
116 ringToneParam.SetRingTone( ringingtone ); |
|
117 ringToneParam.SetType( EPhoneRingToneProfile ); |
|
118 |
|
119 iRingingtoneplayer->PlayRingToneL( &ringToneParam ); |
|
120 |
|
121 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
122 delete aAudioVideoRingingTone; |
|
123 |
|
124 } |
|
125 |
|
126 void ut_cphoneringingtonecontroller::T_PlayRingingtoneSilence( ) |
|
127 { |
|
128 _LIT8( KMethod, "CPhoneRingingtonePlayer::PlaySilentTone" ); |
|
129 |
|
130 iMockContext->ExpectCallL( KMethod() ); |
|
131 |
|
132 TPhoneCmdParamRingTone ringToneParam; |
|
133 ringToneParam.SetVolume(5); |
|
134 ringToneParam.SetRingingType(EProfileRingingTypeSilent); |
|
135 // Set the profile ring tone |
|
136 TBuf<50> ringingtone(KNokiatune); |
|
137 ringToneParam.SetRingTone( ringingtone ); |
|
138 ringToneParam.SetType( EPhoneRingToneProfile ); |
|
139 |
|
140 iRingingtoneplayer->PlayRingToneL( &ringToneParam ); |
|
141 |
|
142 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
143 } |
|
144 |
|
145 void ut_cphoneringingtonecontroller::T_PlayRingingtoneBeepOnce( ) |
|
146 { |
|
147 _LIT8( KMethod, "CPhoneRingingtonePlayer::PlayBeepOnce" ); |
|
148 iMockContext->ExpectCallL( KMethod() ).WithL(5); |
|
149 |
|
150 TPhoneCmdParamRingTone ringToneParam; |
|
151 ringToneParam.SetVolume(5); |
|
152 ringToneParam.SetRingingType(EProfileRingingTypeBeepOnce); |
|
153 // Set the profile ring tone |
|
154 TBuf<50> ringingtone(KNokiatune); |
|
155 ringToneParam.SetRingTone( ringingtone ); |
|
156 ringToneParam.SetType( EPhoneRingToneProfile ); |
|
157 |
|
158 iRingingtoneplayer->PlayRingToneL( &ringToneParam ); |
|
159 |
|
160 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
161 } |
|
162 |
|
163 void ut_cphoneringingtonecontroller::T_PlayRingingtoneAscending( ) |
|
164 { |
|
165 TBuf<50> ringingtone(KNokiatune); |
|
166 _LIT8( KMethod, "CPhoneRingingtonePlayer::PlayProfileBasedTone" ); |
|
167 CPhoneRingingTone* aAudioVideoRingingTone = CPhoneRingingTone::NewL(ringingtone); |
|
168 aAudioVideoRingingTone->SetRingingType(EProfileRingingTypeAscending); |
|
169 aAudioVideoRingingTone->SetTtsToneToBePlayed(EFalse); |
|
170 aAudioVideoRingingTone->SetVolume(5); |
|
171 iMockContext->ExpectCallL( KMethod() ).WithL(aAudioVideoRingingTone); |
|
172 |
|
173 TPhoneCmdParamRingTone ringToneParam; |
|
174 ringToneParam.SetVolume(5); |
|
175 ringToneParam.SetRingingType(EProfileRingingTypeAscending); |
|
176 // Set the profile ring tone |
|
177 ringToneParam.SetRingTone( ringingtone ); |
|
178 ringToneParam.SetType( EPhoneRingToneProfile ); |
|
179 |
|
180 iRingingtoneplayer->PlayRingToneL( &ringToneParam ); |
|
181 |
|
182 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
183 delete aAudioVideoRingingTone; |
|
184 } |
|
185 |
|
186 void ut_cphoneringingtonecontroller::T_PlayRingingtoneRingingOnce( ) |
|
187 { |
|
188 TBuf<50> ringingtone(KNokiatune); |
|
189 _LIT8( KMethod, "CPhoneRingingtonePlayer::PlayProfileBasedTone" ); |
|
190 CPhoneRingingTone* aAudioVideoRingingTone = CPhoneRingingTone::NewL(ringingtone); |
|
191 aAudioVideoRingingTone->SetRingingType(EProfileRingingTypeRingingOnce); |
|
192 aAudioVideoRingingTone->SetTtsToneToBePlayed(EFalse); |
|
193 aAudioVideoRingingTone->SetVolume(5); |
|
194 iMockContext->ExpectCallL( KMethod() ).WithL(aAudioVideoRingingTone); |
|
195 |
|
196 TPhoneCmdParamRingTone ringToneParam; |
|
197 ringToneParam.SetVolume(5); |
|
198 ringToneParam.SetRingingType(EProfileRingingTypeRingingOnce); |
|
199 // Set the profile ring tone |
|
200 ringToneParam.SetRingTone( ringingtone ); |
|
201 ringToneParam.SetType( EPhoneRingToneProfile ); |
|
202 |
|
203 iRingingtoneplayer->PlayRingToneL( &ringToneParam ); |
|
204 |
|
205 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
206 delete aAudioVideoRingingTone; |
|
207 } |
|
208 |
|
209 void ut_cphoneringingtonecontroller::T_PlayRingingtoneTTS() |
|
210 { |
|
211 // Expected data |
|
212 _LIT(KTextToSay, "Mr. Brownstone"); |
|
213 TBuf<30> texttosay (KTextToSay); |
|
214 TBuf<50> ringingtone(KNokiatune); |
|
215 CPhoneRingingTone* aAudioVideoRingingTone = CPhoneRingingTone::NewL(ringingtone); |
|
216 aAudioVideoRingingTone->SetRingingType(EProfileRingingTypeRinging); |
|
217 aAudioVideoRingingTone->SetTtsToneToBePlayed(ETrue); |
|
218 aAudioVideoRingingTone->SetVolume(5); |
|
219 _LIT8( KMethod, "CPhoneTTSPlayer::NewL" ); |
|
220 iMockContext->ExpectCallL( KMethod() ); |
|
221 _LIT8( KMethod2, "CPhoneTTSPlayer::PlayTtsTone" ); |
|
222 iMockContext->ExpectCallL( KMethod2() ).WithL(KTextToSay(), aAudioVideoRingingTone); |
|
223 _LIT8( KMethod3, "CPhoneRingingtonePlayer::PlayProfileBasedTone" ); |
|
224 iMockContext->ExpectCallL( KMethod3() ).WithL(aAudioVideoRingingTone); |
|
225 |
|
226 TPhoneCmdParamRingTone ringToneParam; |
|
227 ringToneParam.SetVolume(5); |
|
228 ringToneParam.SetRingingType(EProfileRingingTypeRinging); |
|
229 ringToneParam.SetTextToSay(texttosay); |
|
230 // Set the profile ring tone |
|
231 ringToneParam.SetRingTone( ringingtone); |
|
232 ringToneParam.SetType( EPhoneRingToneProfile ); |
|
233 |
|
234 iRingingtoneplayer->PlayRingToneL( &ringToneParam ); |
|
235 |
|
236 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
237 delete aAudioVideoRingingTone; |
|
238 } |
|
239 |
|
240 void ut_cphoneringingtonecontroller::T_StopRingingtone() |
|
241 { |
|
242 _LIT8( KMethod, "CPhoneRingingtonePlayer::StopPlaying" ); |
|
243 iMockContext->ExpectCallL( KMethod() ); |
|
244 |
|
245 iRingingtoneplayer->StopPlaying(); |
|
246 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
247 } |
|
248 // - EUnit test table ------------------------------------------------------- |
|
249 |
|
250 EUNIT_BEGIN_TEST_TABLE( |
|
251 ut_cphoneringingtonecontroller, |
|
252 "Add test suite description here.", |
|
253 "UNIT" ) |
|
254 |
|
255 EUNIT_TEST( |
|
256 "T_PlayRingingtoneRinging", |
|
257 "", |
|
258 "", |
|
259 "FUNCTIONALITY", |
|
260 SetupL, T_PlayRingingtoneRinging, Teardown) |
|
261 |
|
262 EUNIT_TEST( |
|
263 "T_PlayRingingtoneSilence", |
|
264 "", |
|
265 "", |
|
266 "FUNCTIONALITY", |
|
267 SetupL, T_PlayRingingtoneSilence, Teardown) |
|
268 |
|
269 EUNIT_TEST( |
|
270 "T_PlayRingingtoneBeepOnce", |
|
271 "", |
|
272 "", |
|
273 "FUNCTIONALITY", |
|
274 SetupL, T_PlayRingingtoneBeepOnce, Teardown) |
|
275 |
|
276 EUNIT_TEST( |
|
277 "T_PlayRingingtoneAscending", |
|
278 "", |
|
279 "", |
|
280 "FUNCTIONALITY", |
|
281 SetupL, T_PlayRingingtoneAscending, Teardown) |
|
282 |
|
283 EUNIT_TEST( |
|
284 "T_PlayRingingtoneAscending", |
|
285 "", |
|
286 "", |
|
287 "FUNCTIONALITY", |
|
288 SetupL, T_PlayRingingtoneRingingOnce, Teardown) |
|
289 |
|
290 EUNIT_TEST( |
|
291 "T_PlayRingingtoneTTS", |
|
292 "", |
|
293 "", |
|
294 "FUNCTIONALITY", |
|
295 SetupL, T_PlayRingingtoneTTS, Teardown) |
|
296 |
|
297 EUNIT_TEST( |
|
298 "T_StopRingingtone", |
|
299 "", |
|
300 "", |
|
301 "FUNCTIONALITY", |
|
302 SetupL, T_StopRingingtone, Teardown) |
|
303 EUNIT_END_TEST_TABLE |
|