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