kerneltest/f32test/server/t_notifier.cpp
changeset 0 a41df078684a
child 31 56f325a607ea
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-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 "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 // f32test\server\t_notifier.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <e32test.h>
       
    20 #include <e32svr.h>
       
    21 #include <hal.h>
       
    22 #include "t_server.h"
       
    23 #include "t_chlffs.h"
       
    24 #include "t_notify_plugin.h"
       
    25 
       
    26 const TInt KNotificationHeaderSize = (sizeof(TUint16)*2)+(sizeof(TUint));
       
    27 const TInt KMinNotificationBufferSize = 2*KNotificationHeaderSize + 2*KMaxFileName;
       
    28 
       
    29 
       
    30 RTest test(_L("T_NOTIFIER"));
       
    31 const TInt KMaxHeapSize = 0x800000;
       
    32 TInt globalDriveNum;
       
    33 
       
    34 void DismountPlugin()
       
    35 	{
       
    36 	TheFs.DismountPlugin(KNotifyPluginName);
       
    37 	TheFs.RemovePlugin(KNotifyPluginFileName);
       
    38 	}
       
    39 
       
    40 inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TText* aName)
       
    41 	{
       
    42 	if(aError!=KErrNone)
       
    43 		{
       
    44 		test.Printf(_L(": ERROR : %d received on line %d\n"),aError,aLine);
       
    45 		DismountPlugin();
       
    46 		aTest.operator()(aError==KErrNone,aLine,(TText*)aName);
       
    47 		}
       
    48 	}
       
    49 
       
    50 // Used by TestMultipleNotificationsL() to show which line the function is called from
       
    51 inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TInt aLineCall)
       
    52 	{
       
    53 	if(aError != KErrNone)
       
    54 		{
       
    55 		aTest.Printf(_L(": ERROR : %d received on line %d\n"), aError, aLine);
       
    56 		aTest.Printf(_L(": ERROR : Function called from line number: %d\n"), aLineCall);
       
    57 		aTest.operator()(aError == KErrNone, aLine);
       
    58 		}
       
    59 	}
       
    60 
       
    61 // Prints out the filename
       
    62 #define ExpandMe(X)	 L ## X
       
    63 #define Expand(X)	 ExpandMe(X)
       
    64 
       
    65 namespace t_notification
       
    66 	{
       
    67 	enum EOperation
       
    68 		{
       
    69 		//TFsNotification::ECreate
       
    70 		EFileReplace,
       
    71 		EFileCreate,
       
    72 		EFileCreate_subs,			//Create files in subdir, watch subdirs
       
    73 		EFileCreate_subs_nowatch,	//Create files in subdir, do not monitor subdirs
       
    74 		EFileCreate_txt_nowatch,	//Create .txt files in subdir, do not monitor subdirs
       
    75 		EFileCreate_txt,            //Create .txt files
       
    76 		EFsMkDir,					//Create directory
       
    77 		//TFsNotification::EAttribute
       
    78 		EFileSetAtt,
       
    79 		EFileSetAtt_subs,			//Set attributes in subdir
       
    80 		EFileSet,
       
    81 		EFsSetEntry,
       
    82 		//TFsNotification::ERename
       
    83 		EFsReplace,					//Replace file
       
    84 		EFsRename,					//Rename file
       
    85 		EFsRename_dir,				//Rename directory
       
    86 		EFileRename,
       
    87 		EFileRename_wild,			//Rename file using wildcard name
       
    88 		//TFsNotification::EDelete
       
    89 		EFsDelete,					//Delete file
       
    90 		EFsRmDir,					//Remove directory
       
    91 		EFsRmDir_nonEmpty,			//Remove non-empty directory, which will return KErrInUse
       
    92 		EFsRmDir_wild,				//Remove subdirectory using wildcard name
       
    93 		//TFsNotification::EFileChange
       
    94 		EFileWrite,
       
    95 		EFileWrite_samesize,		//Write to file without changing its size
       
    96 		EFileWrite_async,			//Asynchronous write
       
    97 		EFileSetSize,
       
    98 		//TFsNotification::EVolumeName
       
    99 		ESetVolumeLabel,
       
   100 		//TFsNotification::EDriveName
       
   101 		ESetDriveName,
       
   102 		//TFsNotification::EMediaChange
       
   103 		EMount,
       
   104 		EDismount,
       
   105 		EMountScan,
       
   106 		EMountDismount,
       
   107 		EFormat,
       
   108 		EMediaCardRemoval,
       
   109 		EMediaCardInsertion,
       
   110 		ERawDiskWrite,
       
   111 		//Multiple Filters
       
   112 		EAllOps1,					//Create/Replace and Delete
       
   113 		EAllOps2,					//Create/Replace, FileChange(Write) and Delete
       
   114 		EAllOps3,					//Create/Replace, FileChange(SetSize) and Delete
       
   115 		EAllOps4,					//Create/Replace, Attribute(SetAtt) and Delete
       
   116 		EAllOps5,					//Create/Replace and Rename
       
   117 		EAllOps6,					//VolumeName and DriveName
       
   118 		ECFileManMove               //Create filex in monitored directory, write 4, move to unmonitored, setsize 8, move back, delete
       
   119 		};
       
   120 	}
       
   121 
       
   122 // Package filename and semaphore for thread
       
   123 struct SThreadPackage
       
   124 	{
       
   125 	TFileName iFileName;
       
   126 	RSemaphore iBarrier;
       
   127 	};
       
   128 
       
   129 struct SThreadPackageDualSemaphore
       
   130 	{
       
   131 	TFileName iFileName;
       
   132 	RSemaphore iBarrier;
       
   133 	RSemaphore iBarrier2;
       
   134 	};
       
   135 
       
   136 struct SThreadPackage2
       
   137 	{
       
   138 	TInt iTestCase;
       
   139 	RSemaphore iBarrier;
       
   140 	};
       
   141 
       
   142 // Used by TestMultipleNotificationsL
       
   143 struct SThreadPackageMultiple
       
   144 	{
       
   145 	TFileName iString; 		//Commonly stores the filename
       
   146 	TFileName iFileName; 	//Commonly stores the path (not inc filename)
       
   147 	RSemaphore iBarrier;
       
   148 	t_notification::EOperation iOperation;
       
   149 	TFsNotification::TFsNotificationType iNotifyType;
       
   150 	TInt iIterations;    	//# of times to 'do' something
       
   151 	TInt iMaxNotifications; //# of notifications expected
       
   152 	TInt iBufferSize;
       
   153 	TInt iLineCall;			//Line where the function is called from
       
   154 	};
       
   155 
       
   156 void PrintLine()
       
   157 	{
       
   158 	test.Printf(_L("======================================================================\n"));
       
   159 	}
       
   160 
       
   161 
       
   162 // We should receive an EMediaChange notification even though we did not register for it 
       
   163 void TestMediaCardNotificationWhenNotRegisteredForIt()
       
   164 	{
       
   165 	RFs fs;
       
   166 	TInt r = fs.Connect();
       
   167 	test(r==KErrNone);
       
   168 	
       
   169 	CFsNotify* notify = NULL;
       
   170 	TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
       
   171 	
       
   172 	TBuf<40> path;
       
   173 	path.Append((TChar)gDriveToTest);
       
   174 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
   175 	
       
   176 	TBuf<20> filename;
       
   177 	filename.Append(_L("media.change1"));
       
   178 	
       
   179 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
   180 	test(r==KErrNone);
       
   181 	
       
   182 	TRequestStatus status;
       
   183 	r = notify->RequestNotifications(status);
       
   184 	test(r==KErrNone);
       
   185 	
       
   186 	test.Printf(_L("*****************************************************************\n"));
       
   187 	test.Printf(_L("Waiting 10 seconds.\n"));
       
   188 	test.Printf(_L("This is a MANUAL test, it requires the removal of the media card.\n"));
       
   189 	test.Printf(_L("PLEASE REMOVE THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
       
   190 	test.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
       
   191 	test.Printf(_L("*****************************************************************\n"));
       
   192 	RTimer timer1;
       
   193 	r = timer1.CreateLocal();
       
   194 	test(r == KErrNone);
       
   195 	TRequestStatus timeout;
       
   196 	TTimeIntervalMicroSeconds32 time = 10000000;
       
   197 	timer1.After(timeout,time);
       
   198 	User::WaitForRequest(timeout,status);
       
   199 	test(status.Int() != KRequestPending);
       
   200 	timer1.Cancel();
       
   201 	timer1.Close();
       
   202 	
       
   203 	const TFsNotification* notification = notify->NextNotification();
       
   204 	test(notification != NULL);
       
   205 	TFsNotification::TFsNotificationType type = notification->NotificationType();
       
   206 	test(type == TFsNotification::EMediaChange);
       
   207 	TBuf<2> drive;
       
   208 	drive.Append((TChar)gDriveToTest);
       
   209 	drive.Append(_L(":"));
       
   210 	TPtrC drivePtr;
       
   211 	r = notification->Path(drivePtr);
       
   212 	test(r==KErrNone);
       
   213 	r = drivePtr.Compare(drive);
       
   214 	test(r==0);
       
   215 	
       
   216 	test.Printf(_L("*****************************************************************\n"));
       
   217 	test.Printf(_L("Waiting 10 seconds.\n"));
       
   218 	test.Printf(_L("This is a MANUAL test, it requires the insertion of the media card.\n"));
       
   219 	test.Printf(_L("PLEASE INSERT THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
       
   220 	test.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
       
   221 	test.Printf(_L("*****************************************************************\n"));
       
   222 	
       
   223 	notification = notify->NextNotification();
       
   224 	if(notification == NULL)
       
   225 		{
       
   226 		notify->RequestNotifications(status);
       
   227 		RTimer timer2;
       
   228 		r = timer2.CreateLocal();
       
   229 		test(r == KErrNone);
       
   230 		TRequestStatus timeout2;
       
   231 		timer2.After(timeout2,time);
       
   232 		User::WaitForRequest(timeout2,status);
       
   233 		test(status.Int() != KRequestPending);
       
   234 		notification = notify->NextNotification();
       
   235 		timer2.Cancel();
       
   236 		timer2.Close();
       
   237 		}
       
   238 	test(notification != NULL);
       
   239 	type = notification->NotificationType();
       
   240 	test(type == TFsNotification::EMediaChange);
       
   241 
       
   242 	delete notify;
       
   243 	fs.Close();
       
   244 	}
       
   245 
       
   246 // Creates two sessions, removes the first one
       
   247 // and then checks if the second one still works
       
   248 TInt TestClientRemovalL()
       
   249 	{
       
   250 	RFs fs;
       
   251 	TInt r = fs.Connect();
       
   252 	test(r==KErrNone);
       
   253 	
       
   254 	CFsNotify* notify1 = NULL;
       
   255 	CFsNotify* notify2 = NULL;
       
   256 	TRAP(r,notify1= CFsNotify::NewL(fs,KMinNotificationBufferSize);
       
   257 		   notify2= CFsNotify::NewL(fs,KMinNotificationBufferSize);
       
   258 		);
       
   259 	if(r!=KErrNone)
       
   260 		{
       
   261 		delete notify1;
       
   262 		delete notify2;
       
   263 		test(r==KErrNone);
       
   264 		}
       
   265 	
       
   266 	TBuf<40> path;
       
   267 	path.Append((TChar)gDriveToTest);
       
   268 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
   269 	
       
   270 	TBuf<15> filename;
       
   271 	filename.Append(_L("create.file"));
       
   272 	
       
   273 	TBuf<40> fullname;
       
   274 	fullname.Append(path);
       
   275 	fullname.Append(filename);
       
   276 	
       
   277 	r = notify1->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
   278 	test(r==KErrNone);
       
   279 	r = notify2->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
   280 	test(r==KErrNone);
       
   281 	
       
   282 	delete notify1; //Delete notify1 and ensure we still get notification on notify2
       
   283 	
       
   284 	TRequestStatus status;
       
   285 	r = notify2->RequestNotifications(status);
       
   286 	test(r==KErrNone);
       
   287 	
       
   288 	RFile file;
       
   289 	file.Replace(fs,fullname,EFileWrite); //Replace produces Create notification
       
   290 	file.Close();
       
   291 	
       
   292 	RTimer tim;
       
   293 	r = tim.CreateLocal();
       
   294 	test(r==KErrNone);
       
   295 	
       
   296 	TRequestStatus timStatus;
       
   297 	TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
       
   298 	tim.After(timStatus,time);
       
   299 	
       
   300 	User::WaitForRequest(status,timStatus);
       
   301 	test(status!=KRequestPending);
       
   302 	
       
   303 	r = fs.Delete(fullname);
       
   304 	test(r==KErrNone);
       
   305 	
       
   306 	delete notify2;
       
   307 	tim.Close();
       
   308 	fs.Close();
       
   309 	return KErrNone;
       
   310 	}
       
   311 
       
   312 /*
       
   313  * This tests that u can set and receive notifications in the root
       
   314  * of a drive.
       
   315  * 
       
   316  * (something which was apparently not possible on RFs::NotifyChange)
       
   317  */
       
   318 TInt TestRootDriveNotifications()
       
   319 	{
       
   320 	test.Next(_L("TestRootDriveNotifications"));
       
   321 	RFs fs;
       
   322 	fs.Connect();
       
   323 	
       
   324 	CFsNotify* notify = NULL;
       
   325 	
       
   326 	TRAPD(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize););
       
   327 	test(r==KErrNone);
       
   328 	test(notify!=NULL);
       
   329 	
       
   330 	TBuf<40> path;
       
   331 	path.Append((TChar)gDriveToTest);
       
   332 	path.Append(_L(":\\"));
       
   333 	
       
   334 	TBuf<15> filename;
       
   335 	filename.Append(_L("*"));
       
   336 	
       
   337 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
   338 	test(r==KErrNone);
       
   339 	
       
   340 	TRequestStatus status;
       
   341 	r = notify->RequestNotifications(status);
       
   342 	test(r==KErrNone);
       
   343 	
       
   344 	RFile file;
       
   345 	TBuf<40> filePath;
       
   346 	filePath.Append((TChar)gDriveToTest);
       
   347 	filePath.Append(_L(":\\file.root"));
       
   348 	r = file.Replace(fs,filePath,EFileRead);
       
   349 	test(r==KErrNone);
       
   350 	file.Close();
       
   351 	
       
   352 	TRequestStatus s2;
       
   353 	RTimer tim;
       
   354 	test(tim.CreateLocal()==KErrNone);
       
   355 	TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
       
   356 	tim.After(s2,time);
       
   357 	User::WaitForRequest(status,s2);
       
   358 	test(status!=KRequestPending);
       
   359 	
       
   360 	delete notify;
       
   361 	notify = NULL;
       
   362 	tim.Close();
       
   363 	fs.Close();
       
   364 	return KErrNone;	
       
   365 	}
       
   366 
       
   367 /*
       
   368  * Creates and deletes loads of CFsNotify objects and makes sure they're all
       
   369  * cleaned up afterwards.
       
   370  */
       
   371 TInt TestNewDeleteCFsNotify(TInt aIterations)
       
   372 	{
       
   373 	RPointerArray<CFsNotify> array;
       
   374 	TInt inArray = 0;
       
   375 	TInt r = KErrNone;
       
   376 	for(TInt i = 0; i < aIterations; i++)
       
   377 		{
       
   378 		CFsNotify* notify = NULL;
       
   379 		TRAP(r,notify = CFsNotify::NewL(TheFs,500));
       
   380 		if(r==KErrNone)
       
   381 			{
       
   382 			test(notify!=NULL);
       
   383 			r = array.Append(notify);
       
   384 			if(r==KErrNone)
       
   385 				{
       
   386 				inArray++;
       
   387 				}
       
   388 			else
       
   389 				{
       
   390 				delete notify;
       
   391 				break;
       
   392 				}
       
   393 			}
       
   394 		else
       
   395 			{
       
   396 			break;
       
   397 			}
       
   398 		}
       
   399 	
       
   400 	for(TInt j = inArray-1; j >= 0; j--)
       
   401 		{
       
   402 		CFsNotify* notify = (CFsNotify*)array[j];
       
   403 		array.Remove(j);
       
   404 		delete notify;
       
   405 		}
       
   406 	
       
   407 	array.Reset();
       
   408 	array.Close();
       
   409 	return KErrNone;
       
   410 	}
       
   411 
       
   412 
       
   413 /*
       
   414  * Creates a file
       
   415  * Used in SimpleTest1L(), TestTwoDoersL() TestTwoWatchersL(), TestCancelNotificationL()
       
   416  */
       
   417 TInt SimpleSingleNotificationTFDoer(TAny* aAny)
       
   418 	{
       
   419 	SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny;
       
   420 	RTest simpleTestDoer(_L("SimpleSingleNotificationTFDoer"));
       
   421 	simpleTestDoer.Start(_L("SimpleSingleNotificationTFDoer"));
       
   422 	TBuf<40> path;
       
   423 	path.Append(gDriveToTest);
       
   424 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
   425 	path.Append(pkgDoer.iFileName);
       
   426 	
       
   427 	//Delete file so we definitely get a create notification
       
   428 	RFs fs;
       
   429 	TInt r = fs.Connect();
       
   430 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   431 	r = fs.Delete(path);
       
   432 	if(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound)
       
   433 		r = KErrNone;
       
   434 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   435 	r = fs.MkDirAll(path);
       
   436 	if(r==KErrNone || r==KErrAlreadyExists)
       
   437 		r = KErrNone;
       
   438 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   439 	
       
   440 	simpleTestDoer.Printf(_L("SimpleSingleNotificationTFDoer - Create File %S\n"),&path);
       
   441 	//Create file
       
   442 	RFile file;
       
   443 	r = file.Create(fs,path,EFileWrite);	
       
   444 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   445 	file.Close();	
       
   446 
       
   447 	fs.Close();
       
   448 	simpleTestDoer.End();
       
   449 	simpleTestDoer.Close();
       
   450 	return KErrNone;
       
   451 	}
       
   452 
       
   453 /*
       
   454  * Watches 1 file creation
       
   455  * Used in SimpleTest1L()
       
   456  */
       
   457 TInt SimpleSingleNotificationTFWatcher(TAny* aAny)
       
   458 	{
       
   459 	CTrapCleanup* cleanup;
       
   460 	cleanup = CTrapCleanup::New();
       
   461 	RThread thread;
       
   462 	TUint64 threadId = thread.Id().Id();
       
   463 	
       
   464 	SThreadPackage pkgDoer = *(SThreadPackage*)aAny;
       
   465 	RSemaphore& simpleBarrierTest = pkgDoer.iBarrier;
       
   466 	
       
   467 	RTest simpleTestWatcher(_L("SimpleSingleNotificationTFWatcher"));
       
   468 	simpleTestWatcher.Start(_L("SimpleSingleNotificationTFWatcher"));
       
   469 	
       
   470 	RFs fs;
       
   471 	fs.Connect();
       
   472 	
       
   473 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Create CFsNotify\n"),threadId);
       
   474 	CFsNotify* notify = NULL;
       
   475 	TRAPD(r,notify = CFsNotify::NewL(fs,100); );
       
   476 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   477 	TBuf<40> path;
       
   478 	path.Append(gDriveToTest);
       
   479 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
       
   480 	
       
   481 	TBuf<20> filename;
       
   482 	filename.Append(pkgDoer.iFileName);
       
   483 	
       
   484 	TBuf<40> fullname;
       
   485 	fullname.Append(path);
       
   486 	fullname.Append(filename);
       
   487 	
       
   488 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher - Add Notification for %S\n"),&path);
       
   489 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
   490 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   491 	TRequestStatus status;
       
   492 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Request Notifications\n"),threadId);
       
   493 	r = notify->RequestNotifications(status);
       
   494 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   495 	
       
   496 	simpleBarrierTest.Signal();
       
   497 	
       
   498 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Wait for status to return\n"),threadId);
       
   499 	User::WaitForRequest(status);
       
   500 		
       
   501 	simpleTestWatcher.Printf(_L("(%d) NextNotification\n"),threadId);
       
   502 	const TFsNotification* notification = notify->NextNotification();
       
   503 	//Test notification is not null.
       
   504 	//We should be getting 1 notification.
       
   505 	if(notification == NULL)
       
   506 		safe_test(simpleTestWatcher,KErrNotFound,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   507 	
       
   508 	simpleTestWatcher.Printf(_L("(%d) - Notification Type\n"),threadId);
       
   509 	TFsNotification::TFsNotificationType notificationType = ((TFsNotification*)notification)->NotificationType();
       
   510 	if(notificationType != TFsNotification::ECreate)
       
   511 		safe_test(simpleTestWatcher,KErrGeneral,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   512 	simpleTestWatcher.Printf(_L("(%d) - Notification Path\n"),threadId);
       
   513 	TPtrC _pathC;
       
   514 	((TFsNotification*)notification)->Path(_pathC);
       
   515 	simpleTestWatcher.Printf(_L("Notification Path = %S\n"),&_pathC);
       
   516 	TBuf<40> _path;
       
   517 	_path.Copy(_pathC);
       
   518 	if(_path.Match(fullname)!=KErrNone)
       
   519 		safe_test(simpleTestWatcher,KErrBadName,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   520 	
       
   521 	/*
       
   522 	TInt driveNumber = 0;
       
   523 	TInt gDriveNum = -1;
       
   524 	notification->DriveNumber(driveNumber);
       
   525 	RFs::CharToDrive(_pathC[0],gDriveNum);
       
   526 	if(driveNumber != gDriveNum)
       
   527 		safe_test(simpleTestWatcher,KErrBadHandle,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   528 	
       
   529 	TUid uid;
       
   530 	TUint32 realUID = 0x76543210;
       
   531 	r = notification->UID(uid);
       
   532 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   533 	safe_test(simpleTestWatcher,(realUID == uid.iUid)==1,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   534 	*/
       
   535 	delete notify;
       
   536 	fs.Close();
       
   537 	simpleTestWatcher.End();
       
   538 	simpleTestWatcher.Close();
       
   539 	delete cleanup;
       
   540 	return KErrNone;
       
   541 	}
       
   542 
       
   543 /*
       
   544  * SimpleTest1L - Runs a simple Create test, gets 1 notification, calls type, path etc and exits
       
   545  * Two threads: 1 watcher, 1 doer
       
   546  */
       
   547 TInt SimpleCreateTestL()
       
   548 	{
       
   549 	test.Next(_L("SimpleTest"));
       
   550 	RFs fs;
       
   551 	fs.Connect();
       
   552 	_LIT(KFileName,"simple.create");
       
   553 	SThreadPackage pkgDoer;
       
   554 	pkgDoer.iFileName = KFileName;
       
   555 	
       
   556 	SThreadPackage watcherPkg;
       
   557 	watcherPkg.iFileName = KFileName;
       
   558 	User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0));
       
   559 	User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0));
       
   560 	RThread watcher;
       
   561 	RThread doer;
       
   562 	watcher.Create(_L("Simple1WatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
       
   563 	doer.Create(_L("Simple1DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
       
   564 	watcher.Resume();
       
   565 	watcherPkg.iBarrier.Wait(); //Wait till Watcher has requested notification
       
   566 	doer.Resume();
       
   567 	
       
   568 	TRequestStatus status;
       
   569 	doer.Logon(status);
       
   570 	User::WaitForRequest(status);
       
   571 	test.Printf(_L("SimpleCreateTest - Doer Exit Reason = %d\n"),doer.ExitReason());
       
   572 	safe_test(test,doer.ExitReason(),__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   573 	
       
   574 	RDebug::Print(_L("Line %d"),__LINE__);
       
   575 	
       
   576 
       
   577 	watcher.Logon(status);
       
   578 	RTimer timer1;
       
   579 	TInt r = timer1.CreateLocal();
       
   580 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   581 	TRequestStatus timeout;
       
   582 	TTimeIntervalMicroSeconds32 time = 10000000;    //10 seconds
       
   583 	timer1.After(timeout,time);
       
   584 	User::WaitForRequest(timeout,status);
       
   585 	test(status.Int() != KRequestPending);
       
   586 	timer1.Cancel();
       
   587 	timer1.Close();
       
   588 
       
   589 	
       
   590 //	User::WaitForRequest(status);
       
   591 	test.Printf(_L("SimpleCreateTest - Watcher Exit Reason = %d\n"),watcher.ExitReason());
       
   592 	safe_test(test,watcher.ExitReason(),__LINE__,(TText*)Expand("t_notifier.cpp"));
       
   593 	
       
   594 	CLOSE_AND_WAIT(doer);
       
   595 	CLOSE_AND_WAIT(watcher);
       
   596 	
       
   597 	pkgDoer.iBarrier.Close();
       
   598 	watcherPkg.iBarrier.Close();
       
   599 	fs.Close();
       
   600 	return KErrNone;
       
   601 	}
       
   602 
       
   603 // Doer thread for TestMultipleNotificationsL
       
   604 TInt MultipleNotificationTFDoer(TAny* aAny)
       
   605 	{
       
   606 	RDebug::Print(_L("MultipleNotificationTFDoer - Start, Line %d"), __LINE__);
       
   607 	SThreadPackageMultiple pkgDoer = *(SThreadPackageMultiple*)aAny;
       
   608 	RTest multipleTestDoer(_L("MultipleNotificationTFDoer"));
       
   609 	multipleTestDoer.Start(_L("Multi-Doer"));
       
   610 	multipleTestDoer.Printf(_L("MultipleNotificationTFDoer - Line %d"),__LINE__);
       
   611 	TBuf<40> basepath;
       
   612 	basepath.Append(gDriveToTest);
       
   613 	basepath.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
   614 	
       
   615 	RThread thread;
       
   616 	RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
       
   617 	TUint64 threadID = thread.Id().Id();
       
   618 	RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
       
   619 	
       
   620 	//Delete file so we definitely get a create notification
       
   621 	RFs fs;
       
   622 	TInt r = fs.Connect();
       
   623 	safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   624 
       
   625 	TEntry entry;
       
   626 	TBool wildcard = EFalse;
       
   627 	TBuf<40> _path;
       
   628 	_path.Append(basepath);
       
   629 	_path.Append(pkgDoer.iFileName);
       
   630 	_path.Append(pkgDoer.iString);
       
   631 	r = fs.Entry(_path, entry);
       
   632 	if (pkgDoer.iNotifyType != TFsNotification::EMediaChange &&
       
   633 		pkgDoer.iNotifyType != TFsNotification::EDriveName &&
       
   634 		pkgDoer.iNotifyType != TFsNotification::EVolumeName &&
       
   635 		pkgDoer.iOperation != t_notification::EAllOps6)
       
   636 		{
       
   637 		if (r == KErrBadName)
       
   638 			{
       
   639 			wildcard = ETrue;
       
   640 			}
       
   641 		if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound && r != KErrBadName)
       
   642 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   643 		if (r == KErrNone && !entry.IsDir() && pkgDoer.iOperation != t_notification::EFsDelete && !wildcard &&
       
   644 			pkgDoer.iOperation != t_notification::EFsRmDir && pkgDoer.iOperation != t_notification::EFsRmDir_nonEmpty)
       
   645 			{
       
   646 			r = fs.Delete(_path);
       
   647 			if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
       
   648 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   649 			}
       
   650 		r = fs.MkDirAll(basepath);
       
   651 		if(r != KErrNone && r != KErrAlreadyExists)
       
   652 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   653 		}
       
   654 	
       
   655 	multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
       
   656 	
       
   657 	switch(pkgDoer.iOperation)
       
   658 		{
       
   659 		case t_notification::EFileReplace:
       
   660 			{
       
   661 			RFile file;
       
   662 			//Generate Notification
       
   663 			multipleTestDoer.Printf(_L("File Replace - (%d)\n"),threadID);
       
   664 			r = file.Replace(fs,_path,EFileWrite);	//RFile::Replace -> TFsNotification::ECreate
       
   665 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   666 			file.Close();
       
   667 			
       
   668 			r = fs.Delete(_path);
       
   669 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   670 			break;
       
   671 			}
       
   672 		case t_notification::EFileCreate:
       
   673 		case t_notification::EFileCreate_txt_nowatch:
       
   674 		case t_notification::EFileCreate_txt:
       
   675 		case t_notification::EAllOps1:
       
   676 			{
       
   677 			multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
       
   678 			if(wildcard)
       
   679 				{
       
   680 				for (TInt i = 0; i < pkgDoer.iIterations; i++)
       
   681 					{
       
   682 					multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
       
   683 					RFile file;
       
   684 					TBuf<40> path;
       
   685 					path.Append(basepath);
       
   686 					path.AppendNum(i);
       
   687 					if(pkgDoer.iOperation == t_notification::EFileCreate_txt)
       
   688 						{
       
   689 						//Create file with different extension (no notification)
       
   690 						path.Append(_L(".wrg"));
       
   691 						fs.Delete(path);
       
   692 						multipleTestDoer.Printf(_L("File Create (wrong extension) - %S (%d)\n"),&path,threadID);
       
   693 						r = file.Create(fs, path, EFileWrite);
       
   694 						safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   695 						//Change path to contain file with correct extension (notification occurs)
       
   696 						path.Replace(path.Length()-3,3,_L("txt"));
       
   697 						}
       
   698 					else if(pkgDoer.iOperation == t_notification::EFileCreate_txt_nowatch)
       
   699 					    {
       
   700 					    path.Append(_L(".txt"));
       
   701 					    }
       
   702 					fs.Delete(path);
       
   703 					
       
   704 					multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&path,threadID);
       
   705 					r = file.Create(fs, path, EFileWrite);
       
   706 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   707 					file.Close();
       
   708 					r = fs.Delete(path);
       
   709 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   710 					}
       
   711 				}
       
   712 			else
       
   713 				{
       
   714 				multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
       
   715 				for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
   716 					{
       
   717 					multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
       
   718 					RFile file;
       
   719 					multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&_path,threadID);
       
   720 					r = file.Create(fs,_path,EFileWrite);
       
   721 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   722 					file.Close();
       
   723 					r = fs.Delete(_path);
       
   724 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   725 					}
       
   726 				}
       
   727 			break;
       
   728 			}
       
   729 		case t_notification::EFileCreate_subs:
       
   730 		case t_notification::EFileCreate_subs_nowatch:
       
   731 			{
       
   732 			if (wildcard)
       
   733 				{
       
   734 				for (TInt i = 0; i < pkgDoer.iIterations; i++)
       
   735 					{
       
   736 					RFile file;
       
   737 					TBuf<40> path;
       
   738 					path.Append(basepath);
       
   739 					path.Append(_L("SubDir\\"));
       
   740 					r = fs.MkDirAll(path);
       
   741 					if(r != KErrNone && r != KErrAlreadyExists)
       
   742 						safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   743 					path.AppendNum(i);
       
   744 					fs.Delete(path);
       
   745 					multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&path,threadID);
       
   746 					r = file.Create(fs, path, EFileWrite);
       
   747 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   748 					file.Close();
       
   749 					r = fs.Delete(path);
       
   750 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   751 					}
       
   752 				}
       
   753 			break;
       
   754 			}
       
   755 		case t_notification::EFileWrite:
       
   756 		case t_notification::EAllOps2:
       
   757 			{
       
   758 			//Works on single file
       
   759 			RFile file;
       
   760 			TBuf<40> path;
       
   761 			path.Append(basepath);
       
   762 			path.Append(pkgDoer.iFileName);
       
   763 			path.Append(pkgDoer.iString);
       
   764 			r = file.Replace(fs,path,EFileWrite);
       
   765 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   766 			for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
   767 				{
       
   768 				multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
       
   769 				r = file.Write(4*i,_L8("abcd"));
       
   770 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   771                 //If cache is enabled, a notification is received only when the cache is flushed
       
   772                 //We flush the file to make this a general test
       
   773 				multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
       
   774                 r = file.Flush();
       
   775                 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   776 				}
       
   777 			file.Close();
       
   778 			r = fs.Delete(path);
       
   779 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   780 			break;
       
   781 			}
       
   782 		case t_notification::EFileWrite_samesize:
       
   783 			{
       
   784 			RFile file;
       
   785 			TBuf<40> path;
       
   786 			path.Append(basepath);
       
   787 			path.Append(pkgDoer.iFileName);
       
   788 			path.Append(pkgDoer.iString);
       
   789 			r = file.Replace(fs,path,EFileWrite);
       
   790 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   791 			multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
       
   792 			r = file.Write(0,_L8("abcd"));
       
   793 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   794 			
       
   795             //If cache is enabled, a notification is received only when the cache is flushed
       
   796             //We flush the file to make this a general test
       
   797             multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
       
   798             r = file.Flush();
       
   799             safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   800             
       
   801 			for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
   802 				{
       
   803 				TBuf<2> toWrite;
       
   804 				toWrite.AppendNum(i);
       
   805 				multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
       
   806 				r = file.Write(0,(TDesC8&)toWrite);
       
   807 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   808 				multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
       
   809                 r = file.Flush();
       
   810                 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   811 				}
       
   812 			file.Close();
       
   813 			r = fs.Delete(path);
       
   814 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   815 			break;
       
   816 			}
       
   817 		case t_notification::EFileWrite_async:
       
   818 			{
       
   819 			RFile file;
       
   820 			TBuf<40> path;
       
   821 			path.Append(basepath);
       
   822 			path.Append(pkgDoer.iFileName);
       
   823 			path.Append(pkgDoer.iString);
       
   824 			r = file.Replace(fs,path,EFileWrite);
       
   825 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   826 			for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
   827 				{
       
   828 				TRequestStatus status;
       
   829 				file.Write(52*i, _L8("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), status);			
       
   830 				User::WaitForRequest(status);
       
   831 				multipleTestDoer.Printf(_L("File Write Async - %S (%d)\n"),&path,threadID);
       
   832 				TInt fileSize;
       
   833 				file.Size(fileSize);
       
   834 				multipleTestDoer.Printf(_L("File Write Async - FileSize: %d\n"),fileSize);
       
   835 				multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
       
   836                 r = file.Flush();
       
   837                 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   838 				}
       
   839 			file.Close();
       
   840 			r = fs.Delete(path);
       
   841 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   842 			break;
       
   843 			}
       
   844 		case t_notification::EFileSetSize:
       
   845 		case t_notification::EAllOps3:
       
   846 			{
       
   847 			//Works on single file
       
   848 			RFile file;
       
   849 			TBuf<40> path;
       
   850 			path.Append(basepath);
       
   851 			path.Append(pkgDoer.iFileName);
       
   852 			path.Append(pkgDoer.iString);
       
   853 			r = file.Replace(fs,path,EFileWrite);
       
   854 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   855 			
       
   856 			//Increase file size
       
   857 			for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
   858 				{
       
   859 				r = file.SetSize(4*(i+1));
       
   860 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   861 				multipleTestDoer.Printf(_L("File Set Size - %d (%d)\n"),4*(i+1),threadID);
       
   862 				}
       
   863 			
       
   864 			//Decrease file size
       
   865 			for(TInt j = pkgDoer.iIterations - 2; j >= 0; j--)
       
   866 				{
       
   867 				r = file.SetSize(4*(j+1));
       
   868 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   869 				multipleTestDoer.Printf(_L("File Set Size - %d (%d)\n"),4*(j+1),threadID);
       
   870 				}	
       
   871 			
       
   872 			file.Close();	
       
   873 			r = fs.Delete(path);
       
   874 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   875 			break;
       
   876 			}
       
   877 		case t_notification::EFsReplace:
       
   878 			{
       
   879 			TBuf<45> path;
       
   880 			path.Append(basepath);
       
   881 			path.Append(pkgDoer.iFileName);
       
   882 			path.Append(pkgDoer.iString);
       
   883 			path.AppendNum(0);
       
   884 			
       
   885 			RFile tempFile;
       
   886 			multipleTestDoer.Printf(_L("RFs Replace (Create temp file) - (%d)\n"),threadID);
       
   887 			r = tempFile.Replace(fs,_path,EFileWrite);
       
   888 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   889 			tempFile.Close();
       
   890 			
       
   891 			multipleTestDoer.Printf(_L("RFs Replace - (%d)\n"),threadID);
       
   892 			r = fs.Replace(_path,path); //RFs::Replace -> TFsNotification::ERename
       
   893 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   894 			
       
   895 			r = fs.Delete(path);
       
   896 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   897 			break;
       
   898 			}
       
   899 		case t_notification::EFsRename:
       
   900 			{
       
   901 			TBuf<45> path;
       
   902 			path.Append(basepath);
       
   903 			path.Append(pkgDoer.iFileName);
       
   904 			path.Append(pkgDoer.iString);
       
   905 			path.AppendNum(0);
       
   906 	
       
   907 			RFile file;
       
   908 			r = file.Replace(fs,_path,EFileWrite);
       
   909 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   910 			file.Close();
       
   911 
       
   912 			multipleTestDoer.Printf(_L("RFs Rename - (%d)\n"),threadID);
       
   913 			r = fs.Rename(_path,path);
       
   914 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   915 						
       
   916 			r = fs.Delete(path);
       
   917 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   918 			break;
       
   919 			}
       
   920 		case t_notification::EFileRename:
       
   921 		case t_notification::EFileRename_wild:
       
   922 		case t_notification::EAllOps5:
       
   923 			{
       
   924 			TBuf<45> path;
       
   925 			path.Append(basepath);
       
   926 			if (!wildcard)
       
   927 				{
       
   928 				path.Append(pkgDoer.iFileName);
       
   929 				path.Append(pkgDoer.iString);
       
   930 				}
       
   931 			path.AppendNum(0);
       
   932 			
       
   933 			//Delete new path to ensure it does not exist
       
   934 			r = fs.Delete(path);
       
   935 			if(r != KErrNone && r != KErrNotFound && r != KErrPathNotFound)
       
   936 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   937 			
       
   938 			if (wildcard)
       
   939 				{
       
   940 				_path.Delete(_path.Length()-1,1);
       
   941 				_path.AppendNum(9);
       
   942 				}
       
   943 			
       
   944 			RFile file;
       
   945 			r = file.Replace(fs, _path, EFileWrite);
       
   946 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   947 
       
   948 			if (wildcard)
       
   949 				{
       
   950 				for(TInt i = 1; i <= pkgDoer.iIterations; i++)
       
   951 					{
       
   952 					path.Delete(path.Length()-1,1);
       
   953 					path.AppendNum(i);
       
   954 					multipleTestDoer.Printf(_L("File Rename - %S (%d)\n"),&path,threadID);
       
   955 					r = file.Rename(path);
       
   956 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   957 					}
       
   958 				}
       
   959 			else
       
   960 				{
       
   961 				multipleTestDoer.Printf(_L("File Rename - (%d)\n"),threadID);
       
   962 				r = file.Rename(path);
       
   963 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   964 				}
       
   965 			
       
   966 			file.Close();
       
   967 			r = fs.Delete(path);
       
   968 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   969 			break;
       
   970 			}
       
   971 		case t_notification::EFsRename_dir:
       
   972 			{
       
   973 			r = fs.MkDirAll(_path);
       
   974 			if(r != KErrNone && r != KErrAlreadyExists)
       
   975 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   976 			
       
   977 			TBuf<45> newPath;
       
   978 			newPath.Copy(_path);
       
   979 			newPath.Delete(newPath.Length()-1,1);
       
   980 			newPath.AppendNum(0);
       
   981 			newPath.Append(KPathDelimiter);
       
   982 			
       
   983 			//Delete new path to ensure it does not exist
       
   984 			r = fs.RmDir(newPath);
       
   985 			if(r != KErrNone && r != KErrNotFound && r != KErrPathNotFound)
       
   986 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   987 
       
   988 			multipleTestDoer.Printf(_L("RFs Rename Dir - (%d)\n"),threadID);
       
   989 			r = fs.Rename(_path,newPath);
       
   990 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
   991 			break;
       
   992 			}
       
   993 		case t_notification::EFsDelete:
       
   994 			{
       
   995 			if (wildcard)
       
   996 				{
       
   997 				for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
   998 					{
       
   999 					//Create/replace file
       
  1000 					RFile file;
       
  1001 					TBuf<40> path;
       
  1002 					path.Append(basepath);
       
  1003 					r = fs.MkDirAll(path);
       
  1004 					if(r != KErrNone && r != KErrAlreadyExists)
       
  1005 						safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1006 					path.AppendNum(i);
       
  1007 					path.Append(_L(".txt"));
       
  1008 					r = file.Replace(fs,path,EFileWrite);
       
  1009 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1010 					file.Close();
       
  1011 					
       
  1012 					//Delete file
       
  1013 					multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
       
  1014 					r = fs.Delete(path);
       
  1015 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1016 					
       
  1017 					//Create file with a different extension which should not produce notifications
       
  1018 					path.AppendNum(i);
       
  1019 					r = file.Replace(fs,path,EFileWrite);
       
  1020 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1021 					file.Close();
       
  1022 					
       
  1023 					//Delete that file
       
  1024 					multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
       
  1025 					r = fs.Delete(path);
       
  1026 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1027 					}
       
  1028 				}
       
  1029 			else
       
  1030 				{
       
  1031 				RFile file;
       
  1032 				r = file.Replace(fs,_path,EFileWrite); //Make sure file exists
       
  1033 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1034 				file.Close();
       
  1035 
       
  1036 				multipleTestDoer.Printf(_L("RFs Delete - (%d)\n"),threadID);
       
  1037 				r = fs.Delete(_path);
       
  1038 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1039 				}
       
  1040 			break;
       
  1041 			}
       
  1042 		case t_notification::EFileSet:
       
  1043 			{
       
  1044 			RFile file;
       
  1045 			r = file.Replace(fs,_path,EFileWrite);
       
  1046 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1047 			
       
  1048 			multipleTestDoer.Printf(_L("File Set - (%d)\n"),threadID);
       
  1049 			r = file.Set(TTime(0),KEntryAttHidden,KEntryAttReadOnly);
       
  1050 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1051 			
       
  1052 			file.Close();
       
  1053 			break;
       
  1054 			}
       
  1055 		case t_notification::EFileSetAtt:
       
  1056 		case t_notification::EAllOps4:
       
  1057 			{
       
  1058 			RFile file;
       
  1059 			r = file.Replace(fs,_path,EFileWrite);
       
  1060 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1061 			
       
  1062 			multipleTestDoer.Printf(_L("File SetAtt - (%d)\n"),threadID);
       
  1063 			r = file.SetAtt(KEntryAttHidden,KEntryAttReadOnly);
       
  1064 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1065 			
       
  1066 			file.Close();
       
  1067 			r = fs.Delete(_path);
       
  1068 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1069 			break;
       
  1070 			}
       
  1071 		case t_notification::EFileSetAtt_subs:
       
  1072 			{
       
  1073 			if (wildcard)
       
  1074 				{
       
  1075 				TBuf<40> path;
       
  1076 				path.Append(basepath);
       
  1077 				path.Append(_L("SubDir\\"));
       
  1078 				r = fs.MkDirAll(path);
       
  1079 				if(r != KErrNone && r != KErrAlreadyExists)
       
  1080 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1081 				
       
  1082 				//Create/replace files and set their attributes
       
  1083 				for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
  1084 					{
       
  1085 					RFile file;
       
  1086 					TBuf<40> dirPath;
       
  1087 					dirPath.Append(path);
       
  1088 					dirPath.AppendNum(i);
       
  1089 					dirPath.Append(_L(".ext"));
       
  1090 					r = file.Replace(fs, dirPath, EFileWrite);
       
  1091 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1092 					
       
  1093 					multipleTestDoer.Printf(_L("File SetAtt Subs - %d.ext - (%d)\n"),i,threadID);
       
  1094 					r = file.SetAtt(KEntryAttHidden,KEntryAttReadOnly);
       
  1095 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1096 					
       
  1097 					file.Close();
       
  1098 					r = fs.Delete(dirPath);
       
  1099 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1100 					}							
       
  1101 				}
       
  1102 			break;
       
  1103 			}
       
  1104 		case t_notification::EFsSetEntry:
       
  1105 			{
       
  1106 			RFile file;
       
  1107 			r = file.Replace(fs,_path,EFileWrite);
       
  1108 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1109 			file.Close();
       
  1110 
       
  1111 			multipleTestDoer.Printf(_L("RFs SetEntry - (%d)\n"),threadID);
       
  1112 			r = fs.SetEntry(_path,TTime(0),KEntryAttHidden,KEntryAttReadOnly);
       
  1113 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1114 			break;
       
  1115 			}
       
  1116 		case t_notification::EDismount:
       
  1117 			{
       
  1118 			multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
       
  1119 			r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
       
  1120 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1121 			break;
       
  1122 			}
       
  1123 		case t_notification::EMount:
       
  1124 			{
       
  1125 			multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
       
  1126 			r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum);
       
  1127 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1128 			break;
       
  1129 			}
       
  1130 		case t_notification::EMountScan:
       
  1131 			{
       
  1132 			multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
       
  1133 			r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
       
  1134 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1135 			TBool isMount;
       
  1136 			multipleTestDoer.Printf(_L("MountFileSystemAndScan - (%d)\n"),threadID);
       
  1137 			r = fs.MountFileSystemAndScan(pkgDoer.iFileName,globalDriveNum,isMount);
       
  1138 			if(!isMount)
       
  1139 				safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall);
       
  1140 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1141 			break;
       
  1142 			}
       
  1143 		case t_notification::EMountDismount:
       
  1144 			{
       
  1145 			for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
  1146 				{
       
  1147 				multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
       
  1148 				r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
       
  1149 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1150 				
       
  1151 				multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
       
  1152 				r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum);
       
  1153 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1154 				}
       
  1155 			break;
       
  1156 			}
       
  1157 		case t_notification::EFormat:
       
  1158 			{
       
  1159 			RFormat format;
       
  1160 			TInt count = -1;
       
  1161 			TBuf<2> driveDes;
       
  1162 			driveDes.Append(pkgDoer.iFileName);
       
  1163 			driveDes.Append((TChar)':');
       
  1164 			format.Open(fs,driveDes,EQuickFormat,count);
       
  1165 			multipleTestDoer.Printf(_L("Format - (%d)\n"),threadID);
       
  1166 			while(count != 0)
       
  1167 				{
       
  1168 				format.Next(count);
       
  1169 				}
       
  1170 			format.Close();			
       
  1171 			
       
  1172 			break;
       
  1173 			}
       
  1174 		case t_notification::EMediaCardRemoval:
       
  1175 		case t_notification::EMediaCardInsertion:
       
  1176 			{
       
  1177 			//These are MANUAL tests, they require the removal/insertion of the media card
       
  1178 			//Instructions are given out in the watcher thread
       
  1179 			break;
       
  1180 			}
       
  1181 		case t_notification::ESetDriveName:
       
  1182 			{
       
  1183 			for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
  1184 				{
       
  1185 				multipleTestDoer.Printf(_L("SetDriveName - MyDrive\n"));
       
  1186 				_LIT(KDriveName,"MyDrive");
       
  1187 				r = fs.SetDriveName(globalDriveNum,KDriveName);
       
  1188 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1189 				
       
  1190 				multipleTestDoer.Printf(_L("SetDriveName - MyDrive2\n"));
       
  1191 				_LIT(KDriveName2,"MyDrive2");
       
  1192 				r = fs.SetDriveName(globalDriveNum,KDriveName2);
       
  1193 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1194 				}
       
  1195 			break;
       
  1196 			}
       
  1197 		case t_notification::ERawDiskWrite:
       
  1198 			{
       
  1199 			RRawDisk rawdisk;
       
  1200 			TInt drive = 0;
       
  1201 			TBuf<1> driveDes;
       
  1202 			driveDes.Append(pkgDoer.iFileName);
       
  1203 			RFs::CharToDrive(pkgDoer.iFileName[0],drive);
       
  1204 			r = rawdisk.Open(fs,drive);
       
  1205 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1206 			
       
  1207 			//Read some data
       
  1208 			TBuf8<10> readData;
       
  1209 			r = rawdisk.Read(0,readData);
       
  1210 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1211 			
       
  1212 			//Write it back
       
  1213 			TPtrC8 dataPtr(readData);
       
  1214 			r = rawdisk.Write((TInt64)0,dataPtr);
       
  1215 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1216 			rawdisk.Close();
       
  1217 			break;
       
  1218 			}
       
  1219 		case t_notification::ESetVolumeLabel:
       
  1220 			{
       
  1221 			for(TInt i = 0; i < pkgDoer.iIterations; i++)
       
  1222 				{
       
  1223 				multipleTestDoer.Printf(_L("SetVolumeLabel - MyVolume\n"));
       
  1224 				_LIT(KVolumeLabel,"MyVolume");
       
  1225 				r = fs.SetVolumeLabel(KVolumeLabel,globalDriveNum);
       
  1226 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1227 				
       
  1228 				multipleTestDoer.Printf(_L("SetVolumeLabel - MyVolume2\n"));
       
  1229 				_LIT(KVolumeLabel2,"MyVolume2");
       
  1230 				r = fs.SetVolumeLabel(KVolumeLabel2,globalDriveNum);
       
  1231 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1232 				}
       
  1233 			break;
       
  1234 			}
       
  1235 		case t_notification::EFsRmDir:
       
  1236 			{
       
  1237 			r = fs.MkDirAll(_path); //Make sure directory exists
       
  1238 			if(r != KErrNone && r != KErrAlreadyExists)
       
  1239 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1240 			multipleTestDoer.Printf(_L("RFs RmDir - Remove directory\n"));
       
  1241 			r = fs.RmDir(_path);
       
  1242 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1243 			break;
       
  1244 			}
       
  1245 		case t_notification::EFsRmDir_wild:
       
  1246 			{
       
  1247 			if (wildcard)
       
  1248 				{
       
  1249 				TBuf<40> path;
       
  1250 				path.Append(basepath);
       
  1251 				path.Append(_L("SubDir\\"));
       
  1252 				r = fs.MkDirAll(path);
       
  1253 				if(r != KErrNone && r != KErrAlreadyExists)
       
  1254 					safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1255 				
       
  1256 				multipleTestDoer.Printf(_L("RFs RmDir - Remove directory\n"));
       
  1257 				r = fs.RmDir(path);
       
  1258 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1259 				break;
       
  1260 				}
       
  1261 			}
       
  1262 		case t_notification::EFsRmDir_nonEmpty:
       
  1263 		case t_notification::EFsMkDir:
       
  1264 			{
       
  1265 			TBuf<50> path;
       
  1266 			path.Append(_path);
       
  1267 			path.Append(pkgDoer.iFileName); //Append another sub-directory
       
  1268 			multipleTestDoer.Printf(_L("RFs RmDir \n"));
       
  1269 			r=fs.RmDir(path);
       
  1270 			if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
       
  1271 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1272 			r=fs.RmDir(_path);
       
  1273 			if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
       
  1274 				safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1275 			
       
  1276 			multipleTestDoer.Printf(_L("RFs MkDir \n"));
       
  1277 			r=fs.MkDir(path);
       
  1278 			multipleTestDoer (r==KErrPathNotFound);
       
  1279 			r=fs.MkDir(_path);
       
  1280 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1281 			r=fs.MkDir(path);
       
  1282 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1283 				
       
  1284 			multipleTestDoer.Printf(_L("RFs RmDir nonEmpty - Full path: %S"),&_path);
       
  1285 			r = fs.RmDir(_path);
       
  1286 			if(r != KErrInUse)
       
  1287 				safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall);
       
  1288 
       
  1289 			r = fs.RmDir(path);
       
  1290 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1291 		
       
  1292 			multipleTestDoer.Printf(_L("RFs EFsRmDir_nonEmpty - Full path: %S"),&_path);
       
  1293 			r = fs.RmDir(_path);
       
  1294 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1295 
       
  1296 			break;
       
  1297 			}
       
  1298 		case t_notification::EAllOps6:
       
  1299 			{
       
  1300 			//Set drive name to TestDrive
       
  1301 			multipleTestDoer.Printf(_L("SetDriveName - TestDrive\n"));
       
  1302 			_LIT(KDriveName,"TestDrive");
       
  1303 			r = fs.SetDriveName(globalDriveNum,KDriveName);
       
  1304 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1305 			//Set volume label to TestVolume
       
  1306 			multipleTestDoer.Printf(_L("SetVolumeLabel - TestVolume\n"));
       
  1307 			_LIT(KVolumeLabel,"TestVolume");
       
  1308 			r = fs.SetVolumeLabel(KVolumeLabel,globalDriveNum);
       
  1309 			safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1310 			break;
       
  1311 			}
       
  1312 		case t_notification::ECFileManMove:
       
  1313 		    {
       
  1314 		    CTrapCleanup* cleanup;
       
  1315 		    cleanup = CTrapCleanup::New();
       
  1316 		      
       
  1317 		    multipleTestDoer.Printf(_L("Doer - ECFileManMove_part1\n"));
       
  1318 		    
       
  1319 		    //Stage 1 - Create File & write some data
       
  1320 		    RFile file;
       
  1321 		    r = file.Replace(fs,_path,EFileWrite);
       
  1322 		    safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1323 		    r = file.SetSize(4);
       
  1324 		    safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1325 		    file.Close();
       
  1326 		    
       
  1327 		    CFileMan* cfman = NULL;
       
  1328 		    TRAP(r, cfman = CFileMan::NewL(fs);)
       
  1329 		    test(r == KErrNone);
       
  1330             test(cfman != NULL);
       
  1331             TBuf<40> unmonitored_path;
       
  1332             unmonitored_path.Append(gDriveToTest);
       
  1333             unmonitored_path.Append(_L(":\\F32-TST\\"));
       
  1334             unmonitored_path.Append(pkgDoer.iString);
       
  1335 
       
  1336             //Stage 2 - Move to unmonitored Dir
       
  1337             //Rename 1 
       
  1338             r = cfman->Move(_path,unmonitored_path);
       
  1339             safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1340             
       
  1341             //SetSize (size := 8)
       
  1342             RFile file2;
       
  1343             r = file2.Open(fs,unmonitored_path,EFileWrite);
       
  1344             safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1345             r = file2.SetSize(8);
       
  1346             safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1347             file2.Flush();
       
  1348             file2.Close();            
       
  1349             
       
  1350             //Stage 3 - Move back to monitored Dir
       
  1351             //Rename 2
       
  1352             r = cfman->Move(unmonitored_path,_path);
       
  1353             safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1354             
       
  1355             //Stage 4 - Delete
       
  1356             //Delete
       
  1357             r = cfman->Delete(_path);
       
  1358             safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
       
  1359             
       
  1360             delete cleanup;
       
  1361             delete cfman;
       
  1362             break;
       
  1363 		    }
       
  1364 		default:
       
  1365 			{
       
  1366 			break;
       
  1367 			}
       
  1368 		}
       
  1369 	
       
  1370 	fs.Close();
       
  1371 	multipleTestDoer.End();
       
  1372 	multipleTestDoer.Close();
       
  1373 	return KErrNone;	
       
  1374 	}
       
  1375 
       
  1376 /*
       
  1377  * Test process Capabilites tries to set up filters on the
       
  1378  * the private folder for uid 01234567.
       
  1379  * This function returns the results to trying to add filters on the specified path.
       
  1380  * 
       
  1381  * There are three MMP files:
       
  1382  * t_notifier_nocaps.mmp, t_notifier_allfiles.mmp, t_notifier_belongs.mmp
       
  1383  * 
       
  1384  * t_notifier_nocaps.mmp - 
       
  1385  * 		This process does not have any capabilites, so should not be allowed to set the filter.
       
  1386  * t_notifier_allfiles.mmp -
       
  1387  * 		 This process has ALLFILES capability, so should
       
  1388  * t_notifier_belongs.mmp - 
       
  1389  * 		This process is process with UID 01234567 so this should work too.
       
  1390  * 
       
  1391  * See: f32test\server\t_notifier_caps.cpp
       
  1392  */
       
  1393 TInt TestProcessCapabilities(const TDesC& aProcessName)
       
  1394 	{
       
  1395 	RProcess process;
       
  1396 	TUidType uid;
       
  1397 	TPtrC command((TText*)&gDriveToTest,1);
       
  1398 	TInt r = process.Create(aProcessName,command,uid);
       
  1399 	test(r==KErrNone);
       
  1400 	process.Resume();
       
  1401 	TRequestStatus s1;
       
  1402 	TRequestStatus s2;
       
  1403 	RTimer tim;
       
  1404 	r = tim.CreateLocal();
       
  1405 	test(r==KErrNone);
       
  1406 	TTimeIntervalMicroSeconds32 delay = 5000000; //5 seconds
       
  1407 	tim.After(s1,delay);
       
  1408 	process.Logon(s2);
       
  1409 	User::WaitForRequest(s1,s2);
       
  1410 	test(s2.Int()!=KRequestPending);
       
  1411 	r = process.ExitReason();
       
  1412 	process.Close();
       
  1413 	return r;
       
  1414 	}
       
  1415 
       
  1416 /*
       
  1417  * Creates a file and writes to it twice.
       
  1418  * Used in TestTwoNotificationsL().
       
  1419  */
       
  1420 TInt TwoNotificationsTFDoer(TAny* aAny)
       
  1421 	{
       
  1422 	RTest testDoer(_L("TestTwoNotificationsThreadFunctionDoer"));
       
  1423 	testDoer.Start(_L("TestTwoNotificationsThreadFunctionDoer"));
       
  1424 	
       
  1425 	SThreadPackageMultiple package = *(SThreadPackageMultiple*)aAny;
       
  1426 	TBuf<40> path;
       
  1427 	path.Append(gDriveToTest);
       
  1428 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
       
  1429 	path.Append(package.iFileName);
       
  1430 	
       
  1431 	//Delete file so we definitely get a create notification
       
  1432 	RFs fs;
       
  1433 	TInt r = fs.Connect();
       
  1434 	testDoer(r==KErrNone);
       
  1435 	r = fs.Delete(path);
       
  1436 	testDoer(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
       
  1437 	r = fs.MkDirAll(path);
       
  1438 	testDoer(r==KErrNone || r==KErrAlreadyExists);
       
  1439 		
       
  1440 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Create File %S\n"),&path);
       
  1441 	//Create file
       
  1442 	RFile file;
       
  1443 	r = file.Create(fs,path,EFileWrite);
       
  1444 	testDoer(r == KErrNone);
       
  1445 	
       
  1446 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 1 %S\n"),&path);
       
  1447 	TInt fileSize = 0;
       
  1448 	r = file.Size(fileSize);
       
  1449 	testDoer(r == KErrNone);
       
  1450 	testDoer(fileSize==0);
       
  1451 		
       
  1452 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Write File 1 %S\n"),&path);
       
  1453 	r = file.Write(_L8("1234"));
       
  1454 	testDoer(r == KErrNone);
       
  1455 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 2 %S\n"),&path);
       
  1456 	r = file.Size(fileSize);
       
  1457 	testDoer(r == KErrNone);
       
  1458 	test(fileSize==4);
       
  1459 
       
  1460 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Write File 2 %S\n"),&path);
       
  1461 	r = file.Write(_L8("5678"));
       
  1462 	testDoer(r == KErrNone);
       
  1463 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 3 %S\n"),&path);
       
  1464 	r = file.Size(fileSize);
       
  1465 	testDoer(r == KErrNone);
       
  1466 	test(fileSize==8);
       
  1467 	
       
  1468 	file.Close();	
       
  1469 
       
  1470 	fs.Close();
       
  1471 	testDoer.End();
       
  1472 	testDoer.Close();
       
  1473 	return KErrNone;	
       
  1474 	}
       
  1475 
       
  1476 	/*
       
  1477 	 * The following enum are for the CFileMan test
       
  1478 	 */
       
  1479 	enum TCFsManEnum
       
  1480         {
       
  1481         ECFManCreate1       = 0x01,
       
  1482         ECFManWrite1        = 0x02,
       
  1483         ECFManDelete1       = 0x04,
       
  1484         ECFManCreate2       = 0x08,
       
  1485         ECFManSetSize1      = 0x10,
       
  1486         ECFManWrite2        = 0x20,
       
  1487         ECFManAtt1          = 0x40,
       
  1488         ECFManDelete2       = 0x80,
       
  1489         //Either a create, copy, delete (above - not supported in test) 
       
  1490         //or rename operation (below) 
       
  1491         ECFManRename1      = 0x100,
       
  1492         ECFManRename2      = 0x200
       
  1493         };
       
  1494 
       
  1495 /*
       
  1496  * Used by MultipleNotificationsTFWatcher() to test the notifications.
       
  1497  */
       
  1498 void HandleMultipleNotifications(RTest& aTest, SThreadPackageMultiple& aPackage, CFsNotify* notify, TDesC& aFullname)
       
  1499 	{
       
  1500 	RThread thread;
       
  1501 	TUint64 threadID = thread.Id().Id();
       
  1502 	TInt numNotifications = 0;
       
  1503 	TInt64 fileSize = 0;
       
  1504 	TBool overflow = EFalse;
       
  1505 	
       
  1506 	TInt scratch = 0;
       
  1507 	
       
  1508 	for(TInt i = 0; i < aPackage.iMaxNotifications; ) //Outer-loop to control when we should exit
       
  1509 		{
       
  1510 		aTest.Printf(_L("(%d) - NextNotification\n"),threadID);
       
  1511 		const TFsNotification* notification = notify->NextNotification();
       
  1512 		while(notification != NULL)
       
  1513 				{
       
  1514 				numNotifications++;
       
  1515 				aTest.Printf(_L("NumNotifications = %d\n"),numNotifications);
       
  1516 				//Test notification is not null.
       
  1517 				//We should be getting 1 notification.
       
  1518 				aTest(notification != NULL);
       
  1519 
       
  1520 				aTest.Printf(_L("(%d) - Notification Type\n"),threadID);
       
  1521 				TFsNotification::TFsNotificationType notificationType = notification->NotificationType();
       
  1522 				aTest(notificationType & aPackage.iNotifyType ||
       
  1523 					  notificationType &	TFsNotification::EOverflow);
       
  1524 				
       
  1525 				aTest.Printf(_L("Notification Type = %u - (%d)\n"),notificationType,threadID);
       
  1526 				
       
  1527 				if(notificationType != TFsNotification::EOverflow)
       
  1528 					{
       
  1529 					aTest.Printf(_L("(%d) - Notification Path\n"),threadID);
       
  1530 					TPtrC _pathC;
       
  1531 					((TFsNotification*) notification)->Path(_pathC);
       
  1532 					aTest.Printf(_L("%S - (%d)\n"),&_pathC,threadID);
       
  1533 					
       
  1534 					if(aPackage.iOperation == t_notification::ECFileManMove 
       
  1535 					        && (scratch == (ECFManWrite1 | ECFManCreate1)))
       
  1536 					    {
       
  1537 					    TChar drive = gDriveToTest;
       
  1538 					    TBuf<40> unmodified_path;
       
  1539 					    unmodified_path.Append(drive);
       
  1540 					    unmodified_path.Append(_L(":\\F32-TST\\"));
       
  1541 					    unmodified_path.Append(_L("cf1le.man"));
       
  1542 					    ((TFsNotification*) notification)->NewName(_pathC);
       
  1543 					    TInt matches = _pathC.Match(unmodified_path);
       
  1544 					    safe_test(aTest,matches,__LINE__,aPackage.iLineCall); 
       
  1545 					    }
       
  1546 					else if((scratch == (ECFManWrite1 | ECFManCreate1 | ECFManRename1)))
       
  1547 					    {
       
  1548 					    ((TFsNotification*) notification)->NewName(_pathC);
       
  1549 					    safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall); 
       
  1550 					    }
       
  1551 					else
       
  1552 					    {
       
  1553 					    safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall);  
       
  1554 					    }
       
  1555 					
       
  1556 					}
       
  1557 				else
       
  1558 					{
       
  1559 					aTest.Printf(_L("(%d) - OVERFLOW\n"),threadID);
       
  1560 					//Overflow
       
  1561 					overflow = ETrue;					
       
  1562 					return;
       
  1563 					}
       
  1564 				
       
  1565 				//notificationType will only be of 1 type
       
  1566 				if(notificationType == TFsNotification::EFileChange)
       
  1567 				    {
       
  1568 				    if(!(((aPackage.iNotifyType & TFsNotification::EFileChange) == TFsNotification::EFileChange) &&
       
  1569 				           (aPackage.iOperation == t_notification::EFileWrite ||
       
  1570 				            aPackage.iOperation == t_notification::EFileWrite_async ||
       
  1571 				            aPackage.iOperation == t_notification::EFileWrite_samesize ||
       
  1572 				            aPackage.iOperation == t_notification::EFileSetSize ||
       
  1573 				            aPackage.iOperation == t_notification::ECFileManMove ||
       
  1574 				            aPackage.iOperation == t_notification::EAllOps2 ||
       
  1575 				            aPackage.iOperation == t_notification::EAllOps3)))
       
  1576 				    	safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);				    	
       
  1577 				    
       
  1578                     if (aPackage.iOperation == t_notification::ECFileManMove)
       
  1579                         {
       
  1580                         ((TFsNotification*) notification)->FileSize(fileSize);
       
  1581                         //File just been created and written to.
       
  1582                         if(fileSize == 4)
       
  1583                             {
       
  1584                             scratch |= ECFManWrite1;    
       
  1585                             }
       
  1586                         else if(fileSize == 8)
       
  1587                             {
       
  1588                             scratch |= ECFManWrite2;
       
  1589                             }                            
       
  1590                         }
       
  1591                     else if (aPackage.iNotifyType == TFsNotification::EFileChange)
       
  1592 				        {
       
  1593 				        ((TFsNotification*) notification)->FileSize(fileSize);
       
  1594 				        aTest.Printf(_L("Filesize - %d (%d)\n"),fileSize,threadID);
       
  1595 				        //A notification is received every time the size is changed
       
  1596 				        //due to the flushing
       
  1597 				        if (aPackage.iOperation == t_notification::EFileWrite_async)
       
  1598                             {
       
  1599                             //We write 52 letters
       
  1600                             if(fileSize != 52*(i+1))
       
  1601                             	safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1602                             }
       
  1603                         else if (aPackage.iOperation == t_notification::EFileWrite_samesize)
       
  1604                             {
       
  1605                             //Only 4 letters in file
       
  1606                             if(fileSize != 4)
       
  1607                             	safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1608                             }
       
  1609                         else if (i < aPackage.iIterations)
       
  1610                             {
       
  1611                             //We write/increase size by 4 letters/bytes
       
  1612                             if(fileSize != 4*(i+1))
       
  1613                             	safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1614                             }
       
  1615                         else
       
  1616                             {
       
  1617                             //We decrease size by 4 bytes
       
  1618                             if(fileSize != 4*(aPackage.iMaxNotifications-i))
       
  1619                             	safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1620                             }                           
       
  1621 				        }
       
  1622 				    }
       
  1623 				else if(notificationType == TFsNotification::ECreate)
       
  1624 					{
       
  1625 					if(!(((aPackage.iNotifyType & TFsNotification::ECreate) == TFsNotification::ECreate) &&
       
  1626 						   (aPackage.iOperation == t_notification::EFileCreate ||
       
  1627 							aPackage.iOperation == t_notification::EFileReplace ||
       
  1628 							aPackage.iOperation == t_notification::EFileCreate_subs || 
       
  1629 							aPackage.iOperation == t_notification::EFileCreate_subs_nowatch ||
       
  1630 							aPackage.iOperation == t_notification::EFileCreate_txt_nowatch ||
       
  1631 							aPackage.iOperation == t_notification::EFileCreate_txt ||
       
  1632 							aPackage.iOperation == t_notification::EFsMkDir ||
       
  1633 							aPackage.iOperation == t_notification::ECFileManMove ||
       
  1634 							aPackage.iOperation == t_notification::EAllOps1 ||
       
  1635 							aPackage.iOperation == t_notification::EAllOps2 ||
       
  1636 							aPackage.iOperation == t_notification::EAllOps3 ||
       
  1637 							aPackage.iOperation == t_notification::EAllOps4 ||
       
  1638 							aPackage.iOperation == t_notification::EAllOps5)))
       
  1639 						safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1640 					if (aPackage.iOperation == t_notification::EFileCreate_txt)
       
  1641 					    {
       
  1642 					    //Check filename is of correct extension
       
  1643 					    TPtrC _path;
       
  1644 					    ((TFsNotification*) notification)->Path(_path);
       
  1645 					    TBuf<5> _ext;
       
  1646 					    _ext.Append(_L(".txt"));
       
  1647 					    TBuf<5> ext;
       
  1648 					    ext.Append(_path.Right(4));
       
  1649 					    safe_test(aTest,ext.Match(_ext),__LINE__,aPackage.iLineCall);
       
  1650 					    }
       
  1651 					else if (aPackage.iOperation == t_notification::ECFileManMove)
       
  1652 					    {
       
  1653 					    if(scratch & ECFManCreate1)
       
  1654 					        {
       
  1655 					        scratch |= ECFManCreate2;  //File created second time    
       
  1656 					        }
       
  1657 					    else
       
  1658 					        {
       
  1659 					        scratch |= ECFManCreate1;  //File created first time
       
  1660 					        }
       
  1661 					    }
       
  1662 					}
       
  1663 				else if(notificationType == TFsNotification::EDelete)
       
  1664 					{
       
  1665 					if(!(((aPackage.iNotifyType & TFsNotification::EDelete) == TFsNotification::EDelete) &&
       
  1666 						   (aPackage.iOperation == t_notification::EFsDelete ||
       
  1667 							aPackage.iOperation == t_notification::EFsRmDir ||
       
  1668 							aPackage.iOperation == t_notification::EFsRmDir_nonEmpty ||
       
  1669 							aPackage.iOperation == t_notification::EFsRmDir_wild ||
       
  1670 							aPackage.iOperation == t_notification::ECFileManMove ||
       
  1671 							aPackage.iOperation == t_notification::EAllOps1 ||
       
  1672 							aPackage.iOperation == t_notification::EAllOps2 ||
       
  1673 							aPackage.iOperation == t_notification::EAllOps3 ||
       
  1674 							aPackage.iOperation == t_notification::EAllOps4)))
       
  1675 						safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1676 					
       
  1677 					if(aPackage.iOperation == t_notification::ECFileManMove)
       
  1678 					    {
       
  1679 					    if(scratch & ECFManDelete1)
       
  1680 					        {
       
  1681 					        scratch |= ECFManDelete2;
       
  1682 					        }
       
  1683 					    else
       
  1684 					        {
       
  1685 					        scratch |= ECFManDelete1;
       
  1686 					        }
       
  1687 					    }
       
  1688 					}
       
  1689 				else if(notificationType == TFsNotification::ERename)
       
  1690 					{
       
  1691 					if(!(((aPackage.iNotifyType & TFsNotification::ERename) == TFsNotification::ERename) &&
       
  1692 						   (aPackage.iOperation == t_notification::EFileRename ||
       
  1693 							aPackage.iOperation == t_notification::EFileRename_wild ||
       
  1694 							aPackage.iOperation == t_notification::EFsReplace ||
       
  1695 							aPackage.iOperation == t_notification::ECFileManMove ||
       
  1696 							aPackage.iOperation == t_notification::EFsRename ||
       
  1697 							aPackage.iOperation == t_notification::EFsRename_dir ||
       
  1698 							aPackage.iOperation == t_notification::EAllOps5)))
       
  1699 						safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1700 					TPtrC newnameC;
       
  1701 					((TFsNotification*)notification)->NewName(newnameC);
       
  1702 					aTest.Printf(_L("%S - (%d)\n"),&newnameC,threadID);
       
  1703 					
       
  1704 					TPtrC _pathC;
       
  1705 					((TFsNotification*) notification)->Path(_pathC);
       
  1706 					
       
  1707 					TBuf<40> _path;
       
  1708 					_path.Copy(_pathC);
       
  1709 					
       
  1710 					if (aPackage.iOperation == t_notification::EFsRename_dir)
       
  1711 						{
       
  1712 						_path.Delete(_path.Length()-1,1);
       
  1713 						_path.AppendNum(0);
       
  1714 						_path.Append(KPathDelimiter);
       
  1715 						}
       
  1716 					else if (aPackage.iOperation == t_notification::EFileRename_wild)
       
  1717 						{
       
  1718 						_path.Delete(_path.Length()-1,1);
       
  1719 						_path.AppendNum(numNotifications);
       
  1720 						}
       
  1721 					else
       
  1722 						{
       
  1723 						_path.AppendNum(0);
       
  1724 						}
       
  1725 				
       
  1726 					if(aPackage.iOperation != t_notification::ECFileManMove)
       
  1727 					    {
       
  1728 					    safe_test(aTest,newnameC.Match(_path),__LINE__,aPackage.iLineCall);    
       
  1729 					    }
       
  1730 					else if(scratch & ECFManRename1)
       
  1731 					    {
       
  1732 					    scratch |= ECFManRename2;
       
  1733 					    }
       
  1734 					else 
       
  1735 					    {
       
  1736 					    scratch |= ECFManRename1;
       
  1737 					    }
       
  1738 					
       
  1739 					}
       
  1740 				else if(notificationType == TFsNotification::EAttribute)
       
  1741 					{
       
  1742 					if(!(((aPackage.iNotifyType & TFsNotification::EAttribute) == TFsNotification::EAttribute) &&
       
  1743 						   (aPackage.iOperation == t_notification::EFsSetEntry ||
       
  1744 							aPackage.iOperation == t_notification::EFileSet ||
       
  1745 							aPackage.iOperation == t_notification::EFileSetAtt ||
       
  1746 							aPackage.iOperation == t_notification::EFileSetAtt_subs ||
       
  1747 							aPackage.iOperation == t_notification::ECFileManMove ||
       
  1748 							aPackage.iOperation == t_notification::EAllOps4)))
       
  1749 						safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1750 					TUint setAtt = 0;
       
  1751 					TUint clearAtt = 0;
       
  1752 					((TFsNotification*) notification)->Attributes(setAtt, clearAtt);
       
  1753 					
       
  1754 				    if(aPackage.iOperation == t_notification::ECFileManMove)
       
  1755 				        {
       
  1756 				        scratch |= ECFManAtt1;
       
  1757 				        }
       
  1758 				    else
       
  1759 				        {
       
  1760 			            if(setAtt != KEntryAttHidden)
       
  1761 			                safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1762 			            if(clearAtt != KEntryAttReadOnly)
       
  1763 			                safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1764 				        }
       
  1765 					}
       
  1766 				else if(notificationType == TFsNotification::EMediaChange)
       
  1767 					{
       
  1768 					if(!(((aPackage.iNotifyType & TFsNotification::EMediaChange) == TFsNotification::EMediaChange) &&
       
  1769 						   (aPackage.iOperation == t_notification::EMount || 
       
  1770 							aPackage.iOperation == t_notification::EMountScan || 
       
  1771 							aPackage.iOperation == t_notification::EDismount ||
       
  1772 							aPackage.iOperation == t_notification::EMountDismount ||
       
  1773 							aPackage.iOperation == t_notification::EMediaCardInsertion ||
       
  1774 							aPackage.iOperation == t_notification::EMediaCardRemoval ||
       
  1775 							aPackage.iOperation == t_notification::EFormat ||
       
  1776 							aPackage.iOperation == t_notification::ECFileManMove ||
       
  1777 							aPackage.iOperation == t_notification::ERawDiskWrite)))
       
  1778 						safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1779 					}
       
  1780 				else if(notificationType == TFsNotification::EDriveName)
       
  1781 					{
       
  1782 					if(!(((aPackage.iNotifyType & TFsNotification::EDriveName) == TFsNotification::EDriveName) &&
       
  1783 						   (aPackage.iOperation == t_notification::ESetDriveName ||
       
  1784 							aPackage.iOperation == t_notification::EAllOps6)))
       
  1785 						safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1786 					}
       
  1787 				else if(notificationType == TFsNotification::EVolumeName)
       
  1788 					{
       
  1789 					if(!(((aPackage.iNotifyType & TFsNotification::EVolumeName) == TFsNotification::EVolumeName) &&
       
  1790 						   (aPackage.iOperation == t_notification::ESetVolumeLabel ||
       
  1791 							aPackage.iOperation == t_notification::EAllOps6)))
       
  1792 						safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1793 					
       
  1794 					TPtrC newnameC;
       
  1795 					((TFsNotification*)notification)->NewName(newnameC);
       
  1796 					aTest.Printf(_L("New volume name: %S - (%d)\n"),&newnameC,threadID);
       
  1797 					}
       
  1798 
       
  1799 				i++;
       
  1800 				notification = notify->NextNotification();
       
  1801 				if (notification == NULL)
       
  1802 					aTest.Printf(_L("Notification is NULL - (%d)\n"),threadID);
       
  1803 				}
       
  1804 		
       
  1805 		if(i==1) //First iteration will only ever get 1 notification
       
  1806 			{
       
  1807 			if(numNotifications != 1)
       
  1808 				safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1809 			}
       
  1810 		
       
  1811 		if(numNotifications < aPackage.iMaxNotifications && !overflow) //Ensure we get all of the notifications we expected
       
  1812 			{
       
  1813 			TRequestStatus status;
       
  1814 			notify->RequestNotifications(status);
       
  1815 			User::WaitForRequest(status);
       
  1816 			}
       
  1817 		}
       
  1818 	
       
  1819 	//0x307 = create1 | write1 | delete1 | rename1 | rename2 
       
  1820 	if(aPackage.iOperation == t_notification::ECFileManMove && (scratch != 0x307))
       
  1821 	    {
       
  1822 	    aTest.Printf(_L("CFileManMove test failure - scratch = 0x%x"),scratch);
       
  1823 	    safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
       
  1824 	    }
       
  1825 	    
       
  1826 	}
       
  1827 
       
  1828 /*
       
  1829  * Watches for changes in files/directories.
       
  1830  * Used in TestMultipleNotificationsL().
       
  1831  */
       
  1832 TInt MultipleNotificationsTFWatcher(TAny* aAny)
       
  1833 	{
       
  1834 	CTrapCleanup* cleanup;
       
  1835 	cleanup = CTrapCleanup::New();
       
  1836 	
       
  1837 	RThread thread;
       
  1838 	TUint64 threadID = thread.Id().Id();
       
  1839 	
       
  1840 	SThreadPackageMultiple package = *(SThreadPackageMultiple*) aAny;
       
  1841 	RTest multipleWatcherTest(_L("MultipleNotificationsTFWatcher"));
       
  1842 	multipleWatcherTest.Start(_L("MultipleNotificationsTFWatcher"));
       
  1843 	
       
  1844 	RFs fs;
       
  1845 	fs.Connect();
       
  1846 	
       
  1847 	multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher (%d) - Create CFsNotify\n"),threadID);
       
  1848 	CFsNotify* notify = NULL;
       
  1849 	TRAPD(r,notify = CFsNotify::NewL(fs,package.iBufferSize));
       
  1850 	safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
       
  1851 	TBuf<40> path;
       
  1852 	TBuf<20> filename;
       
  1853 	if(package.iNotifyType != TFsNotification::EMediaChange &&
       
  1854 	   package.iNotifyType != TFsNotification::EDriveName &&
       
  1855 	   package.iNotifyType != TFsNotification::EVolumeName &&
       
  1856 	   package.iOperation != t_notification::EAllOps6)
       
  1857 		{
       
  1858 		path.Append(gDriveToTest);
       
  1859 		path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
       
  1860 		path.Append(package.iFileName);	
       
  1861 		filename.Append(package.iString);
       
  1862 		}
       
  1863 	else
       
  1864 		{
       
  1865 		path.Append((TChar)globalDriveNum+(TChar)'A');
       
  1866 		path.Append(_L(":"));
       
  1867 		}
       
  1868 	TBuf<40> fullname;
       
  1869 	fullname.Append(path);
       
  1870 	fullname.Append(filename);
       
  1871 	
       
  1872 	if (package.iNotifyType == TFsNotification::EVolumeName ||
       
  1873 		package.iOperation == t_notification::EAllOps6)
       
  1874 		{
       
  1875 		//Ensure volume has no label
       
  1876 		multipleWatcherTest.Printf(_L("Set volume label to nothing\n"));
       
  1877 		r = fs.SetVolumeLabel(_L(""),globalDriveNum);
       
  1878 		safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
       
  1879 		}
       
  1880 	
       
  1881 	if (package.iNotifyType == TFsNotification::EDriveName ||
       
  1882 		package.iOperation == t_notification::EAllOps6)
       
  1883 		{
       
  1884 		//Ensure drive has no name
       
  1885 		multipleWatcherTest.Printf(_L("Set drive name to nothing\n"));
       
  1886 		r = fs.SetDriveName(globalDriveNum,_L(""));
       
  1887 		safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
       
  1888 		}
       
  1889 	
       
  1890 	multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher - Add Notification for path %S\n"),&path);
       
  1891 	multipleWatcherTest.Printf(_L("Add Notification for type %u - (%d)\n"),(TUint)package.iNotifyType,threadID);	
       
  1892 	r = notify->AddNotification((TUint)package.iNotifyType,path,filename);	
       
  1893 	safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
       
  1894 
       
  1895 	TRequestStatus status;
       
  1896 	multipleWatcherTest.Printf(_L("(%d) - Request Notifications\n"),threadID);
       
  1897 	r = notify->RequestNotifications(status);
       
  1898 	safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
       
  1899 	
       
  1900 	if (package.iOperation == t_notification::EMediaCardRemoval)
       
  1901 		{
       
  1902 		multipleWatcherTest.Printf(_L("*****************************************************************\n"));
       
  1903 		multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
       
  1904 		multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the removal of the media card.\n"));
       
  1905 		multipleWatcherTest.Printf(_L("PLEASE REMOVE THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
       
  1906 		multipleWatcherTest.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
       
  1907 		multipleWatcherTest.Printf(_L("*****************************************************************\n"));
       
  1908 		}
       
  1909 	if (package.iOperation == t_notification::EMediaCardInsertion)
       
  1910 		{
       
  1911 		multipleWatcherTest.Printf(_L("*******************************************************************\n"));
       
  1912 		multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
       
  1913 		multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the insertion of the media card.\n"));
       
  1914 		multipleWatcherTest.Printf(_L("PLEASE INSERT THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
       
  1915 		multipleWatcherTest.Printf(_L("*******************************************************************\n"));
       
  1916 		}
       
  1917 	
       
  1918 	multipleWatcherTest.Printf(_L("(%d) - Signal Test thread to start Doer thread\n"),threadID);
       
  1919 	package.iBarrier.Signal();
       
  1920 	User::WaitForRequest(status);
       
  1921 	
       
  1922 	multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
       
  1923 	
       
  1924 	//Handles the notifications
       
  1925 	HandleMultipleNotifications(multipleWatcherTest, package, notify, (TDesC&)fullname);
       
  1926 	
       
  1927 	multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
       
  1928 	
       
  1929 	delete notify;
       
  1930 	fs.Close();
       
  1931 	multipleWatcherTest.End();
       
  1932 	multipleWatcherTest.Close();
       
  1933 	delete cleanup;
       
  1934 	return KErrNone;	
       
  1935 	}
       
  1936 
       
  1937 /*
       
  1938  * TestTwoNotificationsL - Tests File Write, 1 Doer writes to a file twice.
       
  1939  *  1 Watcher watches for file write changes. Just so happens that the second one overflows.
       
  1940  */
       
  1941 TInt TestTwoNotificationsL()
       
  1942 	{
       
  1943 	test.Next(_L("TestTwoNotifications"));
       
  1944 	
       
  1945 	RFs fs;
       
  1946 	fs.Connect();
       
  1947 	RSemaphore twoNotificationsDoerBar;
       
  1948 	SThreadPackageMultiple package;
       
  1949 	_LIT(KFileName,"file0.write");
       
  1950 	package.iIterations = 10;
       
  1951 	package.iOperation = t_notification::EFileWrite;
       
  1952 	package.iNotifyType = TFsNotification::EFileChange;
       
  1953 	package.iFileName = KFileName;
       
  1954 	package.iBufferSize = 100; //Should get changed to KMin... in CFsNotify::NewL
       
  1955 	
       
  1956 	User::LeaveIfError(twoNotificationsDoerBar.CreateLocal(0));
       
  1957 	User::LeaveIfError(package.iBarrier.CreateLocal(0));
       
  1958 	RThread watcher;
       
  1959 	RThread doer;
       
  1960 	
       
  1961 	TInt r = watcher.Create(_L("TestTwoNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
       
  1962 	test(r==KErrNone);
       
  1963 	r = doer.Create(_L("TestTwoNotificationsDoerThread"),TwoNotificationsTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
       
  1964 	test(r==KErrNone);
       
  1965 	test.Next(_L("TestTwoNotifications - Resume Watcher"));
       
  1966 	watcher.Resume();
       
  1967 	test.Next(_L("TestTwoNotifications - Wait for Watcher to be ready"));
       
  1968 	package.iBarrier.Wait(); //Wait till Watcher has requested notification
       
  1969 	test.Next(_L("TestTwoNotifications - Resume Doer"));
       
  1970 	doer.Resume();
       
  1971 		
       
  1972 	test.Next(_L("TestTwoNotifications - Wait for doer thread death"));
       
  1973 	TRequestStatus status;
       
  1974 	doer.Logon(status);
       
  1975 	User::WaitForRequest(status);
       
  1976 	test(doer.ExitReason()==KErrNone);
       
  1977 	
       
  1978 	test.Next(_L("TestTwoNotifications - Wait for watcher thread death"));
       
  1979 	watcher.Logon(status);
       
  1980 	User::WaitForRequest(status);
       
  1981 	test(watcher.ExitReason()==KErrNone);
       
  1982 	
       
  1983 	CLOSE_AND_WAIT(doer);
       
  1984 	CLOSE_AND_WAIT(watcher);
       
  1985 	
       
  1986 	twoNotificationsDoerBar.Close();
       
  1987 	package.iBarrier.Close();
       
  1988 	fs.Close();
       
  1989 	
       
  1990 	return KErrNone;	
       
  1991 	}
       
  1992 
       
  1993 
       
  1994 /*
       
  1995  * Watch two threads to receive two notifications.
       
  1996  * Used in TestTwoDoersL().
       
  1997  */
       
  1998 TInt TestTwoDoersWatcher(TAny* aAny)
       
  1999 	{
       
  2000 	CTrapCleanup* cleanup;
       
  2001 	cleanup = CTrapCleanup::New();
       
  2002 	
       
  2003 	RSemaphore& twoThreadsBarrier = *(RSemaphore*)aAny;
       
  2004 	RTest twoThreadsWatcherTest(_L("TwoThreadsWatcher"));
       
  2005 	twoThreadsWatcherTest.Start(_L("TwoThreadsWatcher"));
       
  2006 	
       
  2007 	RFs fs;
       
  2008 	fs.Connect();
       
  2009 	
       
  2010 	twoThreadsWatcherTest.Next(_L("Create CFsNotify"));
       
  2011 	CFsNotify* notify = NULL;
       
  2012 	TRAPD(r,notify = CFsNotify::NewL(fs,200));
       
  2013 	twoThreadsWatcherTest(r == KErrNone);
       
  2014 	
       
  2015 	TBuf<40> path1;
       
  2016 	TBuf<20> filename1;
       
  2017 	TBuf<40> path2;
       
  2018 	TBuf<20> filename2;
       
  2019 	path1.Append(gDriveToTest);
       
  2020 	path2.Append(gDriveToTest);
       
  2021 	path1.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  2022 	filename1.Append(_L("file1.create"));
       
  2023 	path2.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  2024 	filename2.Append(_L("file2.create"));
       
  2025 	TBuf<40> fullname1;
       
  2026 	fullname1.Append(path1);
       
  2027 	fullname1.Append(filename1);
       
  2028 	TBuf<40> fullname2;
       
  2029 	fullname2.Append(path2);
       
  2030 	fullname2.Append(filename2);
       
  2031 	
       
  2032 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path1);
       
  2033 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path1,filename1);
       
  2034 	twoThreadsWatcherTest(r == KErrNone);
       
  2035 	
       
  2036 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path2);
       
  2037 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path2,filename2);
       
  2038 	twoThreadsWatcherTest(r == KErrNone);
       
  2039 		
       
  2040 	TRequestStatus status;
       
  2041 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Request Notifications"));
       
  2042 	r = notify->RequestNotifications(status);
       
  2043 	twoThreadsWatcherTest(r == KErrNone);
       
  2044 
       
  2045 	twoThreadsBarrier.Signal(); //Signal Doer threads to start
       
  2046 	User::WaitForRequest(status);
       
  2047 
       
  2048 	// We should be getting 2 notifications
       
  2049 	// Test notifications are not null and check notification types and paths
       
  2050 	// 1st notification:
       
  2051 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification"));
       
  2052 	const TFsNotification* notification = notify->NextNotification();
       
  2053 	twoThreadsWatcherTest(notification != NULL);
       
  2054 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Type"));
       
  2055 	TFsNotification::TFsNotificationType notificationType = ((TFsNotification*)notification)->NotificationType();
       
  2056 	twoThreadsWatcherTest(notificationType == TFsNotification::ECreate);
       
  2057 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Path"));
       
  2058 	TPtrC _pathC;
       
  2059 	((TFsNotification*)notification)->Path(_pathC);
       
  2060 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - First Notification Path returned %S\n"),&_pathC);
       
  2061 	TBuf<40> _path;
       
  2062 	_path.Copy(_pathC);
       
  2063 	//We can't guarantee which thread ran first so check that it was either path1 or path2
       
  2064 	twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone);
       
  2065 		
       
  2066 	// 2nd notification:
       
  2067 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification"));
       
  2068 	notification = notify->NextNotification();	
       
  2069 	// Check if next notification exists
       
  2070 	if (!notification)
       
  2071 		{
       
  2072 		notify->RequestNotifications(status);
       
  2073 		User::WaitForRequest(status);
       
  2074 		notification = notify->NextNotification();
       
  2075 		}	
       
  2076 	twoThreadsWatcherTest(notification != NULL);
       
  2077 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Type"));
       
  2078 	notificationType = ((TFsNotification*)notification)->NotificationType();
       
  2079 	twoThreadsWatcherTest(notificationType == TFsNotification::ECreate);
       
  2080 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Path"));
       
  2081 	((TFsNotification*)notification)->Path(_pathC);
       
  2082 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Second Notification Path returned %S\n"),&_pathC);
       
  2083 	_path.Copy(_pathC);
       
  2084 	twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone);
       
  2085 	
       
  2086 	delete notify;	
       
  2087 	fs.Close();
       
  2088 	twoThreadsWatcherTest.End();
       
  2089 	twoThreadsWatcherTest.Close();
       
  2090 	delete cleanup;
       
  2091 	return KErrNone;	
       
  2092 	}
       
  2093 
       
  2094 /*
       
  2095  * TestTwoDoersL - Two Doer threads create a file each and there's one Watcher
       
  2096  *  which expects two notifications (one from each Doer).
       
  2097  */
       
  2098 TInt TestTwoDoersL()
       
  2099 	{
       
  2100 	test.Next(_L("TestTwoDoers"));
       
  2101 	
       
  2102 	RFs fs;
       
  2103 	fs.Connect();
       
  2104 	
       
  2105 	_LIT(KFileName1,"file1.create");
       
  2106 	_LIT(KFileName2,"file2.create");
       
  2107 	RSemaphore simpleBarrierTest;
       
  2108 	SThreadPackage pkgDoer1;
       
  2109 	SThreadPackage pkgDoer2;
       
  2110 	pkgDoer1.iFileName = KFileName1;
       
  2111 	pkgDoer2.iFileName = KFileName2;
       
  2112 		
       
  2113 	User::LeaveIfError(pkgDoer1.iBarrier.CreateLocal(0));
       
  2114 	User::LeaveIfError(pkgDoer2.iBarrier.CreateLocal(0));
       
  2115 	User::LeaveIfError(simpleBarrierTest.CreateLocal(0));
       
  2116 	RThread watcher;
       
  2117 	RThread doer1;
       
  2118 	RThread doer2;
       
  2119 	
       
  2120 	watcher.Create(_L("TestTwoDoers-WatcherThread"),TestTwoDoersWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&simpleBarrierTest);
       
  2121 	doer1.Create(_L("TestTwoDoers-DoerThread1"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer1);
       
  2122 	doer2.Create(_L("TestTwoDoers-DoerThread2"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer2);
       
  2123 	watcher.Resume();
       
  2124 	simpleBarrierTest.Wait();	//Wait until Watcher has created CFsNotify
       
  2125 	
       
  2126 	doer1.Resume();
       
  2127 	doer2.Resume();
       
  2128 	
       
  2129 	test.Next(_L("TestTwoDoers - Wait for doer1 thread death"));
       
  2130 	TRequestStatus status;
       
  2131 	doer1.Logon(status);
       
  2132 	User::WaitForRequest(status);
       
  2133 	test(doer1.ExitReason()==KErrNone);
       
  2134 	
       
  2135 	test.Next(_L("TestTwoDoers - Wait for doer2 thread death"));
       
  2136 	doer2.Logon(status);
       
  2137 	User::WaitForRequest(status);
       
  2138 	test(doer2.ExitReason()==KErrNone);
       
  2139 	
       
  2140 	test.Next(_L("TestTwoDoers - Wait for watcher thread death"));
       
  2141 	watcher.Logon(status);
       
  2142 	RTimer timer1;
       
  2143 	TInt r = timer1.CreateLocal();
       
  2144 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  2145 	TRequestStatus timeout;
       
  2146 	TTimeIntervalMicroSeconds32 time = 10000000;    //10 seconds
       
  2147 	timer1.After(timeout,time);
       
  2148 	User::WaitForRequest(timeout,status);
       
  2149 	test(status.Int() != KRequestPending);
       
  2150 	timer1.Cancel();
       
  2151 	timer1.Close();
       
  2152 	//User::WaitForRequest(status);
       
  2153 	test(watcher.ExitReason()==KErrNone);
       
  2154 	
       
  2155 	CLOSE_AND_WAIT(doer1);
       
  2156 	CLOSE_AND_WAIT(doer2);
       
  2157 	CLOSE_AND_WAIT(watcher);
       
  2158 	
       
  2159 	pkgDoer1.iBarrier.Close();
       
  2160 	pkgDoer2.iBarrier.Close();
       
  2161 	simpleBarrierTest.Close();
       
  2162 	fs.Close();
       
  2163 	return KErrNone;
       
  2164 	}
       
  2165 
       
  2166 /*
       
  2167  * TestTwoWatchersL - Uses two watcher threads and one doer thread to test that running 
       
  2168  *  two distinct sub sessions at the same time (both watch the same file).
       
  2169  */
       
  2170 TInt TestTwoWatchersL()
       
  2171 	{
       
  2172 	test.Next(_L("TestTwoWatchers"));
       
  2173 	RFs fs;
       
  2174 	fs.Connect();
       
  2175 	_LIT(KFileName,"file.creat3");
       
  2176 	SThreadPackage pkgDoer;
       
  2177 	pkgDoer.iFileName = KFileName;
       
  2178 	
       
  2179 	SThreadPackage watcherPkg;
       
  2180 	watcherPkg.iFileName = KFileName;
       
  2181 		
       
  2182 	User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0));
       
  2183 	User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0));
       
  2184 	RThread watcher;
       
  2185 	RThread watcher2;
       
  2186 	RThread doer;
       
  2187 	watcher.Create(_L("TestTwoWatchersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
       
  2188 	watcher2.Create(_L("TestTwoWatchersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
       
  2189 	doer.Create(_L("TestTwoWatchersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
       
  2190 	watcher.Resume();
       
  2191 	watcher2.Resume();
       
  2192 	watcherPkg.iBarrier.Wait(); //Wait till both watchers have requested notification
       
  2193 	watcherPkg.iBarrier.Wait(); 
       
  2194 	doer.Resume();
       
  2195 
       
  2196 	test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
       
  2197 	TRequestStatus status;
       
  2198 	doer.Logon(status);
       
  2199 	User::WaitForRequest(status);
       
  2200 	test(doer.ExitReason()==KErrNone);
       
  2201 	
       
  2202 	test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
       
  2203 	watcher.Logon(status);
       
  2204 	RTimer timer1;
       
  2205 	TInt r = timer1.CreateLocal();
       
  2206 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  2207 	TRequestStatus timeout;
       
  2208 	TTimeIntervalMicroSeconds32 time = 10000000;    //10 seconds
       
  2209 	timer1.After(timeout,time);
       
  2210 	User::WaitForRequest(timeout,status);
       
  2211 	test(status.Int() != KRequestPending);
       
  2212 	timer1.Cancel();
       
  2213 	timer1.Close();
       
  2214 //	User::WaitForRequest(status);
       
  2215 	test(watcher.ExitReason()==KErrNone);
       
  2216 	
       
  2217 	test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
       
  2218 	watcher2.Logon(status);
       
  2219 	RTimer timer2;
       
  2220 	r = timer2.CreateLocal();
       
  2221 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  2222 	TRequestStatus timeout2;
       
  2223 	timer2.After(timeout2,time);
       
  2224 	User::WaitForRequest(timeout2,status);
       
  2225 	test(status.Int() != KRequestPending);
       
  2226 	timer2.Cancel();
       
  2227 	timer2.Close();
       
  2228 	//User::WaitForRequest(status);
       
  2229 	test(watcher2.ExitReason()==KErrNone);
       
  2230 	
       
  2231 	CLOSE_AND_WAIT(doer);
       
  2232 	CLOSE_AND_WAIT(watcher);
       
  2233 	CLOSE_AND_WAIT(watcher2);
       
  2234 	
       
  2235 	pkgDoer.iBarrier.Close();
       
  2236 	watcherPkg.iBarrier.Close();
       
  2237 	fs.Close();
       
  2238 	return KErrNone;	
       
  2239 	}
       
  2240 
       
  2241 
       
  2242 /*
       
  2243  * TestTwoWatchersTwoDoersL - Two watcher threads watches two different doer threads.
       
  2244  */
       
  2245 TInt TestTwoWatchersTwoDoersL()
       
  2246 	{
       
  2247 	test.Next(_L("TestTwoWatchersTwoDoers"));
       
  2248 	RFs fs;
       
  2249 	fs.Connect();
       
  2250 	_LIT(KFileName1,"f1le.create");
       
  2251 	_LIT(KFileName2,"f2le.create");
       
  2252 	SThreadPackage package1;
       
  2253 	package1.iFileName = KFileName1;
       
  2254 	
       
  2255 	SThreadPackage package2;
       
  2256 	package2.iFileName = KFileName2;
       
  2257 		
       
  2258 	User::LeaveIfError(package1.iBarrier.CreateLocal(0));
       
  2259 	User::LeaveIfError(package2.iBarrier.CreateLocal(0));
       
  2260 	RThread watcher;
       
  2261 	RThread watcher2;
       
  2262 	RThread doer;
       
  2263 	RThread doer2;
       
  2264 	watcher.Create(_L("TestTwoWatchersTwoDoersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
       
  2265 	doer.Create(_L("TestTwoWatchersTwoDoersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
       
  2266 	
       
  2267 	watcher2.Create(_L("TestTwoWatchersTwoDoersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
       
  2268 	doer2.Create(_L("TestTwoWatchersTwoDoersDoer2Thread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
       
  2269 	watcher.Resume();
       
  2270 	watcher2.Resume();
       
  2271 	package1.iBarrier.Wait(); //Wait till both watchers have requested notification
       
  2272 	package2.iBarrier.Wait(); 
       
  2273 	doer.Resume();
       
  2274 	doer2.Resume();
       
  2275 	
       
  2276 	test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
       
  2277 	TRequestStatus status;
       
  2278 	doer.Logon(status);
       
  2279 	User::WaitForRequest(status);
       
  2280 	test(doer.ExitReason()==KErrNone);
       
  2281 	
       
  2282 	test.Printf(_L("Wait for DOER2 to terminate , Line %d"),__LINE__);
       
  2283 	doer2.Logon(status);
       
  2284 	User::WaitForRequest(status);
       
  2285 	test(doer2.ExitReason()==KErrNone);
       
  2286 
       
  2287 	test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
       
  2288 	watcher.Logon(status);
       
  2289 	RTimer timer1;
       
  2290 	TInt r = timer1.CreateLocal();
       
  2291 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  2292 	TRequestStatus timeout;
       
  2293 	TTimeIntervalMicroSeconds32 time = 10000000;    //10 seconds
       
  2294 	timer1.After(timeout,time);
       
  2295 	User::WaitForRequest(timeout,status);
       
  2296 	test(status.Int() != KRequestPending);
       
  2297 	timer1.Cancel();
       
  2298 	timer1.Close();
       
  2299 	test(watcher.ExitReason()==KErrNone);
       
  2300 	
       
  2301 	test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
       
  2302 	watcher2.Logon(status);
       
  2303 	RTimer timer2;
       
  2304 	r = timer2.CreateLocal();
       
  2305 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  2306 	TRequestStatus timeout2;
       
  2307 	timer2.After(timeout2,time);
       
  2308 	User::WaitForRequest(timeout2,status);
       
  2309 	test(status.Int() != KRequestPending);
       
  2310 	timer2.Cancel();
       
  2311 	timer2.Close();
       
  2312 	test(watcher2.ExitReason()==KErrNone);
       
  2313 	
       
  2314 	CLOSE_AND_WAIT(doer);
       
  2315 	CLOSE_AND_WAIT(doer2);
       
  2316 	CLOSE_AND_WAIT(watcher);
       
  2317 	CLOSE_AND_WAIT(watcher2);
       
  2318 	
       
  2319 	package1.iBarrier.Close();
       
  2320 	package2.iBarrier.Close();
       
  2321 	fs.Close();
       
  2322 	return KErrNone;		
       
  2323 	}
       
  2324 
       
  2325 
       
  2326 /*
       
  2327  * Multi-purpose test
       
  2328  * 
       
  2329  * If aFailureExpected is ETrue, it is expected that the watcher thread is not terminated normally,
       
  2330  * due to the notification(s) not being sent.
       
  2331  * Since this function is called many times, aLineCall is used to show the line where it is called from.
       
  2332  * See SThreadPackageMultiple.
       
  2333  */
       
  2334 TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations,
       
  2335 								TInt aMaxNotifications, t_notification::EOperation aOperation,
       
  2336 								TUint aNotifyType, TInt aBufferSize, TBool aFailureExpected, TInt aLineCall)
       
  2337 	{
       
  2338 	test.Next(_L("TestMultipleNotifications"));
       
  2339 	
       
  2340 	RFs fs;
       
  2341 	fs.Connect();
       
  2342 	SThreadPackageMultiple package;
       
  2343 	package.iIterations = aIterations;
       
  2344 	package.iMaxNotifications = aMaxNotifications;
       
  2345 	package.iOperation = aOperation;
       
  2346 	package.iNotifyType = (TFsNotification::TFsNotificationType)aNotifyType;
       
  2347 	package.iString = aString;
       
  2348 	package.iFileName = aFilename;
       
  2349 	package.iBufferSize = aBufferSize;
       
  2350 	package.iLineCall = aLineCall;
       
  2351 	
       
  2352 	User::LeaveIfError(package.iBarrier.CreateLocal(0));
       
  2353 	RThread watcher;
       
  2354 	RThread doer;
       
  2355 	RTimer tim;
       
  2356 	User::LeaveIfError(tim.CreateLocal());
       
  2357 	
       
  2358 	TInt r = watcher.Create(_L("TestMultipleNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
       
  2359 	safe_test(test,r,__LINE__,package.iLineCall);
       
  2360 	r = doer.Create(_L("TestMultipleNotificationsDoerThread"),MultipleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
       
  2361 	safe_test(test,r,__LINE__,package.iLineCall);
       
  2362 	test.Next(_L("TestMultipleNotifications - Resume Watcher"));
       
  2363 	watcher.Resume();
       
  2364 	test.Next(_L("TestMultipleNotifications - Wait for Watcher to be ready"));
       
  2365 	package.iBarrier.Wait(); //Wait till Watcher has requested notification
       
  2366 	test.Next(_L("TestMultipleNotifications - Resume Doer"));
       
  2367 	doer.Resume();
       
  2368 		
       
  2369 	test.Next(_L("TestMultipleNotifications - Wait for doer thread death"));
       
  2370 	TRequestStatus status;
       
  2371 	doer.Logon(status);
       
  2372 	User::WaitForRequest(status);
       
  2373 	test.Printf(_L("TestMultipleNotifications - Doer Exit Reason %d\n"),doer.ExitReason());
       
  2374 	safe_test(test,doer.ExitReason(),__LINE__,package.iLineCall);
       
  2375 	
       
  2376 	TRequestStatus timStatus;
       
  2377 	TTimeIntervalMicroSeconds32 timeout;
       
  2378 	if (aFailureExpected && !(package.iOperation == t_notification::EMediaCardInsertion ||
       
  2379 							  package.iOperation == t_notification::EMediaCardRemoval))
       
  2380 		{
       
  2381 		timeout = 1500000; //1.5 seconds, we don't want to wait too long if we expect it to fail
       
  2382 		}
       
  2383 	else
       
  2384 		{
       
  2385 		timeout = 10000000; //10 seconds
       
  2386 		}
       
  2387 	tim.After(timStatus,timeout);
       
  2388 	
       
  2389 	test.Next(_L("TestMultipleNotifications - Wait for watcher thread death or timeout"));
       
  2390 	watcher.Logon(status);
       
  2391 	User::WaitForRequest(status,timStatus);
       
  2392 	if(!(status != KRequestPending || aFailureExpected))
       
  2393 		safe_test(test,KErrGeneral,__LINE__,package.iLineCall);
       
  2394 	
       
  2395 	test.Printf(_L("TestMultipleNotifications - Watcher Exit Reason %d\n"),watcher.ExitReason());
       
  2396 	safe_test(test,watcher.ExitReason(),__LINE__,package.iLineCall);
       
  2397 	
       
  2398 	CLOSE_AND_WAIT(doer);
       
  2399 	
       
  2400 	if(status == KRequestPending)
       
  2401 		{
       
  2402 		watcher.Kill(KErrTimedOut);
       
  2403 		test.Printf(_L("TestMultipleNotifications - Watcher timed out\n"));
       
  2404 		}
       
  2405 	CLOSE_AND_WAIT(watcher);
       
  2406 	
       
  2407 	package.iBarrier.Close();
       
  2408 	fs.Close();
       
  2409 	tim.Close();
       
  2410 	test.Printf(_L("----------------------------------------------------------------------\n"));
       
  2411 	return KErrNone;	
       
  2412 	}
       
  2413 
       
  2414 TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations,
       
  2415 								TInt aMaxNotifications, t_notification::EOperation aOperation,
       
  2416 								TFsNotification::TFsNotificationType aNotifyType, TInt aBufferSize,
       
  2417 								TBool aFailureExpected, TInt aLineCall)
       
  2418 	{
       
  2419 	return TestMultipleNotificationsL(aFilename, aString, aIterations, aMaxNotifications, aOperation,
       
  2420 									 (TUint)aNotifyType, aBufferSize, aFailureExpected, aLineCall);
       
  2421 	}
       
  2422 
       
  2423 TInt TestMultipleNotificationsL(const TDesC& aFilename, TInt aIterations, TInt aMaxNotifications,
       
  2424 								t_notification::EOperation aOperation, TUint aNotifyType, TInt aBufferSize,
       
  2425 								TBool aFailureExpected, TInt aLineCall)
       
  2426 	{
       
  2427 	return TestMultipleNotificationsL(aFilename,_L(""), aIterations, aMaxNotifications, aOperation, aNotifyType,
       
  2428 									  aBufferSize, aFailureExpected, aLineCall);
       
  2429 	}
       
  2430 
       
  2431 
       
  2432 // Watcher for TestAddRemoveNotificationL()
       
  2433 TInt TestAddRemoveNotificationWatcher(TAny* aAny)
       
  2434 	{
       
  2435 	CTrapCleanup* cleanup;
       
  2436 	cleanup = CTrapCleanup::New();
       
  2437 	RThread thread;
       
  2438 	TUint64 threadId = thread.Id().Id();
       
  2439 	
       
  2440 	SThreadPackage pkgDoer = *(SThreadPackage*)aAny;
       
  2441 	RSemaphore& addRemoveBarrier = pkgDoer.iBarrier;
       
  2442 	
       
  2443 	RTest addRemoveWatcherTest(_L("TestAddRemoveNotificationWatcher"));
       
  2444 	addRemoveWatcherTest.Start(_L("TestAddRemoveNotificationWatcher"));
       
  2445 	
       
  2446 	RFs fs;
       
  2447 	fs.Connect();
       
  2448 	
       
  2449 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
       
  2450 	CFsNotify* notify = NULL;
       
  2451 	TRAPD(r,notify = CFsNotify::NewL(fs,100); );
       
  2452 	addRemoveWatcherTest( r == KErrNone);
       
  2453 	TBuf<40> path;
       
  2454 	TBuf<20> filename;
       
  2455 	path.Append(gDriveToTest);
       
  2456 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
       
  2457 	filename.Append(pkgDoer.iFileName);
       
  2458 	
       
  2459 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher - Add Notification for %S\n"),&path);
       
  2460 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
  2461 	addRemoveWatcherTest(r==KErrNone);
       
  2462 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Remove Notifications\n"),threadId);
       
  2463 	r = notify->RemoveNotifications();
       
  2464 	addRemoveWatcherTest(r==KErrNone);
       
  2465 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Request Notifications\n"),threadId);
       
  2466 	TRequestStatus status;
       
  2467 	r = notify->RequestNotifications(status);
       
  2468 	addRemoveWatcherTest(r==KErrNone);
       
  2469 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher status = %d"),status.Int());
       
  2470 	addRemoveBarrier.Signal();
       
  2471 	
       
  2472 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - NextNotification\n"),threadId);
       
  2473 	//We should not be getting any notifications as the notification request has been removed
       
  2474 	const TFsNotification* notification = notify->NextNotification();
       
  2475 	addRemoveWatcherTest(notification == NULL);
       
  2476 	
       
  2477 	delete notify;
       
  2478 	fs.Close();
       
  2479 	addRemoveWatcherTest.End();
       
  2480 	addRemoveWatcherTest.Close();
       
  2481 	delete cleanup;
       
  2482 	return KErrNone;
       
  2483 	}
       
  2484 
       
  2485 
       
  2486 /*
       
  2487  * TestAddRemoveNotificationL - Watcher adds and removes notification request.
       
  2488  *  Any changes by doer thread should not be detected.
       
  2489  */
       
  2490 TInt TestAddRemoveNotificationL()
       
  2491 	{
       
  2492 	test.Next(_L("TestAddRemoveNotification"));
       
  2493 	RFs fs;
       
  2494 	fs.Connect();
       
  2495 
       
  2496 	SThreadPackage package;
       
  2497 	_LIT(KFileName,"noFile.create");
       
  2498 	package.iFileName = KFileName;
       
  2499 
       
  2500 	User::LeaveIfError(package.iBarrier.CreateLocal(0));
       
  2501 	RThread watcher;
       
  2502 	RThread doer;
       
  2503 
       
  2504 	watcher.Create(_L("TestAddRemoveNotification-WatcherThread"),TestAddRemoveNotificationWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
       
  2505 	doer.Create(_L("TestAddRemoveNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
       
  2506 	watcher.Resume();
       
  2507 	
       
  2508 	test.Printf(_L("TestAddRemoveNotification - Wait until Watcher has created CFsNotify\n"));
       
  2509 	package.iBarrier.Wait();	//Wait until Watcher has created CFsNotify
       
  2510 	doer.Resume();
       
  2511 	
       
  2512 	test.Next(_L("TestAddRemoveNotification - Wait for doer thread death"));
       
  2513 	TRequestStatus status;
       
  2514 	doer.Logon(status);
       
  2515 	User::WaitForRequest(status);
       
  2516 	test(doer.ExitReason()==KErrNone);
       
  2517 
       
  2518 	test.Next(_L("TestAddRemoveNotification - Wait for watcher thread death"));
       
  2519 	watcher.Logon(status);
       
  2520 	RTimer timer1;
       
  2521 	TInt r = timer1.CreateLocal();
       
  2522 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  2523 	TRequestStatus timeout;
       
  2524 	TTimeIntervalMicroSeconds32 time = 10000000;    //10 seconds
       
  2525 	timer1.After(timeout,time);
       
  2526 	User::WaitForRequest(timeout,status);
       
  2527 	test(status.Int() != KRequestPending);
       
  2528 	timer1.Cancel();
       
  2529 	timer1.Close();
       
  2530 	test.Printf(_L("Test - Watcher Exit Reason %d\n"),watcher.ExitReason());
       
  2531 	test(watcher.ExitReason()==KErrNone);
       
  2532 
       
  2533 	CLOSE_AND_WAIT(doer);
       
  2534 	CLOSE_AND_WAIT(watcher);
       
  2535 
       
  2536 	package.iBarrier.Close();
       
  2537 	fs.Close();
       
  2538 	return KErrNone;	
       
  2539 	}
       
  2540 
       
  2541 
       
  2542 /*
       
  2543  * Adds and cancels notification request.
       
  2544  * Used in TestCancelNotificationL().
       
  2545  */
       
  2546 TInt TestCancelNotificationWatcher(TAny* aAny)
       
  2547 	{
       
  2548 	CTrapCleanup* cleanup;
       
  2549 	cleanup = CTrapCleanup::New();
       
  2550 	
       
  2551 	RTest cancelNotificationsWatcherTest(_L("TestCancelNotificationWatcher"));
       
  2552 	cancelNotificationsWatcherTest.Start(_L("TestCancelNotificationWatcher"));
       
  2553 	
       
  2554 	RThread thread;
       
  2555 	TUint64 threadId = thread.Id().Id();
       
  2556 	
       
  2557 	SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny;
       
  2558 	RSemaphore& addRemoveBarrier = pkgDoer.iBarrier;
       
  2559 	RSemaphore& addRemoveBarrier2 = pkgDoer.iBarrier2;
       
  2560 	
       
  2561 	RFs fs;
       
  2562 	fs.Connect();
       
  2563 	
       
  2564 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
       
  2565 	CFsNotify* notify = NULL;
       
  2566 	TRAPD(r,notify = CFsNotify::NewL(fs,100); );
       
  2567 	cancelNotificationsWatcherTest(r == KErrNone);
       
  2568 	TBuf<40> path;
       
  2569 	TBuf<20> filename;
       
  2570 	path.Append(gDriveToTest);
       
  2571 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
       
  2572 	filename.Append(pkgDoer.iFileName);
       
  2573 	
       
  2574 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher - Add Notification for %S\n"),&path);
       
  2575 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
  2576 	cancelNotificationsWatcherTest(r==KErrNone);
       
  2577 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Request Notifications\n"),threadId);
       
  2578 	TRequestStatus status;
       
  2579 	r = notify->RequestNotifications(status);
       
  2580 	cancelNotificationsWatcherTest(r==KErrNone);
       
  2581 	
       
  2582 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Cancel Notifications\n"),threadId);
       
  2583 	r = notify->CancelNotifications(status);
       
  2584 	cancelNotificationsWatcherTest(r==KErrNone);
       
  2585 	
       
  2586 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Signal W1 - Start doer\n"),threadId);
       
  2587 	addRemoveBarrier.Signal(); //W1 - Start doer
       
  2588 
       
  2589 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Wait S1 - doer complete\n"),threadId);
       
  2590 	addRemoveBarrier2.Wait();	//S1 - Wait for doer to have created file
       
  2591 	
       
  2592 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - NextNotification\n"),threadId);
       
  2593 	//We should not be getting any notifications as the notification request has been removed
       
  2594 	const TFsNotification* notification = notify->NextNotification();
       
  2595 	cancelNotificationsWatcherTest(notification == NULL);
       
  2596 	
       
  2597 	delete notify;
       
  2598 	fs.Close();
       
  2599 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Complete\n"),threadId);
       
  2600 	cancelNotificationsWatcherTest.End();
       
  2601 	cancelNotificationsWatcherTest.Close();
       
  2602 	delete cleanup;
       
  2603 	return KErrNone;
       
  2604 	}
       
  2605 
       
  2606 
       
  2607 /*
       
  2608  * TestCancelNotificationL - Watcher adds and cancels notification request.
       
  2609  */
       
  2610 TInt TestCancelNotificationL()
       
  2611 	{
       
  2612 	test.Next(_L("TestCancelNotification"));
       
  2613 	RFs fs;
       
  2614 	fs.Connect();
       
  2615 
       
  2616 	SThreadPackageDualSemaphore package;
       
  2617 	_LIT(KFileName,"cancel.create");
       
  2618 	package.iFileName = KFileName;
       
  2619 
       
  2620 	User::LeaveIfError(package.iBarrier.CreateLocal(0));
       
  2621 	User::LeaveIfError(package.iBarrier2.CreateLocal(0));
       
  2622 	RThread watcher;
       
  2623 	RThread doer;
       
  2624 
       
  2625 	TInt r = watcher.Create(_L("TestCancelNotification-WatcherThread"),TestCancelNotificationWatcher,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
       
  2626 	test(r == KErrNone);
       
  2627 	r = doer.Create(_L("TestCancelNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
       
  2628 	test(r == KErrNone);
       
  2629 	test.Printf(_L("TestCancelNotificationL - Watcher.Resume()"));
       
  2630 	watcher.Resume();
       
  2631 	test.Printf(_L("TestCancelNotificationL - Waiting on package.iBarrier.Wait()"));
       
  2632 	package.iBarrier.Wait();	//W1 - Wait until Watcher has created CFsNotify
       
  2633 	test.Printf(_L("TestCancelNotificationL -Doer Resume"));
       
  2634 	TRequestStatus status;
       
  2635 	doer.Logon(status);
       
  2636 	doer.Resume();
       
  2637 	
       
  2638 	test.Next(_L("TestCancelNotification - Wait for doer thread death"));
       
  2639 	User::WaitForRequest(status);
       
  2640 	test(doer.ExitReason()==KErrNone);
       
  2641 	
       
  2642 	package.iBarrier2.Signal(); //S1
       
  2643 
       
  2644 	test.Next(_L("TestCancelNotification - Wait for watcher thread death"));
       
  2645 	watcher.Logon(status);
       
  2646 	
       
  2647 	RTimer tim;
       
  2648 	r = tim.CreateLocal();
       
  2649 	test(r==KErrNone);
       
  2650 	
       
  2651 	TRequestStatus timStatus;
       
  2652 	TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
       
  2653 	tim.After(timStatus,time);
       
  2654 	
       
  2655 	User::WaitForRequest(status,timStatus);
       
  2656 	test(status!=KRequestPending);
       
  2657 	test(watcher.ExitReason()==KErrNone);
       
  2658 
       
  2659 	CLOSE_AND_WAIT(doer);
       
  2660 	CLOSE_AND_WAIT(watcher);
       
  2661 
       
  2662 	package.iBarrier.Close();
       
  2663 	package.iBarrier2.Close();
       
  2664 	fs.Close();
       
  2665 	tim.Close();
       
  2666 	return KErrNone;	
       
  2667 	}
       
  2668 
       
  2669 /*
       
  2670  * Test that if we close the session 
       
  2671  * before closing the subsession (deleting CFsNotify)
       
  2672  * that everything is A-Ok.
       
  2673  */
       
  2674 TInt TestSessionCloseTF(TAny* aTestCase)
       
  2675 	{
       
  2676 	CTrapCleanup* cleanup;
       
  2677 	cleanup = CTrapCleanup::New();
       
  2678 	
       
  2679 	TRAPD(r,
       
  2680 	RFs fs;
       
  2681 	fs.Connect();
       
  2682 	RDebug::Printf("TestSessionClose\n");
       
  2683 	
       
  2684 	SThreadPackage2 package = *(SThreadPackage2*)aTestCase;
       
  2685 	package.iBarrier.Signal();
       
  2686 	
       
  2687 	switch(package.iTestCase)
       
  2688 		{
       
  2689 		case 1:
       
  2690 			{
       
  2691 			RDebug::Printf("TestSessionCloseTF - Case 1 - NewL\n");
       
  2692 			CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize);
       
  2693 			User::LeaveIfNull(notify);
       
  2694 			
       
  2695 			RDebug::Printf("TestSessionCloseTF - Case 1 - Fs.Close\n");
       
  2696 			fs.Close();
       
  2697 			
       
  2698 			TBuf<45> path;
       
  2699 			path.Append((TChar)gDriveToTest);
       
  2700 			path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  2701 			
       
  2702 			TBuf<20> filename;
       
  2703 			filename.Append(_L("session.close"));
       
  2704 			
       
  2705 			CleanupStack::PushL(notify);
       
  2706 			
       
  2707 			RDebug::Printf("TestSessionCloseTF - Case 1 - Add Notification - Panic Expected\n");
       
  2708 			r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
  2709 			User::LeaveIfError(r);
       
  2710 			
       
  2711 			RDebug::Printf("TestSessionCloseTF - Case 1 - After Session Close\n");
       
  2712 			fs.Close();
       
  2713 			CleanupStack::Pop(notify);
       
  2714 			
       
  2715 			RDebug::Printf("TestSessionCloseTF - Case 1 - After Delete Notify\n");
       
  2716 			delete notify;
       
  2717 			break;
       
  2718 			}
       
  2719 		case 2:
       
  2720 			{
       
  2721 			RDebug::Printf("TestSessionCloseTF - Case 2 - NewL\n");
       
  2722 			CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize);
       
  2723 			User::LeaveIfNull(notify);
       
  2724 			
       
  2725 			TBuf<45> path;
       
  2726 			path.Append((TChar)gDriveToTest);
       
  2727 			path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  2728 			TBuf<20> filename;
       
  2729 			filename.Append(_L("session.close"));
       
  2730 			
       
  2731 			RDebug::Printf("TestSessionCloseTF - Case 2 - Add Notification\n");
       
  2732 			r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
       
  2733 			test(r==KErrNone);
       
  2734 			
       
  2735 			RDebug::Printf("TestSessionCloseTF - Case 2 - Fs.Close\n");
       
  2736 			fs.Close();
       
  2737 
       
  2738 			CleanupStack::PushL(notify);
       
  2739 			TRequestStatus status;
       
  2740 			RDebug::Printf("TestSessionCloseTF - Case 2 - Request Notification - Panic Expected\n");
       
  2741 			r = notify->RequestNotifications(status);
       
  2742 			CleanupStack::Pop(notify);
       
  2743 			
       
  2744 			RDebug::Printf("TestSessionCloseTF - Case 2 - After Delete Notify\n");
       
  2745 			delete notify;
       
  2746 			break;
       
  2747 			}
       
  2748 		default:
       
  2749 			{
       
  2750 			break;
       
  2751 			}
       
  2752 		}
       
  2753 	);
       
  2754 	delete cleanup;
       
  2755 	return r;
       
  2756 	}
       
  2757 
       
  2758 /*
       
  2759  * Test that if we close the session
       
  2760  * before closing the subsession (deleting CFsNotify)
       
  2761  * that everything is A-Ok.
       
  2762  */
       
  2763 void TestSessionClose(TInt aTestCase)
       
  2764 	{
       
  2765 	RSemaphore sem;
       
  2766 	User::LeaveIfError(sem.CreateLocal(0));
       
  2767 	
       
  2768 	SThreadPackage2 package;
       
  2769 	package.iTestCase = aTestCase;
       
  2770 	package.iBarrier = sem;
       
  2771 	
       
  2772 	RThread thread;
       
  2773 	thread.Create(_L("TestSessionClose"),TestSessionCloseTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
       
  2774 	
       
  2775 	thread.Resume();
       
  2776 	sem.Wait();
       
  2777 	
       
  2778 	TRequestStatus status;
       
  2779 	thread.Logon(status);
       
  2780 	User::WaitForRequest(status);
       
  2781 	test.Printf(_L("Kern-Exec 0 is EXPECTED\n"));
       
  2782 	TInt err = thread.ExitReason();
       
  2783 	test(err == KErrNone);
       
  2784 	TExitType et = thread.ExitType();
       
  2785 	test(et == EExitPanic);
       
  2786 	CLOSE_AND_WAIT(thread);
       
  2787 	sem.Close();
       
  2788 	}
       
  2789 
       
  2790 const TInt KNotificationOverflowIterationLimit = 7;
       
  2791 
       
  2792 /*
       
  2793  * Does stuff for TestOverflowL
       
  2794  * Synchronises such that watchers have seen 1 change.
       
  2795  * Then fills their buffers up to KNotificationOverflowIterationLimit.
       
  2796  * 
       
  2797  */
       
  2798 TInt TestOverflowDoerTF(TAny* aAny)
       
  2799 	{
       
  2800 	RFs fs;
       
  2801 	fs.Connect();
       
  2802 	
       
  2803 	SThreadPackage& package = *(SThreadPackage*) aAny; 
       
  2804 	
       
  2805 	TBuf<45> path;
       
  2806 	path.Append((TChar)gDriveToTest);
       
  2807 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  2808 	path.Append(package.iFileName);
       
  2809 	
       
  2810 	fs.MkDirAll(path);
       
  2811 	
       
  2812 	RFile file;
       
  2813 	TInt r = file.Replace(fs,path,EFileWrite);
       
  2814 	User::LeaveIfError(r);
       
  2815 	
       
  2816 	//Perform first set size.
       
  2817 	r = file.SetSize(1);
       
  2818 	User::LeaveIfError(r);
       
  2819 	
       
  2820 	//Wait until both watchers have received this change.
       
  2821 	package.iBarrier.Wait();
       
  2822 	
       
  2823 	for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++)
       
  2824 		{
       
  2825 		file.SetSize(i);
       
  2826 		}
       
  2827 	
       
  2828 	file.Close();
       
  2829 	fs.Close();	
       
  2830 	return KErrNone;
       
  2831 	}
       
  2832 
       
  2833 /*
       
  2834  * Thread function used as part of TestOverflowL
       
  2835  * Counts the number of notifications and ensures it the correct number before overflow is received#
       
  2836  */
       
  2837 TInt TestOverflowWatcher1TF(TAny* aAny)
       
  2838 	{
       
  2839 	CTrapCleanup* cleanup;
       
  2840 	cleanup = CTrapCleanup::New();
       
  2841 	
       
  2842 	RTest overflowTest(_L("TestOverflowWatcher1TF"));
       
  2843 	overflowTest.Start(_L("TestOverflowWatcher1TF"));
       
  2844 	
       
  2845 	SThreadPackage& package = *(SThreadPackage*) aAny; 
       
  2846 	RFs fs;
       
  2847 	fs.Connect();
       
  2848 	TBuf<45> path;
       
  2849 	TBuf<20> filename;
       
  2850 	path.Append((TChar)gDriveToTest);
       
  2851 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  2852 	filename.Append(package.iFileName);
       
  2853 	
       
  2854 	TRequestStatus status;
       
  2855 	CFsNotify* notify = NULL;
       
  2856 	
       
  2857 	//This notification's size is 80.
       
  2858 	//80*7 = 560.
       
  2859 	// -4 means we should get 6 notifications
       
  2860 	//Except the first one will still be in the buffer
       
  2861 	// (as we've not called RequestNotification yet) so we'll only actually get 5.
       
  2862 	TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4));
       
  2863 	test(r == KErrNone);
       
  2864 	User::LeaveIfNull(notify);
       
  2865 	notify->AddNotification(TFsNotification::EFileChange,path,filename);
       
  2866 	notify->RequestNotifications(status);
       
  2867 	
       
  2868 	//Signal that we are ready for doer to start (W1)
       
  2869 	package.iBarrier.Signal();
       
  2870 	
       
  2871 	//We wait for the 1 notification (doer only does 1 at first)
       
  2872 	User::WaitForRequest(status);
       
  2873 	
       
  2874 	overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
       
  2875 	const TFsNotification *notification = notify->NextNotification();
       
  2876 	
       
  2877 	TFsNotification::TFsNotificationType type = notification->NotificationType();
       
  2878 	overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
       
  2879 	
       
  2880 	//Signal the test thread (W2)
       
  2881 	package.iBarrier.Signal();
       
  2882 	//Wait for Signal to continue (W3);
       
  2883 	package.iBarrier.Wait();
       
  2884 	
       
  2885 	notify->RequestNotifications(status);
       
  2886 	User::WaitForRequest(status);
       
  2887 	
       
  2888 	TInt count = 0;
       
  2889 	overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
       
  2890 	notification = notify->NextNotification();
       
  2891 	while(notification != NULL)
       
  2892 		{
       
  2893 		
       
  2894 		type = notification->NotificationType();
       
  2895 		overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
       
  2896 		if(type & TFsNotification::EOverflow)
       
  2897 			{
       
  2898 			delete notify;
       
  2899 			fs.Close();
       
  2900 			overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
       
  2901 			overflowTest.End();
       
  2902 			overflowTest.Close();
       
  2903 			return count;
       
  2904 			}
       
  2905 		
       
  2906 		notification = notify->NextNotification();
       
  2907 		count++;
       
  2908 		}
       
  2909 	overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
       
  2910 	
       
  2911 	overflowTest.End();
       
  2912 	overflowTest.Close();
       
  2913 	delete notify;
       
  2914 	delete cleanup;
       
  2915 	fs.Close();
       
  2916 	return -1;
       
  2917 	}
       
  2918 
       
  2919 
       
  2920 /*
       
  2921  * Overflow test
       
  2922  * As some of the tests above assume sucess if they receive an overflow 
       
  2923  * we need to ensure that overflow works properly!
       
  2924  */
       
  2925 TInt TestOverflowL()
       
  2926 	{
       
  2927 	/*
       
  2928 	 * The scheme used is as follows:
       
  2929 	 * 1 Doer thread which is setting the size of a file, over and over.
       
  2930 	 * 1 watcher thread.
       
  2931 	 * 
       
  2932 	 * The doer thread does 1 operation then waits on a signal.
       
  2933 	 * The watcher thread requests notification and receives 1 notification.
       
  2934 	 * It then signals the Doer thread.
       
  2935 	 * 
       
  2936 	 * The doer thread continues doing setsize until the number of notifications
       
  2937 	 * should have overflowed.
       
  2938 	 * 
       
  2939 	 * The watcher Waits for a signal from doer (that all of the notifications have been sent).
       
  2940 	 * The watcher's last notification should be an overflow
       
  2941 	 */
       
  2942 	test.Next(_L("TestOverflow"));
       
  2943 	RFs fs;
       
  2944 	TInt r = fs.Connect();
       
  2945 	test(r == KErrNone);
       
  2946 	_LIT(KFileName,"over.flow");
       
  2947 	SThreadPackage doerPkg;
       
  2948 	doerPkg.iFileName = KFileName;
       
  2949 	
       
  2950 	SThreadPackage watcher1Pkg;
       
  2951 	watcher1Pkg.iFileName = KFileName;
       
  2952 		
       
  2953 	User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0));
       
  2954 	User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0));
       
  2955 	RThread watcher1;
       
  2956 	RThread doer;
       
  2957 	watcher1.Create(_L("TestOverflowWatcher1Thread"),TestOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
       
  2958 	doer.Create(_L("TestOverflowDoerThread"),TestOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
       
  2959 	watcher1.Resume();
       
  2960 
       
  2961 	//Wait until Request has been requested. (W1)
       
  2962 	watcher1Pkg.iBarrier.Wait();
       
  2963 	
       
  2964 	doer.Resume();
       
  2965 	
       
  2966 	//Wait till watcher has received first notification (W2)
       
  2967 	watcher1Pkg.iBarrier.Wait(); 
       
  2968 
       
  2969 	//Signal the doer that it is free to continue
       
  2970 	//doing the rest of the operations
       
  2971 	doerPkg.iBarrier.Signal();
       
  2972 	
       
  2973 	test.Next(_L("TestOverflow - Wait for doer thread death"));
       
  2974 	TRequestStatus status;
       
  2975 	doer.Logon(status);
       
  2976 	User::WaitForRequest(status);
       
  2977 	test(doer.ExitReason()==KErrNone);
       
  2978 	CLOSE_AND_WAIT(doer);
       
  2979 	
       
  2980 	//Wait until doer has finished doing notifications
       
  2981 	//thus the watcher should receive an overflow
       
  2982 	// (W3)
       
  2983 	watcher1Pkg.iBarrier.Signal();
       
  2984 	
       
  2985 	RTimer tim;
       
  2986 	r = tim.CreateLocal();
       
  2987 	test(r==KErrNone);
       
  2988 	TRequestStatus timStatus;
       
  2989 	
       
  2990 	test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
       
  2991 	TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds
       
  2992 	tim.After(timStatus,interval);
       
  2993 	watcher1.Logon(status);
       
  2994 	User::WaitForRequest(status,timStatus);
       
  2995 	test(status != KRequestPending);
       
  2996 	/*
       
  2997 	 * The number of notifications returned here should be 5.
       
  2998 	 * This is because :
       
  2999 	 * 
       
  3000 	 * The first notification means that the buffer has lost 80 (the size of this
       
  3001 	 * particular notification). Even though the client has read it becase they've not called
       
  3002 	 * RequestNotification the server doesn't know that yet so that's why it's 5 not 6.
       
  3003 	 * 
       
  3004 	 * That leaves 556 - 80. Which means only 5 notifications will fit.
       
  3005 	 */
       
  3006 	TInt count = watcher1.ExitReason();
       
  3007 	test(count==5);
       
  3008 	
       
  3009 	CLOSE_AND_WAIT(watcher1);
       
  3010 	watcher1Pkg.iBarrier.Close();
       
  3011 	doerPkg.iBarrier.Close();
       
  3012 	fs.Close();
       
  3013 	tim.Close();
       
  3014 	return KErrNone;
       
  3015 	}
       
  3016 
       
  3017 /*
       
  3018  * Does stuff for TestPostOverflowL
       
  3019  * Synchronises such that watchers have seen 1 change.
       
  3020  * Then fills their buffers up to KNotificationOverflowIterationLimit.
       
  3021  * Then continues to request changes and akes sure that it gets 3 non-overflow notifications
       
  3022  * For DEF140387.
       
  3023  */
       
  3024 TInt TestPostOverflowDoerTF(TAny* aAny)
       
  3025     {
       
  3026     RFs fs;
       
  3027     fs.Connect();
       
  3028     
       
  3029     SThreadPackage& package = *(SThreadPackage*) aAny; 
       
  3030     
       
  3031     TBuf<45> path;
       
  3032     path.Append((TChar)gDriveToTest);
       
  3033     path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  3034     path.Append(package.iFileName);
       
  3035     
       
  3036     fs.MkDirAll(path);
       
  3037     
       
  3038     RFile file;
       
  3039     TInt r = file.Replace(fs,path,EFileWrite);
       
  3040     User::LeaveIfError(r);
       
  3041     
       
  3042     //Perform first set size.
       
  3043     r = file.SetSize(1);
       
  3044     User::LeaveIfError(r);
       
  3045     
       
  3046     //Wait until both watchers have received this change.
       
  3047     //D-W-1
       
  3048     package.iBarrier.Wait();
       
  3049     
       
  3050     for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++)
       
  3051         {
       
  3052         file.SetSize(i);
       
  3053         }
       
  3054     
       
  3055     file.Close();
       
  3056     fs.Close(); 
       
  3057     return KErrNone;
       
  3058     }
       
  3059 
       
  3060 TInt HandlePostOverflow(SThreadPackage& aPackage, CFsNotify* aNotify)
       
  3061     {
       
  3062     TRequestStatus status;
       
  3063     TInt r = aNotify->RequestNotifications(status);
       
  3064     test(r == KErrNone);
       
  3065     //Signal that overflow has been found (W4)
       
  3066     aPackage.iBarrier.Signal();
       
  3067     
       
  3068     User::WaitForRequest(status);
       
  3069     
       
  3070     const TFsNotification* notification = NULL;
       
  3071     TInt count = 1;
       
  3072     
       
  3073     notification = aNotify->NextNotification();
       
  3074     test(notification != NULL);
       
  3075     
       
  3076     //3 set sizes will be done (Sx)
       
  3077     aPackage.iBarrier.Wait();
       
  3078     
       
  3079     while(count < 3)
       
  3080         {
       
  3081         TUint type = notification->NotificationType();
       
  3082         if(type & TFsNotification::EOverflow)
       
  3083             {
       
  3084             return KErrOverflow;
       
  3085             }
       
  3086         notification = aNotify->NextNotification();
       
  3087         if(notification == NULL)
       
  3088             {
       
  3089             r = aNotify->RequestNotifications(status);
       
  3090             test(r == KErrNone);
       
  3091             User::WaitForRequest(status);
       
  3092             notification = aNotify->NextNotification();
       
  3093             }
       
  3094         test(notification != NULL);
       
  3095         count++;
       
  3096         }
       
  3097     return count;
       
  3098     }
       
  3099 
       
  3100 
       
  3101 /*
       
  3102  * Thread function used as part of TestOverflowL
       
  3103  * Counts the number of notifications and ensures it the correct number before overflow is received#
       
  3104  */
       
  3105 TInt TestPostOverflowWatcher1TF(TAny* aAny)
       
  3106     {
       
  3107     CTrapCleanup* cleanup;
       
  3108     cleanup = CTrapCleanup::New();
       
  3109     
       
  3110     RTest overflowTest(_L("TestOverflowWatcher1TF"));
       
  3111     overflowTest.Start(_L("TestOverflowWatcher1TF"));
       
  3112     
       
  3113     SThreadPackage& package = *(SThreadPackage*) aAny; 
       
  3114     RFs fs;
       
  3115     fs.Connect();
       
  3116     TBuf<45> path;
       
  3117     TBuf<20> filename;
       
  3118     path.Append((TChar)gDriveToTest);
       
  3119     path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  3120     filename.Append(package.iFileName);
       
  3121     
       
  3122     TRequestStatus status;
       
  3123     CFsNotify* notify = NULL;
       
  3124     
       
  3125     //This notification's size is 80.
       
  3126     //80*7 = 560.
       
  3127     // -4 means we should get 6 notifications
       
  3128     //Except the first one will still be in the buffer
       
  3129     // (as we've not called RequestNotification yet) so we'll only actually get 5.
       
  3130     TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4));
       
  3131     test(r == KErrNone);
       
  3132     User::LeaveIfNull(notify);
       
  3133     notify->AddNotification(TFsNotification::EFileChange,path,filename);
       
  3134     notify->RequestNotifications(status);
       
  3135     
       
  3136     //Signal that we are ready for doer to start (W1)
       
  3137     package.iBarrier.Signal();
       
  3138     
       
  3139     //We wait for the 1 notification (doer only does 1 at first)
       
  3140     User::WaitForRequest(status);
       
  3141     
       
  3142     overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
       
  3143     const TFsNotification *notification = notify->NextNotification();
       
  3144     
       
  3145     TFsNotification::TFsNotificationType type = notification->NotificationType();
       
  3146     overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
       
  3147     
       
  3148     //Signal the test thread (W2)
       
  3149     package.iBarrier.Signal();
       
  3150     //Wait for Signal to continue (W3);
       
  3151     package.iBarrier.Wait();
       
  3152     
       
  3153     notify->RequestNotifications(status);
       
  3154     User::WaitForRequest(status);
       
  3155     
       
  3156     TInt handlePostOverflow = 0;
       
  3157     TInt count = 0;
       
  3158     overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
       
  3159     notification = notify->NextNotification();
       
  3160     while(notification != NULL)
       
  3161         {
       
  3162         
       
  3163         type = notification->NotificationType();
       
  3164         overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
       
  3165         if(type & TFsNotification::EOverflow)
       
  3166             {
       
  3167             overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
       
  3168             if(handlePostOverflow)
       
  3169                 {
       
  3170                 count = HandlePostOverflow(package,notify);
       
  3171                 }
       
  3172             delete notify;
       
  3173             fs.Close();
       
  3174             overflowTest.End();
       
  3175             overflowTest.Close();
       
  3176             return count;
       
  3177             }
       
  3178         notification = notify->NextNotification();
       
  3179         count++;
       
  3180         
       
  3181         if(count==5)
       
  3182             handlePostOverflow = 1;
       
  3183         }
       
  3184     overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
       
  3185     
       
  3186     overflowTest.End();
       
  3187     overflowTest.Close();
       
  3188     delete notify;
       
  3189     delete cleanup;
       
  3190     fs.Close();
       
  3191     return -1;
       
  3192     }
       
  3193 
       
  3194 
       
  3195 TInt TestPostOverflowNotifications()
       
  3196     {
       
  3197     test.Next(_L("TestPostOverflowNotifications"));
       
  3198     RFs fs;
       
  3199     TInt r = fs.Connect();
       
  3200     test(r == KErrNone);
       
  3201     _LIT(KFileName,"post.over");
       
  3202     SThreadPackage doerPkg;
       
  3203     doerPkg.iFileName = KFileName;
       
  3204     
       
  3205     SThreadPackage watcher1Pkg;
       
  3206     watcher1Pkg.iFileName = KFileName;
       
  3207         
       
  3208     User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0));
       
  3209     User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0));
       
  3210     RThread watcher1;
       
  3211     RThread doer;
       
  3212     watcher1.Create(_L("TestPostOverflowWatcher1Thread"),TestPostOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
       
  3213     doer.Create(_L("TestPostOverflowDoerThread"),TestPostOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
       
  3214     watcher1.Resume();
       
  3215 
       
  3216     //Wait until Request has been requested. (W1)
       
  3217     watcher1Pkg.iBarrier.Wait();
       
  3218     
       
  3219     doer.Resume();
       
  3220     
       
  3221     //Wait till watcher has received first notification (W2)
       
  3222     watcher1Pkg.iBarrier.Wait(); 
       
  3223 
       
  3224     //Signal the doer that it is free to continue
       
  3225     //doing the rest of the operations (D-W-1)
       
  3226     doerPkg.iBarrier.Signal();
       
  3227     
       
  3228     test.Next(_L("TestOverflow - Wait for doer thread death"));
       
  3229     TRequestStatus status;
       
  3230     doer.Logon(status);
       
  3231     User::WaitForRequest(status);
       
  3232     test(doer.ExitReason()==KErrNone);
       
  3233     CLOSE_AND_WAIT(doer);
       
  3234     
       
  3235     //Wait until doer has finished doing notifications
       
  3236     //thus the watcher should receive an overflow
       
  3237     // (W3)
       
  3238     watcher1Pkg.iBarrier.Signal();
       
  3239     
       
  3240     
       
  3241     //wait for the watcher to have processed the first overflow
       
  3242     //and to have requested notification.
       
  3243     //Then we will perform some actions here
       
  3244     // The watcher will wait on the semaphore until we are doing
       
  3245     // doing all the operations we want to do
       
  3246     // then it should process next notification
       
  3247     watcher1Pkg.iBarrier.Wait(); //W4
       
  3248 
       
  3249     TBuf<45> path;
       
  3250     path.Append((TChar)gDriveToTest);
       
  3251     path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  3252     path.Append(watcher1Pkg.iFileName);
       
  3253     RFile file;
       
  3254     r = file.Open(fs,path,EFileWrite);
       
  3255     test(r==KErrNone);
       
  3256     
       
  3257     r = file.SetSize(1);
       
  3258     test(r==KErrNone);
       
  3259     r = file.SetSize(2);
       
  3260     test(r==KErrNone);
       
  3261     r = file.SetSize(3);
       
  3262     test(r==KErrNone);
       
  3263     file.Close();
       
  3264     
       
  3265     watcher1Pkg.iBarrier.Signal(); // Signal post operations complete (Sx)
       
  3266     
       
  3267     RTimer tim;
       
  3268     r = tim.CreateLocal();
       
  3269     test(r==KErrNone);
       
  3270     TRequestStatus timStatus;
       
  3271     
       
  3272     test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
       
  3273     TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds
       
  3274     tim.After(timStatus,interval);
       
  3275     watcher1.Logon(status);
       
  3276     User::WaitForRequest(status,timStatus);
       
  3277     test(status != KRequestPending);
       
  3278     /*
       
  3279      * The number of notifications returned here should be 3.
       
  3280      * This is because :
       
  3281      * 
       
  3282      * The first notification means that the buffer has lost 80 (the size of this
       
  3283      * particular notification). Even though the client has read it becase they've not called
       
  3284      * RequestNotification the server doesn't know that yet so that's why it's 5 not 6.
       
  3285      * 
       
  3286      * That leaves 556 - 80. Which means only 5 notifications will fit.
       
  3287      * 
       
  3288      * Then overflow occurs.
       
  3289      * 
       
  3290      * Then count is reset and 3 more operations are performed.
       
  3291      */
       
  3292     TInt count = watcher1.ExitReason();
       
  3293     test(count==3);
       
  3294     
       
  3295     CLOSE_AND_WAIT(watcher1);
       
  3296     watcher1Pkg.iBarrier.Close();
       
  3297     doerPkg.iBarrier.Close();
       
  3298     fs.Close();
       
  3299     tim.Close();
       
  3300     return KErrNone;    
       
  3301     }
       
  3302 
       
  3303 /*
       
  3304  * Call AddNotification with a file without a path nor drive
       
  3305  */
       
  3306 void TestNonDriveFilters()
       
  3307 	{
       
  3308 	test.Next(_L("TestNonDriveFilters"));
       
  3309 	RFs fs;
       
  3310 	TInt r = fs.Connect();
       
  3311 	test(r==KErrNone);
       
  3312 	
       
  3313 	TDriveList drives;
       
  3314 	r = fs.DriveList(drives);
       
  3315 	test(r==KErrNone);
       
  3316 	
       
  3317 	CFsNotify* notify = NULL;
       
  3318 	TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
       
  3319 	
       
  3320 	TBuf<20> testfile;
       
  3321 	testfile.Append(_L("test.file"));
       
  3322 	
       
  3323 	r = notify->AddNotification((TUint)TFsNotification::ECreate,_L(""),testfile);
       
  3324 	test(r==KErrNone);
       
  3325 	
       
  3326 	TRequestStatus status;
       
  3327 	r = notify->RequestNotifications(status);
       
  3328 	test(r==KErrNone);
       
  3329 	
       
  3330 	TBuf<40> path;
       
  3331 	path.Append((TChar)gDriveToTest);
       
  3332 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  3333 	
       
  3334 	TBuf<40> fullname;
       
  3335 	fullname.Append(path);
       
  3336 	fullname.Append(testfile);
       
  3337 	
       
  3338 	RFile file;
       
  3339 	r = fs.MkDirAll(path);
       
  3340 	test(r==KErrNone || r==KErrAlreadyExists);
       
  3341 	r = file.Replace(fs,fullname,EFileWrite);
       
  3342 	test(r==KErrNone);
       
  3343 	file.Close();
       
  3344 	
       
  3345 	fs.Delete(fullname);
       
  3346 	
       
  3347 	TChar testDrive = (TChar)gDriveToTest;
       
  3348 	testDrive.UpperCase();
       
  3349 
       
  3350 	//Also create the file on another drive;
       
  3351 	for(TInt i = 0; i < KMaxDrives; i++)
       
  3352 		{
       
  3353 		TChar drive = drives[i];
       
  3354 		if(drive == testDrive)
       
  3355 			continue;
       
  3356 		
       
  3357 		if(drive)
       
  3358 			{
       
  3359 			TText16 drive16 = (TText16)(i+(TChar)'A');
       
  3360 			fullname.operator [](0) = drive16;
       
  3361 			break;
       
  3362 			}
       
  3363 		}
       
  3364 	
       
  3365 	r = fs.MkDirAll(fullname);
       
  3366 	test(r==KErrNone || r==KErrAlreadyExists);
       
  3367 	r = file.Replace(fs,fullname,EFileWrite);
       
  3368 	test(r==KErrNone);
       
  3369 	file.Close();
       
  3370 	
       
  3371 	RTimer timer1;
       
  3372 	r = timer1.CreateLocal();
       
  3373 	test(r == KErrNone);
       
  3374 	TRequestStatus timeout;
       
  3375 	TTimeIntervalMicroSeconds32 time = 10000000;    //10 seconds
       
  3376 	timer1.After(timeout,time);
       
  3377 	User::WaitForRequest(timeout,status);
       
  3378 	test(status.Int() != KRequestPending);
       
  3379 	timer1.Cancel();
       
  3380 	timer1.Close();
       
  3381 
       
  3382 	const TFsNotification* notification = notify->NextNotification();
       
  3383 	test(notification != NULL);
       
  3384 	TPtrC _path;
       
  3385 	r = notification->Path(_path);
       
  3386 	test(r==KErrNone);
       
  3387 	TChar driveletter = _path[0];
       
  3388 	driveletter.UpperCase();
       
  3389 	test(driveletter ==  (TChar)gDriveToTest);
       
  3390 	
       
  3391 	if(notification = notify->NextNotification(), notification==NULL)
       
  3392 		{
       
  3393 		TRequestStatus status2;
       
  3394 		r = notify->RequestNotifications(status2);
       
  3395 		test(r==KErrNone);
       
  3396 		
       
  3397 		RTimer timer2;
       
  3398 		r = timer2.CreateLocal();
       
  3399 		test(r == KErrNone);
       
  3400 		TRequestStatus timeout2;
       
  3401 		TTimeIntervalMicroSeconds32 time2 = 10000000;    //10 seconds
       
  3402 		timer2.After(timeout2,time2);
       
  3403 		User::WaitForRequest(timeout2,status2);
       
  3404 		test(status2.Int() != KRequestPending);
       
  3405 		timer2.Cancel();
       
  3406 		timer2.Close();
       
  3407 		
       
  3408 		notification = notify->NextNotification();
       
  3409 		}
       
  3410 	test(notification != NULL);
       
  3411 	r = notification->Path(_path);
       
  3412 	test(r==KErrNone);
       
  3413 	driveletter = _path[0];
       
  3414 	driveletter.UpperCase();
       
  3415 	test(driveletter == (TChar)'C');	
       
  3416 	
       
  3417 	delete notify;
       
  3418 	fs.Close();	
       
  3419 	}
       
  3420 
       
  3421 // Negative testing for directory without *
       
  3422 // We receive no notifications for files changed under the directory
       
  3423 void NegativeTestDirStar()
       
  3424 	{
       
  3425 	RFs fs;
       
  3426 	TInt r = fs.Connect();
       
  3427 	test(r==KErrNone);
       
  3428 	
       
  3429 	CFsNotify* notify = NULL;
       
  3430 	TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
       
  3431 	
       
  3432 	TBuf<40> path;
       
  3433 	path.Append((TChar)gDriveToTest);
       
  3434 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  3435 	r = fs.MkDirAll(path);
       
  3436 	test(r == KErrNone || r == KErrAlreadyExists);
       
  3437 	
       
  3438 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path,_L(""));
       
  3439 	test(r==KErrNone);
       
  3440 	
       
  3441 	TRequestStatus status;
       
  3442 	r = notify->RequestNotifications(status);
       
  3443 	test(r==KErrNone);
       
  3444 	
       
  3445 	TBuf<40> filename;
       
  3446 	filename.Append((TChar)gDriveToTest);
       
  3447 	filename.Append(_L(":\\F32-TST\\T_NOTIFIER\\dir.star"));
       
  3448 	
       
  3449 	RFile file;
       
  3450 	r = file.Replace(fs,filename,EFileWrite);
       
  3451 	test(r==KErrNone);
       
  3452 	file.Close();
       
  3453 	
       
  3454 	RTimer timer1;
       
  3455 	r = timer1.CreateLocal();
       
  3456 	test(r == KErrNone);
       
  3457 	TRequestStatus timeout;
       
  3458 	TTimeIntervalMicroSeconds32 time = 2000000;    //2 seconds
       
  3459 	timer1.After(timeout,time);
       
  3460 	User::WaitForRequest(timeout,status);
       
  3461 	test(status.Int() == KRequestPending);
       
  3462 	timer1.Cancel();
       
  3463 	timer1.Close();
       
  3464 
       
  3465 	const TFsNotification* notification = notify->NextNotification();
       
  3466 	test(notification == NULL);
       
  3467 	
       
  3468 	delete notify;
       
  3469 	fs.Close();	
       
  3470 	}
       
  3471 
       
  3472 /*
       
  3473  * Negative Testing
       
  3474  */
       
  3475 void NegativeTests()
       
  3476 	{
       
  3477 	test.Next(_L("Negative Tests"));
       
  3478 	//1
       
  3479 	test.Printf(_L("NegativeTests() A\n"));
       
  3480 	RFs fs;
       
  3481 	CFsNotify* notify = NULL;
       
  3482 	TInt r = fs.Connect();
       
  3483 	test(r == KErrNone);
       
  3484 	TRAP(r,notify = CFsNotify::NewL(fs,0));
       
  3485 	test(notify != NULL);
       
  3486 	delete notify;
       
  3487 	notify = NULL;
       
  3488 	
       
  3489 	//2
       
  3490 	test.Printf(_L("NegativeTests() B\n"));
       
  3491 	TRAP(r,notify = CFsNotify::NewL(fs,-1));
       
  3492 	test(notify != NULL);
       
  3493 	delete notify;
       
  3494 	notify = NULL;
       
  3495 
       
  3496 	test.Printf(_L("NegativeTests() C\n"));
       
  3497 	TRAP(r,notify = CFsNotify::NewL(fs,KMaxTInt));
       
  3498 	test(r==KErrArgument);
       
  3499 	test(notify==NULL);
       
  3500 	
       
  3501 	//3
       
  3502 	test.Printf(_L("NegativeTests() D\n"));
       
  3503 	TBuf<40> path;
       
  3504 	path.Append((TChar)gDriveToTest);
       
  3505 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
       
  3506 	TBuf<20> filename;
       
  3507 	filename.Append(_L("file.txt"));
       
  3508 	TRAP(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize));
       
  3509 	test(r==KErrNone);
       
  3510 	test(notify!=NULL);
       
  3511 	r = notify->AddNotification(0,path,filename);
       
  3512 	test(r == KErrArgument);
       
  3513 	
       
  3514 	test.Printf(_L("NegativeTests() E\n"));
       
  3515 	r = notify->AddNotification((TUint)0x8000,path,filename); //invalid value
       
  3516 	test(r == KErrArgument);
       
  3517 	
       
  3518 	test.Printf(_L("NegativeTests() F\n"));
       
  3519 	TBuf<40> invalidPath;
       
  3520 	invalidPath.Append(_L("1:\\*"));
       
  3521 	r = notify->AddNotification((TUint)TFsNotification::ECreate,invalidPath,filename);
       
  3522 	test(r == KErrNotFound || r == KErrPathNotFound);
       
  3523 	
       
  3524 	//4
       
  3525 	test.Printf(_L("NegativeTests() G\n"));
       
  3526 	TRequestStatus wrongStatus;
       
  3527 	wrongStatus = KRequestPending;
       
  3528 	r = notify->RequestNotifications(wrongStatus);
       
  3529 	test(r == KErrInUse);
       
  3530 	
       
  3531 	test.Printf(_L("NegativeTests() H\n"));
       
  3532 	TRequestStatus status;
       
  3533 	r = notify->RequestNotifications(status);
       
  3534 	test(r==KErrNone);
       
  3535 	r = notify->CancelNotifications(wrongStatus);
       
  3536 	test(r == KErrInUse);
       
  3537 	
       
  3538 	delete notify;
       
  3539 	notify = NULL;
       
  3540 	fs.Close();
       
  3541 	}
       
  3542 
       
  3543 
       
  3544 /*
       
  3545  * RPlugin devired.
       
  3546  * Doesn't actually do anything special.
       
  3547  * Can probably be deleted.
       
  3548  */
       
  3549 class MyRPlugin : public RPlugin
       
  3550 	{
       
  3551 public:
       
  3552 	void DoRequest(TInt aReqNo,TRequestStatus& aStatus) const;
       
  3553 	void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const;
       
  3554 	void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const;
       
  3555 	TInt DoControl(TInt aFunction) const;
       
  3556 	TInt DoControl(TInt aFunction,TDes8& a1) const;
       
  3557 	TInt DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const;
       
  3558 	void DoCancel(TUint aReqMask) const;
       
  3559 	};
       
  3560 
       
  3561 void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus) const
       
  3562 	{
       
  3563 	RPlugin::DoRequest(aReqNo,aStatus);
       
  3564 	}
       
  3565 void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const
       
  3566 	{
       
  3567 	RPlugin::DoRequest(aReqNo,aStatus,a1);
       
  3568 	}
       
  3569 void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const
       
  3570 	{
       
  3571 	RPlugin::DoRequest(aReqNo,aStatus,a1,a2);
       
  3572 	}
       
  3573 TInt MyRPlugin::DoControl(TInt aFunction) const
       
  3574 	{
       
  3575 	return RPlugin::DoControl(aFunction);
       
  3576 	}
       
  3577 TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1) const
       
  3578 	{
       
  3579 	return RPlugin::DoControl(aFunction,a1);
       
  3580 	}
       
  3581 TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const
       
  3582 	{
       
  3583 	return RPlugin::DoControl(aFunction,a1,a2);
       
  3584 	}
       
  3585 void MyRPlugin::DoCancel(TUint aReqMask) const
       
  3586 	{
       
  3587 	RPlugin::DoCancel(aReqMask);
       
  3588 	}
       
  3589 
       
  3590 /*
       
  3591  * This tests that when file server plugins perform operations that
       
  3592  * the framework doesn't notify about them
       
  3593  */
       
  3594 TInt TestNotificationsWithFServPlugins()
       
  3595 	{
       
  3596 	TInt r = TheFs.AddPlugin(KNotifyPluginFileName);
       
  3597 	test(r==KErrNone || r==KErrAlreadyExists);
       
  3598 	r = TheFs.MountPlugin(KNotifyPluginName,(TUint)gDriveToTest.GetUpperCase() - 65);
       
  3599 	if (r == KErrNotSupported)
       
  3600 		{
       
  3601 		test.Printf(_L("Plugins are not supported on pagable drives.\nSkipping test.\n"));
       
  3602 		safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3603 		}
       
  3604 	
       
  3605 	MyRPlugin rplugin;
       
  3606 	TPckgBuf<TChar> drivePckg(gDriveToTest);
       
  3607 	
       
  3608 	test.Next(_L("Open RPlugin connection for NotifyPlugin"));
       
  3609 	r = rplugin.Open(TheFs,KNotifyPos);
       
  3610 	safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
       
  3611 
       
  3612 	test.Next(_L("Send drive letter to test down to plugin"));
       
  3613 	r = rplugin.DoControl(KPluginSetDrive,drivePckg);
       
  3614 	safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
       
  3615 	rplugin.Close();
       
  3616 	
       
  3617 	r = SimpleCreateTestL();
       
  3618 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3619 	
       
  3620 	DismountPlugin();
       
  3621 	return KErrNone;
       
  3622 	}
       
  3623 
       
  3624 /*
       
  3625  * This test is testing the use cases
       
  3626  * and for negative testing of SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
       
  3627  * 
       
  3628  * Performance tests can be found in test t_notify_perf
       
  3629  */
       
  3630 void CallTestsL()
       
  3631 	{
       
  3632 	CTrapCleanup* cleanup;
       
  3633 	cleanup = CTrapCleanup::New();
       
  3634 	
       
  3635 	globalDriveNum = gDriveToTest - (TChar)'A';
       
  3636 	
       
  3637 	PrintLine();
       
  3638 	test.Start(_L("T_NOTIFIER Test Start"));
       
  3639 	TInt r = KErrNone;
       
  3640 	
       
  3641 	//=========================================================================================
       
  3642 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2443
       
  3643 	//! @SYMTestType 			CIT
       
  3644 	//! @SYMREQ 				PREQ1847
       
  3645 	//! @SYMTestCaseDesc 		Simple Tests/User Heap Tests
       
  3646 	//! @SYMTestStatus          Implemented
       
  3647 	//=========================================================================================
       
  3648 	//
       
  3649 	// 1.	Create and delete many CFsNotify objects
       
  3650 	//
       
  3651 	PrintLine();
       
  3652 	test.Next(_L("CFsNotify Creation and Delete Tests"));
       
  3653 	//Creates and Deletes 1 CFsNotify
       
  3654 	__UHEAP_MARK;
       
  3655 	r = TestNewDeleteCFsNotify(1);
       
  3656 	__UHEAP_MARKEND;
       
  3657 	test(r==KErrNone);	
       
  3658 	//Creates and Deletes 50 CFsNotifys
       
  3659 	__UHEAP_MARK;
       
  3660 	r = TestNewDeleteCFsNotify(50);
       
  3661 	__UHEAP_MARKEND;
       
  3662 	test(r==KErrNone);
       
  3663 	test.Printf(_L("------- End of User Heap Tests ---------------------------------------\n"));
       
  3664 	//
       
  3665 	// 2.	Add notification for creating a file
       
  3666 	//		Create that file
       
  3667 	//
       
  3668 	PrintLine();
       
  3669 	__UHEAP_MARK;
       
  3670 	r = SimpleCreateTestL();
       
  3671 	__UHEAP_MARKEND;
       
  3672 	test(r==KErrNone);
       
  3673 	test.Printf(_L("------- End of CFsNotify Creation and Delete Tests -------------------\n"));
       
  3674 	//
       
  3675 	// 3.	Add notification at the root of a drive
       
  3676 	//		Create a file in that drive
       
  3677 	//
       
  3678 	PrintLine();
       
  3679 	TestRootDriveNotifications();
       
  3680 	test.Printf(_L("------- End of RootDriveNotifications Test ---------------------------\n"));
       
  3681 	//
       
  3682 	// 4.	Add notification for a filename without a drive
       
  3683 	//		Create that file in the current drive
       
  3684 	//		Create that file in another drive
       
  3685 	//
       
  3686 	PrintLine();
       
  3687 	TestNonDriveFilters();
       
  3688 	test.Printf(_L("------- End of TestNonDriveFilters Test ------------------------------\n"));
       
  3689 	//
       
  3690 	// 5.	Add notifications for 2 file creations
       
  3691 	//		Create 2 clients
       
  3692 	//		The clients create a file each
       
  3693 	//
       
  3694 	PrintLine();
       
  3695 	__UHEAP_MARK;
       
  3696 	r = TestTwoDoersL();
       
  3697 	__UHEAP_MARKEND;
       
  3698 	test(r==KErrNone);
       
  3699 	test.Printf(_L("------- End of TwoDoers Test -----------------------------------------\n"));
       
  3700 	//
       
  3701 	// 6.	Create 2 file server sessions
       
  3702 	//		Add a notification on each session for the same specific file creation
       
  3703 	//		Create that file
       
  3704 	//
       
  3705 	PrintLine();
       
  3706 	__UHEAP_MARK;
       
  3707 	r = TestTwoWatchersL();
       
  3708 	__UHEAP_MARKEND;
       
  3709 	test(r==KErrNone);
       
  3710 	test.Printf(_L("------- End of TwoWatchers Test --------------------------------------\n"));
       
  3711 	//
       
  3712 	// 7.	Create 2 file server sessions and 2 clients
       
  3713 	//		Add a notification on each session for different file creations
       
  3714 	//		Clients create a file each
       
  3715 	//
       
  3716 	PrintLine();
       
  3717 	__UHEAP_MARK;
       
  3718 	r = TestTwoWatchersTwoDoersL();
       
  3719 	__UHEAP_MARKEND;
       
  3720 	test(r==KErrNone);
       
  3721 	test.Printf(_L("------- End of TwoWatchersTwoDoers Test ------------------------------\n"));
       
  3722 	//
       
  3723 	// 8.	Add notification for a specific file creation
       
  3724 	//		Cancel the notification request
       
  3725 	//		Create that file
       
  3726 	//
       
  3727 	PrintLine();
       
  3728 	__UHEAP_MARK;
       
  3729 	r =  TestCancelNotificationL();
       
  3730 	__UHEAP_MARKEND;
       
  3731 	test(r==KErrNone);
       
  3732 	test.Printf(_L("------- End of CancelNotification Test -------------------------------\n"));
       
  3733 	//
       
  3734 	// 9.	Create 2 file server sessions
       
  3735 	//		Add a notification on each session for the same specific file creation
       
  3736 	//		Delete the first notification
       
  3737 	//		Create that file
       
  3738 	//
       
  3739 	PrintLine();
       
  3740 	test.Next(_L("TestClientRemoval"));
       
  3741 	__UHEAP_MARK;
       
  3742 	r = TestClientRemovalL();
       
  3743 	__UHEAP_MARKEND;
       
  3744 	test(r==KErrNone);
       
  3745 	test.Printf(_L("------- End of TestClientRemoval Test --------------------------------\n"));
       
  3746 	//
       
  3747 	// 10.	Create a CFsNotify object
       
  3748 	//		Close the session before closing the subsession
       
  3749 	//		Add notification and request notifications
       
  3750 	//
       
  3751 	PrintLine();
       
  3752 	__UHEAP_MARK;
       
  3753 	// Close session after creating the object
       
  3754 	TestSessionClose(1);
       
  3755 	__UHEAP_MARKEND;
       
  3756 	__UHEAP_MARK;
       
  3757 	// Close session after adding the notification
       
  3758 	TestSessionClose(2);
       
  3759 	__UHEAP_MARKEND;
       
  3760 	test.Printf(_L("------- End of TestSessionClose Test ---------------------------------\n"));
       
  3761 		
       
  3762 
       
  3763 	//=========================================================================================
       
  3764 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2444
       
  3765 	//! @SYMTestType 			UT
       
  3766 	//! @SYMREQ 				PREQ1847
       
  3767 	//! @SYMTestCaseDesc 		File/Directory Create and Replace – Single File Server Session
       
  3768 	//! @SYMTestStatus          Implemented
       
  3769 	//!
       
  3770 	//! TFsNotificationType		ECreate
       
  3771     //=========================================================================================
       
  3772 	//
       
  3773 	// RFile::Create
       
  3774 	// 1.  Add notification for a specific file creation
       
  3775 	//     Create that file
       
  3776 	//
       
  3777 	PrintLine();
       
  3778 	test.Next(_L("EFileCreate Tests"));
       
  3779 	_LIT(KFilename3,"file.create");
       
  3780 	r = TestMultipleNotificationsL(_L(""),KFilename3,5,5,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3781 	test(r==KErrNone);
       
  3782 	test.Printf(_L("------- End of EFileCreate Tests -------------------------------------\n"));
       
  3783 	//
       
  3784 	// RFs::MkDir
       
  3785 	// 2.  Add notification for a specific directory creation 
       
  3786 	//     Create that directory
       
  3787 	//
       
  3788 	PrintLine();
       
  3789 	test.Next(_L("EFsMkDir Test"));
       
  3790 	_LIT(KDirName1,"dirCreate\\");
       
  3791 	r = TestMultipleNotificationsL(KDirName1,_L(""),1,1,t_notification::EFsMkDir,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3792 	test(r==KErrNone);
       
  3793 	test.Printf(_L("------- End of EFsMkDir Test -----------------------------------------\n"));
       
  3794 	//
       
  3795 	// RFile::Replace
       
  3796 	// 3.  Add notification for a specific file creation
       
  3797 	//     Replace that file
       
  3798 	//
       
  3799 	PrintLine();
       
  3800 	test.Next(_L("EFileReplace Test"));
       
  3801 	r = TestMultipleNotificationsL(_L(""),KFilename3,1,1,t_notification::EFileReplace,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3802 	test(r==KErrNone);
       
  3803 	test.Printf(_L("------- End of EFileReplace Test -------------------------------------\n"));
       
  3804 	//
       
  3805 	// 4.  Add notification for a specific file creation
       
  3806 	//     Remove that notification
       
  3807 	//     Create that file
       
  3808 	//
       
  3809 	PrintLine();
       
  3810 	__UHEAP_MARK;
       
  3811 	r =  TestAddRemoveNotificationL();
       
  3812 	__UHEAP_MARKEND;
       
  3813 	test(r==KErrNone);
       
  3814 	test.Printf(_L("------- End of Add and Remove Notification Test ----------------------\n"));
       
  3815 	//
       
  3816 	// Wildcard Create Tests
       
  3817 	// 5.  Add notification for file creation using wildcard name
       
  3818 	//     Add notification for file/directory wildcard including subdirectories 
       
  3819 	//     Create number of files and directories that match each notification
       
  3820 	//
       
  3821 	PrintLine();
       
  3822 	test.Next(_L("Wildcard Create Tests"));
       
  3823 	//
       
  3824 	// Wildcard Name
       
  3825 	_LIT(KWildcardName1,"*");
       
  3826 	r = TestMultipleNotificationsL(_L(""),KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3827 	test(r==KErrNone);
       
  3828 	r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3829 	test(r==KErrNone);
       
  3830 	r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
       
  3831 	test(r==KErrNone);
       
  3832 	//
       
  3833 	// Wildcard including Subdirectories
       
  3834 	_LIT(KWildcardName2,"*\\");
       
  3835 	r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
       
  3836 	test(r==KErrNone);
       
  3837 	r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3838 	test(r==KErrNone);
       
  3839 	_LIT(KDirName2,"SubDir\\");
       
  3840 	_LIT(KWildcardName3,"?");
       
  3841 	r = TestMultipleNotificationsL(KDirName2,KWildcardName3,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3842 	test(r==KErrNone);
       
  3843 	//
       
  3844 	// Wildcard Type
       
  3845 	_LIT(KWildcardName4,"*.*");
       
  3846 	r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_txt_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3847 	test(r==KErrNone);
       
  3848 	r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
       
  3849 	test(r==KErrNone);
       
  3850 	//
       
  3851 	// 6.  Add notification for file creation for a specific type
       
  3852 	//     Create file with that type
       
  3853 	//     Create file with different type
       
  3854 	//
       
  3855 	_LIT(KWildcardName5,"*.txt");
       
  3856 	r = TestMultipleNotificationsL(_L(""),KWildcardName5,1,1,t_notification::EFileCreate_txt,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3857 	test(r==KErrNone);
       
  3858 	test.Printf(_L("------- End of Wildcard Create Tests ---------------------------------\n"));
       
  3859 	
       
  3860 	
       
  3861 	//=============================================================================
       
  3862 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2445
       
  3863 	//! @SYMTestType 			UT
       
  3864 	//! @SYMREQ 				PREQ1847
       
  3865 	//! @SYMTestCaseDesc 		File Attribute Change – Single File Server Session
       
  3866 	//! @SYMTestStatus          Implemented
       
  3867 	//
       
  3868 	//	TFsNotificationType		EAttribute
       
  3869 	//=============================================================================
       
  3870 	//
       
  3871 	// RFile::SetAtt, RFile::Set and RFs::SetEntry
       
  3872 	// 1.  Add notification for a specific file attribute change
       
  3873 	//     Change the attribute for that file
       
  3874 	//
       
  3875 	PrintLine();
       
  3876 	test.Next(_L("Attribute Tests"));
       
  3877 	_LIT(KFilename4,"file.setatts");
       
  3878 	r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSetAtt,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3879 	test(r==KErrNone);
       
  3880 	r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSet,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3881 	test(r==KErrNone);
       
  3882 	r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFsSetEntry,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3883 	test(r==KErrNone);
       
  3884 	//
       
  3885 	// Wildcard Attribute Test including subdirectories
       
  3886 	// 2.  Add notification for file attribute change using wildcard name
       
  3887 	//     Create number of files that match the notification
       
  3888 	//     Change attributes of some files
       
  3889 	//
       
  3890 	r = TestMultipleNotificationsL(KWildcardName2,_L("*"),3,3,t_notification::EFileSetAtt_subs,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3891 	test(r==KErrNone);
       
  3892 	test.Printf(_L("------- End of Attribute Tests ---------------------------------------\n"));
       
  3893 	
       
  3894 	
       
  3895 	//=============================================================================
       
  3896 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2446
       
  3897 	//! @SYMTestType 			UT
       
  3898 	//! @SYMREQ 				PREQ1847
       
  3899 	//! @SYMTestCaseDesc 		File/Directory Rename – Single File Server Session
       
  3900 	//! @SYMTestStatus          Implemented
       
  3901 	//
       
  3902 	//	TFsNotificationType		ERename
       
  3903 	//=============================================================================
       
  3904 	//
       
  3905 	// RFs::Replace, RFs::Rename and RFile::Rename
       
  3906 	// 1.  Add notification for a specific file rename change
       
  3907 	//     Rename that file
       
  3908 	// 
       
  3909 	PrintLine();
       
  3910 	test.Next(_L("Rename Tests"));
       
  3911 	_LIT(KFilename5,"file.rename");
       
  3912 	r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsReplace,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3913 	test(r==KErrNone);
       
  3914 	r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3915 	test(r==KErrNone);
       
  3916 	r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFileRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3917 	test(r==KErrNone);
       
  3918 	//
       
  3919 	// 2.  Add notification for a specific directory rename
       
  3920 	//     Rename that directory
       
  3921 	//
       
  3922 	_LIT(KDirName3,"dirRename\\");
       
  3923 	r = TestMultipleNotificationsL(KDirName3,_L(""),1,1,t_notification::EFsRename_dir,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3924 	test(r==KErrNone);
       
  3925 	//
       
  3926 	// 3.  Add notification for file rename using wildcard name
       
  3927 	//     Create file that match the notification
       
  3928 	//     Repeatedly rename the file
       
  3929 	//
       
  3930 	r = TestMultipleNotificationsL(_L(""),KWildcardName1,3,3,t_notification::EFileRename_wild,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3931 	test(r==KErrNone);
       
  3932 	test.Printf(_L("------- End of Rename Tests ------------------------------------------\n"));
       
  3933 	
       
  3934 	
       
  3935 	//=============================================================================
       
  3936 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2447
       
  3937 	//! @SYMTestType 			UT
       
  3938 	//! @SYMREQ 				PREQ1847
       
  3939 	//! @SYMTestCaseDesc 		File/Directory Delete – Single File Server Session
       
  3940 	//! @SYMTestStatus          Implemented
       
  3941 	//
       
  3942 	//	TFsNotificationType		EDelete
       
  3943 	//=============================================================================
       
  3944 	//
       
  3945 	// RFs::Delete
       
  3946 	// 1.  Add notification for a specific file delete
       
  3947 	//     Delete that file
       
  3948 	//
       
  3949 	PrintLine();
       
  3950 	test.Next(_L("EFsDelete Test"));
       
  3951 	_LIT(KFilename6,"file.delete");
       
  3952 	r = TestMultipleNotificationsL(_L(""),KFilename6,1,1,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3953 	test(r==KErrNone);	
       
  3954 	//
       
  3955 	// RFs::RmDir
       
  3956 	// 2.  Add notification for a specific directory delete
       
  3957 	//     Delete that directory
       
  3958 	//
       
  3959 	PrintLine();
       
  3960 	test.Next(_L("EFsRmDir Tests"));
       
  3961 	_LIT(KDirName4,"dirRemove\\");
       
  3962 	r = TestMultipleNotificationsL(KDirName4,_L(""),1,1,t_notification::EFsRmDir,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3963 	test(r==KErrNone);
       
  3964     //
       
  3965     // This test should not receive any notifications because a non-empty directory cannot be removed
       
  3966     // 3.  Add notification for specific directory delete
       
  3967     //     Create files inside that directory
       
  3968     //     Delete the directory
       
  3969     //
       
  3970     _LIT(KDirName5,"dirRmNonEmp\\");
       
  3971     r = TestMultipleNotificationsL(KDirName5,_L(""),1,1,t_notification::EFsRmDir_nonEmpty,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
       
  3972     test(r==KErrNone);	
       
  3973     //
       
  3974     // Wildcard Name ("*")
       
  3975     // 4.  Add notification for directory delete using wildcard name
       
  3976     //     Create directory that match the notification
       
  3977 	//	   Delete that directory
       
  3978     //
       
  3979     r = TestMultipleNotificationsL(KWildcardName1,_L(""),1,1,t_notification::EFsRmDir_wild,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3980     test(r==KErrNone);	
       
  3981     //
       
  3982     // Wildcard Type ("*.txt")
       
  3983     // Creates files with different types and should only receive notifications from "*.txt" file deletions
       
  3984     // 5.  Add notification for file deletes using wildcard type
       
  3985     //     Create number of files that match the notification
       
  3986     //     Delete those files
       
  3987     //
       
  3988     r = TestMultipleNotificationsL(_L(""),KWildcardName4,3,3,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  3989     test(r==KErrNone);
       
  3990     test.Printf(_L("------- End of Delete Tests ------------------------------------------\n"));
       
  3991 	
       
  3992 	
       
  3993 	//======================================================================
       
  3994 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2448
       
  3995 	//! @SYMTestType 			UT
       
  3996 	//! @SYMREQ 				PREQ1847
       
  3997 	//! @SYMTestCaseDesc 		File Change – Single File Server Session
       
  3998     //! @SYMTestStatus          Implemented
       
  3999     //
       
  4000 	//	TFsNotificationType		EFileChange
       
  4001 	//======================================================================
       
  4002 	//
       
  4003 	// File Write
       
  4004 	// If caching is enabled, notifications are received only when the file cache is flushed
       
  4005 	// We flush everytime we do a write to ensure the tests work regardless of cache
       
  4006     //
       
  4007     // 1.   Add notification for a specific file change
       
  4008     //      Create the file
       
  4009     //      Write to that file
       
  4010 	//
       
  4011 	PrintLine();
       
  4012 	test.Next(_L("EFileWrite Tests"));
       
  4013 	_LIT(KFilename7,"file.write");
       
  4014 	__UHEAP_MARK;
       
  4015 	r = TestMultipleNotificationsL(_L(""),KFilename7,7,7,t_notification::EFileWrite,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4016 	__UHEAP_MARKEND;
       
  4017 	test(r==KErrNone);
       
  4018 	//
       
  4019 	// 2.  Add notification for a specific file change
       
  4020 	//     Write to the specified file a number of times without changing its size
       
  4021 	//
       
  4022 	// Four letters are written to a file, then the first letter in the file is replaced aIterations times
       
  4023 	//     aMaxNotifications = 1 + aIterations
       
  4024 	//
       
  4025 	r = TestMultipleNotificationsL(_L(""),KFilename7,3,4,t_notification::EFileWrite_samesize,TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4026 	test(r==KErrNone);
       
  4027 	test.Printf(_L("------- End of EFileWrite Tests --------------------------------------\n"));
       
  4028 	//
       
  4029 	// 3.  Add notification for a specific file change
       
  4030 	//     Write to that file asynchronously
       
  4031 	//
       
  4032 	PrintLine();
       
  4033 	test.Next(_L("EFileWrite_async Tests"));
       
  4034 	_LIT(KFilename8,"async.write");
       
  4035 	__UHEAP_MARK;
       
  4036 	r = TestMultipleNotificationsL(_L(""),KFilename8,4,4,t_notification::EFileWrite_async,TFsNotification::EFileChange,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4037 	__UHEAP_MARKEND;
       
  4038 	test(r==KErrNone);
       
  4039 	test.Printf(_L("------- End of EFileWrite_async Tests --------------------------------\n"));	
       
  4040 	//
       
  4041 	// File Set Size
       
  4042 	// 4.  Add notification for a specific file change
       
  4043 	//     Both increase and decrease the file sizes a number of times
       
  4044 	//
       
  4045 	// The file size is increased aIterations times, and decreased (aIterations - 1) times
       
  4046 	//     aMaxNotifications = 2*aIterations - 1
       
  4047 	//
       
  4048 	PrintLine();
       
  4049 	test.Next(_L("EFileSetSize Tests"));
       
  4050 	_LIT(KFilename9,"file.setsize");
       
  4051 	r = TestMultipleNotificationsL(_L(""),KFilename9,5,9,t_notification::EFileSetSize,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4052 	test(r==KErrNone);
       
  4053 	test.Printf(_L("------- End of EFileSetSize Tests ------------------------------------\n"));
       
  4054 
       
  4055 
       
  4056 	//
       
  4057     PrintLine();
       
  4058 	test.Next(_L("CFileMan Tests"));
       
  4059 	_LIT(KFilenameCFMan,"cf1le.man");
       
  4060 	TUint notificationTypes = (TUint)TFsNotification::ECreate|TFsNotification::EFileChange|TFsNotification::EAttribute|TFsNotification::EDelete|TFsNotification::ERename;
       
  4061 	r = TestMultipleNotificationsL(_L(""),KFilenameCFMan,1,5,t_notification::ECFileManMove,notificationTypes,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4062 	test(r==KErrNone);
       
  4063 	test.Printf(_L("------- End of CFileMan Tests -------------------------------------\n"));
       
  4064 	
       
  4065 	
       
  4066 	//========================================================================================
       
  4067 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2449
       
  4068 	//! @SYMTestType 			UT
       
  4069 	//! @SYMREQ 				PREQ1847
       
  4070 	//! @SYMTestCaseDesc 		File System Mounted/Dismounted, Media Card Removal/Insertion,
       
  4071 	//                          RawDisk Write – Single File Server Session
       
  4072 	//! @SYMTestStatus          Implemented
       
  4073 	//
       
  4074 	//	TFsNotificationType		EMediaChange
       
  4075 	//========================================================================================
       
  4076 	//
       
  4077 	// RFs::DismountFileSystem
       
  4078 	// 1.  Add notification for media change
       
  4079 	//     Dismount the file system
       
  4080 	//
       
  4081 	PrintLine();
       
  4082 	test.Next(_L("Mount Tests"));
       
  4083 	TFullName filesystemName;
       
  4084 	r = TheFs.FileSystemName(filesystemName,globalDriveNum);
       
  4085 	test(r==KErrNone);
       
  4086 	r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EDismount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4087 	test(r==KErrNone);
       
  4088 	//
       
  4089 	// RFs::MountFileSystem
       
  4090 	// 2.  Add notification for media change
       
  4091 	//     Mount the file system
       
  4092 	//
       
  4093 	r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EMount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4094 	test(r==KErrNone);
       
  4095 	//
       
  4096 	// Repeatedly mount and dismount the file system
       
  4097 	// 3.  Add notification for media change
       
  4098 	//     Repeatedly dismount and mount the file system
       
  4099 	//
       
  4100 	// The file system is dismounted and mounted aIterations times
       
  4101 	//     aMaxNotifications = 2*aIterations
       
  4102 	//
       
  4103 	r = TestMultipleNotificationsL(filesystemName,5,10,t_notification::EMountDismount,TFsNotification::EMediaChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4104 	test(r==KErrNone);
       
  4105 	//
       
  4106 	// RFs::MountFileSystemAndScan
       
  4107 	// 4.  Add notification for media change
       
  4108 	//     Mount and scan the file system
       
  4109 	//
       
  4110 	// The file system is dismounted and mounted aIterations times
       
  4111 	//     aMaxNotifications = 2*aIterations
       
  4112 	//
       
  4113 //#ifndef __WINS__
       
  4114 //    r = TestMultipleNotificationsL(filesystemName,1,2,t_notification::EMountScan,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4115 //    test(r==KErrNone);
       
  4116 //#endif
       
  4117 	test.Printf(_L("------- End of Mount Tests -------------------------------------------\n"));
       
  4118 	TDriveInfo drvInfo;
       
  4119 	TInt driveNum;
       
  4120 	TheFs.CharToDrive(gDriveToTest,driveNum);
       
  4121 	r = TheFs.Drive(drvInfo,driveNum);
       
  4122 	test (r == KErrNone);
       
  4123 	TPtrC driveDes((TText*)&gDriveToTest,1);
       
  4124 	//
       
  4125 	// Manual Tests - Will only run on removable drives
       
  4126 	//
       
  4127 /*	if(drvInfo.iDriveAtt & KDriveAttRemovable)
       
  4128 		{
       
  4129 		//
       
  4130 		// 5. Add notification for media change
       
  4131 		//    Remove media card manually
       
  4132 		//
       
  4133 		PrintLine();
       
  4134 		test.Next(_L("Media Card Removal/Insertion Tests"));
       
  4135 		r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardRemoval,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4136 		test(r==KErrNone);
       
  4137 		//
       
  4138 		// 6. Add notification for media change
       
  4139 		//    Insert media card manually
       
  4140 		//
       
  4141 		r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardInsertion,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4142 		test(r==KErrNone);
       
  4143 		test.Printf(_L("------- End of Media Card Removal/Insertion Tests --------------------\n"));
       
  4144 		//
       
  4145 		// We should receive an EMediaChange notification even though we did not register for it
       
  4146 		// 7. Do not add notification for media change
       
  4147 		//    Remove and insert media card manually
       
  4148 		//  
       
  4149 		PrintLine();
       
  4150 		TestMediaCardNotificationWhenNotRegisteredForIt();
       
  4151 		test.Printf(_L("------- End of TestMediaCardNotificationWhenNotRegisteredForIt -------\n"));
       
  4152 		}
       
  4153 */	//
       
  4154 	// RRawDisk::Write
       
  4155 	// 8.  Add notification for media change
       
  4156 	//     Write directly to the media
       
  4157 	//
       
  4158 #ifdef __WINS__
       
  4159     if(gDriveToTest-(TChar)'A' != 2)
       
  4160 #endif
       
  4161         {
       
  4162         PrintLine();
       
  4163         test.Next(_L("RRawDisk::Write Tests"));
       
  4164         r = TestMultipleNotificationsL(driveDes,1,1,t_notification::ERawDiskWrite,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4165         test(r==KErrNone);
       
  4166         test.Printf(_L("------- End of RRawDisk::Write Test ------------------------------  \n"));
       
  4167         }	
       
  4168 	
       
  4169 	
       
  4170 	//===============================================================================
       
  4171 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2450
       
  4172 	//! @SYMTestType 			UT
       
  4173 	//! @SYMREQ 				PREQ1847
       
  4174 	//! @SYMTestCaseDesc 		Drive Name Modification – Single File Server Session
       
  4175     //! @SYMTestStatus          Implemented
       
  4176     //
       
  4177 	//	TFsNotificationType		EDriveName
       
  4178 	//===============================================================================
       
  4179 	//
       
  4180 	// RFs::SetDriveName
       
  4181     // The drive name is renamed 2*aIterations times
       
  4182     //     aMaxNotifications = 2*aIterations
       
  4183     //
       
  4184     // 1.   Add notification for a specific drive name change
       
  4185     //      Change the drive name
       
  4186 	//
       
  4187 	PrintLine();
       
  4188 	test.Next(_L("DriveName Test"));
       
  4189 	r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4190 	test(r==KErrNone);
       
  4191 	//
       
  4192 	// 2.  Add notification for a specific drive name change
       
  4193 	//     Repeatedly rename the drive
       
  4194 	//
       
  4195 	r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4196 	test(r==KErrNone);
       
  4197 	test.Printf(_L("------- End of DriveName Test ----------------------------------------\n"));
       
  4198 	
       
  4199 	
       
  4200 	//================================================================================
       
  4201 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2451
       
  4202 	//! @SYMTestType 			UT
       
  4203 	//! @SYMREQ 				PREQ1847
       
  4204 	//! @SYMTestCaseDesc 		Volume Name Modification – Single File Server Session
       
  4205     //! @SYMTestStatus          Implemented
       
  4206     //
       
  4207 	//	TFsNotificationType		EVolumeName
       
  4208 	//================================================================================
       
  4209 	//
       
  4210 	// RFs::SetVolumeLabel - Does not run on WINS
       
  4211     // The volume name is renamed 2*aIterations times
       
  4212     //     aMaxNotifications = 2*aIterations
       
  4213 	//
       
  4214 #ifndef __WINS__
       
  4215 	PrintLine();
       
  4216 	test.Next(_L("VolumeName Test"));
       
  4217 	//
       
  4218 	// 1.  Add notification for a specific volume name change
       
  4219 	//     Change the volume name
       
  4220 	//
       
  4221 	r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4222 	test(r==KErrNone);
       
  4223 	//
       
  4224 	// 2.  Add notification for a specific volume name change
       
  4225 	//     Repeatedly rename the volume
       
  4226 	//
       
  4227 	r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4228 	test(r==KErrNone);
       
  4229 	test.Printf(_L("------- End of VolumeName Test ---------------------------------------\n"));
       
  4230 #endif
       
  4231 		
       
  4232 	
       
  4233     //=============================================================================
       
  4234     //! @SYMTestCaseID          PBASE-T_NOTIFY-2452
       
  4235     //! @SYMTestType            UT
       
  4236     //! @SYMREQ                 PREQ1847
       
  4237     //! @SYMTestCaseDesc        All Operations Filter – Single File Server Session
       
  4238     //! @SYMTestStatus          Implemented
       
  4239     //
       
  4240     //  TFsNotificationType     EAllOps
       
  4241 	//=============================================================================
       
  4242 	PrintLine();
       
  4243 	test.Next(_L("AllOps Tests"));
       
  4244 	//
       
  4245 	// 1.	Add notification for all operations
       
  4246 	//		Create a file
       
  4247 	//		Delete the file
       
  4248 	//
       
  4249 	// EAllOps1: A file is created and deleted aIterations times
       
  4250 	// 		aMaxNotification = 2*aIterations
       
  4251 	//
       
  4252 	_LIT(KFilename10,"file.allops");
       
  4253 	r = TestMultipleNotificationsL(_L(""),KFilename10,4,8,t_notification::EAllOps1,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4254 	test(r==KErrNone);
       
  4255 	//
       
  4256 	// 2.	Add notification for all operations
       
  4257 	//		Create a file
       
  4258 	//		Write to the file
       
  4259 	//		Delete the file
       
  4260 	//
       
  4261 	// EAllOps2: A file is created, written to aIterations times and then deleted
       
  4262 	// 		aMaxNotification = 2 + aIterations (See File Write Tests)
       
  4263 	//
       
  4264 	r = TestMultipleNotificationsL(_L(""),KFilename10,4,6,t_notification::EAllOps2,(TUint)TFsNotification::EAllOps,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4265 	test(r==KErrNone);
       
  4266 	//
       
  4267 	// 3.	Add notification for all operations
       
  4268 	//		Create a file
       
  4269 	//		Change the file size
       
  4270 	//		Delete the file
       
  4271 	//
       
  4272 	// EAllOps3: A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times
       
  4273 	// 			 and then deleted
       
  4274 	//     aMaxNotifications = 1 + 2*aIterations
       
  4275 	//
       
  4276 	r = TestMultipleNotificationsL(_L(""),KFilename10,4,6,t_notification::EAllOps3,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4277 	test(r==KErrNone);
       
  4278 	//
       
  4279 	// 4.	Add notification for all operations
       
  4280 	//		Create a file
       
  4281 	//		Change the file attribute
       
  4282 	//		Delete the file
       
  4283 	//
       
  4284 	// EAllOps4: A file is created, its attribute is changed and the file is deleted
       
  4285 	// 		aMaxNotification = 3
       
  4286 	//
       
  4287 	r = TestMultipleNotificationsL(_L(""),KFilename10,1,3,t_notification::EAllOps4,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4288 	test(r==KErrNone);
       
  4289 	//
       
  4290 	// 5.	Add notification for all operations
       
  4291 	//		Create a file
       
  4292 	//		Rename the file
       
  4293 	//
       
  4294 	// EAllOps5: A file is created and renamed
       
  4295 	// 		aMaxNotification = 2
       
  4296 	//
       
  4297 	r = TestMultipleNotificationsL(_L(""),KFilename10,1,2,t_notification::EAllOps5,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4298 	test(r==KErrNone);
       
  4299 	//
       
  4300 	// 6.	Add notification for all operations
       
  4301 	//		Change drive name
       
  4302 	//		Change volume name
       
  4303 	//
       
  4304 	// SetVolumeLabel does not run on WINS
       
  4305 	// EAllOps6: The drive and volume names are changed
       
  4306 	//		aMaxNotification = 2
       
  4307 	//
       
  4308 #ifndef __WINS__
       
  4309 	r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4310 	test(r==KErrNone);
       
  4311 #endif
       
  4312 	test.Printf(_L("------- End of AllOps Tests ------------------------------------------\n"));
       
  4313 	
       
  4314 	
       
  4315     //=============================================================================
       
  4316     //! @SYMTestCaseID          PBASE-T_NOTIFY-2453
       
  4317     //! @SYMTestType            UT
       
  4318     //! @SYMREQ                 PREQ1847
       
  4319     //! @SYMTestCaseDesc        Multiple Filters – Single File Server Session
       
  4320     //! @SYMTestStatus          Implemented
       
  4321 	//=============================================================================
       
  4322 	PrintLine();
       
  4323 	test.Next(_L("Multiple-Filter Tests"));
       
  4324 	//
       
  4325 	// TFsNotification::ECreate | TFsNotification::EDelete
       
  4326 	// 1.	Add notification for create and delete for a specific file
       
  4327 	//		Create that file
       
  4328 	//		Delete the file
       
  4329 	//
       
  4330 	// A file is created and deleted aIterations times
       
  4331 	// 		aMaxNotification = 2*aIterations
       
  4332 	//
       
  4333 	_LIT(KFilename11,"file.mulfil");
       
  4334 	r = TestMultipleNotificationsL(_L(""),KFilename11,3,6,t_notification::EAllOps1,TFsNotification::ECreate | TFsNotification::EDelete,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4335 	test(r==KErrNone);
       
  4336 	//
       
  4337 	// TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange
       
  4338 	// 2.	Add notification for create, file change and delete for a specific file
       
  4339 	//		Create a file
       
  4340 	//		Change the file size
       
  4341 	//		Delete the file
       
  4342 	//
       
  4343 	// A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times
       
  4344 	// and then deleted
       
  4345 	//     aMaxNotifications = 1 + 2*aIterations
       
  4346 	//
       
  4347 	r = TestMultipleNotificationsL(_L(""),KFilename11,4,6,t_notification::EAllOps3,TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4348 	test(r==KErrNone);
       
  4349 	//
       
  4350 	// TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate
       
  4351 	// 3.	Add notification for create, attribute change and delete for a specific file
       
  4352 	//		Create a file
       
  4353 	//		Change the file attribute
       
  4354 	//		Delete the file
       
  4355 	//
       
  4356 	// A file is created, its attribute is changed and the file is deleted
       
  4357 	// 		aMaxNotification = 3
       
  4358 	//
       
  4359 	r = TestMultipleNotificationsL(_L(""),KFilename11,1,3,t_notification::EAllOps4,TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4360 	test(r==KErrNone);
       
  4361 	//
       
  4362 	// TFsNotification::ERename | TFsNotification::ECreate
       
  4363 	// 4.	Add notification for create and rename for a specific file
       
  4364 	//		Create a file
       
  4365 	//		Rename the file
       
  4366 	//
       
  4367 	// A file is created and renamed
       
  4368 	// 		aMaxNotification = 2
       
  4369 	//
       
  4370 	r = TestMultipleNotificationsL(_L(""),KFilename11,1,2,t_notification::EAllOps5,TFsNotification::ERename | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4371 	test(r==KErrNone);
       
  4372 	//
       
  4373 	// TFsNotification::EVolumeName | TFsNotification::EDriveName
       
  4374 	// 5.	Add notification for drive and volume name change for a specific drive
       
  4375 	//		Change drive name
       
  4376 	//		Change volume name
       
  4377 	//
       
  4378 	// SetVolumeLabel does not run on WINS
       
  4379 	// The drive and volume names are changed
       
  4380 	//		aMaxNotification = 2
       
  4381 	//
       
  4382 #ifndef __WINS__
       
  4383 	r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,TFsNotification::EVolumeName | TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4384 	test(r==KErrNone);
       
  4385 #endif
       
  4386 	test.Printf(_L("------- End of Multiple-Filter Tests ---------------------------------\n"));
       
  4387 	
       
  4388 	
       
  4389 	//==============================================================================
       
  4390 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2454
       
  4391 	//! @SYMTestType 			UT
       
  4392 	//! @SYMREQ 				PREQ1847
       
  4393 	//! @SYMTestCaseDesc 		Overflow Notification – Single File Server Session
       
  4394     //! @SYMTestStatus          Implemented
       
  4395 	//==============================================================================
       
  4396 	//
       
  4397 	// 1.	Add notification with a small buffer size, for a specific file change
       
  4398 	//		Change the file size once
       
  4399 	// 2.	Make continuous file size changes to the file
       
  4400 	// 3.	When overflow notification occurs, delete the notification
       
  4401 	//
       
  4402 	PrintLine();
       
  4403 	r = TestOverflowL();
       
  4404 	test(r==KErrNone);
       
  4405 	
       
  4406 	//For DEF140387
       
  4407 	PrintLine();
       
  4408 	r= TestPostOverflowNotifications();
       
  4409 	test(r==KErrNone);
       
  4410 	test.Printf(_L("------- End of Overflow Test -----------------------------------------\n"));
       
  4411 	
       
  4412 	
       
  4413 	//============================================================================
       
  4414 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2455
       
  4415 	//! @SYMTestType 			CIT
       
  4416 	//! @SYMREQ 				PREQ1847
       
  4417 	//! @SYMTestCaseDesc 		API Negative Testing – Single File Server Session
       
  4418     //! @SYMTestStatus          Implemented
       
  4419 	//============================================================================
       
  4420 	// 1.
       
  4421 	//	a-CFsNotify class creation with zero buffer size
       
  4422 	//
       
  4423 	// 2.
       
  4424 	//	b-CFsNotify class creation with negative buffer size
       
  4425 	//	c-CFsNotify class creation with buffer size that is too large
       
  4426 	//
       
  4427 	// 3.
       
  4428 	//	d-Call AddNotification with aNotiififcationType zero
       
  4429 	//	e-Call AddNotification with aNotiififcationType invalid
       
  4430 	//	f-Call AddNotification with many different invalid paths
       
  4431 	//
       
  4432 	// 4.
       
  4433 	//	g-Call RequestNotifications with status that is already in use
       
  4434 	//	h-Call CancelNotifications with wrong status
       
  4435 	//
       
  4436 	PrintLine();
       
  4437 	__UHEAP_MARK;
       
  4438 	NegativeTests();
       
  4439 	__UHEAP_MARKEND;
       
  4440 	//
       
  4441 	// 5.
       
  4442 	//	i-Negative testing for directory without *
       
  4443 	//
       
  4444 	test.Printf(_L("NegativeTests() I\n"));
       
  4445 	NegativeTestDirStar();
       
  4446 	test.Printf(_L("------- End of Negative Tests ----------------------------------------\n"));
       
  4447 	
       
  4448 	
       
  4449     //=============================================================================
       
  4450     //! @SYMTestCaseID          PBASE-T_NOTIFY-2461
       
  4451     //! @SYMTestType            CIT
       
  4452     //! @SYMREQ                 PREQ1847
       
  4453     //! @SYMTestCaseDesc        Plugin Tests
       
  4454     //! @SYMTestStatus          
       
  4455 	//=============================================================================
       
  4456 	PrintLine();
       
  4457 	r = TestNotificationsWithFServPlugins();
       
  4458 	test(r==KErrNone);
       
  4459 	test.Printf(_L("------- End of Plugin Tests ------------------------------------------\n"));
       
  4460 		
       
  4461 	
       
  4462 	//======================================================================
       
  4463 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2459
       
  4464 	//! @SYMTestType 			UT
       
  4465 	//! @SYMREQ 				PREQ1847
       
  4466 	//! @SYMTestCaseDesc 		Drive Formatting – Single File Server Session
       
  4467 	//! @SYMTestStatus          Implemented
       
  4468 	//
       
  4469 	//	TFsNotificationType		EMediaChange
       
  4470 	//======================================================================
       
  4471 	//
       
  4472 	// RFormat
       
  4473 	// We do these last so that we can be sure to have deleted anything we've inadvertently not deleted
       
  4474 	//
       
  4475 	// 1.  Add notification for media change of a specific drive
       
  4476 	//     Format the drive
       
  4477 	//
       
  4478 #ifdef __WINS__
       
  4479 	if(gDriveToTest-(TChar)'A' != 2)
       
  4480 #endif
       
  4481 		{
       
  4482 		PrintLine();
       
  4483 		test.Next(_L("Format Tests"));
       
  4484 		r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EFormat,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
       
  4485 		test(r==KErrNone);
       
  4486 		test.Printf(_L("------- End of Format Tests ------------------------------------------\n"));
       
  4487 		}
       
  4488 	
       
  4489 	
       
  4490 	//======================================================================
       
  4491 	//! @SYMTestCaseID			PBASE-T_NOTIFY-2460
       
  4492 	//! @SYMTestType 			UT
       
  4493 	//! @SYMREQ 				PREQ1847
       
  4494 	//! @SYMTestCaseDesc 		Notifications for Data Caged Areas
       
  4495 	//! @SYMTestStatus          Implemented
       
  4496 	//======================================================================
       
  4497 	//
       
  4498 	// Create a private folder for a specified uid
       
  4499 	// Add notification filter using the following processes:
       
  4500 	//	1.	A process with no capability
       
  4501 	//	2.	A process with all capabilities
       
  4502 	//	3.	A process with the specified uid
       
  4503 	//
       
  4504 	PrintLine();
       
  4505 	test.Next(_L("Test T_NOTIFIER_NOCAPS.EXE"));
       
  4506 	r = TestProcessCapabilities(_L("T_NOTIFIER_NOCAPS.EXE"));
       
  4507 	test(r == KErrPermissionDenied); //Failure on emulator -> Did you forget to do a wintest?
       
  4508 	
       
  4509 	test.Next(_L("Test T_NOTIFIER_ALLFILES.EXE"));
       
  4510 	r = TestProcessCapabilities(_L("T_NOTIFIER_ALLFILES.EXE"));
       
  4511 	test(r == KErrNone);
       
  4512 	
       
  4513 	test.Next(_L("Test T_NOTIFIER_BELONGS.EXE"));
       
  4514 	r = TestProcessCapabilities(_L("T_NOTIFIER_BELONGS.EXE"));
       
  4515 	test(r == KErrNone);
       
  4516 	test.Printf(_L("------- End of Data-Caging Tests -------------------------------------\n"));
       
  4517 	
       
  4518 	
       
  4519 	test.End();
       
  4520 	test.Close();
       
  4521 	delete cleanup;
       
  4522 	}	//End of CallTestsL
       
  4523