|
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: Tester class for abstractmediamtpdp plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32def.h> |
|
20 #include <stiftestinterface.h> |
|
21 #include <settingserverclient.h> |
|
22 #include <mtp/mtpprotocolconstants.h> |
|
23 #include <mtp/cmtptypeobjectinfo.h> |
|
24 #include <mtp/cmtptypefile.h> |
|
25 #include <mtp/cmtptypestring.h> |
|
26 #include <mtp/cmtptypearray.h> |
|
27 #include <mtp/cmtptypeobjectproplist.h> |
|
28 #include <mtp/cmtptypeobjectpropdesc.h> |
|
29 #include <bautils.h> |
|
30 #include <f32file.h> |
|
31 #include <mpxharvesterutility.h> |
|
32 #include "cabstractmediamtpdataprovidertester.h" |
|
33 #include "logging.h" |
|
34 |
|
35 #ifdef LOGGER |
|
36 #undef LOGGER |
|
37 #endif |
|
38 #define LOGGER iLog |
|
39 |
|
40 // definitions and constants for the test data |
|
41 |
|
42 const TUint32 KTestStorageId = 0x10000; |
|
43 const TInt KTestObjectsCount = 1; |
|
44 const TUint KTestDirHandle = 1; |
|
45 const TInt KTestDirDataproviderId = 0; |
|
46 const TInt KPlaylistsDirParentId = 0; |
|
47 _LIT( KTempDirPath, "C:\\mtp_testdata\\temp\\" ); |
|
48 _LIT( KTestDirPath, "C:\\mtp_testdata\\temp\\TESTDIR\\" ); |
|
49 _LIT( KPlaylistFileOrigPath, "C:\\mtp_testdata\\PLAYLIST.M3U" ); |
|
50 _LIT( KPlaylistFileTempPath, "C:\\mtp_testdata\\temp\\PLAYLIST.m3u" ); |
|
51 _LIT( KPlaylistFilePath, "C:\\mtp_testdata\\temp\\PLAYLIST.m3u" ); |
|
52 _LIT( KPlaylistsDirPath, "C:\\mtp_testdata\\temp\\Playlists\\" ); |
|
53 _LIT( KTestDirOrigPath, "C:\\mtp_testdata\\TESTDIR\\*" ); |
|
54 _LIT( KTestDirTempPath, "C:\\mtp_testdata\\temp\\TESTDIR\\" ); |
|
55 _LIT( KTestDirPhysicalStorage, "C:\\mtp_testdata\\temp\\" ); |
|
56 _LIT( KTestDirLogicalStorage, "C:\\mtp_testdata\\temp\\" ); |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // Two-phased constructor. |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 CAbstractMediaMtpDataProviderTester* CAbstractMediaMtpDataProviderTester::NewL() |
|
63 { |
|
64 CAbstractMediaMtpDataProviderTester* self = |
|
65 new ( ELeave ) CAbstractMediaMtpDataProviderTester(); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop( self ); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // C++ default constructor can NOT contain any code, that might leave. |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 CAbstractMediaMtpDataProviderTester::CAbstractMediaMtpDataProviderTester() |
|
77 : CMmMtpDataProviderTester() |
|
78 { |
|
79 // no implementation required |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // Symbian 2nd phase constructor can leave. |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 void CAbstractMediaMtpDataProviderTester::ConstructL() |
|
87 { |
|
88 TFileName logFileName; |
|
89 logFileName.Copy( KMtpDataProviderTestModuleLogFile ); |
|
90 |
|
91 iLog = CStifLogger::NewL( KMtpDataProviderTestModuleLogPath, |
|
92 logFileName, |
|
93 CStifLogger::ETxt, |
|
94 TRACE_TARGET, |
|
95 ETrue, ETrue, ETrue, EFalse, ETrue ); |
|
96 PRINTF0( ">CAbstractMediaMtpDataProviderTester::ConstructL" ); |
|
97 iActiveSchedulerWait = new ( ELeave ) CActiveSchedulerWait(); |
|
98 iFsSession.Connect(); |
|
99 iFileMan = CFileMan::NewL( iFsSession ); |
|
100 PRINTF0( "<CAbstractMediaMtpDataProviderTester::ConstructL" ); |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // Destructor. |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 CAbstractMediaMtpDataProviderTester::~CAbstractMediaMtpDataProviderTester() |
|
108 { |
|
109 PRINTF0( ">CAbstractMediaMtpDataProviderTester::~CAbstractMediaMtpDataProviderTester" ); |
|
110 delete iActiveSchedulerWait; |
|
111 delete iFileMan; |
|
112 iFsSession.Close(); |
|
113 PRINTF0( "<CAbstractMediaMtpDataProviderTester::~CAbstractMediaMtpDataProviderTester" ); |
|
114 delete iLog; |
|
115 } |
|
116 |
|
117 TInt CAbstractMediaMtpDataProviderTester::PrepareEnvironmentL() |
|
118 { |
|
119 PRINTF0( ">CAbstractMediaMtpDataProviderTester::PrepareEnvironmentL" ); |
|
120 TInt result = KErrNone; |
|
121 |
|
122 result = iFileMan->RmDir( KTempDirPath ); |
|
123 if ( result == KErrNone ) |
|
124 { |
|
125 PRINTN0( "Warning: old temp directory found, deleted" ); |
|
126 } |
|
127 result = KErrNone; |
|
128 |
|
129 // create the temp dir if it doesn't exist |
|
130 BaflUtils::EnsurePathExistsL( iFsSession, KTempDirPath ); |
|
131 |
|
132 // copy the test data to temp dir |
|
133 result = iFileMan->Copy( KPlaylistFileOrigPath, KPlaylistFileTempPath ); |
|
134 if ( result != KErrNone ) |
|
135 { |
|
136 PRINTE1( "Failed to copy playlist file, error %d", result ); |
|
137 } |
|
138 else |
|
139 { |
|
140 result = iFileMan->Copy( KTestDirOrigPath, KTestDirTempPath, |
|
141 CFileMan::EOverWrite | CFileMan::ERecurse ); |
|
142 if ( result != KErrNone ) |
|
143 { |
|
144 PRINTE1( "Failed to copy test dir, error %d", result ); |
|
145 } |
|
146 } |
|
147 |
|
148 MMPXHarvesterUtility* harvester = CMPXHarvesterFactory::NewL(); |
|
149 CleanupClosePushL( *harvester ); |
|
150 PRINTN0( "Starting to import playlist to mpx" ); |
|
151 iTestObserver->SetPendingOperation( CTestObserver::EHarvesterAddObject ); |
|
152 harvester->AddFileL(KPlaylistFilePath, iTestObserver); |
|
153 |
|
154 // waiting for asynchronous operation to complete |
|
155 result = iTestObserver->WaitForPendingOperation(); |
|
156 if ( result != KErrNone ) |
|
157 { |
|
158 PRINTE1( "Importing playlist to mpx failed with result %d", result ); |
|
159 } |
|
160 harvester->CloseTransactionL(); |
|
161 CleanupStack::PopAndDestroy( harvester ); |
|
162 PRINTF1( "<CAbstractMediaMtpDataProviderTester::PrepareEnvironmentL result = %d", result ); |
|
163 return result; |
|
164 } |
|
165 |
|
166 TInt CAbstractMediaMtpDataProviderTester::CleanEnvironmentL() |
|
167 { |
|
168 PRINTF0( ">CAbstractMediaMtpDataProviderTester::CleanEnvironmentL" ); |
|
169 TInt result = KErrNone; |
|
170 TMTPObjectMgrQueryParams queryParams ( KMTPStorageAll, KMTPFormatsAll, |
|
171 KMTPHandleNone ); |
|
172 RMTPObjectMgrQueryContext context; |
|
173 RArray<TUint> handles; |
|
174 CleanupClosePushL( handles ); |
|
175 |
|
176 PRINTN0( "Starting to delete entries from mpx" ); |
|
177 MMPXHarvesterUtility* harvester = CMPXHarvesterFactory::NewL(); |
|
178 CleanupClosePushL( *harvester ); |
|
179 |
|
180 iTestObserver->ObjectMgr().GetObjectHandlesL( queryParams, context, |
|
181 handles ); |
|
182 PRINTV1( "Handle count: %d", handles.Count() ); |
|
183 context.Close(); |
|
184 |
|
185 CMTPObjectMetaData* metadata = CMTPObjectMetaData::NewLC(); |
|
186 for ( TInt i = 0; i < handles.Count(); i++ ) |
|
187 { |
|
188 TUint handle = handles[i]; |
|
189 if ( handle != KTestDirHandle ) |
|
190 { |
|
191 iTestObserver->ObjectMgr().ObjectL( handles[i], *metadata ); |
|
192 TPtrC fileName = metadata->DesC( CMTPObjectMetaData::ESuid ); |
|
193 PRINTV1( "Handle: %d", handles[i] ); |
|
194 PRINTV1( "File name: %S", &fileName ); |
|
195 |
|
196 PRINTN0( "Starting to delete the file from mpx" ); |
|
197 iTestObserver->SetPendingOperation( CTestObserver::EHarvesterDeleteObject ); |
|
198 harvester->DeleteFileL( fileName, iTestObserver ); |
|
199 User::After( 1000000 ); |
|
200 // waiting for asynchronous operation to complete |
|
201 result = iTestObserver->WaitForPendingOperation(); |
|
202 if ( result != KErrNone ) |
|
203 { |
|
204 PRINTE1( "Warning: failed to delete from mpx, error %d", result ); |
|
205 result = KErrNone; // ignore for now, there are problems after DeleteObject |
|
206 } |
|
207 } |
|
208 } |
|
209 CleanupStack::PopAndDestroy( 3 ); // metadata, harvester, handles |
|
210 PRINTN0( "Finished deleting entries from mpx" ); |
|
211 |
|
212 if ( result == KErrNone ) |
|
213 { |
|
214 PRINTN0( "Deleting temp directory" ); |
|
215 result = iFileMan->RmDir( KTempDirPath ); |
|
216 if ( result != KErrNone ) |
|
217 { |
|
218 PRINTE1( "Warning: failed to delete temp directory, error %d", result ); |
|
219 result = KErrNone; |
|
220 } |
|
221 } |
|
222 |
|
223 PRINTF1( "<CAbstractMediaMtpDataProviderTester::CleanEnvironmentL result = %d", result ); |
|
224 return result; |
|
225 } |
|
226 |
|
227 TBool CAbstractMediaMtpDataProviderTester::ObjectEnumerationL_prepare( |
|
228 CMTPStorageMetaData* aPhysicalStorage, |
|
229 CMTPStorageMetaData* aLogicalStorage ) |
|
230 { |
|
231 PRINTF0( ">CAbstractMediaMtpDataProviderTester::ObjectEnumerationL_prepare" ); |
|
232 |
|
233 TBool result = ETrue; |
|
234 aPhysicalStorage->SetDesCL( CMTPStorageMetaData::EStorageSuid, |
|
235 KTestDirPhysicalStorage() ); |
|
236 aPhysicalStorage->SetUint( CMTPStorageMetaData::EStorageSystemType, |
|
237 CMTPStorageMetaData::ESystemTypeDefaultFileSystem ); |
|
238 |
|
239 aLogicalStorage->SetDesCL( CMTPStorageMetaData::EStorageSuid, |
|
240 KTestDirLogicalStorage() ); |
|
241 aLogicalStorage->SetUint( CMTPStorageMetaData::EStorageSystemType, |
|
242 CMTPStorageMetaData::ESystemTypeDefaultFileSystem ); |
|
243 |
|
244 // insert TESTDIR object manually |
|
245 CMTPObjectMetaData* object( CMTPObjectMetaData::NewLC( 0, |
|
246 EMTPFormatCodeAssociation, // a folder object |
|
247 KTestStorageId, KTestDirPath ) ); |
|
248 // object is in storage root |
|
249 object->SetInt( CMTPObjectMetaData::EParentId, KErrNotFound ); |
|
250 |
|
251 iTestObserver->ObjectMgr().InsertObjectL( *object ); |
|
252 CleanupStack::PopAndDestroy( object ); |
|
253 |
|
254 PRINTF1( "<CAbstractMediaMtpDataProviderTester::ObjectEnumerationL_prepare result = %d", result ); |
|
255 return result; |
|
256 } |
|
257 |
|
258 TInt CAbstractMediaMtpDataProviderTester::ObjectEnumerationL_checkresults( |
|
259 MMTPObjectMgr& aObjectManager ) |
|
260 { |
|
261 PRINTF0( ">CAbstractMediaMtpDataProviderTester::ObjectEnumerationL_checkresults" ); |
|
262 |
|
263 TInt result = KErrNone; |
|
264 |
|
265 TMTPObjectMgrQueryParams queryParams ( KMTPStorageAll, KMTPFormatsAll, |
|
266 KMTPHandleNone ); |
|
267 RMTPObjectMgrQueryContext context; |
|
268 RArray<TUint> handles; |
|
269 CleanupClosePushL( handles ); |
|
270 MMPXHarvesterUtility* harvester = CMPXHarvesterFactory::NewL(); |
|
271 CleanupClosePushL( *harvester ); |
|
272 |
|
273 aObjectManager.GetObjectHandlesL( queryParams, context, handles ); |
|
274 context.Close(); |
|
275 TInt count = handles.Count(); |
|
276 PRINTV1( "Handle count: %d", count ); |
|
277 if ( count != KTestObjectsCount ) |
|
278 { |
|
279 PRINTE2( "Wrong number of handles: %d != %d", count, KTestObjectsCount ); |
|
280 result = KErrGeneral; |
|
281 } |
|
282 |
|
283 CMTPObjectMetaData* metadata = CMTPObjectMetaData::NewLC(); |
|
284 for ( TInt i = 0; i < count; i++ ) |
|
285 { |
|
286 TUint handle = handles[i]; |
|
287 aObjectManager.ObjectL( handle, *metadata ); |
|
288 TPtrC suid = metadata->DesC( CMTPObjectMetaData::ESuid ); |
|
289 TUint formatCode = metadata->Uint( CMTPObjectMetaData::EFormatCode ); |
|
290 TUint dataproviderId = metadata->Uint( CMTPObjectMetaData::EDataProviderId ); |
|
291 TUint storageId = metadata->Uint( CMTPObjectMetaData::EStorageId ); |
|
292 TInt parentId = metadata->Int( CMTPObjectMetaData::EParentId ); |
|
293 |
|
294 PRINTN1( "Handle: %d", handle ); |
|
295 PRINTN1( "Suid: %S", &suid ); |
|
296 |
|
297 if ( dataproviderId != KTestDirDataproviderId ) |
|
298 { |
|
299 PRINTE2( "Wrong dataprovider id: %d != %d", dataproviderId, KTestDirDataproviderId ); |
|
300 result = KErrGeneral; |
|
301 } |
|
302 if ( storageId != KTestStorageId ) |
|
303 { |
|
304 PRINTE2( "Wrong storage id: %d != %d", storageId, KTestStorageId ); |
|
305 result = KErrGeneral; |
|
306 } |
|
307 switch ( handle ) |
|
308 { |
|
309 case 1: |
|
310 { |
|
311 if ( suid.Match( KTestDirPath ) != 0 ) |
|
312 { |
|
313 PRINTE2( "Wrong test dir path: %S != %S", &suid, &KTestDirPath ); |
|
314 result = KErrGeneral; |
|
315 } |
|
316 if ( formatCode != EMTPFormatCodeAssociation ) |
|
317 { |
|
318 PRINTE2( "Wrong format code: 0x%x != 0x%x", formatCode, EMTPFormatCodeAssociation ); |
|
319 result = KErrGeneral; |
|
320 } |
|
321 if ( parentId != KErrNotFound ) |
|
322 { |
|
323 PRINTE2( "Wrong parent id: %d != %d", parentId, KErrNotFound ); |
|
324 result = KErrGeneral; |
|
325 } |
|
326 break; |
|
327 } |
|
328 case 2: |
|
329 { |
|
330 if ( suid.Match( KPlaylistsDirPath ) != 0 ) |
|
331 { |
|
332 PRINTE2( "Wrong test object 1 path: %S != %S", &suid, &KPlaylistsDirPath ); |
|
333 result = KErrGeneral; |
|
334 } |
|
335 if ( formatCode != EMTPFormatCodeAssociation ) |
|
336 { |
|
337 PRINTE2( "Wrong format code: 0x%x != 0x%x", formatCode, EMTPFormatCodeAssociation ); |
|
338 result = KErrGeneral; |
|
339 } |
|
340 if ( parentId != KPlaylistsDirParentId ) |
|
341 { |
|
342 PRINTE2( "Wrong parent id: %d != %d", parentId, KPlaylistsDirParentId ); |
|
343 result = KErrGeneral; |
|
344 } |
|
345 break; |
|
346 } |
|
347 default: |
|
348 { |
|
349 PRINTE1( "Unexpected handle: %d", handle ); |
|
350 result = KErrGeneral; |
|
351 } |
|
352 } |
|
353 /* |
|
354 if ( ( result == KErrNone ) && ( handle != KTestDirHandle ) ) |
|
355 { |
|
356 PRINTN0( "Starting to harvest the file" ); |
|
357 iTestObserver->SetPendingOperation( CTestObserver::EHarvesterAddObject ); |
|
358 harvester->AddFileL( metadata->DesC( CMTPObjectMetaData::ESuid ), iTestObserver ); |
|
359 PRINTN0( "Waiting for harvesting to complete" ); |
|
360 result = iTestObserver->WaitForPendingOperation(); |
|
361 if ( result != KErrNone ) |
|
362 { |
|
363 PRINTE1( "Harvesting error: %d", result ); |
|
364 } |
|
365 } |
|
366 */ |
|
367 } |
|
368 CleanupStack::PopAndDestroy( 3 ); // handles, harvester, metadata |
|
369 PRINTF1( "<CAbstractMediaMtpDataProviderTester::ObjectEnumerationL_checkresults result = %d", result ); |
|
370 return result; |
|
371 } |
|
372 |
|
373 TInt CAbstractMediaMtpDataProviderTester::DeleteObjectL_checkresults( |
|
374 MMTPObjectMgr& aObjectManager ) |
|
375 { |
|
376 PRINTF0( ">CAbstractMediaMtpDataProviderTester::DeleteObjectL_checkresults" ); |
|
377 TInt result = KErrNone; |
|
378 // check that everything has been deleted from the file system |
|
379 if ( BaflUtils::FileExists( iFsSession, KPlaylistFilePath ) ) |
|
380 { |
|
381 PRINTE0( "Playlist file was not deleted successfully" ); |
|
382 // playlist file is not enumerated, so it cannot be deleted |
|
383 //result = KErrGeneral; |
|
384 } |
|
385 PRINTF1( ">CAbstractMediaMtpDataProviderTester::DeleteObjectL_checkresults result = %d", result ); |
|
386 return result; |
|
387 } |