45 Test the file info function |
46 Test the file info function |
46 */ |
47 */ |
47 { |
48 { |
48 TEntry entry; |
49 TEntry entry; |
49 TInt r=TheFs.Entry(noDevice,entry); |
50 TInt r=TheFs.Entry(noDevice,entry); |
50 test((r==KErrNotReady)||(r==KErrPathNotFound)); |
51 test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound)); |
51 r=TheFs.Entry(noDirectory,entry); |
52 r=TheFs.Entry(noDirectory,entry); |
52 test(r==KErrPathNotFound); |
53 test_Value(r, r == KErrPathNotFound); |
53 r=TheFs.Entry(noFile,entry); |
54 r=TheFs.Entry(noFile,entry); |
54 test(r==KErrNotFound); |
55 test_Value(r, r == KErrNotFound); |
55 r=TheFs.Entry(existsFile,entry); |
56 r=TheFs.Entry(existsFile,entry); |
56 test(r==KErrNone); |
57 test_KErrNone(r); |
57 test(entry.iSize==KSizeExistsFile); |
58 test(entry.iSize==KSizeExistsFile); |
58 test(!entry.IsDir()); |
59 test(!entry.IsDir()); |
59 test(!(entry.iAtt&KEntryAttDir)); |
60 test(!(entry.iAtt&KEntryAttDir)); |
60 r=TheFs.Entry(existsFile2,entry); |
61 r=TheFs.Entry(existsFile2,entry); |
61 test(r==KErrNone); |
62 test_KErrNone(r); |
62 test(entry.iSize==KSizeExistsFile2); |
63 test(entry.iSize==KSizeExistsFile2); |
63 test(!entry.IsDir()); |
64 test(!entry.IsDir()); |
64 test(!(entry.iAtt&KEntryAttDir)); |
65 test(!(entry.iAtt&KEntryAttDir)); |
65 } |
66 } |
66 |
67 |
68 /* |
69 /* |
69 Test the delete |
70 Test the delete |
70 */ |
71 */ |
71 { |
72 { |
72 TInt r=TheFs.Delete(noDevice); |
73 TInt r=TheFs.Delete(noDevice); |
73 test((r==KErrNotReady)||(r==KErrPathNotFound)); |
74 test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound)); |
74 r=TheFs.Delete(noDirectory); |
75 r=TheFs.Delete(noDirectory); |
75 test(r==KErrPathNotFound); |
76 test_Value(r, r == KErrPathNotFound); |
76 r=TheFs.Delete(noFile); |
77 r=TheFs.Delete(noFile); |
77 test(r==KErrNotFound); |
78 test_Value(r, r == KErrNotFound); |
78 r=TheFs.Delete(existsFile); |
79 r=TheFs.Delete(existsFile); |
79 test(r==KErrNone); |
80 test_KErrNone(r); |
80 r=TheFs.Delete(existsFile2); |
81 r=TheFs.Delete(existsFile2); |
81 test(r==KErrNone); |
82 test_KErrNone(r); |
82 TEntry entry; |
83 TEntry entry; |
83 r=TheFs.Entry(existsFile,entry); |
84 r=TheFs.Entry(existsFile,entry); |
84 test(r==KErrNotFound); |
85 test_Value(r, r == KErrNotFound); |
85 r=TheFs.Entry(existsFile2,entry); |
86 r=TheFs.Entry(existsFile2,entry); |
86 test(r==KErrNotFound); |
87 test_Value(r, r == KErrNotFound); |
87 } |
88 } |
88 |
89 |
89 LOCAL_C void TestRename() |
90 LOCAL_C void TestRename() |
90 /* |
91 /* |
91 Test the rename |
92 Test the rename |
92 */ |
93 */ |
93 { |
94 { |
94 TInt r=TheFs.Rename(noDevice,fileName); |
95 TInt r=TheFs.Rename(noDevice,fileName); |
95 test(r==KErrArgument); |
96 test_Value(r, r == KErrArgument); |
96 r=TheFs.Rename(noDirectory,fileName); |
97 r=TheFs.Rename(noDirectory,fileName); |
97 test(r==KErrPathNotFound); |
98 test_Value(r, r == KErrPathNotFound); |
98 r=TheFs.Rename(noFile,fileName); |
99 r=TheFs.Rename(noFile,fileName); |
99 test(r==KErrNotFound); |
100 test_Value(r, r == KErrNotFound); |
100 r=TheFs.Rename(existsFile,existsFile2); |
101 r=TheFs.Rename(existsFile,existsFile2); |
101 test(r==KErrAlreadyExists); |
102 test_Value(r, r == KErrAlreadyExists); |
102 r=TheFs.Delete(existsFile); |
103 r=TheFs.Delete(existsFile); |
103 test(r==KErrNone); |
104 test_KErrNone(r); |
104 r=TheFs.Rename(existsFile,existsFile); |
105 r=TheFs.Rename(existsFile,existsFile); |
105 test(r==KErrNotFound); |
106 test_Value(r, r == KErrNotFound); |
106 r=TheFs.Rename(existsFile2,existsFile); |
107 r=TheFs.Rename(existsFile2,existsFile); |
107 test(r==KErrNone); |
108 test_KErrNone(r); |
108 TEntry entry; |
109 TEntry entry; |
109 r=TheFs.Entry(existsFile2,entry); |
110 r=TheFs.Entry(existsFile2,entry); |
110 test(r==KErrNotFound); |
111 test_Value(r, r == KErrNotFound); |
111 r=TheFs.Entry(existsFile,entry); |
112 r=TheFs.Entry(existsFile,entry); |
112 test(r==KErrNone); |
113 test_KErrNone(r); |
113 r=TheFs.Delete(existsFile); |
114 r=TheFs.Delete(existsFile); |
114 test(r==KErrNone); |
115 test_KErrNone(r); |
115 } |
116 } |
116 |
117 |
117 LOCAL_C void TestMkDir() |
118 LOCAL_C void TestMkDir() |
118 { |
119 { |
119 TParse fparse; |
120 TParse fparse; |
120 TInt r=TheFs.MkDirAll(directoryFile); |
121 TInt r=TheFs.MkDirAll(directoryFile); |
121 test(r==KErrNone); |
122 test_KErrNone(r); |
122 TEntry entry; |
123 TEntry entry; |
123 r=TheFs.Entry(directoryFile.Left(directoryFile.Length()-1),entry); |
124 r=TheFs.Entry(directoryFile.Left(directoryFile.Length()-1),entry); |
124 test(r==KErrNone); |
125 test_KErrNone(r); |
125 test(entry.IsDir()); |
126 test(entry.IsDir()); |
126 test(entry.iAtt&KEntryAttDir); |
127 test(entry.iAtt&KEntryAttDir); |
127 r=TheFs.RmDir(directoryFile); |
128 r=TheFs.RmDir(directoryFile); |
128 test(r==KErrNone); |
129 test_KErrNone(r); |
129 r=fparse.Set(directoryFile,NULL,NULL); |
130 r=fparse.Set(directoryFile,NULL,NULL); |
130 test(r==KErrNone); |
131 test_KErrNone(r); |
131 r=fparse.PopDir(); |
132 r=fparse.PopDir(); |
132 test(r==KErrNone); |
133 test_KErrNone(r); |
133 r=TheFs.RmDir(fparse.DriveAndPath()); |
134 r=TheFs.RmDir(fparse.DriveAndPath()); |
134 test(r==KErrNone); |
135 test_KErrNone(r); |
135 r=fparse.PopDir(); |
136 r=fparse.PopDir(); |
136 test(r==KErrNone); |
137 test_KErrNone(r); |
137 r=TheFs.RmDir(fparse.DriveAndPath()); |
138 r=TheFs.RmDir(fparse.DriveAndPath()); |
138 test(r==KErrNone); |
139 test_KErrNone(r); |
139 } |
140 } |
140 |
141 |
141 |
142 |
142 LOCAL_C void TestOpenUnique() |
143 LOCAL_C void TestOpenUnique() |
143 /* |
144 /* |
146 { |
147 { |
147 RFile p1; |
148 RFile p1; |
148 RFile p2; |
149 RFile p2; |
149 |
150 |
150 TInt r=p1.Open(TheFs,noDevice,EFileStreamText); |
151 TInt r=p1.Open(TheFs,noDevice,EFileStreamText); |
151 test((r==KErrNotReady)||(r==KErrPathNotFound)); |
152 test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound)); |
152 r=p1.Open(TheFs,noDirectory,EFileStreamText); |
153 r=p1.Open(TheFs,noDirectory,EFileStreamText); |
153 test(r==KErrPathNotFound); |
154 test_Value(r, r == KErrPathNotFound); |
154 TFileName generated1; |
155 TFileName generated1; |
155 r=p1.Temp(TheFs,noDevicePath,generated1,EFileStreamText); |
156 r=p1.Temp(TheFs,noDevicePath,generated1,EFileStreamText); |
156 test((r==KErrNotReady)||(r==KErrPathNotFound)); |
157 test_Value(r, (r == KErrNotReady)||(r==KErrPathNotFound)); |
157 r=p1.Temp(TheFs,noDirectoryPath,generated1,EFileStreamText); |
158 r=p1.Temp(TheFs,noDirectoryPath,generated1,EFileStreamText); |
158 test(r==KErrPathNotFound); |
159 test_Value(r, r == KErrPathNotFound); |
159 |
160 |
160 r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText); |
161 r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText); |
161 test(r==KErrNone); |
162 test_KErrNone(r); |
162 TFileName generated2; |
163 TFileName generated2; |
163 r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText); |
164 r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText); |
164 test(r==KErrNone); |
165 test_KErrNone(r); |
165 test(generated1!=generated2); |
166 test(generated1!=generated2); |
166 p1.Close(); |
167 p1.Close(); |
167 TFileName generated3; |
168 TFileName generated3; |
168 r=p1.Temp(TheFs,_L(""),generated3,EFileStream); |
169 r=p1.Temp(TheFs,_L(""),generated3,EFileStream); |
169 test(r==KErrNone); |
170 test_KErrNone(r); |
170 test(generated3!=generated2); |
171 test(generated3!=generated2); |
171 test(generated3!=generated1); |
172 test(generated3!=generated1); |
172 p2.Close(); |
173 p2.Close(); |
173 p1.Close(); |
174 p1.Close(); |
174 |
175 |
175 r=TheFs.Delete(generated1); |
176 r=TheFs.Delete(generated1); |
176 test(r==KErrNone); |
177 test_KErrNone(r); |
177 r=TheFs.Delete(generated2); |
178 r=TheFs.Delete(generated2); |
178 test(r==KErrNone); |
179 test_KErrNone(r); |
179 r=TheFs.Delete(generated3); |
180 r=TheFs.Delete(generated3); |
180 test(r==KErrNone); |
181 test_KErrNone(r); |
181 |
182 |
182 r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText); |
183 r=p1.Temp(TheFs,_L(""),generated1,EFileStreamText); |
183 test(r==KErrNone); |
184 test_KErrNone(r); |
184 r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText); |
185 r=p2.Temp(TheFs,_L(""),generated2,EFileStreamText); |
185 test(r==KErrNone); |
186 test_KErrNone(r); |
186 test(generated1!=generated2); |
187 test(generated1!=generated2); |
187 p1.Close(); |
188 p1.Close(); |
188 r=p1.Temp(TheFs,_L(""),generated3,EFileStream); |
189 r=p1.Temp(TheFs,_L(""),generated3,EFileStream); |
189 test(r==KErrNone); |
190 test_KErrNone(r); |
190 test(generated3!=generated2); |
191 test(generated3!=generated2); |
191 test(generated3!=generated1); |
192 test(generated3!=generated1); |
192 p2.Close(); |
193 p2.Close(); |
193 p1.Close(); |
194 p1.Close(); |
194 |
195 |
195 r=TheFs.Delete(generated1); |
196 r=TheFs.Delete(generated1); |
196 test(r==KErrNone); |
197 test_KErrNone(r); |
197 r=TheFs.Delete(generated2); |
198 r=TheFs.Delete(generated2); |
198 test(r==KErrNone); |
199 test_KErrNone(r); |
199 r=TheFs.Delete(generated3); |
200 r=TheFs.Delete(generated3); |
200 test(r==KErrNone); |
201 test_KErrNone(r); |
201 |
202 |
202 r=TheFs.MkDir(openUniqueDir); |
203 r=TheFs.MkDir(openUniqueDir); |
203 test(r==KErrNone); |
204 test_KErrNone(r); |
204 r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream); |
205 r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream); |
205 test(r==KErrNone); |
206 test_KErrNone(r); |
206 r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText|EFileWrite); |
207 r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText|EFileWrite); |
207 test(r==KErrNone); |
208 test_KErrNone(r); |
208 r=p1.Write(_L8("junk"),4); |
209 r=p1.Write(_L8("junk"),4); |
209 test(r==KErrNone); |
210 test_KErrNone(r); |
210 TInt pos=0; |
211 TInt pos=0; |
211 r=p1.Seek(ESeekCurrent,pos);//P_FSET |
212 r=p1.Seek(ESeekCurrent,pos);//P_FSET |
212 test(r==KErrNone); |
213 test_KErrNone(r); |
213 p1.Close(); |
214 p1.Close(); |
214 p2.Close(); |
215 p2.Close(); |
215 |
216 |
216 r=TheFs.Delete(generated1); |
217 r=TheFs.Delete(generated1); |
217 test(r==KErrNone); |
218 test_KErrNone(r); |
218 r=TheFs.Delete(generated2); |
219 r=TheFs.Delete(generated2); |
219 test(r==KErrNone); |
220 test_KErrNone(r); |
220 |
221 |
221 r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream); |
222 r=p1.Temp(TheFs,openUniqueDir,generated1,EFileStream); |
222 test(r==KErrNone); |
223 test_KErrNone(r); |
223 r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText); |
224 r=p2.Temp(TheFs,openUniqueDir,generated2,EFileStreamText); |
224 test(r==KErrNone); |
225 test_KErrNone(r); |
225 p1.Close(); |
226 p1.Close(); |
226 |
227 |
227 pos=0; |
228 pos=0; |
228 r=p2.Seek(ESeekStart,pos); |
229 r=p2.Seek(ESeekStart,pos); |
229 test(r==KErrNone); |
230 test_KErrNone(r); |
230 p2.Close(); |
231 p2.Close(); |
231 r=TheFs.Delete(generated1); |
232 r=TheFs.Delete(generated1); |
232 test(r==KErrNone); |
233 test_KErrNone(r); |
233 r=TheFs.Delete(generated2); |
234 r=TheFs.Delete(generated2); |
234 test(r==KErrNone); |
235 test_KErrNone(r); |
235 r=TheFs.RmDir(openUniqueDir); |
236 r=TheFs.RmDir(openUniqueDir); |
236 test(r==KErrNone); |
237 test_KErrNone(r); |
237 } |
238 } |
238 |
239 |
239 LOCAL_C void TestPaths() |
240 LOCAL_C void TestPaths() |
240 { |
241 { |
241 TFileName path1; |
242 TFileName path1; |
242 TInt r=TheFs.SessionPath(path1); |
243 TInt r=TheFs.SessionPath(path1); |
243 test(r==KErrNone); |
244 test_KErrNone(r); |
244 r=TheFs.SetSessionPath(path1); |
245 r=TheFs.SetSessionPath(path1); |
245 test(r==KErrNone); |
246 test_KErrNone(r); |
246 TFileName path2; |
247 TFileName path2; |
247 r=TheFs.SessionPath(path2); |
248 r=TheFs.SessionPath(path2); |
248 test(r==KErrNone); |
249 test_KErrNone(r); |
249 test(path1==path2); |
250 test(path1==path2); |
250 RDir dir; |
251 RDir dir; |
251 r=dir.Open(TheFs,path1,0); |
252 r=dir.Open(TheFs,path1,0); |
252 test(r==KErrNone); |
253 test_KErrNone(r); |
253 dir.Close(); |
254 dir.Close(); |
254 } |
255 } |
255 |
256 |
256 LOCAL_C void TestFileStatus() |
257 LOCAL_C void TestFileStatus() |
257 { |
258 { |
258 TEntry blk; |
259 TEntry blk; |
259 TInt r=TheFs.Entry(existsFile,blk); |
260 TInt r=TheFs.Entry(existsFile,blk); |
260 test(r==KErrNone); |
261 test_KErrNone(r); |
261 TEntry blk1=blk; |
262 TEntry blk1=blk; |
262 |
263 |
263 /* Toggle the write attribute */ |
264 /* Toggle the write attribute */ |
264 TUint clear,set; /* were modifying write attrib */ |
265 TUint clear,set; /* were modifying write attrib */ |
265 if (blk1.IsReadOnly()) |
266 if (blk1.IsReadOnly()) |
271 { |
272 { |
272 clear=0; |
273 clear=0; |
273 set=KEntryAttReadOnly; |
274 set=KEntryAttReadOnly; |
274 } |
275 } |
275 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); |
276 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); |
276 test(r==KErrNone); |
277 test_KErrNone(r); |
277 r=TheFs.Entry(existsFile,blk); |
278 r=TheFs.Entry(existsFile,blk); |
278 test(r==KErrNone); |
279 test_KErrNone(r); |
279 if (blk1.IsReadOnly()) |
280 if (blk1.IsReadOnly()) |
280 test(!blk.IsReadOnly()); |
281 test(!blk.IsReadOnly()); |
281 else |
282 else |
282 test(blk.IsReadOnly()); |
283 test(blk.IsReadOnly()); |
283 |
284 |
284 /* set write attrib back */ |
285 /* set write attrib back */ |
285 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); |
286 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); |
286 test(r==KErrNone); |
287 test_KErrNone(r); |
287 r=TheFs.Entry(existsFile,blk); |
288 r=TheFs.Entry(existsFile,blk); |
288 test(r==KErrNone); |
289 test_KErrNone(r); |
289 if (blk1.IsReadOnly()) |
290 if (blk1.IsReadOnly()) |
290 test(blk.IsReadOnly()); |
291 test(blk.IsReadOnly()); |
291 else |
292 else |
292 test(!blk.IsReadOnly()); |
293 test(!blk.IsReadOnly()); |
293 |
294 |
301 { |
302 { |
302 clear=0; |
303 clear=0; |
303 set=KEntryAttArchive; |
304 set=KEntryAttArchive; |
304 } |
305 } |
305 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); |
306 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); |
306 test(r==KErrNone); |
307 test_KErrNone(r); |
307 r=TheFs.Entry(existsFile,blk); |
308 r=TheFs.Entry(existsFile,blk); |
308 test(r==KErrNone); |
309 test_KErrNone(r); |
309 if (blk1.IsArchive()) |
310 if (blk1.IsArchive()) |
310 test(!blk.IsArchive()); |
311 test(!blk.IsArchive()); |
311 else |
312 else |
312 test(blk.IsArchive()); |
313 test(blk.IsArchive()); |
313 /* set archive attrib back */ |
314 /* set archive attrib back */ |
314 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); |
315 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); |
315 test(r==KErrNone); |
316 test_KErrNone(r); |
316 r=TheFs.Entry(existsFile,blk); |
317 r=TheFs.Entry(existsFile,blk); |
317 test(r==KErrNone); |
318 test_KErrNone(r); |
318 if (blk1.IsArchive()) |
319 if (blk1.IsArchive()) |
319 test(blk.IsArchive()); |
320 test(blk.IsArchive()); |
320 else |
321 else |
321 test(!blk.IsArchive()); |
322 test(!blk.IsArchive()); |
322 |
323 |
359 { |
360 { |
360 clear=0; |
361 clear=0; |
361 set=KEntryAttSystem; |
362 set=KEntryAttSystem; |
362 } |
363 } |
363 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); |
364 r=TheFs.SetEntry(existsFile,blk1.iModified,set,clear); |
364 test(r==KErrNone); |
365 test_KErrNone(r); |
365 r=TheFs.Entry(existsFile,blk); |
366 r=TheFs.Entry(existsFile,blk); |
366 test(r==KErrNone); |
367 test_KErrNone(r); |
367 if (blk1.IsSystem()) |
368 if (blk1.IsSystem()) |
368 test(!blk.IsSystem()); |
369 test(!blk.IsSystem()); |
369 else |
370 else |
370 test(blk.IsSystem()); |
371 test(blk.IsSystem()); |
371 /* set system attrib back */ |
372 /* set system attrib back */ |
372 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); |
373 r=TheFs.SetEntry(existsFile,blk1.iModified,clear,set); |
373 test(r==KErrNone); |
374 test_KErrNone(r); |
374 r=TheFs.Entry(existsFile,blk); |
375 r=TheFs.Entry(existsFile,blk); |
375 test(r==KErrNone); |
376 test_KErrNone(r); |
376 if (blk1.IsSystem()) |
377 if (blk1.IsSystem()) |
377 test(blk.IsSystem()); |
378 test(blk.IsSystem()); |
378 else |
379 else |
379 test(!blk.IsSystem()); |
380 test(!blk.IsSystem()); |
380 r=TheFs.Delete(existsFile); |
381 r=TheFs.Delete(existsFile); |
381 test(r==KErrNone); |
382 test_KErrNone(r); |
382 r=TheFs.Delete(existsFile2); |
383 r=TheFs.Delete(existsFile2); |
383 test(r==KErrNone); |
384 test_KErrNone(r); |
384 } |
385 } |
385 |
386 |
386 |
387 |
387 LOCAL_C void CreateTestFiles() |
388 LOCAL_C void CreateTestFiles() |
388 { |
389 { |
389 RFile fcb; |
390 RFile fcb; |
390 TInt r=fcb.Replace(TheFs,existsFile,EFileWrite); |
391 TInt r=fcb.Replace(TheFs,existsFile,EFileWrite); |
391 test(r==KErrNone); |
392 test_KErrNone(r); |
392 r=fcb.Write(_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),KSizeExistsFile); |
393 r=fcb.Write(_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),KSizeExistsFile); |
393 test(r==KErrNone); |
394 test_KErrNone(r); |
394 fcb.Close(); |
395 fcb.Close(); |
395 |
396 |
396 r=fcb.Replace(TheFs,existsFile2,EFileWrite); |
397 r=fcb.Replace(TheFs,existsFile2,EFileWrite); |
397 test(r==KErrNone); |
398 test_KErrNone(r); |
398 r=fcb.Write(_L8("bcdefghijklmnopqrstuvwxyz"),KSizeExistsFile2); |
399 r=fcb.Write(_L8("bcdefghijklmnopqrstuvwxyz"),KSizeExistsFile2); |
399 test(r==KErrNone); |
400 test_KErrNone(r); |
400 fcb.Close(); |
401 fcb.Close(); |
401 } |
402 } |
402 |
403 |
403 GLDEF_C void CallTestsL(void) |
404 GLDEF_C void CallTestsL(void) |
404 // |
405 // |