|
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 "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 // [INCLUDE FILES] - do not remove |
|
20 #include <e32svr.h> |
|
21 #include <StifParser.h> |
|
22 #include <StifTestEventInterface.h> |
|
23 #include <StifTestInterface.h> |
|
24 #include "HarvesterPluginTest.h" |
|
25 |
|
26 #include "mdsutils.h" |
|
27 #include "harvesterblacklist.h" |
|
28 #include "mdeobject.h" |
|
29 #include "mdeobjecthandler.h" |
|
30 |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CHarvesterPluginTest::Delete |
|
36 // Delete here all resources allocated and opened from test methods. |
|
37 // Called from destructor. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 void CHarvesterPluginTest::Delete() |
|
41 { |
|
42 |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CHarvesterPluginTest::RunMethodL |
|
47 // Run specified method. Contains also table of test mothods and their names. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 TInt CHarvesterPluginTest::RunMethodL( |
|
51 CStifItemParser& aItem ) |
|
52 { |
|
53 |
|
54 static TStifFunctionInfo const KFunctions[] = |
|
55 { |
|
56 // Copy this line for every implemented function. |
|
57 // First string is the function name used in TestScripter script file. |
|
58 // Second is the actual implementation member function. |
|
59 |
|
60 ENTRY( "BeginTestSession", CHarvesterPluginTest::BeginTestSessionL ), |
|
61 ENTRY( "EndTestSession", CHarvesterPluginTest::EndTestSession ), |
|
62 ENTRY( "LoadPlugins", CHarvesterPluginTest::LoadPluginsL ), |
|
63 ENTRY( "TestFunctions", CHarvesterPluginTest::TestFunctionsL ), |
|
64 |
|
65 }; |
|
66 |
|
67 const TInt count = sizeof( KFunctions ) / |
|
68 sizeof( TStifFunctionInfo ); |
|
69 |
|
70 return RunInternalL( KFunctions, count, aItem ); |
|
71 |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CHarvesterPluginTest::HandleSessionOpened |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CHarvesterPluginTest::HandleSessionOpened( CMdESession& /*aClient*/, TInt aError ) |
|
79 { |
|
80 _LIT( KMsg, "CallBck HandleSessionOpened - Error code : %d" ); |
|
81 TBuf <100> msg; |
|
82 msg.Format(KMsg, aError); |
|
83 iLog->Log( msg ); |
|
84 RDebug::Print(msg); |
|
85 |
|
86 TRAP_IGNORE( iMdeObjectHandler = CMdeObjectHandler::NewL( *iMdeSession ) ); |
|
87 |
|
88 // session event |
|
89 TEventIf event( TEventIf::ESetEvent, _L("Session") ); |
|
90 TestModuleIf().Event( event ); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CHarvesterPluginTest::HandleSessionError |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CHarvesterPluginTest::HandleSessionError( CMdESession& /*aClient*/, TInt aError ) |
|
98 { |
|
99 _LIT( KMsg, "CallBck HandleSessionError - Error code : %d" ); |
|
100 TBuf <100> msg; |
|
101 msg.Format(KMsg, aError); |
|
102 iLog->Log( msg ); |
|
103 RDebug::Print(msg); |
|
104 |
|
105 // session event |
|
106 TEventIf event( TEventIf::ESetEvent, _L("Session") ); |
|
107 TestModuleIf().Event( event ); |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CHarvesterPluginTest::HarvestingCompleted |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CHarvesterPluginTest::HarvestingCompleted( CHarvesterData* /* aHarvesterData */ ) |
|
115 { |
|
116 // harvest event |
|
117 TEventIf event( TEventIf::ESetEvent, _L("Harvest") ); |
|
118 TestModuleIf().Event( event ); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CHarvesterPluginTest::BeginTestSessionL |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CHarvesterPluginTest::BeginTestSessionL( CStifItemParser& /* aItem */ ) |
|
126 { |
|
127 TRAPD( error, iMdeSession = CMdESession::NewL( *this ) ); |
|
128 |
|
129 iSession = CMdEHarvesterSession::NewL( *iMdeSession ); |
|
130 |
|
131 iCtxEngine = NULL; |
|
132 |
|
133 iBlacklist = CHarvesterBlacklist::NewL(); |
|
134 |
|
135 _LIT( KMsg, "Exit BeginTestSession - Error code : %d" ); |
|
136 TBuf <100> msg; |
|
137 msg.Format(KMsg, error); |
|
138 iLog->Log( msg ); |
|
139 RDebug::Print( msg ); |
|
140 |
|
141 User::LeaveIfError( error ); |
|
142 |
|
143 return KErrNone; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CHarvesterPluginTest::EndTestSession |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CHarvesterPluginTest::EndTestSession( CStifItemParser& /* aItem */ ) |
|
151 { |
|
152 iPluginInfoArray.ResetAndDestroy(); |
|
153 iPluginInfoArray.Close(); |
|
154 |
|
155 REComSession::FinalClose(); |
|
156 |
|
157 if ( iCtxEngine ) |
|
158 { |
|
159 iCtxEngine->ReleaseInstance(); |
|
160 iCtxEngine = NULL; |
|
161 } |
|
162 |
|
163 if ( iBlacklist ) |
|
164 { |
|
165 iBlacklist->CloseDatabase(); |
|
166 delete iBlacklist; |
|
167 } |
|
168 |
|
169 if ( iSession ) |
|
170 { |
|
171 delete iSession; |
|
172 iSession = NULL; |
|
173 } |
|
174 |
|
175 if ( iMdeObjectHandler ) |
|
176 { |
|
177 delete iMdeObjectHandler; |
|
178 iMdeObjectHandler = NULL; |
|
179 } |
|
180 |
|
181 if( iMdeSession ) |
|
182 { |
|
183 delete iMdeSession; |
|
184 iMdeSession = NULL; |
|
185 } |
|
186 |
|
187 _LIT( KMsg, "Exit EndTestSession" ); |
|
188 iLog->Log( KMsg ); |
|
189 RDebug::Print(KMsg); |
|
190 |
|
191 return KErrNone; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CHarvesterPluginTest::LoadPluginsL |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CHarvesterPluginTest::LoadPluginsL( CStifItemParser& /* aItem */ ) |
|
199 { |
|
200 _LIT( KMsg1, "Enter LoadPlugins" ); |
|
201 iLog->Log( KMsg1 ); |
|
202 RDebug::Print( KMsg1 ); |
|
203 |
|
204 RImplInfoPtrArray infoArray; |
|
205 |
|
206 TCleanupItem cleanupItem( MdsUtils::CleanupEComArray, &infoArray ); |
|
207 CleanupStack::PushL( cleanupItem ); |
|
208 |
|
209 CHarvesterPlugin::ListImplementationsL( infoArray ); |
|
210 TInt count( 0 ); |
|
211 count = infoArray.Count(); |
|
212 |
|
213 if( count == 0 ) |
|
214 { |
|
215 return KErrNotFound; |
|
216 } |
|
217 |
|
218 for ( TInt i=0; i < count; i++ ) |
|
219 { |
|
220 // Parse the file extensions and resolve plug-in's uids from infoArray to iDataTypeArray |
|
221 TBufC8<256> type; |
|
222 TBufC8<256> opaque; |
|
223 |
|
224 type = infoArray[i]->DataType(); |
|
225 opaque = infoArray[i]->OpaqueData(); |
|
226 TUid implUID = infoArray[i]->ImplementationUid(); |
|
227 |
|
228 AddNewPluginL(type, opaque, implUID); |
|
229 } |
|
230 |
|
231 CleanupStack::PopAndDestroy( &infoArray ); // infoArray, results in a call to CleanupEComArray |
|
232 |
|
233 _LIT( KMsg2, "Exit LoadPlugins" ); |
|
234 iLog->Log( KMsg2 ); |
|
235 RDebug::Print( KMsg2 ); |
|
236 |
|
237 return KErrNone; |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CHarvesterPluginTest::TestFunctionsL |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 TInt CHarvesterPluginTest::TestFunctionsL( CStifItemParser& aItem ) |
|
245 { |
|
246 _LIT( KMsg1, "Enter TestFunctions" ); |
|
247 iLog->Log( KMsg1 ); |
|
248 RDebug::Print( KMsg1 ); |
|
249 |
|
250 TPtrC inputFile; |
|
251 User::LeaveIfError( aItem.GetNextString( inputFile ) ); |
|
252 |
|
253 iMdeSession->RemoveObjectL( inputFile ); |
|
254 |
|
255 TBuf<100> aObjectDef; |
|
256 |
|
257 _LIT( KMsg2_1, "enter GetObjectDef" ); |
|
258 iLog->Log( KMsg2_1 ); |
|
259 RDebug::Print( KMsg2_1 ); |
|
260 |
|
261 GetObjectDef( inputFile, aObjectDef, EFalse ); |
|
262 |
|
263 _LIT( KMsg2_2, "return from GetObjectDef" ); |
|
264 iLog->Log( KMsg2_2 ); |
|
265 RDebug::Print( KMsg2_2 ); |
|
266 |
|
267 // harvesterdata object |
|
268 HBufC* uriBuf = inputFile.AllocLC(); |
|
269 |
|
270 _LIT( KMsg3, "Creating harvester data" ); |
|
271 iLog->Log( KMsg3 ); |
|
272 RDebug::Print( KMsg3 ); |
|
273 |
|
274 CHarvesterData* data = CHarvesterData::NewL( uriBuf ); |
|
275 data->SetPluginObserver( *this ); |
|
276 CMdEObject* mdeObject = NULL; |
|
277 _LIT( string, "Image" ); |
|
278 |
|
279 _LIT( KMsg4, "Getting metadata object" ); |
|
280 iLog->Log( KMsg4 ); |
|
281 RDebug::Print( KMsg4 ); |
|
282 |
|
283 mdeObject = iMdeObjectHandler->GetMetadataObjectL( *data, string ); |
|
284 |
|
285 _LIT( KMsg5, "Setting metadata object" ); |
|
286 iLog->Log( KMsg5 ); |
|
287 RDebug::Print( KMsg5 ); |
|
288 |
|
289 data->SetMdeObject( mdeObject ); |
|
290 |
|
291 _LIT( KMsg6, "Metadata object set" ); |
|
292 iLog->Log( KMsg6 ); |
|
293 RDebug::Print( KMsg6 ); |
|
294 |
|
295 CleanupStack::Pop( uriBuf ); |
|
296 |
|
297 _LIT( KMsg7, "Calling HarvestL" ); |
|
298 iLog->Log( KMsg7 ); |
|
299 RDebug::Print( KMsg7 ); |
|
300 |
|
301 HarvestL( data ); |
|
302 |
|
303 _LIT( KMsg8, "Exit TestFunctions" ); |
|
304 iLog->Log( KMsg8 ); |
|
305 RDebug::Print( KMsg8 ); |
|
306 |
|
307 return KErrNone; |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // GetObjectDef |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 TBool CHarvesterPluginTest::GetObjectDef(const TDesC& aUri, TDes& aObjectDef, TBool aCheck) |
|
315 { |
|
316 _LIT( KMsg1, "GetObjectDef" ); |
|
317 iLog->Log( KMsg1 ); |
|
318 RDebug::Print( KMsg1 ); |
|
319 |
|
320 CHarvesterPluginInfo* hpi = NULL; |
|
321 |
|
322 TRAPD( err, hpi = GetHPIFromFileNameL(aUri) ); |
|
323 if ( err != KErrNone ) |
|
324 { |
|
325 _LIT( KMsg2, "GetHPIFromFileNameL not KErrNone, objectDef is 0, return" ); |
|
326 iLog->Log( KMsg2 ); |
|
327 RDebug::Print( KMsg2 ); |
|
328 |
|
329 aObjectDef.Zero(); |
|
330 return EFalse; |
|
331 } |
|
332 |
|
333 if ( !hpi ) |
|
334 { |
|
335 _LIT( KMsg3, "no hpi, objectDef is 0, return" ); |
|
336 iLog->Log( KMsg3 ); |
|
337 RDebug::Print( KMsg3 ); |
|
338 aObjectDef.Zero(); |
|
339 } |
|
340 else |
|
341 { |
|
342 _LIT( KMsg4, "hpi found" ); |
|
343 iLog->Log( KMsg4 ); |
|
344 RDebug::Print( KMsg4 ); |
|
345 |
|
346 if( hpi->iObjectTypes.Count() > 1) |
|
347 { |
|
348 _LIT( KMsg5_1, "plugin supports over 1 object type" ); |
|
349 iLog->Log( KMsg5_1 ); |
|
350 RDebug::Print( KMsg5_1 ); |
|
351 |
|
352 if( aCheck ) |
|
353 { |
|
354 aObjectDef.Zero(); |
|
355 return ETrue; |
|
356 } |
|
357 |
|
358 if ( ! hpi->iPlugin ) |
|
359 { |
|
360 TRAPD( error, hpi->iPlugin = CHarvesterPlugin::NewL( hpi->iPluginUid ) ); |
|
361 if( error ) |
|
362 { |
|
363 aObjectDef.Zero(); |
|
364 return EFalse; |
|
365 } |
|
366 else |
|
367 { |
|
368 hpi->iPlugin->SetQueue( hpi->iQueue ); |
|
369 } |
|
370 } |
|
371 |
|
372 _LIT( KMsg5_2, "calling iPlugin->GetObjectType" ); |
|
373 iLog->Log( KMsg5_2 ); |
|
374 RDebug::Print( KMsg5_2 ); |
|
375 |
|
376 hpi->iPlugin->GetObjectType( aUri, aObjectDef ); |
|
377 |
|
378 _LIT( KMsg5_3, "object type selected" ); |
|
379 iLog->Log( KMsg5_3 ); |
|
380 RDebug::Print( KMsg5_3 ); |
|
381 } |
|
382 else |
|
383 { |
|
384 _LIT( KMsg6_1, "plugin supports 1 object type, select it" ); |
|
385 iLog->Log( KMsg6_1 ); |
|
386 RDebug::Print( KMsg6_1 ); |
|
387 |
|
388 aObjectDef.Copy( *(hpi->iObjectTypes[0]) ); |
|
389 _LIT( KMsg6_2, "object type selected" ); |
|
390 iLog->Log( KMsg6_2 ); |
|
391 RDebug::Print( KMsg6_2 ); |
|
392 } |
|
393 } |
|
394 |
|
395 return EFalse; |
|
396 } |
|
397 |
|
398 // --------------------------------------------------------------------------- |
|
399 // HarvestL |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 TInt CHarvesterPluginTest::HarvestL( CHarvesterData* aHD ) |
|
403 { |
|
404 _LIT( KMsg1, "Enter HarvestL" ); |
|
405 iLog->Log( KMsg1 ); |
|
406 RDebug::Print( KMsg1 ); |
|
407 |
|
408 CHarvesterPluginInfo* hpi = aHD->HarvesterPluginInfo(); |
|
409 |
|
410 if ( !hpi ) |
|
411 { |
|
412 hpi = GetHPIFromFileNameL( aHD->Uri() ); |
|
413 } |
|
414 |
|
415 if ( hpi ) |
|
416 { |
|
417 if ( ! hpi->iPlugin ) |
|
418 { |
|
419 hpi->iPlugin = CHarvesterPlugin::NewL( hpi->iPluginUid ); |
|
420 hpi->iPlugin->SetQueue( hpi->iQueue ); |
|
421 hpi->iPlugin->SetBlacklist( *iBlacklist ); |
|
422 } |
|
423 |
|
424 if( aHD->ObjectType() == EFastHarvest || aHD->Origin() == MdeConstants::Object::ECamera ) |
|
425 { |
|
426 hpi->iQueue.Insert( aHD, 0 ); |
|
427 } |
|
428 else |
|
429 { |
|
430 hpi->iQueue.AppendL( aHD ); |
|
431 } |
|
432 |
|
433 hpi->iPlugin->StartHarvest(); |
|
434 |
|
435 _LIT( KMsg2, "Exit HarvestL" ); |
|
436 iLog->Log( KMsg2 ); |
|
437 RDebug::Print( KMsg2 ); |
|
438 |
|
439 return KErrNone; |
|
440 } |
|
441 |
|
442 return KErrNotFound; |
|
443 } |
|
444 |
|
445 // ----------------------------------------------------------------------------- |
|
446 // AddNewPluginL |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 void CHarvesterPluginTest::AddNewPluginL( const TDesC8& aType, const TDesC8& aOpaque, TUid aPluginUid ) |
|
450 { |
|
451 CHarvesterPluginInfo* pluginInfo = new (ELeave) CHarvesterPluginInfo; |
|
452 CleanupStack::PushL( pluginInfo ); |
|
453 |
|
454 // get file extensions |
|
455 TLex8 lex( aOpaque ); |
|
456 while ( !lex.Eos() ) |
|
457 { |
|
458 /* Tokenizing file extensions using TLex8 */ |
|
459 lex.SkipSpaceAndMark(); |
|
460 |
|
461 TPtrC8 extToken = lex.NextToken(); |
|
462 |
|
463 HBufC* str = HBufC::NewLC( extToken.Length() ); |
|
464 str->Des().Copy( extToken ); |
|
465 pluginInfo->iExtensions.AppendL( str ); |
|
466 CleanupStack::Pop( str ); |
|
467 } |
|
468 |
|
469 // get object types |
|
470 TLex8 lexObjectTypes( aType ); |
|
471 while ( !lexObjectTypes.Eos() ) |
|
472 { |
|
473 /* Tokenizing object types using TLex8 */ |
|
474 lexObjectTypes.SkipSpaceAndMark(); |
|
475 |
|
476 TPtrC8 objectTypeToken = lexObjectTypes.NextToken(); |
|
477 |
|
478 HBufC* str = HBufC::NewLC( objectTypeToken.Length() ); |
|
479 str->Des().Copy( objectTypeToken ); |
|
480 pluginInfo->iObjectTypes.AppendL( str ); |
|
481 CleanupStack::Pop( str ); |
|
482 } |
|
483 |
|
484 /* We set plugin as NULL - we only load them when needed */ |
|
485 pluginInfo->iPlugin = NULL; |
|
486 pluginInfo->iPluginUid = aPluginUid; |
|
487 iPluginInfoArray.AppendL( pluginInfo ); |
|
488 CleanupStack::Pop( pluginInfo ); |
|
489 } |
|
490 |
|
491 // --------------------------------------------------------------------------- |
|
492 // GetHPIFromFileNameL |
|
493 // --------------------------------------------------------------------------- |
|
494 // |
|
495 CHarvesterPluginInfo* CHarvesterPluginTest::GetHPIFromFileNameL(const TDesC& aFileName) |
|
496 { |
|
497 _LIT( KMsg1, "Enter GetHPIFromFileNameL" ); |
|
498 iLog->Log( KMsg1 ); |
|
499 RDebug::Print( KMsg1 ); |
|
500 |
|
501 TParsePtrC parser( aFileName ); |
|
502 |
|
503 // without trailing dot "." |
|
504 TPtrC ptr = parser.Ext(); |
|
505 if ( ptr.Length() > 1 ) |
|
506 { |
|
507 ptr.Set( ptr.Mid( 1 ) ); |
|
508 } |
|
509 |
|
510 _LIT( KMsg2, "Exit GetHPIFromFileNameL" ); |
|
511 iLog->Log( KMsg2 ); |
|
512 RDebug::Print( KMsg2 ); |
|
513 |
|
514 return GetFromNormalFileL( ptr ); |
|
515 } |
|
516 |
|
517 // --------------------------------------------------------------------------- |
|
518 // GetFromNormalFile |
|
519 // --------------------------------------------------------------------------- |
|
520 // |
|
521 CHarvesterPluginInfo* CHarvesterPluginTest::GetFromNormalFileL( TDesC& aExt ) |
|
522 { |
|
523 _LIT( KMsg1, "Enter GetFromNormalFileL" ); |
|
524 iLog->Log( KMsg1 ); |
|
525 RDebug::Print( KMsg1 ); |
|
526 |
|
527 CHarvesterPluginInfo* retVal = NULL; |
|
528 |
|
529 for ( TInt i = iPluginInfoArray.Count(); --i >= 0; ) |
|
530 { |
|
531 CHarvesterPluginInfo* info = iPluginInfoArray[i]; |
|
532 TBool found = EFalse; |
|
533 |
|
534 for ( TInt k = info->iExtensions.Count(); --k >= 0; ) |
|
535 { |
|
536 TDesC* ext = info->iExtensions[k]; |
|
537 |
|
538 // checking against supported plugin file extensions |
|
539 TInt result = ext->CompareF( aExt ); |
|
540 if ( result == 0 ) |
|
541 { |
|
542 retVal = info; |
|
543 found = ETrue; |
|
544 break; |
|
545 } |
|
546 } |
|
547 if ( found ) |
|
548 { |
|
549 break; |
|
550 } |
|
551 } |
|
552 |
|
553 _LIT( KMsg2, "Exit GetFromNormalFileL" ); |
|
554 iLog->Log( KMsg2 ); |
|
555 RDebug::Print( KMsg2 ); |
|
556 |
|
557 return retVal; |
|
558 } |
|
559 |
|
560 // [End of File] - Do not remove |