kerneltest/f32test/server/t_notifier.cpp
changeset 299 b5a01337d018
parent 189 a5496987b1da
equal deleted inserted replaced
297:b2826f67641f 299:b5a01337d018
    21 #include <e32svr.h>
    21 #include <e32svr.h>
    22 #include <hal.h>
    22 #include <hal.h>
    23 #include "t_server.h"
    23 #include "t_server.h"
    24 #include "t_chlffs.h"
    24 #include "t_chlffs.h"
    25 #include "t_notify_plugin.h"
    25 #include "t_notify_plugin.h"
       
    26 #include "f32_test_utils.h"
    26 
    27 
    27 const TInt KNotificationHeaderSize = (sizeof(TUint16)*2)+(sizeof(TUint));
    28 const TInt KNotificationHeaderSize = (sizeof(TUint16)*2)+(sizeof(TUint));
    28 const TInt KMinNotificationBufferSize = 2*KNotificationHeaderSize + 2*KMaxFileName;
    29 const TInt KMinNotificationBufferSize = 2*KNotificationHeaderSize + 2*KMaxFileName;
    29 
    30 
    30 
    31 
    31 RTest test(_L("T_NOTIFIER"));
    32 RTest test(_L("T_NOTIFIER"));
    32 const TInt KMaxHeapSize = 0x800000;
    33 const TInt KMaxHeapSize = 0x800000;
    33 TInt globalDriveNum;
    34 TInt globalDriveNum;
       
    35 TBuf<50> filesystem; //storing original file system name
       
    36 _LIT(KTestNotifyFileSystemExeName,"t_tfsys_notify.fsy");
       
    37 _LIT(KNotifyTestFileSystem,"CNotifyTestFileSystem");
    34 
    38 
    35 void DismountPlugin()
    39 void DismountPlugin()
    36 	{
    40 	{
    37 	TheFs.DismountPlugin(KNotifyPluginName);
    41 	TheFs.DismountPlugin(KNotifyPluginName);
    38 	TheFs.RemovePlugin(KNotifyPluginFileName);
    42 	TheFs.RemovePlugin(KNotifyPluginFileName);
    39 	}
    43 	}
       
    44 
       
    45 void RemountOriginalFileSystem()
       
    46     {
       
    47     //Replace old FS.
       
    48     TheFs.DismountFileSystem(KNotifyTestFileSystem,globalDriveNum);
       
    49     TheFs.MountFileSystem(filesystem,globalDriveNum);
       
    50     TheFs.RemoveFileSystem(KNotifyTestFileSystem);
       
    51     }
       
    52 
       
    53 inline void safe_external_test(RTest& aTest, TInt aError, TInt aLine, TText* aName)
       
    54     {
       
    55     if(aError!=KErrNone)
       
    56         {
       
    57         test.Printf(_L(": ERROR : %d received on line %d\n"),aError,aLine);
       
    58         RemountOriginalFileSystem();
       
    59         aTest.operator()(aError==KErrNone,aLine,(TText*)aName);
       
    60         }
       
    61     }
    40 
    62 
    41 inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TText* aName)
    63 inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TText* aName)
    42 	{
    64 	{
    43 	if(aError!=KErrNone)
    65 	if(aError!=KErrNone)
    44 		{
    66 		{
   517 	TBuf<40> _path;
   539 	TBuf<40> _path;
   518 	_path.Copy(_pathC);
   540 	_path.Copy(_pathC);
   519 	if(_path.Match(fullname)!=KErrNone)
   541 	if(_path.Match(fullname)!=KErrNone)
   520 		safe_test(simpleTestWatcher,KErrBadName,__LINE__,(TText*)Expand("t_notifier.cpp"));
   542 		safe_test(simpleTestWatcher,KErrBadName,__LINE__,(TText*)Expand("t_notifier.cpp"));
   521 	
   543 	
   522 	/*
   544 	
   523 	TInt driveNumber = 0;
   545 	TInt driveNumber = 0;
   524 	TInt gDriveNum = -1;
   546 	TInt gDriveNum = -1;
   525 	notification->DriveNumber(driveNumber);
   547 	notification->DriveNumber(driveNumber);
   526 	RFs::CharToDrive(_pathC[0],gDriveNum);
   548 	RFs::CharToDrive(_pathC[0],gDriveNum);
   527 	if(driveNumber != gDriveNum)
   549 	if(driveNumber != gDriveNum)
   528 		safe_test(simpleTestWatcher,KErrBadHandle,__LINE__,(TText*)Expand("t_notifier.cpp"));
   550 		safe_test(simpleTestWatcher,KErrBadHandle,__LINE__,(TText*)Expand("t_notifier.cpp"));
   529 	
   551 	
   530 	TUid uid;
   552 	TUid uid;
   531 	TUint32 realUID = 0x76543210;
   553 	TInt32 realUID = 0x76543210;
   532 	r = notification->UID(uid);
   554 	r = notification->UID(uid);
   533 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
   555 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
   534 	safe_test(simpleTestWatcher,(realUID == uid.iUid)==1,__LINE__,(TText*)Expand("t_notifier.cpp"));
   556 	safe_test(simpleTestWatcher,((realUID == uid.iUid)?KErrNone:KErrNotFound),__LINE__,(TText*)Expand("t_notifier.cpp"));
   535 	*/
   557 	
   536 	delete notify;
   558 	delete notify;
   537 	fs.Close();
   559 	fs.Close();
   538 	simpleTestWatcher.End();
   560 	simpleTestWatcher.End();
   539 	simpleTestWatcher.Close();
   561 	simpleTestWatcher.Close();
   540 	delete cleanup;
   562 	delete cleanup;
  3619 	
  3641 	
  3620 	DismountPlugin();
  3642 	DismountPlugin();
  3621 	return KErrNone;
  3643 	return KErrNone;
  3622 	}
  3644 	}
  3623 
  3645 
       
  3646 _LIT(KPhantomExtendedReplace,"?:\\PhantomExtended_Replaced.txt");
       
  3647 _LIT(KPhantomExtendedRenamed,"?:\\PhantomExtended_Renamed.txt");
       
  3648 _LIT(KPhantomExtendedRenameMe,"?:\\PhantomExtended_RenameMe.txt");
       
  3649 
       
  3650 TInt DoTestExternalNotificationL()
       
  3651     {
       
  3652     TRequestStatus statusN, statusT;
       
  3653     RTimer timer1;
       
  3654     TTimeIntervalMicroSeconds32 time = 10000000;    
       
  3655     
       
  3656     test.Printf(_L("DoTestExternalNotification"));
       
  3657     CFsNotify* notify = CFsNotify::NewL(TheFs,1024);
       
  3658     TInt r = notify->AddNotification(TFsNotification::ECreate, _L("?:\\"),_L("PhantomExtended_Replaced.txt"));
       
  3659     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3660     r = notify->RequestNotifications(statusN);
       
  3661     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3662     
       
  3663     RFile file;
       
  3664     r = file.Replace(TheFs,_L("\\Extended_Replaced.txt"),EFileWrite);
       
  3665     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3666     file.Close();    
       
  3667     
       
  3668     r = timer1.CreateLocal();
       
  3669     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3670     timer1.After(statusT,time);
       
  3671     User::WaitForRequest(statusN,statusT);
       
  3672     test_Compare(statusN.Int(),!=,KRequestPending)
       
  3673     timer1.Cancel();
       
  3674     timer1.Close();
       
  3675     User::WaitForRequest(statusT);
       
  3676     
       
  3677     const TFsNotification* notification = notify->NextNotification();
       
  3678     if(!notification)
       
  3679         safe_external_test(test,KErrUnderflow,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3680     
       
  3681     //Check Path
       
  3682     TPtrC path;
       
  3683     r = notification->Path(path);
       
  3684     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3685     
       
  3686     if(path.Match(KPhantomExtendedReplace)==KErrNotFound)
       
  3687         {
       
  3688         safe_external_test(test,KErrNotFound,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3689         }
       
  3690    
       
  3691     //Check NewName
       
  3692     TPtrC newName;
       
  3693     r = notification->NewName(newName);
       
  3694     safe_external_test(test,(r==KErrNotSupported) ? KErrNone : r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3695     
       
  3696     notify->CancelNotifications(statusN);
       
  3697     delete notify;
       
  3698     
       
  3699     //*************************************************************
       
  3700     // Rename:
       
  3701     //*************************************************************
       
  3702     
       
  3703     notify = CFsNotify::NewL(TheFs,1024);
       
  3704     r = notify->AddNotification(TFsNotification::ERename, _L("?:\\"),_L("PhantomExtended_Renamed.txt"));
       
  3705     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3706     r = notify->RequestNotifications(statusN);
       
  3707     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3708 
       
  3709     r = file.Replace(TheFs,_L("\\Extended_RenameMe.txt"),EFileWrite);
       
  3710     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3711     file.Close();    
       
  3712 
       
  3713     r = timer1.CreateLocal();
       
  3714     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3715     timer1.After(statusT,time);
       
  3716     User::WaitForRequest(statusN,statusT);
       
  3717     test_Compare(statusN.Int(),!=,KRequestPending)
       
  3718     timer1.Cancel();
       
  3719     timer1.Close();
       
  3720     User::WaitForRequest(statusT);
       
  3721 
       
  3722     notification = notify->NextNotification();
       
  3723     if(!notification)
       
  3724         safe_external_test(test,KErrUnderflow,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3725 
       
  3726     r = notification->Path(path);
       
  3727     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3728 
       
  3729     if(path.Match(KPhantomExtendedRenameMe)==KErrNotFound)
       
  3730         {
       
  3731         safe_external_test(test,KErrNotFound,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3732         }
       
  3733     
       
  3734     //Check NewName
       
  3735     r = notification->NewName(newName);
       
  3736     if(newName.Match(KPhantomExtendedRenamed)==KErrNotFound)
       
  3737         {
       
  3738         safe_external_test(test,KErrNotFound,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3739         }
       
  3740 
       
  3741     notify->CancelNotifications(statusN);
       
  3742     delete notify;
       
  3743         
       
  3744     return KErrNone;
       
  3745     }
       
  3746 
       
  3747 void TestExternalNotifications()
       
  3748     {
       
  3749     test.Printf(_L("Test External Notifications (Load test file system)"));
       
  3750 
       
  3751     if(F32_Test_Utils::Is_SimulatedSystemDrive(TheFs,globalDriveNum))
       
  3752         {
       
  3753         test.Printf(_L("Not testing External Notifications on SimulatedSystemDrive"));
       
  3754         return;
       
  3755         }
       
  3756 
       
  3757     TInt r = TheFs.FileSystemName(filesystem,globalDriveNum);
       
  3758     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3759     r = TheFs.DismountFileSystem(filesystem,globalDriveNum);
       
  3760     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3761     r = TheFs.AddFileSystem(KTestNotifyFileSystemExeName);
       
  3762     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3763     r = TheFs.MountFileSystem(KNotifyTestFileSystem,globalDriveNum);
       
  3764     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3765     
       
  3766     TRAP(r,DoTestExternalNotificationL());
       
  3767     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3768         
       
  3769     //Replace old FS.
       
  3770     r = TheFs.DismountFileSystem(KNotifyTestFileSystem,globalDriveNum);
       
  3771     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3772     r = TheFs.MountFileSystem(filesystem,globalDriveNum);
       
  3773     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3774     r = TheFs.RemoveFileSystem(KNotifyTestFileSystem);
       
  3775     safe_external_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
       
  3776     }
       
  3777 
  3624 /*
  3778 /*
  3625  * This test is testing the use cases
  3779  * This test is testing the use cases
  3626  * and for negative testing of SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
  3780  * and for negative testing of SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
  3627  * 
  3781  * 
  3628  * Performance tests can be found in test t_notify_perf
  3782  * Performance tests can be found in test t_notify_perf
  4513 	test.Next(_L("Test T_NOTIFIER_BELONGS.EXE"));
  4667 	test.Next(_L("Test T_NOTIFIER_BELONGS.EXE"));
  4514 	r = TestProcessCapabilities(_L("T_NOTIFIER_BELONGS.EXE"));
  4668 	r = TestProcessCapabilities(_L("T_NOTIFIER_BELONGS.EXE"));
  4515 	test_KErrNone(r);
  4669 	test_KErrNone(r);
  4516 	test.Printf(_L("------- End of Data-Caging Tests -------------------------------------\n"));
  4670 	test.Printf(_L("------- End of Data-Caging Tests -------------------------------------\n"));
  4517 	
  4671 	
       
  4672 	PrintLine();
       
  4673 	test.Next(_L("Test TestExternalNotifications()"));
       
  4674 	TestExternalNotifications();
       
  4675 	test.Printf(_L("------- End of TestExternalNotifications Tests -------------------------------------\n"));
  4518 	
  4676 	
  4519 	test.End();
  4677 	test.End();
  4520 	test.Close();
  4678 	test.Close();
  4521 	delete cleanup;
  4679 	delete cleanup;
  4522 	}	//End of CallTestsL
  4680 	}	//End of CallTestsL