messagingfw/msgtestfw/TestActions/Drm/src/CMtfTestActionCheckDrmMetaData.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // CheckDrmMetaData
       
    17 // [Action Parameters]
       
    18 // metaDataFile			input		HBufC, path and name of the meta data file to check
       
    19 // numberOfFiles		input		TInt, number of expected meta data files
       
    20 // [Action Description]
       
    21 // CheckDrmReceipt Test Action is intended to check the DRM meta data file produced
       
    22 // by the DRM test agent and verify its contents
       
    23 // [APIs Used]	
       
    24 // RFile::Open
       
    25 // RFile::Read
       
    26 // TDesC8::CompareF
       
    27 // __ACTION_INFO_END__
       
    28 //
       
    29 
       
    30 //! @file
       
    31 
       
    32 #include "CMtfTestActionCheckDrmMetaData.h"
       
    33 
       
    34 #include "CMtfTestCase.h"
       
    35 #include "CMtfTestActionParameters.h"
       
    36 
       
    37 _LIT8(KContentTypeString, "Content-Type: application/");
       
    38 _LIT(KFileFilter, "*.txt");
       
    39 
       
    40 /**
       
    41   Function : NewL
       
    42   Description : 
       
    43   @internalTechnology
       
    44   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    45   @param : aActionParams - CMtfTestActionParameters 
       
    46   @return : CMtfTestAction* - a base class pointer to the newly created CMtfTestActionCheckDrmMetaData object
       
    47   @pre none
       
    48   @post none
       
    49 */
       
    50 CMtfTestAction* CMtfTestActionCheckDrmMetaData::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    51 {
       
    52 	CMtfTestActionCheckDrmMetaData* self = new (ELeave) CMtfTestActionCheckDrmMetaData(aTestCase);
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL(aActionParameters);
       
    55 	CleanupStack::Pop(self);
       
    56 	return self;
       
    57 }
       
    58 
       
    59 /**
       
    60   Function : CMtfTestActionCheckDrmMetaData
       
    61   Description : Constructor
       
    62   @internalTechnology
       
    63   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    64   @return : N/A
       
    65   @pre none
       
    66   @post none
       
    67 */
       
    68 CMtfTestActionCheckDrmMetaData::CMtfTestActionCheckDrmMetaData(CMtfTestCase& aTestCase) : CMtfSynchronousTestAction(aTestCase)
       
    69 {
       
    70 }
       
    71 	
       
    72 /**
       
    73   Function : ~CMtfTestActionCheckDrmMetaData
       
    74   Description : Destructor
       
    75   @internalTechnology
       
    76   @param :
       
    77   @return : 
       
    78   @pre 
       
    79   @post 
       
    80 */
       
    81 CMtfTestActionCheckDrmMetaData::~CMtfTestActionCheckDrmMetaData()
       
    82 {
       
    83 }
       
    84 
       
    85 /**
       
    86   Function : ExecuteActionL
       
    87   Description : Entry point for the this test action in the test framework
       
    88   @internalTechnology
       
    89   @param : none
       
    90   @return : void
       
    91   @pre none 
       
    92   @post none
       
    93 */
       
    94 void CMtfTestActionCheckDrmMetaData::ExecuteActionL()
       
    95 {
       
    96 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCheckDrmMetaData);
       
    97 	HBufC* metaDataFile = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(0));
       
    98 	TInt numberOfFiles = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(1));
       
    99 	
       
   100 	RFs fs;
       
   101 	RFile file;
       
   102 	User::LeaveIfError(fs.Connect());
       
   103 	CleanupClosePushL(fs);
       
   104 	
       
   105 	// Get the contents of the directory
       
   106 	CDir* dir = NULL;
       
   107 	
       
   108 	{
       
   109 		TFileName dirString;
       
   110 		dirString.Append(*metaDataFile);
       
   111 		dirString.Append(KFileFilter);
       
   112 		
       
   113 		User::LeaveIfError(fs.GetDir(dirString, KEntryAttMaskSupported, ESortByName, dir));
       
   114 		CleanupStack::PushL(dir);
       
   115 	}
       
   116 	
       
   117 	TBool success = ETrue;
       
   118 	TInt count = dir->Count();
       
   119 	
       
   120 	if (count != numberOfFiles)
       
   121 	{
       
   122 		// no meta data generated. failed.
       
   123 		TestCase().ERR_PRINTF3(_L("CMtfTestActionCheckDrmMetaData: FAILED! Incorrect number of files, expected [%d], found [%d]"), numberOfFiles, count);
       
   124 		success = EFalse;
       
   125 	}
       
   126 	else
       
   127 	{
       
   128 		for (TInt i = 0; i < count; i++)
       
   129 		{
       
   130 			// open the file
       
   131 			TFileName fileName;
       
   132 			fileName.Append(*metaDataFile);
       
   133 			fileName.Append((*dir)[i].iName);
       
   134 			
       
   135 			User::LeaveIfError(file.Open(fs, fileName, EFileShareAny | EFileRead));
       
   136 			CleanupClosePushL(file);
       
   137 			
       
   138 			// Parse the file and verify its contents
       
   139 			TInt fileSize = 0;
       
   140 			User::LeaveIfError(file.Size(fileSize));
       
   141 			
       
   142 			HBufC8* fileContent = HBufC8::NewLC(fileSize);
       
   143 			TPtr8 des = fileContent->Des();
       
   144 			
       
   145 			User::LeaveIfError(file.Read(des, fileSize));
       
   146 			
       
   147 			if (fileContent->FindF(KContentTypeString) == KErrNotFound)
       
   148 			{
       
   149 				TestCase().ERR_PRINTF1(_L("CMtfTestActionCheckDrmMetaData: FAILED! Content-Type not found. Meta-data file corrupt!"));
       
   150 				success = EFalse;
       
   151 			}
       
   152 			
       
   153 			CleanupStack::PopAndDestroy(2); // file, fileContent
       
   154 		}
       
   155 	}
       
   156 
       
   157 	if (count > 0)
       
   158 	{
       
   159 		// delete the meta data files
       
   160 		for (TInt i = 0; i < count; i++)
       
   161 		{
       
   162 			TFileName fileName;
       
   163 			fileName.Append(*metaDataFile);
       
   164 			fileName.Append((*dir)[i].iName);
       
   165 			TInt err = fs.Delete(fileName);
       
   166 			if (err != KErrNone)
       
   167 			{
       
   168 				TestCase().ERR_PRINTF2(_L("CMtfTestActionCheckDrmMetaData: FAILED! Couldn't delete Meta-data file: [%d]!"), err);
       
   169 				success = EFalse;
       
   170 			}
       
   171 		}
       
   172 	}
       
   173 	
       
   174 	CleanupStack::PopAndDestroy(2); // fs, dir
       
   175 	
       
   176 	if (success)
       
   177 	{
       
   178 		TestCase().INFO_PRINTF1(_L("CMtfTestActionCheckDrmMetaData: Meta-data check successful. Test case PASSED."));
       
   179 		TestCase().SetTestStepResult(EPass);
       
   180 	}
       
   181 	else
       
   182 	{
       
   183 		TestCase().ERR_PRINTF1(_L("CMtfTestActionCheckDrmMetaData: Meta-data check failed. Test case FAILED."));
       
   184 		TestCase().SetTestStepResult(EFail);
       
   185 	}
       
   186 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCheckDrmMetaData);
       
   187 	TestCase().ActionCompletedL(*this);
       
   188 }