appfw/apparchitecture/tef/t_drivenotification.cpp
changeset 0 2e3d3ce01487
child 29 6a787171e1de
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 // Only in Armv5 platform,
       
    15 // C: Drive is set to be monitored using KApaDrivesToMonitor. The value of 
       
    16 // KApaDrivesToMonitor is set to 4. It is computed in the following way.
       
    17 // ZY XWVU TSRQ PONM LKJI HGFE DCBA
       
    18 // 00 0000 0000 0000 0000 0000 0100. 
       
    19 // If the value is Set then the corresponding drive has to be monitored.
       
    20 // 
       
    21 //
       
    22 
       
    23 /**
       
    24  @file
       
    25  @test
       
    26  @internalComponent - Internal Symbian test code
       
    27 */
       
    28 
       
    29 #include <e32test.h>
       
    30 #include "appfwk_test_utils.h"
       
    31 #include "t_drivenotification.h"
       
    32 
       
    33 _LIT(KResourceFileSourceZ, "z:\\system\\data\\tnotifydrivesapp_reg.rsc");
       
    34 
       
    35 void CDriveTestObserver::HandleAppListEvent(TInt /*aEvent*/)
       
    36 	{
       
    37 	iNotified++;
       
    38 	if (iNotifier)
       
    39 		iNotifier->Cancel();
       
    40 	CActiveScheduler::Stop();
       
    41 	}
       
    42 
       
    43 CT_DriveNotificationStep::~CT_DriveNotificationStep()
       
    44 	{	
       
    45 	}
       
    46 
       
    47 CT_DriveNotificationStep::CT_DriveNotificationStep()
       
    48 	{
       
    49 	// Call base class method to set up the human readable name for logging
       
    50 	SetTestStepName(KT_DriveNotificationStep);
       
    51 	}
       
    52 	
       
    53 /**
       
    54    @SYMTestCaseID	APPFWK-APPARC-0083
       
    55   
       
    56    @SYMCR 			CR1035
       
    57   
       
    58    @SYMTestCaseDesc Test for the drive's notification.
       
    59    
       
    60    @SYMTestPriority High 
       
    61   
       
    62    @SYMTestStatus 	Implemented
       
    63    
       
    64    @SYMTestActions 	In armv5 platform, the patchable constant KApaDrivesToMonitor is set to monitor C: drive. 
       
    65    Hence the notifications from other drives are ignored. The test copies the tnotifydrivesapp_reg.rsc to either 
       
    66    D: or E: drive and also to C:. There will be no notification from D: or E: drives and the applist wont be 
       
    67    updated whereas from C: notifications will be issued and applist will be updated.
       
    68    In Winscw platform, all the drives will be monitored by default and notifications will be issued when the test
       
    69    copies tnotifydrivesapp_reg.rsc to C: drive and W: drive and the applist will be updated.
       
    70    
       
    71    @SYMTestExpectedResults The app is not added to the applist when no notification is issued and applist is 
       
    72    updated when notifications are issued.
       
    73 */    
       
    74 void CT_DriveNotificationStep::TestDrivesNotificationL()
       
    75 	{
       
    76 	INFO_PRINTF1(_L("Start TestDriveNotification()"));
       
    77 	
       
    78 	TApaAppInfo appInfo;
       
    79 	TUid appUid = {0xA0003376};
       
    80 	RApaLsSession theLs;
       
    81 	User::LeaveIfError(theLs.Connect());
       
    82 	CleanupClosePushL(theLs);
       
    83 	
       
    84 	// Wait for applist to be updated.... 
       
    85 	RPointerArray<TDesC> dummy;
       
    86 	User::LeaveIfError(theLs.ForceRegistration(dummy));
       
    87 	
       
    88 	//Check whether app is not present in the applist
       
    89 	TInt ret = theLs.GetAppInfo(appInfo,appUid);
       
    90 	INFO_PRINTF3(_L(" Expected value is %d, Call to GetAppInfo returned : %d  "), KErrNotFound, ret);
       
    91 	TEST(ret==KErrNotFound);
       
    92 	
       
    93 	//Copy the registration file to C: drive.
       
    94 	CopyRegFileL(EDriveC);
       
    95 	
       
    96 	CDriveTestObserver* obs = new(ELeave) CDriveTestObserver();
       
    97 	CleanupStack::PushL(obs);
       
    98 	CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh);
       
    99 	CleanupStack::PushL(notif);
       
   100 	
       
   101 	obs->iNotifier = notif;
       
   102 		
       
   103 	CActiveScheduler::Start();
       
   104 	//Since c:\\private\\10003a3f\\Import\\apps\\ path is Monitored, a notification is issued and applist is updated.
       
   105 	TEST(obs->iNotified > 0);	
       
   106 	INFO_PRINTF2(_L("Received %d notifications"),obs->iNotified);
       
   107 	
       
   108 	//Check whether applist is updated and app is present in the applist.
       
   109 	ret = theLs.GetAppInfo(appInfo,appUid);
       
   110 	INFO_PRINTF3(_L(" Expected value is %d, Call to GetAppInfo returned : %d  "), KErrNone, ret);
       
   111 	TEST(ret==KErrNone);
       
   112 	
       
   113 	//Deleting the rsc file that is present in c:\\private\\10003a3f\\Import\\apps\\ path.
       
   114 	DeleteRegFileL(EDriveC);
       
   115 	
       
   116 	// Wait for applist to be updated.... 
       
   117 	User::LeaveIfError(theLs.ForceRegistration(dummy));
       
   118 	
       
   119 	//Check whether applist is updated and app is absent in the applist.
       
   120 	ret = theLs.GetAppInfo(appInfo,appUid);
       
   121 	INFO_PRINTF3(_L(" Expected value is %d, Call to GetAppInfo returned : %d  "), KErrNotFound, ret);
       
   122 	TEST(ret==KErrNotFound);
       
   123 		
       
   124 	//Armv5 platform, GetMMCDriveL() returns either the D: (in case of NAND rom) or E: (in case of Normal rom).
       
   125 	//Winscw platform, GetMMCDriveL() returns W:.
       
   126 	TDriveNumber drive = GetMMCDriveL();
       
   127 	
       
   128 	//Copy the registration file to drive specified.
       
   129 	CopyRegFileL(drive);
       
   130 	
       
   131 	// Wait for applist to be updated.... 
       
   132 	User::LeaveIfError(theLs.ForceRegistration(dummy));
       
   133 	
       
   134 	//Check whether applist is updated and app is present in the applist.
       
   135 #ifdef __EABI__
       
   136 	ret = theLs.GetAppInfo(appInfo,appUid);
       
   137 	TEST (ret == KErrNotFound);
       
   138 	INFO_PRINTF3(_L(" Expected value is %d, Call to GetAppInfo returned : %d  "), KErrNotFound, ret);
       
   139 	//Deleting the rsc file.
       
   140 	DeleteRegFileL(drive);
       
   141 #else	
       
   142 	ret = theLs.GetAppInfo(appInfo,appUid);
       
   143 	TEST(ret==KErrNone);
       
   144 	INFO_PRINTF3(_L(" Expected value is %d, Call to GetAppInfo returned : %d  "),KErrNone, ret);
       
   145 	//Deleting the rsc file.
       
   146 	DeleteRegFileL(drive);
       
   147 #endif
       
   148 	CleanupStack::PopAndDestroy(3, &theLs);
       
   149 	
       
   150 	INFO_PRINTF1(_L("End TestDrivesNotificationL()"));
       
   151 	}
       
   152 /*
       
   153 Copy the tnotifydrivesapp_reg.rsc file from source to destination. 
       
   154 In Winscw platform, the registration file is copied to C: and W: drive.
       
   155 In Armv5 platform, the registration file is copied to C: and D: or E: drive. 
       
   156 */
       
   157 
       
   158 void CT_DriveNotificationStep::CopyRegFileL(TDriveNumber aDriveNumber)
       
   159 	{
       
   160 	_LIT(KResourceFileTarget, ":\\private\\10003a3f\\Import\\apps\\tnotifydrivesapp_reg.rsc");	
       
   161 	_LIT(KResourceAppFolder, ":\\private\\10003a3f\\Import\\apps\\");
       
   162 	RBuf tempPathToBeCopied, tempFolderToBeCreated;
       
   163 	RFs fs;
       
   164 	TChar driveLetter;
       
   165 	CleanupClosePushL(fs);
       
   166 	User::LeaveIfError(fs.Connect());
       
   167 	TInt maxSizeofFileName = KResourceFileTarget().Length() + 1;
       
   168 	TInt maxSizeofFolderName = KResourceAppFolder().Length() + 1;
       
   169 	tempPathToBeCopied.CreateL(maxSizeofFileName);
       
   170 	CleanupClosePushL(tempPathToBeCopied);
       
   171 	tempFolderToBeCreated.CreateL(maxSizeofFolderName);
       
   172 	CleanupClosePushL(tempFolderToBeCreated);
       
   173 	fs.DriveToChar(aDriveNumber,driveLetter);
       
   174 	tempPathToBeCopied.Append(driveLetter);
       
   175 	tempPathToBeCopied.Append(KResourceFileTarget);
       
   176 	tempFolderToBeCreated.Append(driveLetter);
       
   177 	tempFolderToBeCreated.Append(KResourceAppFolder);
       
   178 	RSmlTestUtils smlServer;
       
   179 	CleanupClosePushL(smlServer);
       
   180 	TInt ret = smlServer.Connect();
       
   181 	TEST(ret == KErrNone);
       
   182 	ret = smlServer.CreateDirectoryL(tempFolderToBeCreated);
       
   183 	if (ret != KErrNone && ret != KErrAlreadyExists)
       
   184 		{
       
   185 		User::LeaveIfError(ret);
       
   186 		}
       
   187 	ret = smlServer.CopyFileL(KResourceFileSourceZ, tempPathToBeCopied);
       
   188 	TEST(ret == KErrNone);
       
   189 	INFO_PRINTF2(_L("Copied Registration file. Finished with the value : %d "), ret);
       
   190 	CleanupStack::PopAndDestroy(4, &fs);
       
   191 	}
       
   192 
       
   193 
       
   194 
       
   195 void CT_DriveNotificationStep::DeleteRegFileL(TDriveNumber aDriveNumber)
       
   196 	{
       
   197 	_LIT(KResourceFileTarget, ":\\private\\10003a3f\\Import\\apps\\tnotifydrivesapp_reg.rsc");	
       
   198 	RBuf tempPathToBeDeleted;
       
   199 	RFs fs;
       
   200 	TChar driveLetter;
       
   201 	CleanupClosePushL(fs);
       
   202 	User::LeaveIfError(fs.Connect());
       
   203 	TInt maxSizeofFileName = KResourceFileTarget().Length() + 1;
       
   204 	tempPathToBeDeleted.CreateL(maxSizeofFileName);
       
   205 	CleanupClosePushL(tempPathToBeDeleted);
       
   206 	fs.DriveToChar(aDriveNumber,driveLetter);
       
   207 	tempPathToBeDeleted.Append(driveLetter);
       
   208 	tempPathToBeDeleted.Append(KResourceFileTarget);
       
   209 	RSmlTestUtils smlServer;
       
   210 	CleanupClosePushL(smlServer);
       
   211 	TInt ret = smlServer.Connect();
       
   212 	TEST(ret == KErrNone);
       
   213 	ret = smlServer.SetReadOnly(tempPathToBeDeleted, 0)	;
       
   214 	TEST(ret == KErrNone);
       
   215 	//delete the file
       
   216 	ret = smlServer.DeleteFileL(tempPathToBeDeleted);	
       
   217 	TEST(ret == KErrNone);
       
   218 	INFO_PRINTF2(_L("Deleted Registration file. Finished with value : %d"), ret);	
       
   219 	CleanupStack::PopAndDestroy(3,&fs);
       
   220 	}
       
   221 	
       
   222 
       
   223 TDriveNumber CT_DriveNotificationStep::GetMMCDriveL()
       
   224 	{
       
   225 	TDriveNumber drive = EDriveW;	
       
   226 #ifdef __EABI__
       
   227 	RFs	fs;
       
   228  	User::LeaveIfError(fs.Connect());
       
   229 	// The removable media is expected at D: on NAND ROM and at E: on normal ROMs.
       
   230 	//The following code works on techview but not guaranteed to work on all platforms. 
       
   231 	TDriveInfo driveInfo;
       
   232 	TInt err = fs.Drive(driveInfo, EDriveD);
       
   233 	if(err == KErrNone && ((driveInfo.iDriveAtt & KDriveAttRemovable) != 0))
       
   234 		{
       
   235 	 	 // Use drive D
       
   236 	 	drive = EDriveD;
       
   237 	 	}
       
   238 	 else
       
   239 	 	{
       
   240 		err = fs.Drive(driveInfo, EDriveE);
       
   241 		if(err == KErrNone && ((driveInfo.iDriveAtt & KDriveAttRemovable) != 0))
       
   242 			{
       
   243 		 	// Use drive E
       
   244 		 	drive = EDriveE;
       
   245 		 	}
       
   246 		}
       
   247 	fs.Close();
       
   248 #else
       
   249 	drive = EDriveW;
       
   250 #endif	
       
   251 	return drive;
       
   252 	}
       
   253 
       
   254 
       
   255 TVerdict CT_DriveNotificationStep::doTestStepL()
       
   256 	{
       
   257 	INFO_PRINTF1(_L("Testing the Notifications ... T_DriveNotification"));
       
   258 	
       
   259 	// start an active scheduler
       
   260 	iScheduler=new(ELeave) CActiveScheduler();
       
   261 	CActiveScheduler::Install(iScheduler);
       
   262 	
       
   263 	// run the testcode (inside an alloc heaven harness)
       
   264  	__UHEAP_MARK;
       
   265  	 	
       
   266  	TRAPD(ret,TestDrivesNotificationL());
       
   267 	TEST(ret==KErrNone);
       
   268 	INFO_PRINTF2(_L("TestDrivesNotificationL finished with code '%d'\n"), ret);
       
   269  	
       
   270   	__UHEAP_MARKEND;
       
   271 
       
   272 	INFO_PRINTF1(_L("T_DriveNotification Completed."));
       
   273 	return TestStepResult();
       
   274 	}
       
   275