os/kernelhwsrv/kerneltest/f32test/server/b_osfil.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1996-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // f32test\server\b_osfil.cpp
    15 // 
    16 //
    17 
    18 #include <f32file.h>
    19 #include <e32test.h>
    20 #include "t_server.h"
    21 
    22 const TInt KSizeExistsFile=26;
    23 const TInt KSizeExistsFile2=25;
    24 
    25 GLDEF_D RTest test(_L("B_OSFIL"));
    26 
    27 /* these buffers get written to in order to change the file system */	
    28 //LOCAL_D TBuf<5> fileSystemName =_L("LOC::");   /* default file system name */
    29 LOCAL_D TBuf<20> noDevice = _L("L:\\tmpfile.tmp");
    30 LOCAL_D TBuf<15> noDevicePath = _L("L:\\");
    31 LOCAL_D TBuf<28> noDirectory = _L("C:\\nodirect\\tmpfile.tmp");
    32 LOCAL_D TBuf<30> noDirectoryPath = _L("C:\\nodirect\\");
    33 LOCAL_D TBuf<20> noFile = _L("C:\\notafile.tmp");
    34 LOCAL_D TBuf<19> fileName = _L("C:\\tmpfile.tmp");
    35 LOCAL_D TBuf<20> existsFile = _L("C:\\tmpexst1.tmp");
    36 LOCAL_D TBuf<20> existsFile2 = _L("C:\\tmpexst2.tmp");
    37 LOCAL_D TBuf<21> renameFile1 = _L("C:\\tmpren1.tmp");
    38 LOCAL_D TBuf<21> renameFile2 = _L("C:\\tmpren2.tmp");
    39 LOCAL_D TBuf<34> directoryFile = _L("C:\\nodirect\\nodirect\\nodirect\\");
    40 LOCAL_D TBuf<14> openUniqueDir = _L("C:\\nodir2\\");
    41 
    42 /*************************************************************************/
    43 LOCAL_C void TestInfo()
    44 /*
    45 Test the file info function
    46 */
    47 	{
    48 	TEntry entry;
    49 	TInt r=TheFs.Entry(noDevice,entry);
    50 	test((r==KErrNotReady)||(r==KErrPathNotFound));
    51 	r=TheFs.Entry(noDirectory,entry);
    52 	test(r==KErrPathNotFound);
    53 	r=TheFs.Entry(noFile,entry);
    54 	test(r==KErrNotFound);
    55 	r=TheFs.Entry(existsFile,entry);
    56 	test(r==KErrNone);
    57 	test(entry.iSize==KSizeExistsFile);
    58 	test(!entry.IsDir());
    59 	test(!(entry.iAtt&KEntryAttDir));
    60 	r=TheFs.Entry(existsFile2,entry);
    61 	test(r==KErrNone);
    62 	test(entry.iSize==KSizeExistsFile2);
    63 	test(!entry.IsDir());
    64 	test(!(entry.iAtt&KEntryAttDir));
    65 	}
    66 
    67 LOCAL_C void TestDelete()
    68 /*
    69 Test the delete
    70 */
    71 	{
    72 	TInt r=TheFs.Delete(noDevice);
    73 	test((r==KErrNotReady)||(r==KErrPathNotFound));
    74 	r=TheFs.Delete(noDirectory);
    75 	test(r==KErrPathNotFound);
    76 	r=TheFs.Delete(noFile);
    77 	test(r==KErrNotFound);
    78 	r=TheFs.Delete(existsFile);
    79 	test(r==KErrNone);
    80 	r=TheFs.Delete(existsFile2);
    81 	test(r==KErrNone);
    82 	TEntry entry;
    83 	r=TheFs.Entry(existsFile,entry);
    84 	test(r==KErrNotFound);
    85 	r=TheFs.Entry(existsFile2,entry);
    86 	test(r==KErrNotFound);
    87 	}
    88 
    89 LOCAL_C void TestRename()
    90 /*
    91 Test the rename
    92 */
    93 	{
    94 	TInt r=TheFs.Rename(noDevice,fileName);
    95 	test(r==KErrArgument);
    96 	r=TheFs.Rename(noDirectory,fileName);
    97 	test(r==KErrPathNotFound);
    98 	r=TheFs.Rename(noFile,fileName);
    99 	test(r==KErrNotFound);
   100 	r=TheFs.Rename(existsFile,existsFile2);
   101 	test(r==KErrAlreadyExists);
   102 	r=TheFs.Delete(existsFile);
   103 	test(r==KErrNone);
   104 	r=TheFs.Rename(existsFile,existsFile);
   105 	test(r==KErrNotFound);
   106 	r=TheFs.Rename(existsFile2,existsFile);
   107 	test(r==KErrNone);
   108 	TEntry entry;
   109 	r=TheFs.Entry(existsFile2,entry);
   110 	test(r==KErrNotFound);
   111 	r=TheFs.Entry(existsFile,entry);
   112 	test(r==KErrNone);
   113 	r=TheFs.Delete(existsFile);
   114 	test(r==KErrNone);
   115 	}
   116 
   117 LOCAL_C void TestMkDir()
   118 	{
   119 	TParse fparse;
   120 	TInt r=TheFs.MkDirAll(directoryFile);
   121 	test(r==KErrNone);
   122 	TEntry entry;
   123 	r=TheFs.Entry(directoryFile.Left(directoryFile.Length()-1),entry);
   124 	test(r==KErrNone);
   125 	test(entry.IsDir());
   126 	test(entry.iAtt&KEntryAttDir);
   127 	r=TheFs.RmDir(directoryFile);
   128 	test(r==KErrNone);
   129 	r=fparse.Set(directoryFile,NULL,NULL);
   130 	test(r==KErrNone);
   131 	r=fparse.PopDir();
   132 	test(r==KErrNone);
   133 	r=TheFs.RmDir(fparse.DriveAndPath());
   134 	test(r==KErrNone);
   135 	r=fparse.PopDir();
   136 	test(r==KErrNone);
   137 	r=TheFs.RmDir(fparse.DriveAndPath());
   138 	test(r==KErrNone);
   139 	}
   140 
   141 
   142 LOCAL_C void TestOpenUnique()
   143 /*
   144 Test unique file name generator
   145 */
   146 	{
   147 	RFile p1;
   148 	RFile p2;
   149 
   150 	TInt r=p1.Open(TheFs,noDevice,EFileStreamText);
   151 	test((r==KErrNotReady)||(r==KErrPathNotFound));
   152 	r=p1.Open(TheFs,noDirectory,EFileStreamText);
   153 	test(r==KErrPathNotFound);
   154 	TFileName generated1;
   155 	r=p1.Temp(TheFs,noDevicePath,generated1,EFileStreamText);
   156 	test((r==KErrNotReady)||(r==KErrPathNotFound));
   157 	r=p1.Temp(TheFs,noDirectoryPath,generated1,EFileStreamText);
   158 	test(r==KErrPathNotFound);
   159 
   160 	r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText);
   161 	test(r==KErrNone);
   162 	TFileName generated2;
   163 	r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText);
   164 	test(r==KErrNone);
   165 	test(generated1!=generated2);
   166 	p1.Close();
   167 	TFileName generated3;
   168 	r=p1.Temp(TheFs,_L(""),generated3,EFileStream);
   169 	test(r==KErrNone);
   170 	test(generated3!=generated2);
   171 	test(generated3!=generated1);
   172 	p2.Close();
   173 	p1.Close();
   174 
   175 	r=TheFs.Delete(generated1);
   176 	test(r==KErrNone);
   177 	r=TheFs.Delete(generated2);
   178 	test(r==KErrNone);
   179 	r=TheFs.Delete(generated3);
   180 	test(r==KErrNone);
   181 
   182 	r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText);
   183 	test(r==KErrNone);
   184 	r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText);
   185 	test(r==KErrNone);
   186 	test(generated1!=generated2);
   187 	p1.Close();
   188 	r=p1.Temp(TheFs,_L(""),generated3,EFileStream);
   189 	test(r==KErrNone);
   190 	test(generated3!=generated2);
   191 	test(generated3!=generated1);
   192 	p2.Close();
   193 	p1.Close();
   194 
   195 	r=TheFs.Delete(generated1);
   196 	test(r==KErrNone);
   197 	r=TheFs.Delete(generated2);
   198 	test(r==KErrNone);
   199 	r=TheFs.Delete(generated3);
   200 	test(r==KErrNone);
   201 
   202 	r=TheFs.MkDir(openUniqueDir);
   203 	test(r==KErrNone);
   204 	r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream);
   205 	test(r==KErrNone);
   206 	r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText|EFileWrite);
   207 	test(r==KErrNone);
   208 	r=p1.Write(_L8("junk"),4);
   209 	test(r==KErrNone);
   210 	TInt pos=0;
   211 	r=p1.Seek(ESeekCurrent,pos);//P_FSET
   212 	test(r==KErrNone);
   213 	p1.Close();
   214 	p2.Close();
   215 	
   216 	r=TheFs.Delete(generated1);
   217 	test(r==KErrNone);
   218 	r=TheFs.Delete(generated2);
   219 	test(r==KErrNone);
   220 
   221 	r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream);
   222 	test(r==KErrNone);
   223 	r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText);
   224 	test(r==KErrNone);
   225 	p1.Close();
   226 
   227 	pos=0;
   228 	r=p2.Seek(ESeekStart,pos);
   229 	test(r==KErrNone);
   230 	p2.Close();
   231 	r=TheFs.Delete(generated1);
   232 	test(r==KErrNone);
   233 	r=TheFs.Delete(generated2);
   234 	test(r==KErrNone);
   235 	r=TheFs.RmDir(openUniqueDir);
   236 	test(r==KErrNone);
   237 	}
   238 
   239 LOCAL_C void TestPaths()
   240 	{
   241 	TFileName path1;
   242 	TInt r=TheFs.SessionPath(path1);
   243 	test(r==KErrNone);
   244 	r=TheFs.SetSessionPath(path1);
   245 	test(r==KErrNone);
   246 	TFileName path2;
   247 	r=TheFs.SessionPath(path2);
   248 	test(r==KErrNone);
   249 	test(path1==path2);
   250 	RDir dir;
   251 	r=dir.Open(TheFs,path1,0);
   252 	test(r==KErrNone);
   253 	dir.Close();
   254 	}
   255 
   256 LOCAL_C void TestFileStatus()
   257 	{
   258 	TEntry blk;
   259 	TInt r=TheFs.Entry(existsFile,blk);
   260 	test(r==KErrNone);
   261 	TEntry blk1=blk;
   262 
   263 /* Toggle the write attribute */
   264 	TUint clear,set; /* were modifying write attrib */
   265 	if (blk1.IsReadOnly())
   266 		{
   267 		clear=KEntryAttReadOnly;
   268 		set=0;
   269 		}
   270 	else
   271 		{
   272 		clear=0;
   273 		set=KEntryAttReadOnly;
   274 		}
   275 	r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
   276 	test(r==KErrNone);
   277 	r=TheFs.Entry(existsFile,blk);
   278 	test(r==KErrNone);
   279 	if (blk1.IsReadOnly())
   280 		test(!blk.IsReadOnly());
   281 	else
   282 		test(blk.IsReadOnly());
   283 
   284 /* set write attrib back */
   285 	r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
   286 	test(r==KErrNone);
   287 	r=TheFs.Entry(existsFile,blk);
   288 	test(r==KErrNone);
   289 	if (blk1.IsReadOnly())
   290 		test(blk.IsReadOnly());
   291 	else
   292 		test(!blk.IsReadOnly());
   293 
   294 /* toggle the archive bit */
   295 	if (blk1.IsArchive())
   296 		{
   297 		clear=KEntryAttArchive;
   298 		set=0;
   299 		}
   300 	else
   301 		{
   302 		clear=0;
   303 		set=KEntryAttArchive;
   304 		}
   305 	r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
   306 	test(r==KErrNone);
   307 	r=TheFs.Entry(existsFile,blk);
   308 	test(r==KErrNone);
   309 	if (blk1.IsArchive())
   310 		test(!blk.IsArchive());
   311 	else
   312 		test(blk.IsArchive());
   313 /* set archive attrib back */
   314 	r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
   315 	test(r==KErrNone);
   316 	r=TheFs.Entry(existsFile,blk);
   317 	test(r==KErrNone);
   318 	if (blk1.IsArchive())
   319 		test(blk.IsArchive());
   320 	else
   321 		test(!blk.IsArchive());
   322 
   323 /* toggle the hidden bit */
   324 	if (blk1.IsHidden())
   325 		{
   326 		clear=KEntryAttHidden;
   327 		set=0;
   328 		}
   329 	else
   330 		{
   331 		clear=0;
   332 		set=KEntryAttHidden;
   333 		}
   334 	r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
   335 	test(r==KErrNone);
   336 	r=TheFs.Entry(existsFile,blk);
   337 	test(r==KErrNone);
   338 	if (blk1.IsHidden())
   339 		test(!blk.IsHidden());
   340 	else
   341 		test(blk.IsHidden());
   342 /* set hidden attrib back */
   343 	r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
   344 	test(r==KErrNone);
   345 	r=TheFs.Entry(existsFile,blk);
   346 	test(r==KErrNone);
   347 	if (blk1.IsHidden())
   348 		test(blk.IsHidden());
   349 	else
   350 		test(!blk.IsHidden());
   351 
   352 /* toggle the system bit */
   353 	if (blk1.IsSystem())
   354 		{
   355 		clear=KEntryAttSystem;
   356 		set=0;
   357 		}
   358 	else
   359 		{
   360 		clear=0;
   361 		set=KEntryAttSystem;
   362 		}
   363 	r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear);
   364 	test(r==KErrNone);
   365 	r=TheFs.Entry(existsFile,blk);
   366 	test(r==KErrNone);
   367 	if (blk1.IsSystem())
   368 		test(!blk.IsSystem());
   369 	else
   370 		test(blk.IsSystem());
   371 /* set system attrib back */
   372 	r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set);
   373 	test(r==KErrNone);
   374 	r=TheFs.Entry(existsFile,blk);
   375 	test(r==KErrNone);
   376 	if (blk1.IsSystem())
   377 		test(blk.IsSystem());
   378 	else
   379 		test(!blk.IsSystem());
   380 	r=TheFs.Delete(existsFile);
   381 	test(r==KErrNone);
   382 	r=TheFs.Delete(existsFile2);
   383 	test(r==KErrNone);
   384 	}
   385 
   386 
   387 LOCAL_C void CreateTestFiles()
   388 	{
   389 	RFile fcb;
   390 	TInt r=fcb.Replace(TheFs,existsFile,EFileWrite);
   391 	test(r==KErrNone);
   392 	r=fcb.Write(_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),KSizeExistsFile);
   393 	test(r==KErrNone);
   394 	fcb.Close();
   395 
   396 	r=fcb.Replace(TheFs,existsFile2,EFileWrite);
   397 	test(r==KErrNone);
   398 	r=fcb.Write(_L8("bcdefghijklmnopqrstuvwxyz"),KSizeExistsFile2);
   399 	test(r==KErrNone);
   400 	fcb.Close();
   401 	}
   402 
   403 GLDEF_C void CallTestsL(void)
   404 //
   405 // Do testing on aDrive
   406 //
   407 	{
   408 	test.Title();
   409 
   410 	TVolumeInfo di;
   411 	TInt r=TheFs.Volume(di);
   412 	test(r==KErrNone);
   413 	test.Start(_L("Info()"));
   414 	CreateTestFiles();
   415 	TestInfo();
   416 	test.Next(_L("Delete()"));
   417 	CreateTestFiles();
   418 	TestDelete();
   419 	test.Next(_L("Rename()"));
   420 	CreateTestFiles();
   421 	TestRename();
   422 	test.Next(_L("MkDir()"));
   423 	TestMkDir();
   424 	test.Next(_L("Temp()"));
   425 	TestOpenUnique();
   426 	test.Next(_L("Paths"));	
   427 	TestPaths();
   428 	test.Next(_L("File status"));
   429 	CreateTestFiles();
   430 	TestFileStatus();
   431 	test.End();
   432 	}