localisation/apparchitecture/tef/T_ServiceRegistryStep.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include "T_ServiceRegistryStep.h"
       
    25 #include <ServiceRegistry.h>
       
    26 #include "testableapalssession.h"
       
    27 #include "appfwk_test_utils.h"
       
    28 
       
    29 /**
       
    30  * Constructor
       
    31  */	
       
    32 CT_ServiceRegistryTestStep::CT_ServiceRegistryTestStep()
       
    33 	{
       
    34 	// Call base class method to set up the human readable name for logging
       
    35 	SetTestStepName(KT_ServiceRegistryStep);
       
    36 	}
       
    37 
       
    38 /**
       
    39  * Destructor
       
    40  */
       
    41 CT_ServiceRegistryTestStep::~CT_ServiceRegistryTestStep()
       
    42 	{
       
    43 	}
       
    44 
       
    45 /**
       
    46  * @return - TVerdict code
       
    47  * Override of base class virtual
       
    48  */	
       
    49 TVerdict CT_ServiceRegistryTestStep::doTestStepPreambleL()
       
    50 	{
       
    51 	SetTestStepResult(EPass);
       
    52 	return TestStepResult();
       
    53 	}
       
    54 
       
    55 /**
       
    56  * @return - TVerdict code
       
    57  * Override of base class virtual
       
    58  */
       
    59 TVerdict CT_ServiceRegistryTestStep::doTestStepPostambleL()
       
    60 	{
       
    61 	return TestStepResult();
       
    62 	}
       
    63 
       
    64 TVerdict CT_ServiceRegistryTestStep::doTestStepL()
       
    65 	{
       
    66 	INFO_PRINTF1(_L("Testing Apparc...T_ServiceRegistry Test Cases Running..."));
       
    67 
       
    68     // start an active scheduler
       
    69     iScheduler=new(ELeave) CActiveScheduler();
       
    70     CActiveScheduler::Install(iScheduler);
       
    71     
       
    72 	__UHEAP_MARK;
       
    73 	TInt ret;
       
    74 	TRAP(ret,RunTestCasesL())
       
    75 	TEST(ret==KErrNone);
       
    76 	__UHEAP_MARKEND;
       
    77 	
       
    78 	INFO_PRINTF1(_L("...T_ServiceRegistry Test Cases Completed."));
       
    79 
       
    80 	return TestStepResult();
       
    81 	}
       
    82 
       
    83 TInt CT_ServiceRegistryTestStep::RunTestCasesL()
       
    84 	{
       
    85 	RTestableApaLsSession ls;
       
    86 	TEST(KErrNone == ls.Connect());
       
    87 	CleanupClosePushL(ls);
       
    88 
       
    89 	// Use DONT_CHECK because it complaints of heap unbalance (a CTypeStoreManager object, althought it is not actually leaked,
       
    90 	//   but reallocated in CApaAppListServer::DoUpdateTypeStoreL(void)). 
       
    91 	//   This unbalance happens 'randonmly', possibly a timing issue, as the TypeStore refresh is performed in response to a callback from 
       
    92 	//	 a CApaFsMonitor object, which introduces an extra 0.25 second delay before invoking the callback.
       
    93 	//	 *** See DEF101056 ****
       
    94 	HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestAssociation1L(), NO_CLEANUP);
       
    95 	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);
       
    97     
       
    98 	CleanupStack::PopAndDestroy(&ls);	
       
    99 	return KErrNone;
       
   100 	}
       
   101 	
       
   102 /**
       
   103    @SYMTestCaseID T-ServiceRegistryTestStep-TestAssociation1L
       
   104   
       
   105    @SYMPREQ 
       
   106   
       
   107    @SYMTestCaseDesc Test the functionality of ServiceRegistry 
       
   108    
       
   109    @SYMTestPriority 
       
   110   
       
   111    @SYMTestStatus Implemented
       
   112    
       
   113    @SYMTestActions Tests the addition, retrieval and deletions of 
       
   114    associations
       
   115    
       
   116    @SYMTestExpectedResults The association are added, retrieved and deleted
       
   117    from the registry
       
   118  */
       
   119 void CT_ServiceRegistryTestStep::TestAssociation1L()
       
   120 	{
       
   121 	INFO_PRINTF1(_L("TestAssociation1L"));
       
   122 	CServiceRegistry* registry = CServiceRegistry::NewL();
       
   123 	CleanupStack::PushL(registry);
       
   124 	
       
   125 	const TUid uid1 = { 0x11111111 };
       
   126 	const TUid uid2 = { 0x22222222 };
       
   127 	
       
   128 	const TUid serviceUid1 = { 0x00001111 };
       
   129 	const TUid serviceUid2 = { 0x00002222 };
       
   130 
       
   131 	const TDataType data1(uid1);
       
   132 	const TDataType data2(uid2);
       
   133 	
       
   134 	TUid result;
       
   135 	
       
   136 	TInt err = registry->GetDefault(serviceUid1, data1, result);
       
   137 	TEST(err == KErrNotFound);
       
   138 	TEST(result == KNullUid);
       
   139 	
       
   140 	err = registry->SetDefault(serviceUid1, data1, uid1);
       
   141 	TEST(err == KErrNone);
       
   142 	err = registry->SetDefault(serviceUid2, data2, uid2);
       
   143 	TEST(err == KErrNone);
       
   144 	
       
   145 	err = registry->GetDefault(serviceUid1, data1, result);
       
   146 	TEST(err == KErrNone);
       
   147 	TEST(result == uid1);
       
   148 	
       
   149 	err = registry->GetDefault(serviceUid2, data2, result);
       
   150 	TEST(err == KErrNone);
       
   151 	TEST(result == uid2);
       
   152 	
       
   153 	err = registry->RemoveEntry(serviceUid1, data1);
       
   154 	TEST(err == KErrNone);
       
   155 	
       
   156 	err = registry->RemoveEntry(serviceUid1, data1);
       
   157 	TEST(err == KErrNotFound);
       
   158 	
       
   159 	err = registry->GetDefault(serviceUid1, data1, result);
       
   160 	TEST(err == KErrNotFound);
       
   161 	TEST(result == KNullUid);
       
   162 	
       
   163 	err = registry->GetDefault(serviceUid2, data2, result);
       
   164 	TEST(err == KErrNone);
       
   165 	TEST(result == uid2);
       
   166 	
       
   167 	err = registry->RemoveEntry(serviceUid2, data2);
       
   168 	TEST(err == KErrNone);
       
   169 	
       
   170 	err = registry->GetDefault(serviceUid2, data2, result);
       
   171 	TEST(err == KErrNotFound);
       
   172 	TEST(result == KNullUid);
       
   173 	
       
   174 	CleanupStack::PopAndDestroy(registry);
       
   175 	}
       
   176 	
       
   177 /**
       
   178    @SYMTestCaseID T-ServiceRegistryTestStep-TestAppForDataTypeAndServiceL
       
   179   
       
   180    @SYMPREQ 
       
   181   
       
   182    @SYMTestCaseDesc Test the functionality of ServiceRegistry 
       
   183    
       
   184    @SYMTestPriority 
       
   185   
       
   186    @SYMTestStatus Implemented
       
   187    
       
   188    @SYMTestActions Tests that the RApaLsSession::AppForDataTypeAndService
       
   189    function behaves correctly when associations are added to the registry
       
   190    
       
   191    @SYMTestExpectedResults The correct application is returned
       
   192  */
       
   193 void CT_ServiceRegistryTestStep::TestAppForDataTypeAndServiceL(RApaLsSession& aLs)
       
   194 	{
       
   195 	INFO_PRINTF1(_L("TestAppForDataTypeAndServiceL"));
       
   196 
       
   197 	const TUid KUidServerApp = {0x10004c56};
       
   198 	const TUid KUidServerApp2 = {0x10004c58};
       
   199 	const TUid KUidServerAppDummy = {0x12344268};
       
   200 	const TUid KUidService01020333 = {0x01020333};
       
   201 	_LIT8(KLitMimeTypePriority,"text/priority");
       
   202 
       
   203 	CServiceRegistry* registry = CServiceRegistry::NewL();
       
   204 	CleanupStack::PushL(registry);
       
   205 
       
   206 	// Check first the default association (no association in registry)
       
   207 	TUid appUid;
       
   208 	TInt err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   209 	TEST(err == KErrNone);
       
   210 	TEST(appUid == KUidServerApp);
       
   211 
       
   212 	// Check after having added an association in the registry
       
   213 	err = registry->SetDefault(KUidService01020333, TDataType(KLitMimeTypePriority), KUidServerApp2);
       
   214 	TEST(err == KErrNone);
       
   215 
       
   216 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   217 	TEST(err == KErrNone);
       
   218 	TEST(appUid == KUidServerApp2);
       
   219 
       
   220 	err = registry->RemoveEntry(KUidService01020333, TDataType(KLitMimeTypePriority));
       
   221 	TEST(err == KErrNone);
       
   222 
       
   223 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   224 	TEST(err == KErrNone);
       
   225 	TEST(appUid == KUidServerApp);
       
   226 
       
   227 	// Check association with app that doesn't exist
       
   228 	err = registry->SetDefault(KUidService01020333, TDataType(KLitMimeTypePriority), KUidServerAppDummy);
       
   229 	TEST(err == KErrNone);
       
   230 
       
   231 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   232 	TEST(err == KErrNone);
       
   233 	TEST(appUid == KUidServerApp);
       
   234 
       
   235 	err = registry->RemoveEntry(KUidService01020333, TDataType(KLitMimeTypePriority));
       
   236 	TEST(err == KErrNone);
       
   237 
       
   238 	err = aLs.AppForDataTypeAndService(TDataType(KLitMimeTypePriority), KUidService01020333,appUid);
       
   239 	TEST(err == KErrNone);
       
   240 	TEST(appUid == KUidServerApp);
       
   241 
       
   242 	CleanupStack::PopAndDestroy(registry);
       
   243 	}
       
   244 
       
   245 /**
       
   246    @SYMTestCaseID APPFWK-APPARC-0104
       
   247   
       
   248    @SYMDEF INC138417 
       
   249   
       
   250    @SYMTestCaseDesc Tests whether a data mapping of an applicaiton is removed from 
       
   251                     service registry if that applicaiton is uninstalled.
       
   252    
       
   253    @SYMTestPriority 
       
   254   
       
   255    @SYMTestStatus Implemented
       
   256    
       
   257    @SYMTestActions Inserts data mapping for an applicaion and uninstalls that application.
       
   258                    Tests whether the inserted data mapping is removed from the service registry. 
       
   259    
       
   260    @SYMTestExpectedResults The inserted data mapping is removed from the service registry.
       
   261  */
       
   262 
       
   263 void CT_ServiceRegistryTestStep::TestUpdateOfServiceRegistryOnAppUninstallationL(RApaLsSession& aLs)   
       
   264     {
       
   265     INFO_PRINTF1(_L("TestUpdateOfServiceRegistryOnAppUninstallationL"));
       
   266     RSmlTestUtils fs;
       
   267     CleanupClosePushL(fs);
       
   268     User::LeaveIfError(fs.Connect());
       
   269 
       
   270      _LIT(KImportAppsDir,"c:\\private\\10003a3f\\import\\apps\\");
       
   271      
       
   272      TInt err = fs.CreateDirectoryL(KImportAppsDir);
       
   273      TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   274      INFO_PRINTF1(_L("c:\\private\\10003a3f\\import\\apps is created successfully or already exists"));
       
   275 
       
   276      
       
   277      // 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);
       
   282      TEST(err == KErrNone);
       
   283      INFO_PRINTF1(_L("Successfully copied TestUpdRegAppUninstallati on_reg.rsc from Z:\\system\\data to c:\\private\\10003a3f\\import\\apps"));
       
   284 
       
   285      CServiceRegistry* registry = CServiceRegistry::NewL();
       
   286      CleanupStack::PushL(registry);
       
   287      
       
   288      //Wait till the application scanning is completed.
       
   289      CTestApplistChangeObserver* obs = new(ELeave) CTestApplistChangeObserver();
       
   290      CleanupStack::PushL(obs);
       
   291      CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
       
   292      CleanupStack::PushL(notif);
       
   293      obs->iNotifier = notif;
       
   294      CActiveScheduler::Start();
       
   295      INFO_PRINTF1(_L("Applicaiton scanning is completed."));
       
   296      CleanupStack::PopAndDestroy(notif);
       
   297  
       
   298      TUid uid1 = {0x10207f80};
       
   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     }
       
   342 
       
   343 void CTestApplistChangeObserver::HandleAppListEvent(TInt /*aEvent*/)
       
   344     {
       
   345     CActiveScheduler::Stop();    
       
   346     }