|
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 the License "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 |
|
19 // INCLUDES |
|
20 #include "VCXScheduledDownloadTester.h" |
|
21 #include "VCXTestMyVideosCollectionClient.h" |
|
22 #include "VCXTestLog.h" |
|
23 |
|
24 #include <ipvideo/CCseSchedulerAPI.h> |
|
25 #include <ipvideo/CCseScheduledProgram.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CVCXScheduledDownloadTester::NewL |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CVCXScheduledDownloadTester* CVCXScheduledDownloadTester::NewL( CVCXTestStifScriptBaseExt* aStifScriptBase ) |
|
36 { |
|
37 VCXLOGLO1(">>>CVCXScheduledDownloadTester::NewL"); |
|
38 CVCXScheduledDownloadTester* self = new (ELeave) CVCXScheduledDownloadTester( aStifScriptBase ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop( self ); |
|
42 VCXLOGLO1("<<<CVCXScheduledDownloadTester::NewL"); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CVCXScheduledDownloadTester::~CVCXScheduledDownloadTester |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CVCXScheduledDownloadTester::~CVCXScheduledDownloadTester() |
|
51 { |
|
52 VCXLOGLO1(">>>CVCXScheduledDownloadTester::~CVCXScheduledDownloadTester"); |
|
53 |
|
54 delete iMyVideosCollectionClient; |
|
55 iMyVideosCollectionClient = NULL; |
|
56 |
|
57 delete iMessageWait; |
|
58 iMessageWait = NULL; |
|
59 |
|
60 delete iSchedulerClient; |
|
61 iSchedulerClient = NULL; |
|
62 |
|
63 VCXLOGLO1("<<<CVCXScheduledDownloadTester::~CVCXScheduledDownloadTester"); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CVCXScheduledDownloadTester::CVCXScheduledDownloadTester |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CVCXScheduledDownloadTester::CVCXScheduledDownloadTester( CVCXTestStifScriptBaseExt* aStifScriptBase ) |
|
71 : iStifScriptBase( aStifScriptBase ) |
|
72 { |
|
73 |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CVCXScheduledDownloadTester::ConstructL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CVCXScheduledDownloadTester::ConstructL() |
|
81 { |
|
82 VCXLOGLO1(">>>CVCXScheduledDownloadTester::ConstructL"); |
|
83 iMessageWait = CVCXTestMessageWait::NewL( this ); |
|
84 |
|
85 iMyVideosCollectionClient = CVCXTestMyVideosCollectionClient::NewL( this ); |
|
86 |
|
87 // Wait for video list to open. |
|
88 iMessageWait->WaitForMessageL( EVCXTestVideoListRefreshed, 30, ETrue ); |
|
89 |
|
90 iSchedulerClient = CCseSchedulerApi::NewL(); |
|
91 |
|
92 VCXLOGLO1("<<<CVCXScheduledDownloadTester::ConstructL"); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CVCXScheduledDownloadTester::RefreshL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CVCXScheduledDownloadTester::RefreshL() |
|
100 { |
|
101 VCXLOGLO1(">>>CVCXScheduledDownloadTester::RefreshL"); |
|
102 |
|
103 iMyVideosCollectionClient->RefreshCollectionL(); |
|
104 iMessageWait->AddMessage( EVCXTestVideoListRefreshed ); |
|
105 iMessageWait->WaitForAllL( 60, ETrue ); |
|
106 |
|
107 VCXLOGLO1("<<<CVCXScheduledDownloadTester::RefreshL"); |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CVCXScheduledDownloadTester::RemoveAllMediasL |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CVCXScheduledDownloadTester::RemoveAllMediasL() |
|
115 { |
|
116 VCXLOGLO1(">>>CVCXScheduledDownloadTester::RemoveAllMediasL"); |
|
117 |
|
118 iMyVideosCollectionClient->EnsureMediaFilesAreNotInUseL(); |
|
119 |
|
120 TBool retries = 3; |
|
121 TInt err( KErrNone ); |
|
122 TBool removalFailed( EFalse ); |
|
123 |
|
124 TInt videoCount = iMyVideosCollectionClient->VideoCount(); |
|
125 TInt downloadCount = iMyVideosCollectionClient->DownloadCount(); |
|
126 |
|
127 VCXLOGLO2("CVCXScheduledDownloadTester:: videoCount: %d", videoCount ); |
|
128 VCXLOGLO2("CVCXScheduledDownloadTester:: downloadCount: %d", downloadCount ); |
|
129 |
|
130 do |
|
131 { |
|
132 TInt successCount = 0; |
|
133 |
|
134 for( TInt i = 0; i < videoCount; i++ ) |
|
135 { |
|
136 TRAP( err, RemoveVideoL( 0 ) ); |
|
137 if( err != KErrNone ) |
|
138 { |
|
139 VCXLOGLO2("CVCXScheduledDownloadTester:: removing of video left with %d", err ); |
|
140 removalFailed = ETrue; |
|
141 } |
|
142 else |
|
143 { |
|
144 successCount++; |
|
145 } |
|
146 } |
|
147 |
|
148 videoCount -= successCount; |
|
149 successCount = 0; |
|
150 |
|
151 if( err == KErrNone ) |
|
152 { |
|
153 for( TInt i = 0; i < downloadCount; i++ ) |
|
154 { |
|
155 TRAP( err, CancelDownloadL( 0 ) ); |
|
156 if( err != KErrNone ) |
|
157 { |
|
158 VCXLOGLO2("CVCXScheduledDownloadTester:: cancel download left with %d", err ); |
|
159 removalFailed = ETrue; |
|
160 } |
|
161 else |
|
162 { |
|
163 successCount++; |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 downloadCount -= successCount; |
|
169 |
|
170 // If something failed, wait minute before retry. |
|
171 if( removalFailed ) |
|
172 { |
|
173 User::After( 60 * 1000000 ); |
|
174 } |
|
175 } |
|
176 while( --retries > 0 && removalFailed ); |
|
177 |
|
178 User::LeaveIfError( err ); |
|
179 |
|
180 VCXLOGLO1("<<<CVCXScheduledDownloadTester::RemoveAllMediasL"); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CVCXScheduledDownloadTester::RemoveVideoL |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CVCXScheduledDownloadTester::RemoveVideoL( TUint aIndex ) |
|
188 { |
|
189 VCXLOGLO1(">>>CVCXScheduledDownloadTester::RemoveVideoL"); |
|
190 |
|
191 iMyVideosCollectionClient->RemoveVideoL( aIndex ); |
|
192 iMessageWait->AddMessage( EVCXTestVideoVideoDeleted ); |
|
193 iMessageWait->AddMessage( EVCXTestVideoListRefreshed ); |
|
194 iMessageWait->WaitForAllL( 60, ETrue ); |
|
195 |
|
196 iMyVideosCollectionClient->RefreshCollectionL(); |
|
197 iMessageWait->AddMessage( EVCXTestVideoListRefreshed ); |
|
198 iMessageWait->WaitForAllL( 60, ETrue ); |
|
199 |
|
200 VCXLOGLO1("<<<CVCXScheduledDownloadTester::RemoveVideoL"); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CVCXScheduledDownloadTester::DownloadL |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CVCXScheduledDownloadTester::DownloadL( const TDesC& aUrl, TUint aIapId, const TDesC& aUserName, const TDesC& aPassword ) |
|
208 { |
|
209 VCXLOGLO1(">>>CVCXScheduledDownloadTester::DownloadL"); |
|
210 |
|
211 iMessageWait->Reset(); |
|
212 iMyVideosCollectionClient->DownloadL( aUrl, aIapId, aUserName, aPassword ); |
|
213 iMessageWait->AddMessage( EVCXTestVideoDownloadStarted ); |
|
214 iMessageWait->AddMessage( EVCXTestVideoDownloadCompleted ); |
|
215 iMessageWait->WaitForAllL( 4*60, ETrue ); |
|
216 |
|
217 VCXLOGLO1("<<<CVCXScheduledDownloadTester::DownloadL"); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CVCXScheduledDownloadTester::CancelDownloadL |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CVCXScheduledDownloadTester::CancelDownloadL( TUint aIndex ) |
|
225 { |
|
226 VCXLOGLO1(">>>CVCXScheduledDownloadTester::CancelDownloadL"); |
|
227 |
|
228 iMessageWait->Reset(); |
|
229 iMyVideosCollectionClient->CancelDownloadL( aIndex ); |
|
230 |
|
231 iMessageWait->AddMessage( EVCXTestVideoVideoDeleted ); |
|
232 iMessageWait->WaitForAllL( 60, ETrue ); |
|
233 |
|
234 iMyVideosCollectionClient->RefreshCollectionL(); |
|
235 iMessageWait->AddMessage( EVCXTestVideoListRefreshed ); |
|
236 iMessageWait->WaitForAllL( 60, ETrue ); |
|
237 |
|
238 VCXLOGLO1("<<<CVCXScheduledDownloadTester::CancelDownloadL"); |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CVCXScheduledDownloadTester::WaitForVideoEventsL |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CVCXScheduledDownloadTester::WaitForVideoEventsL( TInt aTimeoutSeconds, RArray<TInt32> aEvents ) |
|
246 { |
|
247 VCXLOGLO1(">>>CVCXScheduledDownloadTester::WaitForVideoEventsL"); |
|
248 |
|
249 iMessageWait->Reset(); |
|
250 for( TInt i = 0; i < aEvents.Count(); i++ ) |
|
251 { |
|
252 VCXLOGLO2("CVCXScheduledDownloadTester:: message: %d", aEvents[i]); |
|
253 iMessageWait->AddMessage( aEvents[i] ); |
|
254 } |
|
255 iMessageWait->WaitForAllL( aTimeoutSeconds, ETrue ); |
|
256 |
|
257 VCXLOGLO1("<<<CVCXScheduledDownloadTester::WaitForVideoEventsL"); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CVCXScheduledDownloadTester::CoolDown |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CVCXScheduledDownloadTester::CoolDown() |
|
265 { |
|
266 VCXLOGLO1(">>>CVCXScheduledDownloadTester::CoolDown"); |
|
267 |
|
268 iMessageWait->CoolDownL( 30 ); |
|
269 |
|
270 VCXLOGLO1("<<<CVCXScheduledDownloadTester::CoolDown"); |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CVCXScheduledDownloadTester::VideoCount |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 TInt CVCXScheduledDownloadTester::VideoCount() |
|
278 { |
|
279 VCXLOGLO1(">>>CVCXScheduledDownloadTester::VideoCount"); |
|
280 TInt count = iMyVideosCollectionClient->VideoCount(); |
|
281 VCXLOGLO1("<<<CVCXScheduledDownloadTester::VideoCount"); |
|
282 return count; |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CVCXScheduledDownloadTester::DownloadCount |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 TInt CVCXScheduledDownloadTester::DownloadCount() |
|
290 { |
|
291 VCXLOGLO1(">>>CVCXScheduledDownloadTester::DownloadCount"); |
|
292 TInt count = iMyVideosCollectionClient->DownloadCount(); |
|
293 VCXLOGLO1("<<<CVCXScheduledDownloadTester::DownloadCount"); |
|
294 return count; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CVCXScheduledDownloadTester::RemoveAllSchedulesL |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CVCXScheduledDownloadTester::RemoveAllSchedulesL() |
|
302 { |
|
303 VCXLOGLO1(">>>CVCXScheduledDownloadTester::RemoveAllSchedulesL"); |
|
304 |
|
305 TTimeIntervalYears years( 2 ); |
|
306 |
|
307 TTime start; |
|
308 start.HomeTime(); |
|
309 start -= years; |
|
310 |
|
311 TTime end; |
|
312 end.HomeTime(); |
|
313 end += years; |
|
314 |
|
315 RPointerArray<CCseScheduledProgram> programs; |
|
316 |
|
317 iSchedulerClient->GetSchedulesByTime( start, end, programs ); |
|
318 CleanupClosePushL( programs ); |
|
319 |
|
320 for( TInt i = 0; i < programs.Count(); i++ ) |
|
321 { |
|
322 User::LeaveIfError( iSchedulerClient->RemoveSchedule( programs[i]->DbIdentifier() ) ); |
|
323 } |
|
324 |
|
325 CleanupStack::PopAndDestroy( &programs ); |
|
326 |
|
327 VCXLOGLO1("<<<CVCXScheduledDownloadTester::RemoveAllSchedulesL"); |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CVCXScheduledDownloadTester::GetLastError |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 TInt CVCXScheduledDownloadTester::GetLastError() |
|
335 { |
|
336 return iError; |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CVCXScheduledDownloadTester::VideoEventL |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 void CVCXScheduledDownloadTester::VideoEventL( TVCXTestVideoEvent aEvent, |
|
344 TUint32 aParam1, TUint32 aParam2, TInt aError ) |
|
345 { |
|
346 VCXLOGLO1(">>>CVCXScheduledDownloadTester::VideoEventL"); |
|
347 |
|
348 iMessageWait->ReceiveMessage( aEvent, aError ); |
|
349 |
|
350 switch( aEvent ) |
|
351 { |
|
352 case EVCXTestVideoGeneral: |
|
353 { |
|
354 VCXLOGLO1("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoGeneral =----->"); |
|
355 } |
|
356 break; |
|
357 |
|
358 case EVCXTestVideoListRefreshed: |
|
359 { |
|
360 VCXLOGLO1("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoListRefreshed =----->"); |
|
361 } |
|
362 break; |
|
363 |
|
364 case EVCXTestVideoVideoAdded: |
|
365 { |
|
366 VCXLOGLO2("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoVideoAdded. Id: %d =----->", aParam1); |
|
367 } |
|
368 break; |
|
369 |
|
370 case EVCXTestVideoVideoDeleted: |
|
371 { |
|
372 VCXLOGLO2("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoVideoDeleted. Id: %d =----->", aParam1); |
|
373 } |
|
374 break; |
|
375 |
|
376 case EVCXTestVideoDownloadStarted: |
|
377 { |
|
378 VCXLOGLO2("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoDownloadStarted. Id: %d =----->", aParam1); |
|
379 } |
|
380 break; |
|
381 |
|
382 case EVCXTestVideoDownloadPaused: |
|
383 { |
|
384 VCXLOGLO2("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoDownloadPaused. Id: %d =----->", aParam1); |
|
385 } |
|
386 break; |
|
387 |
|
388 case EVCXTestVideoDownloadFailed: |
|
389 { |
|
390 VCXLOGLO2("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoDownloadFailed. Id: %d =----->", aParam1); |
|
391 } |
|
392 break; |
|
393 |
|
394 case EVCXTestVideoDownloadCompleted: |
|
395 { |
|
396 VCXLOGLO2("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoDownloadCompleted. Id: %d =----->", aParam1); |
|
397 } |
|
398 break; |
|
399 |
|
400 case EVCXTestVideoDownloadProgressed: |
|
401 { |
|
402 VCXLOGLO3("CVCXScheduledDownloadTester::VideoEventL: EVCXTestVideoDownloadProgressed. Id: %d, progress: %d =----->", aParam1, aParam2); |
|
403 } |
|
404 break; |
|
405 |
|
406 default: |
|
407 break; |
|
408 } |
|
409 |
|
410 if( aError != KErrNone ) |
|
411 { |
|
412 VCXLOGLO2("CVCXScheduledDownloadTester::VideoEventL: aError: %d =----->", aError); |
|
413 iError = aError; |
|
414 } |
|
415 |
|
416 VCXLOGLO1("<<<CVCXScheduledDownloadTester::VideoEventL"); |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CVCXScheduledDownloadTester::MessageWaitComplete |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 void CVCXScheduledDownloadTester::MessageWaitComplete( TInt aError ) |
|
424 { |
|
425 if( aError == KErrTimedOut ) |
|
426 { |
|
427 VCXLOGLO1("CVCXScheduledDownloadTester:: Message wait TIMEOUT!"); |
|
428 iStifScriptBase->Signal( aError ); |
|
429 } |
|
430 } |