Beispiel #1
0
void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
//
// Make a file and write uid and data
//
	{
	RFile file;
	TInt r=file.Replace(TheFs,aFileName,0);
	test_Value(r, r == KErrNone || r==KErrPathNotFound);
	if (r==KErrPathNotFound)
		{
		r=TheFs.MkDirAll(aFileName);
		test_KErrNone(r);
		r=file.Replace(TheFs,aFileName,0);
		test_KErrNone(r);
		}
	TCheckedUid checkedUid(aUidType);
	TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(uidData);
	test_KErrNone(r);
	r=file.Write(aFileContents);
	test_KErrNone(r);
	file.Close();
	}
Beispiel #2
0
LOCAL_C void CreateUidTestFiles()
//
// Create files with uids for testing
//
	{
    // Create \\gSessionPath\\UIDCHKNO.SHT - no uid, zero length
	RFile file;
	TInt r=file.Replace(TheFs,_L("UIDCHKNO.SHT"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.Close();

    // Create \\gSessionPath\\UIDCHKNO.LNG - no uid, long length
	r=file.Replace(TheFs,_L("UIDCHKNO.LNG"),EFileRead|EFileWrite);
	test_KErrNone(r);
	r=file.Write(_L8("Hello World needs to be over 16 bytes"));
	file.Close();

    // Create \\gSessionPath\\UIDCHK.BLG - with uid no data
	r=file.Replace(TheFs,_L("UIDCHK.BLG"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
	TCheckedUid checkedUid(uidType);
	TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	file.Close();

    // Create \\gSessionPath\\UIDCHK.MSG - with uid and data
	r=file.Replace(TheFs,_L("UIDCHK.MSG"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
	checkedUid.Set(uidType2);
	buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	r=file.Write(_L8("More file data"));
	test_KErrNone(r);
	file.Close();

    // Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
	r=file.Replace(TheFs,_L("UIDCHK.DAT"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
	checkedUid.Set(uidType3);
	buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	r=file.Write(_L8("More file data"));
	test_KErrNone(r);
	file.Close();

    // Create \\gSessionPath\\UIDCHK.PE - uid stored in WINS PE file header
	r=file.Replace(TheFs,_L("UIDWINS.PE"),EFileRead|EFileWrite);
	test_KErrNone(r);

#if defined(__WINS__)
    if (!IsTestingLFFS())
        {
	    RFile fileSource;
	    r=fileSource.Open(TheFs,_L("Z:\\TEST\\T_CHKUID.EXE"),EFileShareReadersOnly|EFileRead);
	    test_KErrNone(r);

	    TBuf8<0x100> buffer;
	    do
		    {
		    r=fileSource.Read(buffer);
		    test_KErrNone(r);
		    r=file.Write(buffer);
		    test_KErrNone(r);
		    }
	    while (buffer.Length()==buffer.MaxLength());

	    fileSource.Close();
        }
    else
        {
	    r=file.Write(_L8("Some zany stuff here!"));
	    test_KErrNone(r);
        }
#else
	r=file.Write(_L8("Some zany stuff here!"));
	test_KErrNone(r);
#endif
	file.Close();
	}
Beispiel #3
0
LOCAL_C void CreateTestFiles()
//
// Create files with uids for testing
//
	{

	test.Next(_L("Create test files"));
	TInt r=TheFs.MkDir(_L("\\F32-TST\\"));
	test_Value(r, r == KErrNone || r==KErrAlreadyExists);

	RFile file;

//	Create \\gSessionPath\\UIDCHK.BLG - with uid no data
	r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.BLG"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
	TCheckedUid checkedUid(uidType);
	TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	file.Close();

//	Create \\gSessionPath\\UIDCHK.MSG - with uid and data
	r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.MSG"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
	checkedUid.Set(uidType2);
	buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	r=file.Write(_L8("More file data"));
	test_KErrNone(r);
	file.Close();
	
//	Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
	r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
	checkedUid.Set(uidType3);
	buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	r=file.Write(_L8("More file data"));
	test_KErrNone(r);
	file.Close();

//	Make a few random files - these will be deleted before the test begins
//	but are necessary to try to split file ReadFileSection into non-contiguous clusters
	
	r=file.Replace(TheFs,_L("\\F32-TST\\Temp1.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(550);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp2.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp3.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();
	
	r=file.Replace(TheFs,_L("\\F32-TST\\Temp4.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(550);
	file.Close();
	
	r=file.Replace(TheFs,_L("\\F32-TST\\Temp5.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp6.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp7.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp8.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp9.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp10.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	TheFs.Delete(_L("\\F32-TST\\Temp2.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp4.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp6.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp8.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp10.txt"));
	
	r=file.Replace(TheFs,_L("\\F32-TST\\ReadFileSection1.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);

//	Write 5000 bytes of nonsense
	
	TInt i=0;
	for ( ; i<100; i++)
		{
		r=file.Write(alphaPtr);
		test_KErrNone(r);
		r=file.Write(numberPtr);
		test_KErrNone(r);
		r=file.Write(humptyPtr);
		test_KErrNone(r);
		}
	
	file.Close();

	TheFs.Delete(_L("\\F32-TST\\Temp1.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp3.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp5.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp7.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp9.txt"));
	}