kerneltest/f32test/server/b_gen.cpp
branchRCL_3
changeset 19 4a8fed1c0ef6
parent 0 a41df078684a
child 43 c1f20ce4abcf
equal deleted inserted replaced
15:2d65c2f76d7b 19:4a8fed1c0ef6
    18 #include <e32math.h>
    18 #include <e32math.h>
    19 #include <e32hal.h>
    19 #include <e32hal.h>
    20 #include "t_server.h"
    20 #include "t_server.h"
    21 #include "t_chlffs.h"
    21 #include "t_chlffs.h"
    22 
    22 
    23 #ifdef __VC32__
    23 #include "f32_test_utils.h"
    24     // Solve compilation problem caused by non-English locale
    24 using namespace F32_Test_Utils;
    25     #pragma setlocale("english")
    25 
    26 #endif
    26 RTest test(_L("B_GEN"));
    27 
       
    28 GLDEF_D RTest test(_L("B_GEN"));
       
    29 //
    27 //
    30 // File test - general test of local filing system routines
    28 // File test - general test of local filing system routines
    31 //             (finishes with formating current device).
    29 //             (finishes with formating current device).
    32 // Modified from BB's epoc test code
    30 // Modified from BB's epoc test code
    33 
    31 
    35 #define DateTests   10
    33 #define DateTests   10
    36 
    34 
    37 // GLREF_D P_DEVICE p_file;
    35 // GLREF_D P_DEVICE p_file;
    38 // GLREF_D P_DEVICE p_wind,p_screen,p_cons;
    36 // GLREF_D P_DEVICE p_wind,p_screen,p_cons;
    39 
    37 
    40 GLDEF_D TBuf<0x100> gNameBuf;
    38 TBuf<0x100> gNameBuf;
    41 GLDEF_D	TBuf<0x100> gNameOut;
    39 TBuf<0x100> gNameOut;
    42 GLDEF_D RFile gFile;
    40 RFile gFile;
    43 GLDEF_D RFile gFileErr;
    41 RFile gFileErr;
    44 GLDEF_D RFile gFile2;
    42 RFile gFile2;
    45 GLDEF_D RDir gDir;
    43 RDir gDir;
    46 GLDEF_D RFormat gFormat;
    44 RFormat gFormat;
    47 //GLDEF_D void *chan1,*chan2;
    45 TFileName fBuf;
    48 GLDEF_D TFileName fBuf;
    46 TInt gDriveNum = -1;
    49 //GLDEF_D TUint8 fBuf[P_FNAMESIZE];
    47 
    50 
    48 
    51 
    49 static TBuf8<0x4000> gDataBuf;
    52 LOCAL_D TBuf8<0x4000> gDataBuf;
    50 static TEntry gFileEntry;
    53 LOCAL_D TEntry gFileEntry;
    51 static TVolumeInfo volInfo;
    54 // LOCAL_D P_DINFO volInfo;
    52 static TFileName pathBuf;
    55 LOCAL_D TVolumeInfo volInfo;
    53 
    56 // LOCAL_D P_NINFO nInfo;
    54 
    57 LOCAL_D TFileName pathBuf;
    55 const TInt NameErr=KErrBadName;
    58 
    56 const TInt DirErr=KErrPathNotFound;
    59 
    57 const TInt AccessErr=KErrAccessDenied;
    60 LOCAL_D TInt NameErr=KErrBadName;
    58 const TInt LockedErr=KErrInUse;
    61 LOCAL_D TInt DirErr=KErrPathNotFound;
    59 const TInt ExistsErr=KErrAlreadyExists;
    62 LOCAL_D TInt AccessErr=KErrAccessDenied;
    60 const TInt NotExistsErr=KErrNotFound;
    63 LOCAL_D TInt LockedErr=KErrInUse;
    61 const TInt EofErr=KErrEof;
    64 LOCAL_D TInt ExistsErr=KErrAlreadyExists;
    62 const TInt DeviceErr=KErrNotReady;
    65 LOCAL_D TInt NotExistsErr=KErrNotFound;
       
    66 LOCAL_D TInt EofErr=KErrEof;
       
    67 LOCAL_D TInt DeviceErr=KErrNotReady;
       
    68 //LOCAL_D TInt NoFileSystemErr=KErrNotReady;
    63 //LOCAL_D TInt NoFileSystemErr=KErrNotReady;
    69 //LOCAL_D TInt NotSupportedErr=KErrNotSupported;
    64 //LOCAL_D TInt NotSupportedErr=KErrNotSupported;
    70 LOCAL_D TInt ReadOnlyErr=KErrAccessDenied;
    65 const TInt ReadOnlyErr=KErrAccessDenied;
    71 
    66 
    72 LOCAL_D TInt P_FASTREAM=EFileStream;
    67 const TInt P_FASTREAM=EFileStream;
    73 LOCAL_D TInt P_FAEXEC=0;
    68 const TInt P_FAEXEC=0;
    74 LOCAL_D TInt P_FAMOD=KEntryAttArchive;
    69 const TInt P_FAMOD=KEntryAttArchive;
    75 LOCAL_D TInt P_FAREAD=KEntryAttReadOnly;
    70 const TInt P_FAREAD=KEntryAttReadOnly;
    76 //LOCAL_D TInt P_FAHIDDEN=KEntryAttHidden;
    71 //LOCAL_D TInt P_FAHIDDEN=KEntryAttHidden;
    77 //LOCAL_D TInt P_FASYSTEM=KEntryAttSystem;
    72 //LOCAL_D TInt P_FASYSTEM=KEntryAttSystem;
    78 //LOCAL_C TInt P_FAVOLUME=KEntryAttVolume;
    73 //static TInt P_FAVOLUME=KEntryAttVolume;
    79 LOCAL_C TInt P_FADIR=KEntryAttDir;
    74 const TInt P_FADIR=KEntryAttDir;
    80 LOCAL_C TInt P_FRANDOM=0;
    75 const TInt P_FRANDOM=0;
    81 LOCAL_C TInt P_FABS=ESeekStart;
    76 const TInt P_FABS=ESeekStart;
    82 
    77 
    83 LOCAL_C TInt P_FUPDATE=EFileWrite;
    78 const TInt P_FUPDATE=EFileWrite;
    84 
    79 
    85 
    80 
    86 LOCAL_C void doError(const TDesC &aMess, TInt anErr, TInt line)
    81 static void doError(const TDesC &aMess, TInt anErr, TInt line)
    87 	{ 
    82 	{ 
    88     test.Printf(_L("%S failed at line %d. Error %d\n"),&aMess, line, anErr);
    83     test.Printf(_L("%S failed at line %d. Error %d\n"),&aMess, line, anErr);
    89     test(0);
    84     test(0);
    90 	}
    85 	}
    91 #define Error(aMess, anErr) doError(aMess, anErr, __LINE__)
    86 #define Error(aMess, anErr) doError(aMess, anErr, __LINE__)
    92 
    87 
    93 LOCAL_C void doError2(const TDesC &aMess, TInt anErr, TInt line, TInt callLine)
    88 static void doError2(const TDesC &aMess, TInt anErr, TInt line, TInt callLine)
    94 	{ 
    89 	{ 
    95     test.Printf(_L("%S failed at line %d. Error %d. Called from line %d\n"),&aMess, line, anErr, callLine); \
    90     test.Printf(_L("%S failed at line %d. Error %d. Called from line %d\n"),&aMess, line, anErr, callLine); \
    96     test(0);
    91     test(0);
    97 	}
    92 	}
    98 #define Error2(aMess, anErr, line) doError2(aMess, anErr, __LINE__, line)
    93 #define Error2(aMess, anErr, line) doError2(aMess, anErr, __LINE__, line)
    99 
    94 
   100 LOCAL_C void testWrite(const TDesC& aName,TInt aLen,TInt32 aSize,TBool aShouldChange)
    95 static void testWrite(const TDesC& aName,TInt aLen,TInt32 aSize,TBool aShouldChange)
   101 //
    96 //
   102 // Write to a file
    97 // Write to a file
   103 //
    98 //
   104     {
    99     {
   105 
   100 
   121 		Error(_L("Change flag check 6"),0);
   116 		Error(_L("Change flag check 6"),0);
   122 	if (gFileEntry.iSize!=aSize)
   117 	if (gFileEntry.iSize!=aSize)
   123 		Error(_L("Size check 602"),0);
   118 		Error(_L("Size check 602"),0);
   124     }
   119     }
   125 
   120 
   126 LOCAL_C void testSetEof(const TDesC& aName,TUint32 aPos,TBool aShouldChange)
   121 static void testSetEof(const TDesC& aName,TUint32 aPos,TBool aShouldChange)
   127 //
   122 //
   128 // Set the end of a file
   123 // Set the end of a file
   129 //
   124 //
   130 	{
   125 	{
   131 
   126 
   146 	if ((saveTime!=gFileEntry.iModified)!=aShouldChange)
   141 	if ((saveTime!=gFileEntry.iModified)!=aShouldChange)
   147 		Error(_L("Change flag check 5"),0);
   142 		Error(_L("Change flag check 5"),0);
   148 	}
   143 	}
   149 
   144 
   150 
   145 
   151 LOCAL_C void testDir(const TDesC& aDirName)
   146 static void testDir(const TDesC& aDirName)
   152 //
   147 //
   153 // Create a directory
   148 // Create a directory
   154 //
   149 //
   155     {
   150     {
   156 
   151 
   171 		Error(_L("Device info 1000"),c);
   166 		Error(_L("Device info 1000"),c);
   172     }
   167     }
   173 
   168 
   174 
   169 
   175 /*
   170 /*
   176 LOCAL_C void testNodeInfo(const TDesC& aName,TInt type,TInt anErr)
   171 static void testNodeInfo(const TDesC& aName,TInt type,TInt anErr)
   177 //
   172 //
   178 // Test p_ninfo.
   173 // Test p_ninfo.
   179 //
   174 //
   180     {
   175     {
   181 
   176 
   191 //			Error(_L("Node type check"),0);
   186 //			Error(_L("Node type check"),0);
   192 		}
   187 		}
   193     }
   188     }
   194 */
   189 */
   195 
   190 
   196 LOCAL_C void testDeviceInfo(const TDesC& aDeviceName,TInt anErr)
   191 static void testDeviceInfo(const TDesC& aDeviceName,TInt anErr)
   197 //
   192 //
   198 // Test p_dinfo.
   193 // Test p_dinfo.
   199 //
   194 //
   200     {
   195     {
   201 
   196 
   216 		if (volInfo.iFree>volInfo.iSize)
   211 		if (volInfo.iFree>volInfo.iSize)
   217 			Error(_L("Free greater than size check"),0);
   212 			Error(_L("Free greater than size check"),0);
   218 		}
   213 		}
   219     }
   214     }
   220 
   215 
   221 LOCAL_C void testFileInfo(const TDesC& aFileName,TInt anErr)
   216 static void testFileInfo(const TDesC& aFileName,TInt anErr)
   222 //
   217 //
   223 // Test entry info
   218 // Test entry info
   224 //
   219 //
   225 	{
   220 	{
   226 
   221 
   245 				Error(_L("Info size check"),0);
   240 				Error(_L("Info size check"),0);
   246 			}
   241 			}
   247 		}
   242 		}
   248 	}
   243 	}
   249 
   244 
   250 LOCAL_C void testRenameFromRoot(const TDesC& aRName,const TDesC& aDName)
   245 static void testRenameFromRoot(const TDesC& aRName,const TDesC& aDName)
   251 //
   246 //
   252 //
   247 //
   253 //
   248 //
   254 	{
   249 	{
   255 
   250 
   261 	gFile.Close();
   256 	gFile.Close();
   262 	if ((c=TheFs.Delete(aRName))!=NotExistsErr)
   257 	if ((c=TheFs.Delete(aRName))!=NotExistsErr)
   263 		Error(_L("Delete 92"),c);
   258 		Error(_L("Delete 92"),c);
   264 	}
   259 	}
   265 
   260 
   266 LOCAL_C void testRenameToRoot(const TDesC& pName,const TDesC& rName)
   261 static void testRenameToRoot(const TDesC& pName,const TDesC& rName)
   267 //
   262 //
   268 //
   263 //
   269 //
   264 //
   270 	{
   265 	{
   271 
   266 
   280 	gFile.Close();
   275 	gFile.Close();
   281 	if ((c=TheFs.Delete(pName))!=NotExistsErr)
   276 	if ((c=TheFs.Delete(pName))!=NotExistsErr)
   282 		Error(_L("Delete 91"),c);
   277 		Error(_L("Delete 91"),c);
   283 	}
   278 	}
   284 
   279 
   285 LOCAL_C void verifyTestPat1()
   280 static void verifyTestPat1()
   286 //
   281 //
   287 //
   282 //
   288 //
   283 //
   289 	{
   284 	{
   290 
   285 
   318 	test(err == KErrNone);
   313 	test(err == KErrNone);
   319 	err = TheFs.RmDir(KDir1);
   314 	err = TheFs.RmDir(KDir1);
   320 	test(err == KErrNone);
   315 	test(err == KErrNone);
   321 	}
   316 	}
   322 	
   317 	
   323 LOCAL_C void testRename()
   318 static void testRename()
   324 //
   319 //
   325 // Test TheFs.Rename function.
   320 // Test TheFs.Rename function.
   326 //
   321 //
   327 	{
   322 	{
   328 
   323 
   473 		Error(_L("Delete 115"),c);
   468 		Error(_L("Delete 115"),c);
   474 	
   469 	
   475 	TestINC103141();  // PDEF104017
   470 	TestINC103141();  // PDEF104017
   476 	}    
   471 	}    
   477 
   472 
   478 LOCAL_C void testDelete()
   473 static void testDelete()
   479 //
   474 //
   480 // Test RFs::Delete function.
   475 // Test RFs::Delete function.
   481 //
   476 //
   482 	{
   477 	{
   483 
   478 
   499 		Error(_L("Delete 503"),c);
   494 		Error(_L("Delete 503"),c);
   500 	if ((c=TheFs.RmDir(_L("\\TESTDIR\\")))!=KErrNone)
   495 	if ((c=TheFs.RmDir(_L("\\TESTDIR\\")))!=KErrNone)
   501 		Error(_L("Delete 504"),c);
   496 		Error(_L("Delete 504"),c);
   502 	}
   497 	}
   503 
   498 
   504 LOCAL_C void testUnique(TUint fileFormat)
   499 static void testUnique(TUint fileFormat)
   505 //
   500 //
   506 // Test RFile::Temp
   501 // Test RFile::Temp
   507 //
   502 //
   508 	{
   503 	{
   509 
   504 
   523 	gFile.Close();
   518 	gFile.Close();
   524 	if ((c=TheFs.Delete(gNameBuf))!=KErrNone)
   519 	if ((c=TheFs.Delete(gNameBuf))!=KErrNone)
   525 		Error(_L("Delete"),c);
   520 		Error(_L("Delete"),c);
   526 	}
   521 	}
   527 
   522 
   528 LOCAL_C void testFileName(const TDesC& aFileName,TInt res)
   523 static void testFileName(const TDesC& aFileName,TInt res)
   529 //
   524 //
   530 //
   525 //
   531 //
   526 //
   532 	{
   527 	{
   533 
   528 
   554 		if ((c=gFile.Replace(TheFs,aFileName,EFileStream))!=res)
   549 		if ((c=gFile.Replace(TheFs,aFileName,EFileStream))!=res)
   555 			Error(_L("Replace 202"),c);
   550 			Error(_L("Replace 202"),c);
   556 		}
   551 		}
   557 	}
   552 	}
   558 
   553 
   559 #if defined(_UNICODE)
   554 static void testFileName(const TDesC8& aFileName,TInt res)
   560 LOCAL_C void testFileName(const TDesC8& aFileName,TInt res)
       
   561 //
   555 //
   562 // Defined to cope with all the instances of testFileName(gDataBuf,...)
   556 // Defined to cope with all the instances of testFileName(gDataBuf,...)
   563 //
   557 //
   564 	{
   558 	{
   565 	TPtrC gDataBuf16((TText*)aFileName.Ptr(),gDataBuf.Size()/sizeof(TText8));
   559 	TPtrC gDataBuf16((TText*)aFileName.Ptr(),gDataBuf.Size()/sizeof(TText8));
   566 	testFileName(gDataBuf16,res);
   560 	testFileName(gDataBuf16,res);
   567 	}
   561 	}
   568 #endif
   562 
   569 
   563 static void testVolumeName(const TDesC& aVolumeName,TInt aResultExpected)
   570 LOCAL_C void testVolumeName(const TDesC& aVolumeName,TInt aResultExpected)
       
   571 //
   564 //
   572 //
   565 //
   573 //
   566 //
   574 	{
   567 	{
   575 
   568 
   603 		}
   596 		}
   604 */
   597 */
   605 	}
   598 	}
   606 
   599 
   607 #define testMakeDir(aDirName, res) TestMakeDirLine(aDirName, res, __LINE__)
   600 #define testMakeDir(aDirName, res) TestMakeDirLine(aDirName, res, __LINE__)
   608 LOCAL_C void TestMakeDirLine(const TDesC& aDirName,TInt res, TInt line)
   601 static void TestMakeDirLine(const TDesC& aDirName,TInt res, TInt line)
   609 //
   602 //
   610 //
   603 //
   611 //
   604 //
   612 	{
   605 	{
   613 
   606 
   661                 break;
   654                 break;
   662         	}
   655         	}
   663     	}
   656     	}
   664 	}
   657 	}
   665 
   658 
   666 #if defined(_UNICODE)
   659 
   667 LOCAL_C void TestMakeDirLine(const TDesC8& aDirName, TInt res, TInt line)
   660 static void TestMakeDirLine(const TDesC8& aDirName, TInt res, TInt line)
   668 //
   661 //
   669 // Defined to cope with all the instances of testMakeDir(gDataBuf,...)
   662 // Defined to cope with all the instances of testMakeDir(gDataBuf,...)
   670 //
   663 //
   671 {
   664 {
   672     
   665     
   673     TPtrC gDataBuf16((TText*)aDirName.Ptr(),gDataBuf.Size()/sizeof(TText8));
   666     TPtrC gDataBuf16((TText*)aDirName.Ptr(),gDataBuf.Size()/sizeof(TText8));
   674     //	Not sizeof(TText16) since gDataBuf is a TBuf*!	
   667     //	Not sizeof(TText16) since gDataBuf is a TBuf*!	
   675     TestMakeDirLine(gDataBuf16, res, line);
   668     TestMakeDirLine(gDataBuf16, res, line);
   676 }
   669 }
   677 #endif
   670 
   678 
   671 
   679 #ifdef  TEST_MEDIA
   672 #ifdef  TEST_MEDIA
   680 LOCAL_C void testMedia(const TDesC& instructions,TInt anErr)
   673 static void testMedia(const TDesC& instructions,TInt anErr)
   681 //
   674 //
   682 //
   675 //
   683 //
   676 //
   684 	{
   677 	{
   685 
   678 
   711 			Error(_L("Close 100"),c);
   704 			Error(_L("Close 100"),c);
   712 		}
   705 		}
   713 	}
   706 	}
   714 #endif
   707 #endif
   715 
   708 
   716 GLDEF_C void CallTestsL()
   709 void CallTestsL()
   717 //
       
   718 // Do All tests
       
   719 //
       
   720     {
   710     {
       
   711 
       
   712     //-- set up console output
       
   713     F32_Test_Utils::SetConsole(test.Console());
       
   714 
       
   715     TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum);
       
   716     test(nRes==KErrNone);
       
   717     
       
   718     PrintDrvInfo(TheFs, gDriveNum);
       
   719 
       
   720     //-- quick format the drive, if it isn't the emulator's C:  
       
   721     if(!Is_Win32(TheFs, gDriveNum))
       
   722     {
       
   723         nRes = FormatDrive(TheFs, gDriveNum, ETrue); 
       
   724         test(nRes==KErrNone);
       
   725     }
       
   726 
       
   727     //-----------------------------------
   721 	TInt c;
   728 	TInt c;
   722 	TInt i,count;
   729 	TInt i,count;
   723 	TInt pos;
   730 	TInt pos;
   724 	TInt64 seed;
   731 	TInt64 seed;
   725 	TInt attrib,mask;
   732 	TInt attrib,mask;
  1450 	if ((c=gFormat.Open(TheFs,fBuf,EFullFormat,count))!=KErrNone)
  1457 	if ((c=gFormat.Open(TheFs,fBuf,EFullFormat,count))!=KErrNone)
  1451 		{
  1458 		{
  1452 		if (c==LockedErr || c==AccessErr)
  1459 		if (c==LockedErr || c==AccessErr)
  1453 			{
  1460 			{
  1454 			test.Printf(_L("Format: locked, no test\n"));
  1461 			test.Printf(_L("Format: locked, no test\n"));
  1455 			goto noFormat;
       
  1456 			}
  1462 			}
       
  1463 		    else
       
  1464             {
  1457 		Error(_L("Format lock check"),c);
  1465 		Error(_L("Format lock check"),c);
  1458 		}
  1466 		}
  1459 
  1467 		}
  1460 //	if ((c=p_read(chan2,&count,2))<0)
  1468 
  1461 //		{
       
  1462 //		if (c==NotSupportedErr)
       
  1463 //			{
       
  1464 //			test.Printf(_L("Format: not supported, no test\n"));
       
  1465 //			goto noFormatClose;
       
  1466 //			}
       
  1467 //		Error(_L("Read format count"),c);
       
  1468 //		}
       
  1469 //	for (i=1;;i++)
       
  1470 //		{
       
  1471 //		if ((c=g(chan2,&val,2))<0)
       
  1472 //			{
       
  1473 //			if (c==EofErr)
       
  1474 //			break;
       
  1475 //			Error(_L("Format"),c);
       
  1476 //			}
       
  1477 //		test.Printf(_L("\r%05u %05u\n"),i,val);
       
  1478 //		}
       
  1479 //	if ((i-1)!=count)
       
  1480 //		Error(_L("Format count"),i);
       
  1481 // noFormatClose:
       
  1482 //	if ((c=p_close(chan2))!=KErrNone)
       
  1483 //		Error(_L("Close"),c);
       
  1484 noFormat:
       
  1485 	gFormat.Close();
  1469 	gFormat.Close();
       
  1470 	
  1486 	DeleteTestDirectory();
  1471 	DeleteTestDirectory();
  1487 	
  1472 	
  1488 	}
  1473 	}