Update contrib.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <test/testexecutelog.h>
23 #include "cafserver.h"
25 #include "RecognizerStep.h"
26 #include "CafApaRecognizer.h"
28 using namespace ContentAccess;
30 const TInt KCafTestMaxDataTypeLength = 255;
31 const TInt KCAFTestApparcBufferSize = 100;
34 * This step starts the CAF Apparc recognizer and checks to see that it recognizes the
39 CCAFRecognizeStep::~CCAFRecognizeStep()
43 CCAFRecognizeStep::CCAFRecognizeStep(CCAFServer& aParent)
46 SetTestStepName(KCAFRecognizeStep);
49 /* Tests whether a file opened under the caf framework reports the same size as
50 * RFile. Only works for files that are owned by the f32agent which doesn't
51 * change the content at all.
53 TVerdict CCAFRecognizeStep::doTestStepL()
55 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
56 TBool wmdrmFlag = EFalse;
57 GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag);
61 TVerdict verdict = doWmdrmTestStepL();
64 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
66 TBuf8 <KCAFTestApparcBufferSize> buf;
68 CAgentResolver *resolver;
70 // If we leave before our DoRecognize is complete, something must have gone seriously wrong
71 SetTestStepResult(EFail);
73 TBuf8 <KCafTestMaxDataTypeLength> ContainerMimeType;
74 TBuf8 <KCafTestMaxDataTypeLength> ContentMimeType;
79 TPtrC expectedContainerMime, expectedContentMime;
81 // Retrieve filename to analyse and expected results from INI file
82 GetStringFromConfig(ConfigSection(),_L("FileName"),fileName);
83 GetStringFromConfig(ConfigSection(),_L("Container"),expectedContainerMime);
84 GetStringFromConfig(ConfigSection(),_L("Content"),expectedContentMime);
85 GetBoolFromConfig(ConfigSection(),_L("Recognized"),expectedresult);
89 INFO_PRINTF4(_L("DoRecognize Test DRM file: %S, Container Mime Type: %S, Content Mime Type: %S"),&fileName, &expectedContainerMime, &expectedContentMime);
93 INFO_PRINTF2(_L("DoRecognize Test non DRM file: %S"), &fileName);
98 // Read the first KCAFTestApparcBufferSize bytes into the buffer in the same way apparc would do
99 ReadBufferL(fileName, buf);
101 // Pass the filename and buffer to CAF DoRecognize function
102 resolver = CAgentResolver::NewLC(ETrue);
104 result = resolver->DoRecognizeL(fileName, buf, ContainerMimeType, ContentMimeType);
106 CheckResultL(result, ContainerMimeType, ContentMimeType, expectedresult, expectedContainerMime, expectedContentMime);
108 CleanupStack::PopAndDestroy(resolver);
111 return TestStepResult();
114 void CCAFRecognizeStep::CheckResultL(TBool aResult, TDes8& aContainerMimeType, TDes8& aContentMimeType, TBool aExpectedResult, TDesC16& aExpectedContainerMime, TDesC16& aExpectedContentMime)
116 // start off by assuming recognition was ok, then check
117 SetTestStepResult(EPass);
119 if(aResult != aExpectedResult)
123 INFO_PRINTF1(_L("File was incorrectly recognized as DRM"));
127 INFO_PRINTF1(_L("File was incorrectly recognized as not DRM"));
129 SetTestStepResult(EFail);
133 if(!aResult) // not a drm file so we don't care about the mime types
138 // Convert TDes16 mime types read from the INI file to TPtr8's
139 HBufC8 *container = ConvertDes16toHBufC8LC(aExpectedContainerMime);
140 TPtr8 containerptr(container->Des());
142 HBufC8 *content = ConvertDes16toHBufC8LC(aExpectedContentMime);
143 TPtr8 contentptr(content->Des());
145 // Compare expected Mime Types vs mime type
146 compare = aContainerMimeType.Compare(containerptr);
149 INFO_PRINTF1(_L("Incorrect Container Mime Type recognized"));
150 SetTestStepResult(EFail);
152 compare = aContentMimeType.Compare(contentptr);
155 INFO_PRINTF1(_L("Incorrect Content Mime Type recognized"));
156 SetTestStepResult(EFail);
158 CleanupStack::PopAndDestroy(2, container);
163 * This step starts the CAF Apparc recognizer speed test
164 * Does 1000 recognitions, log file will measure the time
168 CCAFRecognizerSpeedStep::~CCAFRecognizerSpeedStep()
172 CCAFRecognizerSpeedStep::CCAFRecognizerSpeedStep(CCAFServer& aParent) : iParent(aParent)
174 SetTestStepName(KCAFRecognizerSpeedStep);
178 TVerdict CCAFRecognizerSpeedStep::doTestStepL()
180 TBuf8 <KCAFTestApparcBufferSize> buf;
182 CAgentResolver *resolver;
184 // If we leave before our DoRecognize is complete, something must have gone seriously wrong
185 SetTestStepResult(EFail);
187 TBuf8 <KCafTestMaxDataTypeLength> ContainerMimeType;
188 TBuf8 <KCafTestMaxDataTypeLength> ContentMimeType;
191 TBool expectedresult;
192 TPtrC expectedContainerMime, expectedContentMime;
194 // Retrieve filename to analyse and expected results from INI file
195 GetStringFromConfig(ConfigSection(),_L("FileName"),fileName);
196 GetStringFromConfig(ConfigSection(),_L("Container"),expectedContainerMime);
197 GetStringFromConfig(ConfigSection(),_L("Content"),expectedContentMime);
198 GetBoolFromConfig(ConfigSection(),_L("Recognized"),expectedresult);
202 INFO_PRINTF4(_L("DoRecognize Speed Test DRM file: %S, Container Mime Type: %S, Content Mime Type: %S"),&fileName, &expectedContainerMime, &expectedContentMime);
206 INFO_PRINTF2(_L("DoRecognize Speed Test non DRM file: %S"), &fileName);
211 // Read the first KCAFTestApparcBufferSize bytes into the buffer in the same way apparc would do
212 ReadBufferL(fileName, buf);
214 // Pass the filename and buffer to CAF DoRecognize function
215 resolver = CAgentResolver::NewLC(ETrue);
217 INFO_PRINTF1(_L("Entering measured mile"));
219 for(TInt Count=0; Count < 1000; Count++)
220 resolver->DoRecognizeL(fileName, buf, ContainerMimeType, ContentMimeType);
222 INFO_PRINTF1(_L("passing mile marker (1000 recognitions)"));
224 CleanupStack::PopAndDestroy(resolver);
227 SetTestStepResult(EPass);
228 return TestStepResult();
233 * This step starts the CAF Apparc recognizer and checks to see that it recognizes the
238 CCAFBufferSizeStep::~CCAFBufferSizeStep()
242 CCAFBufferSizeStep::CCAFBufferSizeStep(CCAFServer& aParent) : iParent(aParent)
244 SetTestStepName(KCAFBufferSizeStep);
248 /* Apparc uses a buffer to pass data from the start of the file into the apparc recognizer
249 * to help it determine what mime type the file is.
250 * In CAF this recognition task is actually handed over to the agents. Each one attempts to
251 * recognize the file until one is successful or until all agents have rejected the file.
252 * Each agent may have it's own preferred size for this buffer. This is configured in each
253 * agent's RSS file, under the default_data tag.
254 * CAgentResolver::PreferredBufferSize() will return the highest value returned by any agent.
256 TVerdict CCAFBufferSizeStep::doTestStepL()
258 CAgentResolver *resolver;
259 TInt expectedBufferSize;
262 SetTestStepResult(EFail);
265 // Find the expected max buffer size from the INI file
266 GetIntFromConfig(ConfigSection(),_L("size"),expectedBufferSize);
268 INFO_PRINTF2(_L("Expected buffer size: %d"), expectedBufferSize);
273 resolver = CAgentResolver::NewLC(ETrue);
275 bufferSize = resolver->PreferredBufferSize();
277 INFO_PRINTF2(_L("Caf Preferred buffer size: %d"), bufferSize);
279 if(bufferSize == expectedBufferSize)
281 SetTestStepResult(EPass);
284 CleanupStack::PopAndDestroy(resolver);
287 return TestStepResult();
292 CCAFApparcStep::~CCAFApparcStep()
296 CCAFApparcStep::CCAFApparcStep(CCAFServer& aParent) : iParent(aParent)
298 SetTestStepName(KCAFApparcStep);
303 * This step loads the apparc recognizer and gives it a test run by
304 * pretending to be apparc
307 TVerdict CCAFApparcStep::doTestStepL()
312 TDataType dataTypeNull(_L8(""));
313 TPtrC8 mimeType(KNullDesC8);
314 HBufC16 *displayMime;
315 HBufC16 *displayMime2;
318 TPtrC expectedMimeType;
319 TPtrC nullFileName(KNullDesC);
322 SetTestStepResult(EInconclusive);
326 // Retrieve filename to analyse and expected results from INI file
327 GetStringFromConfig(ConfigSection(),_L("URI"),uri);
328 GetStringFromConfig(ConfigSection(),_L("FileName"),fileName);
329 GetStringFromConfig(ConfigSection(),_L("CafMimeType"),expectedMimeType);
331 // Use the Application Architecture Server to find the Mime type
332 RApaLsSession apparcSession;
333 User::LeaveIfError(apparcSession.Connect());
334 CleanupClosePushL(apparcSession);
335 User::LeaveIfError(apparcSession.AppForDocument(fileName, uid, dataType));
338 fileHandle.Open(iParent.Fs(), uri, EFileRead);
339 User::LeaveIfError(apparcSession.AppForDocument(fileHandle, uid, dataType2));
341 // Pass in a null file name to make sure it doesn't panic
342 User::LeaveIfError(apparcSession.AppForDocument(nullFileName, uid, dataType3));
344 CleanupStack::PopAndDestroy(&apparcSession); // close
347 // check mime type of the file (fileName)
348 mimeType.Set(dataType.Des8());
349 displayMime = ConvertDes8toHBufC16LC(mimeType);
350 TPtr16 displayPtr(displayMime->Des());
351 if(displayPtr.Compare(expectedMimeType) != 0)
353 INFO_PRINTF2(_L("CAgentResolver returned a mime type of: %S"),&displayPtr);
354 INFO_PRINTF1(_L("Please make sure the configuration file RecCafMimeTypes.txt exists for RECCAF.DLL."));
355 SetTestStepResult(EFail);
358 INFO_PRINTF3(_L("File - CAgentResolver returned a mime type of: %S, matching the expected mime type of: %S"),&displayPtr, &expectedMimeType);
361 // check mime type of the file (fileHandle)
362 mimeType.Set(dataType2.Des8());
363 displayMime2 = ConvertDes8toHBufC16LC(mimeType);
364 TPtr16 displayPtr2(displayMime2->Des());
365 if(displayPtr2.Compare(expectedMimeType) != 0)
367 INFO_PRINTF2(_L("CAgentResolver returned a mime type of: %S"),&displayPtr2);
368 INFO_PRINTF1(_L("Please make sure the configuration file RecCafMimeTypes.txt exists for RECCAF.DLL."));
369 SetTestStepResult(EFail);
372 INFO_PRINTF3(_L("FileHandle - CAgentResolver returned a mime type of: %S, matching the expected mime type of: %S"),&displayPtr2, &expectedMimeType);
374 // Check the returned datatype is null, when a null filename is passed in
375 if (dataType3 == dataTypeNull)
376 INFO_PRINTF1(_L("A null datatype is returned, when a null file name is passed in"));
378 SetTestStepResult(EFail);
380 CleanupStack::PopAndDestroy(displayMime2);
381 CleanupStack::PopAndDestroy(displayMime);
385 if (TestStepResult() != EFail)
387 SetTestStepResult(EPass);
390 return TestStepResult();
394 * This test verifies that upper case Mime types can be recognized.
396 * See DEF077443: Propagated:CAF should not be performing case sensitive comparisons on MIME types
399 CCAF_DEF077443_Step::~CCAF_DEF077443_Step()
403 CCAF_DEF077443_Step::CCAF_DEF077443_Step(CCAFServer& aParent) : iParent(aParent)
405 SetTestStepName(KCAF_DEF077443_Step);
408 TVerdict CCAF_DEF077443_Step::doTestStepL()
412 TPtrC8 mimeType(KNullDesC8);
413 HBufC16 *displayMime;
414 HBufC16 *displayMime2;
415 TPtrC upperCaseFileName;
417 TPtrC expectedContentMimeType;
418 TPtrC expectedFileMimeType;
421 SetTestStepResult(EInconclusive);
425 // Retrieve filename to analyse and expected results from INI file.
426 // The CAF resolver forces mime types retrieved from agents to lower case.
427 // When recognising the file mime type and content mine type for a file the
428 // resolver passes the request to each agent. Its possible that the agent will
429 // not use lower case for the file mime type and content mime type. To be
430 // consistent the resolver should set the returned data to lower case as well.
432 // The test agent takes content mime type from the uppercasetest.drm file.
433 // For this case the content mime type is upper case (e.g. TEXT/PLAIN).
434 GetStringFromConfig(ConfigSection(),_L("FileName1"), upperCaseFileName);
435 GetStringFromConfig(ConfigSection(),_L("CafContentMimeType"), expectedContentMimeType);
437 // For a drm file with no recognised content the test agent sets the file mime type
438 // as APPLICATION/TESTAGENT.DRM.
439 // For this case the file emptytest.drm is used.
440 GetStringFromConfig(ConfigSection(),_L("FileName2"), emptyFileName);
441 GetStringFromConfig(ConfigSection(),_L("CafFileMimeType"), expectedFileMimeType);
443 // create empty DRM file
447 // remove first if exists
448 Delete(emptyFileName);
451 TInt result = file.Create(fs, emptyFileName, EFileWrite);
455 // Use the Application Architecture Server to find the Content Mime type
456 RApaLsSession apparcSession;
457 User::LeaveIfError(apparcSession.Connect());
458 CleanupClosePushL(apparcSession);
459 User::LeaveIfError(apparcSession.AppForDocument(upperCaseFileName, uid, dataType));
461 // Use the Application Architecture Server to find the File Mime type
462 User::LeaveIfError(apparcSession.AppForDocument(emptyFileName, uid, dataType2));
464 CleanupStack::PopAndDestroy(&apparcSession); // close
467 Delete(emptyFileName);
469 // check content mime type
470 mimeType.Set(dataType.Des8());
471 displayMime = ConvertDes8toHBufC16LC(mimeType);
472 TPtr16 displayPtr(displayMime->Des());
473 if(displayPtr.Compare(expectedContentMimeType) != 0)
475 INFO_PRINTF2(_L("CAgentResolver returned a content mime type of: %S"),&displayPtr);
476 INFO_PRINTF1(_L("Please make sure the configuration file RecCafMimeTypes.txt exists for RECCAF.DLL."));
477 SetTestStepResult(EFail);
480 INFO_PRINTF3(_L("Content - CAgentResolver returned a mime type of: %S, matching the expected mime type of: %S"),&displayPtr, &expectedContentMimeType);
482 // check file mime type
483 mimeType.Set(dataType2.Des8());
484 displayMime2 = ConvertDes8toHBufC16LC(mimeType);
485 TPtr16 displayPtr2(displayMime2->Des());
486 if(displayPtr2.Compare(expectedFileMimeType) != 0)
488 INFO_PRINTF2(_L("CAgentResolver returned a file mime type of: %S"),&displayPtr2);
489 INFO_PRINTF1(_L("Please make sure the configuration file RecCafMimeTypes.txt exists for RECCAF.DLL."));
490 SetTestStepResult(EFail);
493 INFO_PRINTF3(_L("File - CAgentResolver returned a mime type of: %S, matching the expected mime type of: %S"),&displayPtr2, &expectedFileMimeType);
495 CleanupStack::PopAndDestroy(displayMime2);
496 CleanupStack::PopAndDestroy(displayMime);
500 if (TestStepResult() != EFail)
502 SetTestStepResult(EPass);
505 return TestStepResult();
508 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
510 // Tests DoRecognizeL API for WMDRM content .
512 TVerdict CCAFRecognizeStep::doWmdrmTestStepL()
514 SetTestStepResult(EFail);
516 TPtrC expectedFileMimeType;
517 GetStringFromConfig(ConfigSection(),_L("filemime"), expectedFileMimeType);
519 TPtrC expectedContentMimeType;
520 GetStringFromConfig(ConfigSection(),_L("contentmime"), expectedContentMimeType);
522 TBool expectedResult;
523 GetBoolFromConfig(ConfigSection(),_L("recognized"), expectedResult);
527 HBufC8* headerData = NULL;
529 if(GetStringFromConfig(ConfigSection(),_L("header"), header))
531 headerData = ConvertDes16toHBufC8LC(header);
535 headerData = CreateWmdrmHeaderLC();
538 // Pass the WMDRM header data to CAF DoRecognize function
539 CAgentResolver* resolver = CAgentResolver::NewLC(ETrue);
541 TBuf8 <KCafTestMaxDataTypeLength> fileMimeType;
542 TBuf8 <KCafTestMaxDataTypeLength> contentMimeType;
544 TBool result = resolver->DoRecognizeL(*headerData, fileMimeType, contentMimeType);
546 CheckResultL(result, fileMimeType, contentMimeType, expectedResult, expectedFileMimeType, expectedContentMimeType);
548 CleanupStack::PopAndDestroy(2, headerData);
551 return TestStepResult();
554 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT