sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\b_file.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: sl@0: GLDEF_D RTest test(_L("B_FILE")); sl@0: sl@0: LOCAL_D RFile TheFile; sl@0: LOCAL_D TInt bret; // Expected error return sl@0: LOCAL_D TInt aret; // Actual error return sl@0: LOCAL_D TBuf8<10000> tbuf; // Test buffer sl@0: LOCAL_D TPtrC tbin(_S("\\F32-TST\\TEST.BIN")); sl@0: LOCAL_D TPtrC rndm(_S("\\F32-TST\\RANDOM.TST")); sl@0: LOCAL_D TPtrC tzzz(_S("\\F32-TST\\ZZZZZZ.ZZZ")); sl@0: LOCAL_D const TInt KRandomNumbers=1024; sl@0: sl@0: LOCAL_C void bopen(TUint aMode) sl@0: // sl@0: // Open the binary file. sl@0: // sl@0: { sl@0: sl@0: aret=TheFile.Open(TheFs,tbin,aMode); sl@0: test(aret==bret); sl@0: } sl@0: sl@0: LOCAL_C void bcreate(TUint aMode) sl@0: // sl@0: // Open the binary file. sl@0: // sl@0: { sl@0: sl@0: aret=TheFile.Create(TheFs,tbin,aMode); sl@0: test(aret==bret); sl@0: } sl@0: sl@0: LOCAL_C void breplace(TUint aMode) sl@0: // sl@0: // Open the binary file. sl@0: // sl@0: { sl@0: sl@0: aret=TheFile.Replace(TheFs,tbin,aMode); sl@0: test(aret==bret); sl@0: } sl@0: sl@0: LOCAL_C void bwrite(TInt aLength) sl@0: // sl@0: // Write aLength bytes of test data at current position. sl@0: // sl@0: { sl@0: sl@0: CheckDisk(); sl@0: test.Printf(_L("bwrite1,len=%u\n"),aLength); sl@0: TInt pos=0; // Relative position zero sl@0: aret=TheFile.Seek(ESeekCurrent,pos); sl@0: test.Printf(_L("bwrite2,pos=%u\n"),pos); sl@0: test(aret==KErrNone); sl@0: TInt count=pos&0xff; sl@0: tbuf.SetLength(aLength); sl@0: TText8* p=(TText8*)tbuf.Ptr(); sl@0: TText8* pE=p+aLength; sl@0: while (p b; sl@0: b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed)); sl@0: aret=TheFile.Write(b); sl@0: test(aret==KErrNone); sl@0: } sl@0: TheFile.Close(); sl@0: // sl@0: test.Next(_L("Reading back")); sl@0: seed=zero; sl@0: aret=TheFile.Open(TheFs,rndm,aMode); sl@0: test(aret==KErrNone); sl@0: for (cnt=0;cnt b; sl@0: b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed)); sl@0: TBuf8<8> r; sl@0: aret=TheFile.Read(r); sl@0: test(aret==KErrNone); sl@0: test(b==r); sl@0: } sl@0: TheFile.Close(); sl@0: aret=TheFs.Delete(rndm); sl@0: test(aret==KErrNone); sl@0: // sl@0: test.End(); sl@0: } sl@0: sl@0: LOCAL_C void testAutoClose() sl@0: // sl@0: // Tests TAutoClose template class sl@0: // sl@0: { sl@0: sl@0: test.Start(_L("TAutoClose...")); sl@0: TAutoClose f; sl@0: aret=f.iObj.Replace(TheFs,rndm,EFileWrite); sl@0: test(aret==KErrNone); sl@0: TInt64 seed; sl@0: for (TInt cnt=0;cnt b; sl@0: b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed)); sl@0: aret=f.iObj.Write(b); sl@0: test(aret==KErrNone); sl@0: } sl@0: test.End(); sl@0: } sl@0: sl@0: LOCAL_C void readWithNegativeLengthTest() sl@0: { sl@0: test.Start(_L("Read with Negative Length Test...")); sl@0: TInt ret; sl@0: TRequestStatus status = KRequestPending; sl@0: TheFile.Open(TheFs,tbin,EFileRead); sl@0: ret = TheFile.Read(0,tbuf,-1); // sync sl@0: test ( ret == KErrArgument); sl@0: TheFile.Read(0,tbuf,-1,status); // async sl@0: User::WaitForRequest(status); sl@0: test(status.Int() == KErrArgument); sl@0: TheFile.Close(); sl@0: test.End(); sl@0: } sl@0: sl@0: LOCAL_C void readWithNegativeLengthTestForEmptyFile() sl@0: sl@0: { sl@0: sl@0: test.Start(_L("Read with Negative Length Test(For EmptyFile)...")); sl@0: RFile f; sl@0: MakeFile(_L("C:\\F32-TST\\TFILE\\hello2.txt")); sl@0: TInt r=f.Open(TheFs,_L("C:\\F32-TST\\TFILE\\hello2.txt"),EFileRead); sl@0: test(r==KErrNone); sl@0: sl@0: TBuf8<0x100> a; sl@0: test.Next(_L("Check Negative length when file is empty")); sl@0: r=f.Read(a, -10); sl@0: test(r==KErrArgument); sl@0: r=f.Read(0,a, -1); sl@0: test(r==KErrArgument); sl@0: r=f.Read(0,a, -10); sl@0: test(r==KErrArgument); sl@0: TRequestStatus stat1; sl@0: f.Read(0,a,-5,stat1); sl@0: User::WaitForRequest(stat1); sl@0: test(stat1.Int() == KErrArgument); sl@0: f.Read(a,-5,stat1); sl@0: User::WaitForRequest(stat1); sl@0: test(stat1.Int() == KErrArgument); sl@0: f.Close(); sl@0: test.End(); sl@0: sl@0: } sl@0: sl@0: GLDEF_C void CallTestsL() sl@0: // sl@0: // Call tests that may leave sl@0: // sl@0: { sl@0: sl@0: testAutoClose(); sl@0: btest1(EFileStream); sl@0: btest2(EFileStream); sl@0: btest1(EFileStreamText); sl@0: btest2(EFileStreamText); sl@0: rndtest(EFileStream); sl@0: readWithNegativeLengthTest(); sl@0: readWithNegativeLengthTestForEmptyFile(); sl@0: sl@0: }