contentmgmt/referencedrmagent/tcaf/source/SupplierStep.cpp
changeset 15 da2ae96f639b
child 19 cd501b96611d
equal deleted inserted replaced
10:afc583cfa176 15:da2ae96f639b
       
     1 /*
       
     2 * Copyright (c) 2003-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 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 
       
    18 
       
    19 #include <test/testexecutelog.h>
       
    20 #include <s32mem.h>
       
    21 #include "cafserver.h"
       
    22 #include "SupplierStep.h"
       
    23 #include "supplier.h"
       
    24 #include "cafmimeheader.h"
       
    25 #include "caferr.h"
       
    26 #include "metadataarray.h"
       
    27 #include "supplieroutputfile.h"
       
    28 #include "attribute.h"
       
    29 #include "bitset.h"
       
    30 
       
    31 #include <uri8.h>
       
    32 #ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY
       
    33 #include <http.h>
       
    34 #include <http/rhttpsession.h>
       
    35 #include <http/rhttptransaction.h>
       
    36 #include <http/rhttpheaders.h>
       
    37 #endif
       
    38 
       
    39 using namespace ContentAccess;
       
    40 
       
    41 
       
    42 /* 
       
    43  * This step imports a DCF file into CAF 
       
    44  *
       
    45  */
       
    46 CCafSupplierStep::~CCafSupplierStep()
       
    47 	{
       
    48 	}
       
    49 
       
    50 CCafSupplierStep::CCafSupplierStep(CCAFServer& aParent) : iParent(aParent)
       
    51 	{
       
    52 	SetTestStepName(KCAFSupplierStep);
       
    53 	}
       
    54 
       
    55 
       
    56 TVerdict CCafSupplierStep::doTestStepL()
       
    57 	{
       
    58 	SetTestStepResult(EInconclusive);
       
    59 
       
    60 	RFs fs;
       
    61 	RFile file;
       
    62 	TBuf8 <128> readBuffer;
       
    63 	
       
    64 	INFO_PRINTF1(_L("Supplier Test - Agent provides output files"));
       
    65 	
       
    66 	TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType;
       
    67 	TInt expectedLeave;
       
    68 
       
    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);
       
    75 	
       
    76 	StartApparcServerL();
       
    77 
       
    78 	__UHEAP_MARK;
       
    79 	
       
    80 	HBufC8 *mime = ConvertDes16toHBufC8LC(mimeType);
       
    81 
       
    82 	CCafMimeHeader *header = CCafMimeHeader::NewL(mime->Des());
       
    83 	CleanupStack::PushL(header);
       
    84 
       
    85 	CSupplier *mySupplier = CSupplier::NewLC();
       
    86 	mySupplier->SetOutputDirectoryL(outputDirectory);
       
    87 	
       
    88 	// ignore return value, just exercises code for CCover
       
    89 	mySupplier->IsImportSupported(header->StandardMimeData(EContentType));
       
    90 
       
    91 	CImportFile *import = NULL;
       
    92 	TRAPD(leaveResult, import = mySupplier->ImportFileL(*header, suggestedFileName));
       
    93 	if(leaveResult != expectedLeave)
       
    94 		{
       
    95 		SetTestStepResult(EFail);
       
    96 		}
       
    97 	if(leaveResult == KErrNone)
       
    98 		{
       
    99 		CleanupStack::PushL(import);
       
   100 
       
   101 		// read the input file and pass it to the CAF
       
   102 		fs.Connect();
       
   103 		CleanupClosePushL(fs);
       
   104 	
       
   105 		TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny);
       
   106 		CleanupClosePushL(file);
       
   107 		while(result == KErrNone)
       
   108 			{
       
   109 			result = file.Read(readBuffer);
       
   110 			if(readBuffer.Length() == 0)
       
   111 				break;
       
   112 			User::LeaveIfError(import->WriteData(readBuffer));
       
   113 			}
       
   114 		CleanupStack::PopAndDestroy(&file); 
       
   115 		User::LeaveIfError(import->WriteDataComplete());
       
   116 
       
   117 		TInt n = import->OutputFileCountL();
       
   118 		for(TInt i = 0; i < n; i++)
       
   119 			{
       
   120 			// get output file name
       
   121 			TPtrC OutputFileName = import->OutputFileL(i).FileName();
       
   122 			INFO_PRINTF2(_L("Output File Created: %S"),&OutputFileName);
       
   123 
       
   124 			// get output file type (content or receipt)
       
   125 			TOutputType outputType = import->OutputFileL(i).OutputType();
       
   126 
       
   127 			if(outputType == EReceipt)
       
   128 				{
       
   129 				INFO_PRINTF1(_L("Output File is a receipt"));
       
   130 				}
       
   131 			else
       
   132 				{
       
   133 				INFO_PRINTF1(_L("Output File is content"));
       
   134 				}
       
   135 
       
   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); 
       
   141 			}
       
   142 		CleanupStack::PopAndDestroy(&fs); 
       
   143 		CleanupStack::PopAndDestroy(import); 
       
   144 		}
       
   145 	CleanupStack::PopAndDestroy(mySupplier); 
       
   146 	CleanupStack::PopAndDestroy(header); 
       
   147 	CleanupStack::PopAndDestroy(mime); 
       
   148 	__UHEAP_MARKEND;
       
   149 
       
   150 	if (TestStepResult() != EFail)
       
   151 		{
       
   152 		SetTestStepResult(EPass);
       
   153 		}
       
   154 
       
   155 	return TestStepResult();
       
   156 	}
       
   157 
       
   158 
       
   159 
       
   160 /* 
       
   161  * This step imports a DCF file into CAF 
       
   162  *
       
   163  */
       
   164 CCafSupplierAsyncStep::~CCafSupplierAsyncStep()
       
   165 	{
       
   166 	}
       
   167 
       
   168 CCafSupplierAsyncStep::CCafSupplierAsyncStep(CCAFServer& aParent) : iParent(aParent)
       
   169 	{
       
   170 	SetTestStepName(KCAFSupplierAsyncStep);
       
   171 	}
       
   172 
       
   173 
       
   174 TVerdict CCafSupplierAsyncStep::doTestStepL()
       
   175 	{
       
   176 	SetTestStepResult(EInconclusive);
       
   177 
       
   178 	RFs fs;
       
   179 	RFile file;
       
   180 	TBuf8 <128> readBuffer;
       
   181 	TRequestStatus status;
       
   182 
       
   183 	INFO_PRINTF1(_L("Asynchronous Supplier Test - Agent provides output files"));
       
   184 	
       
   185 	TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType;
       
   186 	TInt expectedLeave;
       
   187 	
       
   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);
       
   194 
       
   195 	StartApparcServerL();
       
   196 
       
   197 
       
   198 	__UHEAP_MARK;
       
   199 	
       
   200 	HBufC8 *mime = ConvertDes16toHBufC8LC(mimeType);
       
   201 
       
   202 	CCafMimeHeader *header = CCafMimeHeader::NewL(mime->Des());
       
   203 	CleanupStack::PushL(header);
       
   204 
       
   205 	CSupplier *mySupplier = CSupplier::NewLC();
       
   206 	mySupplier->SetOutputDirectoryL(outputDirectory);
       
   207 
       
   208 	// ignore return value, just exercises code for CCover
       
   209 	mySupplier->IsImportSupported(header->StandardMimeData(EContentType));
       
   210 
       
   211 	CImportFile *import = NULL;
       
   212 	TRAPD(leaveResult, import = mySupplier->ImportFileL(*header, suggestedFileName));
       
   213 	if(leaveResult != expectedLeave)
       
   214 		{
       
   215 		SetTestStepResult(EFail);
       
   216 		}
       
   217 	if(leaveResult == KErrNone)
       
   218 		{
       
   219 		CleanupStack::PushL(import);
       
   220 
       
   221 		// read the input file and pass it to the CAF
       
   222 		fs.Connect();
       
   223 		CleanupClosePushL(fs);
       
   224 	
       
   225 		TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny);
       
   226 		CleanupClosePushL(file);
       
   227 		while(result == KErrNone)
       
   228 			{
       
   229 			result = file.Read(readBuffer);
       
   230 			if(readBuffer.Length() == 0)
       
   231 				break;
       
   232 			status = KRequestPending;
       
   233 			import->WriteData(readBuffer,status);
       
   234 			User::WaitForRequest(status);
       
   235 			}
       
   236 		CleanupStack::PopAndDestroy(&file); 
       
   237 		status = KRequestPending;
       
   238 		import->WriteDataComplete(status);
       
   239 		User::WaitForRequest(status);
       
   240 
       
   241 		TInt n = import->OutputFileCountL();
       
   242 		for(TInt i = 0; i < n; i++)
       
   243 			{
       
   244 			// get output file name
       
   245 			TPtrC OutputFileName = import->OutputFileL(i).FileName();
       
   246 			INFO_PRINTF2(_L("Output File Created: %S"),&OutputFileName);
       
   247 
       
   248 			// get output file type (content or receipt)
       
   249 			TOutputType outputType = import->OutputFileL(i).OutputType();
       
   250 
       
   251 			if(outputType == EReceipt)
       
   252 				{
       
   253 				INFO_PRINTF1(_L("Output File is a receipt"));
       
   254 				}
       
   255 			else
       
   256 				{
       
   257 				INFO_PRINTF1(_L("Output File is content"));
       
   258 				}
       
   259 
       
   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); 
       
   265 			}
       
   266 
       
   267 		CleanupStack::PopAndDestroy(&fs); 
       
   268 		CleanupStack::PopAndDestroy(import); 
       
   269 		}
       
   270 	CleanupStack::PopAndDestroy(mySupplier); 
       
   271 	CleanupStack::PopAndDestroy(header); 
       
   272 	CleanupStack::PopAndDestroy(mime); 
       
   273 	__UHEAP_MARKEND;
       
   274 		
       
   275 	if (TestStepResult() != EFail)
       
   276 		{
       
   277 		SetTestStepResult(EPass);
       
   278 		}
       
   279 
       
   280 	return TestStepResult();
       
   281 	}
       
   282 
       
   283 
       
   284 
       
   285 /* 
       
   286  * This step imports a DCF file into CAF 
       
   287  *
       
   288  */
       
   289 CCafClientOutputSupplierStep::~CCafClientOutputSupplierStep()
       
   290 	{
       
   291 	}
       
   292 
       
   293 CCafClientOutputSupplierStep::CCafClientOutputSupplierStep(CCAFServer& aParent) : iParent(aParent)
       
   294 	{
       
   295 	SetTestStepName(KCAFClientOutputSupplierStep);
       
   296 	}
       
   297 
       
   298 void CCafClientOutputSupplierStep::CheckContentMimeL(CImportFile* aImport, TDes8& aContentMime, TDesC8& aExpectedContentMime)
       
   299 	{
       
   300 	if(!aImport->ContentMimeTypeL(aContentMime))
       
   301 		{
       
   302 		//Agent can't determine the content MIME type with available data at the moment
       
   303 						
       
   304 		INFO_PRINTF1(_L("Content MIME Type can't be determined"));
       
   305 		SetTestStepResult(EFail);
       
   306 		return;
       
   307 		}
       
   308 	
       
   309 									    
       
   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);
       
   314 										    					    				    					    	
       
   315 	if(aContentMime.CompareF(aExpectedContentMime) == 0)
       
   316 		{
       
   317 		SetTestStepResult(EPass);
       
   318 		}
       
   319 	else
       
   320 		{
       
   321 		ERR_PRINTF1(_L("Content MIME Type doesn't match expected"));
       
   322 		SetTestStepResult(EFail);
       
   323 		}
       
   324 			
       
   325 	}
       
   326 
       
   327 
       
   328 TVerdict CCafClientOutputSupplierStep::doTestStepL()
       
   329 	{
       
   330 	SetTestStepResult(EInconclusive);
       
   331 
       
   332 	RFs fs;
       
   333 	RFile file;
       
   334 	TBuf8 <128> readBuffer;
       
   335 	TBuf8 <255> mimetype8;
       
   336 	TFileName outputFileName;
       
   337 	RFile outputFile;
       
   338 	CImportFile *import = NULL;
       
   339 	
       
   340 	// first output file will be a.txt
       
   341 	_LIT(KOutputFileName, "C:\\something.drm");
       
   342 	outputFileName.Copy(KOutputFileName);
       
   343 	
       
   344 	INFO_PRINTF1(_L("Supplier Test - Client provides output files"));
       
   345 	
       
   346 	TPtrC outputDirectory, sourceFileName, suggestedFileName, mimeType, expectedContentMime;
       
   347 	TInt expectedLeave;
       
   348 	TBool checkContentMime = EFalse;
       
   349 	TBuf8<KMaxDataTypeLength> contentMimeType;	
       
   350 	
       
   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);
       
   359 	
       
   360 	
       
   361 	StartApparcServerL();
       
   362 
       
   363 	__UHEAP_MARK;
       
   364 	
       
   365 	mimetype8.Copy(mimeType);
       
   366 
       
   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);
       
   372 
       
   373 	// create a supplier session
       
   374 	CSupplier *mySupplier = CSupplier::NewL();
       
   375 	CleanupStack::PushL(mySupplier);
       
   376 	
       
   377 	// check import is supported, ignore return value, just exercises code for CCover
       
   378 	mySupplier->IsImportSupported(array->SearchL(KContentType()));
       
   379 
       
   380 	// create import session
       
   381 	TRAPD(leaveResult, import = mySupplier->ImportFileL(mimetype8, *array));
       
   382 	if(leaveResult != expectedLeave)
       
   383 		{
       
   384 		SetTestStepResult(EFail);
       
   385 		}
       
   386 	if(leaveResult == KErrNone)
       
   387 		{
       
   388 		CleanupStack::PushL(import);
       
   389 
       
   390 		// read the input file and pass it to the CAF
       
   391 		fs.Connect();
       
   392 		CleanupClosePushL(fs);
       
   393 		TInt result = file.Open(fs, sourceFileName, EFileRead | EFileStream | EFileShareAny);
       
   394 		CleanupClosePushL(file);
       
   395 		
       
   396 		TParsePtrC parse(suggestedFileName);
       
   397 		TPtrC desiredOutFileName( parse.Name() );
       
   398 		
       
   399 		while(result == KErrNone)
       
   400 			{
       
   401 			result = file.Read(readBuffer);
       
   402 			if(readBuffer.Length() == 0)
       
   403 				break;
       
   404 			result = import->WriteData(readBuffer);
       
   405 			while(result == KErrCANewFileHandleRequired)
       
   406 				{
       
   407 				
       
   408 				if(checkContentMime)
       
   409 					{
       
   410 					
       
   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
       
   415 					//type
       
   416 					TBuf8<KMaxDataTypeLength> expectedContentMime8bit;
       
   417 					expectedContentMime8bit.Copy(expectedContentMime);
       
   418 					CheckContentMimeL(import, contentMimeType, expectedContentMime8bit);
       
   419 					//no more check needed in following iterations
       
   420 					checkContentMime = EFalse;
       
   421 						
       
   422 					//At this point client should decide where to save the file based on content mime
       
   423 					
       
   424 					}
       
   425 				
       
   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);
       
   436 				outputFile.Close();
       
   437 				}
       
   438 			User::LeaveIfError(result);
       
   439 			}
       
   440 		CleanupStack::PopAndDestroy(&file); 
       
   441 		result = import->WriteDataComplete();
       
   442 		while(result == KErrCANewFileHandleRequired)
       
   443 				{
       
   444 				TFileName suggestedName;
       
   445 				User::LeaveIfError(import->GetSuggestedOutputFileName(suggestedName));
       
   446 				outputFileName.Copy(outputDirectory);
       
   447 				outputFileName.Append(suggestedName);
       
   448 
       
   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);
       
   453 				outputFile.Close();
       
   454 				}
       
   455 	
       
   456 
       
   457 		TInt n = import->OutputFileCountL();
       
   458 		for(TInt i = 0; i < n; i++)
       
   459 			{
       
   460 			// get output file name
       
   461 			TPtrC OutputFileName = import->OutputFileL(i).FileName();
       
   462 			INFO_PRINTF2(_L("Output File Created: %S"),&OutputFileName);
       
   463 
       
   464 			// get output file type (content or receipt)
       
   465 			TOutputType outputType = import->OutputFileL(i).OutputType();
       
   466 
       
   467 			if(outputType == EReceipt)
       
   468 				{
       
   469 				INFO_PRINTF1(_L("Output File is a receipt"));
       
   470 				}
       
   471 			else
       
   472 				{
       
   473 				INFO_PRINTF1(_L("Output File is content"));
       
   474 				}
       
   475 
       
   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); 
       
   481 			}
       
   482 		CleanupStack::PopAndDestroy(&fs); 
       
   483 		CleanupStack::PopAndDestroy(import); 
       
   484 		}
       
   485 	CleanupStack::PopAndDestroy(mySupplier); 
       
   486 	CleanupStack::PopAndDestroy(array); 
       
   487 	__UHEAP_MARKEND;
       
   488 
       
   489 	if (TestStepResult() != EFail)
       
   490 		{
       
   491 		SetTestStepResult(EPass);
       
   492 		}
       
   493 
       
   494 	return TestStepResult();
       
   495 	}
       
   496 
       
   497 
       
   498 /* 
       
   499  * This step tests the ExternalizeL() and InternalizeL() functions for
       
   500  * CCafMimeHeader
       
   501  */
       
   502 CCAFSupplierSerializeStep::~CCAFSupplierSerializeStep()
       
   503 	{
       
   504 	}
       
   505 
       
   506 CCAFSupplierSerializeStep::CCAFSupplierSerializeStep(CCAFServer& aParent) : iParent(aParent)
       
   507 	{
       
   508 	SetTestStepName(KCAFSupplierSerializeStep);
       
   509 	}
       
   510 
       
   511 
       
   512 TVerdict CCAFSupplierSerializeStep::doTestStepL()
       
   513 	{	
       
   514 	_LIT8(KDrmMime,"application/testagent.drm");
       
   515 	_LIT8(KBinaryEncoding,"Binary");
       
   516 	_LIT8(KOmaRightsPending, "X-Oma-Drm-Separate-Delivery");
       
   517 	_LIT8(KOmaRightsPendingValue, "12");
       
   518 	
       
   519 	SetTestStepResult(EInconclusive); // Default result to EInconclusive
       
   520 
       
   521 	__UHEAP_MARK;
       
   522 	
       
   523 	// create a CafMimeHeader with "content type:" application/testagent.drm
       
   524 	CCafMimeHeader *header = CCafMimeHeader::NewL(KDrmMime());
       
   525 	CleanupStack::PushL(header);
       
   526 	
       
   527 	// Add some information to the header
       
   528 	header->SetStandardMimeDataL(EContentTransferEncoding, KBinaryEncoding());
       
   529 	header->AddNonStandardMimeL(KOmaRightsPending(), KOmaRightsPendingValue());
       
   530 
       
   531 	// Create a buffer stream
       
   532 	CBufFlat* buf = CBufFlat::NewL(50);
       
   533 	CleanupStack::PushL(buf);
       
   534 	RBufWriteStream stream(*buf);
       
   535 	CleanupClosePushL(stream);
       
   536 
       
   537 	// call the stream function
       
   538 	stream << *header;
       
   539 	CleanupStack::PopAndDestroy(&stream);
       
   540 
       
   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());
       
   546 
       
   547 	// destroy the buffer
       
   548 	CleanupStack::PopAndDestroy(buf);
       
   549 	CleanupStack::PushL(des);
       
   550 
       
   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);
       
   558 
       
   559 	// Now check that the new bitset equals the old one
       
   560 	TInt result = newHeader->StandardMimeData(EContentType).Compare(KDrmMime());
       
   561 	if (result != 0)
       
   562 		{
       
   563 		INFO_PRINTF1(_L("Content type was not copied properly during seriaization"));
       
   564 		SetTestStepResult(EFail);
       
   565 		}
       
   566 	result = newHeader->StandardMimeData(EContentTransferEncoding).Compare(KBinaryEncoding());
       
   567 	if (result != 0)
       
   568 		{
       
   569 		INFO_PRINTF1(_L("Content Length was not copied properly during seriaization"));
       
   570 		SetTestStepResult(EFail);
       
   571 		}
       
   572 	
       
   573 	if (newHeader->NonStandardMimeCount() != 1)
       
   574 		{
       
   575 		INFO_PRINTF1(_L("Non standard field array not copied properly during seriaization"));
       
   576 		SetTestStepResult(EFail);
       
   577 		}
       
   578 
       
   579 	result = newHeader->NonStandardMimeField(0).Compare(KOmaRightsPending());
       
   580 	if (result != 0)
       
   581 		{
       
   582 		INFO_PRINTF1(_L("Non standard field not copied properly during seriaization"));
       
   583 		SetTestStepResult(EFail);
       
   584 		}
       
   585 
       
   586 	result = newHeader->NonStandardMimeData(0).Compare(KOmaRightsPendingValue());
       
   587 	if (result != 0)
       
   588 		{
       
   589 		INFO_PRINTF1(_L("Non standard field data was not copied properly during seriaization"));
       
   590 		SetTestStepResult(EFail);
       
   591 		}
       
   592 
       
   593 	CleanupStack::PopAndDestroy(3, header);
       
   594 
       
   595 	__UHEAP_MARKEND;
       
   596 	
       
   597 	if (TestStepResult() != EFail)
       
   598 		{
       
   599 		SetTestStepResult(EPass);
       
   600 		}
       
   601 
       
   602 	return TestStepResult();
       
   603 	}
       
   604 
       
   605 #ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY
       
   606 
       
   607 /* 
       
   608  * Check that applications can retrieve the HTTP request headers
       
   609  */
       
   610 CCAFHTTPRequestHeadersStep::~CCAFHTTPRequestHeadersStep()
       
   611 	{
       
   612 	}
       
   613 
       
   614 CCAFHTTPRequestHeadersStep::CCAFHTTPRequestHeadersStep(CCAFServer& aParent) : iParent(aParent)
       
   615 	{
       
   616 	SetTestStepName(KCAFHTTPRequestHeadersStep);
       
   617 	}
       
   618 
       
   619 
       
   620 void CCAFHTTPRequestHeadersStep::MHFRunL(RHTTPTransaction, const THTTPEvent&)
       
   621 	{
       
   622 	
       
   623 	}
       
   624 	
       
   625 TInt CCAFHTTPRequestHeadersStep::MHFRunError(TInt, RHTTPTransaction, const THTTPEvent&)
       
   626 	{
       
   627 	return 0;
       
   628 	}
       
   629 
       
   630 
       
   631 TVerdict CCAFHTTPRequestHeadersStep::doTestStepL()
       
   632 	{	
       
   633 	_LIT8(Kuri, "http://www.symbian.com/");
       
   634 	TPtrC8 acceptHeader;
       
   635 	TInt i = 0;
       
   636 	TInt result = 0;
       
   637 	
       
   638 	SetTestStepResult(EInconclusive); // Default result to EInconclusive
       
   639 	THTTPHdrVal aValue;
       
   640 	
       
   641 	__UHEAP_MARK;
       
   642 
       
   643 	CSupplier* supplier = CSupplier::NewLC();
       
   644 	
       
   645 	// Create an HTTP session 
       
   646 	RHTTPSession session;
       
   647 	session.OpenL();
       
   648 	RStringPool pool = session.StringPool();
       
   649 	
       
   650 	
       
   651 	// Convert the URI string into a TUri8
       
   652 	TUriParser8 parser;
       
   653 	parser.Parse(Kuri());
       
   654 	
       
   655 	// create an HTTP transaction
       
   656 	RHTTPTransaction transaction = session.OpenTransactionL(parser, *this, pool.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   657 	RHTTPHeaders hdr = transaction.Request().GetHeaderCollection();
       
   658 
       
   659 	// Get the request headers from the agent
       
   660 	supplier->PrepareHTTPRequestHeaders(pool, hdr);
       
   661 	
       
   662 	TInt fieldParts = hdr.FieldPartsL(pool.StringF(HTTP::EAccept, RHTTPSession::GetTable()));
       
   663 	if(fieldParts == 3)
       
   664 		{
       
   665 		for(i = 0; i < fieldParts; i++)
       
   666 			{
       
   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));
       
   669 	
       
   670 			RStringF header = (RStringF) aValue;
       
   671 			acceptHeader.Set(header.DesC()); 
       
   672 		
       
   673 			// Reference Test Agent - content MIME type
       
   674 			if(acceptHeader.Compare(_L8("application/x-rta.drm.content")) == 0)
       
   675 				{
       
   676 				result |= 1;
       
   677 				}
       
   678 			// Reference Test Agent - content + rights MIME type
       
   679 			else if(acceptHeader.Compare(_L8("application/x-rta.drm.contentrights")) == 0)
       
   680 				{
       
   681 				result |= 2;
       
   682 				}
       
   683 			// Test Agent - MIME type
       
   684 			else if(acceptHeader.Compare(_L8("APPLICATION/TESTAGENT.DRM")) == 0)
       
   685 				{
       
   686 				result |= 4;
       
   687 				}
       
   688 			}
       
   689 		if(result != 7)
       
   690 			{
       
   691 			// not all three headers were found
       
   692 			INFO_PRINTF1(_L("Not all expected HTTP Accept headers were present"));
       
   693 			SetTestStepResult(EFail);		
       
   694 			}
       
   695 		}
       
   696 	else
       
   697 		{
       
   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);	
       
   702 		}
       
   703 		
       
   704 	transaction.Close();
       
   705 	session.Close();
       
   706 	CleanupStack::PopAndDestroy(supplier);
       
   707 	__UHEAP_MARKEND;
       
   708 	
       
   709 	if (TestStepResult() != EFail)
       
   710 		{
       
   711 		SetTestStepResult(EPass);
       
   712 		}
       
   713 
       
   714 	return TestStepResult();
       
   715 	}
       
   716 
       
   717 #endif
       
   718 
       
   719