First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_notifier.cpp
24 #include "t_notify_plugin.h"
26 const TInt KNotificationHeaderSize = (sizeof(TUint16)*2)+(sizeof(TUint));
27 const TInt KMinNotificationBufferSize = 2*KNotificationHeaderSize + 2*KMaxFileName;
30 RTest test(_L("T_NOTIFIER"));
31 const TInt KMaxHeapSize = 0x800000;
36 TheFs.DismountPlugin(KNotifyPluginName);
37 TheFs.RemovePlugin(KNotifyPluginFileName);
40 inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TText* aName)
44 test.Printf(_L(": ERROR : %d received on line %d\n"),aError,aLine);
46 aTest.operator()(aError==KErrNone,aLine,(TText*)aName);
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)
53 if(aError != KErrNone)
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);
61 // Prints out the filename
62 #define ExpandMe(X) L ## X
63 #define Expand(X) ExpandMe(X)
65 namespace t_notification
69 //TFsNotification::ECreate
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
79 EFileSetAtt_subs, //Set attributes in subdir
82 //TFsNotification::ERename
83 EFsReplace, //Replace file
84 EFsRename, //Rename file
85 EFsRename_dir, //Rename directory
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
95 EFileWrite_samesize, //Write to file without changing its size
96 EFileWrite_async, //Asynchronous write
98 //TFsNotification::EVolumeName
100 //TFsNotification::EDriveName
102 //TFsNotification::EMediaChange
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
122 // Package filename and semaphore for thread
123 struct SThreadPackage
129 struct SThreadPackageDualSemaphore
133 RSemaphore iBarrier2;
136 struct SThreadPackage2
142 // Used by TestMultipleNotificationsL
143 struct SThreadPackageMultiple
145 TFileName iString; //Commonly stores the filename
146 TFileName iFileName; //Commonly stores the path (not inc filename)
148 t_notification::EOperation iOperation;
149 TFsNotification::TFsNotificationType iNotifyType;
150 TInt iIterations; //# of times to 'do' something
151 TInt iMaxNotifications; //# of notifications expected
153 TInt iLineCall; //Line where the function is called from
158 test.Printf(_L("======================================================================\n"));
162 // We should receive an EMediaChange notification even though we did not register for it
163 void TestMediaCardNotificationWhenNotRegisteredForIt()
166 TInt r = fs.Connect();
169 CFsNotify* notify = NULL;
170 TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
173 path.Append((TChar)gDriveToTest);
174 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
177 filename.Append(_L("media.change1"));
179 r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
182 TRequestStatus status;
183 r = notify->RequestNotifications(status);
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"));
193 r = timer1.CreateLocal();
195 TRequestStatus timeout;
196 TTimeIntervalMicroSeconds32 time = 10000000;
197 timer1.After(timeout,time);
198 User::WaitForRequest(timeout,status);
199 test(status.Int() != KRequestPending);
203 const TFsNotification* notification = notify->NextNotification();
204 test(notification != NULL);
205 TFsNotification::TFsNotificationType type = notification->NotificationType();
206 test(type == TFsNotification::EMediaChange);
208 drive.Append((TChar)gDriveToTest);
209 drive.Append(_L(":"));
211 r = notification->Path(drivePtr);
213 r = drivePtr.Compare(drive);
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"));
223 notification = notify->NextNotification();
224 if(notification == NULL)
226 notify->RequestNotifications(status);
228 r = timer2.CreateLocal();
230 TRequestStatus timeout2;
231 timer2.After(timeout2,time);
232 User::WaitForRequest(timeout2,status);
233 test(status.Int() != KRequestPending);
234 notification = notify->NextNotification();
238 test(notification != NULL);
239 type = notification->NotificationType();
240 test(type == TFsNotification::EMediaChange);
246 // Creates two sessions, removes the first one
247 // and then checks if the second one still works
248 TInt TestClientRemovalL()
251 TInt r = fs.Connect();
254 CFsNotify* notify1 = NULL;
255 CFsNotify* notify2 = NULL;
256 TRAP(r,notify1= CFsNotify::NewL(fs,KMinNotificationBufferSize);
257 notify2= CFsNotify::NewL(fs,KMinNotificationBufferSize);
267 path.Append((TChar)gDriveToTest);
268 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
271 filename.Append(_L("create.file"));
274 fullname.Append(path);
275 fullname.Append(filename);
277 r = notify1->AddNotification((TUint)TFsNotification::ECreate,path,filename);
279 r = notify2->AddNotification((TUint)TFsNotification::ECreate,path,filename);
282 delete notify1; //Delete notify1 and ensure we still get notification on notify2
284 TRequestStatus status;
285 r = notify2->RequestNotifications(status);
289 file.Replace(fs,fullname,EFileWrite); //Replace produces Create notification
293 r = tim.CreateLocal();
296 TRequestStatus timStatus;
297 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
298 tim.After(timStatus,time);
300 User::WaitForRequest(status,timStatus);
301 test(status!=KRequestPending);
303 r = fs.Delete(fullname);
313 * This tests that u can set and receive notifications in the root
316 * (something which was apparently not possible on RFs::NotifyChange)
318 TInt TestRootDriveNotifications()
320 test.Next(_L("TestRootDriveNotifications"));
324 CFsNotify* notify = NULL;
326 TRAPD(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize););
331 path.Append((TChar)gDriveToTest);
332 path.Append(_L(":\\"));
335 filename.Append(_L("*"));
337 r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
340 TRequestStatus status;
341 r = notify->RequestNotifications(status);
346 filePath.Append((TChar)gDriveToTest);
347 filePath.Append(_L(":\\file.root"));
348 r = file.Replace(fs,filePath,EFileRead);
354 test(tim.CreateLocal()==KErrNone);
355 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
357 User::WaitForRequest(status,s2);
358 test(status!=KRequestPending);
368 * Creates and deletes loads of CFsNotify objects and makes sure they're all
369 * cleaned up afterwards.
371 TInt TestNewDeleteCFsNotify(TInt aIterations)
373 RPointerArray<CFsNotify> array;
376 for(TInt i = 0; i < aIterations; i++)
378 CFsNotify* notify = NULL;
379 TRAP(r,notify = CFsNotify::NewL(TheFs,500));
383 r = array.Append(notify);
400 for(TInt j = inArray-1; j >= 0; j--)
402 CFsNotify* notify = (CFsNotify*)array[j];
415 * Used in SimpleTest1L(), TestTwoDoersL() TestTwoWatchersL(), TestCancelNotificationL()
417 TInt SimpleSingleNotificationTFDoer(TAny* aAny)
419 SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny;
420 RTest simpleTestDoer(_L("SimpleSingleNotificationTFDoer"));
421 simpleTestDoer.Start(_L("SimpleSingleNotificationTFDoer"));
423 path.Append(gDriveToTest);
424 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
425 path.Append(pkgDoer.iFileName);
427 //Delete file so we definitely get a create notification
429 TInt r = fs.Connect();
430 safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
432 if(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound)
434 safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
435 r = fs.MkDirAll(path);
436 if(r==KErrNone || r==KErrAlreadyExists)
438 safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
440 simpleTestDoer.Printf(_L("SimpleSingleNotificationTFDoer - Create File %S\n"),&path);
443 r = file.Create(fs,path,EFileWrite);
444 safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
448 simpleTestDoer.End();
449 simpleTestDoer.Close();
454 * Watches 1 file creation
455 * Used in SimpleTest1L()
457 TInt SimpleSingleNotificationTFWatcher(TAny* aAny)
459 CTrapCleanup* cleanup;
460 cleanup = CTrapCleanup::New();
462 TUint64 threadId = thread.Id().Id();
464 SThreadPackage pkgDoer = *(SThreadPackage*)aAny;
465 RSemaphore& simpleBarrierTest = pkgDoer.iBarrier;
467 RTest simpleTestWatcher(_L("SimpleSingleNotificationTFWatcher"));
468 simpleTestWatcher.Start(_L("SimpleSingleNotificationTFWatcher"));
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"));
478 path.Append(gDriveToTest);
479 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
482 filename.Append(pkgDoer.iFileName);
485 fullname.Append(path);
486 fullname.Append(filename);
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"));
496 simpleBarrierTest.Signal();
498 simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Wait for status to return\n"),threadId);
499 User::WaitForRequest(status);
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"));
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);
514 ((TFsNotification*)notification)->Path(_pathC);
515 simpleTestWatcher.Printf(_L("Notification Path = %S\n"),&_pathC);
518 if(_path.Match(fullname)!=KErrNone)
519 safe_test(simpleTestWatcher,KErrBadName,__LINE__,(TText*)Expand("t_notifier.cpp"));
522 TInt driveNumber = 0;
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"));
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"));
537 simpleTestWatcher.End();
538 simpleTestWatcher.Close();
544 * SimpleTest1L - Runs a simple Create test, gets 1 notification, calls type, path etc and exits
545 * Two threads: 1 watcher, 1 doer
547 TInt SimpleCreateTestL()
549 test.Next(_L("SimpleTest"));
552 _LIT(KFileName,"simple.create");
553 SThreadPackage pkgDoer;
554 pkgDoer.iFileName = KFileName;
556 SThreadPackage watcherPkg;
557 watcherPkg.iFileName = KFileName;
558 User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0));
559 User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0));
562 watcher.Create(_L("Simple1WatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
563 doer.Create(_L("Simple1DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
565 watcherPkg.iBarrier.Wait(); //Wait till Watcher has requested notification
568 TRequestStatus 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"));
574 RDebug::Print(_L("Line %d"),__LINE__);
577 watcher.Logon(status);
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);
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"));
594 CLOSE_AND_WAIT(doer);
595 CLOSE_AND_WAIT(watcher);
597 pkgDoer.iBarrier.Close();
598 watcherPkg.iBarrier.Close();
603 // Doer thread for TestMultipleNotificationsL
604 TInt MultipleNotificationTFDoer(TAny* aAny)
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__);
612 basepath.Append(gDriveToTest);
613 basepath.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
616 RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
617 TUint64 threadID = thread.Id().Id();
618 RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
620 //Delete file so we definitely get a create notification
622 TInt r = fs.Connect();
623 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
626 TBool wildcard = EFalse;
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)
637 if (r == KErrBadName)
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)
646 r = fs.Delete(_path);
647 if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
648 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
650 r = fs.MkDirAll(basepath);
651 if(r != KErrNone && r != KErrAlreadyExists)
652 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
655 multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
657 switch(pkgDoer.iOperation)
659 case t_notification::EFileReplace:
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);
668 r = fs.Delete(_path);
669 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
672 case t_notification::EFileCreate:
673 case t_notification::EFileCreate_txt_nowatch:
674 case t_notification::EFileCreate_txt:
675 case t_notification::EAllOps1:
677 multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
680 for (TInt i = 0; i < pkgDoer.iIterations; i++)
682 multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
685 path.Append(basepath);
687 if(pkgDoer.iOperation == t_notification::EFileCreate_txt)
689 //Create file with different extension (no notification)
690 path.Append(_L(".wrg"));
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"));
698 else if(pkgDoer.iOperation == t_notification::EFileCreate_txt_nowatch)
700 path.Append(_L(".txt"));
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);
709 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
714 multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
715 for(TInt i = 0; i < pkgDoer.iIterations; i++)
717 multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
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);
723 r = fs.Delete(_path);
724 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
729 case t_notification::EFileCreate_subs:
730 case t_notification::EFileCreate_subs_nowatch:
734 for (TInt i = 0; i < pkgDoer.iIterations; i++)
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);
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);
750 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
755 case t_notification::EFileWrite:
756 case t_notification::EAllOps2:
758 //Works on single file
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++)
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);
775 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
779 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
782 case t_notification::EFileWrite_samesize:
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);
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);
799 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
801 for(TInt i = 0; i < pkgDoer.iIterations; i++)
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);
810 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
814 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
817 case t_notification::EFileWrite_async:
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++)
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);
834 multipleTestDoer.Printf(_L("File Write Async - FileSize: %d\n"),fileSize);
835 multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
837 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
841 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
844 case t_notification::EFileSetSize:
845 case t_notification::EAllOps3:
847 //Works on single file
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);
857 for(TInt i = 0; i < pkgDoer.iIterations; i++)
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);
865 for(TInt j = pkgDoer.iIterations - 2; j >= 0; j--)
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);
874 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
877 case t_notification::EFsReplace:
880 path.Append(basepath);
881 path.Append(pkgDoer.iFileName);
882 path.Append(pkgDoer.iString);
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);
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);
896 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
899 case t_notification::EFsRename:
902 path.Append(basepath);
903 path.Append(pkgDoer.iFileName);
904 path.Append(pkgDoer.iString);
908 r = file.Replace(fs,_path,EFileWrite);
909 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
912 multipleTestDoer.Printf(_L("RFs Rename - (%d)\n"),threadID);
913 r = fs.Rename(_path,path);
914 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
917 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
920 case t_notification::EFileRename:
921 case t_notification::EFileRename_wild:
922 case t_notification::EAllOps5:
925 path.Append(basepath);
928 path.Append(pkgDoer.iFileName);
929 path.Append(pkgDoer.iString);
933 //Delete new path to ensure it does not exist
935 if(r != KErrNone && r != KErrNotFound && r != KErrPathNotFound)
936 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
940 _path.Delete(_path.Length()-1,1);
945 r = file.Replace(fs, _path, EFileWrite);
946 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
950 for(TInt i = 1; i <= pkgDoer.iIterations; i++)
952 path.Delete(path.Length()-1,1);
954 multipleTestDoer.Printf(_L("File Rename - %S (%d)\n"),&path,threadID);
955 r = file.Rename(path);
956 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
961 multipleTestDoer.Printf(_L("File Rename - (%d)\n"),threadID);
962 r = file.Rename(path);
963 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
968 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
971 case t_notification::EFsRename_dir:
973 r = fs.MkDirAll(_path);
974 if(r != KErrNone && r != KErrAlreadyExists)
975 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
979 newPath.Delete(newPath.Length()-1,1);
980 newPath.AppendNum(0);
981 newPath.Append(KPathDelimiter);
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);
988 multipleTestDoer.Printf(_L("RFs Rename Dir - (%d)\n"),threadID);
989 r = fs.Rename(_path,newPath);
990 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
993 case t_notification::EFsDelete:
997 for(TInt i = 0; i < pkgDoer.iIterations; i++)
999 //Create/replace file
1002 path.Append(basepath);
1003 r = fs.MkDirAll(path);
1004 if(r != KErrNone && r != KErrAlreadyExists)
1005 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1007 path.Append(_L(".txt"));
1008 r = file.Replace(fs,path,EFileWrite);
1009 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1013 multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
1014 r = fs.Delete(path);
1015 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1017 //Create file with a different extension which should not produce notifications
1019 r = file.Replace(fs,path,EFileWrite);
1020 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1024 multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
1025 r = fs.Delete(path);
1026 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1032 r = file.Replace(fs,_path,EFileWrite); //Make sure file exists
1033 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1036 multipleTestDoer.Printf(_L("RFs Delete - (%d)\n"),threadID);
1037 r = fs.Delete(_path);
1038 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1042 case t_notification::EFileSet:
1045 r = file.Replace(fs,_path,EFileWrite);
1046 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
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);
1055 case t_notification::EFileSetAtt:
1056 case t_notification::EAllOps4:
1059 r = file.Replace(fs,_path,EFileWrite);
1060 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1062 multipleTestDoer.Printf(_L("File SetAtt - (%d)\n"),threadID);
1063 r = file.SetAtt(KEntryAttHidden,KEntryAttReadOnly);
1064 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1067 r = fs.Delete(_path);
1068 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1071 case t_notification::EFileSetAtt_subs:
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);
1082 //Create/replace files and set their attributes
1083 for(TInt i = 0; i < pkgDoer.iIterations; i++)
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);
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);
1098 r = fs.Delete(dirPath);
1099 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1104 case t_notification::EFsSetEntry:
1107 r = file.Replace(fs,_path,EFileWrite);
1108 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
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);
1116 case t_notification::EDismount:
1118 multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
1119 r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
1120 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1123 case t_notification::EMount:
1125 multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
1126 r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum);
1127 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1130 case t_notification::EMountScan:
1132 multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
1133 r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
1134 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1136 multipleTestDoer.Printf(_L("MountFileSystemAndScan - (%d)\n"),threadID);
1137 r = fs.MountFileSystemAndScan(pkgDoer.iFileName,globalDriveNum,isMount);
1139 safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall);
1140 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1143 case t_notification::EMountDismount:
1145 for(TInt i = 0; i < pkgDoer.iIterations; i++)
1147 multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
1148 r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
1149 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1151 multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
1152 r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum);
1153 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1157 case t_notification::EFormat:
1162 driveDes.Append(pkgDoer.iFileName);
1163 driveDes.Append((TChar)':');
1164 format.Open(fs,driveDes,EQuickFormat,count);
1165 multipleTestDoer.Printf(_L("Format - (%d)\n"),threadID);
1174 case t_notification::EMediaCardRemoval:
1175 case t_notification::EMediaCardInsertion:
1177 //These are MANUAL tests, they require the removal/insertion of the media card
1178 //Instructions are given out in the watcher thread
1181 case t_notification::ESetDriveName:
1183 for(TInt i = 0; i < pkgDoer.iIterations; i++)
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);
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);
1197 case t_notification::ERawDiskWrite:
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);
1209 r = rawdisk.Read(0,readData);
1210 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1213 TPtrC8 dataPtr(readData);
1214 r = rawdisk.Write((TInt64)0,dataPtr);
1215 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1219 case t_notification::ESetVolumeLabel:
1221 for(TInt i = 0; i < pkgDoer.iIterations; i++)
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);
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);
1235 case t_notification::EFsRmDir:
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);
1245 case t_notification::EFsRmDir_wild:
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);
1256 multipleTestDoer.Printf(_L("RFs RmDir - Remove directory\n"));
1258 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1262 case t_notification::EFsRmDir_nonEmpty:
1263 case t_notification::EFsMkDir:
1267 path.Append(pkgDoer.iFileName); //Append another sub-directory
1268 multipleTestDoer.Printf(_L("RFs RmDir \n"));
1270 if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
1271 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1273 if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
1274 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1276 multipleTestDoer.Printf(_L("RFs MkDir \n"));
1278 multipleTestDoer (r==KErrPathNotFound);
1280 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1282 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1284 multipleTestDoer.Printf(_L("RFs RmDir nonEmpty - Full path: %S"),&_path);
1285 r = fs.RmDir(_path);
1287 safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall);
1290 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1292 multipleTestDoer.Printf(_L("RFs EFsRmDir_nonEmpty - Full path: %S"),&_path);
1293 r = fs.RmDir(_path);
1294 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1298 case t_notification::EAllOps6:
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);
1312 case t_notification::ECFileManMove:
1314 CTrapCleanup* cleanup;
1315 cleanup = CTrapCleanup::New();
1317 multipleTestDoer.Printf(_L("Doer - ECFileManMove_part1\n"));
1319 //Stage 1 - Create File & write some data
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);
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);
1336 //Stage 2 - Move to unmonitored Dir
1338 r = cfman->Move(_path,unmonitored_path);
1339 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1341 //SetSize (size := 8)
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);
1350 //Stage 3 - Move back to monitored Dir
1352 r = cfman->Move(unmonitored_path,_path);
1353 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1357 r = cfman->Delete(_path);
1358 safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1371 multipleTestDoer.End();
1372 multipleTestDoer.Close();
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.
1381 * There are three MMP files:
1382 * t_notifier_nocaps.mmp, t_notifier_allfiles.mmp, t_notifier_belongs.mmp
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.
1391 * See: f32test\server\t_notifier_caps.cpp
1393 TInt TestProcessCapabilities(const TDesC& aProcessName)
1397 TPtrC command((TText*)&gDriveToTest,1);
1398 TInt r = process.Create(aProcessName,command,uid);
1404 r = tim.CreateLocal();
1406 TTimeIntervalMicroSeconds32 delay = 5000000; //5 seconds
1407 tim.After(s1,delay);
1409 User::WaitForRequest(s1,s2);
1410 test(s2.Int()!=KRequestPending);
1411 r = process.ExitReason();
1417 * Creates a file and writes to it twice.
1418 * Used in TestTwoNotificationsL().
1420 TInt TwoNotificationsTFDoer(TAny* aAny)
1422 RTest testDoer(_L("TestTwoNotificationsThreadFunctionDoer"));
1423 testDoer.Start(_L("TestTwoNotificationsThreadFunctionDoer"));
1425 SThreadPackageMultiple package = *(SThreadPackageMultiple*)aAny;
1427 path.Append(gDriveToTest);
1428 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1429 path.Append(package.iFileName);
1431 //Delete file so we definitely get a create notification
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);
1440 testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Create File %S\n"),&path);
1443 r = file.Create(fs,path,EFileWrite);
1444 testDoer(r == KErrNone);
1446 testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 1 %S\n"),&path);
1448 r = file.Size(fileSize);
1449 testDoer(r == KErrNone);
1450 testDoer(fileSize==0);
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);
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);
1477 * The following enum are for the CFileMan test
1481 ECFManCreate1 = 0x01,
1482 ECFManWrite1 = 0x02,
1483 ECFManDelete1 = 0x04,
1484 ECFManCreate2 = 0x08,
1485 ECFManSetSize1 = 0x10,
1486 ECFManWrite2 = 0x20,
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
1496 * Used by MultipleNotificationsTFWatcher() to test the notifications.
1498 void HandleMultipleNotifications(RTest& aTest, SThreadPackageMultiple& aPackage, CFsNotify* notify, TDesC& aFullname)
1501 TUint64 threadID = thread.Id().Id();
1502 TInt numNotifications = 0;
1503 TInt64 fileSize = 0;
1504 TBool overflow = EFalse;
1508 for(TInt i = 0; i < aPackage.iMaxNotifications; ) //Outer-loop to control when we should exit
1510 aTest.Printf(_L("(%d) - NextNotification\n"),threadID);
1511 const TFsNotification* notification = notify->NextNotification();
1512 while(notification != NULL)
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);
1520 aTest.Printf(_L("(%d) - Notification Type\n"),threadID);
1521 TFsNotification::TFsNotificationType notificationType = notification->NotificationType();
1522 aTest(notificationType & aPackage.iNotifyType ||
1523 notificationType & TFsNotification::EOverflow);
1525 aTest.Printf(_L("Notification Type = %u - (%d)\n"),notificationType,threadID);
1527 if(notificationType != TFsNotification::EOverflow)
1529 aTest.Printf(_L("(%d) - Notification Path\n"),threadID);
1531 ((TFsNotification*) notification)->Path(_pathC);
1532 aTest.Printf(_L("%S - (%d)\n"),&_pathC,threadID);
1534 if(aPackage.iOperation == t_notification::ECFileManMove
1535 && (scratch == (ECFManWrite1 | ECFManCreate1)))
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);
1546 else if((scratch == (ECFManWrite1 | ECFManCreate1 | ECFManRename1)))
1548 ((TFsNotification*) notification)->NewName(_pathC);
1549 safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall);
1553 safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall);
1558 aTest.Printf(_L("(%d) - OVERFLOW\n"),threadID);
1564 //notificationType will only be of 1 type
1565 if(notificationType == TFsNotification::EFileChange)
1567 if(!(((aPackage.iNotifyType & TFsNotification::EFileChange) == TFsNotification::EFileChange) &&
1568 (aPackage.iOperation == t_notification::EFileWrite ||
1569 aPackage.iOperation == t_notification::EFileWrite_async ||
1570 aPackage.iOperation == t_notification::EFileWrite_samesize ||
1571 aPackage.iOperation == t_notification::EFileSetSize ||
1572 aPackage.iOperation == t_notification::ECFileManMove ||
1573 aPackage.iOperation == t_notification::EAllOps2 ||
1574 aPackage.iOperation == t_notification::EAllOps3)))
1575 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1577 if (aPackage.iOperation == t_notification::ECFileManMove)
1579 ((TFsNotification*) notification)->FileSize(fileSize);
1580 //File just been created and written to.
1583 scratch |= ECFManWrite1;
1585 else if(fileSize == 8)
1587 scratch |= ECFManWrite2;
1590 else if (aPackage.iNotifyType == TFsNotification::EFileChange)
1592 ((TFsNotification*) notification)->FileSize(fileSize);
1593 aTest.Printf(_L("Filesize - %d (%d)\n"),fileSize,threadID);
1594 //A notification is received every time the size is changed
1595 //due to the flushing
1596 if (aPackage.iOperation == t_notification::EFileWrite_async)
1598 //We write 52 letters
1599 if(fileSize != 52*(i+1))
1600 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1602 else if (aPackage.iOperation == t_notification::EFileWrite_samesize)
1604 //Only 4 letters in file
1606 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1608 else if (i < aPackage.iIterations)
1610 //We write/increase size by 4 letters/bytes
1611 if(fileSize != 4*(i+1))
1612 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1616 //We decrease size by 4 bytes
1617 if(fileSize != 4*(aPackage.iMaxNotifications-i))
1618 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1622 else if(notificationType == TFsNotification::ECreate)
1624 if(!(((aPackage.iNotifyType & TFsNotification::ECreate) == TFsNotification::ECreate) &&
1625 (aPackage.iOperation == t_notification::EFileCreate ||
1626 aPackage.iOperation == t_notification::EFileReplace ||
1627 aPackage.iOperation == t_notification::EFileCreate_subs ||
1628 aPackage.iOperation == t_notification::EFileCreate_subs_nowatch ||
1629 aPackage.iOperation == t_notification::EFileCreate_txt_nowatch ||
1630 aPackage.iOperation == t_notification::EFileCreate_txt ||
1631 aPackage.iOperation == t_notification::EFsMkDir ||
1632 aPackage.iOperation == t_notification::ECFileManMove ||
1633 aPackage.iOperation == t_notification::EAllOps1 ||
1634 aPackage.iOperation == t_notification::EAllOps2 ||
1635 aPackage.iOperation == t_notification::EAllOps3 ||
1636 aPackage.iOperation == t_notification::EAllOps4 ||
1637 aPackage.iOperation == t_notification::EAllOps5)))
1638 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1639 if (aPackage.iOperation == t_notification::EFileCreate_txt)
1641 //Check filename is of correct extension
1643 ((TFsNotification*) notification)->Path(_path);
1645 _ext.Append(_L(".txt"));
1647 ext.Append(_path.Right(4));
1648 safe_test(aTest,ext.Match(_ext),__LINE__,aPackage.iLineCall);
1650 else if (aPackage.iOperation == t_notification::ECFileManMove)
1652 if(scratch & ECFManCreate1)
1654 scratch |= ECFManCreate2; //File created second time
1658 scratch |= ECFManCreate1; //File created first time
1662 else if(notificationType == TFsNotification::EDelete)
1664 if(!(((aPackage.iNotifyType & TFsNotification::EDelete) == TFsNotification::EDelete) &&
1665 (aPackage.iOperation == t_notification::EFsDelete ||
1666 aPackage.iOperation == t_notification::EFsRmDir ||
1667 aPackage.iOperation == t_notification::EFsRmDir_nonEmpty ||
1668 aPackage.iOperation == t_notification::EFsRmDir_wild ||
1669 aPackage.iOperation == t_notification::ECFileManMove ||
1670 aPackage.iOperation == t_notification::EAllOps1 ||
1671 aPackage.iOperation == t_notification::EAllOps2 ||
1672 aPackage.iOperation == t_notification::EAllOps3 ||
1673 aPackage.iOperation == t_notification::EAllOps4)))
1674 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1676 if(aPackage.iOperation == t_notification::ECFileManMove)
1678 if(scratch & ECFManDelete1)
1680 scratch |= ECFManDelete2;
1684 scratch |= ECFManDelete1;
1688 else if(notificationType == TFsNotification::ERename)
1690 if(!(((aPackage.iNotifyType & TFsNotification::ERename) == TFsNotification::ERename) &&
1691 (aPackage.iOperation == t_notification::EFileRename ||
1692 aPackage.iOperation == t_notification::EFileRename_wild ||
1693 aPackage.iOperation == t_notification::EFsReplace ||
1694 aPackage.iOperation == t_notification::ECFileManMove ||
1695 aPackage.iOperation == t_notification::EFsRename ||
1696 aPackage.iOperation == t_notification::EFsRename_dir ||
1697 aPackage.iOperation == t_notification::EAllOps5)))
1698 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1700 ((TFsNotification*)notification)->NewName(newnameC);
1701 aTest.Printf(_L("%S - (%d)\n"),&newnameC,threadID);
1704 ((TFsNotification*) notification)->Path(_pathC);
1709 if (aPackage.iOperation == t_notification::EFsRename_dir)
1711 _path.Delete(_path.Length()-1,1);
1713 _path.Append(KPathDelimiter);
1715 else if (aPackage.iOperation == t_notification::EFileRename_wild)
1717 _path.Delete(_path.Length()-1,1);
1718 _path.AppendNum(numNotifications);
1725 if(aPackage.iOperation != t_notification::ECFileManMove)
1727 safe_test(aTest,newnameC.Match(_path),__LINE__,aPackage.iLineCall);
1729 else if(scratch & ECFManRename1)
1731 scratch |= ECFManRename2;
1735 scratch |= ECFManRename1;
1739 else if(notificationType == TFsNotification::EAttribute)
1741 if(!(((aPackage.iNotifyType & TFsNotification::EAttribute) == TFsNotification::EAttribute) &&
1742 (aPackage.iOperation == t_notification::EFsSetEntry ||
1743 aPackage.iOperation == t_notification::EFileSet ||
1744 aPackage.iOperation == t_notification::EFileSetAtt ||
1745 aPackage.iOperation == t_notification::EFileSetAtt_subs ||
1746 aPackage.iOperation == t_notification::ECFileManMove ||
1747 aPackage.iOperation == t_notification::EAllOps4)))
1748 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1751 ((TFsNotification*) notification)->Attributes(setAtt, clearAtt);
1753 if(aPackage.iOperation == t_notification::ECFileManMove)
1755 scratch |= ECFManAtt1;
1759 if(setAtt != KEntryAttHidden)
1760 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1761 if(clearAtt != KEntryAttReadOnly)
1762 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1765 else if(notificationType == TFsNotification::EMediaChange)
1767 if(!(((aPackage.iNotifyType & TFsNotification::EMediaChange) == TFsNotification::EMediaChange) &&
1768 (aPackage.iOperation == t_notification::EMount ||
1769 aPackage.iOperation == t_notification::EMountScan ||
1770 aPackage.iOperation == t_notification::EDismount ||
1771 aPackage.iOperation == t_notification::EMountDismount ||
1772 aPackage.iOperation == t_notification::EMediaCardInsertion ||
1773 aPackage.iOperation == t_notification::EMediaCardRemoval ||
1774 aPackage.iOperation == t_notification::EFormat ||
1775 aPackage.iOperation == t_notification::ECFileManMove ||
1776 aPackage.iOperation == t_notification::ERawDiskWrite)))
1777 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1779 else if(notificationType == TFsNotification::EDriveName)
1781 if(!(((aPackage.iNotifyType & TFsNotification::EDriveName) == TFsNotification::EDriveName) &&
1782 (aPackage.iOperation == t_notification::ESetDriveName ||
1783 aPackage.iOperation == t_notification::EAllOps6)))
1784 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1786 else if(notificationType == TFsNotification::EVolumeName)
1788 if(!(((aPackage.iNotifyType & TFsNotification::EVolumeName) == TFsNotification::EVolumeName) &&
1789 (aPackage.iOperation == t_notification::ESetVolumeLabel ||
1790 aPackage.iOperation == t_notification::EAllOps6)))
1791 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1794 ((TFsNotification*)notification)->NewName(newnameC);
1795 aTest.Printf(_L("New volume name: %S - (%d)\n"),&newnameC,threadID);
1799 notification = notify->NextNotification();
1800 if (notification == NULL)
1801 aTest.Printf(_L("Notification is NULL - (%d)\n"),threadID);
1804 if(i==1) //First iteration will only ever get 1 notification
1806 if(numNotifications != 1)
1807 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1810 if(numNotifications < aPackage.iMaxNotifications && !overflow) //Ensure we get all of the notifications we expected
1812 TRequestStatus status;
1813 notify->RequestNotifications(status);
1814 User::WaitForRequest(status);
1818 //0x307 = create1 | write1 | delete1 | rename1 | rename2
1819 if(aPackage.iOperation == t_notification::ECFileManMove && (scratch != 0x307))
1821 aTest.Printf(_L("CFileManMove test failure - scratch = 0x%x"),scratch);
1822 safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1828 * Watches for changes in files/directories.
1829 * Used in TestMultipleNotificationsL().
1831 TInt MultipleNotificationsTFWatcher(TAny* aAny)
1833 CTrapCleanup* cleanup;
1834 cleanup = CTrapCleanup::New();
1837 TUint64 threadID = thread.Id().Id();
1839 SThreadPackageMultiple package = *(SThreadPackageMultiple*) aAny;
1840 RTest multipleWatcherTest(_L("MultipleNotificationsTFWatcher"));
1841 multipleWatcherTest.Start(_L("MultipleNotificationsTFWatcher"));
1846 multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher (%d) - Create CFsNotify\n"),threadID);
1847 CFsNotify* notify = NULL;
1848 TRAPD(r,notify = CFsNotify::NewL(fs,package.iBufferSize));
1849 safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1852 if(package.iNotifyType != TFsNotification::EMediaChange &&
1853 package.iNotifyType != TFsNotification::EDriveName &&
1854 package.iNotifyType != TFsNotification::EVolumeName &&
1855 package.iOperation != t_notification::EAllOps6)
1857 path.Append(gDriveToTest);
1858 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1859 path.Append(package.iFileName);
1860 filename.Append(package.iString);
1864 path.Append((TChar)globalDriveNum+(TChar)'A');
1865 path.Append(_L(":"));
1868 fullname.Append(path);
1869 fullname.Append(filename);
1871 if (package.iNotifyType == TFsNotification::EVolumeName ||
1872 package.iOperation == t_notification::EAllOps6)
1874 //Ensure volume has no label
1875 multipleWatcherTest.Printf(_L("Set volume label to nothing\n"));
1876 r = fs.SetVolumeLabel(_L(""),globalDriveNum);
1877 safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1880 if (package.iNotifyType == TFsNotification::EDriveName ||
1881 package.iOperation == t_notification::EAllOps6)
1883 //Ensure drive has no name
1884 multipleWatcherTest.Printf(_L("Set drive name to nothing\n"));
1885 r = fs.SetDriveName(globalDriveNum,_L(""));
1886 safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1889 multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher - Add Notification for path %S\n"),&path);
1890 multipleWatcherTest.Printf(_L("Add Notification for type %u - (%d)\n"),(TUint)package.iNotifyType,threadID);
1891 r = notify->AddNotification((TUint)package.iNotifyType,path,filename);
1892 safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1894 TRequestStatus status;
1895 multipleWatcherTest.Printf(_L("(%d) - Request Notifications\n"),threadID);
1896 r = notify->RequestNotifications(status);
1897 safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1899 if (package.iOperation == t_notification::EMediaCardRemoval)
1901 multipleWatcherTest.Printf(_L("*****************************************************************\n"));
1902 multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
1903 multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the removal of the media card.\n"));
1904 multipleWatcherTest.Printf(_L("PLEASE REMOVE THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
1905 multipleWatcherTest.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
1906 multipleWatcherTest.Printf(_L("*****************************************************************\n"));
1908 if (package.iOperation == t_notification::EMediaCardInsertion)
1910 multipleWatcherTest.Printf(_L("*******************************************************************\n"));
1911 multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
1912 multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the insertion of the media card.\n"));
1913 multipleWatcherTest.Printf(_L("PLEASE INSERT THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
1914 multipleWatcherTest.Printf(_L("*******************************************************************\n"));
1917 multipleWatcherTest.Printf(_L("(%d) - Signal Test thread to start Doer thread\n"),threadID);
1918 package.iBarrier.Signal();
1919 User::WaitForRequest(status);
1921 multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
1923 //Handles the notifications
1924 HandleMultipleNotifications(multipleWatcherTest, package, notify, (TDesC&)fullname);
1926 multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
1930 multipleWatcherTest.End();
1931 multipleWatcherTest.Close();
1937 * TestTwoNotificationsL - Tests File Write, 1 Doer writes to a file twice.
1938 * 1 Watcher watches for file write changes. Just so happens that the second one overflows.
1940 TInt TestTwoNotificationsL()
1942 test.Next(_L("TestTwoNotifications"));
1946 RSemaphore twoNotificationsDoerBar;
1947 SThreadPackageMultiple package;
1948 _LIT(KFileName,"file0.write");
1949 package.iIterations = 10;
1950 package.iOperation = t_notification::EFileWrite;
1951 package.iNotifyType = TFsNotification::EFileChange;
1952 package.iFileName = KFileName;
1953 package.iBufferSize = 100; //Should get changed to KMin... in CFsNotify::NewL
1955 User::LeaveIfError(twoNotificationsDoerBar.CreateLocal(0));
1956 User::LeaveIfError(package.iBarrier.CreateLocal(0));
1960 TInt r = watcher.Create(_L("TestTwoNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1962 r = doer.Create(_L("TestTwoNotificationsDoerThread"),TwoNotificationsTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1964 test.Next(_L("TestTwoNotifications - Resume Watcher"));
1966 test.Next(_L("TestTwoNotifications - Wait for Watcher to be ready"));
1967 package.iBarrier.Wait(); //Wait till Watcher has requested notification
1968 test.Next(_L("TestTwoNotifications - Resume Doer"));
1971 test.Next(_L("TestTwoNotifications - Wait for doer thread death"));
1972 TRequestStatus status;
1974 User::WaitForRequest(status);
1975 test(doer.ExitReason()==KErrNone);
1977 test.Next(_L("TestTwoNotifications - Wait for watcher thread death"));
1978 watcher.Logon(status);
1979 User::WaitForRequest(status);
1980 test(watcher.ExitReason()==KErrNone);
1982 CLOSE_AND_WAIT(doer);
1983 CLOSE_AND_WAIT(watcher);
1985 twoNotificationsDoerBar.Close();
1986 package.iBarrier.Close();
1994 * Watch two threads to receive two notifications.
1995 * Used in TestTwoDoersL().
1997 TInt TestTwoDoersWatcher(TAny* aAny)
1999 CTrapCleanup* cleanup;
2000 cleanup = CTrapCleanup::New();
2002 RSemaphore& twoThreadsBarrier = *(RSemaphore*)aAny;
2003 RTest twoThreadsWatcherTest(_L("TwoThreadsWatcher"));
2004 twoThreadsWatcherTest.Start(_L("TwoThreadsWatcher"));
2009 twoThreadsWatcherTest.Next(_L("Create CFsNotify"));
2010 CFsNotify* notify = NULL;
2011 TRAPD(r,notify = CFsNotify::NewL(fs,200));
2012 twoThreadsWatcherTest(r == KErrNone);
2018 path1.Append(gDriveToTest);
2019 path2.Append(gDriveToTest);
2020 path1.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
2021 filename1.Append(_L("file1.create"));
2022 path2.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
2023 filename2.Append(_L("file2.create"));
2025 fullname1.Append(path1);
2026 fullname1.Append(filename1);
2028 fullname2.Append(path2);
2029 fullname2.Append(filename2);
2031 twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path1);
2032 r = notify->AddNotification((TUint)TFsNotification::ECreate,path1,filename1);
2033 twoThreadsWatcherTest(r == KErrNone);
2035 twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path2);
2036 r = notify->AddNotification((TUint)TFsNotification::ECreate,path2,filename2);
2037 twoThreadsWatcherTest(r == KErrNone);
2039 TRequestStatus status;
2040 twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Request Notifications"));
2041 r = notify->RequestNotifications(status);
2042 twoThreadsWatcherTest(r == KErrNone);
2044 twoThreadsBarrier.Signal(); //Signal Doer threads to start
2045 User::WaitForRequest(status);
2047 // We should be getting 2 notifications
2048 // Test notifications are not null and check notification types and paths
2049 // 1st notification:
2050 twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification"));
2051 const TFsNotification* notification = notify->NextNotification();
2052 twoThreadsWatcherTest(notification != NULL);
2053 twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Type"));
2054 TFsNotification::TFsNotificationType notificationType = ((TFsNotification*)notification)->NotificationType();
2055 twoThreadsWatcherTest(notificationType == TFsNotification::ECreate);
2056 twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Path"));
2058 ((TFsNotification*)notification)->Path(_pathC);
2059 twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - First Notification Path returned %S\n"),&_pathC);
2062 //We can't guarantee which thread ran first so check that it was either path1 or path2
2063 twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone);
2065 // 2nd notification:
2066 twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification"));
2067 notification = notify->NextNotification();
2068 // Check if next notification exists
2071 notify->RequestNotifications(status);
2072 User::WaitForRequest(status);
2073 notification = notify->NextNotification();
2075 twoThreadsWatcherTest(notification != NULL);
2076 twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Type"));
2077 notificationType = ((TFsNotification*)notification)->NotificationType();
2078 twoThreadsWatcherTest(notificationType == TFsNotification::ECreate);
2079 twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Path"));
2080 ((TFsNotification*)notification)->Path(_pathC);
2081 twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Second Notification Path returned %S\n"),&_pathC);
2083 twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone);
2087 twoThreadsWatcherTest.End();
2088 twoThreadsWatcherTest.Close();
2094 * TestTwoDoersL - Two Doer threads create a file each and there's one Watcher
2095 * which expects two notifications (one from each Doer).
2097 TInt TestTwoDoersL()
2099 test.Next(_L("TestTwoDoers"));
2104 _LIT(KFileName1,"file1.create");
2105 _LIT(KFileName2,"file2.create");
2106 RSemaphore simpleBarrierTest;
2107 SThreadPackage pkgDoer1;
2108 SThreadPackage pkgDoer2;
2109 pkgDoer1.iFileName = KFileName1;
2110 pkgDoer2.iFileName = KFileName2;
2112 User::LeaveIfError(pkgDoer1.iBarrier.CreateLocal(0));
2113 User::LeaveIfError(pkgDoer2.iBarrier.CreateLocal(0));
2114 User::LeaveIfError(simpleBarrierTest.CreateLocal(0));
2119 watcher.Create(_L("TestTwoDoers-WatcherThread"),TestTwoDoersWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&simpleBarrierTest);
2120 doer1.Create(_L("TestTwoDoers-DoerThread1"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer1);
2121 doer2.Create(_L("TestTwoDoers-DoerThread2"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer2);
2123 simpleBarrierTest.Wait(); //Wait until Watcher has created CFsNotify
2128 test.Next(_L("TestTwoDoers - Wait for doer1 thread death"));
2129 TRequestStatus status;
2130 doer1.Logon(status);
2131 User::WaitForRequest(status);
2132 test(doer1.ExitReason()==KErrNone);
2134 test.Next(_L("TestTwoDoers - Wait for doer2 thread death"));
2135 doer2.Logon(status);
2136 User::WaitForRequest(status);
2137 test(doer2.ExitReason()==KErrNone);
2139 test.Next(_L("TestTwoDoers - Wait for watcher thread death"));
2140 watcher.Logon(status);
2142 TInt r = timer1.CreateLocal();
2143 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
2144 TRequestStatus timeout;
2145 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
2146 timer1.After(timeout,time);
2147 User::WaitForRequest(timeout,status);
2148 test(status.Int() != KRequestPending);
2151 //User::WaitForRequest(status);
2152 test(watcher.ExitReason()==KErrNone);
2154 CLOSE_AND_WAIT(doer1);
2155 CLOSE_AND_WAIT(doer2);
2156 CLOSE_AND_WAIT(watcher);
2158 pkgDoer1.iBarrier.Close();
2159 pkgDoer2.iBarrier.Close();
2160 simpleBarrierTest.Close();
2166 * TestTwoWatchersL - Uses two watcher threads and one doer thread to test that running
2167 * two distinct sub sessions at the same time (both watch the same file).
2169 TInt TestTwoWatchersL()
2171 test.Next(_L("TestTwoWatchers"));
2174 _LIT(KFileName,"file.creat3");
2175 SThreadPackage pkgDoer;
2176 pkgDoer.iFileName = KFileName;
2178 SThreadPackage watcherPkg;
2179 watcherPkg.iFileName = KFileName;
2181 User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0));
2182 User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0));
2186 watcher.Create(_L("TestTwoWatchersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
2187 watcher2.Create(_L("TestTwoWatchersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
2188 doer.Create(_L("TestTwoWatchersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
2191 watcherPkg.iBarrier.Wait(); //Wait till both watchers have requested notification
2192 watcherPkg.iBarrier.Wait();
2195 test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
2196 TRequestStatus status;
2198 User::WaitForRequest(status);
2199 test(doer.ExitReason()==KErrNone);
2201 test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
2202 watcher.Logon(status);
2204 TInt r = timer1.CreateLocal();
2205 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
2206 TRequestStatus timeout;
2207 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
2208 timer1.After(timeout,time);
2209 User::WaitForRequest(timeout,status);
2210 test(status.Int() != KRequestPending);
2213 // User::WaitForRequest(status);
2214 test(watcher.ExitReason()==KErrNone);
2216 test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
2217 watcher2.Logon(status);
2219 r = timer2.CreateLocal();
2220 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
2221 TRequestStatus timeout2;
2222 timer2.After(timeout2,time);
2223 User::WaitForRequest(timeout2,status);
2224 test(status.Int() != KRequestPending);
2227 //User::WaitForRequest(status);
2228 test(watcher2.ExitReason()==KErrNone);
2230 CLOSE_AND_WAIT(doer);
2231 CLOSE_AND_WAIT(watcher);
2232 CLOSE_AND_WAIT(watcher2);
2234 pkgDoer.iBarrier.Close();
2235 watcherPkg.iBarrier.Close();
2242 * TestTwoWatchersTwoDoersL - Two watcher threads watches two different doer threads.
2244 TInt TestTwoWatchersTwoDoersL()
2246 test.Next(_L("TestTwoWatchersTwoDoers"));
2249 _LIT(KFileName1,"f1le.create");
2250 _LIT(KFileName2,"f2le.create");
2251 SThreadPackage package1;
2252 package1.iFileName = KFileName1;
2254 SThreadPackage package2;
2255 package2.iFileName = KFileName2;
2257 User::LeaveIfError(package1.iBarrier.CreateLocal(0));
2258 User::LeaveIfError(package2.iBarrier.CreateLocal(0));
2263 watcher.Create(_L("TestTwoWatchersTwoDoersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
2264 doer.Create(_L("TestTwoWatchersTwoDoersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
2266 watcher2.Create(_L("TestTwoWatchersTwoDoersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
2267 doer2.Create(_L("TestTwoWatchersTwoDoersDoer2Thread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
2270 package1.iBarrier.Wait(); //Wait till both watchers have requested notification
2271 package2.iBarrier.Wait();
2275 test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
2276 TRequestStatus status;
2278 User::WaitForRequest(status);
2279 test(doer.ExitReason()==KErrNone);
2281 test.Printf(_L("Wait for DOER2 to terminate , Line %d"),__LINE__);
2282 doer2.Logon(status);
2283 User::WaitForRequest(status);
2284 test(doer2.ExitReason()==KErrNone);
2286 test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
2287 watcher.Logon(status);
2289 TInt r = timer1.CreateLocal();
2290 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
2291 TRequestStatus timeout;
2292 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
2293 timer1.After(timeout,time);
2294 User::WaitForRequest(timeout,status);
2295 test(status.Int() != KRequestPending);
2298 test(watcher.ExitReason()==KErrNone);
2300 test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
2301 watcher2.Logon(status);
2303 r = timer2.CreateLocal();
2304 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
2305 TRequestStatus timeout2;
2306 timer2.After(timeout2,time);
2307 User::WaitForRequest(timeout2,status);
2308 test(status.Int() != KRequestPending);
2311 test(watcher2.ExitReason()==KErrNone);
2313 CLOSE_AND_WAIT(doer);
2314 CLOSE_AND_WAIT(doer2);
2315 CLOSE_AND_WAIT(watcher);
2316 CLOSE_AND_WAIT(watcher2);
2318 package1.iBarrier.Close();
2319 package2.iBarrier.Close();
2326 * Multi-purpose test
2328 * If aFailureExpected is ETrue, it is expected that the watcher thread is not terminated normally,
2329 * due to the notification(s) not being sent.
2330 * Since this function is called many times, aLineCall is used to show the line where it is called from.
2331 * See SThreadPackageMultiple.
2333 TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations,
2334 TInt aMaxNotifications, t_notification::EOperation aOperation,
2335 TUint aNotifyType, TInt aBufferSize, TBool aFailureExpected, TInt aLineCall)
2337 test.Next(_L("TestMultipleNotifications"));
2341 SThreadPackageMultiple package;
2342 package.iIterations = aIterations;
2343 package.iMaxNotifications = aMaxNotifications;
2344 package.iOperation = aOperation;
2345 package.iNotifyType = (TFsNotification::TFsNotificationType)aNotifyType;
2346 package.iString = aString;
2347 package.iFileName = aFilename;
2348 package.iBufferSize = aBufferSize;
2349 package.iLineCall = aLineCall;
2351 User::LeaveIfError(package.iBarrier.CreateLocal(0));
2355 User::LeaveIfError(tim.CreateLocal());
2357 TInt r = watcher.Create(_L("TestMultipleNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
2358 safe_test(test,r,__LINE__,package.iLineCall);
2359 r = doer.Create(_L("TestMultipleNotificationsDoerThread"),MultipleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
2360 safe_test(test,r,__LINE__,package.iLineCall);
2361 test.Next(_L("TestMultipleNotifications - Resume Watcher"));
2363 test.Next(_L("TestMultipleNotifications - Wait for Watcher to be ready"));
2364 package.iBarrier.Wait(); //Wait till Watcher has requested notification
2365 test.Next(_L("TestMultipleNotifications - Resume Doer"));
2368 test.Next(_L("TestMultipleNotifications - Wait for doer thread death"));
2369 TRequestStatus status;
2371 User::WaitForRequest(status);
2372 test.Printf(_L("TestMultipleNotifications - Doer Exit Reason %d\n"),doer.ExitReason());
2373 safe_test(test,doer.ExitReason(),__LINE__,package.iLineCall);
2375 TRequestStatus timStatus;
2376 TTimeIntervalMicroSeconds32 timeout;
2377 if (aFailureExpected && !(package.iOperation == t_notification::EMediaCardInsertion ||
2378 package.iOperation == t_notification::EMediaCardRemoval))
2380 timeout = 1500000; //1.5 seconds, we don't want to wait too long if we expect it to fail
2384 timeout = 10000000; //10 seconds
2386 tim.After(timStatus,timeout);
2388 test.Next(_L("TestMultipleNotifications - Wait for watcher thread death or timeout"));
2389 watcher.Logon(status);
2390 User::WaitForRequest(status,timStatus);
2391 if(!(status != KRequestPending || aFailureExpected))
2392 safe_test(test,KErrGeneral,__LINE__,package.iLineCall);
2394 test.Printf(_L("TestMultipleNotifications - Watcher Exit Reason %d\n"),watcher.ExitReason());
2395 safe_test(test,watcher.ExitReason(),__LINE__,package.iLineCall);
2397 CLOSE_AND_WAIT(doer);
2399 if(status == KRequestPending)
2401 watcher.Kill(KErrTimedOut);
2402 test.Printf(_L("TestMultipleNotifications - Watcher timed out\n"));
2404 CLOSE_AND_WAIT(watcher);
2406 package.iBarrier.Close();
2409 test.Printf(_L("----------------------------------------------------------------------\n"));
2413 TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations,
2414 TInt aMaxNotifications, t_notification::EOperation aOperation,
2415 TFsNotification::TFsNotificationType aNotifyType, TInt aBufferSize,
2416 TBool aFailureExpected, TInt aLineCall)
2418 return TestMultipleNotificationsL(aFilename, aString, aIterations, aMaxNotifications, aOperation,
2419 (TUint)aNotifyType, aBufferSize, aFailureExpected, aLineCall);
2422 TInt TestMultipleNotificationsL(const TDesC& aFilename, TInt aIterations, TInt aMaxNotifications,
2423 t_notification::EOperation aOperation, TUint aNotifyType, TInt aBufferSize,
2424 TBool aFailureExpected, TInt aLineCall)
2426 return TestMultipleNotificationsL(aFilename,_L(""), aIterations, aMaxNotifications, aOperation, aNotifyType,
2427 aBufferSize, aFailureExpected, aLineCall);
2431 // Watcher for TestAddRemoveNotificationL()
2432 TInt TestAddRemoveNotificationWatcher(TAny* aAny)
2434 CTrapCleanup* cleanup;
2435 cleanup = CTrapCleanup::New();
2437 TUint64 threadId = thread.Id().Id();
2439 SThreadPackage pkgDoer = *(SThreadPackage*)aAny;
2440 RSemaphore& addRemoveBarrier = pkgDoer.iBarrier;
2442 RTest addRemoveWatcherTest(_L("TestAddRemoveNotificationWatcher"));
2443 addRemoveWatcherTest.Start(_L("TestAddRemoveNotificationWatcher"));
2448 addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
2449 CFsNotify* notify = NULL;
2450 TRAPD(r,notify = CFsNotify::NewL(fs,100); );
2451 addRemoveWatcherTest( r == KErrNone);
2454 path.Append(gDriveToTest);
2455 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
2456 filename.Append(pkgDoer.iFileName);
2458 addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher - Add Notification for %S\n"),&path);
2459 r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
2460 addRemoveWatcherTest(r==KErrNone);
2461 addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Remove Notifications\n"),threadId);
2462 r = notify->RemoveNotifications();
2463 addRemoveWatcherTest(r==KErrNone);
2464 addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Request Notifications\n"),threadId);
2465 TRequestStatus status;
2466 r = notify->RequestNotifications(status);
2467 addRemoveWatcherTest(r==KErrNone);
2468 addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher status = %d"),status.Int());
2469 addRemoveBarrier.Signal();
2471 addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - NextNotification\n"),threadId);
2472 //We should not be getting any notifications as the notification request has been removed
2473 const TFsNotification* notification = notify->NextNotification();
2474 addRemoveWatcherTest(notification == NULL);
2478 addRemoveWatcherTest.End();
2479 addRemoveWatcherTest.Close();
2486 * TestAddRemoveNotificationL - Watcher adds and removes notification request.
2487 * Any changes by doer thread should not be detected.
2489 TInt TestAddRemoveNotificationL()
2491 test.Next(_L("TestAddRemoveNotification"));
2495 SThreadPackage package;
2496 _LIT(KFileName,"noFile.create");
2497 package.iFileName = KFileName;
2499 User::LeaveIfError(package.iBarrier.CreateLocal(0));
2503 watcher.Create(_L("TestAddRemoveNotification-WatcherThread"),TestAddRemoveNotificationWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
2504 doer.Create(_L("TestAddRemoveNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
2507 test.Printf(_L("TestAddRemoveNotification - Wait until Watcher has created CFsNotify\n"));
2508 package.iBarrier.Wait(); //Wait until Watcher has created CFsNotify
2511 test.Next(_L("TestAddRemoveNotification - Wait for doer thread death"));
2512 TRequestStatus status;
2514 User::WaitForRequest(status);
2515 test(doer.ExitReason()==KErrNone);
2517 test.Next(_L("TestAddRemoveNotification - Wait for watcher thread death"));
2518 watcher.Logon(status);
2520 TInt r = timer1.CreateLocal();
2521 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
2522 TRequestStatus timeout;
2523 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
2524 timer1.After(timeout,time);
2525 User::WaitForRequest(timeout,status);
2526 test(status.Int() != KRequestPending);
2529 test.Printf(_L("Test - Watcher Exit Reason %d\n"),watcher.ExitReason());
2530 test(watcher.ExitReason()==KErrNone);
2532 CLOSE_AND_WAIT(doer);
2533 CLOSE_AND_WAIT(watcher);
2535 package.iBarrier.Close();
2542 * Adds and cancels notification request.
2543 * Used in TestCancelNotificationL().
2545 TInt TestCancelNotificationWatcher(TAny* aAny)
2547 CTrapCleanup* cleanup;
2548 cleanup = CTrapCleanup::New();
2550 RTest cancelNotificationsWatcherTest(_L("TestCancelNotificationWatcher"));
2551 cancelNotificationsWatcherTest.Start(_L("TestCancelNotificationWatcher"));
2554 TUint64 threadId = thread.Id().Id();
2556 SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny;
2557 RSemaphore& addRemoveBarrier = pkgDoer.iBarrier;
2558 RSemaphore& addRemoveBarrier2 = pkgDoer.iBarrier2;
2563 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
2564 CFsNotify* notify = NULL;
2565 TRAPD(r,notify = CFsNotify::NewL(fs,100); );
2566 cancelNotificationsWatcherTest(r == KErrNone);
2569 path.Append(gDriveToTest);
2570 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
2571 filename.Append(pkgDoer.iFileName);
2573 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher - Add Notification for %S\n"),&path);
2574 r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
2575 cancelNotificationsWatcherTest(r==KErrNone);
2576 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Request Notifications\n"),threadId);
2577 TRequestStatus status;
2578 r = notify->RequestNotifications(status);
2579 cancelNotificationsWatcherTest(r==KErrNone);
2581 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Cancel Notifications\n"),threadId);
2582 r = notify->CancelNotifications(status);
2583 cancelNotificationsWatcherTest(r==KErrNone);
2585 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Signal W1 - Start doer\n"),threadId);
2586 addRemoveBarrier.Signal(); //W1 - Start doer
2588 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Wait S1 - doer complete\n"),threadId);
2589 addRemoveBarrier2.Wait(); //S1 - Wait for doer to have created file
2591 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - NextNotification\n"),threadId);
2592 //We should not be getting any notifications as the notification request has been removed
2593 const TFsNotification* notification = notify->NextNotification();
2594 cancelNotificationsWatcherTest(notification == NULL);
2598 cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Complete\n"),threadId);
2599 cancelNotificationsWatcherTest.End();
2600 cancelNotificationsWatcherTest.Close();
2607 * TestCancelNotificationL - Watcher adds and cancels notification request.
2609 TInt TestCancelNotificationL()
2611 test.Next(_L("TestCancelNotification"));
2615 SThreadPackageDualSemaphore package;
2616 _LIT(KFileName,"cancel.create");
2617 package.iFileName = KFileName;
2619 User::LeaveIfError(package.iBarrier.CreateLocal(0));
2620 User::LeaveIfError(package.iBarrier2.CreateLocal(0));
2624 TInt r = watcher.Create(_L("TestCancelNotification-WatcherThread"),TestCancelNotificationWatcher,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
2625 test(r == KErrNone);
2626 r = doer.Create(_L("TestCancelNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
2627 test(r == KErrNone);
2628 test.Printf(_L("TestCancelNotificationL - Watcher.Resume()"));
2630 test.Printf(_L("TestCancelNotificationL - Waiting on package.iBarrier.Wait()"));
2631 package.iBarrier.Wait(); //W1 - Wait until Watcher has created CFsNotify
2632 test.Printf(_L("TestCancelNotificationL -Doer Resume"));
2633 TRequestStatus status;
2637 test.Next(_L("TestCancelNotification - Wait for doer thread death"));
2638 User::WaitForRequest(status);
2639 test(doer.ExitReason()==KErrNone);
2641 package.iBarrier2.Signal(); //S1
2643 test.Next(_L("TestCancelNotification - Wait for watcher thread death"));
2644 watcher.Logon(status);
2647 r = tim.CreateLocal();
2650 TRequestStatus timStatus;
2651 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
2652 tim.After(timStatus,time);
2654 User::WaitForRequest(status,timStatus);
2655 test(status!=KRequestPending);
2656 test(watcher.ExitReason()==KErrNone);
2658 CLOSE_AND_WAIT(doer);
2659 CLOSE_AND_WAIT(watcher);
2661 package.iBarrier.Close();
2662 package.iBarrier2.Close();
2669 * Test that if we close the session
2670 * before closing the subsession (deleting CFsNotify)
2671 * that everything is A-Ok.
2673 TInt TestSessionCloseTF(TAny* aTestCase)
2675 CTrapCleanup* cleanup;
2676 cleanup = CTrapCleanup::New();
2681 RDebug::Printf("TestSessionClose\n");
2683 SThreadPackage2 package = *(SThreadPackage2*)aTestCase;
2684 package.iBarrier.Signal();
2686 switch(package.iTestCase)
2690 RDebug::Printf("TestSessionCloseTF - Case 1 - NewL\n");
2691 CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize);
2692 User::LeaveIfNull(notify);
2694 RDebug::Printf("TestSessionCloseTF - Case 1 - Fs.Close\n");
2698 path.Append((TChar)gDriveToTest);
2699 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
2702 filename.Append(_L("session.close"));
2704 CleanupStack::PushL(notify);
2706 RDebug::Printf("TestSessionCloseTF - Case 1 - Add Notification - Panic Expected\n");
2707 r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
2708 User::LeaveIfError(r);
2710 RDebug::Printf("TestSessionCloseTF - Case 1 - After Session Close\n");
2712 CleanupStack::Pop(notify);
2714 RDebug::Printf("TestSessionCloseTF - Case 1 - After Delete Notify\n");
2720 RDebug::Printf("TestSessionCloseTF - Case 2 - NewL\n");
2721 CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize);
2722 User::LeaveIfNull(notify);
2725 path.Append((TChar)gDriveToTest);
2726 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
2728 filename.Append(_L("session.close"));
2730 RDebug::Printf("TestSessionCloseTF - Case 2 - Add Notification\n");
2731 r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
2734 RDebug::Printf("TestSessionCloseTF - Case 2 - Fs.Close\n");
2737 CleanupStack::PushL(notify);
2738 TRequestStatus status;
2739 RDebug::Printf("TestSessionCloseTF - Case 2 - Request Notification - Panic Expected\n");
2740 r = notify->RequestNotifications(status);
2741 CleanupStack::Pop(notify);
2743 RDebug::Printf("TestSessionCloseTF - Case 2 - After Delete Notify\n");
2758 * Test that if we close the session
2759 * before closing the subsession (deleting CFsNotify)
2760 * that everything is A-Ok.
2762 void TestSessionClose(TInt aTestCase)
2765 User::LeaveIfError(sem.CreateLocal(0));
2767 SThreadPackage2 package;
2768 package.iTestCase = aTestCase;
2769 package.iBarrier = sem;
2772 thread.Create(_L("TestSessionClose"),TestSessionCloseTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
2777 TRequestStatus status;
2778 thread.Logon(status);
2779 User::WaitForRequest(status);
2780 test.Printf(_L("Kern-Exec 0 is EXPECTED\n"));
2781 TInt err = thread.ExitReason();
2782 test(err == KErrNone);
2783 TExitType et = thread.ExitType();
2784 test(et == EExitPanic);
2785 CLOSE_AND_WAIT(thread);
2789 const TInt KNotificationOverflowIterationLimit = 7;
2792 * Does stuff for TestOverflowL
2793 * Synchronises such that watchers have seen 1 change.
2794 * Then fills their buffers up to KNotificationOverflowIterationLimit.
2797 TInt TestOverflowDoerTF(TAny* aAny)
2802 SThreadPackage& package = *(SThreadPackage*) aAny;
2805 path.Append((TChar)gDriveToTest);
2806 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
2807 path.Append(package.iFileName);
2812 TInt r = file.Replace(fs,path,EFileWrite);
2813 User::LeaveIfError(r);
2815 //Perform first set size.
2816 r = file.SetSize(1);
2817 User::LeaveIfError(r);
2819 //Wait until both watchers have received this change.
2820 package.iBarrier.Wait();
2822 for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++)
2833 * Thread function used as part of TestOverflowL
2834 * Counts the number of notifications and ensures it the correct number before overflow is received#
2836 TInt TestOverflowWatcher1TF(TAny* aAny)
2838 CTrapCleanup* cleanup;
2839 cleanup = CTrapCleanup::New();
2841 RTest overflowTest(_L("TestOverflowWatcher1TF"));
2842 overflowTest.Start(_L("TestOverflowWatcher1TF"));
2844 SThreadPackage& package = *(SThreadPackage*) aAny;
2849 path.Append((TChar)gDriveToTest);
2850 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
2851 filename.Append(package.iFileName);
2853 TRequestStatus status;
2854 CFsNotify* notify = NULL;
2856 //This notification's size is 80.
2858 // -4 means we should get 6 notifications
2859 //Except the first one will still be in the buffer
2860 // (as we've not called RequestNotification yet) so we'll only actually get 5.
2861 TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4));
2862 test(r == KErrNone);
2863 User::LeaveIfNull(notify);
2864 notify->AddNotification(TFsNotification::EFileChange,path,filename);
2865 notify->RequestNotifications(status);
2867 //Signal that we are ready for doer to start (W1)
2868 package.iBarrier.Signal();
2870 //We wait for the 1 notification (doer only does 1 at first)
2871 User::WaitForRequest(status);
2873 overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
2874 const TFsNotification *notification = notify->NextNotification();
2876 TFsNotification::TFsNotificationType type = notification->NotificationType();
2877 overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
2879 //Signal the test thread (W2)
2880 package.iBarrier.Signal();
2881 //Wait for Signal to continue (W3);
2882 package.iBarrier.Wait();
2884 notify->RequestNotifications(status);
2885 User::WaitForRequest(status);
2888 overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
2889 notification = notify->NextNotification();
2890 while(notification != NULL)
2893 type = notification->NotificationType();
2894 overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
2895 if(type & TFsNotification::EOverflow)
2899 overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
2901 overflowTest.Close();
2905 notification = notify->NextNotification();
2908 overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
2911 overflowTest.Close();
2921 * As some of the tests above assume sucess if they receive an overflow
2922 * we need to ensure that overflow works properly!
2924 TInt TestOverflowL()
2927 * The scheme used is as follows:
2928 * 1 Doer thread which is setting the size of a file, over and over.
2931 * The doer thread does 1 operation then waits on a signal.
2932 * The watcher thread requests notification and receives 1 notification.
2933 * It then signals the Doer thread.
2935 * The doer thread continues doing setsize until the number of notifications
2936 * should have overflowed.
2938 * The watcher Waits for a signal from doer (that all of the notifications have been sent).
2939 * The watcher's last notification should be an overflow
2941 test.Next(_L("TestOverflow"));
2943 TInt r = fs.Connect();
2944 test(r == KErrNone);
2945 _LIT(KFileName,"over.flow");
2946 SThreadPackage doerPkg;
2947 doerPkg.iFileName = KFileName;
2949 SThreadPackage watcher1Pkg;
2950 watcher1Pkg.iFileName = KFileName;
2952 User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0));
2953 User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0));
2956 watcher1.Create(_L("TestOverflowWatcher1Thread"),TestOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
2957 doer.Create(_L("TestOverflowDoerThread"),TestOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
2960 //Wait until Request has been requested. (W1)
2961 watcher1Pkg.iBarrier.Wait();
2965 //Wait till watcher has received first notification (W2)
2966 watcher1Pkg.iBarrier.Wait();
2968 //Signal the doer that it is free to continue
2969 //doing the rest of the operations
2970 doerPkg.iBarrier.Signal();
2972 test.Next(_L("TestOverflow - Wait for doer thread death"));
2973 TRequestStatus status;
2975 User::WaitForRequest(status);
2976 test(doer.ExitReason()==KErrNone);
2977 CLOSE_AND_WAIT(doer);
2979 //Wait until doer has finished doing notifications
2980 //thus the watcher should receive an overflow
2982 watcher1Pkg.iBarrier.Signal();
2985 r = tim.CreateLocal();
2987 TRequestStatus timStatus;
2989 test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
2990 TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds
2991 tim.After(timStatus,interval);
2992 watcher1.Logon(status);
2993 User::WaitForRequest(status,timStatus);
2994 test(status != KRequestPending);
2996 * The number of notifications returned here should be 5.
2999 * The first notification means that the buffer has lost 80 (the size of this
3000 * particular notification). Even though the client has read it becase they've not called
3001 * RequestNotification the server doesn't know that yet so that's why it's 5 not 6.
3003 * That leaves 556 - 80. Which means only 5 notifications will fit.
3005 TInt count = watcher1.ExitReason();
3008 CLOSE_AND_WAIT(watcher1);
3009 watcher1Pkg.iBarrier.Close();
3010 doerPkg.iBarrier.Close();
3017 * Does stuff for TestPostOverflowL
3018 * Synchronises such that watchers have seen 1 change.
3019 * Then fills their buffers up to KNotificationOverflowIterationLimit.
3020 * Then continues to request changes and akes sure that it gets 3 non-overflow notifications
3023 TInt TestPostOverflowDoerTF(TAny* aAny)
3028 SThreadPackage& package = *(SThreadPackage*) aAny;
3031 path.Append((TChar)gDriveToTest);
3032 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
3033 path.Append(package.iFileName);
3038 TInt r = file.Replace(fs,path,EFileWrite);
3039 User::LeaveIfError(r);
3041 //Perform first set size.
3042 r = file.SetSize(1);
3043 User::LeaveIfError(r);
3045 //Wait until both watchers have received this change.
3047 package.iBarrier.Wait();
3049 for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++)
3059 TInt HandlePostOverflow(SThreadPackage& aPackage, CFsNotify* aNotify)
3061 TRequestStatus status;
3062 TInt r = aNotify->RequestNotifications(status);
3063 test(r == KErrNone);
3064 //Signal that overflow has been found (W4)
3065 aPackage.iBarrier.Signal();
3067 User::WaitForRequest(status);
3069 const TFsNotification* notification = NULL;
3072 notification = aNotify->NextNotification();
3073 test(notification != NULL);
3075 //3 set sizes will be done (Sx)
3076 aPackage.iBarrier.Wait();
3080 TUint type = notification->NotificationType();
3081 if(type & TFsNotification::EOverflow)
3083 return KErrOverflow;
3085 notification = aNotify->NextNotification();
3086 if(notification == NULL)
3088 r = aNotify->RequestNotifications(status);
3089 test(r == KErrNone);
3090 User::WaitForRequest(status);
3091 notification = aNotify->NextNotification();
3093 test(notification != NULL);
3101 * Thread function used as part of TestOverflowL
3102 * Counts the number of notifications and ensures it the correct number before overflow is received#
3104 TInt TestPostOverflowWatcher1TF(TAny* aAny)
3106 CTrapCleanup* cleanup;
3107 cleanup = CTrapCleanup::New();
3109 RTest overflowTest(_L("TestOverflowWatcher1TF"));
3110 overflowTest.Start(_L("TestOverflowWatcher1TF"));
3112 SThreadPackage& package = *(SThreadPackage*) aAny;
3117 path.Append((TChar)gDriveToTest);
3118 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
3119 filename.Append(package.iFileName);
3121 TRequestStatus status;
3122 CFsNotify* notify = NULL;
3124 //This notification's size is 80.
3126 // -4 means we should get 6 notifications
3127 //Except the first one will still be in the buffer
3128 // (as we've not called RequestNotification yet) so we'll only actually get 5.
3129 TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4));
3130 test(r == KErrNone);
3131 User::LeaveIfNull(notify);
3132 notify->AddNotification(TFsNotification::EFileChange,path,filename);
3133 notify->RequestNotifications(status);
3135 //Signal that we are ready for doer to start (W1)
3136 package.iBarrier.Signal();
3138 //We wait for the 1 notification (doer only does 1 at first)
3139 User::WaitForRequest(status);
3141 overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
3142 const TFsNotification *notification = notify->NextNotification();
3144 TFsNotification::TFsNotificationType type = notification->NotificationType();
3145 overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
3147 //Signal the test thread (W2)
3148 package.iBarrier.Signal();
3149 //Wait for Signal to continue (W3);
3150 package.iBarrier.Wait();
3152 notify->RequestNotifications(status);
3153 User::WaitForRequest(status);
3155 TInt handlePostOverflow = 0;
3157 overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
3158 notification = notify->NextNotification();
3159 while(notification != NULL)
3162 type = notification->NotificationType();
3163 overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
3164 if(type & TFsNotification::EOverflow)
3166 overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
3167 if(handlePostOverflow)
3169 count = HandlePostOverflow(package,notify);
3174 overflowTest.Close();
3177 notification = notify->NextNotification();
3181 handlePostOverflow = 1;
3183 overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
3186 overflowTest.Close();
3194 TInt TestPostOverflowNotifications()
3196 test.Next(_L("TestPostOverflowNotifications"));
3198 TInt r = fs.Connect();
3199 test(r == KErrNone);
3200 _LIT(KFileName,"post.over");
3201 SThreadPackage doerPkg;
3202 doerPkg.iFileName = KFileName;
3204 SThreadPackage watcher1Pkg;
3205 watcher1Pkg.iFileName = KFileName;
3207 User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0));
3208 User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0));
3211 watcher1.Create(_L("TestPostOverflowWatcher1Thread"),TestPostOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
3212 doer.Create(_L("TestPostOverflowDoerThread"),TestPostOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
3215 //Wait until Request has been requested. (W1)
3216 watcher1Pkg.iBarrier.Wait();
3220 //Wait till watcher has received first notification (W2)
3221 watcher1Pkg.iBarrier.Wait();
3223 //Signal the doer that it is free to continue
3224 //doing the rest of the operations (D-W-1)
3225 doerPkg.iBarrier.Signal();
3227 test.Next(_L("TestOverflow - Wait for doer thread death"));
3228 TRequestStatus status;
3230 User::WaitForRequest(status);
3231 test(doer.ExitReason()==KErrNone);
3232 CLOSE_AND_WAIT(doer);
3234 //Wait until doer has finished doing notifications
3235 //thus the watcher should receive an overflow
3237 watcher1Pkg.iBarrier.Signal();
3240 //wait for the watcher to have processed the first overflow
3241 //and to have requested notification.
3242 //Then we will perform some actions here
3243 // The watcher will wait on the semaphore until we are doing
3244 // doing all the operations we want to do
3245 // then it should process next notification
3246 watcher1Pkg.iBarrier.Wait(); //W4
3249 path.Append((TChar)gDriveToTest);
3250 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
3251 path.Append(watcher1Pkg.iFileName);
3253 r = file.Open(fs,path,EFileWrite);
3256 r = file.SetSize(1);
3258 r = file.SetSize(2);
3260 r = file.SetSize(3);
3264 watcher1Pkg.iBarrier.Signal(); // Signal post operations complete (Sx)
3267 r = tim.CreateLocal();
3269 TRequestStatus timStatus;
3271 test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
3272 TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds
3273 tim.After(timStatus,interval);
3274 watcher1.Logon(status);
3275 User::WaitForRequest(status,timStatus);
3276 test(status != KRequestPending);
3278 * The number of notifications returned here should be 3.
3281 * The first notification means that the buffer has lost 80 (the size of this
3282 * particular notification). Even though the client has read it becase they've not called
3283 * RequestNotification the server doesn't know that yet so that's why it's 5 not 6.
3285 * That leaves 556 - 80. Which means only 5 notifications will fit.
3287 * Then overflow occurs.
3289 * Then count is reset and 3 more operations are performed.
3291 TInt count = watcher1.ExitReason();
3294 CLOSE_AND_WAIT(watcher1);
3295 watcher1Pkg.iBarrier.Close();
3296 doerPkg.iBarrier.Close();
3303 * Call AddNotification with a file without a path nor drive
3305 void TestNonDriveFilters()
3307 test.Next(_L("TestNonDriveFilters"));
3309 TInt r = fs.Connect();
3313 r = fs.DriveList(drives);
3316 CFsNotify* notify = NULL;
3317 TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
3320 testfile.Append(_L("test.file"));
3322 r = notify->AddNotification((TUint)TFsNotification::ECreate,_L(""),testfile);
3325 TRequestStatus status;
3326 r = notify->RequestNotifications(status);
3330 path.Append((TChar)gDriveToTest);
3331 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
3334 fullname.Append(path);
3335 fullname.Append(testfile);
3338 r = fs.MkDirAll(path);
3339 test(r==KErrNone || r==KErrAlreadyExists);
3340 r = file.Replace(fs,fullname,EFileWrite);
3344 fs.Delete(fullname);
3346 TChar testDrive = (TChar)gDriveToTest;
3347 testDrive.UpperCase();
3349 //Also create the file on another drive;
3350 for(TInt i = 0; i < KMaxDrives; i++)
3352 TChar drive = drives[i];
3353 if(drive == testDrive)
3358 TText16 drive16 = (TText16)(i+(TChar)'A');
3359 fullname.operator [](0) = drive16;
3364 r = fs.MkDirAll(fullname);
3365 test(r==KErrNone || r==KErrAlreadyExists);
3366 r = file.Replace(fs,fullname,EFileWrite);
3371 r = timer1.CreateLocal();
3372 test(r == KErrNone);
3373 TRequestStatus timeout;
3374 TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
3375 timer1.After(timeout,time);
3376 User::WaitForRequest(timeout,status);
3377 test(status.Int() != KRequestPending);
3381 const TFsNotification* notification = notify->NextNotification();
3382 test(notification != NULL);
3384 r = notification->Path(_path);
3386 TChar driveletter = _path[0];
3387 driveletter.UpperCase();
3388 test(driveletter == (TChar)gDriveToTest);
3390 if(notification = notify->NextNotification(), notification==NULL)
3392 TRequestStatus status2;
3393 r = notify->RequestNotifications(status2);
3397 r = timer2.CreateLocal();
3398 test(r == KErrNone);
3399 TRequestStatus timeout2;
3400 TTimeIntervalMicroSeconds32 time2 = 10000000; //10 seconds
3401 timer2.After(timeout2,time2);
3402 User::WaitForRequest(timeout2,status2);
3403 test(status2.Int() != KRequestPending);
3407 notification = notify->NextNotification();
3409 test(notification != NULL);
3410 r = notification->Path(_path);
3412 driveletter = _path[0];
3413 driveletter.UpperCase();
3414 test(driveletter == (TChar)'C');
3420 // Negative testing for directory without *
3421 // We receive no notifications for files changed under the directory
3422 void NegativeTestDirStar()
3425 TInt r = fs.Connect();
3428 CFsNotify* notify = NULL;
3429 TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
3432 path.Append((TChar)gDriveToTest);
3433 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
3434 r = fs.MkDirAll(path);
3435 test(r == KErrNone || r == KErrAlreadyExists);
3437 r = notify->AddNotification((TUint)TFsNotification::ECreate,path,_L(""));
3440 TRequestStatus status;
3441 r = notify->RequestNotifications(status);
3445 filename.Append((TChar)gDriveToTest);
3446 filename.Append(_L(":\\F32-TST\\T_NOTIFIER\\dir.star"));
3449 r = file.Replace(fs,filename,EFileWrite);
3454 r = timer1.CreateLocal();
3455 test(r == KErrNone);
3456 TRequestStatus timeout;
3457 TTimeIntervalMicroSeconds32 time = 2000000; //2 seconds
3458 timer1.After(timeout,time);
3459 User::WaitForRequest(timeout,status);
3460 test(status.Int() == KRequestPending);
3464 const TFsNotification* notification = notify->NextNotification();
3465 test(notification == NULL);
3474 void NegativeTests()
3476 test.Next(_L("Negative Tests"));
3478 test.Printf(_L("NegativeTests() A\n"));
3480 CFsNotify* notify = NULL;
3481 TInt r = fs.Connect();
3482 test(r == KErrNone);
3483 TRAP(r,notify = CFsNotify::NewL(fs,0));
3484 test(notify != NULL);
3489 test.Printf(_L("NegativeTests() B\n"));
3490 TRAP(r,notify = CFsNotify::NewL(fs,-1));
3491 test(notify != NULL);
3495 test.Printf(_L("NegativeTests() C\n"));
3496 TRAP(r,notify = CFsNotify::NewL(fs,KMaxTInt));
3497 test(r==KErrArgument);
3501 test.Printf(_L("NegativeTests() D\n"));
3503 path.Append((TChar)gDriveToTest);
3504 path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
3506 filename.Append(_L("file.txt"));
3507 TRAP(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize));
3510 r = notify->AddNotification(0,path,filename);
3511 test(r == KErrArgument);
3513 test.Printf(_L("NegativeTests() E\n"));
3514 r = notify->AddNotification((TUint)0x8000,path,filename); //invalid value
3515 test(r == KErrArgument);
3517 test.Printf(_L("NegativeTests() F\n"));
3518 TBuf<40> invalidPath;
3519 invalidPath.Append(_L("1:\\*"));
3520 r = notify->AddNotification((TUint)TFsNotification::ECreate,invalidPath,filename);
3521 test(r == KErrNotFound || r == KErrPathNotFound);
3524 test.Printf(_L("NegativeTests() G\n"));
3525 TRequestStatus wrongStatus;
3526 wrongStatus = KRequestPending;
3527 r = notify->RequestNotifications(wrongStatus);
3528 test(r == KErrInUse);
3530 test.Printf(_L("NegativeTests() H\n"));
3531 TRequestStatus status;
3532 r = notify->RequestNotifications(status);
3534 r = notify->CancelNotifications(wrongStatus);
3535 test(r == KErrInUse);
3545 * Doesn't actually do anything special.
3546 * Can probably be deleted.
3548 class MyRPlugin : public RPlugin
3551 void DoRequest(TInt aReqNo,TRequestStatus& aStatus) const;
3552 void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const;
3553 void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const;
3554 TInt DoControl(TInt aFunction) const;
3555 TInt DoControl(TInt aFunction,TDes8& a1) const;
3556 TInt DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const;
3557 void DoCancel(TUint aReqMask) const;
3560 void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus) const
3562 RPlugin::DoRequest(aReqNo,aStatus);
3564 void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const
3566 RPlugin::DoRequest(aReqNo,aStatus,a1);
3568 void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const
3570 RPlugin::DoRequest(aReqNo,aStatus,a1,a2);
3572 TInt MyRPlugin::DoControl(TInt aFunction) const
3574 return RPlugin::DoControl(aFunction);
3576 TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1) const
3578 return RPlugin::DoControl(aFunction,a1);
3580 TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const
3582 return RPlugin::DoControl(aFunction,a1,a2);
3584 void MyRPlugin::DoCancel(TUint aReqMask) const
3586 RPlugin::DoCancel(aReqMask);
3590 * This tests that when file server plugins perform operations that
3591 * the framework doesn't notify about them
3593 TInt TestNotificationsWithFServPlugins()
3595 TInt r = TheFs.AddPlugin(KNotifyPluginFileName);
3596 test(r==KErrNone || r==KErrAlreadyExists);
3597 r = TheFs.MountPlugin(KNotifyPluginName,(TUint)gDriveToTest.GetUpperCase() - 65);
3598 if (r == KErrNotSupported)
3600 test.Printf(_L("Plugins are not supported on pagable drives.\nSkipping test.\n"));
3601 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
3605 TPckgBuf<TChar> drivePckg(gDriveToTest);
3607 test.Next(_L("Open RPlugin connection for NotifyPlugin"));
3608 r = rplugin.Open(TheFs,KNotifyPos);
3609 safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
3611 test.Next(_L("Send drive letter to test down to plugin"));
3612 r = rplugin.DoControl(KPluginSetDrive,drivePckg);
3613 safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
3616 r = SimpleCreateTestL();
3617 safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
3624 * This test is testing the use cases
3625 * and for negative testing of SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
3627 * Performance tests can be found in test t_notify_perf
3631 CTrapCleanup* cleanup;
3632 cleanup = CTrapCleanup::New();
3634 globalDriveNum = gDriveToTest - (TChar)'A';
3637 test.Start(_L("T_NOTIFIER Test Start"));
3640 //=========================================================================================
3641 //! @SYMTestCaseID PBASE-T_NOTIFY-2443
3642 //! @SYMTestType CIT
3643 //! @SYMREQ PREQ1847
3644 //! @SYMTestCaseDesc Simple Tests/User Heap Tests
3645 //! @SYMTestStatus Implemented
3646 //=========================================================================================
3648 // 1. Create and delete many CFsNotify objects
3651 test.Next(_L("CFsNotify Creation and Delete Tests"));
3652 //Creates and Deletes 1 CFsNotify
3654 r = TestNewDeleteCFsNotify(1);
3657 //Creates and Deletes 50 CFsNotifys
3659 r = TestNewDeleteCFsNotify(50);
3662 test.Printf(_L("------- End of User Heap Tests ---------------------------------------\n"));
3664 // 2. Add notification for creating a file
3669 r = SimpleCreateTestL();
3672 test.Printf(_L("------- End of CFsNotify Creation and Delete Tests -------------------\n"));
3674 // 3. Add notification at the root of a drive
3675 // Create a file in that drive
3678 TestRootDriveNotifications();
3679 test.Printf(_L("------- End of RootDriveNotifications Test ---------------------------\n"));
3681 // 4. Add notification for a filename without a drive
3682 // Create that file in the current drive
3683 // Create that file in another drive
3686 TestNonDriveFilters();
3687 test.Printf(_L("------- End of TestNonDriveFilters Test ------------------------------\n"));
3689 // 5. Add notifications for 2 file creations
3691 // The clients create a file each
3695 r = TestTwoDoersL();
3698 test.Printf(_L("------- End of TwoDoers Test -----------------------------------------\n"));
3700 // 6. Create 2 file server sessions
3701 // Add a notification on each session for the same specific file creation
3706 r = TestTwoWatchersL();
3709 test.Printf(_L("------- End of TwoWatchers Test --------------------------------------\n"));
3711 // 7. Create 2 file server sessions and 2 clients
3712 // Add a notification on each session for different file creations
3713 // Clients create a file each
3717 r = TestTwoWatchersTwoDoersL();
3720 test.Printf(_L("------- End of TwoWatchersTwoDoers Test ------------------------------\n"));
3722 // 8. Add notification for a specific file creation
3723 // Cancel the notification request
3728 r = TestCancelNotificationL();
3731 test.Printf(_L("------- End of CancelNotification Test -------------------------------\n"));
3733 // 9. Create 2 file server sessions
3734 // Add a notification on each session for the same specific file creation
3735 // Delete the first notification
3739 test.Next(_L("TestClientRemoval"));
3741 r = TestClientRemovalL();
3744 test.Printf(_L("------- End of TestClientRemoval Test --------------------------------\n"));
3746 // 10. Create a CFsNotify object
3747 // Close the session before closing the subsession
3748 // Add notification and request notifications
3752 // Close session after creating the object
3753 TestSessionClose(1);
3756 // Close session after adding the notification
3757 TestSessionClose(2);
3759 test.Printf(_L("------- End of TestSessionClose Test ---------------------------------\n"));
3762 //=========================================================================================
3763 //! @SYMTestCaseID PBASE-T_NOTIFY-2444
3765 //! @SYMREQ PREQ1847
3766 //! @SYMTestCaseDesc File/Directory Create and Replace – Single File Server Session
3767 //! @SYMTestStatus Implemented
3769 //! TFsNotificationType ECreate
3770 //=========================================================================================
3773 // 1. Add notification for a specific file creation
3777 test.Next(_L("EFileCreate Tests"));
3778 _LIT(KFilename3,"file.create");
3779 r = TestMultipleNotificationsL(_L(""),KFilename3,5,5,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3781 test.Printf(_L("------- End of EFileCreate Tests -------------------------------------\n"));
3784 // 2. Add notification for a specific directory creation
3785 // Create that directory
3788 test.Next(_L("EFsMkDir Test"));
3789 _LIT(KDirName1,"dirCreate\\");
3790 r = TestMultipleNotificationsL(KDirName1,_L(""),1,1,t_notification::EFsMkDir,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3792 test.Printf(_L("------- End of EFsMkDir Test -----------------------------------------\n"));
3795 // 3. Add notification for a specific file creation
3796 // Replace that file
3799 test.Next(_L("EFileReplace Test"));
3800 r = TestMultipleNotificationsL(_L(""),KFilename3,1,1,t_notification::EFileReplace,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3802 test.Printf(_L("------- End of EFileReplace Test -------------------------------------\n"));
3804 // 4. Add notification for a specific file creation
3805 // Remove that notification
3810 r = TestAddRemoveNotificationL();
3813 test.Printf(_L("------- End of Add and Remove Notification Test ----------------------\n"));
3815 // Wildcard Create Tests
3816 // 5. Add notification for file creation using wildcard name
3817 // Add notification for file/directory wildcard including subdirectories
3818 // Create number of files and directories that match each notification
3821 test.Next(_L("Wildcard Create Tests"));
3824 _LIT(KWildcardName1,"*");
3825 r = TestMultipleNotificationsL(_L(""),KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3827 r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3829 r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
3832 // Wildcard including Subdirectories
3833 _LIT(KWildcardName2,"*\\");
3834 r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
3836 r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3838 _LIT(KDirName2,"SubDir\\");
3839 _LIT(KWildcardName3,"?");
3840 r = TestMultipleNotificationsL(KDirName2,KWildcardName3,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3844 _LIT(KWildcardName4,"*.*");
3845 r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_txt_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3847 r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
3850 // 6. Add notification for file creation for a specific type
3851 // Create file with that type
3852 // Create file with different type
3854 _LIT(KWildcardName5,"*.txt");
3855 r = TestMultipleNotificationsL(_L(""),KWildcardName5,1,1,t_notification::EFileCreate_txt,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3857 test.Printf(_L("------- End of Wildcard Create Tests ---------------------------------\n"));
3860 //=============================================================================
3861 //! @SYMTestCaseID PBASE-T_NOTIFY-2445
3863 //! @SYMREQ PREQ1847
3864 //! @SYMTestCaseDesc File Attribute Change – Single File Server Session
3865 //! @SYMTestStatus Implemented
3867 // TFsNotificationType EAttribute
3868 //=============================================================================
3870 // RFile::SetAtt, RFile::Set and RFs::SetEntry
3871 // 1. Add notification for a specific file attribute change
3872 // Change the attribute for that file
3875 test.Next(_L("Attribute Tests"));
3876 _LIT(KFilename4,"file.setatts");
3877 r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSetAtt,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3879 r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSet,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3881 r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFsSetEntry,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3884 // Wildcard Attribute Test including subdirectories
3885 // 2. Add notification for file attribute change using wildcard name
3886 // Create number of files that match the notification
3887 // Change attributes of some files
3889 r = TestMultipleNotificationsL(KWildcardName2,_L("*"),3,3,t_notification::EFileSetAtt_subs,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3891 test.Printf(_L("------- End of Attribute Tests ---------------------------------------\n"));
3894 //=============================================================================
3895 //! @SYMTestCaseID PBASE-T_NOTIFY-2446
3897 //! @SYMREQ PREQ1847
3898 //! @SYMTestCaseDesc File/Directory Rename – Single File Server Session
3899 //! @SYMTestStatus Implemented
3901 // TFsNotificationType ERename
3902 //=============================================================================
3904 // RFs::Replace, RFs::Rename and RFile::Rename
3905 // 1. Add notification for a specific file rename change
3909 test.Next(_L("Rename Tests"));
3910 _LIT(KFilename5,"file.rename");
3911 r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsReplace,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3913 r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3915 r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFileRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3918 // 2. Add notification for a specific directory rename
3919 // Rename that directory
3921 _LIT(KDirName3,"dirRename\\");
3922 r = TestMultipleNotificationsL(KDirName3,_L(""),1,1,t_notification::EFsRename_dir,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3925 // 3. Add notification for file rename using wildcard name
3926 // Create file that match the notification
3927 // Repeatedly rename the file
3929 r = TestMultipleNotificationsL(_L(""),KWildcardName1,3,3,t_notification::EFileRename_wild,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3931 test.Printf(_L("------- End of Rename Tests ------------------------------------------\n"));
3934 //=============================================================================
3935 //! @SYMTestCaseID PBASE-T_NOTIFY-2447
3937 //! @SYMREQ PREQ1847
3938 //! @SYMTestCaseDesc File/Directory Delete – Single File Server Session
3939 //! @SYMTestStatus Implemented
3941 // TFsNotificationType EDelete
3942 //=============================================================================
3945 // 1. Add notification for a specific file delete
3949 test.Next(_L("EFsDelete Test"));
3950 _LIT(KFilename6,"file.delete");
3951 r = TestMultipleNotificationsL(_L(""),KFilename6,1,1,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3955 // 2. Add notification for a specific directory delete
3956 // Delete that directory
3959 test.Next(_L("EFsRmDir Tests"));
3960 _LIT(KDirName4,"dirRemove\\");
3961 r = TestMultipleNotificationsL(KDirName4,_L(""),1,1,t_notification::EFsRmDir,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3964 // This test should not receive any notifications because a non-empty directory cannot be removed
3965 // 3. Add notification for specific directory delete
3966 // Create files inside that directory
3967 // Delete the directory
3969 _LIT(KDirName5,"dirRmNonEmp\\");
3970 r = TestMultipleNotificationsL(KDirName5,_L(""),1,1,t_notification::EFsRmDir_nonEmpty,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
3973 // Wildcard Name ("*")
3974 // 4. Add notification for directory delete using wildcard name
3975 // Create directory that match the notification
3976 // Delete that directory
3978 r = TestMultipleNotificationsL(KWildcardName1,_L(""),1,1,t_notification::EFsRmDir_wild,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3981 // Wildcard Type ("*.txt")
3982 // Creates files with different types and should only receive notifications from "*.txt" file deletions
3983 // 5. Add notification for file deletes using wildcard type
3984 // Create number of files that match the notification
3985 // Delete those files
3987 r = TestMultipleNotificationsL(_L(""),KWildcardName4,3,3,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
3989 test.Printf(_L("------- End of Delete Tests ------------------------------------------\n"));
3992 //======================================================================
3993 //! @SYMTestCaseID PBASE-T_NOTIFY-2448
3995 //! @SYMREQ PREQ1847
3996 //! @SYMTestCaseDesc File Change – Single File Server Session
3997 //! @SYMTestStatus Implemented
3999 // TFsNotificationType EFileChange
4000 //======================================================================
4003 // If caching is enabled, notifications are received only when the file cache is flushed
4004 // We flush everytime we do a write to ensure the tests work regardless of cache
4006 // 1. Add notification for a specific file change
4008 // Write to that file
4011 test.Next(_L("EFileWrite Tests"));
4012 _LIT(KFilename7,"file.write");
4014 r = TestMultipleNotificationsL(_L(""),KFilename7,7,7,t_notification::EFileWrite,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4018 // 2. Add notification for a specific file change
4019 // Write to the specified file a number of times without changing its size
4021 // Four letters are written to a file, then the first letter in the file is replaced aIterations times
4022 // aMaxNotifications = 1 + aIterations
4024 r = TestMultipleNotificationsL(_L(""),KFilename7,3,4,t_notification::EFileWrite_samesize,TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4026 test.Printf(_L("------- End of EFileWrite Tests --------------------------------------\n"));
4028 // 3. Add notification for a specific file change
4029 // Write to that file asynchronously
4032 test.Next(_L("EFileWrite_async Tests"));
4033 _LIT(KFilename8,"async.write");
4035 r = TestMultipleNotificationsL(_L(""),KFilename8,4,4,t_notification::EFileWrite_async,TFsNotification::EFileChange,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4038 test.Printf(_L("------- End of EFileWrite_async Tests --------------------------------\n"));
4041 // 4. Add notification for a specific file change
4042 // Both increase and decrease the file sizes a number of times
4044 // The file size is increased aIterations times, and decreased (aIterations - 1) times
4045 // aMaxNotifications = 2*aIterations - 1
4048 test.Next(_L("EFileSetSize Tests"));
4049 _LIT(KFilename9,"file.setsize");
4050 r = TestMultipleNotificationsL(_L(""),KFilename9,5,9,t_notification::EFileSetSize,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4052 test.Printf(_L("------- End of EFileSetSize Tests ------------------------------------\n"));
4057 test.Next(_L("CFileMan Tests"));
4058 _LIT(KFilenameCFMan,"cf1le.man");
4059 TUint notificationTypes = (TUint)TFsNotification::ECreate|TFsNotification::EFileChange|TFsNotification::EAttribute|TFsNotification::EDelete|TFsNotification::ERename;
4060 r = TestMultipleNotificationsL(_L(""),KFilenameCFMan,1,5,t_notification::ECFileManMove,notificationTypes,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4062 test.Printf(_L("------- End of CFileMan Tests -------------------------------------\n"));
4065 //========================================================================================
4066 //! @SYMTestCaseID PBASE-T_NOTIFY-2449
4068 //! @SYMREQ PREQ1847
4069 //! @SYMTestCaseDesc File System Mounted/Dismounted, Media Card Removal/Insertion,
4070 // RawDisk Write – Single File Server Session
4071 //! @SYMTestStatus Implemented
4073 // TFsNotificationType EMediaChange
4074 //========================================================================================
4076 // RFs::DismountFileSystem
4077 // 1. Add notification for media change
4078 // Dismount the file system
4081 test.Next(_L("Mount Tests"));
4082 TFullName filesystemName;
4083 r = TheFs.FileSystemName(filesystemName,globalDriveNum);
4085 r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EDismount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4088 // RFs::MountFileSystem
4089 // 2. Add notification for media change
4090 // Mount the file system
4092 r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EMount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4095 // Repeatedly mount and dismount the file system
4096 // 3. Add notification for media change
4097 // Repeatedly dismount and mount the file system
4099 // The file system is dismounted and mounted aIterations times
4100 // aMaxNotifications = 2*aIterations
4102 r = TestMultipleNotificationsL(filesystemName,5,10,t_notification::EMountDismount,TFsNotification::EMediaChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4105 // RFs::MountFileSystemAndScan
4106 // 4. Add notification for media change
4107 // Mount and scan the file system
4109 // The file system is dismounted and mounted aIterations times
4110 // aMaxNotifications = 2*aIterations
4113 // r = TestMultipleNotificationsL(filesystemName,1,2,t_notification::EMountScan,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4114 // test(r==KErrNone);
4116 test.Printf(_L("------- End of Mount Tests -------------------------------------------\n"));
4119 TheFs.CharToDrive(gDriveToTest,driveNum);
4120 r = TheFs.Drive(drvInfo,driveNum);
4121 test (r == KErrNone);
4122 TPtrC driveDes((TText*)&gDriveToTest,1);
4124 // Manual Tests - Will only run on removable drives
4126 /* if(drvInfo.iDriveAtt & KDriveAttRemovable)
4129 // 5. Add notification for media change
4130 // Remove media card manually
4133 test.Next(_L("Media Card Removal/Insertion Tests"));
4134 r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardRemoval,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4137 // 6. Add notification for media change
4138 // Insert media card manually
4140 r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardInsertion,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4142 test.Printf(_L("------- End of Media Card Removal/Insertion Tests --------------------\n"));
4144 // We should receive an EMediaChange notification even though we did not register for it
4145 // 7. Do not add notification for media change
4146 // Remove and insert media card manually
4149 TestMediaCardNotificationWhenNotRegisteredForIt();
4150 test.Printf(_L("------- End of TestMediaCardNotificationWhenNotRegisteredForIt -------\n"));
4154 // 8. Add notification for media change
4155 // Write directly to the media
4158 if(gDriveToTest-(TChar)'A' != 2)
4162 test.Next(_L("RRawDisk::Write Tests"));
4163 r = TestMultipleNotificationsL(driveDes,1,1,t_notification::ERawDiskWrite,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4165 test.Printf(_L("------- End of RRawDisk::Write Test ------------------------------ \n"));
4169 //===============================================================================
4170 //! @SYMTestCaseID PBASE-T_NOTIFY-2450
4172 //! @SYMREQ PREQ1847
4173 //! @SYMTestCaseDesc Drive Name Modification – Single File Server Session
4174 //! @SYMTestStatus Implemented
4176 // TFsNotificationType EDriveName
4177 //===============================================================================
4179 // RFs::SetDriveName
4180 // The drive name is renamed 2*aIterations times
4181 // aMaxNotifications = 2*aIterations
4183 // 1. Add notification for a specific drive name change
4184 // Change the drive name
4187 test.Next(_L("DriveName Test"));
4188 r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4191 // 2. Add notification for a specific drive name change
4192 // Repeatedly rename the drive
4194 r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4196 test.Printf(_L("------- End of DriveName Test ----------------------------------------\n"));
4199 //================================================================================
4200 //! @SYMTestCaseID PBASE-T_NOTIFY-2451
4202 //! @SYMREQ PREQ1847
4203 //! @SYMTestCaseDesc Volume Name Modification – Single File Server Session
4204 //! @SYMTestStatus Implemented
4206 // TFsNotificationType EVolumeName
4207 //================================================================================
4209 // RFs::SetVolumeLabel - Does not run on WINS
4210 // The volume name is renamed 2*aIterations times
4211 // aMaxNotifications = 2*aIterations
4215 test.Next(_L("VolumeName Test"));
4217 // 1. Add notification for a specific volume name change
4218 // Change the volume name
4220 r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4223 // 2. Add notification for a specific volume name change
4224 // Repeatedly rename the volume
4226 r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4228 test.Printf(_L("------- End of VolumeName Test ---------------------------------------\n"));
4232 //=============================================================================
4233 //! @SYMTestCaseID PBASE-T_NOTIFY-2452
4235 //! @SYMREQ PREQ1847
4236 //! @SYMTestCaseDesc All Operations Filter – Single File Server Session
4237 //! @SYMTestStatus Implemented
4239 // TFsNotificationType EAllOps
4240 //=============================================================================
4242 test.Next(_L("AllOps Tests"));
4244 // 1. Add notification for all operations
4248 // EAllOps1: A file is created and deleted aIterations times
4249 // aMaxNotification = 2*aIterations
4251 _LIT(KFilename10,"file.allops");
4252 r = TestMultipleNotificationsL(_L(""),KFilename10,4,8,t_notification::EAllOps1,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4255 // 2. Add notification for all operations
4257 // Write to the file
4260 // EAllOps2: A file is created, written to aIterations times and then deleted
4261 // aMaxNotification = 2 + aIterations (See File Write Tests)
4263 r = TestMultipleNotificationsL(_L(""),KFilename10,4,6,t_notification::EAllOps2,(TUint)TFsNotification::EAllOps,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4266 // 3. Add notification for all operations
4268 // Change the file size
4271 // EAllOps3: A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times
4273 // aMaxNotifications = 1 + 2*aIterations
4275 r = TestMultipleNotificationsL(_L(""),KFilename10,4,9,t_notification::EAllOps3,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize*2,(TBool)EFalse,__LINE__);
4278 // 4. Add notification for all operations
4280 // Change the file attribute
4283 // EAllOps4: A file is created, its attribute is changed and the file is deleted
4284 // aMaxNotification = 3
4286 r = TestMultipleNotificationsL(_L(""),KFilename10,1,3,t_notification::EAllOps4,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4289 // 5. Add notification for all operations
4293 // EAllOps5: A file is created and renamed
4294 // aMaxNotification = 2
4296 r = TestMultipleNotificationsL(_L(""),KFilename10,1,2,t_notification::EAllOps5,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4299 // 6. Add notification for all operations
4300 // Change drive name
4301 // Change volume name
4303 // SetVolumeLabel does not run on WINS
4304 // EAllOps6: The drive and volume names are changed
4305 // aMaxNotification = 2
4308 r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4311 test.Printf(_L("------- End of AllOps Tests ------------------------------------------\n"));
4314 //=============================================================================
4315 //! @SYMTestCaseID PBASE-T_NOTIFY-2453
4317 //! @SYMREQ PREQ1847
4318 //! @SYMTestCaseDesc Multiple Filters – Single File Server Session
4319 //! @SYMTestStatus Implemented
4320 //=============================================================================
4322 test.Next(_L("Multiple-Filter Tests"));
4324 // TFsNotification::ECreate | TFsNotification::EDelete
4325 // 1. Add notification for create and delete for a specific file
4329 // A file is created and deleted aIterations times
4330 // aMaxNotification = 2*aIterations
4332 _LIT(KFilename11,"file.mulfil");
4333 r = TestMultipleNotificationsL(_L(""),KFilename11,3,6,t_notification::EAllOps1,TFsNotification::ECreate | TFsNotification::EDelete,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4336 // TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange
4337 // 2. Add notification for create, file change and delete for a specific file
4339 // Change the file size
4342 // A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times
4344 // aMaxNotifications = 1 + 2*aIterations
4346 r = TestMultipleNotificationsL(_L(""),KFilename11,4,9,t_notification::EAllOps3,TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4349 // TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate
4350 // 3. Add notification for create, attribute change and delete for a specific file
4352 // Change the file attribute
4355 // A file is created, its attribute is changed and the file is deleted
4356 // aMaxNotification = 3
4358 r = TestMultipleNotificationsL(_L(""),KFilename11,1,3,t_notification::EAllOps4,TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4361 // TFsNotification::ERename | TFsNotification::ECreate
4362 // 4. Add notification for create and rename for a specific file
4366 // A file is created and renamed
4367 // aMaxNotification = 2
4369 r = TestMultipleNotificationsL(_L(""),KFilename11,1,2,t_notification::EAllOps5,TFsNotification::ERename | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4372 // TFsNotification::EVolumeName | TFsNotification::EDriveName
4373 // 5. Add notification for drive and volume name change for a specific drive
4374 // Change drive name
4375 // Change volume name
4377 // SetVolumeLabel does not run on WINS
4378 // The drive and volume names are changed
4379 // aMaxNotification = 2
4382 r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,TFsNotification::EVolumeName | TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4385 test.Printf(_L("------- End of Multiple-Filter Tests ---------------------------------\n"));
4388 //==============================================================================
4389 //! @SYMTestCaseID PBASE-T_NOTIFY-2454
4391 //! @SYMREQ PREQ1847
4392 //! @SYMTestCaseDesc Overflow Notification – Single File Server Session
4393 //! @SYMTestStatus Implemented
4394 //==============================================================================
4396 // 1. Add notification with a small buffer size, for a specific file change
4397 // Change the file size once
4398 // 2. Make continuous file size changes to the file
4399 // 3. When overflow notification occurs, delete the notification
4402 r = TestOverflowL();
4407 r= TestPostOverflowNotifications();
4409 test.Printf(_L("------- End of Overflow Test -----------------------------------------\n"));
4412 //============================================================================
4413 //! @SYMTestCaseID PBASE-T_NOTIFY-2455
4414 //! @SYMTestType CIT
4415 //! @SYMREQ PREQ1847
4416 //! @SYMTestCaseDesc API Negative Testing – Single File Server Session
4417 //! @SYMTestStatus Implemented
4418 //============================================================================
4420 // a-CFsNotify class creation with zero buffer size
4423 // b-CFsNotify class creation with negative buffer size
4424 // c-CFsNotify class creation with buffer size that is too large
4427 // d-Call AddNotification with aNotiififcationType zero
4428 // e-Call AddNotification with aNotiififcationType invalid
4429 // f-Call AddNotification with many different invalid paths
4432 // g-Call RequestNotifications with status that is already in use
4433 // h-Call CancelNotifications with wrong status
4441 // i-Negative testing for directory without *
4443 test.Printf(_L("NegativeTests() I\n"));
4444 NegativeTestDirStar();
4445 test.Printf(_L("------- End of Negative Tests ----------------------------------------\n"));
4448 //=============================================================================
4449 //! @SYMTestCaseID PBASE-T_NOTIFY-2461
4450 //! @SYMTestType CIT
4451 //! @SYMREQ PREQ1847
4452 //! @SYMTestCaseDesc Plugin Tests
4454 //=============================================================================
4456 r = TestNotificationsWithFServPlugins();
4458 test.Printf(_L("------- End of Plugin Tests ------------------------------------------\n"));
4461 //======================================================================
4462 //! @SYMTestCaseID PBASE-T_NOTIFY-2459
4464 //! @SYMREQ PREQ1847
4465 //! @SYMTestCaseDesc Drive Formatting – Single File Server Session
4466 //! @SYMTestStatus Implemented
4468 // TFsNotificationType EMediaChange
4469 //======================================================================
4472 // We do these last so that we can be sure to have deleted anything we've inadvertently not deleted
4474 // 1. Add notification for media change of a specific drive
4478 if(gDriveToTest-(TChar)'A' != 2)
4482 test.Next(_L("Format Tests"));
4483 r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EFormat,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
4485 test.Printf(_L("------- End of Format Tests ------------------------------------------\n"));
4489 //======================================================================
4490 //! @SYMTestCaseID PBASE-T_NOTIFY-2460
4492 //! @SYMREQ PREQ1847
4493 //! @SYMTestCaseDesc Notifications for Data Caged Areas
4494 //! @SYMTestStatus Implemented
4495 //======================================================================
4497 // Create a private folder for a specified uid
4498 // Add notification filter using the following processes:
4499 // 1. A process with no capability
4500 // 2. A process with all capabilities
4501 // 3. A process with the specified uid
4504 test.Next(_L("Test T_NOTIFIER_NOCAPS.EXE"));
4505 r = TestProcessCapabilities(_L("T_NOTIFIER_NOCAPS.EXE"));
4506 test(r == KErrPermissionDenied); //Failure on emulator -> Did you forget to do a wintest?
4508 test.Next(_L("Test T_NOTIFIER_ALLFILES.EXE"));
4509 r = TestProcessCapabilities(_L("T_NOTIFIER_ALLFILES.EXE"));
4510 test(r == KErrNone);
4512 test.Next(_L("Test T_NOTIFIER_BELONGS.EXE"));
4513 r = TestProcessCapabilities(_L("T_NOTIFIER_BELONGS.EXE"));
4514 test(r == KErrNone);
4515 test.Printf(_L("------- End of Data-Caging Tests -------------------------------------\n"));
4521 } //End of CallTestsL