os/security/contentmgmt/referencedrmagent/tcaf/source/CafutilsStep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-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 <caf/caf.h>
    22 #include <caf/rightsinfo.h>
    23 #include <caf/manager.h>
    24 #include <caf/supplieroutputfile.h>
    25 #include "cafserver.h"
    26 #include "CafUtilsStep.h"
    27 
    28 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    29 #include "refcafhelper.h"
    30 #include <caf/cafhelper.h>     
    31 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT 
    32 
    33 using namespace ContentAccess;
    34 
    35 
    36 CCafCDirStreamStep::~CCafCDirStreamStep()
    37 	{
    38 	}
    39 
    40 CCafCDirStreamStep::CCafCDirStreamStep(CCAFServer& aParent) : iParent(aParent)
    41 	{
    42 	SetTestStepName(KCAFCDirStreamStep);
    43 	}
    44 
    45 
    46 TVerdict CCafCDirStreamStep::doTestStepL()
    47 	{
    48 	SetTestStepResult(EPass);
    49 
    50 	_LIT(KTcafDir, "C:\\tcaf\\");
    51 	
    52 	INFO_PRINTF1(_L("CDirStreamable test"));
    53 	
    54 
    55 	__UHEAP_MARK;
    56 	
    57 	CManager *manager = CManager::NewLC();
    58 	
    59 	CDir *fileList = NULL;
    60 	User::LeaveIfError(manager->GetDir(KTcafDir(),KNullUid, ESortByName, fileList));
    61 	
    62 	CDirStreamable *newFileList = CDirStreamable::NewL(*fileList);
    63 	delete fileList;
    64 	
    65 	// Create a buffer
    66 	CBufFlat* buf = CBufFlat::NewL(50);
    67 	CleanupStack::PushL(buf);
    68 	
    69 	// create write stream
    70 	RBufWriteStream writeStream(*buf);
    71 	CleanupClosePushL(writeStream);
    72 
    73 	// write the directory to the stream
    74 	newFileList->ExternalizeL(writeStream);
    75 	CleanupStack::PopAndDestroy(&writeStream);
    76 
    77 	// create read stream
    78 	RBufReadStream readStream(*buf);
    79 	CleanupClosePushL(readStream);
    80 
    81 	// construct a new CDirStreamable from the stream
    82 	CDirStreamable *streamDir = CDirStreamable::NewL(readStream);
    83 	CleanupStack::PopAndDestroy(&readStream);
    84 	
    85 	for(TInt i = 0; i < newFileList->Count(); i++)
    86 		{
    87 		if((*newFileList)[i].iName != (*streamDir)[i].iName)
    88 			{
    89 			SetTestStepResult(EFail);
    90 			}
    91 		if((*newFileList)[i].iType != (*streamDir)[i].iType)
    92 			{
    93 			SetTestStepResult(EFail);
    94 			}
    95 		}
    96 	
    97 	CleanupStack::PopAndDestroy(buf);
    98 	
    99 	delete newFileList;
   100 	delete streamDir;
   101 	CleanupStack::PopAndDestroy(manager);
   102 	
   103 	__UHEAP_MARKEND;
   104 
   105 	return TestStepResult();
   106 	}
   107 
   108 CCafRAttributeSetStreamStep::~CCafRAttributeSetStreamStep()
   109 	{
   110 	}
   111 
   112 CCafRAttributeSetStreamStep::CCafRAttributeSetStreamStep(CCAFServer& aParent) : iParent(aParent)
   113 	{
   114 	SetTestStepName(KCAFRAttributeSetStreamStep);
   115 	}
   116 
   117 
   118 TVerdict CCafRAttributeSetStreamStep::doTestStepL()
   119 	{
   120 	SetTestStepResult(EPass);
   121 	
   122 	INFO_PRINTF1(_L("CRAttributeSet streaming test"));
   123 	
   124 	__UHEAP_MARK;
   125 	
   126 
   127 	RAttributeSet aSet;
   128 	CleanupClosePushL(aSet);
   129 	aSet.AddL(EIsProtected);
   130 	aSet.AddL(EIsForwardable);
   131 	aSet.AddL(EIsForwardable);
   132 	
   133 	aSet.SetValue(EIsProtected, (TInt) ETrue, KErrNone);
   134 	aSet.SetValue(EIsForwardable, (TInt) EFalse, KErrNone);
   135 		
   136 	// Create a buffer
   137 	CBufFlat* buf = CBufFlat::NewL(50);
   138 	CleanupStack::PushL(buf);
   139 	
   140 	// create write stream
   141 	RBufWriteStream writeStream(*buf);
   142 	CleanupClosePushL(writeStream);
   143 
   144 	// write the directory to the stream
   145 	aSet.ExternalizeL(writeStream);
   146 	CleanupStack::PopAndDestroy(&writeStream);
   147 
   148 	// create read stream
   149 	RBufReadStream readStream(*buf);
   150 	CleanupClosePushL(readStream);
   151 
   152 	// construct a new CDirStreamable from the stream
   153 	RAttributeSet bSet;
   154 	CleanupClosePushL(bSet);
   155 	bSet.InternalizeL(readStream);
   156 		
   157 	TInt valueA, valueB;
   158 	if(aSet.Count() != bSet.Count())
   159 		{
   160 		SetTestStepResult(EFail);
   161 		}
   162 	
   163 	for(TInt i = 0; i < aSet.Count(); i++)
   164 		{
   165 		valueA = -1;
   166 		valueB = -1;
   167 		if(aSet.GetValue(aSet[i],valueA) != bSet.GetValue(aSet[i],valueB))
   168 			{
   169 			SetTestStepResult(EFail);
   170 			}
   171 			
   172 		if(valueA != valueB)
   173 			{
   174 			SetTestStepResult(EFail);
   175 			}
   176 		}
   177 	
   178 	CleanupStack::PopAndDestroy(&bSet);
   179 	CleanupStack::PopAndDestroy(&readStream);
   180 	CleanupStack::PopAndDestroy(buf);
   181 	CleanupStack::PopAndDestroy(&aSet);
   182 	
   183 	__UHEAP_MARKEND;
   184 
   185 	return TestStepResult();
   186 	}
   187 
   188 
   189 CCafRStringAttributeSetStreamStep::~CCafRStringAttributeSetStreamStep()
   190 	{
   191 	}
   192 
   193 CCafRStringAttributeSetStreamStep::CCafRStringAttributeSetStreamStep(CCAFServer& aParent) : iParent(aParent)
   194 	{
   195 	SetTestStepName(KCAFRStringAttributeSetStreamStep);
   196 	}
   197 
   198 
   199 TVerdict CCafRStringAttributeSetStreamStep::doTestStepL()
   200 	{
   201 	SetTestStepResult(EPass);
   202 	
   203 	INFO_PRINTF1(_L("CRStringAttributeSet streaming test"));
   204 	
   205 	_LIT(KMimeType,"mime/type");
   206 
   207 	__UHEAP_MARK;
   208 	
   209 	RStringAttributeSet aSet;
   210 	CleanupClosePushL(aSet);
   211 	aSet.AddL(EMimeType);
   212 	aSet.AddL(EDescription);
   213 	
   214 	// Set some values, normally be done by the agent
   215 	aSet.SetValue(EMimeType, KMimeType(), KErrNone);	
   216 	aSet.SetValue(EDescription, KNullDesC(), KErrNotSupported);	
   217 	
   218 	// Create a buffer
   219 	CBufFlat* buf = CBufFlat::NewL(50);
   220 	CleanupStack::PushL(buf);
   221 	
   222 	// create write stream
   223 	RBufWriteStream writeStream(*buf);
   224 	CleanupClosePushL(writeStream);
   225 
   226 	// write the directory to the stream
   227 	aSet.ExternalizeL(writeStream);
   228 	CleanupStack::PopAndDestroy(&writeStream);
   229 
   230 	// create read stream
   231 	RBufReadStream readStream(*buf);
   232 	CleanupClosePushL(readStream);
   233 
   234 	// construct a new CDirStreamable from the stream
   235 	RStringAttributeSet bSet;
   236 	CleanupClosePushL(bSet);
   237 	bSet.InternalizeL(readStream);
   238 		
   239 	TBuf <1024> valueA;
   240 	TBuf <1024> valueB;
   241 	if(aSet.Count() != bSet.Count())
   242 		{
   243 		SetTestStepResult(EFail);
   244 		}
   245 	
   246 	for(TInt i = 0; i < aSet.Count(); i++)
   247 		{
   248 		valueA.SetLength(0);
   249 		valueB.SetLength(0);
   250 		if(aSet.GetValue(aSet[i],valueA) != bSet.GetValue(aSet[i],valueB))
   251 			{
   252 			SetTestStepResult(EFail);
   253 			}
   254 			
   255 		if(valueA != valueB)
   256 			{
   257 			SetTestStepResult(EFail);
   258 			}
   259 		}
   260 	
   261 	CleanupStack::PopAndDestroy(&bSet);
   262 	CleanupStack::PopAndDestroy(&readStream);
   263 	CleanupStack::PopAndDestroy(buf);
   264 	CleanupStack::PopAndDestroy(&aSet);
   265 	
   266 	__UHEAP_MARKEND;
   267 
   268 	return TestStepResult();
   269 	}
   270 
   271 
   272 
   273 CCafSupplierOutputFileStreamStep::~CCafSupplierOutputFileStreamStep()
   274 	{
   275 	}
   276 
   277 CCafSupplierOutputFileStreamStep::CCafSupplierOutputFileStreamStep(CCAFServer& aParent) : iParent(aParent)
   278 	{
   279 	SetTestStepName(KCAFSupplierOutputFileStreamStep);
   280 	}
   281 
   282 
   283 TVerdict CCafSupplierOutputFileStreamStep::doTestStepL()
   284 	{
   285 	SetTestStepResult(EPass);
   286 
   287 	_LIT(KDummyName, "C:\\tcaf\\supplieroutputfile.txt");
   288 	_LIT8(KDummyType, "something//caf");
   289 	
   290 	INFO_PRINTF1(_L("CSupplierOutputFile test"));
   291 	
   292 
   293 	__UHEAP_MARK;
   294 	
   295 	CSupplierOutputFile *outputFile = CSupplierOutputFile::NewL(KDummyName(), EContent, KDummyType());
   296 	
   297 	// Create a buffer
   298 	CBufFlat* buf = CBufFlat::NewL(50);
   299 	CleanupStack::PushL(buf);
   300 	
   301 	// create write stream
   302 	RBufWriteStream writeStream(*buf);
   303 	CleanupClosePushL(writeStream);
   304 
   305 	// write the directory to the stream
   306 	outputFile->ExternalizeL(writeStream);
   307 	CleanupStack::PopAndDestroy(&writeStream);
   308 
   309 	// create read stream
   310 	RBufReadStream readStream(*buf);
   311 	CleanupClosePushL(readStream);
   312 
   313 	// construct a new CSupplierOutputFile from the stream
   314 	CSupplierOutputFile *outputFile2= CSupplierOutputFile::NewL(readStream);
   315 	CleanupStack::PopAndDestroy(&readStream);
   316 	
   317 	if(outputFile->FileName() != outputFile2->FileName())
   318 			{
   319 			SetTestStepResult(EFail);
   320 			}
   321 	if(outputFile->OutputType() != outputFile2->OutputType())
   322 			{
   323 			SetTestStepResult(EFail);
   324 			}
   325 	if(outputFile->MimeTypeL() != outputFile2->MimeTypeL())
   326 			{
   327 			SetTestStepResult(EFail);
   328 			}
   329 	
   330 	CleanupStack::PopAndDestroy(buf);
   331 	
   332 	delete outputFile;
   333 	delete outputFile2;
   334 	
   335 	__UHEAP_MARKEND;
   336 
   337 	return TestStepResult();
   338 	}
   339 
   340 CCafMetaDataArrayStep::~CCafMetaDataArrayStep()
   341 	{
   342 	}
   343 
   344 CCafMetaDataArrayStep::CCafMetaDataArrayStep(CCAFServer& aParent) : iParent(aParent)
   345 	{
   346 	SetTestStepName(KCAFMetaDataArrayStep);
   347 	}
   348 
   349 
   350 TVerdict CCafMetaDataArrayStep::doTestStepL()
   351 	{
   352 	SetTestStepResult(EPass);
   353 
   354 	_LIT(KTest1, "Cat");
   355 	_LIT(KValue1, "Sat");
   356 
   357 	_LIT8(KTest2, "Mellow");
   358 	_LIT8(KValue2, "Yellow");
   359 
   360 	_LIT8(KTest3, "Tree");
   361 	_LIT8(KValue3, "House");
   362 
   363 	
   364 	INFO_PRINTF1(_L("CMetaDataArray test"));
   365 	
   366 
   367 	__UHEAP_MARK;
   368 	
   369 	CMetaDataArray *array = CMetaDataArray::NewLC();
   370 	array->AddL(KTest1(), KValue1());
   371 	array->AddL(KTest2(), KValue2());
   372 	array->AddL(KTest3(), KValue3());
   373 	
   374 	// Create a buffer
   375 	CBufFlat* buf = CBufFlat::NewL(50);
   376 	CleanupStack::PushL(buf);
   377 	
   378 	// create write stream
   379 	RBufWriteStream writeStream(*buf);
   380 	CleanupClosePushL(writeStream);
   381 
   382 	// write the directory to the stream
   383 	array->ExternalizeL(writeStream);
   384 	CleanupStack::PopAndDestroy(&writeStream);
   385 
   386 	// create read stream
   387 	RBufReadStream readStream(*buf);
   388 	CleanupClosePushL(readStream);
   389 
   390 	// construct a new CSupplierOutputFile from the stream
   391 	CMetaDataArray *array2= CMetaDataArray::NewL(readStream);
   392 	CleanupStack::PopAndDestroy(&readStream);
   393 	
   394 	
   395 	if(array->Count() != array2->Count() || (*array)[0].Field() != KTest1() || (*array)[1].Data8() != KValue2())
   396 			{
   397 			SetTestStepResult(EFail);
   398 			}
   399 	for(TInt i = 0; i < array->Count(); i++)
   400 		{
   401 		const CMetaData &a = (*array)[i];
   402 		const CMetaData &b = (*array2)[i];
   403 		if(a.Field() != b.Field())
   404 			{
   405 			SetTestStepResult(EFail);
   406 			}
   407 		if(a.Field8() != b.Field8())
   408 			{
   409 			SetTestStepResult(EFail);
   410 			}
   411 		if(a.Data() != b.Data())
   412 			{
   413 			SetTestStepResult(EFail);
   414 			}
   415 		if(a.Data8() != b.Data8())
   416 			{
   417 			SetTestStepResult(EFail);
   418 			}
   419 		}
   420 	
   421 	delete array2;
   422 		
   423 	CleanupStack::PopAndDestroy(buf);
   424 	CleanupStack::PopAndDestroy(array);
   425 	
   426 	__UHEAP_MARKEND;
   427 
   428 	return TestStepResult();
   429 	}
   430 
   431 
   432 CCafEmbeddedObjectStep::~CCafEmbeddedObjectStep()
   433 	{
   434 	}
   435 
   436 CCafEmbeddedObjectStep::CCafEmbeddedObjectStep(CCAFServer& aParent) : iParent(aParent)
   437 	{
   438 	SetTestStepName(KCAFEmbeddedObjectStep);
   439 	}
   440 
   441 
   442 TVerdict CCafEmbeddedObjectStep::doTestStepL()
   443 	{
   444 	SetTestStepResult(EPass);
   445 
   446 	_LIT(KTestUniqueId, "The UniqueId");
   447 	_LIT(KTestName, "The Name");
   448 
   449 	_LIT8(KTestMimeType, "The mime type");
   450 
   451 	
   452 	INFO_PRINTF1(_L("CEmbeddedObject test"));
   453 	
   454 
   455 	__UHEAP_MARK;
   456 	
   457 	CEmbeddedObject *aObject = CEmbeddedObject::NewL(KTestUniqueId(), KTestName(), KTestMimeType(), EContentObject);
   458 	
   459 	// Create a buffer
   460 	CBufFlat* buf = CBufFlat::NewL(50);
   461 	CleanupStack::PushL(buf);
   462 	
   463 	// create write stream
   464 	RBufWriteStream writeStream(*buf);
   465 	CleanupClosePushL(writeStream);
   466 
   467 	// write the directory to the stream
   468 	aObject->ExternalizeL(writeStream);
   469 	CleanupStack::PopAndDestroy(&writeStream);
   470 
   471 	// create read stream
   472 	RBufReadStream readStream(*buf);
   473 	CleanupClosePushL(readStream);
   474 
   475 	// construct a new CSupplierOutputFile from the stream
   476 	CEmbeddedObject *bObject= CEmbeddedObject::NewL(readStream);
   477 	CleanupStack::PopAndDestroy(&readStream);
   478 	
   479 	
   480 	if(aObject->UniqueId() != bObject->UniqueId())
   481 			{
   482 			SetTestStepResult(EFail);
   483 			}
   484 			
   485 	if(aObject->Name() != bObject->Name())
   486 			{
   487 			SetTestStepResult(EFail);
   488 			}			
   489 	if(aObject->Type() != bObject->Type())
   490 			{
   491 			SetTestStepResult(EFail);
   492 			}			
   493 	if(aObject->MimeType() != bObject->MimeType())
   494 			{
   495 			SetTestStepResult(EFail);
   496 			}			
   497 	
   498 	CleanupStack::PopAndDestroy(buf);
   499 	delete aObject;
   500 	delete bObject;
   501 	
   502 	__UHEAP_MARKEND;
   503 
   504 	return TestStepResult();
   505 	}
   506 
   507 CCafVirtualPathStep::~CCafVirtualPathStep()
   508 	{
   509 	}
   510 
   511 CCafVirtualPathStep::CCafVirtualPathStep(CCAFServer& aParent) : iParent(aParent)
   512 	{
   513 	SetTestStepName(KCAFVirtualPathStep);
   514 	}
   515 
   516 
   517 TVerdict CCafVirtualPathStep::doTestStepL()
   518 	{
   519 	SetTestStepResult(EPass);
   520 	INFO_PRINTF1(_L("CVirtualPath test"));
   521 	_LIT(KTestUniqueId, "The UniqueId");
   522 	_LIT(KTestUri, "A URI");
   523 	_LIT(KSection,"virtualpath");
   524 	_LIT(KDefaultUniqueID,"DEFAULT");
   525 	TPtrC uri;
   526 	TPtrC uniqueID;
   527 	TPtrC combined;
   528 	TPtrC expecteduniqueid;
   529 	TPtrC expecteduri;
   530 	__UHEAP_MARK;
   531 	
   532 	/* test the creation of TVirtualPathPtr and CVirtualPath objects and check if they contain
   533 	 * the expected URI and UniqueID values.
   534 	 */
   535 	TInt i;
   536 	for(i = 0;i<6;i++)
   537 		{
   538 		TBuf<13> sectionName(KSection);
   539 		sectionName.AppendNum(i);
   540 		GetStringFromConfig(sectionName,_L("uri"),uri);
   541 		GetStringFromConfig(sectionName,_L("uniqueID"),uniqueID);
   542 		GetStringFromConfig(sectionName,_L("combined"),combined);
   543 		GetStringFromConfig(sectionName,_L("expecteduri"),expecteduri);
   544 		GetStringFromConfig(sectionName,_L("expecteduniqueid"),expecteduniqueid);
   545 		// Test the TVirtualPathPtr API
   546 		TVirtualPathPtr vPath(uri,uniqueID);
   547 		if(vPath.URI()!=expecteduri)
   548 			{
   549 			INFO_PRINTF4(_L("TVirtualPathPtr(uri,uniqueID) failed Uri for %S\nExpected %S\nGot %S"),&combined,&expecteduri,&vPath.URI());
   550 			SetTestStepResult(EFail);
   551 			}
   552 		if(vPath.UniqueId()!=expecteduniqueid)
   553 			{
   554 			INFO_PRINTF4(_L("TVirtualPathPtr(uri,uniqueID) failed uniqueID for %S\nExpected %S\nGot %S"),&combined,&expecteduniqueid,&vPath.UniqueId());
   555 			SetTestStepResult(EFail);
   556 			}
   557 		vPath=TVirtualPathPtr(combined);
   558 		if(vPath.URI()!=expecteduri)
   559 			{
   560 			INFO_PRINTF4(_L("TVirtualPathPtr(uri,uniqueID) failed Uri() for %S\nExpected %S\nGot %S"),&combined,&expecteduri,&vPath.URI());
   561 			SetTestStepResult(EFail);
   562 			}
   563 		if(vPath.UniqueId()!=expecteduniqueid)
   564 			{
   565 			INFO_PRINTF4(_L("TVirtualPathPtr(aCombinedUriUniqueId) failed UniqueID() for %S\nExpected %S\nGot %S"),&combined,&expecteduniqueid,&vPath.UniqueId());
   566 			SetTestStepResult(EFail);
   567 			}
   568 		vPath=combined;
   569 		if(vPath.URI()!=expecteduri)
   570 			{
   571 			INFO_PRINTF4(_L("TVirtualPathPtr operator = failed Uri for %S\nExpected %S\nGot %S"),&combined,&expecteduri,&vPath.URI());
   572 			SetTestStepResult(EFail);
   573 			}
   574 		if(vPath.UniqueId()!=expecteduniqueid)
   575 			{
   576 			INFO_PRINTF4(_L("TVirtualPathPtr operator = UniqueId for %S\nExpected %S\nGot %S"),&combined,&expecteduniqueid,&vPath.UniqueId());
   577 			SetTestStepResult(EFail);
   578 			}
   579 		// Test the CVirtualPath API
   580 		CVirtualPath* heapPath = CVirtualPath::NewL(uri,uniqueID);
   581 		if(heapPath->URI()!=expecteduri)
   582 			{
   583 			INFO_PRINTF4(_L("TCVirtualPath::NewL(uri,uniqueID) failed Uri for %S\nExpected %S\nGot %S"),&combined,&expecteduri,&heapPath->URI());
   584 			SetTestStepResult(EFail);
   585 			}
   586 		if(heapPath->UniqueId()!=expecteduniqueid)
   587 			{
   588 			INFO_PRINTF4(_L("CVirtualPath::NewL(uri,uniqueID) failed UniqueID for %S\nExpected %S\nGot %S"),&combined,&expecteduniqueid,&heapPath->UniqueId());;
   589 			SetTestStepResult(EFail);
   590 			}
   591 		if(heapPath->GetCombinedUriUniqueId()!=combined)
   592 			{
   593 			INFO_PRINTF4(_L("CVirtualPath::NewL(uri,uniqueID) failed GetCombinedUriUniqueId() for %S\nExpected %S\nGot %S"),&combined,&combined,&heapPath->GetCombinedUriUniqueId());
   594 			SetTestStepResult(EFail);
   595 			}
   596 		delete heapPath;
   597 		heapPath=NULL;
   598 		
   599 		heapPath = CVirtualPath::NewL(combined);
   600 		if(heapPath->URI()!=expecteduri)
   601 			{
   602 			INFO_PRINTF4(_L("CVirtualPath::NewL(combined) failed Uri for %S\nExpected %S\nGot %S"),&combined,&expecteduri,&heapPath->URI());
   603 			SetTestStepResult(EFail);
   604 			}
   605 		if(heapPath->UniqueId()!=expecteduniqueid)
   606 			{
   607 			INFO_PRINTF4(_L("CVirtualPath::NewL(combined) failed UniqueID for %S\nExpected %S\nGot %S"),&combined,&expecteduniqueid,&heapPath->UniqueId());
   608 			SetTestStepResult(EFail);
   609 			}
   610 		if(heapPath->GetCombinedUriUniqueId()!=combined)
   611 			{
   612 			INFO_PRINTF4(_L("CVirtualPath::NewL(combined) failed GetCombinedUriUniqueId() for %S\nExpected %S\nGot %S"),&combined,&combined,&heapPath->GetCombinedUriUniqueId());
   613 			SetTestStepResult(EFail);
   614 			}
   615 		delete heapPath;
   616 		heapPath=NULL;
   617 		}
   618 
   619 
   620 	CVirtualPath *aPath= CVirtualPath::NewL(KTestUri(), KTestUniqueId());
   621 	
   622 	// Create a buffer
   623 	CBufFlat* buf = CBufFlat::NewL(50);
   624 	CleanupStack::PushL(buf);
   625 	
   626 	// create write stream
   627 	RBufWriteStream writeStream(*buf);
   628 	CleanupClosePushL(writeStream);
   629 
   630 	// write the directory to the stream
   631 	aPath->ExternalizeL(writeStream);
   632 	CleanupStack::PopAndDestroy(&writeStream);
   633 
   634 	// create read stream
   635 	RBufReadStream readStream(*buf);
   636 	CleanupClosePushL(readStream);
   637 
   638 	// construct a new CSupplierOutputFile from the stream
   639 	CVirtualPath *bPath= CVirtualPath::NewL(readStream);
   640 	CleanupStack::PopAndDestroy(&readStream);
   641 	
   642 	
   643 	if(aPath->UniqueId() != bPath->UniqueId())
   644 			{
   645 			SetTestStepResult(EFail);
   646 			}
   647 			
   648 	if(aPath->URI() != bPath->URI())
   649 			{
   650 			SetTestStepResult(EFail);
   651 			}			
   652 
   653 	// Test that if a uniqueID of length greater than ContentAccess::KMaxCafUniqueId
   654 	// is given then it will not treat it as a valid uniqueID
   655 	HBufC* longUID = HBufC::NewLC(aPath->UniqueId().Length() * 100+aPath->URI().Length()+1);
   656 	longUID->Des().Append(aPath->URI());
   657 	longUID->Des().Append(KCafVirtualPathSeparator);
   658 	// create a very long concatenated URI and UniqueID
   659 	for ( i = 0; i < 100; ++i )
   660 		{
   661 		longUID->Des().Append(aPath->UniqueId());
   662 		}
   663 	// create a TVirtualPathPtr with the concatenated URI and UniqueID
   664 	TVirtualPathPtr longPath(longUID->Des());
   665 	// check if the expected URI and UniqueID are stored
   666 	if(longPath.URI()!=longUID->Des())
   667 		{
   668 		SetTestStepResult(EFail);
   669 		}
   670 	if(longPath.UniqueId()!=KDefaultUniqueID)
   671 		{
   672 		SetTestStepResult(EFail);
   673 		}
   674 		
   675 	CleanupStack::PopAndDestroy(longUID);
   676 	CleanupStack::PopAndDestroy(buf);
   677 	delete aPath;
   678 	delete bPath;
   679 	
   680 	
   681 	__UHEAP_MARKEND;
   682 
   683 	return TestStepResult();
   684 	}
   685 
   686 
   687 
   688 CCafRightsInfoStep::~CCafRightsInfoStep()
   689 	{
   690 	}
   691 
   692 CCafRightsInfoStep::CCafRightsInfoStep(CCAFServer& aParent) : iParent(aParent)
   693 	{
   694 	SetTestStepName(KCAFRightsInfoStep);
   695 	}
   696 
   697 
   698 TVerdict CCafRightsInfoStep::doTestStepL()
   699 	{
   700 	SetTestStepResult(EPass);
   701 
   702 	_LIT(KTestUniqueId, "The UniqueId");
   703 	_LIT(KTestDescription, "A Description");
   704 
   705 	INFO_PRINTF1(_L("CRightsInfo test"));
   706 	
   707 
   708 	__UHEAP_MARK;
   709 	
   710 	CRightsInfo *aRights= CRightsInfo::NewL(KTestDescription(), KTestUniqueId(), ERightsTypeConsumable, ERightsStatusNone);
   711 	
   712 	
   713 	// Create a buffer
   714 	CBufFlat* buf = CBufFlat::NewL(50);
   715 	CleanupStack::PushL(buf);
   716 	
   717 	// create write stream
   718 	RBufWriteStream writeStream(*buf);
   719 	CleanupClosePushL(writeStream);
   720 
   721 	// write the directory to the stream
   722 	aRights->ExternalizeL(writeStream);
   723 	CleanupStack::PopAndDestroy(&writeStream);
   724 
   725 	// create read stream
   726 	RBufReadStream readStream(*buf);
   727 	CleanupClosePushL(readStream);
   728 
   729 	// construct a new CSupplierOutputFile from the stream
   730 	CRightsInfo *bRights= CRightsInfo::NewL(readStream);
   731 	CleanupStack::PopAndDestroy(&readStream);
   732 	
   733 	
   734 	if(aRights->UniqueId() != bRights->UniqueId())
   735 			{
   736 			SetTestStepResult(EFail);
   737 			}
   738 			
   739 	if(aRights->Description() != bRights->Description())
   740 			{
   741 			SetTestStepResult(EFail);
   742 			}			
   743 
   744 	if(aRights->RightsType() != bRights->RightsType())
   745 			{
   746 			SetTestStepResult(EFail);
   747 			}			
   748 
   749 	if(aRights->RightsStatus() != bRights->RightsStatus())
   750 			{
   751 			SetTestStepResult(EFail);
   752 			}			
   753 	
   754 	CleanupStack::PopAndDestroy(buf);
   755 	delete aRights;
   756 	delete bRights;
   757 	
   758 	__UHEAP_MARKEND;
   759 
   760 	return TestStepResult();
   761 	}
   762 
   763 
   764 
   765 CCafStreamablePtrArrayStep::~CCafStreamablePtrArrayStep()
   766 	{
   767 	}
   768 
   769 CCafStreamablePtrArrayStep::CCafStreamablePtrArrayStep(CCAFServer& aParent) : iParent(aParent)
   770 	{
   771 	SetTestStepName(KCAFStreamablePtrArrayStep);
   772 	}
   773 
   774 
   775 TVerdict CCafStreamablePtrArrayStep::doTestStepL()
   776 	{
   777 	SetTestStepResult(EPass);
   778 
   779 	_LIT(KTestUniqueId, "The UniqueId");
   780 	_LIT(KTestName, "The Name");
   781 	_LIT8(KTestMimeType, "The mime type");
   782 
   783 	INFO_PRINTF1(_L("StreamablePtrArray test"));
   784 	
   785 	__UHEAP_MARK;
   786 	
   787 	RStreamablePtrArray <CEmbeddedObject> array;
   788 	
   789 	CEmbeddedObject *aObject = CEmbeddedObject::NewL(KTestUniqueId(), KTestName(), KTestMimeType(), EContentObject);
   790 	CEmbeddedObject *bObject = CEmbeddedObject::NewL(KTestUniqueId(), KTestName(), KTestMimeType(), EContentObject);
   791 	CEmbeddedObject *cObject = CEmbeddedObject::NewL(KTestUniqueId(), KTestName(), KTestMimeType(), EContentObject);
   792 	
   793 	array.AppendL(aObject);
   794 	array.AppendL(bObject);
   795 	array.AppendL(cObject);
   796 	
   797 
   798 	// Create a buffer
   799 	CBufFlat* buf = CBufFlat::NewL(50);
   800 	CleanupStack::PushL(buf);
   801 	
   802 	// create write stream
   803 	RBufWriteStream writeStream(*buf);
   804 	CleanupClosePushL(writeStream);
   805 
   806 	// write the directory to the stream
   807 	array.ExternalizeL(writeStream);
   808 	CleanupStack::PopAndDestroy(&writeStream);
   809 
   810 	// create read stream
   811 	RBufReadStream readStream(*buf);
   812 	CleanupClosePushL(readStream);
   813 
   814 	// construct a new CSupplierOutputFile from the stream
   815 	RStreamablePtrArray <CEmbeddedObject> bArray;
   816 	bArray.InternalizeL(readStream);
   817 	CleanupStack::PopAndDestroy(&readStream);
   818 	
   819 	if(array.Count() != bArray.Count())
   820 			{
   821 			SetTestStepResult(EFail);
   822 			}
   823 			
   824 	for(TInt i=0; i < array.Count(); i++)
   825 		{
   826 		if(array[i]->UniqueId() != bArray[i]->UniqueId())
   827 			{
   828 			SetTestStepResult(EFail);
   829 			}
   830 			
   831 		if(array[i]->Name() != bArray[i]->Name())
   832 			{
   833 			SetTestStepResult(EFail);
   834 			}			
   835 		}
   836 	
   837 	CleanupStack::PopAndDestroy(buf);
   838 	array.Close();
   839 	bArray.Close();
   840 	
   841 	__UHEAP_MARKEND;
   842 
   843 	return TestStepResult();
   844 	}
   845 
   846 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   847 
   848 CCafHelperStep::~CCafHelperStep()
   849     {     
   850     }     
   851   
   852 CCafHelperStep::CCafHelperStep()
   853     {     
   854     SetTestStepName(KCAFHelperStep);     
   855     }     
   856       
   857       
   858 TVerdict CCafHelperStep::doTestStepL()     
   859     {     
   860     SetTestStepResult(EFail);     
   861 __UHEAP_MARK;     
   862          
   863     TInt result;     
   864          
   865     TInt error;     
   866     GetIntFromConfig(ConfigSection(),_L("error"),error);     
   867          
   868     TInt expectedValue;     
   869     GetIntFromConfig(ConfigSection(),_L("expected"),expectedValue);     
   870          
   871     // fileheader case.     
   872     TPtrC uri;     
   873     if (!GetStringFromConfig(ConfigSection(), _L("uri"), uri))     
   874         {     
   875         INFO_PRINTF1(_L("CCafHelper test : HeaderData case."));     
   876         result = TestHeaderDataCaseL(error);     
   877         }     
   878              
   879     else     
   880         {     
   881         TBool isFileName = EFalse;     
   882         GetBoolFromConfig(ConfigSection(),_L("flag"),isFileName);     
   883              
   884         // filehandle case     
   885         if(isFileName == EFalse)     
   886             {     
   887             INFO_PRINTF1(_L("CCafHelper test : FileHandle case."));     
   888             result = TestFileHandleCaseL(error, uri);     
   889             }     
   890              
   891         // filename case.     
   892         else     
   893             {     
   894             INFO_PRINTF1(_L("CCafHelper test : FileName case."));     
   895          
   896             CCAFHelper* helperObj = CCAFHelper::NewL();     
   897             CleanupStack::PushL(helperObj);     
   898              
   899             result = (*helperObj)().HandleCAFErrorL(error, uri);     
   900             CleanupStack::PopAndDestroy(helperObj);     
   901             }        
   902         }     
   903          
   904     if(result == expectedValue)     
   905         {     
   906         SetTestStepResult(EPass);     
   907         }     
   908              
   909 __UHEAP_MARKEND;     
   910              
   911     return TestStepResult();     
   912     }     
   913          
   914 TInt CCafHelperStep::TestFileHandleCaseL(TInt aError, const TDesC& aFileName)     
   915     {     
   916 __UHEAP_MARK;     
   917     RFs fs;     
   918     RFile fileHandle;     
   919     User::LeaveIfError(fs.Connect());     
   920     CleanupClosePushL(fs);     
   921     User::LeaveIfError(fileHandle.Open(fs, aFileName, EFileRead));     
   922     CleanupClosePushL(fileHandle);     
   923          
   924     CCAFHelper* helperObj = CCAFHelper::NewL();     
   925     CleanupStack::PushL(helperObj);     
   926     TInt result = (*helperObj)().HandleCAFErrorL(aError, fileHandle);     
   927     CleanupStack::PopAndDestroy(3, &fs);     
   928 __UHEAP_MARKEND;     
   929       
   930     return result;     
   931     }     
   932          
   933 TInt CCafHelperStep::TestHeaderDataCaseL(TInt aError)     
   934     {     
   935     _LIT8(KFileHeaderData,"W\0R\0M\0H\0E\0A\0D\0E\0R\0");     
   936       
   937 __UHEAP_MARK;        
   938     CCAFHelper* helperObj = CCAFHelper::NewL();     
   939     CleanupStack::PushL(helperObj);     
   940          
   941     TInt result = (*helperObj)().HandleCAFErrorL(aError, KFileHeaderData);     
   942     CleanupStack::PopAndDestroy(helperObj);     
   943 __UHEAP_MARKEND;     
   944       
   945     return result;     
   946     }     
   947          
   948 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT 
   949 
   950