installationservices/swi/test/tsisfile/steps/basestep.cpp
changeset 0 ba25891c3a9e
child 58 67f2119dc623
child 62 5cc91383ab1e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2002-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 "tsisstep.h"
       
    20 #include "filesisdataprovider.h"
       
    21 #include "dessisdataprovider.h"
       
    22 
       
    23 #include "siscontents.h"
       
    24 #include "siscontroller.h"
       
    25 #include "sisparser.h"
       
    26 #include "sisptrprovider.h"
       
    27 
       
    28 _LIT(KFileNameKey, "filename");
       
    29 _LIT(KExpectedResultKeyFormat, "result%d");
       
    30 const TInt KResultKeyMaxLength = 8;
       
    31 const TInt KResultKeyMaxNum = 99;
       
    32 const TInt KErrMaxLength = 256; // equivalent to KEikErrorResolverMaxTextLength = 256;
       
    33 using namespace Swi;
       
    34 using namespace Swi::Sis;
       
    35 
       
    36 
       
    37 _LIT(KTestDataDir, "z:\\tswi\\tsis\\data\\");
       
    38 
       
    39 namespace Swi
       
    40 {
       
    41   namespace Sis
       
    42   { 
       
    43     namespace Test
       
    44     { 
       
    45     	CParserTestStep::~CParserTestStep()
       
    46     		{
       
    47     		if (iDataProvider)
       
    48     			{
       
    49     			delete iDataProvider;
       
    50     			}
       
    51     		iExpectedResults.Close();
       
    52     		iFs.Close();
       
    53     		delete iControllerData;
       
    54     		}
       
    55     		
       
    56 		void CParserTestStep::SetTestStepResult(TInt result)
       
    57 			{
       
    58 			TBool isExpected = EFalse;
       
    59 			
       
    60 			for (TInt k = 0; k < iExpectedResults.Count(); k++)
       
    61 				{
       
    62 				if (result == iExpectedResults[k])
       
    63 					{
       
    64 					isExpected = ETrue;
       
    65 					}
       
    66 				
       
    67 				}
       
    68 			
       
    69 			if (!isExpected)
       
    70 				{
       
    71 				INFO_PRINTF2(_L("return set to %d"), result);				
       
    72 				CTestStep::SetTestStepResult(EFail);
       
    73 				}
       
    74 			else 
       
    75 				{
       
    76 				CTestStep::SetTestStepResult(EPass);								
       
    77 				}
       
    78 								
       
    79 			switch (result)
       
    80 				{
       
    81 				case EInconclusive :
       
    82 					{
       
    83 					CTestStep::SetTestStepResult(EInconclusive);									
       
    84 					}
       
    85 					break;
       
    86 														
       
    87 				case EAbort :
       
    88 					{
       
    89 					CTestStep::SetTestStepResult(EAbort);				
       
    90 					}
       
    91 					break;					
       
    92 					
       
    93 				default :
       
    94 					{
       
    95 					// Nothing 
       
    96 					}
       
    97 				}
       
    98 			}
       
    99     		
       
   100     		
       
   101 		CContents* CParserTestStep::GetContentsL()
       
   102 			{
       
   103 			HBufC* fileNameBuf = HBufC::NewMaxLC(KMaxFileName);
       
   104 			TPtrC fileNamePtr(fileNameBuf->Des());
       
   105 			TBool found = GetStringFromConfig(ConfigSection(), KFileNameKey, fileNamePtr);
       
   106 	
       
   107 			if (!found)
       
   108 				{				
       
   109 				ERR_PRINTF1(_L("Missing file name key in .ini file!"));	
       
   110 				SetTestStepResult(EInconclusive);
       
   111 				User::Leave(KErrNotFound);				
       
   112 				}
       
   113 			
       
   114 			TFileName fileName(KTestDataDir);
       
   115 
       
   116 			fileName.Append(fileNamePtr);
       
   117 			CleanupStack::PopAndDestroy(fileNameBuf);
       
   118 				
       
   119 			TInt err = iFs.Connect();
       
   120 			if (err != KErrNone)
       
   121 				{
       
   122 				ERR_PRINTF1(_L("Failed to open a file session"));
       
   123 				SetTestStepResult(EInconclusive);	
       
   124 				return NULL;				
       
   125 				}
       
   126 			iDataProvider = CFileSisDataProvider::NewL(iFs, fileName);
       
   127 			
       
   128 			CContents* contents = NULL;
       
   129 			TRAP(err, contents = Parser::ContentsL(*iDataProvider));
       
   130 			CleanupStack::PushL(contents);
       
   131 			if (err != KErrNone)
       
   132 				{
       
   133 				if (err == KErrCorrupt)
       
   134 					{
       
   135 					ERR_PRINTF1(_L("Failed to parse contents data: KErrCorrupt"));
       
   136 					}
       
   137 				else
       
   138 					{
       
   139 					ERR_PRINTF2(_L("Failed to read contents data: error %d"), err);					
       
   140 					}
       
   141 				SetTestStepResult(err);		
       
   142 				User::Leave(err);
       
   143 				}
       
   144 			TRAP(err, contents->CheckCrcL());
       
   145 			if (err == KErrCorrupt)
       
   146 				{
       
   147 				ERR_PRINTF1(_L("Crc values in SIS file are incorrect"));
       
   148 				SetTestStepResult(err);		
       
   149 				User::Leave(err);
       
   150 				}
       
   151 			CleanupStack::Pop(contents);	
       
   152 			return contents;								
       
   153 			}
       
   154 			
       
   155 	CController* CParserTestStep::GetControllerL(CContents& contents, TBool aUseInPlaceParse)
       
   156 		{
       
   157 		TRAPD(err, iControllerData = contents.ReadControllerL());
       
   158 
       
   159 		if (err != KErrNone)
       
   160 			{
       
   161 			ERR_PRINTF2(_L("Failed to read controller data: error %d"), err);
       
   162 			SetTestStepResult(err);
       
   163 			User::Leave(err);
       
   164 			}
       
   165 		
       
   166 		CController* controller = NULL;
       
   167 		
       
   168 		if (aUseInPlaceParse)
       
   169 			{
       
   170 			TPtrProvider controllerProvider(iControllerData->Des());
       
   171 			TRAP(err, controller = CController::NewL(controllerProvider));
       
   172 			}
       
   173 		else
       
   174 			{
       
   175 
       
   176 			CDesDataProvider* controllerProvider= CDesDataProvider::NewLC(*iControllerData);
       
   177 			TRAP(err, controller = CController::NewL(*controllerProvider));
       
   178 			CleanupStack::PopAndDestroy(controllerProvider);
       
   179 			}
       
   180 			
       
   181 		CleanupStack::PushL(controller);
       
   182 			
       
   183 		if (err != KErrNone)
       
   184 			{
       
   185 			if (err == KErrCorrupt)
       
   186 				{
       
   187 				ERR_PRINTF1(_L("Failed to parse controller data: KErrCorrupt"));
       
   188 				}
       
   189 			else
       
   190 				{
       
   191 				ERR_PRINTF2(_L("Failed to parse controller data: error %d"), err);
       
   192 				}				
       
   193 			SetTestStepResult(err);
       
   194 			User::Leave(err);
       
   195 			}
       
   196 			
       
   197 		CleanupStack::Pop(controller);			
       
   198 		return controller;
       
   199 		}
       
   200 				
       
   201 	EXPORT_C enum TVerdict CParserTestStep::doTestStepPreambleL()
       
   202 		{
       
   203 		SetExpectedResult();
       
   204 		return TestStepResult();		
       
   205 		}
       
   206 
       
   207 
       
   208 	void CParserTestStep::SetExpectedResult()
       
   209 		{
       
   210 		TInt result = KErrNone;
       
   211 		TBuf<KResultKeyMaxLength> resultKey;
       
   212 		TBool found = ETrue;
       
   213 		
       
   214 		for (TInt i = 1; i <= KResultKeyMaxNum && found; i++)
       
   215 			{
       
   216 			resultKey.Format(KExpectedResultKeyFormat, i);
       
   217 			found = GetIntFromConfig(ConfigSection(), resultKey, result);
       
   218 			if (found)
       
   219 				User::LeaveIfError(iExpectedResults.Append(result));
       
   220 			}
       
   221 	
       
   222 		if (iExpectedResults.Count() == 0)
       
   223 			{				
       
   224 			WARN_PRINTF1(_L("Missing Expected result defaulting to KErrNone"));	
       
   225 			}		
       
   226 		else
       
   227 			{
       
   228 			TBuf<128> mymsg;
       
   229 
       
   230 			TBuf<KErrMaxLength> errText;
       
   231 			for (TInt k = 0; k < iExpectedResults.Count(); k++)
       
   232 				{
       
   233 				if (iExpectedResults[k] != KErrNone)
       
   234 					{
       
   235 					errText.Format(_L("%d"), iExpectedResults[k]);
       
   236 					}
       
   237 				else
       
   238 					{
       
   239 					errText.Format(_L("KErrNone"));
       
   240 					}
       
   241 					
       
   242 				mymsg.Format(_L("Expected result: %S (%d)"), &errText, iExpectedResults[k]);
       
   243 
       
   244 				INFO_PRINTF1(mymsg);				
       
   245 				}
       
   246 			}
       
   247 		}
       
   248 	} // namespace Test
       
   249 	  
       
   250   } // namespace Sis
       
   251 	
       
   252 } // namespace Swi