os/kernelhwsrv/kerneltest/f32test/server/t_misc.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_misc.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1398 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\server\t_misc.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <f32file.h>
    1.22 +#include <e32test.h>
    1.23 +#include "t_server.h"
    1.24 +
    1.25 +#ifdef __VC32__
    1.26 +    // Solve compilation problem caused by non-English locale
    1.27 +    #pragma setlocale("english")
    1.28 +#endif
    1.29 +
    1.30 +GLDEF_D RTest test(_L("T_MISC"));
    1.31 +
    1.32 +LOCAL_C void Test1()
    1.33 +//
    1.34 +// Open, write to and read from a file
    1.35 +//
    1.36 +	{
    1.37 +
    1.38 +	test.Next(_L("Open, write to and read from a file"));
    1.39 +	TInt r=TheFs.SetSessionPath(gSessionPath);
    1.40 +	test(r==KErrNone);
    1.41 +	RFile file;
    1.42 +	r=file.Create(TheFs,_L("Hello.Wld"),EFileWrite);
    1.43 +	test(r==KErrNone);
    1.44 +	r=file.Write(_L8("Hello World"),11);
    1.45 +	test(r==KErrNone);
    1.46 +	file.Close();
    1.47 +
    1.48 +	r=file.Open(TheFs,_L("Hello.Wld"),EFileRead);
    1.49 +	test(r==KErrNone);
    1.50 +	TBuf8<256> buf;
    1.51 +	r=file.Read(buf);
    1.52 +	test(r==KErrNone);
    1.53 +	test(buf==_L8("Hello World"));
    1.54 +	file.Close();
    1.55 +	}
    1.56 +
    1.57 +LOCAL_C void Test2()
    1.58 +//
    1.59 +// Open and read from a file
    1.60 +//
    1.61 +	{
    1.62 +
    1.63 +	test.Next(_L("Open and read from a file"));
    1.64 +	TInt r=TheFs.SetSessionPath(gSessionPath);
    1.65 +	test(r==KErrNone);
    1.66 +	RFile file;
    1.67 +	r=file.Open(TheFs,_L("Hello.Wld"),EFileRead);
    1.68 +	test(r==KErrNone);
    1.69 +	TBuf8<256> buf;
    1.70 +	r=file.Read(buf);
    1.71 +	test(r==KErrNone);
    1.72 +	test(buf==_L8("Hello World"));
    1.73 +	file.Close();
    1.74 +	r=TheFs.Delete(_L("HELLO.WLD"));
    1.75 +	test(r==KErrNone);
    1.76 +	}
    1.77 +
    1.78 +LOCAL_C void Test3()
    1.79 +//
    1.80 +// Create nested directories
    1.81 +//
    1.82 +	{
    1.83 +
    1.84 +	test.Next(_L("Create nested directories"));
    1.85 +	TInt r=TheFs.SetSessionPath(gSessionPath);
    1.86 +	test(r==KErrNone);
    1.87 +	TheFs.ResourceCountMarkStart();
    1.88 +//
    1.89 +	r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\A.B"));
    1.90 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.91 +	r=TheFs.MkDir(_L("\\F32-TST\\RIGHT\\"));
    1.92 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.93 +//
    1.94 +	r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\ONE\\"));
    1.95 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.96 +	r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\"));
    1.97 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.98 +	r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\THREE\\"));
    1.99 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.100 +	r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\BOTTOM\\"));
   1.101 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.102 +//
   1.103 +	r=TheFs.MkDirAll(_L("\\F32-TST\\RIGHT\\TOP\\MID\\BOT\\"));
   1.104 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.105 +	}
   1.106 +
   1.107 +LOCAL_C void Test4()
   1.108 +//
   1.109 +// Test returned error values
   1.110 +//
   1.111 +	{
   1.112 +
   1.113 +	test.Next(_L("Test returned error values"));
   1.114 +	TInt r=TheFs.SetSessionPath(gSessionPath);
   1.115 +	test(r==KErrNone);
   1.116 +	TheFs.ResourceCountMarkStart();
   1.117 +//
   1.118 +	r=TheFs.MkDir(_L("\\"));
   1.119 +	test(r==KErrAlreadyExists);
   1.120 +	r=TheFs.MkDir(_L("\\LEFT"));
   1.121 +	test(r==KErrAlreadyExists);
   1.122 +	r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\"));
   1.123 +	test(r==KErrAlreadyExists);
   1.124 +	r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\..\\NEWDIR\\"));
   1.125 +	test(r==KErrBadName);
   1.126 +	r=TheFs.MkDir(_L("\\F32-TST\\NEWDIR\\SUBDIR\\"));
   1.127 +	test(r==KErrPathNotFound);
   1.128 +//
   1.129 +	r=TheFs.RmDir(_L("\\"));
   1.130 +	test(r==KErrInUse);
   1.131 +	r=TheFs.RmDir(_L("\\PROG"));
   1.132 +	test(r==KErrInUse);
   1.133 +	r=TheFs.RmDir(_L("\\F32-TST\\"));
   1.134 +	test(r==KErrInUse);
   1.135 +
   1.136 +
   1.137 +	RDir dir;
   1.138 +	r=dir.Open(TheFs,_L("V:\\asdf"),KEntryAttNormal);
   1.139 +	test(r==KErrNone || r==KErrNotReady || r==KErrNotFound);
   1.140 +	if (r==KErrNone)
   1.141 +		dir.Close();
   1.142 +	r=dir.Open(TheFs,_L("L:\\asdf"),KEntryAttNormal);
   1.143 +	test(r==KErrNone || r==KErrNotReady || r==KErrNotFound);
   1.144 +	dir.Close();
   1.145 +//
   1.146 +	TEntry entry;
   1.147 +	r=TheFs.Entry(_L("z:\\NOTEXiSTS\\file.txt"),entry);
   1.148 +	test(r==KErrPathNotFound);
   1.149 +	r=TheFs.Entry(_L("z:\\NOTEXiSTS\\"),entry);
   1.150 +	test(r==KErrNotFound);
   1.151 +	r=TheFs.Entry(_L("z:\\SYSTEM\\"),entry);
   1.152 +	test(r==KErrNone);
   1.153 +	r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("z:\\SYS\\BIN\\ESHELL.EXE"):_L("z:\\SYSTEM\\BIN\\ESHELL.EXE"),entry);
   1.154 +	test(r==KErrNone);
   1.155 +
   1.156 +	r=dir.Open(TheFs,_L("\\*"),NULL);
   1.157 +	test(r==KErrNone);
   1.158 +	TEntry dirEntry;
   1.159 +	r=dir.Read(dirEntry);
   1.160 +	test(r==KErrNone || r==KErrEof);
   1.161 +	if (r==KErrNone)
   1.162 +		test.Printf(_L("%S\n"),&dirEntry.iName);
   1.163 +	dir.Close();
   1.164 +
   1.165 +	r=dir.Open(TheFs,_L("A:\\*"),NULL);
   1.166 +	test(r==KErrNotReady || r==KErrNone);
   1.167 +	dir.Close();
   1.168 +	}
   1.169 +
   1.170 +LOCAL_C void Test5()
   1.171 +//
   1.172 +// Read files directly from the rom
   1.173 +//
   1.174 +
   1.175 +	{
   1.176 +	test.Next(_L("Read Files directly from the rom"));
   1.177 +
   1.178 +	TInt pos=0;
   1.179 +	TInt r;
   1.180 +	_LIT(KTFileCpp, "Z:\\test\\T_FILE.CPP");
   1.181 +	_LIT(KTFsrvCpp, "Z:\\test\\T_FSRV.CPP");
   1.182 +
   1.183 +	if ( TheFs.IsFileInRom(KTFileCpp) != NULL && TheFs.IsFileInRom(KTFsrvCpp) != NULL )
   1.184 +		{
   1.185 +		RFile f;
   1.186 +		r=f.Open(TheFs,KTFileCpp,EFileRead);
   1.187 +		test(r==KErrNone);
   1.188 +		r=f.Seek(ESeekAddress,pos);
   1.189 +		TText8* ptrPos=*(TText8**)&pos;
   1.190 +		test(r==KErrNone);
   1.191 +		TBuf8<1024> readBuf;
   1.192 +		r=f.Read(readBuf);
   1.193 +		test(r==KErrNone);
   1.194 +		test(readBuf.Length()==readBuf.MaxLength());
   1.195 +		TPtrC8 memBuf(ptrPos,readBuf.Length());
   1.196 +		test(memBuf==readBuf);
   1.197 +
   1.198 +		ptrPos+=9913;
   1.199 +		pos=9913;
   1.200 +		r=f.Seek(ESeekStart,pos);
   1.201 +		test(r==KErrNone);
   1.202 +		readBuf.SetLength(0);
   1.203 +		r=f.Read(readBuf);
   1.204 +		test(r==KErrNone);
   1.205 +		test(readBuf.Length()==readBuf.MaxLength());
   1.206 +		memBuf.Set(ptrPos,readBuf.Length());
   1.207 +		test(memBuf==readBuf);
   1.208 +
   1.209 +		RFile f2;
   1.210 +		pos=10;
   1.211 +		r=f2.Open(TheFs,KTFsrvCpp,EFileRead);
   1.212 +
   1.213 +		test(r==KErrNone);
   1.214 +		r=f2.Seek(ESeekAddress,pos);
   1.215 +		ptrPos=*(TText8**)&pos;
   1.216 +		test(r==KErrNone);
   1.217 +		readBuf.SetLength(0);
   1.218 +		pos=10;
   1.219 +		r=f2.Seek(ESeekStart,pos);
   1.220 +		test(r==KErrNone);
   1.221 +		r=f2.Read(readBuf);
   1.222 +		test(r==KErrNone);
   1.223 +		test(readBuf.Length()==readBuf.MaxLength());
   1.224 +		memBuf.Set(ptrPos,readBuf.Length());
   1.225 +		test(memBuf==readBuf);
   1.226 +
   1.227 +		ptrPos+=2445;
   1.228 +		pos=10+2445;
   1.229 +		r=f2.Seek(ESeekStart,pos);
   1.230 +		test(r==KErrNone);
   1.231 +		readBuf.SetLength(0);
   1.232 +		r=f2.Read(readBuf);
   1.233 +		test(r==KErrNone);
   1.234 +		test(readBuf.Length()==readBuf.MaxLength());
   1.235 +		memBuf.Set(ptrPos,readBuf.Length());
   1.236 +		test(memBuf==readBuf);
   1.237 +
   1.238 +		pos=0;
   1.239 +		r=f.Seek(ESeekAddress,pos);
   1.240 +		ptrPos=*(TText8**)&pos;
   1.241 +		test(r==KErrNone);
   1.242 +		readBuf.SetLength(0);
   1.243 +		pos=0;
   1.244 +		r=f.Seek(ESeekStart,pos);
   1.245 +		test(r==KErrNone);
   1.246 +		r=f.Read(readBuf);
   1.247 +		test(r==KErrNone);
   1.248 +		test(readBuf.Length()==readBuf.MaxLength());
   1.249 +		memBuf.Set(ptrPos,readBuf.Length());
   1.250 +		test(memBuf==readBuf);
   1.251 +
   1.252 +		ptrPos+=5245;
   1.253 +		pos=5245;
   1.254 +		r=f.Seek(ESeekStart,pos);
   1.255 +		test(r==KErrNone);
   1.256 +		readBuf.SetLength(0);
   1.257 +		r=f.Read(readBuf);
   1.258 +		test(r==KErrNone);
   1.259 +		test(readBuf.Length()==readBuf.MaxLength());
   1.260 +		memBuf.Set(ptrPos,readBuf.Length());
   1.261 +		test(memBuf==readBuf);
   1.262 +
   1.263 +		f.Close();
   1.264 +		f2.Close();
   1.265 +		}
   1.266 +	}
   1.267 +
   1.268 +LOCAL_C void Test6()
   1.269 +//
   1.270 +// Test rom return values
   1.271 +//
   1.272 +	{
   1.273 +	test.Next(_L("Test rom return values"));
   1.274 +
   1.275 +	RFile f;
   1.276 +	TInt r=f.Replace(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead);
   1.277 +	test(r==KErrAccessDenied);
   1.278 +	r=f.Create(TheFs,_L("Z:\\Test\\newT_Fsrv.Cpp"),EFileRead);
   1.279 +	test(r==KErrAccessDenied);
   1.280 +	r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead);
   1.281 +	test(r==KErrNone);
   1.282 +	f.Close();
   1.283 +	r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead|EFileWrite);
   1.284 +	test(r==KErrAccessDenied);
   1.285 +	}
   1.286 +
   1.287 +LOCAL_C void Test7()
   1.288 +//
   1.289 +// Test cache
   1.290 +//
   1.291 +	{
   1.292 +
   1.293 +	test.Next(_L("Test cache updated when writing to a file"));
   1.294 +	TUidType uid1(TUid::Uid(1),TUid::Uid(2),TUid::Uid(3));
   1.295 +	TBuf8<32> contents1=_L8("asdf asdf asdf");
   1.296 +	TBuf<32> file1=_L("\\TMISC\\CACHE.FILE");
   1.297 +	MakeFile(file1,uid1,contents1);
   1.298 +
   1.299 +	TEntry entry;
   1.300 +	TInt r=TheFs.Entry(file1,entry);
   1.301 +	test(r==KErrNone);
   1.302 +	test(entry.iType==uid1);
   1.303 +
   1.304 +	TUidType uid2(TUid::Uid(4),TUid::Uid(5),TUid::Uid(6));
   1.305 +	TCheckedUid checkedUid(uid2);
   1.306 +	TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
   1.307 +	RFile f;
   1.308 +	r=f.Open(TheFs,file1,EFileRead|EFileWrite);
   1.309 +	test(r==KErrNone);
   1.310 +	r=f.Write(uidData);
   1.311 +	test(r==KErrNone);
   1.312 +	r = f.Flush();
   1.313 +	test(r==KErrNone);
   1.314 +
   1.315 +	r=TheFs.Entry(file1,entry);
   1.316 +	test(r==KErrNone);
   1.317 +	test(entry.iType==uid2);
   1.318 +
   1.319 +	f.Close();
   1.320 +	r=TheFs.Entry(file1,entry);
   1.321 +	test(r==KErrNone);
   1.322 +	test(entry.iType==uid2);
   1.323 +	}
   1.324 +
   1.325 +LOCAL_C void Test8()
   1.326 +//
   1.327 +// Test IsValidName
   1.328 +//
   1.329 +	{
   1.330 +	test.Next(_L("Test RFs::IsValidName(TDesC)"));
   1.331 +
   1.332 +	// tests calling IsValidName() with invalid name as first call to session
   1.333 +	// see defect EXT-57KH9K
   1.334 +	_LIT(KInvalidName, "test\\i1.jpg");
   1.335 +	RFs fs;
   1.336 +	test(KErrNone==fs.Connect());
   1.337 +	test(fs.IsValidName(KInvalidName)==EFalse);
   1.338 +	fs.Close();
   1.339 +
   1.340 +	test(TheFs.IsValidName(_L("*"))==EFalse);
   1.341 +	test(TheFs.IsValidName(_L("?"))==EFalse);
   1.342 +	test(TheFs.IsValidName(_L(">"))==EFalse);
   1.343 +	test(TheFs.IsValidName(_L("<"))==EFalse);
   1.344 +	test(TheFs.IsValidName(_L(":"))==EFalse);
   1.345 +	test(TheFs.IsValidName(_L("\""))==EFalse);
   1.346 +	test(TheFs.IsValidName(_L("/"))==EFalse);
   1.347 +	test(TheFs.IsValidName(_L("|"))==EFalse);
   1.348 +	test(TheFs.IsValidName(_L("\\"))==EFalse);
   1.349 +
   1.350 +	test(TheFs.IsValidName(_L("xx*yy"))==EFalse);
   1.351 +	test(TheFs.IsValidName(_L("xx?yy"))==EFalse);
   1.352 +	test(TheFs.IsValidName(_L("xx>yy"))==EFalse);
   1.353 +	test(TheFs.IsValidName(_L("xx<yy"))==EFalse);
   1.354 +	test(TheFs.IsValidName(_L("xx:yy"))==EFalse);
   1.355 +	test(TheFs.IsValidName(_L("xx\"yy"))==EFalse);
   1.356 +	test(TheFs.IsValidName(_L("xx/yy"))==EFalse);
   1.357 +	test(TheFs.IsValidName(_L("xx|yy"))==EFalse);
   1.358 +
   1.359 +	test(TheFs.IsValidName(_L("C:\\*\\group\\release.txt"))==EFalse);
   1.360 +	test(TheFs.IsValidName(_L("C:\\?\\group\\release.txt"))==EFalse);
   1.361 +	test(TheFs.IsValidName(_L("C:\\>\\group\\release.txt"))==EFalse);
   1.362 +	test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"))==EFalse);
   1.363 +	test(TheFs.IsValidName(_L("C:\\:\\group\\release.txt"))==EFalse);
   1.364 +	test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"))==EFalse);
   1.365 +	test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"))==EFalse);
   1.366 +	test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"))==EFalse);
   1.367 +
   1.368 +	test(TheFs.IsValidName(_L(""))==EFalse); // must be a name or extension present
   1.369 +	test(TheFs.IsValidName(_L(".ext")));
   1.370 +	test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"))==EFalse);
   1.371 +	test(TheFs.IsValidName(_L("\\"))==EFalse);
   1.372 +
   1.373 +	test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg")));	//	Valid names
   1.374 +	test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg")));	//	Valid names
   1.375 +	test(TheFs.IsValidName(_L("\'")));							//	Valid names
   1.376 +
   1.377 +	test.Next(_L("Test RFs::IsValidName(TDesC, TDes) overload"));
   1.378 +
   1.379 +	TText testChar;
   1.380 +	test(TheFs.IsValidName(_L("*"),testChar)==EFalse);
   1.381 +	test(testChar=='*');
   1.382 +	test(TheFs.IsValidName(_L("?"),testChar)==EFalse);
   1.383 +	test(testChar=='?');
   1.384 +	test(TheFs.IsValidName(_L(">"),testChar)==EFalse);
   1.385 +	test(testChar=='>');
   1.386 +	test(TheFs.IsValidName(_L("<"),testChar)==EFalse);
   1.387 +	test(testChar=='<');
   1.388 +	test(TheFs.IsValidName(_L(":"),testChar)==EFalse);
   1.389 +	test(testChar==':');
   1.390 +	test(TheFs.IsValidName(_L("\""),testChar)==EFalse);
   1.391 +	test(testChar=='\"');	//	Tests that " is illegal
   1.392 +	test(TheFs.IsValidName(_L("/"),testChar)==EFalse);
   1.393 +	test(testChar=='/');
   1.394 +	test(TheFs.IsValidName(_L("|"),testChar)==EFalse);
   1.395 +	test(testChar=='|');
   1.396 +	test(TheFs.IsValidName(_L("\\"),testChar)==EFalse);
   1.397 +	test(testChar==' ');
   1.398 +
   1.399 +	test(TheFs.IsValidName(_L("xx*yy"),testChar)==EFalse);
   1.400 + 	test(testChar=='*');
   1.401 +	test(TheFs.IsValidName(_L("xx?yy"),testChar)==EFalse);
   1.402 +	test(testChar=='?');
   1.403 +	test(TheFs.IsValidName(_L("xx>yy"),testChar)==EFalse);
   1.404 +	test(testChar=='>');
   1.405 +	test(TheFs.IsValidName(_L("xx<yy"),testChar)==EFalse);
   1.406 +	test(testChar=='<');
   1.407 +	test(TheFs.IsValidName(_L("xx:yy"),testChar)==EFalse);
   1.408 +	test(testChar==':');
   1.409 +	test(TheFs.IsValidName(_L("xx\"yy"),testChar)==EFalse);
   1.410 +	test(testChar=='\"');	//	Tests that " is illegal
   1.411 +	test(TheFs.IsValidName(_L("xx/yy"),testChar)==EFalse);
   1.412 +	test(testChar=='/');
   1.413 +	test(TheFs.IsValidName(_L("xx|yy"),testChar)==EFalse);
   1.414 +	test(testChar=='|');
   1.415 +
   1.416 +	test(TheFs.IsValidName(_L("C:\\*\\group\\release.txt"),testChar)==EFalse);
   1.417 +	test(testChar=='*');
   1.418 +	test(TheFs.IsValidName(_L("C:\\?\\group\\release.txt"),testChar)==EFalse);
   1.419 +	test(testChar=='?');
   1.420 +	test(TheFs.IsValidName(_L("C:\\..\\group\\release.txt"),testChar)==EFalse);
   1.421 +	test(testChar=='.');	//	Only one "." returned however many are in filename
   1.422 +	test(TheFs.IsValidName(_L("C:\\.\\group\\release.txt"),testChar)==EFalse);
   1.423 +	test(testChar=='.');
   1.424 +	test(TheFs.IsValidName(_L("C:\\>\\group\\release.txt"),testChar)==EFalse);
   1.425 +	test(testChar=='>');
   1.426 +	test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),testChar)==EFalse);
   1.427 +	test(testChar=='<');
   1.428 +	test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),testChar)==EFalse);
   1.429 +	test(testChar==':');
   1.430 +
   1.431 +
   1.432 +	test(TheFs.IsValidName(_L("C::\\group\\release.txt"),testChar)==EFalse);
   1.433 +	test(testChar==':');
   1.434 +	test(TheFs.IsValidName(_L(">\\group\\release.txt"),testChar)==EFalse);
   1.435 +	test(testChar=='>');
   1.436 +	test(TheFs.IsValidName(_L("C|group\\release.txt"),testChar)==EFalse);
   1.437 +	test(testChar=='|');
   1.438 +	test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),testChar)==EFalse);
   1.439 +	test(testChar=='|');
   1.440 +
   1.441 +	test(TheFs.IsValidName(_L("\\>"),testChar)==EFalse);
   1.442 +	test(testChar=='>');
   1.443 +	test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),testChar)==EFalse);
   1.444 +	test(testChar=='|');
   1.445 +
   1.446 +	test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),testChar)==EFalse);
   1.447 +	test(testChar=='\"');
   1.448 +	test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),testChar)==EFalse);
   1.449 +	test(testChar=='/');
   1.450 +	test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),testChar)==EFalse);
   1.451 +	test(testChar=='|');
   1.452 +	test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),testChar)==EFalse); // must be a name or extension present
   1.453 +	test(testChar==' ');
   1.454 +
   1.455 +//	Test that \ is not allowed in filenames
   1.456 +	TFileName filename;
   1.457 +	filename=_L("C:\\HelloWorld\\\\\\group\\release.txt");
   1.458 +	TPtr pChar(&testChar,sizeof(TText),sizeof(TText));
   1.459 +	test(TheFs.IsValidName(filename,testChar)==EFalse);
   1.460 +	test(pChar.Find(_L("\\"))!=KErrNotFound);
   1.461 +	filename=_L("C:\\\\\\group\\release.txt");
   1.462 +	test(TheFs.IsValidName(filename,testChar)==EFalse);
   1.463 +	test(pChar.Find(_L("\\"))!=KErrNotFound);
   1.464 +	filename=_L("C:\\Hello World\\group\\release.txt");
   1.465 +	filename[8]=KPathDelimiter;	//	Makes C:\\Hello World\\group\\release.txt
   1.466 +	test(TheFs.IsValidName(filename,testChar));
   1.467 +	filename=_L("C:\\HelloWorld\\::\\group\\release.txt");
   1.468 +	test(TheFs.IsValidName(filename,testChar)==EFalse);
   1.469 +	test(pChar.Find(_L(":"))!=KErrNotFound);
   1.470 +
   1.471 +	filename=_L("C:\\>>\\group\\release.txt");
   1.472 +	test(TheFs.IsValidName(filename,testChar)==EFalse);
   1.473 +	test(pChar.Find(_L(">"))!=KErrNotFound);
   1.474 +
   1.475 +	test(TheFs.IsValidName(_L(""),testChar)==EFalse); // Must be a name
   1.476 +	test(testChar==' ');
   1.477 +	test(TheFs.IsValidName(_L(".ext"),testChar));
   1.478 +	test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),testChar)==EFalse);
   1.479 +	test(testChar==' ');	//	Must be a name else testChar is set to blank
   1.480 +	test(TheFs.IsValidName(_L("C:\\asdf.blarg"),testChar));
   1.481 +
   1.482 +	test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),testChar)==EFalse);
   1.483 +	test(testChar==' ');	//	Must be a name else testChar is set to blank
   1.484 +	test(TheFs.IsValidName(_L("C:\\asdf..blarg"),testChar));
   1.485 +
   1.486 +	test(TheFs.IsValidName(_L("\\"),testChar)==EFalse);
   1.487 +	test(testChar==' ');
   1.488 +
   1.489 +//	Test multiple evil characters - parsing occurs from right to left
   1.490 +//	except that wildcarded characters take priority and are picked out first
   1.491 +	test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mno<pqr*stu"),testChar)==EFalse);
   1.492 +	test(testChar=='*');
   1.493 +	test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno?pqr"),testChar)==EFalse);
   1.494 +	test(testChar=='?');
   1.495 +	test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno"),testChar)==EFalse);
   1.496 +	test(testChar==':');
   1.497 +	test(TheFs.IsValidName(_L("abc>def|ghi<jkl"),testChar)==EFalse);
   1.498 +	test(testChar=='<');
   1.499 +	test(TheFs.IsValidName(_L("abc>def|ghi"),testChar)==EFalse);
   1.500 +	test(testChar=='|');
   1.501 +	test(TheFs.IsValidName(_L("abc>def"),testChar)==EFalse);
   1.502 +	test(testChar=='>');
   1.503 +
   1.504 +	test(!TheFs.IsValidName(_L("C:\\v123456.."),testChar));				//	Valid name
   1.505 +	test(TheFs.IsValidName(_L("abc"),testChar));						//	Valid name
   1.506 +	test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),testChar));	//	Valid name
   1.507 +	test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),testChar));	//	Valid name
   1.508 +	test(TheFs.IsValidName(_L("\'"),testChar));							//	Valid name
   1.509 +
   1.510 +	//PDEF133084: The wild character in the extension was not being detected.
   1.511 +	_LIT( KTestString, "E:\\My Videos\\Downloads\\1\\1\\Name.3gp?" );
   1.512 +    TBuf<50> path;
   1.513 +    path = KTestString;
   1.514 +    TBool validName( EFalse );
   1.515 +    TText badChar;
   1.516 +    TInt badCharLoc( KErrNotFound );
   1.517 +
   1.518 +    while ( ! validName )
   1.519 +        {
   1.520 +        validName = TheFs.IsValidName( path, badChar );
   1.521 +
   1.522 +        if ( ! validName )
   1.523 +            {
   1.524 +            badCharLoc = path.LocateReverse( badChar );
   1.525 +
   1.526 +            if ( KErrNotFound != badCharLoc )
   1.527 +                {
   1.528 +                path[badCharLoc] = '_';
   1.529 +                }
   1.530 +            }
   1.531 +        }
   1.532 +	}
   1.533 +
   1.534 +LOCAL_C void Test9()
   1.535 +//
   1.536 +// Test IsFileInRom
   1.537 +//
   1.538 +	{
   1.539 +
   1.540 +	test.Next(_L("Test RFs::IsFileInRom"));
   1.541 +
   1.542 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.543 +	TInt r=fMan->Copy(_L("Z:\\TEST\\T_FILE.CPP"),_L("C:\\T_FILE.CPP"));
   1.544 +	test(r==KErrNone || r==KErrAccessDenied);
   1.545 +	delete fMan;
   1.546 +	TUint8* addr=TheFs.IsFileInRom(_L("C:\\ESHELL.EXE"));
   1.547 +	test(addr==NULL);
   1.548 +	addr=TheFs.IsFileInRom(_L("Z:\\TEST\\T_FILE.CPP"));
   1.549 +	if (addr!=NULL)
   1.550 +		{
   1.551 +		test(addr!=NULL);
   1.552 +		TPtrC8 startOfFile(addr,12);
   1.553 +		test(startOfFile==_L8("// Copyright"));
   1.554 +		}
   1.555 +	else
   1.556 +		{
   1.557 +		test (addr==NULL);
   1.558 +		}
   1.559 +	}
   1.560 +
   1.561 +LOCAL_C void Test10()
   1.562 +//
   1.563 +// Test drive names
   1.564 +//
   1.565 +	{
   1.566 +
   1.567 +	test.Next(_L("Test Drive Names"));
   1.568 +	TFileName driveName;
   1.569 +	TInt i;
   1.570 +	for(i=0;i<KMaxDrives;i++)
   1.571 +		{
   1.572 +		TInt r=TheFs.GetDriveName(i,driveName);
   1.573 +		test(r==KErrNone);
   1.574 +		if (driveName.Length())
   1.575 +			test.Printf(_L("Default name of %c: == %S\n"),'A'+i,&driveName);
   1.576 +		}
   1.577 +
   1.578 +	TBuf<64> drive0=_L("Dilbert");
   1.579 +	TBuf<64> drive4=_L("Dogbert");
   1.580 +	TBuf<64> drive17=_L("Flibble");
   1.581 +	TBuf<64> drive25=_L("RAMDRIVE");
   1.582 +	TInt r=TheFs.SetDriveName(0,drive0);
   1.583 +	test(r==KErrNone);
   1.584 +	r=TheFs.SetDriveName(4,drive4);
   1.585 +	test(r==KErrNone);
   1.586 +	r=TheFs.SetDriveName(17,drive17);
   1.587 +	test(r==KErrNone);
   1.588 +	r=TheFs.SetDriveName(25,drive25);
   1.589 +	test(r==KErrNone);
   1.590 +
   1.591 +	r=TheFs.GetDriveName(0,driveName);
   1.592 +	test(r==KErrNone);
   1.593 +	test(driveName==drive0);
   1.594 +	r=TheFs.GetDriveName(4,driveName);
   1.595 +	test(r==KErrNone);
   1.596 +	test(driveName==drive4);
   1.597 +	r=TheFs.GetDriveName(17,driveName);
   1.598 +	test(r==KErrNone);
   1.599 +	test(driveName==drive17);
   1.600 +	r=TheFs.GetDriveName(25,driveName);
   1.601 +	test(r==KErrNone);
   1.602 +	test(driveName==drive25);
   1.603 +
   1.604 +	drive0=_L("askdjflsdfourewoqiuroiuaksjdvx,cvsdhwjhjhalsjhfshfkjhslj");
   1.605 +	r=TheFs.SetDriveName(0,drive0);
   1.606 +	test(r==KErrNone);
   1.607 +	r=TheFs.GetDriveName(0,driveName);
   1.608 +	test(r==KErrNone);
   1.609 +	test(driveName==drive0);
   1.610 +
   1.611 +//	Test with illegal characters in drive name
   1.612 +	drive0=_L("Dil>bert");
   1.613 +	drive4=_L("Dog?bert");
   1.614 +	drive17=_L("Fli*bble");
   1.615 +	drive25=_L("RAMD//RIVE");
   1.616 +
   1.617 +	r=TheFs.SetDriveName(0,drive0);
   1.618 +	test(r==KErrBadName);
   1.619 +	r=TheFs.SetDriveName(4,drive4);
   1.620 +	test(r==KErrBadName);
   1.621 +	r=TheFs.SetDriveName(17,drive17);
   1.622 +	test(r==KErrBadName);
   1.623 +	r=TheFs.SetDriveName(25,drive25);
   1.624 +	test(r==KErrBadName);
   1.625 +
   1.626 +//	Test that it is OK to set the name to no characters
   1.627 +
   1.628 +	drive0=_L("");
   1.629 +	drive4=_L("");
   1.630 +	drive17=_L("");
   1.631 +	drive25=_L("");
   1.632 +
   1.633 +	r=TheFs.SetDriveName(0,drive0);
   1.634 +	test(r==KErrNone);
   1.635 +	r=TheFs.SetDriveName(4,drive4);
   1.636 +	test(r==KErrNone);
   1.637 +	r=TheFs.SetDriveName(17,drive17);
   1.638 +	test(r==KErrNone);
   1.639 +	r=TheFs.SetDriveName(25,drive25);
   1.640 +	test(r==KErrNone);
   1.641 +
   1.642 +	r=TheFs.GetDriveName(0,driveName);
   1.643 +	test(r==KErrNone);
   1.644 +	test(driveName==drive0);
   1.645 +	r=TheFs.GetDriveName(4,driveName);
   1.646 +	test(r==KErrNone);
   1.647 +	test(driveName==drive4);
   1.648 +	r=TheFs.GetDriveName(17,driveName);
   1.649 +	test(r==KErrNone);
   1.650 +	test(driveName==drive17);
   1.651 +	r=TheFs.GetDriveName(25,driveName);
   1.652 +	test(r==KErrNone);
   1.653 +	test(driveName==drive25);
   1.654 +
   1.655 +
   1.656 +	}
   1.657 +
   1.658 +LOCAL_C void Test11()
   1.659 +//
   1.660 +// Miscellaneous tests
   1.661 +//
   1.662 +	{
   1.663 +
   1.664 +	test.Next(_L("Miscellaneous tests"));
   1.665 +	TVolumeInfo vol;
   1.666 +	TInt r=TheFs.Volume(vol);
   1.667 +	test.Printf(_L("VolumeName = %S\n"),&vol.iName);
   1.668 +	test(r==KErrNone);
   1.669 +	r=TheFs.RmDir(_L("\\asdfasdf.\\"));
   1.670 +	test(r==KErrBadName);
   1.671 +	r=TheFs.MkDir(_L("\\asdfasdf.\\"));
   1.672 +	test(r==KErrBadName);
   1.673 +	}
   1.674 +
   1.675 +LOCAL_C void Test12()
   1.676 +//
   1.677 +// Test SetNotifyUser and GetNotifyUser
   1.678 +//
   1.679 +	{
   1.680 +
   1.681 +	test.Next(_L("Test Set and GetNotifyUser"));
   1.682 +	TBool notifyState=TheFs.GetNotifyUser();
   1.683 +	test(notifyState);
   1.684 +	notifyState=EFalse;
   1.685 +	TheFs.SetNotifyUser(notifyState);
   1.686 +	notifyState=TheFs.GetNotifyUser();
   1.687 +	test(notifyState==EFalse);
   1.688 +	notifyState=ETrue;
   1.689 +	TheFs.SetNotifyUser(notifyState);
   1.690 +	notifyState=TheFs.GetNotifyUser();
   1.691 +	test(notifyState);
   1.692 +	}
   1.693 +
   1.694 +LOCAL_C void Test13()
   1.695 +//
   1.696 +// Test return values from RFs::Volume on cf-cards
   1.697 +//
   1.698 +	{
   1.699 +
   1.700 +	test.Next(_L("Test RFs::Volume"));
   1.701 +	TVolumeInfo vol;
   1.702 +	TInt r=TheFs.Volume(vol,EDriveB);
   1.703 +	test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
   1.704 +	test.Printf(_L("RFs::Volume EDriveB returned %d\n"),r);
   1.705 +
   1.706 +	r=TheFs.Volume(vol,EDriveC);
   1.707 +	test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
   1.708 +	test.Printf(_L("RFs::Volume EDriveC returned %d\n"),r);
   1.709 +
   1.710 +	r=TheFs.Volume(vol,EDriveD);
   1.711 +	test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
   1.712 +	test.Printf(_L("RFs::Volume EDriveD returned %d\n"),r);
   1.713 +
   1.714 +	r=TheFs.Volume(vol,EDriveE);
   1.715 +	test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
   1.716 +	test.Printf(_L("RFs::Volume EDriveE returned %d\n"),r);
   1.717 +
   1.718 +	r=TheFs.Volume(vol,EDriveF);
   1.719 +	test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
   1.720 +	test.Printf(_L("RFs::Volume EDriveF returned %d\n"),r);
   1.721 +	}
   1.722 +
   1.723 +
   1.724 +void    DoTest14(TInt aDrvNum);
   1.725 +TInt    CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
   1.726 +TInt    CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
   1.727 +TBool   CheckFileContents(RFs& aFs, const TDesC& aFileName);
   1.728 +TBool   CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0);
   1.729 +
   1.730 +/**
   1.731 +Testing unallocated data initialization vulnerability in RFile
   1.732 +This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag)
   1.733 +e.g. XSR NAND
   1.734 +*/
   1.735 +LOCAL_C void Test14()
   1.736 +{
   1.737 +	TInt nRes;
   1.738 +
   1.739 +	test.Next(_L("Testing unallocated data initialization vulnerability in RFile"));
   1.740 +
   1.741 +	TDriveList driveList;
   1.742 +	TDriveInfo driveInfo;
   1.743 +
   1.744 +	//-- 1. get drives list
   1.745 +	nRes=TheFs.DriveList(driveList);
   1.746 +    test(nRes == KErrNone);
   1.747 +
   1.748 +	//-- 2. walk through all drives, performing the test only on suitable ones
   1.749 +	for (TInt drvNum=0; drvNum<KMaxDrives; ++drvNum)
   1.750 +    {
   1.751 +	    if(!driveList[drvNum])
   1.752 +	        continue;   //-- skip unexisting drive
   1.753 +
   1.754 +	    //-- get drive info
   1.755 +	    test(TheFs.Drive(driveInfo, drvNum) == KErrNone);
   1.756 +
   1.757 +	    //-- select a suitable drive for the testing. It shall be RAM drive, of FLASH but not removable
   1.758 +	    //-- and not read only, if it is FLASH, it shall support "Delete Notify" facility
   1.759 +        switch(driveInfo.iType)
   1.760 +        {
   1.761 +        //-- RAM drive, OK
   1.762 +        case EMediaRam:
   1.763 +        break;
   1.764 +
   1.765 +        //-- FLASH drive, OK
   1.766 +        case EMediaFlash:
   1.767 +        case EMediaNANDFlash:
   1.768 +            if(driveInfo.iMediaAtt & KMediaAttDeleteNotify)
   1.769 +                break; //-- this type of media shall support DeleteNotify flag, otherwise this test is inconsistent
   1.770 +            else continue;
   1.771 +
   1.772 +        //break; //unreacable
   1.773 +
   1.774 +        default:
   1.775 +            continue;
   1.776 +        }//switch(driveInfo.iType)
   1.777 +
   1.778 +		if (driveInfo.iDriveAtt	& KDriveAttSubsted)
   1.779 +			{
   1.780 +			// skip subst drives.
   1.781 +			continue;
   1.782 +			}
   1.783 +
   1.784 +        TBool readOnly = driveInfo.iMediaAtt & KMediaAttWriteProtected;
   1.785 +        if(readOnly)
   1.786 +            continue; //-- nothing to do, can't create any file etc.
   1.787 +
   1.788 +        //-- skip test on the emulator's C: drive, doesn't make any sense because
   1.789 +        //-- in this case we deal with WIN32 API and filesystem.
   1.790 +        #ifdef __WINS__
   1.791 +        if(drvNum == 2)
   1.792 +        {
   1.793 +             test.Printf(_L("Skipping test on emulator's C: drive\n"));
   1.794 +             continue;
   1.795 +        }
   1.796 +        #endif
   1.797 +
   1.798 +        DoTest14(drvNum);
   1.799 +
   1.800 +    }// for (TInt drvNum=0; ...
   1.801 +
   1.802 +}
   1.803 +
   1.804 +//--------------------------------------------------------
   1.805 +
   1.806 +/**
   1.807 +    Actually perform the test on a drive aDrvNum.
   1.808 +    @param  aDrvNum drive number
   1.809 +*/
   1.810 +void DoTest14(TInt aDrvNum)
   1.811 +{
   1.812 +
   1.813 +    TFileName fileName;
   1.814 +    fileName.Format(_L("Testing drive %c:"), 'A'+aDrvNum);
   1.815 +    test.Next(fileName);
   1.816 +
   1.817 +    const TInt  KFileSize = 0x1000; //-- size of the files t be created
   1.818 +    TInt        nRes;
   1.819 +
   1.820 +    fileName.Format(_L("%c:\\TestFile.bin"), aDrvNum+'A');
   1.821 +    TheFs.Delete(fileName); //-- just in case
   1.822 +
   1.823 +    //==============================
   1.824 +    //== Scenario 1.
   1.825 +    //== Create an empty file; AllocateSingleClusterL, ExtendClusterListL will be involved.
   1.826 +    //== Check that the file doesn't contain any meaningful information
   1.827 +    //==============================
   1.828 +    test.Printf(_L("Testing scenario 1\n"));
   1.829 +
   1.830 +    //-- 1. create an empty file
   1.831 +    nRes = CreateEmptyFile(TheFs, fileName, KFileSize);
   1.832 +    test(nRes == KErrNone);
   1.833 +
   1.834 +    //-- 1.1  check that this file doesn't contain illegitimate information.
   1.835 +    nRes = CheckFileContents(TheFs, fileName);
   1.836 +    test(nRes == KErrNone);
   1.837 +
   1.838 +    //-- 1.2 delete the empty file
   1.839 +    nRes = TheFs.Delete(fileName);
   1.840 +    test(nRes == KErrNone);
   1.841 +
   1.842 +    //==============================
   1.843 +    //== Scenario 2.
   1.844 +    //== Create file, filling it with some pattern.
   1.845 +    //== Delete this file, FreeClusterListL() will be involved.
   1.846 +    //== Create an empty file supposedly of the place of just deleted one
   1.847 +    //== Check that the file doesn't contain any meaningful information
   1.848 +    //==============================
   1.849 +    test.Printf(_L("Testing scenario 2\n"));
   1.850 +
   1.851 +    //-- 2. create file filled with some data pattern
   1.852 +    nRes = CreateStuffedFile(TheFs, fileName, KFileSize);
   1.853 +    test(nRes == KErrNone);
   1.854 +
   1.855 +    //-- 2.1 delete this file
   1.856 +    TheFs.Delete(fileName);
   1.857 +
   1.858 +    //-- 2.1 create an empty file on the place of just deleted one (hopefully)
   1.859 +    nRes = CreateEmptyFile(TheFs, fileName, KFileSize);
   1.860 +    test(nRes == KErrNone);
   1.861 +
   1.862 +    //-- 2.2  check that this file doesn't contain illegitimate information.
   1.863 +    nRes = CheckFileContents(TheFs, fileName);
   1.864 +    test(nRes == KErrNone);
   1.865 +
   1.866 +    //-- 2.3 delete this file
   1.867 +    TheFs.Delete(fileName);
   1.868 +
   1.869 +}
   1.870 +
   1.871 +LOCAL_C void Test15()
   1.872 +//
   1.873 +// Test IsValidName
   1.874 +//
   1.875 +	{
   1.876 +	test.Next(_L("Test RFs::IsValidName(TDesC& ,RFs::TNameValidParam& )"));
   1.877 +	TBool useDefaultSessionPath = EFalse;
   1.878 +	//tests under this loop are run twice
   1.879 +	//first, when the sessionPath is not used.
   1.880 +	//second, when the sessionPath is used.
   1.881 +	for(TInt i = 0; i<2; i++)
   1.882 +		{
   1.883 +		RFs::TNameValidParam param(useDefaultSessionPath);
   1.884 +		test(TheFs.IsValidName(_L("*"),param)==EFalse);
   1.885 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.886 +		test(param.InvalidCharPos() == 1);
   1.887 +	
   1.888 +		test(TheFs.IsValidName(_L("?"),param)==EFalse);
   1.889 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.890 +		test(param.InvalidCharPos() == 1);
   1.891 +		
   1.892 +		test(TheFs.IsValidName(_L(">"),param)==EFalse);
   1.893 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.894 +		test(param.InvalidCharPos() == 1);
   1.895 +	
   1.896 +		test(TheFs.IsValidName(_L("<"),param)==EFalse);
   1.897 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.898 +		test(param.InvalidCharPos() == 1);
   1.899 +		
   1.900 +		test(TheFs.IsValidName(_L(":"),param)==EFalse);
   1.901 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.902 +		test(param.InvalidCharPos() == 1);
   1.903 +	
   1.904 +		test(TheFs.IsValidName(_L("\""),param)==EFalse);
   1.905 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.906 +		test(param.InvalidCharPos() == 1);
   1.907 +	
   1.908 +		test(TheFs.IsValidName(_L("/"),param)==EFalse);
   1.909 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.910 +		test(param.InvalidCharPos() == 1);
   1.911 +	
   1.912 +		test(TheFs.IsValidName(_L("|"),param)==EFalse);
   1.913 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.914 +		test(param.InvalidCharPos() == 1);
   1.915 +	
   1.916 +		test(TheFs.IsValidName(_L("xx*yy"),param)==EFalse);
   1.917 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.918 +		test(param.InvalidCharPos() == 3);
   1.919 +		
   1.920 +		test(TheFs.IsValidName(_L("xx?yy"),param)==EFalse);
   1.921 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.922 +		test(param.InvalidCharPos() == 3);
   1.923 +	
   1.924 +		test(TheFs.IsValidName(_L("xx>yy"),param)==EFalse);
   1.925 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.926 +		test(param.InvalidCharPos() == 3);
   1.927 +	
   1.928 +		test(TheFs.IsValidName(_L("xx<yy"),param)==EFalse);
   1.929 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.930 +		test(param.InvalidCharPos() == 3);
   1.931 +
   1.932 +		test(TheFs.IsValidName(_L("xx:yy"),param)==EFalse);
   1.933 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.934 +		test(param.InvalidCharPos() == 3);
   1.935 +		
   1.936 +		test(TheFs.IsValidName(_L("xx\"yy"),param)==EFalse);
   1.937 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.938 +		test(param.InvalidCharPos() == 3);
   1.939 +		
   1.940 +		test(TheFs.IsValidName(_L("xx/yy"),param)==EFalse);
   1.941 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.942 +		test(param.InvalidCharPos() == 3);
   1.943 +			
   1.944 +		test(TheFs.IsValidName(_L("xx|yy"),param)==EFalse);
   1.945 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.946 +		test(param.InvalidCharPos() == 3);
   1.947 +			
   1.948 +		test(TheFs.IsValidName(_L("C:\\*\\group\\release.txt"),param)==EFalse);
   1.949 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.950 +		test(param.InvalidCharPos() == 4);
   1.951 +	
   1.952 +		test(TheFs.IsValidName(_L("C:\\?\\group\\release.txt"),param)==EFalse);
   1.953 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.954 +		test(param.InvalidCharPos() == 4);
   1.955 +	
   1.956 +		test(TheFs.IsValidName(_L("C:\\..\\group\\release.txt"),param)==EFalse);
   1.957 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.958 +		test(param.InvalidCharPos() == 4);
   1.959 +	
   1.960 +		test(TheFs.IsValidName(_L("C:\\.\\group\\release.txt"),param)==EFalse);
   1.961 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.962 +		test(param.InvalidCharPos() == 4);
   1.963 +		
   1.964 +		test(TheFs.IsValidName(_L("C:\\>\\group\\release.txt"),param)==EFalse);
   1.965 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.966 +		test(param.InvalidCharPos() == 4);
   1.967 +	
   1.968 +		test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),param)==EFalse);
   1.969 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.970 +		test(param.InvalidCharPos() == 4);
   1.971 +	
   1.972 +		test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),param)==EFalse);
   1.973 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.974 +		test(param.InvalidCharPos() == 15);
   1.975 +		
   1.976 +		test(TheFs.IsValidName(_L("C::\\group\\release.txt"),param)==EFalse);
   1.977 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.978 +		test(param.InvalidCharPos() == 3);
   1.979 +			
   1.980 +		test(TheFs.IsValidName(_L(">\\group\\release.txt"),param)==EFalse);
   1.981 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.982 +		test(param.InvalidCharPos() == 1);
   1.983 +			
   1.984 +		test(TheFs.IsValidName(_L("C|group\\release.txt"),param)==EFalse);
   1.985 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.986 +		test(param.InvalidCharPos() == 2);
   1.987 +			
   1.988 +		test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),param)==EFalse);
   1.989 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.990 +		test(param.InvalidCharPos() == 3);
   1.991 +			
   1.992 +		test(TheFs.IsValidName(_L("\\>"),param)==EFalse);
   1.993 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.994 +		test(param.InvalidCharPos() == 2);
   1.995 +			
   1.996 +		test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),param)==EFalse);
   1.997 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
   1.998 +		test(param.InvalidCharPos() == 4);
   1.999 +				
  1.1000 +		test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),param)==EFalse);
  1.1001 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1002 +		test(param.InvalidCharPos() == 4);
  1.1003 +		
  1.1004 +		test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),param)==EFalse);
  1.1005 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1006 +		test(param.InvalidCharPos() == 4);
  1.1007 +	
  1.1008 +		test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),param)==EFalse);
  1.1009 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1010 +		test(param.InvalidCharPos() == 4);
  1.1011 +		
  1.1012 +		test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),param)==EFalse);//intermediate directory names cannot be blank
  1.1013 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName);
  1.1014 +			
  1.1015 +		//	Test that \ is not allowed in filenames
  1.1016 +		TFileName filename;
  1.1017 +		filename=_L("C:\\HelloWorld\\\\\\group\\release.txt");
  1.1018 +		
  1.1019 +		test(TheFs.IsValidName(filename,param)==EFalse);
  1.1020 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1021 +		test(param.InvalidCharPos() == 22);
  1.1022 +		
  1.1023 +		filename=_L("C:\\\\\\group\\release.txt");
  1.1024 +		test(TheFs.IsValidName(filename,param)==EFalse);
  1.1025 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1026 +		test(param.InvalidCharPos() == 11);
  1.1027 +		
  1.1028 +		filename=_L("C:\\Hello World\\group\\release.txt");
  1.1029 +		filename[8]=KPathDelimiter;
  1.1030 +		test(TheFs.IsValidName(filename,param));
  1.1031 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1032 +		
  1.1033 +		filename=_L("C:\\HelloWorld\\::\\group\\release.txt");
  1.1034 +		test(TheFs.IsValidName(filename,param)==EFalse);
  1.1035 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1036 +		test(param.InvalidCharPos() == 16);
  1.1037 +			
  1.1038 +		filename=_L("C:\\>>\\group\\release.txt");
  1.1039 +		test(TheFs.IsValidName(filename,param)==EFalse);
  1.1040 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1041 +		test(param.InvalidCharPos() == 5);
  1.1042 +		
  1.1043 +		test(TheFs.IsValidName(_L(""),param)==EFalse); // Must be a name
  1.1044 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName);
  1.1045 +		
  1.1046 +		test(TheFs.IsValidName(_L(".ext"),param));
  1.1047 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1048 +		
  1.1049 +		test(TheFs.IsValidName(_L("C:\\asdf.blarg"),param));
  1.1050 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1051 +		
  1.1052 +		test(TheFs.IsValidName(_L("C:\\asdf..blarg"),param));
  1.1053 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1054 +		
  1.1055 +		//	Test multiple evil characters - parsing occurs from right to left
  1.1056 +		//	except that wildcarded characters take priority and are picked out first
  1.1057 +		
  1.1058 +		test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mno<pqr*stu"),param)==EFalse);
  1.1059 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1060 +		test(param.InvalidCharPos() == 24);
  1.1061 +	
  1.1062 +		test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno?pqr"),param)==EFalse);
  1.1063 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1064 +		test(param.InvalidCharPos() == 20);
  1.1065 +		
  1.1066 +		test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno"),param)==EFalse);
  1.1067 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1068 +		test(param.InvalidCharPos() == 16);
  1.1069 +		
  1.1070 +		test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno"),param)==EFalse);
  1.1071 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1072 +		test(param.InvalidCharPos() == 16);
  1.1073 +	
  1.1074 +		test(TheFs.IsValidName(_L("abc>def|ghi<jkl"),param)==EFalse);
  1.1075 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1076 +		test(param.InvalidCharPos() == 12);
  1.1077 +				
  1.1078 +		test(TheFs.IsValidName(_L("abc>def|ghi<jkl"),param)==EFalse);
  1.1079 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1080 +		test(param.InvalidCharPos() == 12);
  1.1081 +	
  1.1082 +		test(TheFs.IsValidName(_L("abc>def|ghi"),param)==EFalse);
  1.1083 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1084 +		test(param.InvalidCharPos() == 8);
  1.1085 +			
  1.1086 +		test(TheFs.IsValidName(_L("abc>def|ghi"),param)==EFalse);
  1.1087 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1088 +		test(param.InvalidCharPos() == 8);
  1.1089 +	
  1.1090 +		test(TheFs.IsValidName(_L("abc>def"),param)==EFalse);
  1.1091 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1092 +		test(param.InvalidCharPos() == 4);
  1.1093 +	
  1.1094 +		test(TheFs.IsValidName(_L("abc>def"),param)==EFalse);
  1.1095 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1096 +		test(param.InvalidCharPos() == 4);
  1.1097 +	
  1.1098 +		test(!TheFs.IsValidName(_L("C:\\v123456.."),param));
  1.1099 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1100 +		test(param.InvalidCharPos() == 11);
  1.1101 +		
  1.1102 +		test(!TheFs.IsValidName(_L("C:\\v123456.."),param));
  1.1103 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
  1.1104 +		test(param.InvalidCharPos() == 11);
  1.1105 +	
  1.1106 +		test(TheFs.IsValidName(_L("abc"),param));						//	Valid name
  1.1107 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1108 +	
  1.1109 +		test(TheFs.IsValidName(_L("abc"),param));						//	Valid name
  1.1110 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1111 +	
  1.1112 +		test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param));	//	Valid name
  1.1113 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1114 +	
  1.1115 +		test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param));	//	Valid name
  1.1116 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1117 +	
  1.1118 +		test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param));	//	Valid name
  1.1119 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1120 +	
  1.1121 +		test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param));	//	Valid name
  1.1122 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1123 +	
  1.1124 +		test(TheFs.IsValidName(_L("\'"),param));							//	Valid name
  1.1125 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1126 +		
  1.1127 +		test(TheFs.IsValidName(_L("\'"),param));							//	Valid name
  1.1128 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1129 +		
  1.1130 +		//testing directory names
  1.1131 +		test(TheFs.IsValidName(_L("\\"),param));
  1.1132 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);           // Valid Name
  1.1133 +		
  1.1134 +		test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),param));
  1.1135 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);           // Valid Name
  1.1136 +		
  1.1137 +		
  1.1138 +		test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),param));
  1.1139 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);           // Valid Name
  1.1140 +		
  1.1141 +		test(TheFs.IsValidName(_L("file1.txt\\\\"),param) == EFalse);
  1.1142 +		test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName);
  1.1143 +	
  1.1144 +		// test name which exceeds KMaxFileName only on prepending the session path
  1.1145 +		_LIT(KNameLength250, "AAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAA");
  1.1146 +		if(useDefaultSessionPath)
  1.1147 +			{
  1.1148 +			test(TheFs.IsValidName(KNameLength250, param)==EFalse);
  1.1149 +			test(param.ErrorCode() == RFs::TNameValidParam::ErrNameTooLong);
  1.1150 +			break;
  1.1151 +			}
  1.1152 +		else
  1.1153 +			{
  1.1154 +			test(TheFs.IsValidName(KNameLength250, param));
  1.1155 +			test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
  1.1156 +			}
  1.1157 +		useDefaultSessionPath = ETrue;
  1.1158 +		}
  1.1159 +	}
  1.1160 +
  1.1161 +
  1.1162 +
  1.1163 +void TestGetMediaSerialNumber()
  1.1164 +    {
  1.1165 +	test.Next(_L("Test RFs::GetMediaSerialNumber"));	
  1.1166 +    TInt theDrive;
  1.1167 +    TInt r = TheFs.CharToDrive(gDriveToTest,theDrive);
  1.1168 +    test(r == KErrNone);
  1.1169 +    TMediaSerialNumber serNum;
  1.1170 +    r = TheFs.GetMediaSerialNumber(serNum, theDrive);
  1.1171 +	if (r) test.Printf(_L("RFs::GetMediaSerialNumber returned error %d"), r);
  1.1172 +    test(r == KErrNotSupported || r == KErrNotReady || r == KErrNone);
  1.1173 +    if (r == KErrNotSupported)
  1.1174 +        {
  1.1175 +        test.Printf(_L("MediaSerialNumber: Not Supported\n"));
  1.1176 +        }
  1.1177 +    else
  1.1178 +        {
  1.1179 +        test.Printf(_L("MediaSerialNumber: length=%d\n"), serNum.Length());
  1.1180 +        TBuf<20> str;
  1.1181 +        _LIT(KNumberString, "%02X");
  1.1182 +        _LIT(KNewLine, "\n");
  1.1183 +        TInt i;
  1.1184 +        for (i = 0; i < serNum.Length(); i++)
  1.1185 +            {
  1.1186 +            str.AppendFormat(KNumberString, serNum[i]);
  1.1187 +            if (i%8 == 7)
  1.1188 +                {
  1.1189 +                str.Append(KNewLine);
  1.1190 +                test.Printf(_L("%S"), &str);
  1.1191 +                str.SetLength(0);
  1.1192 +                }
  1.1193 +            }
  1.1194 +        if (i%8 != 7)
  1.1195 +            {
  1.1196 +            test.Printf(KNewLine);
  1.1197 +            }
  1.1198 +        }
  1.1199 +    }
  1.1200 +
  1.1201 +
  1.1202 +//--------------------------------------------------------
  1.1203 +
  1.1204 +/**
  1.1205 +    Create an empty file of specified size.
  1.1206 +    @param  aFs		    ref. to the FS
  1.1207 +    @param  aFileName   name of the file
  1.1208 +    @param  aFileSize   size of the file to be created
  1.1209 +    @return    KErrNone on success, system-wide error code otherwise
  1.1210 +*/
  1.1211 +TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize)
  1.1212 +{
  1.1213 +    RFile   file;
  1.1214 +	TInt    nRes;
  1.1215 +
  1.1216 +	nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite);
  1.1217 +    if(nRes != KErrNone)
  1.1218 +        return nRes;
  1.1219 +
  1.1220 +	nRes = file.SetSize(aFileSize);
  1.1221 +    if(nRes != KErrNone)
  1.1222 +        return nRes;
  1.1223 +
  1.1224 +    file.Close();
  1.1225 +
  1.1226 +    return KErrNone;
  1.1227 +}
  1.1228 +
  1.1229 +//--------------------------------------------------------
  1.1230 +
  1.1231 +/**
  1.1232 +    Create a file of specified size filled with some data pattern.
  1.1233 +    @param  aFs		    ref. to the FS
  1.1234 +    @param  aFileName   name of the file
  1.1235 +    @param  aFileSize   size of the file to be created
  1.1236 +    @return    KErrNone on success, system-wide error code otherwise
  1.1237 +*/
  1.1238 +TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize)
  1.1239 +{
  1.1240 +	TInt    nRes;
  1.1241 +    RFile   file;
  1.1242 +
  1.1243 +	//-- create a buffer with some data
  1.1244 +	const TUint KBufLength = 0x100;
  1.1245 +	TBuf8<KBufLength> buffer;
  1.1246 +	buffer.SetLength(KBufLength);
  1.1247 +
  1.1248 +    TUint i;
  1.1249 +
  1.1250 +	for(i = 0; i < KBufLength; i++)
  1.1251 +		buffer[i] = static_cast<TUint8> (i) ;
  1.1252 +
  1.1253 +	//-- create a file
  1.1254 +	nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite);
  1.1255 +    if(nRes != KErrNone)
  1.1256 +        return nRes;
  1.1257 +
  1.1258 +    const TUint n1 = aFileSize / KBufLength;
  1.1259 +    const TUint n2 = aFileSize % KBufLength;
  1.1260 +
  1.1261 +    //-- fill the file with the data from buffer
  1.1262 +    for(i=0; i<n1; ++i)
  1.1263 +    {
  1.1264 +        nRes = file.Write(buffer);
  1.1265 +        if(nRes != KErrNone)
  1.1266 +            return nRes;
  1.1267 +    }
  1.1268 +
  1.1269 +    if(n2)
  1.1270 +    {
  1.1271 +        nRes = file.Write(buffer, n2); //-- write the rest of the data
  1.1272 +        if(nRes != KErrNone)
  1.1273 +            return nRes;
  1.1274 +    }
  1.1275 +
  1.1276 +    file.Close();
  1.1277 +
  1.1278 +    return KErrNone;
  1.1279 +}
  1.1280 +
  1.1281 +//--------------------------------------------------------
  1.1282 +
  1.1283 +/**
  1.1284 +    Check if the specified file contains illegitimate information i.e. something different from 0x00, 0xff, 0x03, 0xcc
  1.1285 +
  1.1286 +    @param  aFs		    ref. to the FS
  1.1287 +    @param  aFileName   name of the file
  1.1288 +    @return    KErrNone on success, KErrCorrupt otherwise
  1.1289 +*/
  1.1290 +TInt   CheckFileContents(RFs& aFs, const TDesC& aFileName)
  1.1291 +{
  1.1292 +	TInt    nRes = KErrNone;
  1.1293 +    RFile   file;
  1.1294 +
  1.1295 +	const TInt KBufLength = 0x100;
  1.1296 +	TBuf8<KBufLength> buffer;
  1.1297 +    buffer.SetLength(0);
  1.1298 +
  1.1299 +    //-- open the file
  1.1300 +    nRes = file.Open(aFs, aFileName, EFileRead);
  1.1301 +    test(nRes == KErrNone);
  1.1302 +
  1.1303 +    //-- check file contents
  1.1304 +    TUint nFilePos=0;
  1.1305 +    for(;;)
  1.1306 +    {
  1.1307 +        //-- read data from the file into the buffer
  1.1308 +        nRes = file.Read(buffer);
  1.1309 +        test(nRes == KErrNone);
  1.1310 +
  1.1311 +        if(buffer.Length() == 0)
  1.1312 +        {
  1.1313 +            nRes = KErrNone; //-- read all the file, no illegitimate information found
  1.1314 +            break; //EOF
  1.1315 +        }
  1.1316 +
  1.1317 +        //-- check if the buffer contains only allowed data (RAM page initialisation data, etc. e.g. 0x00, 0xff, 0x03, 0xcc)
  1.1318 +        if(!CheckBufferContents(buffer, nFilePos))
  1.1319 +        {
  1.1320 +            test.Printf(_L("\nCheckFileContents failed ! The file contains illegitimate information!\n"));
  1.1321 +            nRes = KErrCorrupt; //-- indicate that the read buffer contains illegitimate information
  1.1322 +            break; //-- comment this out if you need a full dump of the file
  1.1323 +        }
  1.1324 +
  1.1325 +        nFilePos+=buffer.Length();
  1.1326 +    }
  1.1327 +
  1.1328 +    file.Close();
  1.1329 +    return nRes;
  1.1330 +}
  1.1331 +
  1.1332 +//--------------------------------------------------------
  1.1333 +
  1.1334 +/**
  1.1335 +    Check if the buffer contains illegitimate information i.e. something different from 0x00, 0xff, 0x03, 0xcc
  1.1336 +
  1.1337 +    @param  aBuffer         buffer descriptor to check
  1.1338 +    @param  aPrintBaseAddr  dump base address, used for dumping buffer only
  1.1339 +    @return ETrue on success
  1.1340 +*/
  1.1341 +TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr/*=0*/)
  1.1342 +{
  1.1343 +    TBool bRes = ETrue;
  1.1344 +
  1.1345 +    //-- check if the buffer filled with allowable data (RAM page initialisation data or something similar)
  1.1346 +    //-- but not something meaningful.
  1.1347 +    //-- allowable bytes: 0x00, 0x03, 0xff, 0xcc
  1.1348 +    for(TInt i=0; i<aBuffer.Size(); ++i)
  1.1349 +    {
  1.1350 +        TUint8 byte = aBuffer[i];
  1.1351 +        if(byte != 0x00 && byte != 0x03 && byte != 0xff && byte != 0xcc )
  1.1352 +        {
  1.1353 +            bRes = EFalse;
  1.1354 +            break;
  1.1355 +        }
  1.1356 +    }
  1.1357 +
  1.1358 +    //-- dump the buffer if it contains anything different than allowed data
  1.1359 +	if (!bRes)
  1.1360 +	{
  1.1361 +		for (TInt n=0; n<aBuffer.Size(); )
  1.1362 +			{
  1.1363 +			TBuf16<3> byteBuffer;
  1.1364 +			TBuf16<256> lineBuffer;
  1.1365 +			lineBuffer.Format(_L("%08X: "), aPrintBaseAddr+n);
  1.1366 +			for (TInt m=0; m<16 && n<aBuffer.Size(); m++, n++)
  1.1367 +				{
  1.1368 +				byteBuffer.Format(_L("%02X "), aBuffer[n]);
  1.1369 +				lineBuffer.Append(byteBuffer);
  1.1370 +				}
  1.1371 +			test.Printf(lineBuffer);
  1.1372 +			}
  1.1373 +	}
  1.1374 +
  1.1375 +    return bRes;
  1.1376 +}
  1.1377 +
  1.1378 +
  1.1379 +GLDEF_C void CallTestsL()
  1.1380 +//
  1.1381 +// Call tests that may leave
  1.1382 +//
  1.1383 +	{
  1.1384 +
  1.1385 +	Test1();
  1.1386 +	Test2();
  1.1387 +	Test3();
  1.1388 +	Test4();
  1.1389 +	Test5();
  1.1390 +	Test6();
  1.1391 +	Test7();
  1.1392 +	Test8();
  1.1393 +	Test9();
  1.1394 +	Test10();
  1.1395 +	Test11();
  1.1396 +	Test12();
  1.1397 +	Test13();
  1.1398 +	Test14();
  1.1399 +	Test15();
  1.1400 +    TestGetMediaSerialNumber();
  1.1401 +	}