localisation/apparchitecture/tef/T_ServiceRegistryStep.cpp
branchSymbian3
changeset 57 b8d18c84f71c
parent 6 c108117318cb
equal deleted inserted replaced
56:aa99f2208aad 57:b8d18c84f71c
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 
       
    17 
       
    18 /**
    16 /**
    19  @file
    17  @file
    20  @test
    18  @test
    21  @internalComponent - Internal Symbian test code
    19  @internalComponent - Internal Symbian test code
    22 */
    20 */
    23 
    21 
    24 #include "T_ServiceRegistryStep.h"
    22 #include "T_ServiceRegistryStep.h"
    25 #include <ServiceRegistry.h>
    23 #include <serviceregistry.h>
    26 #include "testableapalssession.h"
    24 #include "testableapalssession.h"
    27 #include "appfwk_test_utils.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");
    28 
    38 
    29 /**
    39 /**
    30  * Constructor
    40  * Constructor
    31  */	
    41  */	
    32 CT_ServiceRegistryTestStep::CT_ServiceRegistryTestStep()
    42 CT_ServiceRegistryTestStep::CT_ServiceRegistryTestStep()
    63 
    73 
    64 TVerdict CT_ServiceRegistryTestStep::doTestStepL()
    74 TVerdict CT_ServiceRegistryTestStep::doTestStepL()
    65 	{
    75 	{
    66 	INFO_PRINTF1(_L("Testing Apparc...T_ServiceRegistry Test Cases Running..."));
    76 	INFO_PRINTF1(_L("Testing Apparc...T_ServiceRegistry Test Cases Running..."));
    67 
    77 
    68     // start an active scheduler
    78 	// start an active scheduler
    69     iScheduler=new(ELeave) CActiveScheduler();
    79 	iScheduler=new(ELeave) CActiveScheduler();
    70     CActiveScheduler::Install(iScheduler);
    80 	CActiveScheduler::Install(iScheduler);
    71     
    81 
    72 	__UHEAP_MARK;
    82 	__UHEAP_MARK;
    73 	TInt ret;
    83 	TInt ret;
    74 	TRAP(ret,RunTestCasesL())
    84 	TRAP(ret,RunTestCasesL())
    75 	TEST(ret==KErrNone);
    85 	TEST(ret==KErrNone);
    76 	__UHEAP_MARKEND;
    86 	__UHEAP_MARKEND;
    92 	//	 a CApaFsMonitor object, which introduces an extra 0.25 second delay before invoking the callback.
   102 	//	 a CApaFsMonitor object, which introduces an extra 0.25 second delay before invoking the callback.
    93 	//	 *** See DEF101056 ****
   103 	//	 *** See DEF101056 ****
    94 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAssociation1L(), NO_CLEANUP);
   104 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAssociation1L(), NO_CLEANUP);
    95 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAppForDataTypeAndServiceL(ls), NO_CLEANUP);
   105 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAppForDataTypeAndServiceL(ls), NO_CLEANUP);
    96     HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestUpdateOfServiceRegistryOnAppUninstallationL(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);    
    97     
   108     
    98 	CleanupStack::PopAndDestroy(&ls);	
   109 	CleanupStack::PopAndDestroy(&ls);	
    99 	return KErrNone;
   110 	return KErrNone;
   100 	}
   111 	}
   101 	
   112 	
   239 	TEST(err == KErrNone);
   250 	TEST(err == KErrNone);
   240 	TEST(appUid == KUidServerApp);
   251 	TEST(appUid == KUidServerApp);
   241 
   252 
   242 	CleanupStack::PopAndDestroy(registry);
   253 	CleanupStack::PopAndDestroy(registry);
   243 	}
   254 	}
       
   255 
   244 
   256 
   245 /**
   257 /**
   246    @SYMTestCaseID APPFWK-APPARC-0104
   258    @SYMTestCaseID APPFWK-APPARC-0104
   247   
   259   
   248    @SYMDEF INC138417 
   260    @SYMDEF INC138417 
   265     INFO_PRINTF1(_L("TestUpdateOfServiceRegistryOnAppUninstallationL"));
   277     INFO_PRINTF1(_L("TestUpdateOfServiceRegistryOnAppUninstallationL"));
   266     RSmlTestUtils fs;
   278     RSmlTestUtils fs;
   267     CleanupClosePushL(fs);
   279     CleanupClosePushL(fs);
   268     User::LeaveIfError(fs.Connect());
   280     User::LeaveIfError(fs.Connect());
   269 
   281 
   270      _LIT(KImportAppsDir,"c:\\private\\10003a3f\\import\\apps\\");
       
   271      
       
   272      TInt err = fs.CreateDirectoryL(KImportAppsDir);
   282      TInt err = fs.CreateDirectoryL(KImportAppsDir);
   273      TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
   283      TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
   274      INFO_PRINTF1(_L("c:\\private\\10003a3f\\import\\apps is created successfully or already exists"));
   284      INFO_PRINTF1(_L("c:\\private\\10003a3f\\import\\apps is created successfully or already exists"));
   275 
   285      
   276      
   286      //Make sure that the target file does not exist.
       
   287      DeleteFileL(fs, KAppRscTargetPath);
       
   288 
   277      // Copy TestUpdRegAppUninstallation_reg.rsc from z:\ to c:\private\10003a3f\import\apps\.
   289      // Copy TestUpdRegAppUninstallation_reg.rsc from z:\ to c:\private\10003a3f\import\apps\.
   278      _LIT(KAppRscSourcePath,"z:\\system\\data\\TestUpdRegAppUninstallation_reg.rsc");
       
   279      _LIT(KAppRscTargetPath,"c:\\private\\10003a3f\\import\\apps\\TestUpdRegAppUninstallation_reg.rsc");
       
   280      
       
   281      err = fs.CopyFileL(KAppRscSourcePath, KAppRscTargetPath);
   290      err = fs.CopyFileL(KAppRscSourcePath, KAppRscTargetPath);
   282      TEST(err == KErrNone);
   291      TEST(err == KErrNone);
   283      INFO_PRINTF1(_L("Successfully copied TestUpdRegAppUninstallati on_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
   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();
   284 
   296 
   285      CServiceRegistry* registry = CServiceRegistry::NewL();
   297      CServiceRegistry* registry = CServiceRegistry::NewL();
   286      CleanupStack::PushL(registry);
   298      CleanupStack::PushL(registry);
   287      
   299      
   288      //Wait till the application scanning is completed.
   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     {
   289      CTestApplistChangeObserver* obs = new(ELeave) CTestApplistChangeObserver();
   455      CTestApplistChangeObserver* obs = new(ELeave) CTestApplistChangeObserver();
   290      CleanupStack::PushL(obs);
   456      CleanupStack::PushL(obs);
   291      CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
   457      CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
   292      CleanupStack::PushL(notif);
   458      CleanupStack::PushL(notif);
   293      obs->iNotifier = notif;
   459      obs->iNotifier = notif;
   294      CActiveScheduler::Start();
   460      CActiveScheduler::Start();
   295      INFO_PRINTF1(_L("Applicaiton scanning is completed."));
   461      
   296      CleanupStack::PopAndDestroy(notif);
   462      CleanupStack::PopAndDestroy(notif);  
   297  
   463      CleanupStack::PopAndDestroy(obs);     
   298      TUid uid1 = {0x10207f80};
   464      INFO_PRINTF1(_L("Applicaiton list is updated."));     
   299      TUid resultUid={KNullUidValue};    
       
   300      _LIT8(KLitMimeType,"mime/updregappuninstall");
       
   301      TDataType dataType (KLitMimeType);
       
   302      
       
   303      //Test whether 0x10207f80 application is in application list.
       
   304      TApaAppInfo appInfo;
       
   305      TEST(aLs.GetAppInfo(appInfo,uid1)==KErrNone);
       
   306 
       
   307      //Set 0x10207f80 as default application for "mime/updregappuninstall" MIME type.
       
   308      registry->SetDefault(KOpenServiceUid,dataType, uid1);
       
   309      registry->GetDefault(KOpenServiceUid,dataType, resultUid);
       
   310      TEST(uid1==resultUid);
       
   311  
       
   312      TInt fileExists = EFalse;
       
   313      fs.IsFilePresent(KAppRscTargetPath, fileExists);
       
   314      if (fileExists)
       
   315          {
       
   316          fs.ChangeFilePermissionL(KAppRscTargetPath); // clear readonly attribute inherited from z:
       
   317          err = fs.DeleteFileL(KAppRscTargetPath);
       
   318          if(err == KErrNone) 
       
   319              INFO_PRINTF1(_L("Removed file TestUpdRegAppUninstallation_reg.rsc"));
       
   320          else 
       
   321              INFO_PRINTF1(_L("Failed to remove TestUpdRegAppUninstallation_reg.rsc"));    
       
   322          }
       
   323 
       
   324      //Wait till the application scanning is completed
       
   325      notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
       
   326       CleanupStack::PushL(notif);
       
   327       obs->iNotifier = notif;
       
   328       CActiveScheduler::Start();
       
   329       INFO_PRINTF1(_L("Applicaiton scanning is completed."));
       
   330       CleanupStack::PopAndDestroy(notif);
       
   331       CleanupStack::PopAndDestroy(obs);    
       
   332      
       
   333      //Check the application is removed form the application list
       
   334      TEST(aLs.GetAppInfo(appInfo,uid1)==KErrNotFound);
       
   335      
       
   336      //Check data mappings related to uninstalled applicaiton is also removed.
       
   337      TEST(registry->GetDefault(KOpenServiceUid,dataType, resultUid)==KErrNotFound);
       
   338 
       
   339      CleanupStack::PopAndDestroy(registry);
       
   340      CleanupStack::PopAndDestroy(&fs);  
       
   341     }
   465     }
   342 
       
   343 void CTestApplistChangeObserver::HandleAppListEvent(TInt /*aEvent*/)
       
   344     {
       
   345     CActiveScheduler::Stop();    
       
   346     }