kerneltest/f32test/server/b_file.cpp
changeset 109 b3a1d9898418
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
    13 // Description:
    13 // Description:
    14 // f32test\server\b_file.cpp
    14 // f32test\server\b_file.cpp
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
       
    18 #define __E32TEST_EXTENSION__
    18 #include <f32file.h>
    19 #include <f32file.h>
    19 #include <e32math.h>
    20 #include <e32math.h>
    20 #include <e32test.h>
    21 #include <e32test.h>
    21 #include "t_server.h"
    22 #include "t_server.h"
    22 
    23 
    70 	CheckDisk();
    71 	CheckDisk();
    71     test.Printf(_L("bwrite1,len=%u\n"),aLength);
    72     test.Printf(_L("bwrite1,len=%u\n"),aLength);
    72     TInt pos=0; // Relative position zero
    73     TInt pos=0; // Relative position zero
    73     aret=TheFile.Seek(ESeekCurrent,pos);
    74     aret=TheFile.Seek(ESeekCurrent,pos);
    74     test.Printf(_L("bwrite2,pos=%u\n"),pos);
    75     test.Printf(_L("bwrite2,pos=%u\n"),pos);
    75     test(aret==KErrNone);
    76     test_KErrNone(aret);
    76     TInt count=pos&0xff;
    77     TInt count=pos&0xff;
    77 	tbuf.SetLength(aLength);
    78 	tbuf.SetLength(aLength);
    78 	TText8* p=(TText8*)tbuf.Ptr();
    79 	TText8* p=(TText8*)tbuf.Ptr();
    79 	TText8* pE=p+aLength;
    80 	TText8* pE=p+aLength;
    80     while (p<pE)
    81     while (p<pE)
    96     {
    97     {
    97 
    98 
    98 	CheckDisk();
    99 	CheckDisk();
    99     TInt pos=0; // Relative position zero
   100     TInt pos=0; // Relative position zero
   100     aret=TheFile.Seek(ESeekCurrent,pos);
   101     aret=TheFile.Seek(ESeekCurrent,pos);
   101     test(aret==KErrNone);
   102     test_KErrNone(aret);
   102     TInt count=pos&0xff;
   103     TInt count=pos&0xff;
   103     aret=TheFile.Read(tbuf,aLength);
   104     aret=TheFile.Read(tbuf,aLength);
   104     if (bret<KErrNone)
   105     if (bret<KErrNone)
   105 		{
   106 		{
   106         test(bret==aret);
   107         test(bret==aret);
   125     {
   126     {
   126 
   127 
   127 	CheckDisk();
   128 	CheckDisk();
   128     TInt newpos=aPos;
   129     TInt newpos=aPos;
   129     aret=TheFile.Seek(ESeekStart,newpos);
   130     aret=TheFile.Seek(ESeekStart,newpos);
   130     test(aret==KErrNone);
   131     test_KErrNone(aret);
   131     test(newpos==aPos);
   132     test(newpos==aPos);
   132 	CheckDisk();
   133 	CheckDisk();
   133     }
   134     }
   134 
   135 
   135 LOCAL_C void bclose()
   136 LOCAL_C void bclose()
   163     bret=KErrAlreadyExists;bcreate(aMode|EFileWrite);bret=0;
   164     bret=KErrAlreadyExists;bcreate(aMode|EFileWrite);bret=0;
   164     bopen(aMode|EFileRead);
   165     bopen(aMode|EFileRead);
   165     bret=KErrAccessDenied; bwrite(1); bret=0;
   166     bret=KErrAccessDenied; bwrite(1); bret=0;
   166     bclose();
   167     bclose();
   167 	aret=TheFile.Open(TheFs,tzzz,EFileRead);
   168 	aret=TheFile.Open(TheFs,tzzz,EFileRead);
   168 	test(aret==KErrNotFound);
   169 	test_Value(aret, aret == KErrNotFound);
   169 	test.End();
   170 	test.End();
   170     }
   171     }
   171 
   172 
   172 LOCAL_C void btest2(TUint aMode)
   173 LOCAL_C void btest2(TUint aMode)
   173 //
   174 //
   197     bposa(KMaxTInt);
   198     bposa(KMaxTInt);
   198     bwrite(50);
   199     bwrite(50);
   199     bposa(0);
   200     bposa(0);
   200     bret=1100; bread(1100); bret=0;
   201     bret=1100; bread(1100); bret=0;
   201     aret=TheFile.Flush();
   202     aret=TheFile.Flush();
   202     test(aret==KErrNone);
   203     test_KErrNone(aret);
   203     aret=TheFile.SetSize(2000);
   204     aret=TheFile.SetSize(2000);
   204     test(aret==KErrNone);
   205     test_KErrNone(aret);
   205     TInt pos=0;
   206     TInt pos=0;
   206     aret=TheFile.Seek(ESeekCurrent,pos);
   207     aret=TheFile.Seek(ESeekCurrent,pos);
   207     test(aret==KErrNone && pos==1100);
   208     test_Value(aret, aret == KErrNone && pos==1100);
   208     pos=0;
   209     pos=0;
   209     aret=TheFile.Seek(ESeekEnd,pos);
   210     aret=TheFile.Seek(ESeekEnd,pos);
   210     test(aret==KErrNone && pos==2000);
   211     test_Value(aret, aret == KErrNone && pos==2000);
   211     bclose();
   212     bclose();
   212 	test.End();
   213 	test.End();
   213     }
   214     }
   214 
   215 
   215 LOCAL_C void rndtest(TUint aMode)
   216 LOCAL_C void rndtest(TUint aMode)
   223 
   224 
   224     TInt cnt;
   225     TInt cnt;
   225     test.Start(_L("RNDTEST..."));
   226     test.Start(_L("RNDTEST..."));
   226     TInt64 seed(0),zero(0);
   227     TInt64 seed(0),zero(0);
   227 	aret=TheFile.Replace(TheFs,rndm,EFileWrite|aMode);
   228 	aret=TheFile.Replace(TheFs,rndm,EFileWrite|aMode);
   228 	test(aret==KErrNone);
   229 	test_KErrNone(aret);
   229     for (cnt=0;cnt<KRandomNumbers;cnt++)
   230     for (cnt=0;cnt<KRandomNumbers;cnt++)
   230         {
   231         {
   231 		TBuf8<0x10> b;
   232 		TBuf8<0x10> b;
   232 		b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed));
   233 		b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed));
   233 		aret=TheFile.Write(b);
   234 		aret=TheFile.Write(b);
   234 		test(aret==KErrNone);
   235 		test_KErrNone(aret);
   235         }
   236         }
   236 	TheFile.Close();
   237 	TheFile.Close();
   237 //
   238 //
   238     test.Next(_L("Reading back"));
   239     test.Next(_L("Reading back"));
   239     seed=zero;
   240     seed=zero;
   240 	aret=TheFile.Open(TheFs,rndm,aMode);
   241 	aret=TheFile.Open(TheFs,rndm,aMode);
   241 	test(aret==KErrNone);
   242 	test_KErrNone(aret);
   242     for (cnt=0;cnt<KRandomNumbers;cnt++)
   243     for (cnt=0;cnt<KRandomNumbers;cnt++)
   243         {
   244         {
   244 		TBuf8<8> b;
   245 		TBuf8<8> b;
   245 		b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed));
   246 		b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed));
   246 		TBuf8<8> r;
   247 		TBuf8<8> r;
   247 		aret=TheFile.Read(r);
   248 		aret=TheFile.Read(r);
   248 		test(aret==KErrNone);
   249 		test_KErrNone(aret);
   249 		test(b==r);
   250 		test(b==r);
   250         }
   251         }
   251 	TheFile.Close();
   252 	TheFile.Close();
   252     aret=TheFs.Delete(rndm);
   253     aret=TheFs.Delete(rndm);
   253 	test(aret==KErrNone);
   254 	test_KErrNone(aret);
   254 //
   255 //
   255 	test.End();
   256 	test.End();
   256     }
   257     }
   257 
   258 
   258 LOCAL_C void testAutoClose()
   259 LOCAL_C void testAutoClose()
   262     {
   263     {
   263 
   264 
   264     test.Start(_L("TAutoClose..."));
   265     test.Start(_L("TAutoClose..."));
   265 	TAutoClose<RFile> f;
   266 	TAutoClose<RFile> f;
   266 	aret=f.iObj.Replace(TheFs,rndm,EFileWrite);
   267 	aret=f.iObj.Replace(TheFs,rndm,EFileWrite);
   267 	test(aret==KErrNone);
   268 	test_KErrNone(aret);
   268     TInt64 seed;
   269     TInt64 seed;
   269     for (TInt cnt=0;cnt<KRandomNumbers;cnt++)
   270     for (TInt cnt=0;cnt<KRandomNumbers;cnt++)
   270         {
   271         {
   271 		TBuf8<0x10> b;
   272 		TBuf8<0x10> b;
   272 		b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed));
   273 		b.Format(TPtrC8((TUint8*)"%8x"),Math::Rand(seed));
   273 		aret=f.iObj.Write(b);
   274 		aret=f.iObj.Write(b);
   274 		test(aret==KErrNone);
   275 		test_KErrNone(aret);
   275         }
   276         }
   276 	test.End();
   277 	test.End();
   277     }
   278     }
   278 
   279 
   279 LOCAL_C void readWithNegativeLengthTest()
   280 LOCAL_C void readWithNegativeLengthTest()
   281     test.Start(_L("Read with Negative Length Test..."));
   282     test.Start(_L("Read with Negative Length Test..."));
   282     TInt	ret;
   283     TInt	ret;
   283 	TRequestStatus status = KRequestPending;
   284 	TRequestStatus status = KRequestPending;
   284 	TheFile.Open(TheFs,tbin,EFileRead);
   285 	TheFile.Open(TheFs,tbin,EFileRead);
   285  	ret = TheFile.Read(0,tbuf,-1);			// sync
   286  	ret = TheFile.Read(0,tbuf,-1);			// sync
   286  	test ( ret == KErrArgument);
   287  	test_Value(ret, ret == KErrArgument);
   287  	TheFile.Read(0,tbuf,-1,status);		// async
   288  	TheFile.Read(0,tbuf,-1,status);		// async
   288  	User::WaitForRequest(status);
   289  	User::WaitForRequest(status);
   289  	test(status.Int() == KErrArgument);
   290  	test(status.Int() == KErrArgument);
   290 	TheFile.Close();
   291 	TheFile.Close();
   291 	test.End();
   292 	test.End();
   297 
   298 
   298 	test.Start(_L("Read with Negative Length Test(For EmptyFile)..."));
   299 	test.Start(_L("Read with Negative Length Test(For EmptyFile)..."));
   299 	RFile f;             
   300 	RFile f;             
   300 	MakeFile(_L("C:\\F32-TST\\TFILE\\hello2.txt"));
   301 	MakeFile(_L("C:\\F32-TST\\TFILE\\hello2.txt"));
   301 	TInt r=f.Open(TheFs,_L("C:\\F32-TST\\TFILE\\hello2.txt"),EFileRead); 
   302 	TInt r=f.Open(TheFs,_L("C:\\F32-TST\\TFILE\\hello2.txt"),EFileRead); 
   302 	test(r==KErrNone);
   303 	test_KErrNone(r);
   303 
   304 
   304 	TBuf8<0x100> a;
   305 	TBuf8<0x100> a;
   305 	test.Next(_L("Check Negative length when file is empty"));
   306 	test.Next(_L("Check Negative length when file is empty"));
   306 	r=f.Read(a, -10);
   307 	r=f.Read(a, -10);
   307 	test(r==KErrArgument);
   308 	test_Value(r, r == KErrArgument);
   308 	r=f.Read(0,a, -1);
   309 	r=f.Read(0,a, -1);
   309 	test(r==KErrArgument);
   310 	test_Value(r, r == KErrArgument);
   310 	r=f.Read(0,a, -10);
   311 	r=f.Read(0,a, -10);
   311 	test(r==KErrArgument);
   312 	test_Value(r, r == KErrArgument);
   312 	TRequestStatus	stat1;
   313 	TRequestStatus	stat1;
   313 	f.Read(0,a,-5,stat1);
   314 	f.Read(0,a,-5,stat1);
   314 	User::WaitForRequest(stat1);
   315 	User::WaitForRequest(stat1);
   315 	test(stat1.Int() == KErrArgument);
   316 	test(stat1.Int() == KErrArgument);
   316 	f.Read(a,-5,stat1);
   317 	f.Read(a,-5,stat1);