installationservices/swcomponentregistry/test/tscr/source/installloghistorysteps.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 2008-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 "installloghistorysteps.h"
       
    20 #include <scs/cleanuputils.h>
       
    21 #include "tscrdefs.h"
       
    22 #include <usif/scr/screntries.h>
       
    23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include "screntries_internal.h"
       
    25 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    26 
       
    27 using namespace Usif;
       
    28 
       
    29 _LIT(KScrLogFile, "!:\\private\\10285bc0\\scr.log");
       
    30 
       
    31 // -----------CScrGetLogEntriesStep-----------------
       
    32 
       
    33 CScrGetLogEntriesStep::CScrGetLogEntriesStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
    34 	{
       
    35 	}
       
    36 
       
    37 void CScrGetLogEntriesStep::ImplTestStepPreambleL()
       
    38 	{
       
    39 	CScrTestStep::ImplTestStepPreambleL();
       
    40 	}
       
    41 
       
    42 void CScrGetLogEntriesStep::GetLogEntriesFromConfigL(RPointerArray<CScrLogEntry>& aLogEntries)
       
    43 	{
       
    44 	TInt logCount = 0;
       
    45 	if (!GetIntFromConfig(ConfigSection(), KLogsCountParamName, logCount))
       
    46 		PrintErrorL(_L("Logs count was not found!"), KErrNotFound);
       
    47 		
       
    48 	if (logCount < 0)
       
    49 			PrintErrorL(_L("Logs count is negative!"), KErrNotFound);
       
    50 	
       
    51 	TBuf<MAX_SCR_PARAM_LENGTH> componentNameParam, swTypeNameParam, versionParam, operationTypeParam, globalIdParam;
       
    52 	
       
    53 	for(TInt index=0; index < logCount; ++index)	
       
    54 		{
       
    55 		componentNameParam = KComponentName;
       
    56 		swTypeNameParam = KSoftwareTypeName;
       
    57 		versionParam = KVersionName;
       
    58 		operationTypeParam = KOperationType;
       
    59 		globalIdParam = KGlobalIdName;
       
    60 			
       
    61 		GenerateIndexedAttributeNameL(componentNameParam, index);
       
    62 		GenerateIndexedAttributeNameL(swTypeNameParam, index);
       
    63 		GenerateIndexedAttributeNameL(versionParam, index);
       
    64 		GenerateIndexedAttributeNameL(operationTypeParam, index);
       
    65 		GenerateIndexedAttributeNameL(globalIdParam, index);
       
    66 		
       
    67 		TPtrC componentName;
       
    68 		if (!GetStringFromConfig(ConfigSection(), componentNameParam, componentName))
       
    69 			{
       
    70 			ERR_PRINTF2(_L("The component name param %S could not be found in configuration."), &componentNameParam);
       
    71 			User::Leave(KErrNotFound);
       
    72 			}
       
    73 		
       
    74 		TPtrC swTypeName;
       
    75 		if (!GetStringFromConfig(ConfigSection(), swTypeNameParam, swTypeName))
       
    76 			{
       
    77 			ERR_PRINTF2(_L("The software type name param %S could not be found in configuration."), &swTypeNameParam);
       
    78 			User::Leave(KErrNotFound);
       
    79 			}
       
    80 		
       
    81 		TPtrC version;
       
    82 		if (!GetStringFromConfig(ConfigSection(), versionParam, version))
       
    83 			{
       
    84 			ERR_PRINTF2(_L("The version param %S could not be found in configuration."), &versionParam);
       
    85 			User::Leave(KErrNotFound);
       
    86 			}
       
    87 		
       
    88 		TInt operationType;
       
    89 		if (!GetIntFromConfig(ConfigSection(), operationTypeParam, operationType))
       
    90 			{
       
    91 			ERR_PRINTF2(_L("The operation type param %S could not be found in configuration."), &operationTypeParam);
       
    92 			User::Leave(KErrNotFound);
       
    93 			}
       
    94 		
       
    95 		TPtrC globalId;
       
    96 		if (!GetStringFromConfig(ConfigSection(), globalIdParam, globalId))
       
    97 			{
       
    98 			ERR_PRINTF2(_L("The global id param %S could not be found in configuration."), &globalIdParam);
       
    99 			User::Leave(KErrNotFound);
       
   100 			}
       
   101 		
       
   102 		CScrLogEntry *logEntry = CScrLogEntry::NewLC(componentName, swTypeName, globalId, version, static_cast<TScrComponentOperationType>(operationType));
       
   103 		aLogEntries.AppendL(logEntry);
       
   104 		CleanupStack::Pop(logEntry); // Ownership is transferred
       
   105 		}
       
   106 	}
       
   107 
       
   108 TBool operator ==(CScrLogEntry& aLhsEntry, CScrLogEntry& aRhsEntry)
       
   109 	{
       
   110 	return (aLhsEntry.ComponentName() == aRhsEntry.ComponentName() && 
       
   111 			aLhsEntry.SoftwareTypeName() == aRhsEntry.SoftwareTypeName()&& 
       
   112 			aLhsEntry.ComponentVersion() == aRhsEntry.ComponentVersion()&&
       
   113 			aLhsEntry.GlobalId() == aRhsEntry.GlobalId()&&
       
   114 			aLhsEntry.OperationType() == aRhsEntry.OperationType());
       
   115 	}
       
   116 
       
   117 TBool operator !=(CScrLogEntry& aLhsEntry, CScrLogEntry& aRhsEntry)
       
   118 	{
       
   119 	return !(aLhsEntry == aRhsEntry);
       
   120 	}
       
   121 
       
   122 TBool CScrGetLogEntriesStep::CompareLogEntriesL(RPointerArray<CScrLogEntry>& aFoundLogEntries, RPointerArray<CScrLogEntry>& aExpectedLogEntries)
       
   123 	{
       
   124 	TInt foundEntriesCount = aFoundLogEntries.Count();
       
   125 	TInt expectedEntriesCount = aExpectedLogEntries.Count();
       
   126 		
       
   127 	if (foundEntriesCount != expectedEntriesCount)
       
   128 		{
       
   129 		ERR_PRINTF3(_L("The number of expected log entries %d did not match the number of provided log entries %d."), expectedEntriesCount, foundEntriesCount);
       
   130 		return EFalse; 
       
   131 		}
       
   132 		
       
   133 	for (TInt i = 0; i < foundEntriesCount; ++i)
       
   134 		{
       
   135 		if (*aFoundLogEntries[i] != *aExpectedLogEntries[i])
       
   136 			{
       
   137             ERR_PRINTF2(_L("Log entry %d did not match."), i);
       
   138             ERR_PRINTF2(_L("current device lang is %d"), User::Language());
       
   139 			
       
   140 			ERR_PRINTF6(_L("found values are name %S, type %S, version %S, globalid %S, optype is %d"),
       
   141                             &(aFoundLogEntries[i]->ComponentName()),
       
   142                             &(aFoundLogEntries[i]->SoftwareTypeName()), 
       
   143                             &(aFoundLogEntries[i]->ComponentVersion()), 
       
   144                             &(aFoundLogEntries[i]->GlobalId()),
       
   145                             aFoundLogEntries[i]->OperationType());
       
   146 
       
   147             ERR_PRINTF6(_L("expected values were name %S, type %S, version %S, globalid %S, optype is %d"),
       
   148 							&(aExpectedLogEntries[i]->ComponentName()) ,
       
   149                             &(aExpectedLogEntries[i]->SoftwareTypeName()) , 
       
   150                             &(aExpectedLogEntries[i]->ComponentVersion()), 
       
   151                             &(aExpectedLogEntries[i]->GlobalId()), 
       
   152                             aExpectedLogEntries[i]->OperationType() );
       
   153             return EFalse;
       
   154 			}
       
   155 		}	
       
   156 	return ETrue;
       
   157 	}
       
   158 	
       
   159 void CScrGetLogEntriesStep::ImplTestStepL()
       
   160 	{
       
   161 	TBool isLogFileReadOnly = EFalse; 
       
   162 	(void)GetBoolFromConfig(ConfigSection(), _L("LogFileReadOnly"), isLogFileReadOnly); // since this is an optional param, ignore the return code.
       
   163 	if(isLogFileReadOnly)
       
   164 		{
       
   165 		RBuf fn;
       
   166 		fn.CreateL(KMaxFileName);
       
   167 		fn.CleanupClosePushL();
       
   168 		fn.Copy(KScrLogFile);
       
   169 		RFs fs;
       
   170 		User::Leave(fs.Connect());
       
   171 		CleanupClosePushL(fs);
       
   172 		fn[0] = fs.GetSystemDriveChar();
       
   173 		User::LeaveIfError(fs.SetAtt(fn, KEntryAttReadOnly, 0));
       
   174 		CleanupStack::PopAndDestroy(2, &fn); // fn, fs
       
   175 		}
       
   176 
       
   177 	RPointerArray<CScrLogEntry> expectedLogEntries;
       
   178 	CleanupResetAndDestroyPushL(expectedLogEntries);
       
   179 	GetLogEntriesFromConfigL(expectedLogEntries);
       
   180 	
       
   181 	TPtrC *ptrSwTypeName = NULL;
       
   182 	TPtrC swTypeName;
       
   183 	if (GetStringFromConfig(ConfigSection(), KSoftwareTypeName, swTypeName))
       
   184 		{
       
   185 		ptrSwTypeName = &swTypeName; 
       
   186 		}
       
   187 	
       
   188 	RPointerArray<CScrLogEntry> retrievedLogEntries;
       
   189 	CleanupResetAndDestroyPushL(retrievedLogEntries);
       
   190 	
       
   191 	iScrSession.RetrieveLogEntriesL(retrievedLogEntries, ptrSwTypeName);
       
   192 	
       
   193 	if (!CompareLogEntriesL(retrievedLogEntries, expectedLogEntries))
       
   194 		{
       
   195 		ERR_PRINTF1(_L("The retrieved log entries are different from the expected ones."));
       
   196 		SetTestStepResult(EFail);
       
   197 		}
       
   198 		
       
   199 	CleanupStack::PopAndDestroy(2, &expectedLogEntries); // expectedLogEntries, retrievedLogEntries	
       
   200 	}
       
   201 
       
   202 void CScrGetLogEntriesStep::ImplTestStepPostambleL()
       
   203 	{
       
   204 	CScrTestStep::ImplTestStepPostambleL();
       
   205 	}
       
   206 
       
   207 // -----------CScrSetLogFileReadOnlyAttrStep-----------------
       
   208 
       
   209 CScrSetLogFileReadOnlyAttrStep::CScrSetLogFileReadOnlyAttrStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
   210 	{
       
   211 	}
       
   212 
       
   213 void CScrSetLogFileReadOnlyAttrStep::ImplTestStepPreambleL()
       
   214 	{
       
   215 	CScrTestStep::ImplTestStepPreambleL();
       
   216 	}
       
   217 	
       
   218 void CScrSetLogFileReadOnlyAttrStep::ImplTestStepL()
       
   219 	{
       
   220 	RFs fs;
       
   221 	User::LeaveIfError(fs.Connect());
       
   222 	CleanupClosePushL(fs);
       
   223 				
       
   224 	RBuf fn;
       
   225 	fn.CreateL(KMaxFileName);
       
   226 	fn.CleanupClosePushL();
       
   227 	fn.Copy(KScrLogFile);
       
   228 	fn[0] = fs.GetSystemDriveChar();
       
   229 			
       
   230 	TBool isLogFileReadOnly = EFalse; 
       
   231 	if(!GetBoolFromConfig(ConfigSection(), _L("LogFileReadOnly"), isLogFileReadOnly))
       
   232 		PrintErrorL(_L("LogFileReadOnly flag was not found!"), KErrNotFound);
       
   233 	
       
   234 	if(isLogFileReadOnly)
       
   235 		User::LeaveIfError(fs.SetAtt(fn, KEntryAttReadOnly, 0));
       
   236 	else
       
   237 		User::LeaveIfError(fs.SetAtt(fn, 0, KEntryAttReadOnly));
       
   238 	
       
   239 	CleanupStack::PopAndDestroy(2, &fs); // fs, fn
       
   240 	}
       
   241 
       
   242 void CScrSetLogFileReadOnlyAttrStep::ImplTestStepPostambleL()
       
   243 	{
       
   244 	CScrTestStep::ImplTestStepPostambleL();
       
   245 	}
       
   246 
       
   247 // -----------CScrCreateLogFileStep-----------------
       
   248 
       
   249 CScrCreateLogFileStep::CScrCreateLogFileStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
   250 	{
       
   251 	}
       
   252 
       
   253 void CScrCreateLogFileStep::ImplTestStepPreambleL()
       
   254 	{
       
   255 	CScrTestStep::ImplTestStepPreambleL();
       
   256 	}
       
   257 	
       
   258 void CScrCreateLogFileStep::ImplTestStepL()
       
   259 	{
       
   260 	TInt numOfRecords;
       
   261 	if (!GetIntFromConfig(ConfigSection(), KLogsCountParamName, numOfRecords))
       
   262 		PrintErrorL(_L("The logs count param could not be found in configuration!"), KErrNotFound);
       
   263 	
       
   264 	TComponentId compId (0);
       
   265 	
       
   266 	for(TInt i=0; i<numOfRecords; ++i)
       
   267 		{
       
   268 		compId = iScrSession.AddComponentL(_L("TestComponentName"), _L("TestComponentVendor"),_L("plain"));
       
   269 		iScrSession.SetComponentVersionL(compId,_L("1.2.3"));
       
   270 		}
       
   271 	}
       
   272 
       
   273 void CScrCreateLogFileStep::ImplTestStepPostambleL()
       
   274 	{
       
   275 	CScrTestStep::ImplTestStepPostambleL();
       
   276 	}