installationservices/swi/test/tdataprovider/tdataproviderstep.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2005-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 * This file contains the various test-cases for testing  CCafSisDataProvider, CDesDataProvider and CFileSisDataProvider class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file tdataproviderstep.cpp
       
    22  @internalTechnology
       
    23 */
       
    24 
       
    25 #include <e32std.h>
       
    26 #include <e32base.h>
       
    27 #include <f32file.h>
       
    28 #include "tdataproviderstep.h"
       
    29 #include <e32def.h> 
       
    30 #include <utf.h>
       
    31 #include "sisinstallerrors.h"
       
    32 
       
    33 
       
    34 using namespace Swi;
       
    35 
       
    36 
       
    37 CDataProviderStep::~CDataProviderStep()
       
    38 	{
       
    39 	}
       
    40 
       
    41 CDataProviderStep::CDataProviderStep()
       
    42 	{
       
    43 	}
       
    44 
       
    45 TVerdict CDataProviderStep::doTestStepPreambleL()
       
    46 	{
       
    47 	INFO_PRINTF1(_L("DataProviderStep Read Test Step Preamble"));
       
    48 	SetTestStepResult(EPass);
       
    49 
       
    50 	return TestStepResult();
       
    51 	}
       
    52 
       
    53 /**
       
    54 Description: Creates the dataprovider object at runtime and does the operations
       
    55 exported by the dataprovider classes.  
       
    56 @return:TVerdict - returns EFail if there is a failure else EPass
       
    57 @internalTechnology:
       
    58 @test:
       
    59 */
       
    60 TVerdict CDataProviderStep::doTestStepL()
       
    61 	{
       
    62 
       
    63 	//Get the data provider type from the ini file
       
    64 	__UHEAP_MARK;
       
    65 	SetTestStepResult(EFail);
       
    66 
       
    67 	TInt providerType;
       
    68 	if(!GetIntFromConfig(ConfigSection(),_L("DataProviderType"),providerType))
       
    69 		{
       
    70 		ERR_PRINTF1(_L("DataProviderType not available in the ini file"));
       
    71 		return TestStepResult();
       
    72 		}
       
    73 
       
    74 	TPtrC data;
       
    75 	if(!GetStringFromConfig(ConfigSection(),_L("Data"),data))
       
    76 		{
       
    77 		ERR_PRINTF1(_L("DataProviderType not available in the ini file"));
       
    78 		return TestStepResult();
       
    79 		}
       
    80 	
       
    81 	TInt opType;	
       
    82 	if(!GetIntFromConfig(ConfigSection(),_L("Operation"),opType))
       
    83 		{
       
    84 		ERR_PRINTF1(_L("Operation Type not available in the ini file"));
       
    85 		return TestStepResult();
       
    86 		}
       
    87 		
       
    88 
       
    89 	MSisDataProvider *sisDataProvider = NULL ;
       
    90 	RFs fsSession;
       
    91 	User::LeaveIfError(fsSession.Connect());
       
    92 	CleanupClosePushL(fsSession); 
       
    93 	switch(providerType)
       
    94 		{	
       
    95 		case EDesSisDataProvider:
       
    96 			{
       
    97 			HBufC8 *inData  = HBufC8::NewLC(data.Length());
       
    98 			inData->Des().Copy(data);
       
    99 			//creates the DesSisdataprovider obj
       
   100 			sisDataProvider = CDesDataProvider::NewL(*inData);
       
   101 			DoReadL(sisDataProvider, opType ); 
       
   102 			CleanupStack::PopAndDestroy();
       
   103 			break;
       
   104 			}
       
   105 		case EFileSisDataProvider:
       
   106 			{
       
   107 			TInt inputDataType;
       
   108 			if(!GetIntFromConfig(ConfigSection(),_L("inputdatatype"),inputDataType))
       
   109 				{
       
   110 				ERR_PRINTF1(_L("Input Data type value not available in the ini file"));
       
   111 				return TestStepResult();
       
   112 				}
       
   113 			switch(inputDataType)
       
   114 				{
       
   115 				case EFilename:
       
   116 					{
       
   117 					//creates the FileSisDataProvider object
       
   118 					sisDataProvider = CFileSisDataProvider::NewL(fsSession,data);
       
   119 					DoReadL(sisDataProvider, opType ); 
       
   120 					break;
       
   121 					}
       
   122 				case EFileHandle:
       
   123 					{			
       
   124 					RFile file;
       
   125 	    				User::LeaveIfError(file.Open(fsSession,data, EFileRead | EFileStream | EFileShareReadersOnly));
       
   126 	    				CleanupClosePushL(file);
       
   127 	    				//creates the FileSisDataProvider object
       
   128 	    				sisDataProvider = CFileSisDataProvider::NewL(file);
       
   129 	    	    			DoReadL(sisDataProvider, opType ); 
       
   130 	    				CleanupStack::PopAndDestroy();		
       
   131 					break;
       
   132 					}				
       
   133 				default:
       
   134 					{
       
   135 						ERR_PRINTF1(_L("Unknown Step type"));
       
   136 						break;
       
   137 					}				
       
   138 				}				
       
   139 			break;
       
   140 			}
       
   141 		case ECafSisDataProvider:
       
   142 			{
       
   143 			TInt inputStepType;
       
   144 			if(!GetIntFromConfig(ConfigSection(),_L("inputsteptype"),inputStepType))
       
   145 				{
       
   146 				ERR_PRINTF1(_L("Input Step type value not available in the ini file"));
       
   147 				return TestStepResult();
       
   148 				}
       
   149 			switch(inputStepType)
       
   150 				{
       
   151 				case EReadStep:
       
   152 					{
       
   153 					HBufC8 *inData  = HBufC8::NewLC(data.Length());
       
   154 					inData->Des().Copy(data);
       
   155 					TPtr8 pData(inData->Des());
       
   156 					//creates the CafSisDataProvider object
       
   157 					sisDataProvider = CCafSisDataProvider::NewL(data);
       
   158 					sisDataProvider->Read(pData);
       
   159 					SetTestStepResult(EPass);
       
   160 					CleanupStack::PopAndDestroy();
       
   161 					break;
       
   162 					}
       
   163 				case EOpenStep:
       
   164 					{			
       
   165 					TInt err;
       
   166 					//creates the CafSisDataProvider object
       
   167 					sisDataProvider = CCafSisDataProvider::NewL(data);
       
   168 					sisDataProvider->OpenDrmContentL(ContentAccess::EUnknown);
       
   169 					TRAP(err,sisDataProvider->OpenDrmContentL(ContentAccess::EUnknown)); 
       
   170 					if(err == KErrNone)
       
   171 						{
       
   172 						SetTestStepResult(EPass);
       
   173 						}
       
   174 					break;
       
   175 					}
       
   176 				case ESeekStep:
       
   177 					{
       
   178 					//creates the CafSisDataProvider object
       
   179 					sisDataProvider = CCafSisDataProvider::NewL(data);
       
   180 					sisDataProvider->OpenDrmContentL(ContentAccess::EUnknown);
       
   181 					DoReadL(sisDataProvider,opType);
       
   182 					}
       
   183 				default:
       
   184 					{
       
   185 					ERR_PRINTF1(_L("Unknown Data type"));
       
   186 					break;
       
   187 					}
       
   188 				}
       
   189 			break;
       
   190 			}
       
   191 		default:
       
   192 			{
       
   193 			ERR_PRINTF1(_L("Unknown Provider type"));
       
   194 			break;
       
   195 			}
       
   196 		}
       
   197 	if(sisDataProvider)
       
   198 		{
       
   199 		delete sisDataProvider ;
       
   200 		}
       
   201 	CleanupStack::PopAndDestroy();
       
   202 	__UHEAP_MARKEND;
       
   203 	return TestStepResult();
       
   204 	}
       
   205 
       
   206 
       
   207 /**
       
   208 Description: Generic testing function for all three dataprovider types,exported by the dataprovider classes.  
       
   209 @return:TVerdict - returns EFail if there is a failure else EPass
       
   210 @internalTechnology:
       
   211 @test:
       
   212 */
       
   213 void CDataProviderStep::DoReadL(MSisDataProvider *aSisDataProvider,	const TInt& aOpType ) 
       
   214 	{
       
   215 	TInt seek;
       
   216 	TPtrC pPosition;
       
   217 	TInt64 position = 0;
       
   218 	
       
   219 	SetTestStepResult(EFail);
       
   220 	
       
   221 	if(aOpType == EReadAndSeek || aOpType == EReadSpecificLength)	
       
   222 		{
       
   223 		if(!GetIntFromConfig(ConfigSection(),_L("seek"),seek))
       
   224 			{
       
   225 			ERR_PRINTF1(_L("Seek value not available in the ini file"));
       
   226 			return;
       
   227 			}
       
   228 		if(!GetStringFromConfig(ConfigSection(),_L("position"),pPosition))
       
   229 			{
       
   230 			ERR_PRINTF1(_L("Position value not available in the ini file"));
       
   231 			return;
       
   232 			}
       
   233 		else
       
   234 			{
       
   235 			TLex16 lex(pPosition);
       
   236 			lex.Val(position);
       
   237 			}					
       
   238 		}
       
   239 		
       
   240 	TInt length = 0;
       
   241 	if(aOpType == EReadSpecificLength)	
       
   242 		{
       
   243 		if(!GetIntFromConfig(ConfigSection(),_L("length"),length))
       
   244 			{
       
   245 			ERR_PRINTF1(_L("Length value not available in the ini file"));
       
   246 			return;
       
   247 			}		
       
   248 		}
       
   249 				
       
   250 	TInt bufSize = 0;
       
   251 	if(!GetIntFromConfig(ConfigSection(),_L("bufsize"),bufSize))
       
   252 		{
       
   253 		ERR_PRINTF1(_L("buf size not available in the ini file"));
       
   254 		return;
       
   255 		}	
       
   256 			
       
   257 	TPtrC expectedSisData;
       
   258 	if(!GetStringFromConfig(ConfigSection(),_L("expecteddata"),expectedSisData))
       
   259 		{
       
   260 		ERR_PRINTF1(_L("expecteddata not available in the ini file"));
       
   261 		return;
       
   262 		}
       
   263 
       
   264 	HBufC8 *outData  = HBufC8::NewLC(bufSize);
       
   265 	TPtr8 pdata(outData->Des());
       
   266 	pdata.SetLength(bufSize);
       
   267 	TInt err = 0;
       
   268 	switch(aOpType)
       
   269 		{
       
   270 		case EReadAndSeek:
       
   271 			{
       
   272 			//this case will carry on into EReadOnly case
       
   273 			TInt64 pos = (TInt64)position; 
       
   274 			err = aSisDataProvider->Seek(static_cast<TSeek>(seek),pos);
       
   275 			if (err !=  KErrNone )
       
   276 				{
       
   277 				ERR_PRINTF2(_L("Seek returns Error=%d"),err);
       
   278 				_LIT8(KERR , "%d");
       
   279 				pdata.Format(KERR() , err);
       
   280 				VerifyResult(pdata ,expectedSisData);
       
   281 				break;
       
   282 				}
       
   283 			}
       
   284 		case EReadOnly:
       
   285 			{
       
   286 			err = aSisDataProvider->Read(pdata);
       
   287 			if(err == KErrSISFieldBufferTooShort)
       
   288 				{
       
   289 				ERR_PRINTF1(_L("Seek returns  KErrSISFieldBufferTooShort"));
       
   290 				_LIT8(KERR , "%d");
       
   291 				pdata.Format(KERR() , err);
       
   292 				VerifyResult(pdata ,expectedSisData);
       
   293 				break;	
       
   294 				}
       
   295 			VerifyResult(pdata ,expectedSisData);
       
   296 			break;	
       
   297 			}
       
   298 		case EReadSpecificLength:
       
   299 			{
       
   300 			TInt64 pos = (TInt64)position; 
       
   301 			err = aSisDataProvider->Seek(static_cast<TSeek>(seek),pos);
       
   302 			if (err !=  KErrNone )
       
   303 				{
       
   304 				ERR_PRINTF2(_L("Seek returns Error=%d"),err);
       
   305 				_LIT8(KERR , "%d");
       
   306 				pdata.Format(KERR() , err);
       
   307 				VerifyResult(pdata ,expectedSisData);
       
   308 				break;
       
   309 				}
       
   310 			err = aSisDataProvider->Read(pdata , length);
       
   311 			if(err == KErrSISFieldBufferTooShort)
       
   312 				{
       
   313 				ERR_PRINTF1(_L("Seek returns  KErrSISFieldBufferTooShort"));
       
   314 				_LIT8(KERR , "%d");
       
   315 				pdata.Format(KERR() , err);
       
   316 				VerifyResult(pdata ,expectedSisData);
       
   317 				break;
       
   318 				}
       
   319 			VerifyResult(pdata ,expectedSisData);
       
   320 			break;	
       
   321 			}
       
   322 		default:
       
   323 			{
       
   324 			ERR_PRINTF1(_L("Unknown Operation type in the ini "));
       
   325 			SetTestStepResult(EFail);	
       
   326 			break;
       
   327 			}
       
   328 		}	
       
   329 		CleanupStack::PopAndDestroy();		
       
   330 	}
       
   331 
       
   332 TVerdict CDataProviderStep::doTestStepPostambleL()
       
   333 	{
       
   334 	INFO_PRINTF1(_L("DataProviderStep Read Test Step Postamble"));	
       
   335 	return TestStepResult();
       
   336 	}
       
   337 	
       
   338 void  CDataProviderStep::VerifyResult (const TPtr8& aData , const TPtrC16& aExpectedSisData)
       
   339 	{
       
   340 	TBuf16<KMAXBUF> temp ;	
       
   341 	temp.Copy(aData);
       
   342 	if( aExpectedSisData.Compare(temp) == 0)
       
   343 		{
       
   344 		INFO_PRINTF1(_L("Verify Result Passed"));	
       
   345 		SetTestStepResult(EPass);	
       
   346 		}
       
   347 	else
       
   348 		{
       
   349 		INFO_PRINTF1(_L("Verify Result failed"));	
       
   350 		SetTestStepResult(EFail);
       
   351 		}
       
   352 	}
       
   353 	
       
   354