localisation/apparchitecture/tef/T_ServiceRegistryStep.cpp
branchSymbian3
changeset 57 b8d18c84f71c
parent 6 c108117318cb
--- a/localisation/apparchitecture/tef/T_ServiceRegistryStep.cpp	Wed Jul 28 16:03:37 2010 +0100
+++ b/localisation/apparchitecture/tef/T_ServiceRegistryStep.cpp	Tue Aug 03 10:20:34 2010 +0100
@@ -1,7 +1,7 @@
 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
-// under the terms of the License "Eclipse Public License v1.0"
+// under the terms of "Eclipse Public License v1.0"
 // which accompanies this distribution, and is available
 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 //
@@ -13,8 +13,6 @@
 // Description:
 //
 
-
-
 /**
  @file
  @test
@@ -22,9 +20,21 @@
 */
 
 #include "T_ServiceRegistryStep.h"
-#include <ServiceRegistry.h>
+#include <serviceregistry.h>
 #include "testableapalssession.h"
-#include "appfwk_test_utils.h"
+#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
+#include <apaidpartner.h>
+#endif
+
+
+
+_LIT(KImportAppsDir,"c:\\private\\10003a3f\\import\\apps\\");
+_LIT(KAppRscSourcePath,"z:\\system\\data\\TestUpdRegAppUninstallation_reg.rsc");
+_LIT(KUpgradeAppRscSourcePath,"z:\\system\\data\\TestUpgradeUpdRegAppUninstallation_reg.rsc");
+_LIT(KAppRscTargetPath,"c:\\private\\10003a3f\\import\\apps\\TestUpdRegAppUninstallation_reg.rsc");
+
+_LIT8(KLitMimeType,"mime/updregappuninstall");
+_LIT8(KLitUpgradeAppMimeType,"mime/upgradeupdregappuninstall");
 
 /**
  * Constructor
@@ -65,10 +75,10 @@
 	{
 	INFO_PRINTF1(_L("Testing Apparc...T_ServiceRegistry Test Cases Running..."));
 
-    // start an active scheduler
-    iScheduler=new(ELeave) CActiveScheduler();
-    CActiveScheduler::Install(iScheduler);
-    
+	// start an active scheduler
+	iScheduler=new(ELeave) CActiveScheduler();
+	CActiveScheduler::Install(iScheduler);
+
 	__UHEAP_MARK;
 	TInt ret;
 	TRAP(ret,RunTestCasesL())
@@ -94,6 +104,7 @@
 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAssociation1L(), NO_CLEANUP);
 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAppForDataTypeAndServiceL(ls), NO_CLEANUP);
     HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestUpdateOfServiceRegistryOnAppUninstallationL(ls), NO_CLEANUP);
+    HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestServiceRegistryOnAppUpgradeL(ls), NO_CLEANUP);    
     
 	CleanupStack::PopAndDestroy(&ls);	
 	return KErrNone;
@@ -242,6 +253,7 @@
 	CleanupStack::PopAndDestroy(registry);
 	}
 
+
 /**
    @SYMTestCaseID APPFWK-APPARC-0104
   
@@ -267,71 +279,45 @@
     CleanupClosePushL(fs);
     User::LeaveIfError(fs.Connect());
 
-     _LIT(KImportAppsDir,"c:\\private\\10003a3f\\import\\apps\\");
-     
      TInt err = fs.CreateDirectoryL(KImportAppsDir);
      TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
      INFO_PRINTF1(_L("c:\\private\\10003a3f\\import\\apps is created successfully or already exists"));
+     
+     //Make sure that the target file does not exist.
+     DeleteFileL(fs, KAppRscTargetPath);
 
-     
      // Copy TestUpdRegAppUninstallation_reg.rsc from z:\ to c:\private\10003a3f\import\apps\.
-     _LIT(KAppRscSourcePath,"z:\\system\\data\\TestUpdRegAppUninstallation_reg.rsc");
-     _LIT(KAppRscTargetPath,"c:\\private\\10003a3f\\import\\apps\\TestUpdRegAppUninstallation_reg.rsc");
-     
      err = fs.CopyFileL(KAppRscSourcePath, KAppRscTargetPath);
      TEST(err == KErrNone);
-     INFO_PRINTF1(_L("Successfully copied TestUpdRegAppUninstallati on_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
+     INFO_PRINTF1(_L("Successfully copied TestUpdRegAppUninstallation_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
+
+     //Wait till the applist is updated.
+     WaitForAppListUpdateL();
 
      CServiceRegistry* registry = CServiceRegistry::NewL();
      CleanupStack::PushL(registry);
      
-     //Wait till the application scanning is completed.
-     CTestApplistChangeObserver* obs = new(ELeave) CTestApplistChangeObserver();
-     CleanupStack::PushL(obs);
-     CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
-     CleanupStack::PushL(notif);
-     obs->iNotifier = notif;
-     CActiveScheduler::Start();
-     INFO_PRINTF1(_L("Applicaiton scanning is completed."));
-     CleanupStack::PopAndDestroy(notif);
- 
-     TUid uid1 = {0x10207f80};
+     TUid appUid = {0x10207f80};
      TUid resultUid={KNullUidValue};    
-     _LIT8(KLitMimeType,"mime/updregappuninstall");
      TDataType dataType (KLitMimeType);
      
      //Test whether 0x10207f80 application is in application list.
      TApaAppInfo appInfo;
-     TEST(aLs.GetAppInfo(appInfo,uid1)==KErrNone);
+     TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNone);
 
      //Set 0x10207f80 as default application for "mime/updregappuninstall" MIME type.
-     registry->SetDefault(KOpenServiceUid,dataType, uid1);
+     registry->SetDefault(KOpenServiceUid,dataType, appUid);
      registry->GetDefault(KOpenServiceUid,dataType, resultUid);
-     TEST(uid1==resultUid);
+     TEST(appUid==resultUid);
  
-     TInt fileExists = EFalse;
-     fs.IsFilePresent(KAppRscTargetPath, fileExists);
-     if (fileExists)
-         {
-         fs.ChangeFilePermissionL(KAppRscTargetPath); // clear readonly attribute inherited from z:
-         err = fs.DeleteFileL(KAppRscTargetPath);
-         if(err == KErrNone) 
-             INFO_PRINTF1(_L("Removed file TestUpdRegAppUninstallation_reg.rsc"));
-         else 
-             INFO_PRINTF1(_L("Failed to remove TestUpdRegAppUninstallation_reg.rsc"));    
-         }
-
-     //Wait till the application scanning is completed
-     notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
-      CleanupStack::PushL(notif);
-      obs->iNotifier = notif;
-      CActiveScheduler::Start();
-      INFO_PRINTF1(_L("Applicaiton scanning is completed."));
-      CleanupStack::PopAndDestroy(notif);
-      CleanupStack::PopAndDestroy(obs);    
+     //Delete file c:\\private\\10003a3f\\import\\apps\\TestUpdRegAppUninstallation_reg.rsc 
+     DeleteFileL(fs, KAppRscTargetPath);
      
-     //Check the application is removed form the application list
-     TEST(aLs.GetAppInfo(appInfo,uid1)==KErrNotFound);
+     //Wait till the application list is updated.
+     WaitForAppListUpdateL();  
+     
+     //Check the application is removed from the application list
+     TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNotFound);
      
      //Check data mappings related to uninstalled applicaiton is also removed.
      TEST(registry->GetDefault(KOpenServiceUid,dataType, resultUid)==KErrNotFound);
@@ -344,3 +330,136 @@
     {
     CActiveScheduler::Stop();    
     }
+
+/**
+   @SYMTestCaseID APPFWK-APPARC-0105
+  
+   @SYMDEF INC138417 
+  
+   @SYMTestCaseDesc Tests whether a data mapping of an applicaiton is not changed in 
+                    service registry if that applicaiton is upgraded.
+   
+   @SYMTestPriority 
+  
+   @SYMTestStatus Implemented
+   
+   @SYMTestActions Inserts data mapping for an applicaion and upgrades that application with newer version.
+                   Tests the existence of inserted data mapping in the service registry. 
+   
+   @SYMTestExpectedResults Inserted data mapping is not removed from the service registry.
+ */
+
+void CT_ServiceRegistryTestStep::TestServiceRegistryOnAppUpgradeL(RApaLsSession& aLs)   
+    {
+    INFO_PRINTF1(_L("TestServiceRegistryOnAppUpgrade"));
+ 
+    RSmlTestUtils fs;
+    CleanupClosePushL(fs);
+    User::LeaveIfError(fs.Connect());
+
+     TInt err = fs.CreateDirectoryL(KImportAppsDir);
+     TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
+     INFO_PRINTF1(_L("c:\\private\\10003a3f\\import\\apps is created successfully or already exists"));
+     
+     //Make sure that the target file does not exist.
+     DeleteFileL(fs, KAppRscTargetPath);
+
+     // Copy TestUpdRegAppUninstallation_reg.rsc from z:\ to c:\private\10003a3f\import\apps\.
+     err = fs.CopyFileL(KAppRscSourcePath, KAppRscTargetPath);
+     TEST(err == KErrNone);
+     INFO_PRINTF1(_L("Successfully copied TestUpdRegAppUninstallation_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
+
+     //Wait till the applist is updated.
+     WaitForAppListUpdateL();
+
+     CServiceRegistry* registry = CServiceRegistry::NewL();
+     CleanupStack::PushL(registry);
+     
+     TUid appUid = {0x10207f80};
+     TUid resultUid={KNullUidValue};    
+     TDataType dataType (KLitMimeType);
+     
+     //Test whether 0x10207f80 application is in application list.
+     TApaAppInfo appInfo;
+     TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNone);
+
+     //Set 0x10207f80 as default application for "mime/updregappuninstall" MIME type.
+     registry->SetDefault(KOpenServiceUid,dataType, appUid);
+     registry->GetDefault(KOpenServiceUid,dataType, resultUid);
+     TEST(appUid==resultUid);
+     
+     TDataType upgDataType(KLitUpgradeAppMimeType);
+     err=aLs.AppForDataType(upgDataType,resultUid);
+     TEST(resultUid.iUid==KNullUidValue);
+ 
+     DeleteFileL(fs, KAppRscTargetPath);
+     
+     err = fs.CopyFileL(KUpgradeAppRscSourcePath, KAppRscTargetPath);
+     TEST(err == KErrNone);
+     INFO_PRINTF1(_L("Successfully copied TestUpgradeUpdRegAppUninstallation_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
+
+     //Change the modified time of the file to current time
+     RFs aFs;
+     TEST(aFs.Connect()==KErrNone);
+     TTime modifiedTime(0);
+     modifiedTime.HomeTime();
+     TEST(aFs.SetModified(KAppRscTargetPath, modifiedTime)==KErrNone);
+     aFs.Close();
+     
+     //Wait till the applist is updated.
+     WaitForAppListUpdateL();
+    
+     //Check the application is not removed from the application list
+     TEST(aLs.GetAppInfo(appInfo,appUid)==KErrNone);
+     
+     //Check data mappings related to upgraded applicaiton is not removed.
+     TEST(registry->GetDefault(KOpenServiceUid,dataType, resultUid)==KErrNone);
+     TEST(resultUid==appUid);
+     
+     err=aLs.AppForDataType(upgDataType,resultUid);
+     TEST((err==KErrNone) && (resultUid==appUid));
+     
+     DeleteFileL(fs,KAppRscTargetPath);
+
+     CleanupStack::PopAndDestroy(registry);
+     CleanupStack::PopAndDestroy(&fs);  
+    }
+
+
+//Deletes the file if it exists.
+TInt CT_ServiceRegistryTestStep::DeleteFileL(RSmlTestUtils &aFs, const TDesC &aFileName)
+    {
+    TInt fileExists = EFalse;
+    TInt err;
+    aFs.IsFilePresent(aFileName, fileExists);
+    if (fileExists)
+        {
+        aFs.ChangeFilePermissionL(aFileName);
+        err=aFs.DeleteFileL(aFileName);
+        if(err==KErrNone)
+            INFO_PRINTF2(_L("Removed file %S"), &aFileName);
+        else
+            INFO_PRINTF2(_L("Failed to remove file %S"), &aFileName);
+        }
+    else
+        {
+        err=KErrNotFound;
+        }
+
+    return(err);
+}
+
+//Wait till the application list is updated.
+void CT_ServiceRegistryTestStep::WaitForAppListUpdateL()
+    {
+     CTestApplistChangeObserver* obs = new(ELeave) CTestApplistChangeObserver();
+     CleanupStack::PushL(obs);
+     CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
+     CleanupStack::PushL(notif);
+     obs->iNotifier = notif;
+     CActiveScheduler::Start();
+     
+     CleanupStack::PopAndDestroy(notif);  
+     CleanupStack::PopAndDestroy(obs);     
+     INFO_PRINTF1(_L("Applicaiton list is updated."));     
+    }