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.
19 #include <test/testexecutelog.h>
21 #include "cafserver.h"
22 #include "SupplierStep.h"
24 #include "cafmimeheader.h"
26 #include "metadataarray.h"
27 #include "supplieroutputfile.h"
28 #include "attribute.h"
32 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY
34 #include <http/rhttpsession.h>
35 #include <http/rhttptransaction.h>
36 #include <http/rhttpheaders.h>
39 using namespace ContentAccess;
43 * This step imports a DCF file into CAF
46 CCafSupplierStep::~CCafSupplierStep()
50 CCafSupplierStep::CCafSupplierStep(CCAFServer& aParent) : iParent(aParent)
52 SetTestStepName(KCAFSupplierStep);
56 TVerdict CCafSupplierStep::doTestStepL()
58 SetTestStepResult(EInconclusive);
62 TBuf8 <128> readBuffer;
64 INFO_PRINTF1(_L("Supplier Test - Agent provides output files"));
66 TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType;
69 // Get parameters from INI file
70 GetStringFromConfig(ConfigSection(),_L("OutputPath"),outputDirectory);
71 GetStringFromConfig(ConfigSection(),_L("SourceFileName"),sourceFileName);
72 GetStringFromConfig(ConfigSection(),_L("SuggestedFileName"),suggestedFileName);
73 GetStringFromConfig(ConfigSection(),_L("MimeType"),mimeType);
74 GetIntFromConfig(ConfigSection(),_L("LeaveResult"),expectedLeave);
80 HBufC8 *mime = ConvertDes16toHBufC8LC(mimeType);
82 CCafMimeHeader *header = CCafMimeHeader::NewL(mime->Des());
83 CleanupStack::PushL(header);
85 CSupplier *mySupplier = CSupplier::NewLC();
86 mySupplier->SetOutputDirectoryL(outputDirectory);
88 // ignore return value, just exercises code for CCover
89 mySupplier->IsImportSupported(header->StandardMimeData(EContentType));
91 CImportFile *import = NULL;
92 TRAPD(leaveResult, import = mySupplier->ImportFileL(*header, suggestedFileName));
93 if(leaveResult != expectedLeave)
95 SetTestStepResult(EFail);
97 if(leaveResult == KErrNone)
99 CleanupStack::PushL(import);
101 // read the input file and pass it to the CAF
103 CleanupClosePushL(fs);
105 TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny);
106 CleanupClosePushL(file);
107 while(result == KErrNone)
109 result = file.Read(readBuffer);
110 if(readBuffer.Length() == 0)
112 User::LeaveIfError(import->WriteData(readBuffer));
114 CleanupStack::PopAndDestroy(&file);
115 User::LeaveIfError(import->WriteDataComplete());
117 TInt n = import->OutputFileCountL();
118 for(TInt i = 0; i < n; i++)
120 // get output file name
121 TPtrC OutputFileName = import->OutputFileL(i).FileName();
122 INFO_PRINTF2(_L("Output File Created: %S"),&OutputFileName);
124 // get output file type (content or receipt)
125 TOutputType outputType = import->OutputFileL(i).OutputType();
127 if(outputType == EReceipt)
129 INFO_PRINTF1(_L("Output File is a receipt"));
133 INFO_PRINTF1(_L("Output File is content"));
136 // get output file mime type
137 TPtrC8 OutputMimeType = import->OutputFileL(i).MimeTypeL();
138 HBufC *mime = ConvertDes8toHBufC16LC(OutputMimeType );
139 INFO_PRINTF2(_L("Output File Mime Type: %S"),mime);
140 CleanupStack::PopAndDestroy(mime);
142 CleanupStack::PopAndDestroy(&fs);
143 CleanupStack::PopAndDestroy(import);
145 CleanupStack::PopAndDestroy(mySupplier);
146 CleanupStack::PopAndDestroy(header);
147 CleanupStack::PopAndDestroy(mime);
150 if (TestStepResult() != EFail)
152 SetTestStepResult(EPass);
155 return TestStepResult();
161 * This step imports a DCF file into CAF
164 CCafSupplierAsyncStep::~CCafSupplierAsyncStep()
168 CCafSupplierAsyncStep::CCafSupplierAsyncStep(CCAFServer& aParent) : iParent(aParent)
170 SetTestStepName(KCAFSupplierAsyncStep);
174 TVerdict CCafSupplierAsyncStep::doTestStepL()
176 SetTestStepResult(EInconclusive);
180 TBuf8 <128> readBuffer;
181 TRequestStatus status;
183 INFO_PRINTF1(_L("Asynchronous Supplier Test - Agent provides output files"));
185 TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType;
188 // Get parameters from INI file
189 GetStringFromConfig(ConfigSection(),_L("OutputPath"),outputDirectory);
190 GetStringFromConfig(ConfigSection(),_L("SourceFileName"),sourceFileName);
191 GetStringFromConfig(ConfigSection(),_L("SuggestedFileName"),suggestedFileName);
192 GetStringFromConfig(ConfigSection(),_L("MimeType"),mimeType);
193 GetIntFromConfig(ConfigSection(),_L("LeaveResult"),expectedLeave);
195 StartApparcServerL();
200 HBufC8 *mime = ConvertDes16toHBufC8LC(mimeType);
202 CCafMimeHeader *header = CCafMimeHeader::NewL(mime->Des());
203 CleanupStack::PushL(header);
205 CSupplier *mySupplier = CSupplier::NewLC();
206 mySupplier->SetOutputDirectoryL(outputDirectory);
208 // ignore return value, just exercises code for CCover
209 mySupplier->IsImportSupported(header->StandardMimeData(EContentType));
211 CImportFile *import = NULL;
212 TRAPD(leaveResult, import = mySupplier->ImportFileL(*header, suggestedFileName));
213 if(leaveResult != expectedLeave)
215 SetTestStepResult(EFail);
217 if(leaveResult == KErrNone)
219 CleanupStack::PushL(import);
221 // read the input file and pass it to the CAF
223 CleanupClosePushL(fs);
225 TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny);
226 CleanupClosePushL(file);
227 while(result == KErrNone)
229 result = file.Read(readBuffer);
230 if(readBuffer.Length() == 0)
232 status = KRequestPending;
233 import->WriteData(readBuffer,status);
234 User::WaitForRequest(status);
236 CleanupStack::PopAndDestroy(&file);
237 status = KRequestPending;
238 import->WriteDataComplete(status);
239 User::WaitForRequest(status);
241 TInt n = import->OutputFileCountL();
242 for(TInt i = 0; i < n; i++)
244 // get output file name
245 TPtrC OutputFileName = import->OutputFileL(i).FileName();
246 INFO_PRINTF2(_L("Output File Created: %S"),&OutputFileName);
248 // get output file type (content or receipt)
249 TOutputType outputType = import->OutputFileL(i).OutputType();
251 if(outputType == EReceipt)
253 INFO_PRINTF1(_L("Output File is a receipt"));
257 INFO_PRINTF1(_L("Output File is content"));
260 // get output file mime type
261 TPtrC8 OutputMimeType = import->OutputFileL(i).MimeTypeL();
262 HBufC *mime = ConvertDes8toHBufC16LC(OutputMimeType );
263 INFO_PRINTF2(_L("Output File Mime Type: %S"),mime);
264 CleanupStack::PopAndDestroy(mime);
267 CleanupStack::PopAndDestroy(&fs);
268 CleanupStack::PopAndDestroy(import);
270 CleanupStack::PopAndDestroy(mySupplier);
271 CleanupStack::PopAndDestroy(header);
272 CleanupStack::PopAndDestroy(mime);
275 if (TestStepResult() != EFail)
277 SetTestStepResult(EPass);
280 return TestStepResult();
286 * This step imports a DCF file into CAF
289 CCafClientOutputSupplierStep::~CCafClientOutputSupplierStep()
293 CCafClientOutputSupplierStep::CCafClientOutputSupplierStep(CCAFServer& aParent) : iParent(aParent)
295 SetTestStepName(KCAFClientOutputSupplierStep);
298 void CCafClientOutputSupplierStep::CheckContentMimeL(CImportFile* aImport, TDes8& aContentMime, TDesC8& aExpectedContentMime)
300 if(!aImport->ContentMimeTypeL(aContentMime))
302 //Agent can't determine the content MIME type with available data at the moment
304 INFO_PRINTF1(_L("Content MIME Type can't be determined"));
305 SetTestStepResult(EFail);
310 //If we reach here, we are expecting a correct Content MIME type
311 HBufC *mime = ConvertDes8toHBufC16LC(aContentMime);
312 INFO_PRINTF2(_L("Content MIME Type: %S"), mime);
313 CleanupStack::PopAndDestroy(mime);
315 if(aContentMime.CompareF(aExpectedContentMime) == 0)
317 SetTestStepResult(EPass);
321 ERR_PRINTF1(_L("Content MIME Type doesn't match expected"));
322 SetTestStepResult(EFail);
328 TVerdict CCafClientOutputSupplierStep::doTestStepL()
330 SetTestStepResult(EInconclusive);
334 TBuf8 <128> readBuffer;
335 TBuf8 <255> mimetype8;
336 TFileName outputFileName;
338 CImportFile *import = NULL;
340 // first output file will be a.txt
341 _LIT(KOutputFileName, "C:\\something.drm");
342 outputFileName.Copy(KOutputFileName);
344 INFO_PRINTF1(_L("Supplier Test - Client provides output files"));
346 TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType, expectedContentMime;
348 TBool checkContentMime = EFalse;
349 TBuf8<KMaxDataTypeLength> contentMimeType;
351 // Get parameters from INI file
352 GetStringFromConfig(ConfigSection(),_L("OutputPath"),outputDirectory);
353 GetStringFromConfig(ConfigSection(),_L("SourceFileName"),sourceFileName);
354 GetStringFromConfig(ConfigSection(),_L("SuggestedFileName"),suggestedFileName);
355 GetStringFromConfig(ConfigSection(),_L("MimeType"),mimeType);
356 GetIntFromConfig(ConfigSection(),_L("LeaveResult"),expectedLeave);
357 GetStringFromConfig(ConfigSection(),_L("ExpectedContentMime"),expectedContentMime);
358 GetBoolFromConfig(ConfigSection(),_L("CheckContentMime"),checkContentMime);
361 StartApparcServerL();
365 mimetype8.Copy(mimeType);
367 // fill in meta data - just the mime type really
368 CMetaDataArray *array = CMetaDataArray::NewL();
369 CleanupStack::PushL(array);
370 _LIT8(KContentType,"content-type");
371 array->AddL(KContentType(), mimetype8);
373 // create a supplier session
374 CSupplier *mySupplier = CSupplier::NewL();
375 CleanupStack::PushL(mySupplier);
377 // check import is supported, ignore return value, just exercises code for CCover
378 mySupplier->IsImportSupported(array->SearchL(KContentType()));
380 // create import session
381 TRAPD(leaveResult, import = mySupplier->ImportFileL(mimetype8, *array));
382 if(leaveResult != expectedLeave)
384 SetTestStepResult(EFail);
386 if(leaveResult == KErrNone)
388 CleanupStack::PushL(import);
390 // read the input file and pass it to the CAF
392 CleanupClosePushL(fs);
393 TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny);
394 CleanupClosePushL(file);
396 TParsePtrC parse(suggestedFileName);
397 TPtrC desiredOutFileName( parse.Name() );
399 while(result == KErrNone)
401 result = file.Read(readBuffer);
402 if(readBuffer.Length() == 0)
404 result = import->WriteData(readBuffer);
405 while(result == KErrCANewFileHandleRequired)
411 //If CheckContentMimeL failed, Client code should assume content MIME type wouldn't
412 //be available until after the supply session has finished. The imported data could be
413 //output to default location
414 //In this test step, data are always output to default location regardless of content MIME
416 TBuf8<KMaxDataTypeLength> expectedContentMime8bit;
417 expectedContentMime8bit.Copy(expectedContentMime);
418 CheckContentMimeL(import, contentMimeType, expectedContentMime8bit);
419 //no more check needed in following iterations
420 checkContentMime = EFalse;
422 //At this point client should decide where to save the file based on content mime
426 const TInt KMaxExtLen = 28;
427 TBuf<KMaxExtLen> suggestedExt;
428 User::LeaveIfError(import->GetSuggestedOutputFileExtension(suggestedExt));
429 outputFileName.Copy(outputDirectory);
430 outputFileName.Append(desiredOutFileName);
431 outputFileName.Append(suggestedExt);
432 // create a new outputfile
433 fs.Delete(outputFileName);
434 User::LeaveIfError(outputFile.Create(fs,outputFileName, EFileShareAny | EFileStream | EFileWrite));
435 result = import->ContinueWithNewOutputFile(outputFile,outputFileName);
438 User::LeaveIfError(result);
440 CleanupStack::PopAndDestroy(&file);
441 result = import->WriteDataComplete();
442 while(result == KErrCANewFileHandleRequired)
444 TFileName suggestedName;
445 User::LeaveIfError(import->GetSuggestedOutputFileName(suggestedName));
446 outputFileName.Copy(outputDirectory);
447 outputFileName.Append(suggestedName);
449 // create a new outputfile
450 fs.Delete(outputFileName);
451 User::LeaveIfError(outputFile.Create(fs,outputFileName, EFileShareAny | EFileStream | EFileWrite));
452 result = import->ContinueWithNewOutputFile(outputFile,outputFileName);
457 TInt n = import->OutputFileCountL();
458 for(TInt i = 0; i < n; i++)
460 // get output file name
461 TPtrC OutputFileName = import->OutputFileL(i).FileName();
462 INFO_PRINTF2(_L("Output File Created: %S"),&OutputFileName);
464 // get output file type (content or receipt)
465 TOutputType outputType = import->OutputFileL(i).OutputType();
467 if(outputType == EReceipt)
469 INFO_PRINTF1(_L("Output File is a receipt"));
473 INFO_PRINTF1(_L("Output File is content"));
476 // get output file mime type
477 TPtrC8 OutputMimeType = import->OutputFileL(i).MimeTypeL();
478 HBufC *mime = ConvertDes8toHBufC16LC(OutputMimeType );
479 INFO_PRINTF2(_L("Output File Mime Type: %S"),mime);
480 CleanupStack::PopAndDestroy(mime);
482 CleanupStack::PopAndDestroy(&fs);
483 CleanupStack::PopAndDestroy(import);
485 CleanupStack::PopAndDestroy(mySupplier);
486 CleanupStack::PopAndDestroy(array);
489 if (TestStepResult() != EFail)
491 SetTestStepResult(EPass);
494 return TestStepResult();
499 * This step tests the ExternalizeL() and InternalizeL() functions for
502 CCAFSupplierSerializeStep::~CCAFSupplierSerializeStep()
506 CCAFSupplierSerializeStep::CCAFSupplierSerializeStep(CCAFServer& aParent) : iParent(aParent)
508 SetTestStepName(KCAFSupplierSerializeStep);
512 TVerdict CCAFSupplierSerializeStep::doTestStepL()
514 _LIT8(KDrmMime,"application/testagent.drm");
515 _LIT8(KBinaryEncoding,"Binary");
516 _LIT8(KOmaRightsPending, "X-Oma-Drm-Separate-Delivery");
517 _LIT8(KOmaRightsPendingValue, "12");
519 SetTestStepResult(EInconclusive); // Default result to EInconclusive
523 // create a CafMimeHeader with "content type:" application/testagent.drm
524 CCafMimeHeader *header = CCafMimeHeader::NewL(KDrmMime());
525 CleanupStack::PushL(header);
527 // Add some information to the header
528 header->SetStandardMimeDataL(EContentTransferEncoding, KBinaryEncoding());
529 header->AddNonStandardMimeL(KOmaRightsPending(), KOmaRightsPendingValue());
531 // Create a buffer stream
532 CBufFlat* buf = CBufFlat::NewL(50);
533 CleanupStack::PushL(buf);
534 RBufWriteStream stream(*buf);
535 CleanupClosePushL(stream);
537 // call the stream function
539 CleanupStack::PopAndDestroy(&stream);
541 // Now, create an HBufC8 from the stream buf's length, and copy
542 // the stream buffer into this descriptor
543 HBufC8* des = HBufC8::NewL(buf->Size());
544 TPtr8 ptr(des->Des());
545 buf->Read(0, ptr, buf->Size());
547 // destroy the buffer
548 CleanupStack::PopAndDestroy(buf);
549 CleanupStack::PushL(des);
551 // Now, stream a new CCafMimeHeader from the descriptor
552 CCafMimeHeader* newHeader = CCafMimeHeader::NewL(KNullDesC8());
553 CleanupStack::PushL(newHeader);
554 RDesReadStream readstream(*des);
555 CleanupClosePushL(readstream);
556 readstream >> *newHeader;
557 CleanupStack::PopAndDestroy(&readstream);
559 // Now check that the new bitset equals the old one
560 TInt result = newHeader->StandardMimeData(EContentType).Compare(KDrmMime());
563 INFO_PRINTF1(_L("Content type was not copied properly during seriaization"));
564 SetTestStepResult(EFail);
566 result = newHeader->StandardMimeData(EContentTransferEncoding).Compare(KBinaryEncoding());
569 INFO_PRINTF1(_L("Content Length was not copied properly during seriaization"));
570 SetTestStepResult(EFail);
573 if (newHeader->NonStandardMimeCount() != 1)
575 INFO_PRINTF1(_L("Non standard field array not copied properly during seriaization"));
576 SetTestStepResult(EFail);
579 result = newHeader->NonStandardMimeField(0).Compare(KOmaRightsPending());
582 INFO_PRINTF1(_L("Non standard field not copied properly during seriaization"));
583 SetTestStepResult(EFail);
586 result = newHeader->NonStandardMimeData(0).Compare(KOmaRightsPendingValue());
589 INFO_PRINTF1(_L("Non standard field data was not copied properly during seriaization"));
590 SetTestStepResult(EFail);
593 CleanupStack::PopAndDestroy(3, header);
597 if (TestStepResult() != EFail)
599 SetTestStepResult(EPass);
602 return TestStepResult();
605 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY
608 * Check that applications can retrieve the HTTP request headers
610 CCAFHTTPRequestHeadersStep::~CCAFHTTPRequestHeadersStep()
614 CCAFHTTPRequestHeadersStep::CCAFHTTPRequestHeadersStep(CCAFServer& aParent) : iParent(aParent)
616 SetTestStepName(KCAFHTTPRequestHeadersStep);
620 void CCAFHTTPRequestHeadersStep::MHFRunL(RHTTPTransaction, const THTTPEvent&)
625 TInt CCAFHTTPRequestHeadersStep::MHFRunError(TInt, RHTTPTransaction, const THTTPEvent&)
631 TVerdict CCAFHTTPRequestHeadersStep::doTestStepL()
633 _LIT8(Kuri, "http://www.symbian.com/");
638 SetTestStepResult(EInconclusive); // Default result to EInconclusive
643 CSupplier* supplier = CSupplier::NewLC();
645 // Create an HTTP session
646 RHTTPSession session;
648 RStringPool pool = session.StringPool();
651 // Convert the URI string into a TUri8
653 parser.Parse(Kuri());
655 // create an HTTP transaction
656 RHTTPTransaction transaction = session.OpenTransactionL(parser, *this, pool.StringF(HTTP::EGET,RHTTPSession::GetTable()));
657 RHTTPHeaders hdr = transaction.Request().GetHeaderCollection();
659 // Get the request headers from the agent
660 supplier->PrepareHTTPRequestHeaders(pool, hdr);
662 TInt fieldParts = hdr.FieldPartsL(pool.StringF(HTTP::EAccept, RHTTPSession::GetTable()));
665 for(i = 0; i < fieldParts; i++)
667 // loop over all accept headers make sure we find the three we expect
668 User::LeaveIfError(hdr.GetField(pool.StringF(HTTP::EAccept, RHTTPSession::GetTable()), i, aValue));
670 RStringF header = (RStringF) aValue;
671 acceptHeader.Set(header.DesC());
673 // Reference Test Agent - content MIME type
674 if(acceptHeader.Compare(_L8("application/x-rta.drm.content")) == 0)
678 // Reference Test Agent - content + rights MIME type
679 else if(acceptHeader.Compare(_L8("application/x-rta.drm.contentrights")) == 0)
683 // Test Agent - MIME type
684 else if(acceptHeader.Compare(_L8("APPLICATION/TESTAGENT.DRM")) == 0)
691 // not all three headers were found
692 INFO_PRINTF1(_L("Not all expected HTTP Accept headers were present"));
693 SetTestStepResult(EFail);
698 // We were expecting three accept headers to be set
699 // two from the Reference Test Agent and one from Test Agent
700 INFO_PRINTF2(_L("ERROR: Only %d HTTP Accept headers were returned, expected 3"), fieldParts);
701 SetTestStepResult(EFail);
706 CleanupStack::PopAndDestroy(supplier);
709 if (TestStepResult() != EFail)
711 SetTestStepResult(EPass);
714 return TestStepResult();