installationservices/swcomponentregistry/test/tscr/source/subsessionsteps.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 * Implements test steps for the subsessions interfaces in the SCR
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "subsessionsteps.h"
       
    21 #include <scs/cleanuputils.h>
       
    22 #include "tscrdefs.h"
       
    23 
       
    24 using namespace Usif;
       
    25 
       
    26 TBool IsEqual(const CComponentEntry& aLhsEntry, const CComponentEntry& aRhsEntry)
       
    27 	{
       
    28 	return (aLhsEntry == aRhsEntry);
       
    29 	}
       
    30 
       
    31 TBool IsEqual(const HBufC& aLhs, const HBufC& aRhs)
       
    32 	{
       
    33 	return const_cast<HBufC &>(aLhs).Des() == const_cast<HBufC &>(aRhs).Des();
       
    34 	}
       
    35 
       
    36 template <class T> TBool VerifyMatchingL(const T* aObj, RPointerArray<T>& aExpectedArray)
       
    37 	{
       
    38 	TInt pos = aExpectedArray.Find(aObj, IsEqual);
       
    39 	if (pos != KErrNotFound)
       
    40 		{
       
    41 		T* foundObj = aExpectedArray[pos];
       
    42 		delete foundObj;
       
    43 		aExpectedArray.Remove(pos);
       
    44 		return ETrue;
       
    45 		}
       
    46 	return EFalse;
       
    47 	}
       
    48 
       
    49 
       
    50 // -----------CScrGetComponentStep-----------------
       
    51 
       
    52 CScrComponentRegistrySubsessionStep::CScrComponentRegistrySubsessionStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
    53 	{
       
    54 	}
       
    55 
       
    56 void CScrComponentRegistrySubsessionStep::ImplTestStepPreambleL()
       
    57 	{
       
    58 	CScrTestStep::ImplTestStepPreambleL();
       
    59 	}
       
    60 
       
    61 void CScrComponentRegistrySubsessionStep::GetComponentEntriesFromConfigL(RPointerArray<CComponentEntry>& aEntries)
       
    62 	{
       
    63 	TInt componentsCount(0);
       
    64 	if (!GetIntFromConfig(ConfigSection(), KComponentsCountName, componentsCount))
       
    65 		{
       
    66 		CComponentEntry *componentEntry = GetComponentEntryFromConfigLC();
       
    67 		aEntries.AppendL(componentEntry);
       
    68 		CleanupStack::Pop(componentEntry);
       
    69 		}
       
    70 	
       
    71 	for (TInt i = 0; i < componentsCount; ++i)
       
    72 		{
       
    73 		CComponentEntry *componentEntry = GetComponentEntryFromConfigLC(EFalse,i);
       
    74 		aEntries.AppendL(componentEntry);
       
    75 		CleanupStack::Pop(componentEntry);
       
    76 		}
       
    77 	}
       
    78 
       
    79 void CScrComponentRegistrySubsessionStep::VerifyNonReturnedEntriesL(const RPointerArray<CComponentEntry>& aExpectedEntries)
       
    80 	{
       
    81 	// Check if we need to verify the returned components
       
    82 	// Performance tests don't need verification.
       
    83 	TBool noVerification = EFalse;
       
    84 	GetBoolFromConfig(ConfigSection(), _L("NoVerification"), noVerification);
       
    85 	if(noVerification) return;
       
    86 
       
    87 	if (aExpectedEntries.Count() > 0)
       
    88 		{
       
    89 		TComponentId componentId = aExpectedEntries[0]->ComponentId(); 
       
    90 		const TDesC& componentName = aExpectedEntries[0]->Name();
       
    91 		ERR_PRINTF3(_L("At least one expected entry was not returned by the API - id %d, name %S"), componentId, &componentName);
       
    92 		SetTestStepResult(EFail);
       
    93 		}	
       
    94 	}
       
    95 
       
    96 void CScrComponentRegistrySubsessionStep::TestSingleModeL(const RSoftwareComponentRegistryView& aSubSession, RPointerArray<CComponentEntry>& aExpectedEntries)
       
    97 	{
       
    98 	// Check if we need to verify the returned components
       
    99 	// Performance tests don't need verification. Because the impact verification on performance results.
       
   100 	// In addition, we cannot simply verify some test cases such as retrieving all components or removable components. 
       
   101 	// Because, the perforamce test databases are populated with random data, and in the future we cannot guarantee 
       
   102 	// the values will stay same if the databases are recreated.
       
   103 	
       
   104 	TBool noVerification = EFalse;
       
   105 	GetBoolFromConfig(ConfigSection(), _L("NoVerification"), noVerification);
       
   106 
       
   107 	// Read continuously entries from the sub-session
       
   108 	while (1)
       
   109 		{
       
   110 		CComponentEntry* componentEntry = aSubSession.NextComponentL();
       
   111 		if (componentEntry == NULL)
       
   112 			break; // No more entries were found
       
   113 		CleanupStack::PushL(componentEntry);
       
   114 		
       
   115 		if(noVerification)
       
   116 			{
       
   117 			CleanupStack::PopAndDestroy(componentEntry);
       
   118 			continue;
       
   119 			}
       
   120 		// For each entry, check whether it was found in the expected array.
       
   121 		// If found, delete it from the expected array. If not, fail the test step
       
   122 		if (!VerifyMatchingL(componentEntry, aExpectedEntries))
       
   123 			{
       
   124 			ERR_PRINTF2(_L("The API returned an unexpected entry with id %d"), componentEntry->ComponentId());
       
   125 			SetTestStepResult(EFail);		
       
   126 			CleanupStack::PopAndDestroy(componentEntry);
       
   127 			return;
       
   128 			}
       
   129 				
       
   130 		CleanupStack::PopAndDestroy(componentEntry);
       
   131 		}
       
   132 			
       
   133 	// At the end, check whether there were expected entries which were not found
       
   134 	VerifyNonReturnedEntriesL(aExpectedEntries);
       
   135 	}
       
   136 
       
   137 void CScrComponentRegistrySubsessionStep::TestSetModeL(const RSoftwareComponentRegistryView& aSubSession, TInt aSetSize, RPointerArray<CComponentEntry>& aExpectedEntries)
       
   138 	{
       
   139 	// Check if we need to verify the returned components
       
   140 	// Performance tests don't need verification. See TestSingleModeL for more information.
       
   141 	TBool noVerification = EFalse;
       
   142 	GetBoolFromConfig(ConfigSection(), _L("NoVerification"), noVerification);
       
   143 
       
   144 	while (1)
       
   145 		{
       
   146 		RPointerArray<CComponentEntry> componentSet;
       
   147 		CleanupResetAndDestroyPushL(componentSet);
       
   148 		
       
   149 		aSubSession.NextComponentSetL(aSetSize, componentSet);
       
   150 		TInt returnedComponentsCount = componentSet.Count(); 
       
   151 		if (returnedComponentsCount <= 0)
       
   152 			{
       
   153 			CleanupStack::PopAndDestroy(&componentSet);
       
   154 			break;
       
   155 			}
       
   156 		
       
   157 		if(noVerification) 
       
   158 			{
       
   159 			CleanupStack::PopAndDestroy(&componentSet);
       
   160 			continue;
       
   161 			}
       
   162 				
       
   163 		for (TInt i = 0; i < returnedComponentsCount; ++i)
       
   164 			{
       
   165 			if (!VerifyMatchingL(componentSet[i], aExpectedEntries))
       
   166 				{
       
   167 				ERR_PRINTF2(_L("The API returned an unexpected entry with id %d"), componentSet[i]->ComponentId());
       
   168 				SetTestStepResult(EFail);				
       
   169 				CleanupStack::PopAndDestroy(&componentSet);
       
   170 				return;
       
   171 				}
       
   172 			}
       
   173 		
       
   174 		CleanupStack::PopAndDestroy(&componentSet);
       
   175 		}
       
   176 	
       
   177 	VerifyNonReturnedEntriesL(aExpectedEntries); 
       
   178 	}
       
   179 
       
   180 void CScrComponentRegistrySubsessionStep::ImplTestStepL()
       
   181 	{	
       
   182 	CComponentFilter* componentFilter = ReadComponentFilterFromConfigLC();
       
   183 	INFO_PRINTF1(_L("Read component filter from configuration"));
       
   184 	
       
   185 	INFO_PRINTF1(_L("Opened subsession to SCR"));
       
   186 	
       
   187 	//Get testing mode from configuration (sets or single iteration)
       
   188 	//Delegate the actual invocation and comparison according to the testing mode	
       
   189 	TInt setSize = GetSetSizeFromConfigL();
       
   190 	INFO_PRINTF2(_L("Test set size %d"), setSize);
       
   191 	
       
   192 	// Read expected results from config
       
   193 	RPointerArray<CComponentEntry> expectedComponentEntries;
       
   194 	CleanupResetAndDestroyPushL(expectedComponentEntries);
       
   195 	GetComponentEntriesFromConfigL(expectedComponentEntries);
       
   196 	StartTimer();
       
   197 	// Open the subsession
       
   198 	RSoftwareComponentRegistryView subSession;
       
   199 	CleanupClosePushL(subSession);	
       
   200 	subSession.OpenViewL(iScrSession, componentFilter);
       
   201 		
       
   202 	if (setSize == 1)
       
   203 		TestSingleModeL(subSession, expectedComponentEntries);
       
   204 	else
       
   205 		TestSetModeL(subSession, setSize, expectedComponentEntries);
       
   206 		
       
   207 	CleanupStack::PopAndDestroy(3, componentFilter); // expectedComponentEntries, subSession, componentFilter
       
   208 	}
       
   209 
       
   210 void CScrComponentRegistrySubsessionStep::ImplTestStepPostambleL()
       
   211 	{
       
   212 	CScrTestStep::ImplTestStepPostambleL();
       
   213 	}
       
   214 
       
   215 // -----------CScrFileListSubsessionStep-----------------
       
   216 
       
   217 CScrFileListSubsessionStep::CScrFileListSubsessionStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
   218 	{
       
   219 	}
       
   220 
       
   221 void CScrFileListSubsessionStep::ImplTestStepPreambleL()
       
   222 	{
       
   223 	CScrTestStep::ImplTestStepPreambleL();
       
   224 	}
       
   225 
       
   226 void CScrFileListSubsessionStep::VerifyNonReturnedFilesL(const RPointerArray<HBufC>& aExpectedFiles)
       
   227 	{
       
   228 	if (aExpectedFiles.Count() > 0)
       
   229 		{
       
   230 		HBufC* fileName = aExpectedFiles[0]; 
       
   231 		ERR_PRINTF2(_L("At least one expected files was not returned by the API - name %S"), fileName);
       
   232 		SetTestStepResult(EFail);
       
   233 		}	
       
   234 	}
       
   235 
       
   236 void CScrFileListSubsessionStep::ReportUnexpectedFileL(const TDesC& aUnexpectedFileName)
       
   237 	{
       
   238 	ERR_PRINTF2(_L("The API returned an unexpected file entry with name %S"), &aUnexpectedFileName);
       
   239 	SetTestStepResult(EFail);		
       
   240 	}
       
   241 
       
   242 void CScrFileListSubsessionStep::TestSingleModeL(const RSoftwareComponentRegistryFilesList& aSubSession, 
       
   243 													 RPointerArray<HBufC> &aExpectedFiles)
       
   244 	{
       
   245 	FOREVER
       
   246 		{
       
   247 		HBufC *nextFile = aSubSession.NextFileL();
       
   248 		if (!nextFile)
       
   249 			break;
       
   250 		CleanupStack::PushL(nextFile);
       
   251 		
       
   252 		if (!VerifyMatchingL(nextFile, aExpectedFiles))
       
   253 			{
       
   254 			ReportUnexpectedFileL(*nextFile);
       
   255 			CleanupStack::PopAndDestroy(nextFile);
       
   256 			return;
       
   257 			}
       
   258 		
       
   259 		CleanupStack::PopAndDestroy(nextFile);
       
   260 		}
       
   261 	
       
   262 	VerifyNonReturnedFilesL(aExpectedFiles);
       
   263 	}
       
   264 
       
   265 void CScrFileListSubsessionStep::TestSetModeL(const RSoftwareComponentRegistryFilesList& aSubSession, TInt aSetSize, 
       
   266 											 	  RPointerArray<HBufC>& aExpectedFiles)
       
   267 	{
       
   268 	FOREVER
       
   269 		{
       
   270 		RPointerArray<HBufC> foundFiles;
       
   271 		CleanupResetAndDestroyPushL(foundFiles);
       
   272 		
       
   273 		aSubSession.NextFileSetL(aSetSize, foundFiles);
       
   274 		TInt returnedFilesCount = foundFiles.Count(); 
       
   275 		if (returnedFilesCount <= 0)
       
   276 			{
       
   277 			CleanupStack::PopAndDestroy(&foundFiles);
       
   278 			break;
       
   279 			}
       
   280 		for (TInt i = 0; i < returnedFilesCount; ++i)
       
   281 			{
       
   282 			if (!VerifyMatchingL(foundFiles[i], aExpectedFiles))
       
   283 				{
       
   284 				ReportUnexpectedFileL(*foundFiles[i]);
       
   285 				CleanupStack::PopAndDestroy(&foundFiles);
       
   286 				return;
       
   287 				}
       
   288 			}
       
   289 		
       
   290 		CleanupStack::PopAndDestroy(&foundFiles);
       
   291 		}
       
   292 	VerifyNonReturnedFilesL(aExpectedFiles);
       
   293 	}
       
   294 
       
   295 
       
   296 void CScrFileListSubsessionStep::ImplTestStepL()
       
   297 	{	
       
   298 	TInt componentId = GetComponentIdL();
       
   299 	RSoftwareComponentRegistryFilesList subSession;
       
   300 	CleanupClosePushL(subSession);
       
   301 	
       
   302 	subSession.OpenListL(iScrSession, componentId);
       
   303 	
       
   304 	RPointerArray<HBufC> expectedFiles;
       
   305 	CleanupResetAndDestroyPushL(expectedFiles);
       
   306 	
       
   307 	GetFileNameListFromConfigL(expectedFiles);
       
   308 	TInt setSize = GetSetSizeFromConfigL();
       
   309 
       
   310 	if (setSize > 1)
       
   311 		TestSingleModeL(subSession, expectedFiles);
       
   312 	else
       
   313 		TestSetModeL(subSession, setSize, expectedFiles);	
       
   314 			
       
   315 	CleanupStack::PopAndDestroy(2, &subSession); //expectedEntries 
       
   316 	}
       
   317 
       
   318 void CScrFileListSubsessionStep::ImplTestStepPostambleL()
       
   319 	{
       
   320 	CScrTestStep::ImplTestStepPostambleL();
       
   321 	}