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