34
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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 |
// INCLUDE FILES
|
|
18 |
#include "VCXMyVideosTestUtils.h"
|
|
19 |
#include "VCXTestLog.h"
|
|
20 |
|
|
21 |
// CONSTANTS
|
|
22 |
|
|
23 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
24 |
|
|
25 |
// -----------------------------------------------------------------------------
|
|
26 |
// CVCXMyVideosTestUtils::NewL
|
|
27 |
// -----------------------------------------------------------------------------
|
|
28 |
//
|
|
29 |
CVCXMyVideosTestUtils* CVCXMyVideosTestUtils::NewL()
|
|
30 |
{
|
|
31 |
VCXLOGLO1(">>>CVCXMyVideosTestUtils::NewL");
|
|
32 |
CVCXMyVideosTestUtils* self = new (ELeave) CVCXMyVideosTestUtils();
|
|
33 |
CleanupStack::PushL(self);
|
|
34 |
self->ConstructL( );
|
|
35 |
CleanupStack::Pop(self);
|
|
36 |
VCXLOGLO1("<<<CVCXMyVideosTestUtils::NewL");
|
|
37 |
return self;
|
|
38 |
}
|
|
39 |
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
// CVCXMyVideosTestUtils::CVCXMyVideosTestUtils
|
|
42 |
// -----------------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
CVCXMyVideosTestUtils::CVCXMyVideosTestUtils()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
// CVCXMyVideosTestUtils::~CVCXMyVideosTestUtils
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CVCXMyVideosTestUtils::~CVCXMyVideosTestUtils( )
|
|
53 |
{
|
|
54 |
delete iFileMan;
|
|
55 |
iFileMan = NULL;
|
|
56 |
iFs.Close();
|
|
57 |
}
|
|
58 |
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
// CVCXMyVideosTestUtils::ConstructL
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
void CVCXMyVideosTestUtils::ConstructL( )
|
|
64 |
{
|
|
65 |
VCXLOGLO1(">>>CVCXMyVideosTestUtils::ConstructL");
|
|
66 |
User::LeaveIfError( iFs.Connect() );
|
|
67 |
iFileMan = CFileMan::NewL( iFs );
|
|
68 |
VCXLOGLO1("<<<CVCXMyVideosTestUtils::ConstructL");
|
|
69 |
}
|
|
70 |
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
// CVCXMyVideosTestUtils::EnsureFileIsNotInUse
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
TInt CVCXMyVideosTestUtils::EnsureFileIsNotInUse( const TPtrC& aFileName )
|
|
76 |
{
|
|
77 |
TInt error( KErrNone );
|
|
78 |
RFile file;
|
|
79 |
|
|
80 |
for(TInt retry = 0; retry < 6; retry++)
|
|
81 |
{
|
|
82 |
error = file.Open(iFs, aFileName, EFileShareExclusive);
|
|
83 |
if( error == KErrInUse )
|
|
84 |
{
|
|
85 |
User::After( 1000000 * 10 );
|
|
86 |
}
|
|
87 |
else
|
|
88 |
{
|
|
89 |
break;
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
file.Close();
|
|
94 |
VCXLOGLO2("CVCXTestCommon::EnsureFileIsNotInUse: %d", error);
|
|
95 |
return error;
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
// -----------------------------------------------------------------------------
|
41
|
100 |
// CVCXMyVideosTestUtils::CreateVideoFileL
|
34
|
101 |
// -----------------------------------------------------------------------------
|
|
102 |
//
|
41
|
103 |
void CVCXMyVideosTestUtils::CreateVideoFileL( TVcxTestVideoType aVideoType, TDesC& aFileName, TInt aSize, TBool aUniqueName )
|
34
|
104 |
{
|
|
105 |
VCXLOGLO1(">>>CVcxTestVideoCreator::CreateVideoL");
|
|
106 |
|
41
|
107 |
// Resolve source filename
|
|
108 |
TBuf<256> srcFileName;
|
34
|
109 |
|
41
|
110 |
GetVideoFile( srcFileName, aVideoType, _L("C") );
|
|
111 |
if( !BaflUtils::FileExists(iFs, srcFileName) )
|
|
112 |
{
|
|
113 |
VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
|
|
114 |
GetVideoFile( srcFileName, aVideoType, _L("E") );
|
34
|
115 |
if( !BaflUtils::FileExists(iFs, srcFileName) )
|
|
116 |
{
|
|
117 |
VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
|
41
|
118 |
VCXLOGLO2("CVcxTestVideoCreator:: test video file %S missing! PANIC.", &srcFileName);
|
|
119 |
User::Panic(_L("Video files missing!"), KErrNotFound);
|
34
|
120 |
}
|
41
|
121 |
}
|
|
122 |
|
|
123 |
BaflUtils::EnsurePathExistsL( iFs, aFileName.Left( aFileName.LocateReverse('\\') ) );
|
34
|
124 |
|
41
|
125 |
HBufC* newFileName = HBufC::NewL( 256 );
|
|
126 |
CleanupStack::PushL( newFileName );
|
|
127 |
|
|
128 |
if(!aUniqueName)
|
|
129 |
{
|
|
130 |
newFileName->Des().Copy( aFileName );
|
34
|
131 |
BaflUtils::DeleteFile( iFs, aFileName );
|
41
|
132 |
}
|
|
133 |
else
|
|
134 |
{
|
|
135 |
newFileName->Des().Copy( aFileName );
|
|
136 |
TInt dotPos = aFileName.LocateReverse('.');
|
|
137 |
int count = 0;
|
|
138 |
while( BaflUtils::FileExists( iFs, *newFileName ) )
|
|
139 |
{
|
|
140 |
newFileName->Des().Copy( aFileName.Left( aFileName.LocateReverse('\\') ) );
|
|
141 |
newFileName->Des().Copy( aFileName.Left( dotPos ) );
|
|
142 |
newFileName->Des().Append( _L("_") );
|
|
143 |
newFileName->Des().AppendNum( count++ );
|
|
144 |
newFileName->Des().Append( aFileName.Right( aFileName.Length() - dotPos ) );
|
34
|
145 |
}
|
41
|
146 |
}
|
|
147 |
|
|
148 |
VCXLOGLO2("CVcxTestVideoCreator:: aSize = %d", aSize);
|
|
149 |
|
|
150 |
TInt64 wantedSize( 0 );
|
|
151 |
|
|
152 |
// Check the size
|
|
153 |
if( aSize == KVcxTestLargeFile3GB ) {
|
|
154 |
wantedSize = 1024*1024*1024 * 3;
|
|
155 |
}
|
|
156 |
else {
|
|
157 |
wantedSize = aSize;
|
|
158 |
}
|
|
159 |
|
|
160 |
//wantedSize = wantedSize == 0 ? wantedSize -1 : wantedSize;
|
|
161 |
|
|
162 |
VCXLOGLO2("CVcxTestVideoCreator:: Wanted file size: %Ld", wantedSize);
|
34
|
163 |
|
41
|
164 |
// Read source file into memory, won't work on huge files.
|
|
165 |
RFile64 srcFile;
|
|
166 |
VCXLOGLO2("CVcxTestVideoCreator:: Opening %S", &srcFileName);
|
|
167 |
User::LeaveIfError( srcFile.Open( iFs, srcFileName, EFileRead ) );
|
|
168 |
CleanupClosePushL( srcFile );
|
|
169 |
|
|
170 |
TInt64 srcSize(0);
|
|
171 |
VCXLOGLO2("CVcxTestVideoCreator:: Getting size of %S", &srcFileName);
|
|
172 |
User::LeaveIfError( srcFile.Size( srcSize ) );
|
34
|
173 |
|
41
|
174 |
HBufC8* data = HBufC8::NewL( srcSize );
|
|
175 |
TPtr8 ptr( data->Des() );
|
|
176 |
srcFile.Read( ptr, srcSize );
|
|
177 |
CleanupStack::PopAndDestroy( &srcFile );
|
34
|
178 |
|
41
|
179 |
CleanupStack::PushL( data );
|
|
180 |
|
|
181 |
// Write new file.
|
|
182 |
RFile64 dstFile;
|
|
183 |
VCXLOGLO1("CVcxTestVideoCreator:: Replace");
|
|
184 |
User::LeaveIfError( dstFile.Replace( iFs, *newFileName, EFileWrite ) );
|
|
185 |
CleanupClosePushL(dstFile);
|
34
|
186 |
|
41
|
187 |
if( wantedSize <= srcSize )
|
|
188 |
{
|
|
189 |
if( wantedSize == -1 )
|
|
190 |
{
|
|
191 |
VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", srcSize);
|
|
192 |
User::LeaveIfError( dstFile.Write( *data, srcSize ) );
|
|
193 |
}
|
|
194 |
else
|
|
195 |
{
|
|
196 |
VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", wantedSize);
|
|
197 |
User::LeaveIfError( dstFile.Write( *data, wantedSize ) );
|
|
198 |
}
|
|
199 |
}
|
|
200 |
else
|
|
201 |
{
|
|
202 |
VCXLOGLO2("CVcxTestVideoCreator:: Writing %Ld", srcSize);
|
|
203 |
User::LeaveIfError( dstFile.Write( *data, srcSize ) );
|
34
|
204 |
|
41
|
205 |
const TInt KVcxTest200Kilos = 1024*200;
|
|
206 |
HBufC8* buff = HBufC8::NewL( KVcxTest200Kilos );
|
|
207 |
buff->Des().SetLength( KVcxTest200Kilos );
|
|
208 |
CleanupStack::PushL( buff );
|
|
209 |
TInt64 bytesToWrite = wantedSize - srcSize;
|
|
210 |
while( bytesToWrite > 0 )
|
34
|
211 |
{
|
41
|
212 |
if( bytesToWrite >= KVcxTest200Kilos )
|
34
|
213 |
{
|
41
|
214 |
bytesToWrite -= KVcxTest200Kilos;
|
|
215 |
User::LeaveIfError( dstFile.Write( *buff ) );
|
34
|
216 |
}
|
|
217 |
else
|
|
218 |
{
|
41
|
219 |
User::LeaveIfError( dstFile.Write( *buff, bytesToWrite ) );
|
|
220 |
bytesToWrite = 0;
|
34
|
221 |
}
|
|
222 |
}
|
41
|
223 |
CleanupStack::PopAndDestroy( buff );
|
|
224 |
}
|
34
|
225 |
|
41
|
226 |
CleanupStack::PopAndDestroy( &dstFile );
|
|
227 |
CleanupStack::PopAndDestroy( data );
|
|
228 |
|
|
229 |
CleanupStack::PopAndDestroy( newFileName );
|
34
|
230 |
|
41
|
231 |
VCXLOGLO1("<<<CVcxTestVideoCreator::CreateVideoL");
|
34
|
232 |
}
|
|
233 |
|
|
234 |
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
// CVCXMyVideosTestUtils::CreateVideoFilesL
|
|
237 |
// -----------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
void CVCXMyVideosTestUtils::CreateVideoFilesL( TVcxTestVideoType aVideoType, TDesC& aFileName, TInt aCount, RPointerArray<HBufC>& aFileArray )
|
|
240 |
{
|
|
241 |
VCXLOGLO1(">>>CVcxTestVideoCreator::CreateVideosL");
|
|
242 |
|
|
243 |
// Resolve source filename
|
|
244 |
TBuf<256> srcFileName;
|
|
245 |
|
|
246 |
GetVideoFile( srcFileName, aVideoType, _L("C") );
|
|
247 |
|
|
248 |
if( !BaflUtils::FileExists(iFs, srcFileName) )
|
|
249 |
{
|
|
250 |
VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
|
|
251 |
GetVideoFile( srcFileName, aVideoType, _L("E") );
|
|
252 |
if( !BaflUtils::FileExists(iFs, srcFileName) )
|
|
253 |
{
|
|
254 |
VCXLOGLO2("CVcxTestVideoCreator:: %S does not exist.", &srcFileName);
|
|
255 |
VCXLOGLO2("CVcxTestVideoCreator:: test video file %S missing! PANIC.", &srcFileName);
|
|
256 |
// Comment next line if you want dummy files to be created. They won't be recognized by MDS.
|
|
257 |
User::Panic(_L("Video files missing!"), KErrNotFound);
|
|
258 |
}
|
|
259 |
}
|
|
260 |
|
|
261 |
TBool fileExists = BaflUtils::FileExists(iFs, srcFileName);
|
|
262 |
|
|
263 |
HBufC* newFileName = HBufC::NewL( 256 );
|
|
264 |
CleanupStack::PushL( newFileName );
|
|
265 |
|
|
266 |
newFileName->Des().Copy( aFileName.Left( aFileName.LocateReverse('\\') ) );
|
|
267 |
BaflUtils::EnsurePathExistsL(iFs, *newFileName);
|
|
268 |
|
|
269 |
TInt dotPos = aFileName.LocateReverse('.');
|
|
270 |
|
|
271 |
for( TInt i = 0; i < aCount; i++ )
|
|
272 |
{
|
|
273 |
newFileName->Des().Copy( aFileName.Left( dotPos ) );
|
|
274 |
newFileName->Des().Append( _L("_") );
|
|
275 |
newFileName->Des().AppendNum( i );
|
|
276 |
newFileName->Des().Append( aFileName.Right( aFileName.Length() - dotPos ) );
|
|
277 |
|
|
278 |
HBufC* fileForClient = newFileName->Des().AllocL();
|
|
279 |
aFileArray.Append( fileForClient );
|
|
280 |
|
|
281 |
if( fileExists )
|
|
282 |
{
|
|
283 |
User::LeaveIfError( iFileMan->Copy(srcFileName, *newFileName) );
|
|
284 |
VCXLOGLO2("CVcxTestVideoCreator:: copy file: '%S'", newFileName);
|
|
285 |
}
|
|
286 |
else
|
|
287 |
{
|
|
288 |
VCXLOGLO2("CVcxTestVideoCreator:: new fake file: '%S'", newFileName);
|
|
289 |
RFile file;
|
|
290 |
CleanupClosePushL(file);
|
|
291 |
User::LeaveIfError( file.Replace(iFs, *newFileName, EFileWrite) );
|
|
292 |
User::LeaveIfError( file.SetSize( 1024*10 ) );
|
|
293 |
CleanupStack::PopAndDestroy( &file );
|
|
294 |
}
|
|
295 |
User::After( 100000 ); // Wait tenth of a second.
|
|
296 |
}
|
|
297 |
|
|
298 |
CleanupStack::PopAndDestroy( newFileName );
|
|
299 |
|
|
300 |
VCXLOGLO1("<<<CVcxTestVideoCreator::CreateVideosL");
|
|
301 |
}
|
|
302 |
|
|
303 |
// -----------------------------------------------------------------------------
|
|
304 |
// CVCXMyVideosTestUtils::GetVideoFile
|
|
305 |
// -----------------------------------------------------------------------------
|
|
306 |
//
|
|
307 |
void CVCXMyVideosTestUtils::GetVideoFile( TDes& aFileName, CVCXMyVideosTestUtils::TVcxTestVideoType aVideoType, const TDesC& aDrive )
|
|
308 |
{
|
|
309 |
VCXLOGLO1(">>>CVcxTestVideoCreator::GetVideoFile");
|
|
310 |
aFileName.Copy( aDrive );
|
|
311 |
|
|
312 |
_LIT(KVcxTestVideoBasePath, ":\\testing\\data\\");
|
|
313 |
|
|
314 |
aFileName.Append( KVcxTestVideoBasePath );
|
|
315 |
|
|
316 |
VCXLOGLO2("CVcxTestVideoCreator::GetVideoFile -- using %S", &aFileName);
|
|
317 |
|
|
318 |
switch (aVideoType)
|
|
319 |
{
|
|
320 |
case VcxTestVideo3Gp:
|
|
321 |
{
|
|
322 |
aFileName.Append( _L("video_3gp.xxx") );
|
|
323 |
}
|
|
324 |
break;
|
|
325 |
|
|
326 |
case VcxTestVideoMpeg4:
|
|
327 |
{
|
|
328 |
aFileName.Append( _L("video_mpeg4.xxx") );
|
|
329 |
}
|
|
330 |
break;
|
|
331 |
|
|
332 |
case VcxTestVideoWmv:
|
|
333 |
{
|
|
334 |
aFileName.Append( _L("video_wmv.xxx") );
|
|
335 |
}
|
|
336 |
break;
|
|
337 |
|
|
338 |
default:
|
|
339 |
User::Panic(_L("VcxMyVideosApiTest: Unknown video type!"), KErrCorrupt);
|
|
340 |
}
|
|
341 |
VCXLOGLO1("<<<CVcxTestVideoCreator::GetVideoFile");
|
|
342 |
}
|
|
343 |
|
|
344 |
// End of File
|