Update contrib.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_raw.cpp
18 #define __E32TEST_EXTENSION__
25 #include "fat_utils.h"
26 using namespace Fat_Test_Utils;
29 GLDEF_D RTest test(_L("T_RAW"));
39 test.Start(_L("Test all methods"));
41 TInt r=rd.Open(TheFs,gDrive);
54 // Test cannot open a RRawDisk while other resources are open on it.
58 MakeFile(_L("TRAW.TST"));
59 MakeDir(_L("\\F32-TST\\TRAW\\TRAWTEST\\"));
62 TInt r=f.Open(TheFs,_L("TRAW.TST"),EFileWrite);
65 r=rd.Open(TheFs,gDrive);
68 r=rd.Open(TheFs,gDrive);
73 r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
75 r=rd.Open(TheFs,gDrive);
78 r=rd.Open(TheFs,gDrive);
83 r=d.Open(TheFs,_L("TRAWTEST"),KEntryAttNormal);
85 r=rd.Open(TheFs,gDrive);
88 r=rd.Open(TheFs,gDrive);
94 r=fmt.Open(TheFs,gSessionPath,EQuickFormat,count);
96 r=rd.Open(TheFs,gDrive); // Raw disk access ok during formatting
97 test.Printf(_L("open rd when fmt opn r=%d"),r);
100 r=rd.Open(TheFs,gDrive);
101 test.Printf(_L("open rd when fmt closed r=%d"),r);
104 r=rd2.Open(TheFs,gDrive); //should only have one Raw object open
112 // Test cannot open resources on a disk while raw access is taking place
116 MakeFile(_L("TRAW.TST"));
120 TInt r=rd.Open(TheFs,gDrive);
125 r=f.Open(TheFs,_L("TRAW.TST"),EFileWrite);
127 r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
131 r=d.Open(TheFs,_L("TRAW"),KEntryAttNormal);
136 r=fmt.Open(TheFs,gSessionPath,EQuickFormat,count);
138 test.Printf(_L("Error %d. Sess = %S"), r, &gSessionPath);
141 CDir* dir=(CDir*)0x05;
142 r=TheFs.GetDir(_L("\\F32-TST\\*.*"),KEntryAttNormal,ESortNone,dir);
147 r=rd2.Open(TheFs,gDrive);
157 // Test Read and Write
161 TBuf8<32> contents=_L8("This File says BOO");
162 MakeFile(_L("TRAW.TST"),contents);
165 TInt r=rd.Open(TheFs,gDrive);
171 test.Printf(_L("doing rawread"));
174 r=rd.Read(pos,textBuf);
177 test.Printf(_L("ERROR: RawDisk read returned %d at pos %ld"),r, pos);
182 if ((pos % (1024*1024)) == 0)
183 test.Printf(_L("Read position 0x%x \r"), pos);
184 textBuf.SetLength(contents.Length());
185 if (textBuf==contents)
189 test.Printf(_L("\n"));
191 TBuf8<32> contents2=_L8("This File says MOO");
192 r=rd.Write(pos,contents2);
197 r=f.Open(TheFs,_L("TRAW.TST"),EFileRead);
201 test(textBuf==contents2);
207 EThreadForgetToCloseSession,
208 EThreadForgetToCloseRaw,
212 RSemaphore gSemaphore;
214 TInt MyThreadFunction(TAny* aThreadCommand)
225 r=rd.Open(fs,gDrive);
229 switch((TTestCommands)(TInt)aThreadCommand)
231 case EThreadForgetToCloseSession:
234 case EThreadForgetToCloseRaw:
248 User::Panic(_L("Shouldn't be here!"),0);
254 // Test thread panics
258 test.Next(_L("Test thread panics"));
259 MakeFile(_L("TEST.FILE"));
262 TInt r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadForgetToCloseSession);
264 TRequestStatus reqStat;
265 thread.Logon(reqStat);
267 User::WaitForRequest(reqStat);
268 CLOSE_AND_WAIT(thread);
270 // We know the disconnect has been sent to the file server by this point
271 // but we don't know it has been processed.
272 // Connect and disconnect a session here to make sure.
276 r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
280 r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadForgetToCloseRaw);
282 thread.Logon(reqStat);
284 User::WaitForRequest(reqStat);
285 CLOSE_AND_WAIT(thread);
287 // We know the disconnect has been sent to the file server by this point
288 // but we don't know it has been processed.
289 // Connect and disconnect a session here to make sure.
292 r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
296 r=gSemaphore.CreateGlobal(_L("MySemaphore"),0);
298 r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadHang);
304 r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
306 TBool jit = User::JustInTime();
307 User::SetJustInTime(EFalse);
308 thread.Kill(KErrGeneral);
309 CLOSE_AND_WAIT(thread);
310 User::SetJustInTime(jit);
312 // We know the disconnect has been sent to the file server by this point
313 // but we don't know it has been processed.
314 // Connect and disconnect a session here to make sure.
317 r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
323 GLDEF_C void CallTestsL()
329 //-- set up console output
330 Fat_Test_Utils::SetConsole(test.Console());
332 TInt r=TheFs.CharToDrive(gSessionPath[0],gDrive);
335 PrintDrvInfo(TheFs, gDrive);
337 //-- check if this is FAT
338 if(!Is_Fat(TheFs, gDrive))
340 test.Printf(_L("Skipping. This test requires FAT drive.\n"));
344 //-- format the drive.
345 r = FormatFatDrive(TheFs, gDrive, ETrue);
348 CreateTestDirectory(_L("\\F32-TST\\TRAW\\"));
354 Test4(); // (silly test) Not valid on LFFS
358 DeleteTestDirectory();