32 #ifdef __VC32__ |
27 #ifdef __VC32__ |
33 // Solve compilation problem caused by non-English locale |
28 // Solve compilation problem caused by non-English locale |
34 #pragma setlocale("english") |
29 #pragma setlocale("english") |
35 #endif |
30 #endif |
36 |
31 |
37 RTest test(_L("T_MISC")); |
32 GLDEF_D RTest test(_L("T_MISC")); |
38 |
33 |
39 |
|
40 TInt gDriveNum = -1; |
|
41 const TUint KBufLength = 0x100; |
34 const TUint KBufLength = 0x100; |
42 |
35 |
43 static void Test1() |
36 LOCAL_C void Test1() |
44 // |
37 // |
45 // Open, write to and read from a file |
38 // Open, write to and read from a file |
46 // |
39 // |
47 { |
40 { |
48 |
41 |
49 test.Next(_L("Open, write to and read from a file")); |
42 test.Next(_L("Open, write to and read from a file")); |
50 TInt r=TheFs.SetSessionPath(gSessionPath); |
43 TInt r=TheFs.SetSessionPath(gSessionPath); |
51 test_KErrNone(r); |
44 test(r==KErrNone); |
52 RFile file; |
45 RFile file; |
53 r=file.Create(TheFs,_L("Hello.Wld"),EFileWrite); |
46 r=file.Create(TheFs,_L("Hello.Wld"),EFileWrite); |
54 test_KErrNone(r); |
47 test(r==KErrNone); |
55 r=file.Write(_L8("Hello World"),11); |
48 r=file.Write(_L8("Hello World"),11); |
56 test_KErrNone(r); |
49 test(r==KErrNone); |
57 file.Close(); |
50 file.Close(); |
58 |
51 |
59 r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); |
52 r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); |
60 test_KErrNone(r); |
53 test(r==KErrNone); |
61 TBuf8<256> buf; |
54 TBuf8<256> buf; |
62 r=file.Read(buf); |
55 r=file.Read(buf); |
63 test_KErrNone(r); |
56 test(r==KErrNone); |
64 test(buf==_L8("Hello World")); |
57 test(buf==_L8("Hello World")); |
65 file.Close(); |
58 file.Close(); |
66 } |
59 } |
67 |
60 |
68 static void Test2() |
61 LOCAL_C void Test2() |
69 // |
62 // |
70 // Open and read from a file |
63 // Open and read from a file |
71 // |
64 // |
72 { |
65 { |
73 |
66 |
74 test.Next(_L("Open and read from a file")); |
67 test.Next(_L("Open and read from a file")); |
75 TInt r=TheFs.SetSessionPath(gSessionPath); |
68 TInt r=TheFs.SetSessionPath(gSessionPath); |
76 test_KErrNone(r); |
69 test(r==KErrNone); |
77 RFile file; |
70 RFile file; |
78 r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); |
71 r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); |
79 test_KErrNone(r); |
72 test(r==KErrNone); |
80 TBuf8<256> buf; |
73 TBuf8<256> buf; |
81 r=file.Read(buf); |
74 r=file.Read(buf); |
82 test_KErrNone(r); |
75 test(r==KErrNone); |
83 test(buf==_L8("Hello World")); |
76 test(buf==_L8("Hello World")); |
84 file.Close(); |
77 file.Close(); |
85 r=TheFs.Delete(_L("HELLO.WLD")); |
78 r=TheFs.Delete(_L("HELLO.WLD")); |
86 test_KErrNone(r); |
79 test(r==KErrNone); |
87 } |
80 } |
88 |
81 |
89 static void Test3() |
82 LOCAL_C void Test3() |
90 // |
83 // |
91 // Create nested directories |
84 // Create nested directories |
92 // |
85 // |
93 { |
86 { |
94 |
87 |
95 test.Next(_L("Create nested directories")); |
88 test.Next(_L("Create nested directories")); |
96 TInt r=TheFs.SetSessionPath(gSessionPath); |
89 TInt r=TheFs.SetSessionPath(gSessionPath); |
97 test_KErrNone(r); |
90 test(r==KErrNone); |
98 TheFs.ResourceCountMarkStart(); |
91 TheFs.ResourceCountMarkStart(); |
99 // |
92 // |
100 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\A.B")); |
93 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\A.B")); |
101 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
94 test(r==KErrNone || r==KErrAlreadyExists); |
102 r=TheFs.MkDir(_L("\\F32-TST\\RIGHT\\")); |
95 r=TheFs.MkDir(_L("\\F32-TST\\RIGHT\\")); |
103 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
96 test(r==KErrNone || r==KErrAlreadyExists); |
104 // |
97 // |
105 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\ONE\\")); |
98 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\ONE\\")); |
106 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
99 test(r==KErrNone || r==KErrAlreadyExists); |
107 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\")); |
100 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\")); |
108 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
101 test(r==KErrNone || r==KErrAlreadyExists); |
109 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\THREE\\")); |
102 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\THREE\\")); |
110 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
103 test(r==KErrNone || r==KErrAlreadyExists); |
111 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\BOTTOM\\")); |
104 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\BOTTOM\\")); |
112 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
105 test(r==KErrNone || r==KErrAlreadyExists); |
113 // |
106 // |
114 r=TheFs.MkDirAll(_L("\\F32-TST\\RIGHT\\TOP\\MID\\BOT\\")); |
107 r=TheFs.MkDirAll(_L("\\F32-TST\\RIGHT\\TOP\\MID\\BOT\\")); |
115 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
108 test(r==KErrNone || r==KErrAlreadyExists); |
116 } |
109 } |
117 |
110 |
118 static void Test4() |
111 LOCAL_C void Test4() |
119 // |
112 // |
120 // Test returned error values |
113 // Test returned error values |
121 // |
114 // |
122 { |
115 { |
123 |
116 |
124 test.Next(_L("Test returned error values")); |
117 test.Next(_L("Test returned error values")); |
125 TInt r=TheFs.SetSessionPath(gSessionPath); |
118 TInt r=TheFs.SetSessionPath(gSessionPath); |
126 test_KErrNone(r); |
119 test(r==KErrNone); |
127 TheFs.ResourceCountMarkStart(); |
120 TheFs.ResourceCountMarkStart(); |
128 // |
121 // |
129 r=TheFs.MkDir(_L("\\")); |
122 r=TheFs.MkDir(_L("\\")); |
130 test_Value(r, r == KErrAlreadyExists); |
123 test(r==KErrAlreadyExists); |
131 r=TheFs.MkDir(_L("\\LEFT")); |
124 r=TheFs.MkDir(_L("\\LEFT")); |
132 test_Value(r, r == KErrAlreadyExists); |
125 test(r==KErrAlreadyExists); |
133 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\")); |
126 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\")); |
134 test_Value(r, r == KErrAlreadyExists); |
127 test(r==KErrAlreadyExists); |
135 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\..\\NEWDIR\\")); |
128 r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\..\\NEWDIR\\")); |
136 test_Value(r, r == KErrBadName); |
129 test(r==KErrBadName); |
137 r=TheFs.MkDir(_L("\\F32-TST\\NEWDIR\\SUBDIR\\")); |
130 r=TheFs.MkDir(_L("\\F32-TST\\NEWDIR\\SUBDIR\\")); |
138 test_Value(r, r == KErrPathNotFound); |
131 test(r==KErrPathNotFound); |
139 // |
132 // |
140 r=TheFs.RmDir(_L("\\")); |
133 r=TheFs.RmDir(_L("\\")); |
141 test_Value(r, r == KErrInUse); |
134 test(r==KErrInUse); |
142 r=TheFs.RmDir(_L("\\PROG")); |
135 r=TheFs.RmDir(_L("\\PROG")); |
143 test_Value(r, r == KErrInUse); |
136 test(r==KErrInUse); |
144 r=TheFs.RmDir(_L("\\F32-TST\\")); |
137 r=TheFs.RmDir(_L("\\F32-TST\\")); |
145 test_Value(r, r == KErrInUse); |
138 test(r==KErrInUse); |
146 |
139 |
147 |
140 |
148 RDir dir; |
141 RDir dir; |
149 r=dir.Open(TheFs,_L("V:\\asdf"),KEntryAttNormal); |
142 r=dir.Open(TheFs,_L("V:\\asdf"),KEntryAttNormal); |
150 test_Value(r, r == KErrNone || r==KErrNotReady || r==KErrNotFound); |
143 test(r==KErrNone || r==KErrNotReady || r==KErrNotFound); |
151 if (r==KErrNone) |
144 if (r==KErrNone) |
152 dir.Close(); |
145 dir.Close(); |
153 r=dir.Open(TheFs,_L("L:\\asdf"),KEntryAttNormal); |
146 r=dir.Open(TheFs,_L("L:\\asdf"),KEntryAttNormal); |
154 test_Value(r, r == KErrNone || r==KErrNotReady || r==KErrNotFound); |
147 test(r==KErrNone || r==KErrNotReady || r==KErrNotFound); |
155 dir.Close(); |
148 dir.Close(); |
156 // |
149 // |
157 TEntry entry; |
150 TEntry entry; |
158 r=TheFs.Entry(_L("z:\\NOTEXiSTS\\file.txt"),entry); |
151 r=TheFs.Entry(_L("z:\\NOTEXiSTS\\file.txt"),entry); |
159 test_Value(r, r == KErrPathNotFound); |
152 test(r==KErrPathNotFound); |
160 r=TheFs.Entry(_L("z:\\NOTEXiSTS\\"),entry); |
153 r=TheFs.Entry(_L("z:\\NOTEXiSTS\\"),entry); |
161 test_Value(r, r == KErrNotFound); |
154 test(r==KErrNotFound); |
162 r=TheFs.Entry(_L("z:\\SYSTEM\\"),entry); |
155 r=TheFs.Entry(_L("z:\\SYSTEM\\"),entry); |
163 test_KErrNone(r); |
156 test(r==KErrNone); |
164 r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("z:\\SYS\\BIN\\ESHELL.EXE"):_L("z:\\SYSTEM\\BIN\\ESHELL.EXE"),entry); |
157 r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("z:\\SYS\\BIN\\ESHELL.EXE"):_L("z:\\SYSTEM\\BIN\\ESHELL.EXE"),entry); |
165 test_KErrNone(r); |
158 test(r==KErrNone); |
166 |
159 |
167 r=dir.Open(TheFs,_L("\\*"),NULL); |
160 r=dir.Open(TheFs,_L("\\*"),NULL); |
168 test_KErrNone(r); |
161 test(r==KErrNone); |
169 TEntry dirEntry; |
162 TEntry dirEntry; |
170 r=dir.Read(dirEntry); |
163 r=dir.Read(dirEntry); |
171 test_Value(r, r == KErrNone || r==KErrEof); |
164 test(r==KErrNone || r==KErrEof); |
172 if (r==KErrNone) |
165 if (r==KErrNone) |
173 test.Printf(_L("%S\n"),&dirEntry.iName); |
166 test.Printf(_L("%S\n"),&dirEntry.iName); |
174 dir.Close(); |
167 dir.Close(); |
175 |
168 |
176 r=dir.Open(TheFs,_L("A:\\*"),NULL); |
169 r=dir.Open(TheFs,_L("A:\\*"),NULL); |
177 test_Value(r, r == KErrNotReady || r==KErrNone); |
170 test(r==KErrNotReady || r==KErrNone); |
178 dir.Close(); |
171 dir.Close(); |
179 } |
172 } |
180 |
173 |
181 static void Test5() |
174 LOCAL_C void Test5() |
182 // |
175 // |
183 // Read files directly from the rom |
176 // Read files directly from the rom |
184 // |
177 // |
185 |
178 |
186 { |
179 { |
193 |
186 |
194 if ( TheFs.IsFileInRom(KTFileCpp) != NULL && TheFs.IsFileInRom(KTFsrvCpp) != NULL ) |
187 if ( TheFs.IsFileInRom(KTFileCpp) != NULL && TheFs.IsFileInRom(KTFsrvCpp) != NULL ) |
195 { |
188 { |
196 RFile f; |
189 RFile f; |
197 r=f.Open(TheFs,KTFileCpp,EFileRead); |
190 r=f.Open(TheFs,KTFileCpp,EFileRead); |
198 test_KErrNone(r); |
191 test(r==KErrNone); |
199 r=f.Seek(ESeekAddress,pos); |
192 r=f.Seek(ESeekAddress,pos); |
200 TText8* ptrPos=*(TText8**)&pos; |
193 TText8* ptrPos=*(TText8**)&pos; |
201 test_KErrNone(r); |
194 test(r==KErrNone); |
202 TBuf8<1024> readBuf; |
195 TBuf8<1024> readBuf; |
203 r=f.Read(readBuf); |
196 r=f.Read(readBuf); |
204 test_KErrNone(r); |
197 test(r==KErrNone); |
205 test(readBuf.Length()==readBuf.MaxLength()); |
198 test(readBuf.Length()==readBuf.MaxLength()); |
206 TPtrC8 memBuf(ptrPos,readBuf.Length()); |
199 TPtrC8 memBuf(ptrPos,readBuf.Length()); |
207 test(memBuf==readBuf); |
200 test(memBuf==readBuf); |
208 |
201 |
209 ptrPos+=9913; |
202 ptrPos+=9913; |
210 pos=9913; |
203 pos=9913; |
211 r=f.Seek(ESeekStart,pos); |
204 r=f.Seek(ESeekStart,pos); |
212 test_KErrNone(r); |
205 test(r==KErrNone); |
213 readBuf.SetLength(0); |
206 readBuf.SetLength(0); |
214 r=f.Read(readBuf); |
207 r=f.Read(readBuf); |
215 test_KErrNone(r); |
208 test(r==KErrNone); |
216 test(readBuf.Length()==readBuf.MaxLength()); |
209 test(readBuf.Length()==readBuf.MaxLength()); |
217 memBuf.Set(ptrPos,readBuf.Length()); |
210 memBuf.Set(ptrPos,readBuf.Length()); |
218 test(memBuf==readBuf); |
211 test(memBuf==readBuf); |
219 |
212 |
220 RFile f2; |
213 RFile f2; |
221 pos=10; |
214 pos=10; |
222 r=f2.Open(TheFs,KTFsrvCpp,EFileRead); |
215 r=f2.Open(TheFs,KTFsrvCpp,EFileRead); |
223 |
216 |
224 test_KErrNone(r); |
217 test(r==KErrNone); |
225 r=f2.Seek(ESeekAddress,pos); |
218 r=f2.Seek(ESeekAddress,pos); |
226 ptrPos=*(TText8**)&pos; |
219 ptrPos=*(TText8**)&pos; |
227 test_KErrNone(r); |
220 test(r==KErrNone); |
228 readBuf.SetLength(0); |
221 readBuf.SetLength(0); |
229 pos=10; |
222 pos=10; |
230 r=f2.Seek(ESeekStart,pos); |
223 r=f2.Seek(ESeekStart,pos); |
231 test_KErrNone(r); |
224 test(r==KErrNone); |
232 r=f2.Read(readBuf); |
225 r=f2.Read(readBuf); |
233 test_KErrNone(r); |
226 test(r==KErrNone); |
234 test(readBuf.Length()==readBuf.MaxLength()); |
227 test(readBuf.Length()==readBuf.MaxLength()); |
235 memBuf.Set(ptrPos,readBuf.Length()); |
228 memBuf.Set(ptrPos,readBuf.Length()); |
236 test(memBuf==readBuf); |
229 test(memBuf==readBuf); |
237 |
230 |
238 ptrPos+=2445; |
231 ptrPos+=2445; |
239 pos=10+2445; |
232 pos=10+2445; |
240 r=f2.Seek(ESeekStart,pos); |
233 r=f2.Seek(ESeekStart,pos); |
241 test_KErrNone(r); |
234 test(r==KErrNone); |
242 readBuf.SetLength(0); |
235 readBuf.SetLength(0); |
243 r=f2.Read(readBuf); |
236 r=f2.Read(readBuf); |
244 test_KErrNone(r); |
237 test(r==KErrNone); |
245 test(readBuf.Length()==readBuf.MaxLength()); |
238 test(readBuf.Length()==readBuf.MaxLength()); |
246 memBuf.Set(ptrPos,readBuf.Length()); |
239 memBuf.Set(ptrPos,readBuf.Length()); |
247 test(memBuf==readBuf); |
240 test(memBuf==readBuf); |
248 |
241 |
249 pos=0; |
242 pos=0; |
250 r=f.Seek(ESeekAddress,pos); |
243 r=f.Seek(ESeekAddress,pos); |
251 ptrPos=*(TText8**)&pos; |
244 ptrPos=*(TText8**)&pos; |
252 test_KErrNone(r); |
245 test(r==KErrNone); |
253 readBuf.SetLength(0); |
246 readBuf.SetLength(0); |
254 pos=0; |
247 pos=0; |
255 r=f.Seek(ESeekStart,pos); |
248 r=f.Seek(ESeekStart,pos); |
256 test_KErrNone(r); |
249 test(r==KErrNone); |
257 r=f.Read(readBuf); |
250 r=f.Read(readBuf); |
258 test_KErrNone(r); |
251 test(r==KErrNone); |
259 test(readBuf.Length()==readBuf.MaxLength()); |
252 test(readBuf.Length()==readBuf.MaxLength()); |
260 memBuf.Set(ptrPos,readBuf.Length()); |
253 memBuf.Set(ptrPos,readBuf.Length()); |
261 test(memBuf==readBuf); |
254 test(memBuf==readBuf); |
262 |
255 |
263 ptrPos+=5245; |
256 ptrPos+=5245; |
264 pos=5245; |
257 pos=5245; |
265 r=f.Seek(ESeekStart,pos); |
258 r=f.Seek(ESeekStart,pos); |
266 test_KErrNone(r); |
259 test(r==KErrNone); |
267 readBuf.SetLength(0); |
260 readBuf.SetLength(0); |
268 r=f.Read(readBuf); |
261 r=f.Read(readBuf); |
269 test_KErrNone(r); |
262 test(r==KErrNone); |
270 test(readBuf.Length()==readBuf.MaxLength()); |
263 test(readBuf.Length()==readBuf.MaxLength()); |
271 memBuf.Set(ptrPos,readBuf.Length()); |
264 memBuf.Set(ptrPos,readBuf.Length()); |
272 test(memBuf==readBuf); |
265 test(memBuf==readBuf); |
273 |
266 |
274 f.Close(); |
267 f.Close(); |
275 f2.Close(); |
268 f2.Close(); |
276 } |
269 } |
277 } |
270 } |
278 |
271 |
279 static void Test6() |
272 LOCAL_C void Test6() |
280 // |
273 // |
281 // Test rom return values |
274 // Test rom return values |
282 // |
275 // |
283 { |
276 { |
284 test.Next(_L("Test rom return values")); |
277 test.Next(_L("Test rom return values")); |
285 |
278 |
286 RFile f; |
279 RFile f; |
287 TInt r=f.Replace(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); |
280 TInt r=f.Replace(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); |
288 test_Value(r, r == KErrAccessDenied); |
281 test(r==KErrAccessDenied); |
289 r=f.Create(TheFs,_L("Z:\\Test\\newT_Fsrv.Cpp"),EFileRead); |
282 r=f.Create(TheFs,_L("Z:\\Test\\newT_Fsrv.Cpp"),EFileRead); |
290 test_Value(r, r == KErrAccessDenied); |
283 test(r==KErrAccessDenied); |
291 r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); |
284 r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); |
292 test_KErrNone(r); |
285 test(r==KErrNone); |
293 f.Close(); |
286 f.Close(); |
294 r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead|EFileWrite); |
287 r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead|EFileWrite); |
295 test_Value(r, r == KErrAccessDenied); |
288 test(r==KErrAccessDenied); |
296 } |
289 } |
297 |
290 |
298 static void Test7() |
291 LOCAL_C void Test7() |
299 // |
292 // |
300 // Test cache |
293 // Test cache |
301 // |
294 // |
302 { |
295 { |
303 |
296 |
579 TFileName driveName; |
572 TFileName driveName; |
580 TInt i; |
573 TInt i; |
581 for(i=0;i<KMaxDrives;i++) |
574 for(i=0;i<KMaxDrives;i++) |
582 { |
575 { |
583 TInt r=TheFs.GetDriveName(i,driveName); |
576 TInt r=TheFs.GetDriveName(i,driveName); |
584 test_KErrNone(r); |
577 test(r==KErrNone); |
585 if (driveName.Length()) |
578 if (driveName.Length()) |
586 test.Printf(_L("Default name of %c: == %S\n"),'A'+i,&driveName); |
579 test.Printf(_L("Default name of %c: == %S\n"),'A'+i,&driveName); |
587 } |
580 } |
588 |
581 |
589 TBuf<64> drive0=_L("Dilbert"); |
582 TBuf<64> drive0=_L("Dilbert"); |
590 TBuf<64> drive4=_L("Dogbert"); |
583 TBuf<64> drive4=_L("Dogbert"); |
591 TBuf<64> drive17=_L("Flibble"); |
584 TBuf<64> drive17=_L("Flibble"); |
592 TBuf<64> drive25=_L("RAMDRIVE"); |
585 TBuf<64> drive25=_L("RAMDRIVE"); |
593 TInt r=TheFs.SetDriveName(0,drive0); |
586 TInt r=TheFs.SetDriveName(0,drive0); |
594 test_KErrNone(r); |
587 test(r==KErrNone); |
595 r=TheFs.SetDriveName(4,drive4); |
588 r=TheFs.SetDriveName(4,drive4); |
596 test_KErrNone(r); |
589 test(r==KErrNone); |
597 r=TheFs.SetDriveName(17,drive17); |
590 r=TheFs.SetDriveName(17,drive17); |
598 test_KErrNone(r); |
591 test(r==KErrNone); |
599 r=TheFs.SetDriveName(25,drive25); |
592 r=TheFs.SetDriveName(25,drive25); |
600 test_KErrNone(r); |
593 test(r==KErrNone); |
601 |
594 |
602 r=TheFs.GetDriveName(0,driveName); |
595 r=TheFs.GetDriveName(0,driveName); |
603 test_KErrNone(r); |
596 test(r==KErrNone); |
604 test(driveName==drive0); |
597 test(driveName==drive0); |
605 r=TheFs.GetDriveName(4,driveName); |
598 r=TheFs.GetDriveName(4,driveName); |
606 test_KErrNone(r); |
599 test(r==KErrNone); |
607 test(driveName==drive4); |
600 test(driveName==drive4); |
608 r=TheFs.GetDriveName(17,driveName); |
601 r=TheFs.GetDriveName(17,driveName); |
609 test_KErrNone(r); |
602 test(r==KErrNone); |
610 test(driveName==drive17); |
603 test(driveName==drive17); |
611 r=TheFs.GetDriveName(25,driveName); |
604 r=TheFs.GetDriveName(25,driveName); |
612 test_KErrNone(r); |
605 test(r==KErrNone); |
613 test(driveName==drive25); |
606 test(driveName==drive25); |
614 |
607 |
615 drive0=_L("askdjflsdfourewoqiuroiuaksjdvx,cvsdhwjhjhalsjhfshfkjhslj"); |
608 drive0=_L("askdjflsdfourewoqiuroiuaksjdvx,cvsdhwjhjhalsjhfshfkjhslj"); |
616 r=TheFs.SetDriveName(0,drive0); |
609 r=TheFs.SetDriveName(0,drive0); |
617 test_KErrNone(r); |
610 test(r==KErrNone); |
618 r=TheFs.GetDriveName(0,driveName); |
611 r=TheFs.GetDriveName(0,driveName); |
619 test_KErrNone(r); |
612 test(r==KErrNone); |
620 test(driveName==drive0); |
613 test(driveName==drive0); |
621 |
614 |
622 // Test with illegal characters in drive name |
615 // Test with illegal characters in drive name |
623 drive0=_L("Dil>bert"); |
616 drive0=_L("Dil>bert"); |
624 drive4=_L("Dog?bert"); |
617 drive4=_L("Dog?bert"); |
625 drive17=_L("Fli*bble"); |
618 drive17=_L("Fli*bble"); |
626 drive25=_L("RAMD//RIVE"); |
619 drive25=_L("RAMD//RIVE"); |
627 |
620 |
628 r=TheFs.SetDriveName(0,drive0); |
621 r=TheFs.SetDriveName(0,drive0); |
629 test_Value(r, r == KErrBadName); |
622 test(r==KErrBadName); |
630 r=TheFs.SetDriveName(4,drive4); |
623 r=TheFs.SetDriveName(4,drive4); |
631 test_Value(r, r == KErrBadName); |
624 test(r==KErrBadName); |
632 r=TheFs.SetDriveName(17,drive17); |
625 r=TheFs.SetDriveName(17,drive17); |
633 test_Value(r, r == KErrBadName); |
626 test(r==KErrBadName); |
634 r=TheFs.SetDriveName(25,drive25); |
627 r=TheFs.SetDriveName(25,drive25); |
635 test_Value(r, r == KErrBadName); |
628 test(r==KErrBadName); |
636 |
629 |
637 // Test that it is OK to set the name to no characters |
630 // Test that it is OK to set the name to no characters |
638 |
631 |
639 drive0=_L(""); |
632 drive0=_L(""); |
640 drive4=_L(""); |
633 drive4=_L(""); |
641 drive17=_L(""); |
634 drive17=_L(""); |
642 drive25=_L(""); |
635 drive25=_L(""); |
643 |
636 |
644 r=TheFs.SetDriveName(0,drive0); |
637 r=TheFs.SetDriveName(0,drive0); |
645 test_KErrNone(r); |
638 test(r==KErrNone); |
646 r=TheFs.SetDriveName(4,drive4); |
639 r=TheFs.SetDriveName(4,drive4); |
647 test_KErrNone(r); |
640 test(r==KErrNone); |
648 r=TheFs.SetDriveName(17,drive17); |
641 r=TheFs.SetDriveName(17,drive17); |
649 test_KErrNone(r); |
642 test(r==KErrNone); |
650 r=TheFs.SetDriveName(25,drive25); |
643 r=TheFs.SetDriveName(25,drive25); |
651 test_KErrNone(r); |
644 test(r==KErrNone); |
652 |
645 |
653 r=TheFs.GetDriveName(0,driveName); |
646 r=TheFs.GetDriveName(0,driveName); |
654 test_KErrNone(r); |
647 test(r==KErrNone); |
655 test(driveName==drive0); |
648 test(driveName==drive0); |
656 r=TheFs.GetDriveName(4,driveName); |
649 r=TheFs.GetDriveName(4,driveName); |
657 test_KErrNone(r); |
650 test(r==KErrNone); |
658 test(driveName==drive4); |
651 test(driveName==drive4); |
659 r=TheFs.GetDriveName(17,driveName); |
652 r=TheFs.GetDriveName(17,driveName); |
660 test_KErrNone(r); |
653 test(r==KErrNone); |
661 test(driveName==drive17); |
654 test(driveName==drive17); |
662 r=TheFs.GetDriveName(25,driveName); |
655 r=TheFs.GetDriveName(25,driveName); |
663 test_KErrNone(r); |
656 test(r==KErrNone); |
664 test(driveName==drive25); |
657 test(driveName==drive25); |
665 |
658 |
666 |
659 |
667 } |
660 } |
668 |
661 |
669 static void Test11() |
662 LOCAL_C void Test11() |
670 // |
663 // |
671 // Miscellaneous tests |
664 // Miscellaneous tests |
672 // |
665 // |
673 { |
666 { |
674 |
667 |
675 test.Next(_L("Miscellaneous tests")); |
668 test.Next(_L("Miscellaneous tests")); |
676 TVolumeInfo vol; |
669 TVolumeInfo vol; |
677 TInt r=TheFs.Volume(vol); |
670 TInt r=TheFs.Volume(vol); |
678 test.Printf(_L("VolumeName = %S\n"),&vol.iName); |
671 test.Printf(_L("VolumeName = %S\n"),&vol.iName); |
679 test_KErrNone(r); |
672 test(r==KErrNone); |
680 r=TheFs.RmDir(_L("\\asdfasdf.\\")); |
673 r=TheFs.RmDir(_L("\\asdfasdf.\\")); |
681 test_Value(r, r == KErrBadName); |
674 test(r==KErrBadName); |
682 r=TheFs.MkDir(_L("\\asdfasdf.\\")); |
675 r=TheFs.MkDir(_L("\\asdfasdf.\\")); |
683 test_Value(r, r == KErrBadName); |
676 test(r==KErrBadName); |
684 } |
677 } |
685 |
678 |
686 static void Test12() |
679 LOCAL_C void Test12() |
687 // |
680 // |
688 // Test SetNotifyUser and GetNotifyUser |
681 // Test SetNotifyUser and GetNotifyUser |
689 // |
682 // |
690 { |
683 { |
691 |
684 |
700 TheFs.SetNotifyUser(notifyState); |
693 TheFs.SetNotifyUser(notifyState); |
701 notifyState=TheFs.GetNotifyUser(); |
694 notifyState=TheFs.GetNotifyUser(); |
702 test(notifyState); |
695 test(notifyState); |
703 } |
696 } |
704 |
697 |
705 static void Test13() |
698 LOCAL_C void Test13() |
706 // |
699 // |
707 // Test return values from RFs::Volume on cf-cards |
700 // Test return values from RFs::Volume on cf-cards |
708 // |
701 // |
709 { |
702 { |
710 |
703 |
711 test.Next(_L("Test RFs::Volume")); |
704 test.Next(_L("Test RFs::Volume")); |
712 TVolumeInfo vol; |
705 TVolumeInfo vol; |
713 TInt r=TheFs.Volume(vol,EDriveB); |
706 TInt r=TheFs.Volume(vol,EDriveB); |
714 test_Value(r, r == KErrNotReady || r==KErrNone || r == KErrPathNotFound); |
707 test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); |
715 test.Printf(_L("RFs::Volume EDriveB returned %d\n"),r); |
708 test.Printf(_L("RFs::Volume EDriveB returned %d\n"),r); |
716 |
709 |
717 r=TheFs.Volume(vol,EDriveC); |
710 r=TheFs.Volume(vol,EDriveC); |
718 test_Value(r, r == KErrNotReady || r==KErrNone || r == KErrPathNotFound); |
711 test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); |
719 test.Printf(_L("RFs::Volume EDriveC returned %d\n"),r); |
712 test.Printf(_L("RFs::Volume EDriveC returned %d\n"),r); |
720 |
713 |
721 r=TheFs.Volume(vol,EDriveD); |
714 r=TheFs.Volume(vol,EDriveD); |
722 test_Value(r, r == KErrNotReady || r==KErrNone || r == KErrPathNotFound); |
715 test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); |
723 test.Printf(_L("RFs::Volume EDriveD returned %d\n"),r); |
716 test.Printf(_L("RFs::Volume EDriveD returned %d\n"),r); |
724 |
717 |
725 r=TheFs.Volume(vol,EDriveE); |
718 r=TheFs.Volume(vol,EDriveE); |
726 test_Value(r, r == KErrNotReady || r==KErrNone || r == KErrPathNotFound); |
719 test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); |
727 test.Printf(_L("RFs::Volume EDriveE returned %d\n"),r); |
720 test.Printf(_L("RFs::Volume EDriveE returned %d\n"),r); |
728 |
721 |
729 r=TheFs.Volume(vol,EDriveF); |
722 r=TheFs.Volume(vol,EDriveF); |
730 test_Value(r, r == KErrNotReady || r==KErrNone || r == KErrPathNotFound); |
723 test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); |
731 test.Printf(_L("RFs::Volume EDriveF returned %d\n"),r); |
724 test.Printf(_L("RFs::Volume EDriveF returned %d\n"),r); |
732 } |
725 } |
733 |
726 |
734 |
727 |
735 void DoTest14(TInt aDrvNum); |
728 void DoTest14(TInt aDrvNum); |
736 TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize); |
729 TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize); |
|
730 TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize); |
737 TBool CheckFileContents(RFs& aFs, const TDesC& aFileName); |
731 TBool CheckFileContents(RFs& aFs, const TDesC& aFileName); |
738 #ifndef __NFE_MEDIA_DRIVER_PRESENT__ |
732 #ifndef __NFE_MEDIA_DRIVER_PRESENT__ |
739 TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0); |
733 TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0); |
740 #endif |
734 #endif |
741 |
735 |
742 /** |
736 /** |
743 Testing unallocated data initialization vulnerability in RFile |
737 Testing unallocated data initialization vulnerability in RFile |
744 This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag) |
738 This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag) |
745 e.g. XSR NAND |
739 e.g. XSR NAND |
746 */ |
740 */ |
747 static void Test14() |
741 LOCAL_C void Test14() |
748 { |
742 { |
|
743 TInt nRes; |
749 |
744 |
750 test.Next(_L("Testing unallocated data initialization vulnerability in RFile")); |
745 test.Next(_L("Testing unallocated data initialization vulnerability in RFile")); |
751 |
746 |
752 TDriveInfo driveInfo; |
747 TDriveList driveList; |
753 |
748 TDriveInfo driveInfo; |
754 //-- get drive info |
749 |
755 test(TheFs.Drive(driveInfo, gDriveNum) == KErrNone); |
750 //-- 1. get drives list |
756 |
751 nRes=TheFs.DriveList(driveList); |
757 const TBool bMediaSuitable = (driveInfo.iType == EMediaRam) || //-- RAM drives should be tested |
752 test(nRes == KErrNone); |
758 (driveInfo.iType == EMediaFlash) || //-- NOR FLASH drives should be tested |
753 |
759 (driveInfo.iType == EMediaNANDFlash && driveInfo.iMediaAtt & KMediaAttDeleteNotify); //-- NAND media with DeleteNotify support |
754 //-- 2. walk through all drives, performing the test only on suitable ones |
760 |
755 for (TInt drvNum=0; drvNum<KMaxDrives; ++drvNum) |
761 if(!bMediaSuitable) |
|
762 { |
756 { |
763 test.Printf(_L("This test can't be performed on this type of the media! Skipping.\n")); |
757 if(!driveList[drvNum]) |
764 return; |
758 continue; //-- skip unexisting drive |
765 } |
759 |
766 |
760 //-- get drive info |
767 DoTest14(gDriveNum); |
761 test(TheFs.Drive(driveInfo, drvNum) == KErrNone); |
|
762 |
|
763 //-- select a suitable drive for the testing. It shall be RAM drive, of FLASH but not removable |
|
764 //-- and not read only, if it is FLASH, it shall support "Delete Notify" facility |
|
765 switch(driveInfo.iType) |
|
766 { |
|
767 //-- RAM drive, OK |
|
768 case EMediaRam: |
|
769 break; |
|
770 |
|
771 //-- FLASH drive, OK |
|
772 case EMediaFlash: |
|
773 case EMediaNANDFlash: |
|
774 if(driveInfo.iMediaAtt & KMediaAttDeleteNotify) |
|
775 break; //-- this type of media shall support DeleteNotify flag, otherwise this test is inconsistent |
|
776 else continue; |
|
777 |
|
778 //break; //unreacable |
|
779 |
|
780 default: |
|
781 continue; |
|
782 }//switch(driveInfo.iType) |
|
783 |
|
784 if (driveInfo.iDriveAtt & KDriveAttSubsted) |
|
785 { |
|
786 // skip subst drives. |
|
787 continue; |
|
788 } |
|
789 |
|
790 TBool readOnly = driveInfo.iMediaAtt & KMediaAttWriteProtected; |
|
791 if(readOnly) |
|
792 continue; //-- nothing to do, can't create any file etc. |
|
793 |
|
794 //-- skip test on the emulator's C: drive, doesn't make any sense because |
|
795 //-- in this case we deal with WIN32 API and filesystem. |
|
796 #ifdef __WINS__ |
|
797 if(drvNum == 2) |
|
798 { |
|
799 test.Printf(_L("Skipping test on emulator's C: drive\n")); |
|
800 continue; |
|
801 } |
|
802 #endif |
|
803 |
|
804 DoTest14(drvNum); |
|
805 |
|
806 }// for (TInt drvNum=0; ... |
|
807 |
768 } |
808 } |
769 |
809 |
770 //-------------------------------------------------------- |
810 //-------------------------------------------------------- |
771 |
811 |
772 /** |
812 /** |
1326 } |
1392 } |
1327 |
1393 |
1328 return bRes; |
1394 return bRes; |
1329 } |
1395 } |
1330 |
1396 |
1331 //-------------------------------------------------------- |
1397 |
1332 /** |
1398 GLDEF_C void CallTestsL() |
1333 Check if the drive aDriveNo is finalised or not. |
1399 // |
1334 The "CleanShutDown" is obtained by QueryVolumeInfoExt API which is FS-agnostic. |
1400 // Call tests that may leave |
1335 |
1401 // |
1336 @param aDriveNo drive number to query. |
1402 { |
1337 @return ETrue if the drive if finalised |
1403 |
1338 */ |
|
1339 static TBool IsVolumeFinalised(TInt aDriveNo) |
|
1340 { |
|
1341 TInt nRes; |
|
1342 TPckgBuf<TBool> boolPckg; |
|
1343 |
|
1344 //-- 1. get "Finalised" state by using the API |
|
1345 nRes = TheFs.QueryVolumeInfoExt(aDriveNo, EIsDriveFinalised, boolPckg); |
|
1346 test_KErrNone(nRes); |
|
1347 |
|
1348 return boolPckg(); |
|
1349 } |
|
1350 |
|
1351 |
|
1352 //-------------------------------------------------------- |
|
1353 /** |
|
1354 This is a file system - agnostic test that verifies RFs::FinaliseDrive() API |
|
1355 There are also file system - specific tests that check similar functionallity (see t_mount for example) |
|
1356 |
|
1357 */ |
|
1358 void TestDriveFinalisation() |
|
1359 { |
|
1360 test.Next(_L("TestDriveFinalisation(). Testing RFs::FinaliseDrives() API\n")); |
|
1361 |
|
1362 |
|
1363 if((!Is_Fat(TheFs, gDriveNum) && !Is_ExFat(TheFs, gDriveNum)) || Is_Fat12(TheFs, gDriveNum) ) |
|
1364 { |
|
1365 test.Printf(_L("This test can't be performed on current file system, skipping.\n")); |
|
1366 return; |
|
1367 } |
|
1368 |
|
1369 TVolumeInfo v; |
|
1370 TInt nRes; |
|
1371 |
|
1372 nRes = TheFs.Volume(v); |
|
1373 test(nRes==KErrNone); |
|
1374 |
|
1375 if(v.iDrive.iMediaAtt & KMediaAttVariableSize) |
|
1376 { |
|
1377 test.Printf(_L("Skipping. RAM drive not tested.\n")); |
|
1378 return; |
|
1379 } |
|
1380 |
|
1381 |
|
1382 TBool bDriveFinalised; |
|
1383 |
|
1384 //============= 1. finalise the drive (RW mode) and check the result |
|
1385 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1386 test_KErrNone(nRes); |
|
1387 |
|
1388 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1389 test(bDriveFinalised); |
|
1390 |
|
1391 //-- 1.1 finalise the drive second time EFinal_RW -> EFinal_RW shall work |
|
1392 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1393 test_KErrNone(nRes); |
|
1394 |
|
1395 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1396 test(bDriveFinalised); |
|
1397 |
|
1398 //============= 2. create a file. Shall succeed (EFinal_RW), the volume shall become unfinalised |
|
1399 |
|
1400 RFile file; |
|
1401 _LIT(KFileName, "\\my_file1.dat"); |
|
1402 _LIT8(KSomeData, "this is some data"); |
|
1403 |
|
1404 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1405 test_KErrNone(nRes); |
|
1406 |
|
1407 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1408 test(!bDriveFinalised); //-- the volume has become "unfinalised" |
|
1409 |
|
1410 //---------------------------------------------------------------------------------- |
|
1411 //-- test volume finalisation with opened objects |
|
1412 |
|
1413 //-- 2.1 having opened files should be OK for volume finalisation |
|
1414 |
|
1415 //-- 2.1.1 RW finalisation; after the volume finalised it should be possible to write to the opened file |
|
1416 nRes = file.Open(TheFs, KFileName, EFileWrite | EFileWriteDirectIO); |
|
1417 test_KErrNone(nRes); |
|
1418 |
|
1419 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1420 test_KErrNone(nRes); |
|
1421 |
|
1422 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1423 test(bDriveFinalised); |
|
1424 |
|
1425 nRes = file.Write(0, KSomeData); |
|
1426 test_KErrNone(nRes); |
|
1427 |
|
1428 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1429 test(!bDriveFinalised); //-- the volume should become "unfinalised" |
|
1430 |
|
1431 //-- 2.1.2 RO finalisation; after the volume finalised it shouldn't be possible to write to the opened file |
|
1432 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RO); |
|
1433 test_KErrNone(nRes); |
|
1434 |
|
1435 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1436 test(bDriveFinalised); |
|
1437 |
|
1438 nRes = file.Write(0, KSomeData); |
|
1439 test(nRes == KErrAccessDenied); //-- no write access to the volume |
|
1440 |
|
1441 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1442 test(bDriveFinalised); //-- the volume should become "unfinalised" |
|
1443 |
|
1444 file.Close(); |
|
1445 |
|
1446 //-- remount FS, the drive shall become RW |
|
1447 nRes = RemountFS(TheFs, gDriveNum); |
|
1448 test_KErrNone(nRes); |
|
1449 |
|
1450 |
|
1451 //-- 2.2 having opened directories should be OK for volume finalisation |
|
1452 _LIT(KDirName, "\\Dir11235tt\\"); |
|
1453 MakeDir(KDirName); |
|
1454 RDir dir; |
|
1455 |
|
1456 //-- 2.2.1 RW finalisation; after the volume finalised it should be possible to have write access to it |
|
1457 nRes = dir.Open(TheFs, KDirName, KEntryAttNormal); |
|
1458 test_KErrNone(nRes); |
|
1459 |
|
1460 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1461 test_KErrNone(nRes); |
|
1462 |
|
1463 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1464 test(bDriveFinalised); |
|
1465 |
|
1466 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1467 test_KErrNone(nRes); |
|
1468 |
|
1469 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1470 test(!bDriveFinalised); |
|
1471 |
|
1472 //-- 2.1.2 RO finalisation; after the volume finalised it shouldn't be possible to write to it |
|
1473 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RO); |
|
1474 test_KErrNone(nRes); |
|
1475 |
|
1476 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1477 test(bDriveFinalised); |
|
1478 |
|
1479 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1480 test(nRes == KErrAccessDenied); //-- no write access to the volume |
|
1481 |
|
1482 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1483 test(bDriveFinalised); //-- the volume should become "unfinalised" |
|
1484 |
|
1485 dir.Close(); |
|
1486 |
|
1487 //-- remount FS, the drive shall become RW |
|
1488 nRes = RemountFS(TheFs, gDriveNum); |
|
1489 test_KErrNone(nRes); |
|
1490 |
|
1491 //-- 2.3 having opened disk access objects, like formats or raw disks makes finalisation impossible |
|
1492 RFormat format; |
|
1493 RRawDisk rawDisk; |
|
1494 TInt fmtCnt; |
|
1495 |
|
1496 //-- 2.3.1 format |
|
1497 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1498 test_KErrNone(nRes); |
|
1499 |
|
1500 nRes = format.Open(TheFs, gSessionPath, EFullFormat, fmtCnt); |
|
1501 test_KErrNone(nRes); |
|
1502 |
|
1503 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1504 test(nRes == KErrInUse); |
|
1505 |
|
1506 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RO); |
|
1507 test(nRes == KErrInUse); |
|
1508 |
|
1509 format.Close(); |
|
1510 |
|
1511 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1512 test_KErrNone(nRes); |
|
1513 |
|
1514 //-- 2.3.2 raw disk |
|
1515 nRes = rawDisk.Open(TheFs, gDriveNum); |
|
1516 test_KErrNone(nRes); |
|
1517 |
|
1518 |
|
1519 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1520 test(nRes == KErrInUse); |
|
1521 |
|
1522 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RO); |
|
1523 test(nRes == KErrInUse); |
|
1524 |
|
1525 rawDisk.Close(); |
|
1526 |
|
1527 //-- 2.4 Volume finalisation and file system dismounting |
|
1528 |
|
1529 //-- 2.4.1 "graceful" dismounting should finalise the drive correctly |
|
1530 |
|
1531 //-- "unfinalise the volume" |
|
1532 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1533 test_KErrNone(nRes); |
|
1534 |
|
1535 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1536 test(!bDriveFinalised); |
|
1537 |
|
1538 TFSDescriptor fsDesc; |
|
1539 nRes = GetFileSystemDescriptor(TheFs, gDriveNum, fsDesc); |
|
1540 test_KErrNone(nRes); |
|
1541 |
|
1542 //-- gracefully dismount the file system |
|
1543 nRes = TheFs.DismountFileSystem(fsDesc.iFsName, gDriveNum); |
|
1544 test_KErrNone(nRes); |
|
1545 |
|
1546 //-- mount it back |
|
1547 nRes = MountFileSystem(TheFs, gDriveNum, fsDesc); |
|
1548 test_KErrNone(nRes); |
|
1549 |
|
1550 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1551 test(bDriveFinalised); |
|
1552 |
|
1553 //-- 2.4.2 "forced" dismounting, usually happens when "graceful doesn't work, because there are files opened on the volume. |
|
1554 //-- Should also finalise the drive correctly |
|
1555 |
|
1556 //-- "unfinalise the volume" |
|
1557 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1558 test_KErrNone(nRes); |
|
1559 |
|
1560 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1561 test(!bDriveFinalised); |
|
1562 |
|
1563 //-- open a file on the volume, this will prevent graceful dismounting |
|
1564 nRes = file.Open(TheFs, KFileName, EFileWrite | EFileWriteDirectIO); |
|
1565 test_KErrNone(nRes); |
|
1566 |
|
1567 nRes = GetFileSystemDescriptor(TheFs, gDriveNum, fsDesc); |
|
1568 test_KErrNone(nRes); |
|
1569 |
|
1570 //-- try gracefully dismount the file system |
|
1571 nRes = TheFs.DismountFileSystem(fsDesc.iFsName, gDriveNum); |
|
1572 test(nRes == KErrInUse); //-- no luck, as expected |
|
1573 |
|
1574 //-- now do dismounting by force |
|
1575 TRequestStatus rqStat; |
|
1576 TheFs.NotifyDismount(gDriveNum, rqStat, EFsDismountForceDismount); |
|
1577 User::WaitForRequest(rqStat); |
|
1578 test_KErrNone(rqStat.Int()); |
|
1579 |
|
1580 nRes = file.Write(0, KSomeData); |
|
1581 test(nRes == KErrNotReady); |
|
1582 |
|
1583 file.Close(); |
|
1584 |
|
1585 //-- mount it back |
|
1586 nRes = MountFileSystem(TheFs, gDriveNum, fsDesc); |
|
1587 test_KErrNone(nRes); |
|
1588 |
|
1589 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1590 test(bDriveFinalised); |
|
1591 |
|
1592 //============= 3. test "unfinalise API" |
|
1593 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EForceUnfinalise); |
|
1594 test_KErrNone(nRes); |
|
1595 |
|
1596 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1597 test(!bDriveFinalised); //-- the volume has become "unfinalised" |
|
1598 |
|
1599 //============= 4. test finalisation into RO mode |
|
1600 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RO); //-- the volume becomes RO |
|
1601 test_KErrNone(nRes); |
|
1602 |
|
1603 //-- try to write a file on RO volume; it shall fail with KErrAccessDenied |
|
1604 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1605 test(nRes == KErrAccessDenied); |
|
1606 file.Close(); |
|
1607 |
|
1608 //-- 4.1 try to finalise into EFinal_RW mode, shall fail with KErrAccessDenied |
|
1609 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1610 test(nRes == KErrAccessDenied); |
|
1611 |
|
1612 //-- 4.2 "unfinalise" the volume, it still shall remain RO |
|
1613 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EForceUnfinalise); |
|
1614 test_KErrNone(nRes); |
|
1615 |
|
1616 //-- try to write a file on RO volume; it shall fail with KErrAccessDenied |
|
1617 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1618 test(nRes == KErrAccessDenied); |
|
1619 file.Close(); |
|
1620 |
|
1621 //-- remount FS, the drive shall become RW |
|
1622 nRes = RemountFS(TheFs, gDriveNum); |
|
1623 test_KErrNone(nRes); |
|
1624 |
|
1625 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1626 test(bDriveFinalised); |
|
1627 |
|
1628 //-- try to write a file on RW volume, shall be OK |
|
1629 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1630 test(nRes == KErrNone); |
|
1631 file.Close(); |
|
1632 |
|
1633 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1634 test(!bDriveFinalised); |
|
1635 |
|
1636 //============= 5. test various finalisation modes |
|
1637 |
|
1638 //-- 5.1 Not finalised -> EFinal_RW (KErrNone) |
|
1639 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1640 test(nRes == KErrNone); |
|
1641 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1642 test(bDriveFinalised); |
|
1643 |
|
1644 //-- 5.2 EFinal_RW -> EFinal_RO (KErrNone) |
|
1645 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RO); |
|
1646 test(nRes == KErrNone); |
|
1647 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1648 test(bDriveFinalised); |
|
1649 |
|
1650 //-- 5.2 EFinal_RO -> EFinal_RW (KErrAccessDenied) |
|
1651 nRes =TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW); |
|
1652 test(nRes == KErrAccessDenied); |
|
1653 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1654 test(bDriveFinalised); |
|
1655 |
|
1656 //-- 5.3 restore |
|
1657 nRes = RemountFS(TheFs, gDriveNum); |
|
1658 test_KErrNone(nRes); |
|
1659 |
|
1660 |
|
1661 //============= 6. test old RFs::FinaliseDrives API |
|
1662 |
|
1663 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1664 test(nRes == KErrNone); |
|
1665 |
|
1666 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1667 test(!bDriveFinalised); |
|
1668 |
|
1669 TheFs.FinaliseDrives(); //-- shall work as TheFs.FinaliseDrive(gDriveNum, RFs::EFinal_RW) but for ALL drives |
|
1670 |
|
1671 bDriveFinalised = IsVolumeFinalised(gDriveNum); |
|
1672 test(bDriveFinalised); |
|
1673 |
|
1674 nRes = CreateEmptyFile(TheFs, KFileName, 128000); |
|
1675 test(nRes == KErrNone); |
|
1676 |
|
1677 |
|
1678 |
|
1679 } |
|
1680 |
|
1681 |
|
1682 void CallTestsL() |
|
1683 { |
|
1684 //-- set up console output |
|
1685 F32_Test_Utils::SetConsole(test.Console()); |
|
1686 |
|
1687 TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum); |
|
1688 test_KErrNone(nRes); |
|
1689 |
|
1690 PrintDrvInfo(TheFs, gDriveNum); |
|
1691 |
|
1692 TestDriveFinalisation(); |
|
1693 Test1(); |
1404 Test1(); |
1694 Test2(); |
1405 Test2(); |
1695 Test3(); |
1406 Test3(); |
1696 Test4(); |
1407 Test4(); |
1697 Test5(); |
1408 Test5(); |