kerneltest/f32test/server/t_fman.cpp
changeset 281 13fbfa31d2ba
parent 259 57b9594f5772
equal deleted inserted replaced
266:0008ccd16016 281:13fbfa31d2ba
    25 
    25 
    26 LOCAL_D CFileMan* gFileMan=NULL;
    26 LOCAL_D CFileMan* gFileMan=NULL;
    27 LOCAL_D TBool gAsynch=EFalse;
    27 LOCAL_D TBool gAsynch=EFalse;
    28 LOCAL_D TRequestStatus gStat;
    28 LOCAL_D TRequestStatus gStat;
    29 LOCAL_D TBool testingInvalidPathLengths;
    29 LOCAL_D TBool testingInvalidPathLengths;
       
    30 LOCAL_D TChar gSecDrive;        // a second drive for inter-drive tests
       
    31 LOCAL_D TBool gSecDriveReady;
    30 
    32 
    31 class CFileManObserver : public CBase, public MFileManObserver
    33 class CFileManObserver : public CBase, public MFileManObserver
    32 	{
    34 	{
    33 public:
    35 public:
    34 	CFileManObserver(CFileMan* aFileMan);
    36 	CFileManObserver(CFileMan* aFileMan);
    63 		test_Equal(KErrAlreadyExists, lastError);
    65 		test_Equal(KErrAlreadyExists, lastError);
    64 		test_Value(KErrNotFound, fileName.MatchF(_L("PIPE1.PLP"))!=KErrNotFound || fileName.MatchF(_L("FOUR"))!=KErrNotFound || fileName.MatchF(_L("File*.TXT"))!=KErrNotFound  || fileName.MatchF(_L("ah"))!=KErrNotFound || fileName.MatchF(_L("a"))!=KErrNotFound);
    66 		test_Value(KErrNotFound, fileName.MatchF(_L("PIPE1.PLP"))!=KErrNotFound || fileName.MatchF(_L("FOUR"))!=KErrNotFound || fileName.MatchF(_L("File*.TXT"))!=KErrNotFound  || fileName.MatchF(_L("ah"))!=KErrNotFound || fileName.MatchF(_L("a"))!=KErrNotFound);
    65 		}
    67 		}
    66 	return(MFileManObserver::EContinue);
    68 	return(MFileManObserver::EContinue);
    67 	}
    69 	}
       
    70 
       
    71 LOCAL_C TBool GetSecondDrive(TChar& aDrive) // Get the drive that is ready.
       
    72     {
       
    73     TDriveList list;
       
    74     TheFs.DriveList(list);
       
    75     if (list[EDriveD] != 0)
       
    76         {
       
    77         aDrive = 'D';
       
    78         return ETrue;
       
    79         }
       
    80     
       
    81     TInt drv;
       
    82     // In minibsp rom(sirocco) there is no D drive
       
    83     for(drv = EDriveE; drv < EDriveZ; drv++)
       
    84         {
       
    85         if (list[drv] != 0) 
       
    86             {
       
    87             aDrive = 'A' + drv;
       
    88             return ETrue;
       
    89             }
       
    90         }
       
    91     aDrive = '?';
       
    92     return EFalse;
       
    93     }
    68 
    94 
    69 LOCAL_C void WaitForSuccess()
    95 LOCAL_C void WaitForSuccess()
    70 //
    96 //
    71 // Wait for gStat to complete with KErrNone
    97 // Wait for gStat to complete with KErrNone
    72 //
    98 //
   173 
   199 
   174 	if(aDestOtherDrive)
   200 	if(aDestOtherDrive)
   175 		{
   201 		{
   176 #if !defined(__WINS__)
   202 #if !defined(__WINS__)
   177 		*aDestOtherDrive = gSessionPath[0] == 'C' ? _L("D:\\F32-TST\\TFMAN\\dest\\") : _L("C:\\F32-TST\\TFMAN\\dest\\");
   203 		*aDestOtherDrive = gSessionPath[0] == 'C' ? _L("D:\\F32-TST\\TFMAN\\dest\\") : _L("C:\\F32-TST\\TFMAN\\dest\\");
       
   204         (*aDestOtherDrive)[0] = (TText) gSecDrive;
   178 #else
   205 #else
   179 		*aDestOtherDrive = gSessionPath[0] == 'C' ? _L("Y:\\F32-TST\\TFMAN\\dest\\") : _L("C:\\F32-TST\\TFMAN\\dest\\");
   206 		*aDestOtherDrive = gSessionPath[0] == 'C' ? _L("Y:\\F32-TST\\TFMAN\\dest\\") : _L("C:\\F32-TST\\TFMAN\\dest\\");
   180 #endif
   207 #endif
   181 		err = TheFs.MkDirAll(*aDestOtherDrive);
   208 		err = TheFs.MkDirAll(*aDestOtherDrive);
   182 		test_Value(err, err == KErrNone || err == KErrAlreadyExists);
   209 		test_Value(err, err == KErrNone || err == KErrAlreadyExists);
  2161    	test.Next(_L("Test synchronous and asynchronous move operations (INC108401)"));
  2188    	test.Next(_L("Test synchronous and asynchronous move operations (INC108401)"));
  2162    	TInt err = 0;
  2189    	TInt err = 0;
  2163    	
  2190    	
  2164 	TFileName trgPath = _L("?:\\F32-TST\\");
  2191 	TFileName trgPath = _L("?:\\F32-TST\\");
  2165 
  2192 
  2166 	if (gSessionPath[0]!='D'&& gSessionPath[0]!='Y')
  2193 	if (gSessionPath[0]!='D'&& gSessionPath[0]!='Y' && gSessionPath[0]!='I')
  2167 		{
  2194 		{
  2168 #if !defined(__WINS__)
  2195 #if !defined(__WINS__)
  2169 		trgPath[0] = 'D';
  2196         if (!gSecDriveReady)
       
  2197             {
       
  2198             test.Printf(_L("Second drive not available for test, skip..."));
       
  2199             return;
       
  2200             }
       
  2201 		trgPath[0] = (TText) gSecDrive;
  2170 #else
  2202 #else
  2171 		trgPath[0] = 'Y';
  2203 		trgPath[0] = 'Y';
  2172 #endif
  2204 #endif
  2173 		}
  2205 		}
  2174 	else
  2206 	else
  2791 	TFileName trgSpec  = _L("\\F32-TST\\TFMAN\\RECMOVE2\\*");
  2823 	TFileName trgSpec  = _L("\\F32-TST\\TFMAN\\RECMOVE2\\*");
  2792 
  2824 
  2793 	if (gSessionPath[0]=='C')
  2825 	if (gSessionPath[0]=='C')
  2794 		{
  2826 		{
  2795 #if !defined(__WINS__)
  2827 #if !defined(__WINS__)
  2796 		trgDir	   = _L("D:\\F32-TST\\TFMAN\\RECMOVE2\\");
  2828         if (!gSecDriveReady)
  2797 		trgSpec	   = _L("D:\\F32-TST\\TFMAN\\RECMOVE2\\*");
  2829             {
       
  2830             test.Printf(_L("Second drive not available for test, skip..."));
       
  2831             return;
       
  2832             }
       
  2833 		trgDir	   = _L("?:\\F32-TST\\TFMAN\\RECMOVE2\\");
       
  2834 		trgSpec	   = _L("?:\\F32-TST\\TFMAN\\RECMOVE2\\*");     
       
  2835         trgDir[0] = (TText) gSecDrive;;
       
  2836         trgSpec[0] = (TText) gSecDrive;;
  2798 #else
  2837 #else
  2799 		trgDir     = _L("Y:\\F32-TST\\TFMAN\\RECMOVE2\\");
  2838 		trgDir     = _L("Y:\\F32-TST\\TFMAN\\RECMOVE2\\");
  2800 		trgSpec    = _L("Y:\\F32-TST\\TFMAN\\RECMOVE2\\*");
  2839 		trgSpec    = _L("Y:\\F32-TST\\TFMAN\\RECMOVE2\\*");
  2801 #endif
  2840 #endif
  2802 		}
  2841 		}
  2823 	MakeFile(_L("C:\\F32-TST\\TFMAN\\AFTER\\FILE1.PLP"));
  2862 	MakeFile(_L("C:\\F32-TST\\TFMAN\\AFTER\\FILE1.PLP"));
  2824 	Compare(_L("C:\\F32-TST\\TFMAN\\after\\*"),trgSpec);
  2863 	Compare(_L("C:\\F32-TST\\TFMAN\\after\\*"),trgSpec);
  2825 	RmDir(_L("C:\\F32-TST\\TFMAN\\AFTER\\"));
  2864 	RmDir(_L("C:\\F32-TST\\TFMAN\\AFTER\\"));
  2826 	RmDir(_L("C:\\F32-TST\\TFMAN\\RECMOVE\\"));
  2865 	RmDir(_L("C:\\F32-TST\\TFMAN\\RECMOVE\\"));
  2827 	
  2866 	
       
  2867     TFileName destOtherDrive;
  2828 	//
  2868 	//
  2829 	// Test moving empty directories (DEF073924)
  2869 	// Test moving empty directories (DEF073924)
  2830 	//
  2870 	//
  2831 	test.Next(_L("Test moving empty directories"));
  2871 	test.Next(_L("Test moving empty directories"));
  2832 
  2872 	
  2833 	TFileName destOtherDrive;
  2873 	if (gSecDriveReady)
  2834 	SetupDirectories(EFalse, &destOtherDrive);
  2874 	    {
  2835 
  2875         SetupDirectories(EFalse, &destOtherDrive);
  2836 	err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\"), destOtherDrive, CFileMan::ERecurse);
  2876     
  2837 	test_Equal(KErrNotFound, err);	// Expected - directory is empty
  2877         err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\"), destOtherDrive, CFileMan::ERecurse);
  2838 
  2878         test_Equal(KErrNotFound, err);	// Expected - directory is empty
  2839 	// Test that all directories are still present
  2879     
  2840 	TEntry entry;
  2880         // Test that all directories are still present
  2841 	err = TheFs.Entry(_L("\\F32-TST\\TFMAN\\source\\"), entry);
  2881         TEntry entry;
  2842 	test_KErrNone(err);
  2882         err = TheFs.Entry(_L("\\F32-TST\\TFMAN\\source\\"), entry);
  2843 	err = TheFs.Entry(destOtherDrive, entry);
  2883         test_KErrNone(err);
  2844 	test_KErrNone(err);
  2884         err = TheFs.Entry(destOtherDrive, entry);
  2845 
  2885         test_KErrNone(err);
       
  2886 	    }
       
  2887 	else
       
  2888 	    {
       
  2889         test.Printf(_L("Second drive not available for test, skip..."));
       
  2890 	    }
  2846 	//--------------------------------------------- 
  2891 	//--------------------------------------------- 
  2847 	//! @SYMTestCaseID			PBASE-T_FMAN-0571
  2892 	//! @SYMTestCaseID			PBASE-T_FMAN-0571
  2848 	//! @SYMTestType			UT
  2893 	//! @SYMTestType			UT
  2849 	//! @SYMREQ					INC108401
  2894 	//! @SYMREQ					INC108401
  2850 	//! @SYMTestCaseDesc		This testcase tests the synchronous and asynchronous move operations 
  2895 	//! @SYMTestCaseDesc		This testcase tests the synchronous and asynchronous move operations 
  2880 	//
  2925 	//
  2881 	// Test moving when the source directory contains subdirectories (INC074828, INC078800)
  2926 	// Test moving when the source directory contains subdirectories (INC074828, INC078800)
  2882 	//
  2927 	//
  2883 	test.Next(_L("Test moving a directory containing subdirectories"));
  2928 	test.Next(_L("Test moving a directory containing subdirectories"));
  2884 
  2929 
  2885 	SetupDirectories(ETrue, &destOtherDrive);
  2930     if (gSecDriveReady)
  2886 	err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\"), destOtherDrive, CFileMan::ERecurse | CFileMan::EOverWrite);
  2931         {
  2887 	test_KErrNone(err);
  2932         SetupDirectories(ETrue, &destOtherDrive);
  2888 
  2933         err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\"), destOtherDrive, CFileMan::ERecurse | CFileMan::EOverWrite);
  2889 	destOtherDrive.Append(_L("*"));
  2934         test_KErrNone(err);
  2890 	Compare(_L("\\F32-TST\\TFMAN\\compare\\*"), destOtherDrive);
  2935         
  2891 
  2936         destOtherDrive.Append(_L("*"));
       
  2937         Compare(_L("\\F32-TST\\TFMAN\\compare\\*"), destOtherDrive);
       
  2938         }
       
  2939     else
       
  2940         {
       
  2941         test.Printf(_L("Second drive not available for test, skip..."));
       
  2942         }
  2892 	//--------------------------------------------- 
  2943 	//--------------------------------------------- 
  2893 	//! @SYMTestCaseID			PBASE-T_FMAN-0161
  2944 	//! @SYMTestCaseID			PBASE-T_FMAN-0161
  2894 	//! @SYMTestType			UT 
  2945 	//! @SYMTestType			UT 
  2895 	//! @SYMREQ					DEF087791
  2946 	//! @SYMREQ					DEF087791
  2896 	//! @SYMTestCaseDesc		Test that CFileMan::Move() works when the destination paths does not exist.
  2947 	//! @SYMTestCaseDesc		Test that CFileMan::Move() works when the destination paths does not exist.
  2898 	//! @SYMTestExpectedResults Completes with no error, files are copied and intermediate directories are created.
  2949 	//! @SYMTestExpectedResults Completes with no error, files are copied and intermediate directories are created.
  2899 	//! @SYMTestPriority		High
  2950 	//! @SYMTestPriority		High
  2900 	//! @SYMTestStatus			Implemented 
  2951 	//! @SYMTestStatus			Implemented 
  2901 	//--------------------------------------------- 	
  2952 	//--------------------------------------------- 	
  2902 	test.Next(_L("Test moving when the target directory does not exist"));
  2953 	test.Next(_L("Test moving when the target directory does not exist"));
  2903 
  2954     
  2904 	SetupDirectories(ETrue, &destOtherDrive);
  2955 	if (gSecDriveReady)
  2905 	
  2956         {
  2906 	RmDir(destOtherDrive);
  2957         SetupDirectories(ETrue, &destOtherDrive);
  2907 
  2958         
  2908 	err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\"), destOtherDrive, CFileMan::ERecurse);
  2959         RmDir(destOtherDrive);
  2909 	test_KErrNone(err);
  2960     
  2910 
  2961         err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\"), destOtherDrive, CFileMan::ERecurse);
  2911 	Compare(_L("\\F32-TST\\TFMAN\\compare\\*"), destOtherDrive);
  2962         test_KErrNone(err);
  2912 
  2963     
  2913 	SetupDirectories(ETrue, &destOtherDrive);
  2964         Compare(_L("\\F32-TST\\TFMAN\\compare\\*"), destOtherDrive);
  2914 	
  2965     
  2915 	RmDir(destOtherDrive);
  2966         SetupDirectories(ETrue, &destOtherDrive);
  2916 
  2967         
  2917 	err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source"), destOtherDrive, CFileMan::ERecurse);
  2968         RmDir(destOtherDrive);
  2918 	test_KErrNone(err);
  2969     
  2919 
  2970         err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source"), destOtherDrive, CFileMan::ERecurse);
  2920 	MakeDir(_L("\\F32-TST\\TFMAN\\compare\\subdir\\"));
  2971         test_KErrNone(err);
  2921 	destOtherDrive.Append(_L("source\\"));
  2972     
  2922 	Compare(_L("\\F32-TST\\TFMAN\\compare\\*"), destOtherDrive);
  2973         MakeDir(_L("\\F32-TST\\TFMAN\\compare\\subdir\\"));
  2923 	RmDir(_L("\\F32-TST\\TFMAN\\compare\\subdir\\"));
  2974         destOtherDrive.Append(_L("source\\"));
  2924 
  2975         Compare(_L("\\F32-TST\\TFMAN\\compare\\*"), destOtherDrive);
  2925 	SetupDirectories(ETrue, &destOtherDrive);
  2976         RmDir(_L("\\F32-TST\\TFMAN\\compare\\subdir\\"));
  2926 
  2977     
  2927 	RmDir(destOtherDrive);
  2978         SetupDirectories(ETrue, &destOtherDrive);
  2928 
  2979     
  2929 	err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\File1.TXT"), destOtherDrive, CFileMan::ERecurse);
  2980         RmDir(destOtherDrive);
  2930 	test_KErrNone(err);
  2981     
  2931 
  2982         err = gFileMan->Move(_L("\\F32-TST\\TFMAN\\source\\File1.TXT"), destOtherDrive, CFileMan::ERecurse);
  2932 	CheckFileExists(_L("\\F32-TST\\TFMAN\\source\\File1.TXT"), KErrNotFound, ETrue);
  2983         test_KErrNone(err);
  2933 	destOtherDrive.Append(_L("File1.TXT"));
  2984     
  2934 	CheckFileExists(destOtherDrive, KErrNone, ETrue);
  2985         CheckFileExists(_L("\\F32-TST\\TFMAN\\source\\File1.TXT"), KErrNotFound, ETrue);
  2935 
  2986         destOtherDrive.Append(_L("File1.TXT"));
  2936 	RmDir(destOtherDrive);
  2987         CheckFileExists(destOtherDrive, KErrNone, ETrue);
  2937 	RmDir(_L("\\F32-TST\\TFMAN\\source\\"));
  2988     
       
  2989         RmDir(destOtherDrive);
       
  2990         RmDir(_L("\\F32-TST\\TFMAN\\source\\"));
       
  2991         }
       
  2992     else
       
  2993         {
       
  2994         test.Printf(_L("Second drive not available for test, skip..."));
       
  2995         }
  2938 
  2996 
  2939 	//
  2997 	//
  2940 	// Test recursive move of complex directory structure into itself (INC078759)
  2998 	// Test recursive move of complex directory structure into itself (INC078759)
  2941 	//
  2999 	//
  2942 
  3000 
  3775 	TFileName trgDirFile = _L("\\DRIVEMOVE\\Sketch");
  3833 	TFileName trgDirFile = _L("\\DRIVEMOVE\\Sketch");
  3776 
  3834 
  3777 	if (gSessionPath[0]=='C')
  3835 	if (gSessionPath[0]=='C')
  3778 		{
  3836 		{
  3779 #if !defined(__WINS__)
  3837 #if !defined(__WINS__)
  3780 		trgDrive   = _L("D:\\");
  3838         if (!gSecDriveReady)
  3781 		trgFile    = _L("D:\\Sketch");
  3839             {
  3782 		trgDir     = _L("D:\\DRIVEMOVE\\");
  3840             test.Printf(_L("Second drive not available for test, skip..."));
  3783 		trgDirFile = _L("D:\\DRIVEMOVE\\Sketch");
  3841             return;
       
  3842             }
       
  3843 		trgDrive   = _L("?:\\");
       
  3844 		trgFile    = _L("?:\\Sketch");
       
  3845 		trgDir     = _L("?:\\DRIVEMOVE\\");
       
  3846 		trgDirFile = _L("?:\\DRIVEMOVE\\Sketch");
       
  3847 		trgDrive[0] = (TText) gSecDrive;;
       
  3848         trgFile[0]  = (TText) gSecDrive;
       
  3849         trgDir[0]   = (TText) gSecDrive;
       
  3850         trgDirFile[0]  = (TText) gSecDrive;		
  3784 #else
  3851 #else
  3785 		trgDrive   = _L("Y:\\");
  3852 		trgDrive   = _L("Y:\\");
  3786 		trgFile    = _L("Y:\\Sketch");
  3853 		trgFile    = _L("Y:\\Sketch");
  3787 		trgDir     = _L("Y:\\DRIVEMOVE\\");
  3854 		trgDir     = _L("Y:\\DRIVEMOVE\\");
  3788 		trgDirFile = _L("Y:\\DRIVEMOVE\\Sketch");
  3855 		trgDirFile = _L("Y:\\DRIVEMOVE\\Sketch");
  3883 	TFileName trgDirFile = _L("\\F32-TST\\TFMAN\\CANCELMOVE\\FILE");
  3950 	TFileName trgDirFile = _L("\\F32-TST\\TFMAN\\CANCELMOVE\\FILE");
  3884 
  3951 
  3885 	if (gSessionPath[0]=='C')
  3952 	if (gSessionPath[0]=='C')
  3886 		{
  3953 		{
  3887 #if !defined(__WINS__)
  3954 #if !defined(__WINS__)
  3888 		trgDirRoot = _L("D:\\F32-TST\\TFMAN\\");
  3955         if (!gSecDriveReady)
  3889 		trgDirFull = _L("D:\\F32-TST\\TFMAN\\CANCELMOVE\\");
  3956             {
  3890         trgDirFile = _L("D:\\F32-TST\\TFMAN\\CANCELMOVE\\FILE");
  3957             test.Printf(_L("Second drive not available for test, skip..."));
       
  3958             return;
       
  3959             }
       
  3960 		trgDirRoot = _L("?:\\F32-TST\\TFMAN\\");
       
  3961 		trgDirFull = _L("?:\\F32-TST\\TFMAN\\CANCELMOVE\\");
       
  3962         trgDirFile = _L("?:\\F32-TST\\TFMAN\\CANCELMOVE\\FILE");
       
  3963         trgDirRoot[0] = (TText) gSecDrive;
       
  3964         trgDirFull[0] = (TText) gSecDrive;
       
  3965         trgDirFile[0] = (TText) gSecDrive;
  3891 #else
  3966 #else
  3892 		trgDirRoot = _L("Y:\\F32-TST\\TFMAN\\");
  3967 		trgDirRoot = _L("Y:\\F32-TST\\TFMAN\\");
  3893 		trgDirFull = _L("Y:\\F32-TST\\TFMAN\\CANCELMOVE\\");
  3968 		trgDirFull = _L("Y:\\F32-TST\\TFMAN\\CANCELMOVE\\");
  3894         trgDirFile = _L("Y:\\F32-TST\\TFMAN\\CANCELMOVE\\FILE");
  3969         trgDirFile = _L("Y:\\F32-TST\\TFMAN\\CANCELMOVE\\FILE");
  3895 #endif
  3970 #endif
  3967 //
  4042 //
  3968 	{
  4043 	{
  3969 	test.Next(_L("Test move empty directory"));
  4044 	test.Next(_L("Test move empty directory"));
  3970 
  4045 
  3971 #if !defined(__WINS__)
  4046 #if !defined(__WINS__)
  3972 	TFileName trgDrive=_L("D:\\");
  4047     if (!gSecDriveReady)
       
  4048         {
       
  4049         test.Printf(_L("Second drive not available for test, skip..."));
       
  4050         return;
       
  4051         }
       
  4052 	TFileName trgDrive=_L("?:\\");
       
  4053 	trgDrive[0] = (TText) gSecDrive;
  3973 #else
  4054 #else
  3974 	if (gSessionPath[0]!='C')
  4055 	if (gSessionPath[0]!='C')
  3975 		return;
  4056 		return;
  3976 	TFileName trgDrive=_L("C:\\");
  4057 	TFileName trgDrive=_L("C:\\");
  3977 #endif
  4058 #endif
  4112 //
  4193 //
  4113 	{
  4194 	{
  4114 	gFileMan=CFileMan::NewL(TheFs);
  4195 	gFileMan=CFileMan::NewL(TheFs);
  4115 	gObserver=new(ELeave) CFileManObserver(gFileMan);
  4196 	gObserver=new(ELeave) CFileManObserver(gFileMan);
  4116 	gFileMan->SetObserver(gObserver);
  4197 	gFileMan->SetObserver(gObserver);
       
  4198 	gSecDriveReady = GetSecondDrive(gSecDrive);
  4117 	}
  4199 	}
  4118 
  4200 
  4119 LOCAL_C void Cleanup()
  4201 LOCAL_C void Cleanup()
  4120 //
  4202 //
  4121 // Cleanup test variables
  4203 // Cleanup test variables