appfw/apparchitecture/tef/T_ServiceRegistryStep.cpp
changeset 0 2e3d3ce01487
child 19 924385140d98
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include "T_ServiceRegistryStep.h"
       
    23 #include <serviceregistry.h>
       
    24 #include "testableapalssession.h"
       
    25 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    26 #include <apaidpartner.h>
       
    27 #endif
       
    28 
       
    29 
       
    30 
       
    31 _LIT(KImportAppsDir,"c:\\private\\10003a3f\\import\\apps\\");
       
    32 _LIT(KAppRscSourcePath,"z:\\system\\data\\TestUpdRegAppUninstallation_reg.rsc");
       
    33 _LIT(KUpgradeAppRscSourcePath,"z:\\system\\data\\TestUpgradeUpdRegAppUninstallation_reg.rsc");
       
    34 _LIT(KAppRscTargetPath,"c:\\private\\10003a3f\\import\\apps\\TestUpdRegAppUninstallation_reg.rsc");
       
    35 
       
    36 _LIT8(KLitMimeType,"mime/updregappuninstall");
       
    37 _LIT8(KLitUpgradeAppMimeType,"mime/upgradeupdregappuninstall");
       
    38 
       
    39 /**
       
    40  * Constructor
       
    41  */	
       
    42 CT_ServiceRegistryTestStep::CT_ServiceRegistryTestStep()
       
    43 	{
       
    44 	// Call base class method to set up the human readable name for logging
       
    45 	SetTestStepName(KT_ServiceRegistryStep);
       
    46 	}
       
    47 
       
    48 /**
       
    49  * Destructor
       
    50  */
       
    51 CT_ServiceRegistryTestStep::~CT_ServiceRegistryTestStep()
       
    52 	{
       
    53 	}
       
    54 
       
    55 /**
       
    56  * @return - TVerdict code
       
    57  * Override of base class virtual
       
    58  */	
       
    59 TVerdict CT_ServiceRegistryTestStep::doTestStepPreambleL()
       
    60 	{
       
    61 	SetTestStepResult(EPass);
       
    62 	return TestStepResult();
       
    63 	}
       
    64 
       
    65 /**
       
    66  * @return - TVerdict code
       
    67  * Override of base class virtual
       
    68  */
       
    69 TVerdict CT_ServiceRegistryTestStep::doTestStepPostambleL()
       
    70 	{
       
    71 	return TestStepResult();
       
    72 	}
       
    73 
       
    74 TVerdict CT_ServiceRegistryTestStep::doTestStepL()
       
    75 	{
       
    76 	INFO_PRINTF1(_L("Testing Apparc...T_ServiceRegistry Test Cases Running..."));
       
    77 
       
    78 	// start an active scheduler
       
    79 	iScheduler=new(ELeave) CActiveScheduler();
       
    80 	CActiveScheduler::Install(iScheduler);
       
    81 
       
    82 	__UHEAP_MARK;
       
    83 	TInt ret;
       
    84 	TRAP(ret,RunTestCasesL())
       
    85 	TEST(ret==KErrNone);
       
    86 	__UHEAP_MARKEND;
       
    87 	
       
    88 	INFO_PRINTF1(_L("...T_ServiceRegistry Test Cases Completed."));
       
    89 
       
    90 	return TestStepResult();
       
    91 	}
       
    92 
       
    93 TInt CT_ServiceRegistryTestStep::RunTestCasesL()
       
    94 	{
       
    95 	RTestableApaLsSession ls;
       
    96 	TEST(KErrNone == ls.Connect());
       
    97 	CleanupClosePushL(ls);
       
    98 
       
    99 	// Use DONT_CHECK because it complaints of heap unbalance (a CTypeStoreManager object, althought it is not actually leaked,
       
   100 	//   but reallocated in CApaAppListServer::DoUpdateTypeStoreL(void)). 
       
   101 	//   This unbalance happens 'randonmly', possibly a timing issue, as the TypeStore refresh is performed in response to a callback from 
       
   102 	//	 a CApaFsMonitor object, which introduces an extra 0.25 second delay before invoking the callback.
       
   103 	//	 *** See DEF101056 ****
       
   104 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAssociation1L(), NO_CLEANUP);
       
   105 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAppForDataTypeAndServiceL(ls), NO_CLEANUP);
       
   106     HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestUpdateOfServiceRegistryOnAppUninstallationL(ls), NO_CLEANUP);
       
   107     HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestServiceRegistryOnAppUpgradeL(ls), NO_CLEANUP);    
       
   108     
       
   109 	CleanupStack::PopAndDestroy(&ls);	
       
   110 	return KErrNone;
       
   111 	}
       
   112 	
       
   113 /**
       
   114    @SYMTestCaseID T-ServiceRegistryTestStep-TestAssociation1L
       
   115   
       
   116    @SYMPREQ 
       
   117   
       
   118    @SYMTestCaseDesc Test the functionality of ServiceRegistry 
       
   119    
       
   120    @SYMTestPriority 
       
   121   
       
   122    @SYMTestStatus Implemented
       
   123    
       
   124    @SYMTestActions Tests the addition, retrieval and deletions of 
       
   125    associations
       
   126    
       
   127    @SYMTestExpectedResults The association are added, retrieved and deleted
       
   128    from the registry
       
   129  */
       
   130 void CT_ServiceRegistryTestStep::TestAssociation1L()
       
   131 	{
       
   132 	INFO_PRINTF1(_L("TestAssociation1L"));
       
   133 	CServiceRegistry* registry = CServiceRegistry::NewL();
       
   134 	CleanupStack::PushL(registry);
       
   135 	
       
   136 	const TUid uid1 = { 0x11111111 };
       
   137 	const TUid uid2 = { 0x22222222 };
       
   138 	
       
   139 	const TUid serviceUid1 = { 0x00001111 };
       
   140 	const TUid serviceUid2 = { 0x00002222 };
       
   141 
       
   142 	const TDataType data1(uid1);
       
   143 	const TDataType data2(uid2);
       
   144 	
       
   145 	TUid result;
       
   146 	
       
   147 	TInt err = registry->GetDefault(serviceUid1, data1, result);
       
   148 	TEST(err == KErrNotFound);
       
   149 	TEST(result == KNullUid);
       
   150 	
       
   151 	err = registry->SetDefault(serviceUid1, data1, uid1);
       
   152 	TEST(err == KErrNone);
       
   153 	err = registry->SetDefault(serviceUid2, data2, uid2);
       
   154 	TEST(err == KErrNone);
       
   155 	
       
   156 	err = registry->GetDefault(serviceUid1, data1, result);
       
   157 	TEST(err == KErrNone);
       
   158 	TEST(result == uid1);
       
   159 	
       
   160 	err = registry->GetDefault(serviceUid2, data2, result);
       
   161 	TEST(err == KErrNone);
       
   162 	TEST(result == uid2);
       
   163 	
       
   164 	err = registry->RemoveEntry(serviceUid1, data1);
       
   165 	TEST(err == KErrNone);
       
   166 	
       
   167 	err = registry->RemoveEntry(serviceUid1, data1);
       
   168 	TEST(err == KErrNotFound);
       
   169 	
       
   170 	err = registry->GetDefault(serviceUid1, data1, result);
       
   171 	TEST(err == KErrNotFound);
       
   172 	TEST(result == KNullUid);
       
   173 	
       
   174 	err = registry->GetDefault(serviceUid2, data2, result);
       
   175 	TEST(err == KErrNone);
       
   176 	TEST(result == uid2);
       
   177 	
       
   178 	err = registry->RemoveEntry(serviceUid2, data2);
       
   179 	TEST(err == KErrNone);
       
   180 	
       
   181 	err = registry->GetDefault(serviceUid2, data2, result);
       
   182 	TEST(err == KErrNotFound);
       
   183 	TEST(result == KNullUid);
       
   184 	
       
   185 	CleanupStack::PopAndDestroy(registry);
       
   186 	}
       
   187 	
       
   188 /**
       
   189    @SYMTestCaseID T-ServiceRegistryTestStep-TestAppForDataTypeAndServiceL
       
   190   
       
   191    @SYMPREQ 
       
   192   
       
   193    @SYMTestCaseDesc Test the functionality of ServiceRegistry 
       
   194    
       
   195    @SYMTestPriority 
       
   196   
       
   197    @SYMTestStatus Implemented
       
   198    
       
   199    @SYMTestActions Tests that the RApaLsSession::AppForDataTypeAndService
       
   200    function behaves correctly when associations are added to the registry
       
   201    
       
   202    @SYMTestExpectedResults The correct application is returned
       
   203  */
       
   204 void CT_ServiceRegistryTestStep::TestAppForDataTypeAndServiceL(RApaLsSession& aLs)
       
   205 	{
       
   206 	INFO_PRINTF1(_L("TestAppForDataTypeAndServiceL"));
       
   207 
       
   208 	const TUid KUidServerApp = {0x10004c56};
       
   209 	const TUid KUidServerApp2 = {0x10004c58};
       
   210 	const TUid KUidServerAppDummy = {0x12344268};
       
   211 	const TUid KUidService01020333 = {0x01020333};
       
   212 	_LIT8(KLitMimeTypePriority,"text/priority");
       
   213 
       
   214 	CServiceRegistry* registry = CServiceRegistry::NewL();
       
   215 	CleanupStack::PushL(registry);
       
   216 
       
   217 	// Check first the default association (no association in registry)
       
   218 	TUid appUid;
       
   219 	TInt err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   220 	TEST(err == KErrNone);
       
   221 	TEST(appUid == KUidServerApp);
       
   222 
       
   223 	// Check after having added an association in the registry
       
   224 	err = registry->SetDefault(KUidService01020333, TDataType(KLitMimeTypePriority), KUidServerApp2);
       
   225 	TEST(err == KErrNone);
       
   226 
       
   227 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   228 	TEST(err == KErrNone);
       
   229 	TEST(appUid == KUidServerApp2);
       
   230 
       
   231 	err = registry->RemoveEntry(KUidService01020333, TDataType(KLitMimeTypePriority));
       
   232 	TEST(err == KErrNone);
       
   233 
       
   234 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   235 	TEST(err == KErrNone);
       
   236 	TEST(appUid == KUidServerApp);
       
   237 
       
   238 	// Check association with app that doesn't exist
       
   239 	err = registry->SetDefault(KUidService01020333, TDataType(KLitMimeTypePriority), KUidServerAppDummy);
       
   240 	TEST(err == KErrNone);
       
   241 
       
   242 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   243 	TEST(err == KErrNone);
       
   244 	TEST(appUid == KUidServerApp);
       
   245 
       
   246 	err = registry->RemoveEntry(KUidService01020333, TDataType(KLitMimeTypePriority));
       
   247 	TEST(err == KErrNone);
       
   248 
       
   249 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   250 	TEST(err == KErrNone);
       
   251 	TEST(appUid == KUidServerApp);
       
   252 
       
   253 	CleanupStack::PopAndDestroy(registry);
       
   254 	}
       
   255 
       
   256 
       
   257 /**
       
   258    @SYMTestCaseID APPFWK-APPARC-0104
       
   259   
       
   260    @SYMDEF INC138417 
       
   261   
       
   262    @SYMTestCaseDesc Tests whether a data mapping of an applicaiton is removed from 
       
   263                     service registry if that applicaiton is uninstalled.
       
   264    
       
   265    @SYMTestPriority 
       
   266   
       
   267    @SYMTestStatus Implemented
       
   268    
       
   269    @SYMTestActions Inserts data mapping for an applicaion and uninstalls that application.
       
   270                    Tests whether the inserted data mapping is removed from the service registry. 
       
   271    
       
   272    @SYMTestExpectedResults The inserted data mapping is removed from the service registry.
       
   273  */
       
   274 
       
   275 void CT_ServiceRegistryTestStep::TestUpdateOfServiceRegistryOnAppUninstallationL(RApaLsSession& aLs)   
       
   276     {
       
   277     INFO_PRINTF1(_L("TestUpdateOfServiceRegistryOnAppUninstallationL"));
       
   278     RSmlTestUtils fs;
       
   279     CleanupClosePushL(fs);
       
   280     User::LeaveIfError(fs.Connect());
       
   281 
       
   282      TInt err = fs.CreateDirectoryL(KImportAppsDir);
       
   283      TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   284      INFO_PRINTF1(_L("c:\\private\\10003a3f\\import\\apps is created successfully or already exists"));
       
   285      
       
   286      //Make sure that the target file does not exist.
       
   287      DeleteFileL(fs, KAppRscTargetPath);
       
   288 
       
   289      // Copy TestUpdRegAppUninstallation_reg.rsc from z:\ to c:\private\10003a3f\import\apps\.
       
   290      err = fs.CopyFileL(KAppRscSourcePath, KAppRscTargetPath);
       
   291      TEST(err == KErrNone);
       
   292      INFO_PRINTF1(_L("Successfully copied TestUpdRegAppUninstallation_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
       
   293 
       
   294      //Wait till the applist is updated.
       
   295      WaitForAppListUpdateL();
       
   296 
       
   297      CServiceRegistry* registry = CServiceRegistry::NewL();
       
   298      CleanupStack::PushL(registry);
       
   299      
       
   300      TUid appUid = {0x10207f80};
       
   301      TUid resultUid={KNullUidValue};    
       
   302      TDataType dataType (KLitMimeType);
       
   303      
       
   304      //Test whether 0x10207f80 application is in application list.
       
   305      TApaAppInfo appInfo;
       
   306      TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNone);
       
   307 
       
   308      //Set 0x10207f80 as default application for "mime/updregappuninstall" MIME type.
       
   309      registry->SetDefault(KOpenServiceUid,dataType, appUid);
       
   310      registry->GetDefault(KOpenServiceUid,dataType, resultUid);
       
   311      TEST(appUid==resultUid);
       
   312  
       
   313      //Delete file c:\\private\\10003a3f\\import\\apps\\TestUpdRegAppUninstallation_reg.rsc 
       
   314      DeleteFileL(fs, KAppRscTargetPath);
       
   315      
       
   316      //Wait till the application list is updated.
       
   317      WaitForAppListUpdateL();  
       
   318      
       
   319      //Check the application is removed from the application list
       
   320      TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNotFound);
       
   321      
       
   322      //Check data mappings related to uninstalled applicaiton is also removed.
       
   323      TEST(registry->GetDefault(KOpenServiceUid,dataType, resultUid)==KErrNotFound);
       
   324 
       
   325      CleanupStack::PopAndDestroy(registry);
       
   326      CleanupStack::PopAndDestroy(&fs);  
       
   327     }
       
   328 
       
   329 void CTestApplistChangeObserver::HandleAppListEvent(TInt /*aEvent*/)
       
   330     {
       
   331     CActiveScheduler::Stop();    
       
   332     }
       
   333 
       
   334 /**
       
   335    @SYMTestCaseID APPFWK-APPARC-0105
       
   336   
       
   337    @SYMDEF INC138417 
       
   338   
       
   339    @SYMTestCaseDesc Tests whether a data mapping of an applicaiton is not changed in 
       
   340                     service registry if that applicaiton is upgraded.
       
   341    
       
   342    @SYMTestPriority 
       
   343   
       
   344    @SYMTestStatus Implemented
       
   345    
       
   346    @SYMTestActions Inserts data mapping for an applicaion and upgrades that application with newer version.
       
   347                    Tests the existence of inserted data mapping in the service registry. 
       
   348    
       
   349    @SYMTestExpectedResults Inserted data mapping is not removed from the service registry.
       
   350  */
       
   351 
       
   352 void CT_ServiceRegistryTestStep::TestServiceRegistryOnAppUpgradeL(RApaLsSession& aLs)   
       
   353     {
       
   354     INFO_PRINTF1(_L("TestServiceRegistryOnAppUpgrade"));
       
   355  
       
   356     RSmlTestUtils fs;
       
   357     CleanupClosePushL(fs);
       
   358     User::LeaveIfError(fs.Connect());
       
   359 
       
   360      TInt err = fs.CreateDirectoryL(KImportAppsDir);
       
   361      TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   362      INFO_PRINTF1(_L("c:\\private\\10003a3f\\import\\apps is created successfully or already exists"));
       
   363      
       
   364      //Make sure that the target file does not exist.
       
   365      DeleteFileL(fs, KAppRscTargetPath);
       
   366 
       
   367      // Copy TestUpdRegAppUninstallation_reg.rsc from z:\ to c:\private\10003a3f\import\apps\.
       
   368      err = fs.CopyFileL(KAppRscSourcePath, KAppRscTargetPath);
       
   369      TEST(err == KErrNone);
       
   370      INFO_PRINTF1(_L("Successfully copied TestUpdRegAppUninstallation_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
       
   371 
       
   372      //Wait till the applist is updated.
       
   373      WaitForAppListUpdateL();
       
   374 
       
   375      CServiceRegistry* registry = CServiceRegistry::NewL();
       
   376      CleanupStack::PushL(registry);
       
   377      
       
   378      TUid appUid = {0x10207f80};
       
   379      TUid resultUid={KNullUidValue};    
       
   380      TDataType dataType (KLitMimeType);
       
   381      
       
   382      //Test whether 0x10207f80 application is in application list.
       
   383      TApaAppInfo appInfo;
       
   384      TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNone);
       
   385 
       
   386      //Set 0x10207f80 as default application for "mime/updregappuninstall" MIME type.
       
   387      registry->SetDefault(KOpenServiceUid,dataType, appUid);
       
   388      registry->GetDefault(KOpenServiceUid,dataType, resultUid);
       
   389      TEST(appUid==resultUid);
       
   390      
       
   391      TDataType upgDataType(KLitUpgradeAppMimeType);
       
   392      err=aLs.AppForDataType(upgDataType,resultUid);
       
   393      TEST(resultUid.iUid==KNullUidValue);
       
   394  
       
   395      DeleteFileL(fs, KAppRscTargetPath);
       
   396      
       
   397      err = fs.CopyFileL(KUpgradeAppRscSourcePath, KAppRscTargetPath);
       
   398      TEST(err == KErrNone);
       
   399      INFO_PRINTF1(_L("Successfully copied TestUpgradeUpdRegAppUninstallation_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
       
   400 
       
   401      //Change the modified time of the file to current time
       
   402      RFs aFs;
       
   403      TEST(aFs.Connect()==KErrNone);
       
   404      TTime modifiedTime(0);
       
   405      modifiedTime.HomeTime();
       
   406      TEST(aFs.SetModified(KAppRscTargetPath, modifiedTime)==KErrNone);
       
   407      aFs.Close();
       
   408      
       
   409      //Wait till the applist is updated.
       
   410      WaitForAppListUpdateL();
       
   411     
       
   412      //Check the application is not removed from the application list
       
   413      TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNone);
       
   414      
       
   415      //Check data mappings related to upgraded applicaiton is not removed.
       
   416      TEST(registry->GetDefault(KOpenServiceUid,dataType, resultUid)==KErrNone);
       
   417      TEST(resultUid==appUid);
       
   418      
       
   419      err=aLs.AppForDataType(upgDataType,resultUid);
       
   420      TEST((err==KErrNone) && (resultUid==appUid));
       
   421      
       
   422      DeleteFileL(fs,KAppRscTargetPath);
       
   423 
       
   424      CleanupStack::PopAndDestroy(registry);
       
   425      CleanupStack::PopAndDestroy(&fs);  
       
   426     }
       
   427 
       
   428 
       
   429 //Deletes the file if it exists.
       
   430 TInt CT_ServiceRegistryTestStep::DeleteFileL(RSmlTestUtils &aFs, const TDesC &aFileName)
       
   431     {
       
   432     TInt fileExists = EFalse;
       
   433     TInt err;
       
   434     aFs.IsFilePresent(aFileName, fileExists);
       
   435     if (fileExists)
       
   436         {
       
   437         aFs.ChangeFilePermissionL(aFileName);
       
   438         err=aFs.DeleteFileL(aFileName);
       
   439         if(err==KErrNone)
       
   440             INFO_PRINTF2(_L("Removed file %S"), &aFileName);
       
   441         else
       
   442             INFO_PRINTF2(_L("Failed to remove file %S"), &aFileName);
       
   443         }
       
   444     else
       
   445         {
       
   446         err=KErrNotFound;
       
   447         }
       
   448 
       
   449     return(err);
       
   450 }
       
   451 
       
   452 //Wait till the application list is updated.
       
   453 void CT_ServiceRegistryTestStep::WaitForAppListUpdateL()
       
   454     {
       
   455      CTestApplistChangeObserver* obs = new(ELeave) CTestApplistChangeObserver();
       
   456      CleanupStack::PushL(obs);
       
   457      CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
       
   458      CleanupStack::PushL(notif);
       
   459      obs->iNotifier = notif;
       
   460      CActiveScheduler::Start();
       
   461      
       
   462      CleanupStack::PopAndDestroy(notif);  
       
   463      CleanupStack::PopAndDestroy(obs);     
       
   464      INFO_PRINTF1(_L("Applicaiton list is updated."));     
       
   465     }