kerneltest/f32test/server/t_rename.cpp
changeset 33 0173bcd7697c
parent 0 a41df078684a
child 62 4a8fed1c0ef6
equal deleted inserted replaced
31:56f325a607ea 33:0173bcd7697c
    16 //
    16 //
    17 
    17 
    18 #include <f32file.h>
    18 #include <f32file.h>
    19 #include <e32test.h>
    19 #include <e32test.h>
    20 #include "t_server.h"
    20 #include "t_server.h"
    21 
    21 #include "f32_test_utils.h"
    22 #if defined(__WINS__)
    22 
    23 #define WIN32_LEAN_AND_MEAN
    23 using namespace F32_Test_Utils;
    24 #pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
    24 TInt gDriveNum = -1;
    25 #pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union
    25 
    26 #endif
    26 RTest test(_L("T_RENAME"));
    27 
       
    28 #if defined(_UNICODE)
       
    29 #if !defined(UNICODE)
       
    30 #define UNICODE
       
    31 #endif
       
    32 #endif
       
    33 
       
    34 GLDEF_D RTest test(_L("T_RENAME"));
       
    35 
    27 
    36 TBuf8<26> alphaBuffer=_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    28 TBuf8<26> alphaBuffer=_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    37 TPtr8 alphaPtr((TText8*)alphaBuffer.Ptr(),alphaBuffer.Size(),alphaBuffer.Size());
    29 TPtr8 alphaPtr((TText8*)alphaBuffer.Ptr(),alphaBuffer.Size(),alphaBuffer.Size());
    38 
    30 
    39 TBuf8<17> BeckBuffer=_L8("A Devil's Haircut");
    31 TBuf8<17> BeckBuffer=_L8("A Devil's Haircut");
    40 TPtr8 BeckPtr((TText8*)BeckBuffer.Ptr(),BeckBuffer.Size(),BeckBuffer.Size());
    32 TPtr8 BeckPtr((TText8*)BeckBuffer.Ptr(),BeckBuffer.Size(),BeckBuffer.Size());
    41 
    33 
    42 /*
    34 
    43 
    35 static void CreateTestFiles()
    44 	What this test is for:
       
    45 	Tests bug fix for the bug which created two files of the same name
       
    46  
       
    47 */
       
    48 
       
    49 LOCAL_C void CreateTestFiles()
       
    50 //
       
    51 //
       
    52 //
       
    53 	{
    36 	{
    54 	test.Next(_L("Create test files"));
    37 	test.Next(_L("Create test files"));
    55 	TInt r=TheFs.MkDir(_L("\\F32-TST\\"));
    38 	TInt r=TheFs.MkDir(_L("\\F32-TST\\"));
    56 	test(r==KErrNone || r==KErrAlreadyExists);
    39 	test(r==KErrNone || r==KErrAlreadyExists);
    57 
    40 
    77 	r=file.Write(BeckPtr);
    60 	r=file.Write(BeckPtr);
    78 	test(r==KErrNone);
    61 	test(r==KErrNone);
    79 	file.Close();
    62 	file.Close();
    80 
    63 
    81 	}
    64 	}
    82 /*
    65 
    83 LOCAL_C void CleanUp()
    66 static TInt CountFiles(TPtrC aDirectory, TPtrC aFileName)
    84 //
       
    85 //	Delete any files created by the tests
       
    86 //
       
    87 	{
       
    88 	TInt r=TheFs.Delete(_L("\\F32-TST\\TESTFILE"));
       
    89 	test(r==KErrNone);
       
    90 	r=TheFs.Delete(_L("\\F32-TST\\RFSFILE"));
       
    91 	test(r==KErrNone);
       
    92 	r=TheFs.Delete(_L("\\F32-TST\\EIKFILE"));
       
    93 	test(r==KErrNone);
       
    94 	r=TheFs.Delete(_L("\\F32-TST\\TEST"));
       
    95 	test(r==KErrNone);
       
    96 	r=TheFs.RmDir(_L("\\F32-TST\\SYSTEM\\"));
       
    97 	test(r==KErrNone);
       
    98 	}
       
    99 */
       
   100 
       
   101 LOCAL_C TInt CountFiles(TPtrC aDirectory, TPtrC aFileName)
       
   102 //
    67 //
   103 //	Return the number of files of aFileName found in aDirectory
    68 //	Return the number of files of aFileName found in aDirectory
   104 //	
    69 //	
   105 	{
    70 	{
   106 	RDir dir;
    71 	
       
    72     RDir dir;
   107 	TFileName sessionPath;
    73 	TFileName sessionPath;
   108 	TInt r=TheFs.SessionPath(sessionPath);
    74 	TInt r=TheFs.SessionPath(sessionPath);
   109 	test(r==KErrNone);
    75 	test(r==KErrNone);
   110 	TFileName path=_L("?:");
    76 	TFileName path=_L("?:");
   111 	path[0]=sessionPath[0];
    77 	path[0]=sessionPath[0];
   138 	dir.Close();
   104 	dir.Close();
   139 	delete anEntryList;
   105 	delete anEntryList;
   140 	return(fileCount);
   106 	return(fileCount);
   141 	}
   107 	}
   142 
   108 
   143 LOCAL_C void TestRFileRename()
   109 static void TestRFileRename()
   144 //
   110 //
   145 //	Test RFile::Rename() function
   111 //	Test RFile::Rename() function
   146 //
   112 //
   147 	{
   113 	{
   148 	test.Next(_L("Rename file with DOS compatible name using RFile function"));
   114 	test.Next(_L("Rename file with DOS compatible name using RFile function"));
   166 
   132 
   167 	file.Close();
   133 	file.Close();
   168 	}
   134 	}
   169 
   135 
   170 
   136 
   171 LOCAL_C void TestRFsRename()
   137 static void TestRFsRename()
   172 //
   138 //
   173 //	Test RFs::Rename() function
   139 //	Test RFs::Rename() function
   174 //
   140 //
   175 	{
   141 	{
   176 	test.Next(_L("Rename file with DOS compatible name using RFs function"));
   142 	test.Next(_L("Rename file with DOS compatible name using RFs function"));
   188 	test(r==KErrNone);
   154 	test(r==KErrNone);
   189 
   155 
   190 	file.Close();
   156 	file.Close();
   191 	}
   157 	}
   192 
   158 
   193 LOCAL_C void TestEikonRename()
   159 static void TestEikonRename()
   194 //
   160 //
   195 //	Test EIKON style rename by creating a new file, and copying old data into new file
   161 //	Test EIKON style rename by creating a new file, and copying old data into new file
   196 //
   162 //
   197 	{
   163 	{
   198 	test.Next(_L("Rename file with DOS compatible name simulating EIKON"));
   164 	test.Next(_L("Rename file with DOS compatible name simulating EIKON"));
   217 
   183 
   218 	file.Close();
   184 	file.Close();
   219 	}
   185 	}
   220 
   186 
   221 
   187 
   222 LOCAL_C void TestReplaceAndRename()
   188 static void TestReplaceAndRename()
   223 //
   189 //
   224 //	Tests the bug which allows 2 files of the same name to be created has been fixed
   190 //	Tests the bug which allows 2 files of the same name to be created has been fixed
   225 //
   191 //
   226 	{
   192 	{
   227 	TInt r;
   193 	TInt r;
   426 	test(r==KErrNone);
   392 	test(r==KErrNone);
   427 	fileCount=CountFiles(_L("\\F32-TST\\"),_L("TEST1"));
   393 	fileCount=CountFiles(_L("\\F32-TST\\"),_L("TEST1"));
   428 	test(fileCount==0);
   394 	test(fileCount==0);
   429 	test(r==KErrNone);
   395 	test(r==KErrNone);
   430 
   396 
   431 //	Clean up
   397 	}
   432 	RFormat format;
   398 
   433 	TInt count;
   399 
   434 	TFileName sessionPath;
   400 void CallTestsL(void)
   435 	r=TheFs.SessionPath(sessionPath);
       
   436 	r=format.Open(TheFs,sessionPath,EQuickFormat,count);
       
   437 	if (r == KErrAccessDenied)
       
   438 		return;
       
   439 	test(r==KErrNone);
       
   440 	while(count && r==KErrNone)
       
   441 		r=format.Next(count);
       
   442 	format.Close();
       
   443 	}
       
   444 
       
   445 
       
   446 GLDEF_C void CallTestsL(void)
       
   447 //
       
   448 // Do all tests
       
   449 //
       
   450 	{
   401 	{
   451 	
   402 	
   452 	test.Title();
   403 	test.Title();
   453 	test.Start(_L("Testing rename"));
   404 	test.Start(_L("Testing rename"));
   454 
   405 
   455 	TheFs.MkDir(_L("\\F32-TST\\SYSTEM\\"));
   406     //-- set up console output
       
   407     F32_Test_Utils::SetConsole(test.Console());
       
   408 
       
   409     TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum);
       
   410     test(nRes==KErrNone);
       
   411     
       
   412     PrintDrvInfo(TheFs, gDriveNum);
       
   413 
       
   414     if(!Is_Win32(TheFs, gDriveNum))
       
   415         {
       
   416         nRes = FormatDrive(TheFs, gDriveNum, ETrue);
       
   417         test(nRes==KErrNone);
       
   418         }
       
   419     
       
   420 
       
   421 	MakeDir(_L("\\F32-TST\\SYSTEM\\"));
   456 	CreateTestFiles();
   422 	CreateTestFiles();
   457 	TestRFsRename();
   423 	TestRFsRename();
   458 	TestRFileRename();
   424 	TestRFileRename();
   459 	TestEikonRename();
   425 	TestEikonRename();
   460 	TestReplaceAndRename();
   426 	TestReplaceAndRename();
   461 
   427 
       
   428     if(!Is_Win32(TheFs, gDriveNum))
       
   429         {
       
   430         nRes = FormatDrive(TheFs, gDriveNum, ETrue);
       
   431         test(nRes==KErrNone);
       
   432         }
       
   433 
   462 	test.End();
   434 	test.End();
   463 	test.Close();
   435 	test.Close();
   464 	}
   436 	}
   465 
   437