kerneltest/f32test/filesystem/fat/t_raw.cpp
changeset 109 b3a1d9898418
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
    37 	{
    37 	{
    38 
    38 
    39 	test.Start(_L("Test all methods"));
    39 	test.Start(_L("Test all methods"));
    40 	RRawDisk rd;
    40 	RRawDisk rd;
    41 	TInt r=rd.Open(TheFs,gDrive);
    41 	TInt r=rd.Open(TheFs,gDrive);
    42 	test(r==KErrNone);
    42 	test_KErrNone(r);
    43 	TBuf8<16> buf;
    43 	TBuf8<16> buf;
    44 	r=rd.Read(0,buf);
    44 	r=rd.Read(0,buf);
    45 	test(r==KErrNone);
    45 	test_KErrNone(r);
    46 	r=rd.Write(0,buf);
    46 	r=rd.Write(0,buf);
    47 	test(r==KErrNone);
    47 	test_KErrNone(r);
    48 	rd.Close();
    48 	rd.Close();
    49 	test.End();
    49 	test.End();
    50 	}
    50 	}
    51 
    51 
    52 LOCAL_C void Test2()
    52 LOCAL_C void Test2()
    58 	MakeFile(_L("TRAW.TST"));
    58 	MakeFile(_L("TRAW.TST"));
    59 	MakeDir(_L("\\F32-TST\\TRAW\\TRAWTEST\\"));
    59 	MakeDir(_L("\\F32-TST\\TRAW\\TRAWTEST\\"));
    60 
    60 
    61 	RFile f;
    61 	RFile f;
    62 	TInt r=f.Open(TheFs,_L("TRAW.TST"),EFileWrite);
    62 	TInt r=f.Open(TheFs,_L("TRAW.TST"),EFileWrite);
    63 	test(r==KErrNone);
    63 	test_KErrNone(r);
    64 	RRawDisk rd;
    64 	RRawDisk rd;
    65 	r=rd.Open(TheFs,gDrive);
    65 	r=rd.Open(TheFs,gDrive);
    66 	test(r==KErrInUse);
    66 	test_Value(r, r == KErrInUse);
    67 	f.Close();
    67 	f.Close();
    68 	r=rd.Open(TheFs,gDrive);
    68 	r=rd.Open(TheFs,gDrive);
    69 	test(r==KErrNone);
    69 	test_KErrNone(r);
    70 	rd.Close();
    70 	rd.Close();
    71 
    71 
    72 	TFileName fileName;
    72 	TFileName fileName;
    73 	r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
    73 	r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
    74 	test(r==KErrNone);
    74 	test_KErrNone(r);
    75 	r=rd.Open(TheFs,gDrive);
    75 	r=rd.Open(TheFs,gDrive);
    76 	test(r==KErrInUse);
    76 	test_Value(r, r == KErrInUse);
    77 	f.Close();
    77 	f.Close();
    78 	r=rd.Open(TheFs,gDrive);
    78 	r=rd.Open(TheFs,gDrive);
    79 	test(r==KErrNone);
    79 	test_KErrNone(r);
    80 	rd.Close();
    80 	rd.Close();
    81 
    81 
    82 	RDir d;
    82 	RDir d;
    83 	r=d.Open(TheFs,_L("TRAWTEST"),KEntryAttNormal);
    83 	r=d.Open(TheFs,_L("TRAWTEST"),KEntryAttNormal);
    84 	test(r==KErrNone);
    84 	test_KErrNone(r);
    85 	r=rd.Open(TheFs,gDrive);
    85 	r=rd.Open(TheFs,gDrive);
    86 	test(r==KErrInUse);
    86 	test_Value(r, r == KErrInUse);
    87 	d.Close();
    87 	d.Close();
    88 	r=rd.Open(TheFs,gDrive);
    88 	r=rd.Open(TheFs,gDrive);
    89 	test(r==KErrNone);
    89 	test_KErrNone(r);
    90 	rd.Close();
    90 	rd.Close();
    91 
    91 
    92     RFormat fmt;
    92     RFormat fmt;
    93     TInt count;
    93     TInt count;
    94     r=fmt.Open(TheFs,gSessionPath,EQuickFormat,count);
    94     r=fmt.Open(TheFs,gSessionPath,EQuickFormat,count);
    95     test(r==KErrNone);
    95     test_KErrNone(r);
    96     r=rd.Open(TheFs,gDrive); // Raw disk access ok during formatting
    96     r=rd.Open(TheFs,gDrive); // Raw disk access ok during formatting
    97     test.Printf(_L("open rd when fmt opn r=%d"),r);
    97     test.Printf(_L("open rd when fmt opn r=%d"),r);
    98 	test(r==KErrInUse);
    98 	test_Value(r, r == KErrInUse);
    99     fmt.Close();
    99     fmt.Close();
   100     r=rd.Open(TheFs,gDrive);
   100     r=rd.Open(TheFs,gDrive);
   101 	test.Printf(_L("open rd when fmt closed r=%d"),r);
   101 	test.Printf(_L("open rd when fmt closed r=%d"),r);
   102     test(r==KErrNone);
   102     test_KErrNone(r);
   103 	RRawDisk rd2;
   103 	RRawDisk rd2;
   104 	r=rd2.Open(TheFs,gDrive);	//should only have one Raw object open
   104 	r=rd2.Open(TheFs,gDrive);	//should only have one Raw object open
   105 	test(r==KErrInUse);
   105 	test_Value(r, r == KErrInUse);
   106 	rd2.Close();
   106 	rd2.Close();
   107     rd.Close();
   107     rd.Close();
   108 	}
   108 	}
   109 
   109 
   110 LOCAL_C void Test3()
   110 LOCAL_C void Test3()
   116 	MakeFile(_L("TRAW.TST"));
   116 	MakeFile(_L("TRAW.TST"));
   117 	MakeDir(_L("TRAW"));
   117 	MakeDir(_L("TRAW"));
   118 
   118 
   119 	RRawDisk rd;
   119 	RRawDisk rd;
   120 	TInt r=rd.Open(TheFs,gDrive);
   120 	TInt r=rd.Open(TheFs,gDrive);
   121 	test(r==KErrNone);
   121 	test_KErrNone(r);
   122 
   122 
   123 	RFile f;
   123 	RFile f;
   124 	TFileName fileName;
   124 	TFileName fileName;
   125 	r=f.Open(TheFs,_L("TRAW.TST"),EFileWrite);
   125 	r=f.Open(TheFs,_L("TRAW.TST"),EFileWrite);
   126 	test(r==KErrInUse);
   126 	test_Value(r, r == KErrInUse);
   127 	r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
   127 	r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
   128 	test(r==KErrInUse);
   128 	test_Value(r, r == KErrInUse);
   129 
   129 
   130 	RDir d;
   130 	RDir d;
   131 	r=d.Open(TheFs,_L("TRAW"),KEntryAttNormal);
   131 	r=d.Open(TheFs,_L("TRAW"),KEntryAttNormal);
   132 	test(r==KErrInUse);
   132 	test_Value(r, r == KErrInUse);
   133 
   133 
   134 	RFormat fmt;
   134 	RFormat fmt;
   135 	TInt count;
   135 	TInt count;
   136 	r=fmt.Open(TheFs,gSessionPath,EQuickFormat,count);
   136 	r=fmt.Open(TheFs,gSessionPath,EQuickFormat,count);
   137     if (r != KErrInUse)
   137     if (r != KErrInUse)
   138         test.Printf(_L("Error %d. Sess = %S"), r, &gSessionPath);
   138         test.Printf(_L("Error %d. Sess = %S"), r, &gSessionPath);
   139 	test(r==KErrInUse);
   139 	test_Value(r, r == KErrInUse);
   140 
   140 
   141 	CDir* dir=(CDir*)0x05;
   141 	CDir* dir=(CDir*)0x05;
   142 	r=TheFs.GetDir(_L("\\F32-TST\\*.*"),KEntryAttNormal,ESortNone,dir);
   142 	r=TheFs.GetDir(_L("\\F32-TST\\*.*"),KEntryAttNormal,ESortNone,dir);
   143 	test(r==KErrInUse);
   143 	test_Value(r, r == KErrInUse);
   144 	test(dir==NULL);
   144 	test(dir==NULL);
   145 
   145 
   146 	RRawDisk rd2;
   146 	RRawDisk rd2;
   147 	r=rd2.Open(TheFs,gDrive);
   147 	r=rd2.Open(TheFs,gDrive);
   148 	test(r==KErrInUse);
   148 	test_Value(r, r == KErrInUse);
   149 
   149 
   150 //	fmt.Close();
   150 //	fmt.Close();
   151 	rd.Close();
   151 	rd.Close();
   152 //	rd2.Close();
   152 //	rd2.Close();
   153 	}
   153 	}
   161 	TBuf8<32> contents=_L8("This File says BOO");
   161 	TBuf8<32> contents=_L8("This File says BOO");
   162 	MakeFile(_L("TRAW.TST"),contents);
   162 	MakeFile(_L("TRAW.TST"),contents);
   163 
   163 
   164 	RRawDisk rd;
   164 	RRawDisk rd;
   165 	TInt r=rd.Open(TheFs,gDrive);
   165 	TInt r=rd.Open(TheFs,gDrive);
   166 	test(r==KErrNone);
   166 	test_KErrNone(r);
   167 
   167 
   168 	TBuf8<32> textBuf;
   168 	TBuf8<32> textBuf;
   169 	TInt64 pos=0;
   169 	TInt64 pos=0;
   170 
   170 
   171 	test.Printf(_L("doing rawread"));
   171 	test.Printf(_L("doing rawread"));
   188 		}
   188 		}
   189 	test.Printf(_L("\n"));
   189 	test.Printf(_L("\n"));
   190 
   190 
   191 	TBuf8<32> contents2=_L8("This File says MOO");
   191 	TBuf8<32> contents2=_L8("This File says MOO");
   192 	r=rd.Write(pos,contents2);
   192 	r=rd.Write(pos,contents2);
   193 	test(r==KErrNone);
   193 	test_KErrNone(r);
   194 	rd.Close();
   194 	rd.Close();
   195 
   195 
   196 	RFile f;
   196 	RFile f;
   197 	r=f.Open(TheFs,_L("TRAW.TST"),EFileRead);
   197 	r=f.Open(TheFs,_L("TRAW.TST"),EFileRead);
   198 	test(r==KErrNone);
   198 	test_KErrNone(r);
   199 	r=f.Read(textBuf);
   199 	r=f.Read(textBuf);
   200 	test(r==KErrNone);
   200 	test_KErrNone(r);
   201 	test(textBuf==contents2);
   201 	test(textBuf==contents2);
   202 	f.Close();
   202 	f.Close();
   203 	}
   203 	}
   204 
   204 
   205 enum TTestCommands
   205 enum TTestCommands
   258 	test.Next(_L("Test thread panics"));
   258 	test.Next(_L("Test thread panics"));
   259 	MakeFile(_L("TEST.FILE"));
   259 	MakeFile(_L("TEST.FILE"));
   260 
   260 
   261 	RThread thread;
   261 	RThread thread;
   262 	TInt r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadForgetToCloseSession);
   262 	TInt r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadForgetToCloseSession);
   263 	test(r==KErrNone);
   263 	test_KErrNone(r);
   264 	TRequestStatus reqStat;
   264 	TRequestStatus reqStat;
   265 	thread.Logon(reqStat);
   265 	thread.Logon(reqStat);
   266 	thread.Resume();
   266 	thread.Resume();
   267 	User::WaitForRequest(reqStat);
   267 	User::WaitForRequest(reqStat);
   268 	CLOSE_AND_WAIT(thread);
   268 	CLOSE_AND_WAIT(thread);
   272 	// Connect and disconnect a session here to make sure.
   272 	// Connect and disconnect a session here to make sure.
   273 	FsBarrier();
   273 	FsBarrier();
   274 
   274 
   275 	RFile f;
   275 	RFile f;
   276 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   276 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   277 	test(r==KErrNone);
   277 	test_KErrNone(r);
   278 	f.Close();
   278 	f.Close();
   279 
   279 
   280 	r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadForgetToCloseRaw);
   280 	r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadForgetToCloseRaw);
   281 	test(r==KErrNone);
   281 	test_KErrNone(r);
   282 	thread.Logon(reqStat);
   282 	thread.Logon(reqStat);
   283 	thread.Resume();
   283 	thread.Resume();
   284 	User::WaitForRequest(reqStat);
   284 	User::WaitForRequest(reqStat);
   285 	CLOSE_AND_WAIT(thread);
   285 	CLOSE_AND_WAIT(thread);
   286 
   286 
   288 	// but we don't know it has been processed.
   288 	// but we don't know it has been processed.
   289 	// Connect and disconnect a session here to make sure.
   289 	// Connect and disconnect a session here to make sure.
   290 	FsBarrier();
   290 	FsBarrier();
   291 
   291 
   292 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   292 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   293 	test(r==KErrNone);
   293 	test_KErrNone(r);
   294 	f.Close();
   294 	f.Close();
   295 
   295 
   296 	r=gSemaphore.CreateGlobal(_L("MySemaphore"),0);
   296 	r=gSemaphore.CreateGlobal(_L("MySemaphore"),0);
   297 	test(r==KErrNone);
   297 	test_KErrNone(r);
   298 	r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadHang);
   298 	r=thread.Create(_L("MyThread"),MyThreadFunction,0x1000,0x1000,0x1000,(TAny*)EThreadHang);
   299 	test(r==KErrNone);
   299 	test_KErrNone(r);
   300 	thread.Resume();
   300 	thread.Resume();
   301 	gSemaphore.Wait();
   301 	gSemaphore.Wait();
   302 	gSemaphore.Close();
   302 	gSemaphore.Close();
   303 
   303 
   304 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   304 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   305 	test(r==KErrInUse);
   305 	test_Value(r, r == KErrInUse);
   306 	TBool jit = User::JustInTime();
   306 	TBool jit = User::JustInTime();
   307 	User::SetJustInTime(EFalse);
   307 	User::SetJustInTime(EFalse);
   308 	thread.Kill(KErrGeneral);
   308 	thread.Kill(KErrGeneral);
   309 	CLOSE_AND_WAIT(thread);
   309 	CLOSE_AND_WAIT(thread);
   310 	User::SetJustInTime(jit);
   310 	User::SetJustInTime(jit);
   313 	// but we don't know it has been processed.
   313 	// but we don't know it has been processed.
   314 	// Connect and disconnect a session here to make sure.
   314 	// Connect and disconnect a session here to make sure.
   315 	FsBarrier();
   315 	FsBarrier();
   316 
   316 
   317 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   317 	r=f.Open(TheFs,_L("TEST.FILE"),EFileWrite);
   318 	test(r==KErrNone);
   318 	test_KErrNone(r);
   319 	f.Close();
   319 	f.Close();
   320 	}
   320 	}
   321 
   321 
   322 
   322 
   323 GLDEF_C void CallTestsL()
   323 GLDEF_C void CallTestsL()
   328 
   328 
   329     //-- set up console output
   329     //-- set up console output
   330     Fat_Test_Utils::SetConsole(test.Console());
   330     Fat_Test_Utils::SetConsole(test.Console());
   331 
   331 
   332 	TInt r=TheFs.CharToDrive(gSessionPath[0],gDrive);
   332 	TInt r=TheFs.CharToDrive(gSessionPath[0],gDrive);
   333 	test(r==KErrNone);
   333 	test_KErrNone(r);
   334 
   334 
   335     PrintDrvInfo(TheFs, gDrive);
   335     PrintDrvInfo(TheFs, gDrive);
   336 
   336 
   337     //-- check if this is FAT
   337     //-- check if this is FAT
   338     if(!Is_Fat(TheFs, gDrive))
   338     if(!Is_Fat(TheFs, gDrive))