installationservices/swcomponentregistry/test/tscr/source/installloghistorysteps.cpp
changeset 24 84a16765cd86
child 25 98b66e4fb0be
equal deleted inserted replaced
6:aba6b8104af3 24:84a16765cd86
       
     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 			return EFalse;
       
   139 			}
       
   140 		}	
       
   141 	return ETrue;
       
   142 	}
       
   143 	
       
   144 void CScrGetLogEntriesStep::ImplTestStepL()
       
   145 	{
       
   146 	TBool isLogFileReadOnly = EFalse; 
       
   147 	(void)GetBoolFromConfig(ConfigSection(), _L("LogFileReadOnly"), isLogFileReadOnly); // since this is an optional param, ignore the return code.
       
   148 	if(isLogFileReadOnly)
       
   149 		{
       
   150 		RBuf fn;
       
   151 		fn.CreateL(KMaxFileName);
       
   152 		fn.CleanupClosePushL();
       
   153 		fn.Copy(KScrLogFile);
       
   154 		RFs fs;
       
   155 		User::Leave(fs.Connect());
       
   156 		CleanupClosePushL(fs);
       
   157 		fn[0] = fs.GetSystemDriveChar();
       
   158 		User::LeaveIfError(fs.SetAtt(fn, KEntryAttReadOnly, 0));
       
   159 		CleanupStack::PopAndDestroy(2, &fn); // fn, fs
       
   160 		}
       
   161 
       
   162 	RPointerArray<CScrLogEntry> expectedLogEntries;
       
   163 	CleanupResetAndDestroyPushL(expectedLogEntries);
       
   164 	GetLogEntriesFromConfigL(expectedLogEntries);
       
   165 	
       
   166 	TPtrC *ptrSwTypeName = NULL;
       
   167 	TPtrC swTypeName;
       
   168 	if (GetStringFromConfig(ConfigSection(), KSoftwareTypeName, swTypeName))
       
   169 		{
       
   170 		ptrSwTypeName = &swTypeName; 
       
   171 		}
       
   172 	
       
   173 	RPointerArray<CScrLogEntry> retrievedLogEntries;
       
   174 	CleanupResetAndDestroyPushL(retrievedLogEntries);
       
   175 	
       
   176 	iScrSession.RetrieveLogEntriesL(retrievedLogEntries, ptrSwTypeName);
       
   177 	
       
   178 	if (!CompareLogEntriesL(retrievedLogEntries, expectedLogEntries))
       
   179 		{
       
   180 		ERR_PRINTF1(_L("The retrieved log entries are different from the expected ones."));
       
   181 		SetTestStepResult(EFail);
       
   182 		}
       
   183 		
       
   184 	CleanupStack::PopAndDestroy(2, &expectedLogEntries); // expectedLogEntries, retrievedLogEntries	
       
   185 	}
       
   186 
       
   187 void CScrGetLogEntriesStep::ImplTestStepPostambleL()
       
   188 	{
       
   189 	CScrTestStep::ImplTestStepPostambleL();
       
   190 	}
       
   191 
       
   192 // -----------CScrSetLogFileReadOnlyAttrStep-----------------
       
   193 
       
   194 CScrSetLogFileReadOnlyAttrStep::CScrSetLogFileReadOnlyAttrStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
   195 	{
       
   196 	}
       
   197 
       
   198 void CScrSetLogFileReadOnlyAttrStep::ImplTestStepPreambleL()
       
   199 	{
       
   200 	CScrTestStep::ImplTestStepPreambleL();
       
   201 	}
       
   202 	
       
   203 void CScrSetLogFileReadOnlyAttrStep::ImplTestStepL()
       
   204 	{
       
   205 	RFs fs;
       
   206 	User::LeaveIfError(fs.Connect());
       
   207 	CleanupClosePushL(fs);
       
   208 				
       
   209 	RBuf fn;
       
   210 	fn.CreateL(KMaxFileName);
       
   211 	fn.CleanupClosePushL();
       
   212 	fn.Copy(KScrLogFile);
       
   213 	fn[0] = fs.GetSystemDriveChar();
       
   214 			
       
   215 	TBool isLogFileReadOnly = EFalse; 
       
   216 	if(!GetBoolFromConfig(ConfigSection(), _L("LogFileReadOnly"), isLogFileReadOnly))
       
   217 		PrintErrorL(_L("LogFileReadOnly flag was not found!"), KErrNotFound);
       
   218 	
       
   219 	if(isLogFileReadOnly)
       
   220 		User::LeaveIfError(fs.SetAtt(fn, KEntryAttReadOnly, 0));
       
   221 	else
       
   222 		User::LeaveIfError(fs.SetAtt(fn, 0, KEntryAttReadOnly));
       
   223 	
       
   224 	CleanupStack::PopAndDestroy(2, &fs); // fs, fn
       
   225 	}
       
   226 
       
   227 void CScrSetLogFileReadOnlyAttrStep::ImplTestStepPostambleL()
       
   228 	{
       
   229 	CScrTestStep::ImplTestStepPostambleL();
       
   230 	}
       
   231 
       
   232 // -----------CScrCreateLogFileStep-----------------
       
   233 
       
   234 CScrCreateLogFileStep::CScrCreateLogFileStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
   235 	{
       
   236 	}
       
   237 
       
   238 void CScrCreateLogFileStep::ImplTestStepPreambleL()
       
   239 	{
       
   240 	CScrTestStep::ImplTestStepPreambleL();
       
   241 	}
       
   242 	
       
   243 void CScrCreateLogFileStep::ImplTestStepL()
       
   244 	{
       
   245 	TInt numOfRecords;
       
   246 	if (!GetIntFromConfig(ConfigSection(), KLogsCountParamName, numOfRecords))
       
   247 		PrintErrorL(_L("The logs count param could not be found in configuration!"), KErrNotFound);
       
   248 	
       
   249 	TComponentId compId (0);
       
   250 	
       
   251 	for(TInt i=0; i<numOfRecords; ++i)
       
   252 		{
       
   253 		compId = iScrSession.AddComponentL(_L("TestComponentName"), _L("TestComponentVendor"),_L("plain"));
       
   254 		iScrSession.SetComponentVersionL(compId,_L("1.2.3"));
       
   255 		}
       
   256 	}
       
   257 
       
   258 void CScrCreateLogFileStep::ImplTestStepPostambleL()
       
   259 	{
       
   260 	CScrTestStep::ImplTestStepPostambleL();
       
   261 	}