installationservices/swcomponentregistry/test/tscr/source/subsessionsteps.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     1 /*
       
     2 * Copyright (c) 2008-2010 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 operator ==(const Usif::TAppRegInfo& aLhsEntry, const Usif::TAppRegInfo& aRhsEntry)
       
    32     {
       
    33     return (aLhsEntry.Uid() == aRhsEntry.Uid() && 
       
    34             aLhsEntry.FullName() == aRhsEntry.FullName() &&  
       
    35             aLhsEntry.Caption() == aRhsEntry.Caption() &&  
       
    36             aLhsEntry.ShortCaption() == aRhsEntry.ShortCaption());
       
    37     }
       
    38 TBool operator !=(const TAppRegInfo& aLhsEntry, const TAppRegInfo& aRhsEntry)
       
    39     {
       
    40     return !operator ==(aLhsEntry, aRhsEntry);
       
    41     }
       
    42 
       
    43 TBool IsEqual(const TAppRegInfo& aLhsEntry, const TAppRegInfo& aRhsEntry)
       
    44     {
       
    45     return (aLhsEntry == aRhsEntry);
       
    46     }
       
    47 
       
    48 
       
    49 TBool IsEqual(const HBufC& aLhs, const HBufC& aRhs)
       
    50 	{
       
    51 	return const_cast<HBufC &>(aLhs).Des() == const_cast<HBufC &>(aRhs).Des();
       
    52 	}
       
    53 
       
    54 template <class T> TBool VerifyMatchingL(const T* aObj, RPointerArray<T>& aExpectedArray)
       
    55 	{
       
    56 	TInt pos = aExpectedArray.Find(aObj, IsEqual);
       
    57 	if (pos != KErrNotFound)
       
    58 		{
       
    59 		T* foundObj = aExpectedArray[pos];
       
    60 		delete foundObj;
       
    61 		aExpectedArray.Remove(pos);
       
    62 		return ETrue;
       
    63 		}
       
    64 	return EFalse;
       
    65 	}
       
    66 
       
    67 
       
    68 // -----------CScrGetComponentStep-----------------
       
    69 
       
    70 CScrComponentRegistrySubsessionStep::CScrComponentRegistrySubsessionStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
    71 	{
       
    72 	}
       
    73 
       
    74 void CScrComponentRegistrySubsessionStep::ImplTestStepPreambleL()
       
    75 	{
       
    76 	CScrTestStep::ImplTestStepPreambleL();
       
    77 	}
       
    78 
       
    79 void CScrComponentRegistrySubsessionStep::GetComponentEntriesFromConfigL(RPointerArray<CComponentEntry>& aEntries)
       
    80 	{
       
    81 	TInt componentsCount(0);
       
    82 	if (!GetIntFromConfig(ConfigSection(), KComponentsCountName, componentsCount))
       
    83 		{
       
    84 		CComponentEntry *componentEntry = GetComponentEntryFromConfigLC();
       
    85 		aEntries.AppendL(componentEntry);
       
    86 		CleanupStack::Pop(componentEntry);
       
    87 		}
       
    88 	
       
    89 	for (TInt i = 0; i < componentsCount; ++i)
       
    90 		{
       
    91 		CComponentEntry *componentEntry = GetComponentEntryFromConfigLC(EFalse,i);
       
    92 		aEntries.AppendL(componentEntry);
       
    93 		CleanupStack::Pop(componentEntry);
       
    94 		}
       
    95 	}
       
    96 
       
    97 void CScrComponentRegistrySubsessionStep::VerifyNonReturnedEntriesL(const RPointerArray<CComponentEntry>& aExpectedEntries)
       
    98 	{
       
    99 	// Check if we need to verify the returned components
       
   100 	// Performance tests don't need verification.
       
   101 	TBool noVerification = EFalse;
       
   102 	GetBoolFromConfig(ConfigSection(), _L("NoVerification"), noVerification);
       
   103 	if(noVerification) return;
       
   104 
       
   105 	if (aExpectedEntries.Count() > 0)
       
   106 		{
       
   107 		TComponentId componentId = aExpectedEntries[0]->ComponentId(); 
       
   108 		const TDesC& componentName = aExpectedEntries[0]->Name();
       
   109 		ERR_PRINTF3(_L("At least one expected entry was not returned by the API - id %d, name %S"), componentId, &componentName);
       
   110 		SetTestStepResult(EFail);
       
   111 		}	
       
   112 	}
       
   113 
       
   114 void CScrComponentRegistrySubsessionStep::TestSingleModeL(const RSoftwareComponentRegistryView& aSubSession, RPointerArray<CComponentEntry>& aExpectedEntries)
       
   115 	{
       
   116 	// Check if we need to verify the returned components
       
   117 	// Performance tests don't need verification. Because the impact verification on performance results.
       
   118 	// In addition, we cannot simply verify some test cases such as retrieving all components or removable components. 
       
   119 	// Because, the perforamce test databases are populated with random data, and in the future we cannot guarantee 
       
   120 	// the values will stay same if the databases are recreated.
       
   121 	
       
   122 	TBool noVerification = EFalse;
       
   123 	GetBoolFromConfig(ConfigSection(), _L("NoVerification"), noVerification);
       
   124 
       
   125 	// Read continuously entries from the sub-session
       
   126 	while (1)
       
   127 		{
       
   128 		CComponentEntry* componentEntry = aSubSession.NextComponentL();
       
   129 		if (componentEntry == NULL)
       
   130 			break; // No more entries were found
       
   131 		CleanupStack::PushL(componentEntry);
       
   132 		
       
   133 		if(noVerification)
       
   134 			{
       
   135 			CleanupStack::PopAndDestroy(componentEntry);
       
   136 			continue;
       
   137 			}
       
   138 		// For each entry, check whether it was found in the expected array.
       
   139 		// If found, delete it from the expected array. If not, fail the test step
       
   140 		if (!VerifyMatchingL(componentEntry, aExpectedEntries))
       
   141 			{
       
   142 			ERR_PRINTF2(_L("The API returned an unexpected entry with id %d"), componentEntry->ComponentId());
       
   143 			SetTestStepResult(EFail);		
       
   144 			CleanupStack::PopAndDestroy(componentEntry);
       
   145 			return;
       
   146 			}
       
   147 				
       
   148 		CleanupStack::PopAndDestroy(componentEntry);
       
   149 		}
       
   150 			
       
   151 	// At the end, check whether there were expected entries which were not found
       
   152 	VerifyNonReturnedEntriesL(aExpectedEntries);
       
   153 	}
       
   154 
       
   155 void CScrComponentRegistrySubsessionStep::TestSetModeL(const RSoftwareComponentRegistryView& aSubSession, TInt aSetSize, RPointerArray<CComponentEntry>& aExpectedEntries)
       
   156 	{
       
   157 	// Check if we need to verify the returned components
       
   158 	// Performance tests don't need verification. See TestSingleModeL for more information.
       
   159 	TBool noVerification = EFalse;
       
   160 	GetBoolFromConfig(ConfigSection(), _L("NoVerification"), noVerification);
       
   161 
       
   162 	while (1)
       
   163 		{
       
   164 		RPointerArray<CComponentEntry> componentSet;
       
   165 		CleanupResetAndDestroyPushL(componentSet);
       
   166 		
       
   167 		aSubSession.NextComponentSetL(aSetSize, componentSet);
       
   168 		TInt returnedComponentsCount = componentSet.Count(); 
       
   169 		if (returnedComponentsCount <= 0)
       
   170 			{
       
   171 			CleanupStack::PopAndDestroy(&componentSet);
       
   172 			break;
       
   173 			}
       
   174 		
       
   175 		if(noVerification) 
       
   176 			{
       
   177 			CleanupStack::PopAndDestroy(&componentSet);
       
   178 			continue;
       
   179 			}
       
   180 				
       
   181 		for (TInt i = 0; i < returnedComponentsCount; ++i)
       
   182 			{
       
   183 			if (!VerifyMatchingL(componentSet[i], aExpectedEntries))
       
   184 				{
       
   185 				ERR_PRINTF2(_L("The API returned an unexpected entry with id %d"), componentSet[i]->ComponentId());
       
   186 				SetTestStepResult(EFail);				
       
   187 				CleanupStack::PopAndDestroy(&componentSet);
       
   188 				return;
       
   189 				}
       
   190 			}
       
   191 		
       
   192 		CleanupStack::PopAndDestroy(&componentSet);
       
   193 		}
       
   194 	
       
   195 	VerifyNonReturnedEntriesL(aExpectedEntries); 
       
   196 	}
       
   197 
       
   198 void CScrComponentRegistrySubsessionStep::ImplTestStepL()
       
   199 	{	
       
   200 	CComponentFilter* componentFilter = ReadComponentFilterFromConfigLC();
       
   201 	INFO_PRINTF1(_L("Read component filter from configuration"));
       
   202 	
       
   203 	INFO_PRINTF1(_L("Opened subsession to SCR"));
       
   204 	
       
   205 	//Get testing mode from configuration (sets or single iteration)
       
   206 	//Delegate the actual invocation and comparison according to the testing mode	
       
   207 	TInt setSize = GetSetSizeFromConfigL();
       
   208 	INFO_PRINTF2(_L("Test set size %d"), setSize);
       
   209 	
       
   210 	// Read expected results from config
       
   211 	RPointerArray<CComponentEntry> expectedComponentEntries;
       
   212 	CleanupResetAndDestroyPushL(expectedComponentEntries);
       
   213 	GetComponentEntriesFromConfigL(expectedComponentEntries);
       
   214 	StartTimer();
       
   215 	// Open the subsession
       
   216 	RSoftwareComponentRegistryView subSession;
       
   217 	CleanupClosePushL(subSession);	
       
   218 	subSession.OpenViewL(iScrSession, componentFilter);
       
   219 		
       
   220 	if (setSize == 1)
       
   221 		TestSingleModeL(subSession, expectedComponentEntries);
       
   222 	else
       
   223 		TestSetModeL(subSession, setSize, expectedComponentEntries);
       
   224 		
       
   225 	CleanupStack::PopAndDestroy(3, componentFilter); // expectedComponentEntries, subSession, componentFilter
       
   226 	}
       
   227 
       
   228 void CScrComponentRegistrySubsessionStep::ImplTestStepPostambleL()
       
   229 	{
       
   230 	CScrTestStep::ImplTestStepPostambleL();
       
   231 	}
       
   232 
       
   233 // -----------CScrFileListSubsessionStep-----------------
       
   234 
       
   235 CScrFileListSubsessionStep::CScrFileListSubsessionStep(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
   236 	{
       
   237 	}
       
   238 
       
   239 void CScrFileListSubsessionStep::ImplTestStepPreambleL()
       
   240 	{
       
   241 	CScrTestStep::ImplTestStepPreambleL();
       
   242 	}
       
   243 
       
   244 void CScrFileListSubsessionStep::VerifyNonReturnedFilesL(const RPointerArray<HBufC>& aExpectedFiles)
       
   245 	{
       
   246 	if (aExpectedFiles.Count() > 0)
       
   247 		{
       
   248 		HBufC* fileName = aExpectedFiles[0]; 
       
   249 		ERR_PRINTF2(_L("At least one expected files was not returned by the API - name %S"), fileName);
       
   250 		SetTestStepResult(EFail);
       
   251 		}	
       
   252 	}
       
   253 
       
   254 void CScrFileListSubsessionStep::ReportUnexpectedFileL(const TDesC& aUnexpectedFileName)
       
   255 	{
       
   256 	ERR_PRINTF2(_L("The API returned an unexpected file entry with name %S"), &aUnexpectedFileName);
       
   257 	SetTestStepResult(EFail);		
       
   258 	}
       
   259 
       
   260 void CScrFileListSubsessionStep::TestSingleModeL(const RSoftwareComponentRegistryFilesList& aSubSession, 
       
   261 													 RPointerArray<HBufC> &aExpectedFiles)
       
   262 	{
       
   263 	FOREVER
       
   264 		{
       
   265 		HBufC *nextFile = aSubSession.NextFileL();
       
   266 		if (!nextFile)
       
   267 			break;
       
   268 		CleanupStack::PushL(nextFile);
       
   269 		
       
   270 		if (!VerifyMatchingL(nextFile, aExpectedFiles))
       
   271 			{
       
   272 			ReportUnexpectedFileL(*nextFile);
       
   273 			CleanupStack::PopAndDestroy(nextFile);
       
   274 			return;
       
   275 			}
       
   276 		
       
   277 		CleanupStack::PopAndDestroy(nextFile);
       
   278 		}
       
   279 	
       
   280 	VerifyNonReturnedFilesL(aExpectedFiles);
       
   281 	}
       
   282 
       
   283 void CScrFileListSubsessionStep::TestSetModeL(const RSoftwareComponentRegistryFilesList& aSubSession, TInt aSetSize, 
       
   284 											 	  RPointerArray<HBufC>& aExpectedFiles)
       
   285 	{
       
   286 	FOREVER
       
   287 		{
       
   288 		RPointerArray<HBufC> foundFiles;
       
   289 		CleanupResetAndDestroyPushL(foundFiles);
       
   290 		
       
   291 		aSubSession.NextFileSetL(aSetSize, foundFiles);
       
   292 		TInt returnedFilesCount = foundFiles.Count(); 
       
   293 		if (returnedFilesCount <= 0)
       
   294 			{
       
   295 			CleanupStack::PopAndDestroy(&foundFiles);
       
   296 			break;
       
   297 			}
       
   298 		for (TInt i = 0; i < returnedFilesCount; ++i)
       
   299 			{
       
   300 			if (!VerifyMatchingL(foundFiles[i], aExpectedFiles))
       
   301 				{
       
   302 				ReportUnexpectedFileL(*foundFiles[i]);
       
   303 				CleanupStack::PopAndDestroy(&foundFiles);
       
   304 				return;
       
   305 				}
       
   306 			}
       
   307 		
       
   308 		CleanupStack::PopAndDestroy(&foundFiles);
       
   309 		}
       
   310 	VerifyNonReturnedFilesL(aExpectedFiles);
       
   311 	}
       
   312 
       
   313 
       
   314 void CScrFileListSubsessionStep::ImplTestStepL()
       
   315 	{	
       
   316 	TInt componentId = GetComponentIdL();
       
   317 	RSoftwareComponentRegistryFilesList subSession;
       
   318 	CleanupClosePushL(subSession);
       
   319 	
       
   320 	subSession.OpenListL(iScrSession, componentId);
       
   321 	
       
   322 	RPointerArray<HBufC> expectedFiles;
       
   323 	CleanupResetAndDestroyPushL(expectedFiles);
       
   324 	
       
   325 	GetFileNameListFromConfigL(expectedFiles);
       
   326 	TInt setSize = GetSetSizeFromConfigL();
       
   327 
       
   328 	if (setSize > 1)
       
   329 		TestSingleModeL(subSession, expectedFiles);
       
   330 	else
       
   331 		TestSetModeL(subSession, setSize, expectedFiles);	
       
   332 			
       
   333 	CleanupStack::PopAndDestroy(2, &subSession); //expectedEntries 
       
   334 	}
       
   335 
       
   336 void CScrFileListSubsessionStep::ImplTestStepPostambleL()
       
   337 	{
       
   338 	CScrTestStep::ImplTestStepPostambleL();
       
   339 	}
       
   340 
       
   341 // -----------CAppInfoView-----------------
       
   342 
       
   343 CAppInfoView::CAppInfoView(CScrTestServer& aParent)	: CScrTestStep(aParent)
       
   344 	{
       
   345 	}
       
   346 
       
   347 void CAppInfoView::ImplTestStepPreambleL()
       
   348 	{
       
   349 	CScrTestStep::ImplTestStepPreambleL();
       
   350 	}
       
   351 
       
   352 void CAppInfoView::GetAppEntryFromConfigL(RPointerArray<Usif::TAppRegInfo>& aEntries)
       
   353     {
       
   354     TInt appEntriesCount(0);
       
   355     TAppRegInfo *appRegInfo=NULL;
       
   356     if (!GetIntFromConfig(ConfigSection(), KAppEntriesCountName, appEntriesCount))
       
   357         {
       
   358         appRegInfo = GetAppInfoFromConfigL(ETrue);
       
   359         aEntries.AppendL(appRegInfo);
       
   360         }
       
   361     
       
   362     for (TInt i = 0; i < appEntriesCount; ++i)
       
   363         {
       
   364         appRegInfo = GetAppInfoFromConfigL(EFalse,i);
       
   365         aEntries.AppendL(appRegInfo);
       
   366         }
       
   367     }
       
   368 
       
   369 void CAppInfoView::VerifyNonReturnedEntriesL(const RPointerArray<Usif::TAppRegInfo>& aExpectedEntries)
       
   370     {
       
   371     // Check if we need to verify the returned components
       
   372     // Performance tests don't need verification.
       
   373     TBool noVerification = EFalse;
       
   374     GetBoolFromConfig(ConfigSection(), _L("NoVerification"), noVerification);
       
   375     if(noVerification) return;
       
   376 
       
   377     if (aExpectedEntries.Count() > 0)
       
   378         {
       
   379         TUid appUid = aExpectedEntries[0]->Uid(); 
       
   380         const TDesC& appName = aExpectedEntries[0]->FullName();
       
   381         ERR_PRINTF3(_L("At least one expected entry was not returned by the API - id %d, name %S"), appUid, &appName);
       
   382         SetTestStepResult(EFail);
       
   383         }   
       
   384     }
       
   385 
       
   386 void CAppInfoView::TestSessionL(TInt aNoOfEntries, const RApplicationInfoView& aSubSession, RPointerArray<Usif::TAppRegInfo>& aExpectedEntries)
       
   387     {
       
   388     // Check if we need to verify the returned components
       
   389     // Performance tests don't need verification.
       
   390     TBool isVerification = EFalse;
       
   391     TInt noOfEntriesMatched = 0;
       
   392     TInt totalExpectedEntriesCount = aExpectedEntries.Count();
       
   393     GetBoolFromConfig(ConfigSection(), _L("IsVerification"), isVerification);
       
   394     while (1)
       
   395             {
       
   396             RPointerArray<Usif::TAppRegInfo> appRegInfoSet;
       
   397             aSubSession.GetNextAppInfoL(aNoOfEntries, appRegInfoSet);
       
   398             TInt returnedAppRegInfoCount = appRegInfoSet.Count(); 
       
   399             if (returnedAppRegInfoCount <= 0)
       
   400                 {
       
   401                 INFO_PRINTF2(_L("May be negative case... no entries found ...Entries count read is %d "),returnedAppRegInfoCount);                
       
   402 				appRegInfoSet.Close();
       
   403                 break;
       
   404                 }
       
   405             
       
   406             if(!isVerification) 
       
   407                 {
       
   408                 //INFO_PRINTF2(_L("Read Appuid is  %S"),appRegInfoSet[0]->iFullName );
       
   409                 INFO_PRINTF3(_L("No of entries read is %d and first appuid is %d "),returnedAppRegInfoCount,  appRegInfoSet[0]->Uid());
       
   410                
       
   411                     TAppRegInfo* tp=NULL;
       
   412                     for (TInt i = 0; i<returnedAppRegInfoCount; i++ )
       
   413                         {
       
   414                     tp=appRegInfoSet[i];
       
   415                     delete tp;
       
   416                         }
       
   417                 appRegInfoSet.Close();
       
   418 				continue;
       
   419                 }
       
   420                     
       
   421             for (TInt i = 0; i < returnedAppRegInfoCount; ++i)
       
   422                 {
       
   423                 if (VerifyMatchingL(appRegInfoSet[i], aExpectedEntries))                    
       
   424                     {                                          
       
   425                     ++noOfEntriesMatched;
       
   426                     }
       
   427                 }            
       
   428             TAppRegInfo* tp=NULL;
       
   429             for(TInt i = 0; i<returnedAppRegInfoCount; ++i)
       
   430                {
       
   431                tp=appRegInfoSet[i];
       
   432                delete tp;
       
   433                }
       
   434             appRegInfoSet.Close();     
       
   435             if(noOfEntriesMatched == totalExpectedEntriesCount)
       
   436                 break;
       
   437             }
       
   438         
       
   439     VerifyNonReturnedEntriesL(aExpectedEntries); 
       
   440     
       
   441     }
       
   442 
       
   443 void CAppInfoView::ImplTestStepL()
       
   444 	{	
       
   445 	CAppInfoFilter* appinfoFilter=NULL ;
       
   446 
       
   447 	INFO_PRINTF1(_L("Read appinfo filter from configuration"));
       
   448 	TRAPD(err, ReadAppInfoFilterFromConfigL(&appinfoFilter));
       
   449 	if (KErrNotFound==err)
       
   450 	    {
       
   451 	    delete appinfoFilter;
       
   452 	    appinfoFilter=NULL;
       
   453 	    }
       
   454 	RPointerArray<TAppRegInfo> expectedAppRegEntries;
       
   455     CleanupResetAndDestroyPushL(expectedAppRegEntries);
       
   456 	TInt noOfEntries(1);
       
   457 	GetIntFromConfig(ConfigSection(), _L("NoOfEntries"), noOfEntries);
       
   458 	
       
   459 	TBool isVerification = EFalse;
       
   460 	GetBoolFromConfig(ConfigSection(), _L("IsVerification"), isVerification);
       
   461 	if(isVerification) 
       
   462 	{
       
   463         GetAppEntryFromConfigL(expectedAppRegEntries);
       
   464         INFO_PRINTF1(_L("Read expected entries for verification "));
       
   465 	}
       
   466     
       
   467 	INFO_PRINTF1(_L("Opened subsession to SCR"));
       
   468     TBool callGetNextAppWithLocale=EFalse;
       
   469     TInt appLocale;
       
   470     if (GetIntFromConfig(ConfigSection(), _L("LocaleValue"), appLocale))
       
   471         callGetNextAppWithLocale=ETrue;
       
   472 	RApplicationInfoView  subSession;
       
   473 	CleanupClosePushL(subSession);
       
   474 
       
   475 	if(callGetNextAppWithLocale)
       
   476 	    {
       
   477 	    subSession.OpenViewL(iScrSession,appinfoFilter, (TLanguage)appLocale);
       
   478 	    }
       
   479 	else
       
   480 	    {
       
   481 	    subSession.OpenViewL(iScrSession,appinfoFilter);
       
   482 	    }
       
   483 
       
   484 	if(appinfoFilter)
       
   485 	    delete appinfoFilter;
       
   486 
       
   487     TRAPD(err1,TestSessionL(noOfEntries, subSession, expectedAppRegEntries));
       
   488 
       
   489 	TInt count = expectedAppRegEntries.Count();
       
   490 	TAppRegInfo* tp=NULL;
       
   491 	for (TInt i = 0; i<count; i++ )
       
   492 	    {
       
   493 	    tp=expectedAppRegEntries[i];
       
   494 	    delete tp;
       
   495 	    }
       
   496 	expectedAppRegEntries.Close();
       
   497 	CleanupStack::PopAndDestroy(2, &expectedAppRegEntries); //expectedAppRegEntries, subSession
       
   498 	if (KErrNone!=err1)
       
   499 	    User::Leave(err1);
       
   500 	}
       
   501 
       
   502 void CAppInfoView::ImplTestStepPostambleL()
       
   503 	{
       
   504 	CScrTestStep::ImplTestStepPostambleL();
       
   505 	}