sl@0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\server\t_misc.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <f32file.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include "t_server.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
#ifdef __VC32__
|
sl@0
|
23 |
// Solve compilation problem caused by non-English locale
|
sl@0
|
24 |
#pragma setlocale("english")
|
sl@0
|
25 |
#endif
|
sl@0
|
26 |
|
sl@0
|
27 |
GLDEF_D RTest test(_L("T_MISC"));
|
sl@0
|
28 |
|
sl@0
|
29 |
LOCAL_C void Test1()
|
sl@0
|
30 |
//
|
sl@0
|
31 |
// Open, write to and read from a file
|
sl@0
|
32 |
//
|
sl@0
|
33 |
{
|
sl@0
|
34 |
|
sl@0
|
35 |
test.Next(_L("Open, write to and read from a file"));
|
sl@0
|
36 |
TInt r=TheFs.SetSessionPath(gSessionPath);
|
sl@0
|
37 |
test(r==KErrNone);
|
sl@0
|
38 |
RFile file;
|
sl@0
|
39 |
r=file.Create(TheFs,_L("Hello.Wld"),EFileWrite);
|
sl@0
|
40 |
test(r==KErrNone);
|
sl@0
|
41 |
r=file.Write(_L8("Hello World"),11);
|
sl@0
|
42 |
test(r==KErrNone);
|
sl@0
|
43 |
file.Close();
|
sl@0
|
44 |
|
sl@0
|
45 |
r=file.Open(TheFs,_L("Hello.Wld"),EFileRead);
|
sl@0
|
46 |
test(r==KErrNone);
|
sl@0
|
47 |
TBuf8<256> buf;
|
sl@0
|
48 |
r=file.Read(buf);
|
sl@0
|
49 |
test(r==KErrNone);
|
sl@0
|
50 |
test(buf==_L8("Hello World"));
|
sl@0
|
51 |
file.Close();
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
LOCAL_C void Test2()
|
sl@0
|
55 |
//
|
sl@0
|
56 |
// Open and read from a file
|
sl@0
|
57 |
//
|
sl@0
|
58 |
{
|
sl@0
|
59 |
|
sl@0
|
60 |
test.Next(_L("Open and read from a file"));
|
sl@0
|
61 |
TInt r=TheFs.SetSessionPath(gSessionPath);
|
sl@0
|
62 |
test(r==KErrNone);
|
sl@0
|
63 |
RFile file;
|
sl@0
|
64 |
r=file.Open(TheFs,_L("Hello.Wld"),EFileRead);
|
sl@0
|
65 |
test(r==KErrNone);
|
sl@0
|
66 |
TBuf8<256> buf;
|
sl@0
|
67 |
r=file.Read(buf);
|
sl@0
|
68 |
test(r==KErrNone);
|
sl@0
|
69 |
test(buf==_L8("Hello World"));
|
sl@0
|
70 |
file.Close();
|
sl@0
|
71 |
r=TheFs.Delete(_L("HELLO.WLD"));
|
sl@0
|
72 |
test(r==KErrNone);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
LOCAL_C void Test3()
|
sl@0
|
76 |
//
|
sl@0
|
77 |
// Create nested directories
|
sl@0
|
78 |
//
|
sl@0
|
79 |
{
|
sl@0
|
80 |
|
sl@0
|
81 |
test.Next(_L("Create nested directories"));
|
sl@0
|
82 |
TInt r=TheFs.SetSessionPath(gSessionPath);
|
sl@0
|
83 |
test(r==KErrNone);
|
sl@0
|
84 |
TheFs.ResourceCountMarkStart();
|
sl@0
|
85 |
//
|
sl@0
|
86 |
r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\A.B"));
|
sl@0
|
87 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
88 |
r=TheFs.MkDir(_L("\\F32-TST\\RIGHT\\"));
|
sl@0
|
89 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
90 |
//
|
sl@0
|
91 |
r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\ONE\\"));
|
sl@0
|
92 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
93 |
r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\"));
|
sl@0
|
94 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
95 |
r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\THREE\\"));
|
sl@0
|
96 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
97 |
r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\BOTTOM\\"));
|
sl@0
|
98 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
99 |
//
|
sl@0
|
100 |
r=TheFs.MkDirAll(_L("\\F32-TST\\RIGHT\\TOP\\MID\\BOT\\"));
|
sl@0
|
101 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
LOCAL_C void Test4()
|
sl@0
|
105 |
//
|
sl@0
|
106 |
// Test returned error values
|
sl@0
|
107 |
//
|
sl@0
|
108 |
{
|
sl@0
|
109 |
|
sl@0
|
110 |
test.Next(_L("Test returned error values"));
|
sl@0
|
111 |
TInt r=TheFs.SetSessionPath(gSessionPath);
|
sl@0
|
112 |
test(r==KErrNone);
|
sl@0
|
113 |
TheFs.ResourceCountMarkStart();
|
sl@0
|
114 |
//
|
sl@0
|
115 |
r=TheFs.MkDir(_L("\\"));
|
sl@0
|
116 |
test(r==KErrAlreadyExists);
|
sl@0
|
117 |
r=TheFs.MkDir(_L("\\LEFT"));
|
sl@0
|
118 |
test(r==KErrAlreadyExists);
|
sl@0
|
119 |
r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\"));
|
sl@0
|
120 |
test(r==KErrAlreadyExists);
|
sl@0
|
121 |
r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\..\\NEWDIR\\"));
|
sl@0
|
122 |
test(r==KErrBadName);
|
sl@0
|
123 |
r=TheFs.MkDir(_L("\\F32-TST\\NEWDIR\\SUBDIR\\"));
|
sl@0
|
124 |
test(r==KErrPathNotFound);
|
sl@0
|
125 |
//
|
sl@0
|
126 |
r=TheFs.RmDir(_L("\\"));
|
sl@0
|
127 |
test(r==KErrInUse);
|
sl@0
|
128 |
r=TheFs.RmDir(_L("\\PROG"));
|
sl@0
|
129 |
test(r==KErrInUse);
|
sl@0
|
130 |
r=TheFs.RmDir(_L("\\F32-TST\\"));
|
sl@0
|
131 |
test(r==KErrInUse);
|
sl@0
|
132 |
|
sl@0
|
133 |
|
sl@0
|
134 |
RDir dir;
|
sl@0
|
135 |
r=dir.Open(TheFs,_L("V:\\asdf"),KEntryAttNormal);
|
sl@0
|
136 |
test(r==KErrNone || r==KErrNotReady || r==KErrNotFound);
|
sl@0
|
137 |
if (r==KErrNone)
|
sl@0
|
138 |
dir.Close();
|
sl@0
|
139 |
r=dir.Open(TheFs,_L("L:\\asdf"),KEntryAttNormal);
|
sl@0
|
140 |
test(r==KErrNone || r==KErrNotReady || r==KErrNotFound);
|
sl@0
|
141 |
dir.Close();
|
sl@0
|
142 |
//
|
sl@0
|
143 |
TEntry entry;
|
sl@0
|
144 |
r=TheFs.Entry(_L("z:\\NOTEXiSTS\\file.txt"),entry);
|
sl@0
|
145 |
test(r==KErrPathNotFound);
|
sl@0
|
146 |
r=TheFs.Entry(_L("z:\\NOTEXiSTS\\"),entry);
|
sl@0
|
147 |
test(r==KErrNotFound);
|
sl@0
|
148 |
r=TheFs.Entry(_L("z:\\SYSTEM\\"),entry);
|
sl@0
|
149 |
test(r==KErrNone);
|
sl@0
|
150 |
r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("z:\\SYS\\BIN\\ESHELL.EXE"):_L("z:\\SYSTEM\\BIN\\ESHELL.EXE"),entry);
|
sl@0
|
151 |
test(r==KErrNone);
|
sl@0
|
152 |
|
sl@0
|
153 |
r=dir.Open(TheFs,_L("\\*"),NULL);
|
sl@0
|
154 |
test(r==KErrNone);
|
sl@0
|
155 |
TEntry dirEntry;
|
sl@0
|
156 |
r=dir.Read(dirEntry);
|
sl@0
|
157 |
test(r==KErrNone || r==KErrEof);
|
sl@0
|
158 |
if (r==KErrNone)
|
sl@0
|
159 |
test.Printf(_L("%S\n"),&dirEntry.iName);
|
sl@0
|
160 |
dir.Close();
|
sl@0
|
161 |
|
sl@0
|
162 |
r=dir.Open(TheFs,_L("A:\\*"),NULL);
|
sl@0
|
163 |
test(r==KErrNotReady || r==KErrNone);
|
sl@0
|
164 |
dir.Close();
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
LOCAL_C void Test5()
|
sl@0
|
168 |
//
|
sl@0
|
169 |
// Read files directly from the rom
|
sl@0
|
170 |
//
|
sl@0
|
171 |
|
sl@0
|
172 |
{
|
sl@0
|
173 |
test.Next(_L("Read Files directly from the rom"));
|
sl@0
|
174 |
|
sl@0
|
175 |
TInt pos=0;
|
sl@0
|
176 |
TInt r;
|
sl@0
|
177 |
_LIT(KTFileCpp, "Z:\\test\\T_FILE.CPP");
|
sl@0
|
178 |
_LIT(KTFsrvCpp, "Z:\\test\\T_FSRV.CPP");
|
sl@0
|
179 |
|
sl@0
|
180 |
if ( TheFs.IsFileInRom(KTFileCpp) != NULL && TheFs.IsFileInRom(KTFsrvCpp) != NULL )
|
sl@0
|
181 |
{
|
sl@0
|
182 |
RFile f;
|
sl@0
|
183 |
r=f.Open(TheFs,KTFileCpp,EFileRead);
|
sl@0
|
184 |
test(r==KErrNone);
|
sl@0
|
185 |
r=f.Seek(ESeekAddress,pos);
|
sl@0
|
186 |
TText8* ptrPos=*(TText8**)&pos;
|
sl@0
|
187 |
test(r==KErrNone);
|
sl@0
|
188 |
TBuf8<1024> readBuf;
|
sl@0
|
189 |
r=f.Read(readBuf);
|
sl@0
|
190 |
test(r==KErrNone);
|
sl@0
|
191 |
test(readBuf.Length()==readBuf.MaxLength());
|
sl@0
|
192 |
TPtrC8 memBuf(ptrPos,readBuf.Length());
|
sl@0
|
193 |
test(memBuf==readBuf);
|
sl@0
|
194 |
|
sl@0
|
195 |
ptrPos+=9913;
|
sl@0
|
196 |
pos=9913;
|
sl@0
|
197 |
r=f.Seek(ESeekStart,pos);
|
sl@0
|
198 |
test(r==KErrNone);
|
sl@0
|
199 |
readBuf.SetLength(0);
|
sl@0
|
200 |
r=f.Read(readBuf);
|
sl@0
|
201 |
test(r==KErrNone);
|
sl@0
|
202 |
test(readBuf.Length()==readBuf.MaxLength());
|
sl@0
|
203 |
memBuf.Set(ptrPos,readBuf.Length());
|
sl@0
|
204 |
test(memBuf==readBuf);
|
sl@0
|
205 |
|
sl@0
|
206 |
RFile f2;
|
sl@0
|
207 |
pos=10;
|
sl@0
|
208 |
r=f2.Open(TheFs,KTFsrvCpp,EFileRead);
|
sl@0
|
209 |
|
sl@0
|
210 |
test(r==KErrNone);
|
sl@0
|
211 |
r=f2.Seek(ESeekAddress,pos);
|
sl@0
|
212 |
ptrPos=*(TText8**)&pos;
|
sl@0
|
213 |
test(r==KErrNone);
|
sl@0
|
214 |
readBuf.SetLength(0);
|
sl@0
|
215 |
pos=10;
|
sl@0
|
216 |
r=f2.Seek(ESeekStart,pos);
|
sl@0
|
217 |
test(r==KErrNone);
|
sl@0
|
218 |
r=f2.Read(readBuf);
|
sl@0
|
219 |
test(r==KErrNone);
|
sl@0
|
220 |
test(readBuf.Length()==readBuf.MaxLength());
|
sl@0
|
221 |
memBuf.Set(ptrPos,readBuf.Length());
|
sl@0
|
222 |
test(memBuf==readBuf);
|
sl@0
|
223 |
|
sl@0
|
224 |
ptrPos+=2445;
|
sl@0
|
225 |
pos=10+2445;
|
sl@0
|
226 |
r=f2.Seek(ESeekStart,pos);
|
sl@0
|
227 |
test(r==KErrNone);
|
sl@0
|
228 |
readBuf.SetLength(0);
|
sl@0
|
229 |
r=f2.Read(readBuf);
|
sl@0
|
230 |
test(r==KErrNone);
|
sl@0
|
231 |
test(readBuf.Length()==readBuf.MaxLength());
|
sl@0
|
232 |
memBuf.Set(ptrPos,readBuf.Length());
|
sl@0
|
233 |
test(memBuf==readBuf);
|
sl@0
|
234 |
|
sl@0
|
235 |
pos=0;
|
sl@0
|
236 |
r=f.Seek(ESeekAddress,pos);
|
sl@0
|
237 |
ptrPos=*(TText8**)&pos;
|
sl@0
|
238 |
test(r==KErrNone);
|
sl@0
|
239 |
readBuf.SetLength(0);
|
sl@0
|
240 |
pos=0;
|
sl@0
|
241 |
r=f.Seek(ESeekStart,pos);
|
sl@0
|
242 |
test(r==KErrNone);
|
sl@0
|
243 |
r=f.Read(readBuf);
|
sl@0
|
244 |
test(r==KErrNone);
|
sl@0
|
245 |
test(readBuf.Length()==readBuf.MaxLength());
|
sl@0
|
246 |
memBuf.Set(ptrPos,readBuf.Length());
|
sl@0
|
247 |
test(memBuf==readBuf);
|
sl@0
|
248 |
|
sl@0
|
249 |
ptrPos+=5245;
|
sl@0
|
250 |
pos=5245;
|
sl@0
|
251 |
r=f.Seek(ESeekStart,pos);
|
sl@0
|
252 |
test(r==KErrNone);
|
sl@0
|
253 |
readBuf.SetLength(0);
|
sl@0
|
254 |
r=f.Read(readBuf);
|
sl@0
|
255 |
test(r==KErrNone);
|
sl@0
|
256 |
test(readBuf.Length()==readBuf.MaxLength());
|
sl@0
|
257 |
memBuf.Set(ptrPos,readBuf.Length());
|
sl@0
|
258 |
test(memBuf==readBuf);
|
sl@0
|
259 |
|
sl@0
|
260 |
f.Close();
|
sl@0
|
261 |
f2.Close();
|
sl@0
|
262 |
}
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
LOCAL_C void Test6()
|
sl@0
|
266 |
//
|
sl@0
|
267 |
// Test rom return values
|
sl@0
|
268 |
//
|
sl@0
|
269 |
{
|
sl@0
|
270 |
test.Next(_L("Test rom return values"));
|
sl@0
|
271 |
|
sl@0
|
272 |
RFile f;
|
sl@0
|
273 |
TInt r=f.Replace(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead);
|
sl@0
|
274 |
test(r==KErrAccessDenied);
|
sl@0
|
275 |
r=f.Create(TheFs,_L("Z:\\Test\\newT_Fsrv.Cpp"),EFileRead);
|
sl@0
|
276 |
test(r==KErrAccessDenied);
|
sl@0
|
277 |
r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead);
|
sl@0
|
278 |
test(r==KErrNone);
|
sl@0
|
279 |
f.Close();
|
sl@0
|
280 |
r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead|EFileWrite);
|
sl@0
|
281 |
test(r==KErrAccessDenied);
|
sl@0
|
282 |
}
|
sl@0
|
283 |
|
sl@0
|
284 |
LOCAL_C void Test7()
|
sl@0
|
285 |
//
|
sl@0
|
286 |
// Test cache
|
sl@0
|
287 |
//
|
sl@0
|
288 |
{
|
sl@0
|
289 |
|
sl@0
|
290 |
test.Next(_L("Test cache updated when writing to a file"));
|
sl@0
|
291 |
TUidType uid1(TUid::Uid(1),TUid::Uid(2),TUid::Uid(3));
|
sl@0
|
292 |
TBuf8<32> contents1=_L8("asdf asdf asdf");
|
sl@0
|
293 |
TBuf<32> file1=_L("\\TMISC\\CACHE.FILE");
|
sl@0
|
294 |
MakeFile(file1,uid1,contents1);
|
sl@0
|
295 |
|
sl@0
|
296 |
TEntry entry;
|
sl@0
|
297 |
TInt r=TheFs.Entry(file1,entry);
|
sl@0
|
298 |
test(r==KErrNone);
|
sl@0
|
299 |
test(entry.iType==uid1);
|
sl@0
|
300 |
|
sl@0
|
301 |
TUidType uid2(TUid::Uid(4),TUid::Uid(5),TUid::Uid(6));
|
sl@0
|
302 |
TCheckedUid checkedUid(uid2);
|
sl@0
|
303 |
TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
sl@0
|
304 |
RFile f;
|
sl@0
|
305 |
r=f.Open(TheFs,file1,EFileRead|EFileWrite);
|
sl@0
|
306 |
test(r==KErrNone);
|
sl@0
|
307 |
r=f.Write(uidData);
|
sl@0
|
308 |
test(r==KErrNone);
|
sl@0
|
309 |
r = f.Flush();
|
sl@0
|
310 |
test(r==KErrNone);
|
sl@0
|
311 |
|
sl@0
|
312 |
r=TheFs.Entry(file1,entry);
|
sl@0
|
313 |
test(r==KErrNone);
|
sl@0
|
314 |
test(entry.iType==uid2);
|
sl@0
|
315 |
|
sl@0
|
316 |
f.Close();
|
sl@0
|
317 |
r=TheFs.Entry(file1,entry);
|
sl@0
|
318 |
test(r==KErrNone);
|
sl@0
|
319 |
test(entry.iType==uid2);
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
LOCAL_C void Test8()
|
sl@0
|
323 |
//
|
sl@0
|
324 |
// Test IsValidName
|
sl@0
|
325 |
//
|
sl@0
|
326 |
{
|
sl@0
|
327 |
test.Next(_L("Test RFs::IsValidName(TDesC)"));
|
sl@0
|
328 |
|
sl@0
|
329 |
// tests calling IsValidName() with invalid name as first call to session
|
sl@0
|
330 |
// see defect EXT-57KH9K
|
sl@0
|
331 |
_LIT(KInvalidName, "test\\i1.jpg");
|
sl@0
|
332 |
RFs fs;
|
sl@0
|
333 |
test(KErrNone==fs.Connect());
|
sl@0
|
334 |
test(fs.IsValidName(KInvalidName)==EFalse);
|
sl@0
|
335 |
fs.Close();
|
sl@0
|
336 |
|
sl@0
|
337 |
test(TheFs.IsValidName(_L("*"))==EFalse);
|
sl@0
|
338 |
test(TheFs.IsValidName(_L("?"))==EFalse);
|
sl@0
|
339 |
test(TheFs.IsValidName(_L(">"))==EFalse);
|
sl@0
|
340 |
test(TheFs.IsValidName(_L("<"))==EFalse);
|
sl@0
|
341 |
test(TheFs.IsValidName(_L(":"))==EFalse);
|
sl@0
|
342 |
test(TheFs.IsValidName(_L("\""))==EFalse);
|
sl@0
|
343 |
test(TheFs.IsValidName(_L("/"))==EFalse);
|
sl@0
|
344 |
test(TheFs.IsValidName(_L("|"))==EFalse);
|
sl@0
|
345 |
test(TheFs.IsValidName(_L("\\"))==EFalse);
|
sl@0
|
346 |
|
sl@0
|
347 |
test(TheFs.IsValidName(_L("xx*yy"))==EFalse);
|
sl@0
|
348 |
test(TheFs.IsValidName(_L("xx?yy"))==EFalse);
|
sl@0
|
349 |
test(TheFs.IsValidName(_L("xx>yy"))==EFalse);
|
sl@0
|
350 |
test(TheFs.IsValidName(_L("xx<yy"))==EFalse);
|
sl@0
|
351 |
test(TheFs.IsValidName(_L("xx:yy"))==EFalse);
|
sl@0
|
352 |
test(TheFs.IsValidName(_L("xx\"yy"))==EFalse);
|
sl@0
|
353 |
test(TheFs.IsValidName(_L("xx/yy"))==EFalse);
|
sl@0
|
354 |
test(TheFs.IsValidName(_L("xx|yy"))==EFalse);
|
sl@0
|
355 |
|
sl@0
|
356 |
test(TheFs.IsValidName(_L("C:\\*\\group\\release.txt"))==EFalse);
|
sl@0
|
357 |
test(TheFs.IsValidName(_L("C:\\?\\group\\release.txt"))==EFalse);
|
sl@0
|
358 |
test(TheFs.IsValidName(_L("C:\\>\\group\\release.txt"))==EFalse);
|
sl@0
|
359 |
test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"))==EFalse);
|
sl@0
|
360 |
test(TheFs.IsValidName(_L("C:\\:\\group\\release.txt"))==EFalse);
|
sl@0
|
361 |
test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"))==EFalse);
|
sl@0
|
362 |
test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"))==EFalse);
|
sl@0
|
363 |
test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"))==EFalse);
|
sl@0
|
364 |
|
sl@0
|
365 |
test(TheFs.IsValidName(_L(""))==EFalse); // must be a name or extension present
|
sl@0
|
366 |
test(TheFs.IsValidName(_L(".ext")));
|
sl@0
|
367 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"))==EFalse);
|
sl@0
|
368 |
test(TheFs.IsValidName(_L("\\"))==EFalse);
|
sl@0
|
369 |
|
sl@0
|
370 |
test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"))); // Valid names
|
sl@0
|
371 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"))); // Valid names
|
sl@0
|
372 |
test(TheFs.IsValidName(_L("\'"))); // Valid names
|
sl@0
|
373 |
|
sl@0
|
374 |
test.Next(_L("Test RFs::IsValidName(TDesC, TDes) overload"));
|
sl@0
|
375 |
|
sl@0
|
376 |
TText testChar;
|
sl@0
|
377 |
test(TheFs.IsValidName(_L("*"),testChar)==EFalse);
|
sl@0
|
378 |
test(testChar=='*');
|
sl@0
|
379 |
test(TheFs.IsValidName(_L("?"),testChar)==EFalse);
|
sl@0
|
380 |
test(testChar=='?');
|
sl@0
|
381 |
test(TheFs.IsValidName(_L(">"),testChar)==EFalse);
|
sl@0
|
382 |
test(testChar=='>');
|
sl@0
|
383 |
test(TheFs.IsValidName(_L("<"),testChar)==EFalse);
|
sl@0
|
384 |
test(testChar=='<');
|
sl@0
|
385 |
test(TheFs.IsValidName(_L(":"),testChar)==EFalse);
|
sl@0
|
386 |
test(testChar==':');
|
sl@0
|
387 |
test(TheFs.IsValidName(_L("\""),testChar)==EFalse);
|
sl@0
|
388 |
test(testChar=='\"'); // Tests that " is illegal
|
sl@0
|
389 |
test(TheFs.IsValidName(_L("/"),testChar)==EFalse);
|
sl@0
|
390 |
test(testChar=='/');
|
sl@0
|
391 |
test(TheFs.IsValidName(_L("|"),testChar)==EFalse);
|
sl@0
|
392 |
test(testChar=='|');
|
sl@0
|
393 |
test(TheFs.IsValidName(_L("\\"),testChar)==EFalse);
|
sl@0
|
394 |
test(testChar==' ');
|
sl@0
|
395 |
|
sl@0
|
396 |
test(TheFs.IsValidName(_L("xx*yy"),testChar)==EFalse);
|
sl@0
|
397 |
test(testChar=='*');
|
sl@0
|
398 |
test(TheFs.IsValidName(_L("xx?yy"),testChar)==EFalse);
|
sl@0
|
399 |
test(testChar=='?');
|
sl@0
|
400 |
test(TheFs.IsValidName(_L("xx>yy"),testChar)==EFalse);
|
sl@0
|
401 |
test(testChar=='>');
|
sl@0
|
402 |
test(TheFs.IsValidName(_L("xx<yy"),testChar)==EFalse);
|
sl@0
|
403 |
test(testChar=='<');
|
sl@0
|
404 |
test(TheFs.IsValidName(_L("xx:yy"),testChar)==EFalse);
|
sl@0
|
405 |
test(testChar==':');
|
sl@0
|
406 |
test(TheFs.IsValidName(_L("xx\"yy"),testChar)==EFalse);
|
sl@0
|
407 |
test(testChar=='\"'); // Tests that " is illegal
|
sl@0
|
408 |
test(TheFs.IsValidName(_L("xx/yy"),testChar)==EFalse);
|
sl@0
|
409 |
test(testChar=='/');
|
sl@0
|
410 |
test(TheFs.IsValidName(_L("xx|yy"),testChar)==EFalse);
|
sl@0
|
411 |
test(testChar=='|');
|
sl@0
|
412 |
|
sl@0
|
413 |
test(TheFs.IsValidName(_L("C:\\*\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
414 |
test(testChar=='*');
|
sl@0
|
415 |
test(TheFs.IsValidName(_L("C:\\?\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
416 |
test(testChar=='?');
|
sl@0
|
417 |
test(TheFs.IsValidName(_L("C:\\..\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
418 |
test(testChar=='.'); // Only one "." returned however many are in filename
|
sl@0
|
419 |
test(TheFs.IsValidName(_L("C:\\.\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
420 |
test(testChar=='.');
|
sl@0
|
421 |
test(TheFs.IsValidName(_L("C:\\>\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
422 |
test(testChar=='>');
|
sl@0
|
423 |
test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
424 |
test(testChar=='<');
|
sl@0
|
425 |
test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
426 |
test(testChar==':');
|
sl@0
|
427 |
|
sl@0
|
428 |
|
sl@0
|
429 |
test(TheFs.IsValidName(_L("C::\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
430 |
test(testChar==':');
|
sl@0
|
431 |
test(TheFs.IsValidName(_L(">\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
432 |
test(testChar=='>');
|
sl@0
|
433 |
test(TheFs.IsValidName(_L("C|group\\release.txt"),testChar)==EFalse);
|
sl@0
|
434 |
test(testChar=='|');
|
sl@0
|
435 |
test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
436 |
test(testChar=='|');
|
sl@0
|
437 |
|
sl@0
|
438 |
test(TheFs.IsValidName(_L("\\>"),testChar)==EFalse);
|
sl@0
|
439 |
test(testChar=='>');
|
sl@0
|
440 |
test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),testChar)==EFalse);
|
sl@0
|
441 |
test(testChar=='|');
|
sl@0
|
442 |
|
sl@0
|
443 |
test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
444 |
test(testChar=='\"');
|
sl@0
|
445 |
test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
446 |
test(testChar=='/');
|
sl@0
|
447 |
test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),testChar)==EFalse);
|
sl@0
|
448 |
test(testChar=='|');
|
sl@0
|
449 |
test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),testChar)==EFalse); // must be a name or extension present
|
sl@0
|
450 |
test(testChar==' ');
|
sl@0
|
451 |
|
sl@0
|
452 |
// Test that \ is not allowed in filenames
|
sl@0
|
453 |
TFileName filename;
|
sl@0
|
454 |
filename=_L("C:\\HelloWorld\\\\\\group\\release.txt");
|
sl@0
|
455 |
TPtr pChar(&testChar,sizeof(TText),sizeof(TText));
|
sl@0
|
456 |
test(TheFs.IsValidName(filename,testChar)==EFalse);
|
sl@0
|
457 |
test(pChar.Find(_L("\\"))!=KErrNotFound);
|
sl@0
|
458 |
filename=_L("C:\\\\\\group\\release.txt");
|
sl@0
|
459 |
test(TheFs.IsValidName(filename,testChar)==EFalse);
|
sl@0
|
460 |
test(pChar.Find(_L("\\"))!=KErrNotFound);
|
sl@0
|
461 |
filename=_L("C:\\Hello World\\group\\release.txt");
|
sl@0
|
462 |
filename[8]=KPathDelimiter; // Makes C:\\Hello World\\group\\release.txt
|
sl@0
|
463 |
test(TheFs.IsValidName(filename,testChar));
|
sl@0
|
464 |
filename=_L("C:\\HelloWorld\\::\\group\\release.txt");
|
sl@0
|
465 |
test(TheFs.IsValidName(filename,testChar)==EFalse);
|
sl@0
|
466 |
test(pChar.Find(_L(":"))!=KErrNotFound);
|
sl@0
|
467 |
|
sl@0
|
468 |
filename=_L("C:\\>>\\group\\release.txt");
|
sl@0
|
469 |
test(TheFs.IsValidName(filename,testChar)==EFalse);
|
sl@0
|
470 |
test(pChar.Find(_L(">"))!=KErrNotFound);
|
sl@0
|
471 |
|
sl@0
|
472 |
test(TheFs.IsValidName(_L(""),testChar)==EFalse); // Must be a name
|
sl@0
|
473 |
test(testChar==' ');
|
sl@0
|
474 |
test(TheFs.IsValidName(_L(".ext"),testChar));
|
sl@0
|
475 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),testChar)==EFalse);
|
sl@0
|
476 |
test(testChar==' '); // Must be a name else testChar is set to blank
|
sl@0
|
477 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg"),testChar));
|
sl@0
|
478 |
|
sl@0
|
479 |
test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),testChar)==EFalse);
|
sl@0
|
480 |
test(testChar==' '); // Must be a name else testChar is set to blank
|
sl@0
|
481 |
test(TheFs.IsValidName(_L("C:\\asdf..blarg"),testChar));
|
sl@0
|
482 |
|
sl@0
|
483 |
test(TheFs.IsValidName(_L("\\"),testChar)==EFalse);
|
sl@0
|
484 |
test(testChar==' ');
|
sl@0
|
485 |
|
sl@0
|
486 |
// Test multiple evil characters - parsing occurs from right to left
|
sl@0
|
487 |
// except that wildcarded characters take priority and are picked out first
|
sl@0
|
488 |
test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mno<pqr*stu"),testChar)==EFalse);
|
sl@0
|
489 |
test(testChar=='*');
|
sl@0
|
490 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno?pqr"),testChar)==EFalse);
|
sl@0
|
491 |
test(testChar=='?');
|
sl@0
|
492 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno"),testChar)==EFalse);
|
sl@0
|
493 |
test(testChar==':');
|
sl@0
|
494 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl"),testChar)==EFalse);
|
sl@0
|
495 |
test(testChar=='<');
|
sl@0
|
496 |
test(TheFs.IsValidName(_L("abc>def|ghi"),testChar)==EFalse);
|
sl@0
|
497 |
test(testChar=='|');
|
sl@0
|
498 |
test(TheFs.IsValidName(_L("abc>def"),testChar)==EFalse);
|
sl@0
|
499 |
test(testChar=='>');
|
sl@0
|
500 |
|
sl@0
|
501 |
test(!TheFs.IsValidName(_L("C:\\v123456.."),testChar)); // Valid name
|
sl@0
|
502 |
test(TheFs.IsValidName(_L("abc"),testChar)); // Valid name
|
sl@0
|
503 |
test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),testChar)); // Valid name
|
sl@0
|
504 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),testChar)); // Valid name
|
sl@0
|
505 |
test(TheFs.IsValidName(_L("\'"),testChar)); // Valid name
|
sl@0
|
506 |
|
sl@0
|
507 |
//PDEF133084: The wild character in the extension was not being detected.
|
sl@0
|
508 |
_LIT( KTestString, "E:\\My Videos\\Downloads\\1\\1\\Name.3gp?" );
|
sl@0
|
509 |
TBuf<50> path;
|
sl@0
|
510 |
path = KTestString;
|
sl@0
|
511 |
TBool validName( EFalse );
|
sl@0
|
512 |
TText badChar;
|
sl@0
|
513 |
TInt badCharLoc( KErrNotFound );
|
sl@0
|
514 |
|
sl@0
|
515 |
while ( ! validName )
|
sl@0
|
516 |
{
|
sl@0
|
517 |
validName = TheFs.IsValidName( path, badChar );
|
sl@0
|
518 |
|
sl@0
|
519 |
if ( ! validName )
|
sl@0
|
520 |
{
|
sl@0
|
521 |
badCharLoc = path.LocateReverse( badChar );
|
sl@0
|
522 |
|
sl@0
|
523 |
if ( KErrNotFound != badCharLoc )
|
sl@0
|
524 |
{
|
sl@0
|
525 |
path[badCharLoc] = '_';
|
sl@0
|
526 |
}
|
sl@0
|
527 |
}
|
sl@0
|
528 |
}
|
sl@0
|
529 |
}
|
sl@0
|
530 |
|
sl@0
|
531 |
LOCAL_C void Test9()
|
sl@0
|
532 |
//
|
sl@0
|
533 |
// Test IsFileInRom
|
sl@0
|
534 |
//
|
sl@0
|
535 |
{
|
sl@0
|
536 |
|
sl@0
|
537 |
test.Next(_L("Test RFs::IsFileInRom"));
|
sl@0
|
538 |
|
sl@0
|
539 |
CFileMan* fMan=CFileMan::NewL(TheFs);
|
sl@0
|
540 |
TInt r=fMan->Copy(_L("Z:\\TEST\\T_FILE.CPP"),_L("C:\\T_FILE.CPP"));
|
sl@0
|
541 |
test(r==KErrNone || r==KErrAccessDenied);
|
sl@0
|
542 |
delete fMan;
|
sl@0
|
543 |
TUint8* addr=TheFs.IsFileInRom(_L("C:\\ESHELL.EXE"));
|
sl@0
|
544 |
test(addr==NULL);
|
sl@0
|
545 |
addr=TheFs.IsFileInRom(_L("Z:\\TEST\\T_FILE.CPP"));
|
sl@0
|
546 |
if (addr!=NULL)
|
sl@0
|
547 |
{
|
sl@0
|
548 |
test(addr!=NULL);
|
sl@0
|
549 |
TPtrC8 startOfFile(addr,12);
|
sl@0
|
550 |
test(startOfFile==_L8("// Copyright"));
|
sl@0
|
551 |
}
|
sl@0
|
552 |
else
|
sl@0
|
553 |
{
|
sl@0
|
554 |
test (addr==NULL);
|
sl@0
|
555 |
}
|
sl@0
|
556 |
}
|
sl@0
|
557 |
|
sl@0
|
558 |
LOCAL_C void Test10()
|
sl@0
|
559 |
//
|
sl@0
|
560 |
// Test drive names
|
sl@0
|
561 |
//
|
sl@0
|
562 |
{
|
sl@0
|
563 |
|
sl@0
|
564 |
test.Next(_L("Test Drive Names"));
|
sl@0
|
565 |
TFileName driveName;
|
sl@0
|
566 |
TInt i;
|
sl@0
|
567 |
for(i=0;i<KMaxDrives;i++)
|
sl@0
|
568 |
{
|
sl@0
|
569 |
TInt r=TheFs.GetDriveName(i,driveName);
|
sl@0
|
570 |
test(r==KErrNone);
|
sl@0
|
571 |
if (driveName.Length())
|
sl@0
|
572 |
test.Printf(_L("Default name of %c: == %S\n"),'A'+i,&driveName);
|
sl@0
|
573 |
}
|
sl@0
|
574 |
|
sl@0
|
575 |
TBuf<64> drive0=_L("Dilbert");
|
sl@0
|
576 |
TBuf<64> drive4=_L("Dogbert");
|
sl@0
|
577 |
TBuf<64> drive17=_L("Flibble");
|
sl@0
|
578 |
TBuf<64> drive25=_L("RAMDRIVE");
|
sl@0
|
579 |
TInt r=TheFs.SetDriveName(0,drive0);
|
sl@0
|
580 |
test(r==KErrNone);
|
sl@0
|
581 |
r=TheFs.SetDriveName(4,drive4);
|
sl@0
|
582 |
test(r==KErrNone);
|
sl@0
|
583 |
r=TheFs.SetDriveName(17,drive17);
|
sl@0
|
584 |
test(r==KErrNone);
|
sl@0
|
585 |
r=TheFs.SetDriveName(25,drive25);
|
sl@0
|
586 |
test(r==KErrNone);
|
sl@0
|
587 |
|
sl@0
|
588 |
r=TheFs.GetDriveName(0,driveName);
|
sl@0
|
589 |
test(r==KErrNone);
|
sl@0
|
590 |
test(driveName==drive0);
|
sl@0
|
591 |
r=TheFs.GetDriveName(4,driveName);
|
sl@0
|
592 |
test(r==KErrNone);
|
sl@0
|
593 |
test(driveName==drive4);
|
sl@0
|
594 |
r=TheFs.GetDriveName(17,driveName);
|
sl@0
|
595 |
test(r==KErrNone);
|
sl@0
|
596 |
test(driveName==drive17);
|
sl@0
|
597 |
r=TheFs.GetDriveName(25,driveName);
|
sl@0
|
598 |
test(r==KErrNone);
|
sl@0
|
599 |
test(driveName==drive25);
|
sl@0
|
600 |
|
sl@0
|
601 |
drive0=_L("askdjflsdfourewoqiuroiuaksjdvx,cvsdhwjhjhalsjhfshfkjhslj");
|
sl@0
|
602 |
r=TheFs.SetDriveName(0,drive0);
|
sl@0
|
603 |
test(r==KErrNone);
|
sl@0
|
604 |
r=TheFs.GetDriveName(0,driveName);
|
sl@0
|
605 |
test(r==KErrNone);
|
sl@0
|
606 |
test(driveName==drive0);
|
sl@0
|
607 |
|
sl@0
|
608 |
// Test with illegal characters in drive name
|
sl@0
|
609 |
drive0=_L("Dil>bert");
|
sl@0
|
610 |
drive4=_L("Dog?bert");
|
sl@0
|
611 |
drive17=_L("Fli*bble");
|
sl@0
|
612 |
drive25=_L("RAMD//RIVE");
|
sl@0
|
613 |
|
sl@0
|
614 |
r=TheFs.SetDriveName(0,drive0);
|
sl@0
|
615 |
test(r==KErrBadName);
|
sl@0
|
616 |
r=TheFs.SetDriveName(4,drive4);
|
sl@0
|
617 |
test(r==KErrBadName);
|
sl@0
|
618 |
r=TheFs.SetDriveName(17,drive17);
|
sl@0
|
619 |
test(r==KErrBadName);
|
sl@0
|
620 |
r=TheFs.SetDriveName(25,drive25);
|
sl@0
|
621 |
test(r==KErrBadName);
|
sl@0
|
622 |
|
sl@0
|
623 |
// Test that it is OK to set the name to no characters
|
sl@0
|
624 |
|
sl@0
|
625 |
drive0=_L("");
|
sl@0
|
626 |
drive4=_L("");
|
sl@0
|
627 |
drive17=_L("");
|
sl@0
|
628 |
drive25=_L("");
|
sl@0
|
629 |
|
sl@0
|
630 |
r=TheFs.SetDriveName(0,drive0);
|
sl@0
|
631 |
test(r==KErrNone);
|
sl@0
|
632 |
r=TheFs.SetDriveName(4,drive4);
|
sl@0
|
633 |
test(r==KErrNone);
|
sl@0
|
634 |
r=TheFs.SetDriveName(17,drive17);
|
sl@0
|
635 |
test(r==KErrNone);
|
sl@0
|
636 |
r=TheFs.SetDriveName(25,drive25);
|
sl@0
|
637 |
test(r==KErrNone);
|
sl@0
|
638 |
|
sl@0
|
639 |
r=TheFs.GetDriveName(0,driveName);
|
sl@0
|
640 |
test(r==KErrNone);
|
sl@0
|
641 |
test(driveName==drive0);
|
sl@0
|
642 |
r=TheFs.GetDriveName(4,driveName);
|
sl@0
|
643 |
test(r==KErrNone);
|
sl@0
|
644 |
test(driveName==drive4);
|
sl@0
|
645 |
r=TheFs.GetDriveName(17,driveName);
|
sl@0
|
646 |
test(r==KErrNone);
|
sl@0
|
647 |
test(driveName==drive17);
|
sl@0
|
648 |
r=TheFs.GetDriveName(25,driveName);
|
sl@0
|
649 |
test(r==KErrNone);
|
sl@0
|
650 |
test(driveName==drive25);
|
sl@0
|
651 |
|
sl@0
|
652 |
|
sl@0
|
653 |
}
|
sl@0
|
654 |
|
sl@0
|
655 |
LOCAL_C void Test11()
|
sl@0
|
656 |
//
|
sl@0
|
657 |
// Miscellaneous tests
|
sl@0
|
658 |
//
|
sl@0
|
659 |
{
|
sl@0
|
660 |
|
sl@0
|
661 |
test.Next(_L("Miscellaneous tests"));
|
sl@0
|
662 |
TVolumeInfo vol;
|
sl@0
|
663 |
TInt r=TheFs.Volume(vol);
|
sl@0
|
664 |
test.Printf(_L("VolumeName = %S\n"),&vol.iName);
|
sl@0
|
665 |
test(r==KErrNone);
|
sl@0
|
666 |
r=TheFs.RmDir(_L("\\asdfasdf.\\"));
|
sl@0
|
667 |
test(r==KErrBadName);
|
sl@0
|
668 |
r=TheFs.MkDir(_L("\\asdfasdf.\\"));
|
sl@0
|
669 |
test(r==KErrBadName);
|
sl@0
|
670 |
}
|
sl@0
|
671 |
|
sl@0
|
672 |
LOCAL_C void Test12()
|
sl@0
|
673 |
//
|
sl@0
|
674 |
// Test SetNotifyUser and GetNotifyUser
|
sl@0
|
675 |
//
|
sl@0
|
676 |
{
|
sl@0
|
677 |
|
sl@0
|
678 |
test.Next(_L("Test Set and GetNotifyUser"));
|
sl@0
|
679 |
TBool notifyState=TheFs.GetNotifyUser();
|
sl@0
|
680 |
test(notifyState);
|
sl@0
|
681 |
notifyState=EFalse;
|
sl@0
|
682 |
TheFs.SetNotifyUser(notifyState);
|
sl@0
|
683 |
notifyState=TheFs.GetNotifyUser();
|
sl@0
|
684 |
test(notifyState==EFalse);
|
sl@0
|
685 |
notifyState=ETrue;
|
sl@0
|
686 |
TheFs.SetNotifyUser(notifyState);
|
sl@0
|
687 |
notifyState=TheFs.GetNotifyUser();
|
sl@0
|
688 |
test(notifyState);
|
sl@0
|
689 |
}
|
sl@0
|
690 |
|
sl@0
|
691 |
LOCAL_C void Test13()
|
sl@0
|
692 |
//
|
sl@0
|
693 |
// Test return values from RFs::Volume on cf-cards
|
sl@0
|
694 |
//
|
sl@0
|
695 |
{
|
sl@0
|
696 |
|
sl@0
|
697 |
test.Next(_L("Test RFs::Volume"));
|
sl@0
|
698 |
TVolumeInfo vol;
|
sl@0
|
699 |
TInt r=TheFs.Volume(vol,EDriveB);
|
sl@0
|
700 |
test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
|
sl@0
|
701 |
test.Printf(_L("RFs::Volume EDriveB returned %d\n"),r);
|
sl@0
|
702 |
|
sl@0
|
703 |
r=TheFs.Volume(vol,EDriveC);
|
sl@0
|
704 |
test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
|
sl@0
|
705 |
test.Printf(_L("RFs::Volume EDriveC returned %d\n"),r);
|
sl@0
|
706 |
|
sl@0
|
707 |
r=TheFs.Volume(vol,EDriveD);
|
sl@0
|
708 |
test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
|
sl@0
|
709 |
test.Printf(_L("RFs::Volume EDriveD returned %d\n"),r);
|
sl@0
|
710 |
|
sl@0
|
711 |
r=TheFs.Volume(vol,EDriveE);
|
sl@0
|
712 |
test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
|
sl@0
|
713 |
test.Printf(_L("RFs::Volume EDriveE returned %d\n"),r);
|
sl@0
|
714 |
|
sl@0
|
715 |
r=TheFs.Volume(vol,EDriveF);
|
sl@0
|
716 |
test(r==KErrNotReady || r==KErrNone || KErrPathNotFound);
|
sl@0
|
717 |
test.Printf(_L("RFs::Volume EDriveF returned %d\n"),r);
|
sl@0
|
718 |
}
|
sl@0
|
719 |
|
sl@0
|
720 |
|
sl@0
|
721 |
void DoTest14(TInt aDrvNum);
|
sl@0
|
722 |
TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
|
sl@0
|
723 |
TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
|
sl@0
|
724 |
TBool CheckFileContents(RFs& aFs, const TDesC& aFileName);
|
sl@0
|
725 |
TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0);
|
sl@0
|
726 |
|
sl@0
|
727 |
/**
|
sl@0
|
728 |
Testing unallocated data initialization vulnerability in RFile
|
sl@0
|
729 |
This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag)
|
sl@0
|
730 |
e.g. XSR NAND
|
sl@0
|
731 |
*/
|
sl@0
|
732 |
LOCAL_C void Test14()
|
sl@0
|
733 |
{
|
sl@0
|
734 |
TInt nRes;
|
sl@0
|
735 |
|
sl@0
|
736 |
test.Next(_L("Testing unallocated data initialization vulnerability in RFile"));
|
sl@0
|
737 |
|
sl@0
|
738 |
TDriveList driveList;
|
sl@0
|
739 |
TDriveInfo driveInfo;
|
sl@0
|
740 |
|
sl@0
|
741 |
//-- 1. get drives list
|
sl@0
|
742 |
nRes=TheFs.DriveList(driveList);
|
sl@0
|
743 |
test(nRes == KErrNone);
|
sl@0
|
744 |
|
sl@0
|
745 |
//-- 2. walk through all drives, performing the test only on suitable ones
|
sl@0
|
746 |
for (TInt drvNum=0; drvNum<KMaxDrives; ++drvNum)
|
sl@0
|
747 |
{
|
sl@0
|
748 |
if(!driveList[drvNum])
|
sl@0
|
749 |
continue; //-- skip unexisting drive
|
sl@0
|
750 |
|
sl@0
|
751 |
//-- get drive info
|
sl@0
|
752 |
test(TheFs.Drive(driveInfo, drvNum) == KErrNone);
|
sl@0
|
753 |
|
sl@0
|
754 |
//-- select a suitable drive for the testing. It shall be RAM drive, of FLASH but not removable
|
sl@0
|
755 |
//-- and not read only, if it is FLASH, it shall support "Delete Notify" facility
|
sl@0
|
756 |
switch(driveInfo.iType)
|
sl@0
|
757 |
{
|
sl@0
|
758 |
//-- RAM drive, OK
|
sl@0
|
759 |
case EMediaRam:
|
sl@0
|
760 |
break;
|
sl@0
|
761 |
|
sl@0
|
762 |
//-- FLASH drive, OK
|
sl@0
|
763 |
case EMediaFlash:
|
sl@0
|
764 |
case EMediaNANDFlash:
|
sl@0
|
765 |
if(driveInfo.iMediaAtt & KMediaAttDeleteNotify)
|
sl@0
|
766 |
break; //-- this type of media shall support DeleteNotify flag, otherwise this test is inconsistent
|
sl@0
|
767 |
else continue;
|
sl@0
|
768 |
|
sl@0
|
769 |
//break; //unreacable
|
sl@0
|
770 |
|
sl@0
|
771 |
default:
|
sl@0
|
772 |
continue;
|
sl@0
|
773 |
}//switch(driveInfo.iType)
|
sl@0
|
774 |
|
sl@0
|
775 |
if (driveInfo.iDriveAtt & KDriveAttSubsted)
|
sl@0
|
776 |
{
|
sl@0
|
777 |
// skip subst drives.
|
sl@0
|
778 |
continue;
|
sl@0
|
779 |
}
|
sl@0
|
780 |
|
sl@0
|
781 |
TBool readOnly = driveInfo.iMediaAtt & KMediaAttWriteProtected;
|
sl@0
|
782 |
if(readOnly)
|
sl@0
|
783 |
continue; //-- nothing to do, can't create any file etc.
|
sl@0
|
784 |
|
sl@0
|
785 |
//-- skip test on the emulator's C: drive, doesn't make any sense because
|
sl@0
|
786 |
//-- in this case we deal with WIN32 API and filesystem.
|
sl@0
|
787 |
#ifdef __WINS__
|
sl@0
|
788 |
if(drvNum == 2)
|
sl@0
|
789 |
{
|
sl@0
|
790 |
test.Printf(_L("Skipping test on emulator's C: drive\n"));
|
sl@0
|
791 |
continue;
|
sl@0
|
792 |
}
|
sl@0
|
793 |
#endif
|
sl@0
|
794 |
|
sl@0
|
795 |
DoTest14(drvNum);
|
sl@0
|
796 |
|
sl@0
|
797 |
}// for (TInt drvNum=0; ...
|
sl@0
|
798 |
|
sl@0
|
799 |
}
|
sl@0
|
800 |
|
sl@0
|
801 |
//--------------------------------------------------------
|
sl@0
|
802 |
|
sl@0
|
803 |
/**
|
sl@0
|
804 |
Actually perform the test on a drive aDrvNum.
|
sl@0
|
805 |
@param aDrvNum drive number
|
sl@0
|
806 |
*/
|
sl@0
|
807 |
void DoTest14(TInt aDrvNum)
|
sl@0
|
808 |
{
|
sl@0
|
809 |
|
sl@0
|
810 |
TFileName fileName;
|
sl@0
|
811 |
fileName.Format(_L("Testing drive %c:"), 'A'+aDrvNum);
|
sl@0
|
812 |
test.Next(fileName);
|
sl@0
|
813 |
|
sl@0
|
814 |
const TInt KFileSize = 0x1000; //-- size of the files t be created
|
sl@0
|
815 |
TInt nRes;
|
sl@0
|
816 |
|
sl@0
|
817 |
fileName.Format(_L("%c:\\TestFile.bin"), aDrvNum+'A');
|
sl@0
|
818 |
TheFs.Delete(fileName); //-- just in case
|
sl@0
|
819 |
|
sl@0
|
820 |
//==============================
|
sl@0
|
821 |
//== Scenario 1.
|
sl@0
|
822 |
//== Create an empty file; AllocateSingleClusterL, ExtendClusterListL will be involved.
|
sl@0
|
823 |
//== Check that the file doesn't contain any meaningful information
|
sl@0
|
824 |
//==============================
|
sl@0
|
825 |
test.Printf(_L("Testing scenario 1\n"));
|
sl@0
|
826 |
|
sl@0
|
827 |
//-- 1. create an empty file
|
sl@0
|
828 |
nRes = CreateEmptyFile(TheFs, fileName, KFileSize);
|
sl@0
|
829 |
test(nRes == KErrNone);
|
sl@0
|
830 |
|
sl@0
|
831 |
//-- 1.1 check that this file doesn't contain illegitimate information.
|
sl@0
|
832 |
nRes = CheckFileContents(TheFs, fileName);
|
sl@0
|
833 |
test(nRes == KErrNone);
|
sl@0
|
834 |
|
sl@0
|
835 |
//-- 1.2 delete the empty file
|
sl@0
|
836 |
nRes = TheFs.Delete(fileName);
|
sl@0
|
837 |
test(nRes == KErrNone);
|
sl@0
|
838 |
|
sl@0
|
839 |
//==============================
|
sl@0
|
840 |
//== Scenario 2.
|
sl@0
|
841 |
//== Create file, filling it with some pattern.
|
sl@0
|
842 |
//== Delete this file, FreeClusterListL() will be involved.
|
sl@0
|
843 |
//== Create an empty file supposedly of the place of just deleted one
|
sl@0
|
844 |
//== Check that the file doesn't contain any meaningful information
|
sl@0
|
845 |
//==============================
|
sl@0
|
846 |
test.Printf(_L("Testing scenario 2\n"));
|
sl@0
|
847 |
|
sl@0
|
848 |
//-- 2. create file filled with some data pattern
|
sl@0
|
849 |
nRes = CreateStuffedFile(TheFs, fileName, KFileSize);
|
sl@0
|
850 |
test(nRes == KErrNone);
|
sl@0
|
851 |
|
sl@0
|
852 |
//-- 2.1 delete this file
|
sl@0
|
853 |
TheFs.Delete(fileName);
|
sl@0
|
854 |
|
sl@0
|
855 |
//-- 2.1 create an empty file on the place of just deleted one (hopefully)
|
sl@0
|
856 |
nRes = CreateEmptyFile(TheFs, fileName, KFileSize);
|
sl@0
|
857 |
test(nRes == KErrNone);
|
sl@0
|
858 |
|
sl@0
|
859 |
//-- 2.2 check that this file doesn't contain illegitimate information.
|
sl@0
|
860 |
nRes = CheckFileContents(TheFs, fileName);
|
sl@0
|
861 |
test(nRes == KErrNone);
|
sl@0
|
862 |
|
sl@0
|
863 |
//-- 2.3 delete this file
|
sl@0
|
864 |
TheFs.Delete(fileName);
|
sl@0
|
865 |
|
sl@0
|
866 |
}
|
sl@0
|
867 |
|
sl@0
|
868 |
LOCAL_C void Test15()
|
sl@0
|
869 |
//
|
sl@0
|
870 |
// Test IsValidName
|
sl@0
|
871 |
//
|
sl@0
|
872 |
{
|
sl@0
|
873 |
test.Next(_L("Test RFs::IsValidName(TDesC& ,RFs::TNameValidParam& )"));
|
sl@0
|
874 |
TBool useDefaultSessionPath = EFalse;
|
sl@0
|
875 |
//tests under this loop are run twice
|
sl@0
|
876 |
//first, when the sessionPath is not used.
|
sl@0
|
877 |
//second, when the sessionPath is used.
|
sl@0
|
878 |
for(TInt i = 0; i<2; i++)
|
sl@0
|
879 |
{
|
sl@0
|
880 |
RFs::TNameValidParam param(useDefaultSessionPath);
|
sl@0
|
881 |
test(TheFs.IsValidName(_L("*"),param)==EFalse);
|
sl@0
|
882 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
883 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
884 |
|
sl@0
|
885 |
test(TheFs.IsValidName(_L("?"),param)==EFalse);
|
sl@0
|
886 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
887 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
888 |
|
sl@0
|
889 |
test(TheFs.IsValidName(_L(">"),param)==EFalse);
|
sl@0
|
890 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
891 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
892 |
|
sl@0
|
893 |
test(TheFs.IsValidName(_L("<"),param)==EFalse);
|
sl@0
|
894 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
895 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
896 |
|
sl@0
|
897 |
test(TheFs.IsValidName(_L(":"),param)==EFalse);
|
sl@0
|
898 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
899 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
900 |
|
sl@0
|
901 |
test(TheFs.IsValidName(_L("\""),param)==EFalse);
|
sl@0
|
902 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
903 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
904 |
|
sl@0
|
905 |
test(TheFs.IsValidName(_L("/"),param)==EFalse);
|
sl@0
|
906 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
907 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
908 |
|
sl@0
|
909 |
test(TheFs.IsValidName(_L("|"),param)==EFalse);
|
sl@0
|
910 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
911 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
912 |
|
sl@0
|
913 |
test(TheFs.IsValidName(_L("xx*yy"),param)==EFalse);
|
sl@0
|
914 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
915 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
916 |
|
sl@0
|
917 |
test(TheFs.IsValidName(_L("xx?yy"),param)==EFalse);
|
sl@0
|
918 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
919 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
920 |
|
sl@0
|
921 |
test(TheFs.IsValidName(_L("xx>yy"),param)==EFalse);
|
sl@0
|
922 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
923 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
924 |
|
sl@0
|
925 |
test(TheFs.IsValidName(_L("xx<yy"),param)==EFalse);
|
sl@0
|
926 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
927 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
928 |
|
sl@0
|
929 |
test(TheFs.IsValidName(_L("xx:yy"),param)==EFalse);
|
sl@0
|
930 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
931 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
932 |
|
sl@0
|
933 |
test(TheFs.IsValidName(_L("xx\"yy"),param)==EFalse);
|
sl@0
|
934 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
935 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
936 |
|
sl@0
|
937 |
test(TheFs.IsValidName(_L("xx/yy"),param)==EFalse);
|
sl@0
|
938 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
939 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
940 |
|
sl@0
|
941 |
test(TheFs.IsValidName(_L("xx|yy"),param)==EFalse);
|
sl@0
|
942 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
943 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
944 |
|
sl@0
|
945 |
test(TheFs.IsValidName(_L("C:\\*\\group\\release.txt"),param)==EFalse);
|
sl@0
|
946 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
947 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
948 |
|
sl@0
|
949 |
test(TheFs.IsValidName(_L("C:\\?\\group\\release.txt"),param)==EFalse);
|
sl@0
|
950 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
951 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
952 |
|
sl@0
|
953 |
test(TheFs.IsValidName(_L("C:\\..\\group\\release.txt"),param)==EFalse);
|
sl@0
|
954 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
955 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
956 |
|
sl@0
|
957 |
test(TheFs.IsValidName(_L("C:\\.\\group\\release.txt"),param)==EFalse);
|
sl@0
|
958 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
959 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
960 |
|
sl@0
|
961 |
test(TheFs.IsValidName(_L("C:\\>\\group\\release.txt"),param)==EFalse);
|
sl@0
|
962 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
963 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
964 |
|
sl@0
|
965 |
test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),param)==EFalse);
|
sl@0
|
966 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
967 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
968 |
|
sl@0
|
969 |
test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),param)==EFalse);
|
sl@0
|
970 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
971 |
test(param.InvalidCharPos() == 15);
|
sl@0
|
972 |
|
sl@0
|
973 |
test(TheFs.IsValidName(_L("C::\\group\\release.txt"),param)==EFalse);
|
sl@0
|
974 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
975 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
976 |
|
sl@0
|
977 |
test(TheFs.IsValidName(_L(">\\group\\release.txt"),param)==EFalse);
|
sl@0
|
978 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
979 |
test(param.InvalidCharPos() == 1);
|
sl@0
|
980 |
|
sl@0
|
981 |
test(TheFs.IsValidName(_L("C|group\\release.txt"),param)==EFalse);
|
sl@0
|
982 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
983 |
test(param.InvalidCharPos() == 2);
|
sl@0
|
984 |
|
sl@0
|
985 |
test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),param)==EFalse);
|
sl@0
|
986 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
987 |
test(param.InvalidCharPos() == 3);
|
sl@0
|
988 |
|
sl@0
|
989 |
test(TheFs.IsValidName(_L("\\>"),param)==EFalse);
|
sl@0
|
990 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
991 |
test(param.InvalidCharPos() == 2);
|
sl@0
|
992 |
|
sl@0
|
993 |
test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),param)==EFalse);
|
sl@0
|
994 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
995 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
996 |
|
sl@0
|
997 |
test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),param)==EFalse);
|
sl@0
|
998 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
999 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
1000 |
|
sl@0
|
1001 |
test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),param)==EFalse);
|
sl@0
|
1002 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1003 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
1004 |
|
sl@0
|
1005 |
test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),param)==EFalse);
|
sl@0
|
1006 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1007 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
1008 |
|
sl@0
|
1009 |
test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),param)==EFalse);//intermediate directory names cannot be blank
|
sl@0
|
1010 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName);
|
sl@0
|
1011 |
|
sl@0
|
1012 |
// Test that \ is not allowed in filenames
|
sl@0
|
1013 |
TFileName filename;
|
sl@0
|
1014 |
filename=_L("C:\\HelloWorld\\\\\\group\\release.txt");
|
sl@0
|
1015 |
|
sl@0
|
1016 |
test(TheFs.IsValidName(filename,param)==EFalse);
|
sl@0
|
1017 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1018 |
test(param.InvalidCharPos() == 22);
|
sl@0
|
1019 |
|
sl@0
|
1020 |
filename=_L("C:\\\\\\group\\release.txt");
|
sl@0
|
1021 |
test(TheFs.IsValidName(filename,param)==EFalse);
|
sl@0
|
1022 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1023 |
test(param.InvalidCharPos() == 11);
|
sl@0
|
1024 |
|
sl@0
|
1025 |
filename=_L("C:\\Hello World\\group\\release.txt");
|
sl@0
|
1026 |
filename[8]=KPathDelimiter;
|
sl@0
|
1027 |
test(TheFs.IsValidName(filename,param));
|
sl@0
|
1028 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1029 |
|
sl@0
|
1030 |
filename=_L("C:\\HelloWorld\\::\\group\\release.txt");
|
sl@0
|
1031 |
test(TheFs.IsValidName(filename,param)==EFalse);
|
sl@0
|
1032 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1033 |
test(param.InvalidCharPos() == 16);
|
sl@0
|
1034 |
|
sl@0
|
1035 |
filename=_L("C:\\>>\\group\\release.txt");
|
sl@0
|
1036 |
test(TheFs.IsValidName(filename,param)==EFalse);
|
sl@0
|
1037 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1038 |
test(param.InvalidCharPos() == 5);
|
sl@0
|
1039 |
|
sl@0
|
1040 |
test(TheFs.IsValidName(_L(""),param)==EFalse); // Must be a name
|
sl@0
|
1041 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName);
|
sl@0
|
1042 |
|
sl@0
|
1043 |
test(TheFs.IsValidName(_L(".ext"),param));
|
sl@0
|
1044 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1045 |
|
sl@0
|
1046 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg"),param));
|
sl@0
|
1047 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1048 |
|
sl@0
|
1049 |
test(TheFs.IsValidName(_L("C:\\asdf..blarg"),param));
|
sl@0
|
1050 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1051 |
|
sl@0
|
1052 |
// Test multiple evil characters - parsing occurs from right to left
|
sl@0
|
1053 |
// except that wildcarded characters take priority and are picked out first
|
sl@0
|
1054 |
|
sl@0
|
1055 |
test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mno<pqr*stu"),param)==EFalse);
|
sl@0
|
1056 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1057 |
test(param.InvalidCharPos() == 24);
|
sl@0
|
1058 |
|
sl@0
|
1059 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno?pqr"),param)==EFalse);
|
sl@0
|
1060 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1061 |
test(param.InvalidCharPos() == 20);
|
sl@0
|
1062 |
|
sl@0
|
1063 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno"),param)==EFalse);
|
sl@0
|
1064 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1065 |
test(param.InvalidCharPos() == 16);
|
sl@0
|
1066 |
|
sl@0
|
1067 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl:mno"),param)==EFalse);
|
sl@0
|
1068 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1069 |
test(param.InvalidCharPos() == 16);
|
sl@0
|
1070 |
|
sl@0
|
1071 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl"),param)==EFalse);
|
sl@0
|
1072 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1073 |
test(param.InvalidCharPos() == 12);
|
sl@0
|
1074 |
|
sl@0
|
1075 |
test(TheFs.IsValidName(_L("abc>def|ghi<jkl"),param)==EFalse);
|
sl@0
|
1076 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1077 |
test(param.InvalidCharPos() == 12);
|
sl@0
|
1078 |
|
sl@0
|
1079 |
test(TheFs.IsValidName(_L("abc>def|ghi"),param)==EFalse);
|
sl@0
|
1080 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1081 |
test(param.InvalidCharPos() == 8);
|
sl@0
|
1082 |
|
sl@0
|
1083 |
test(TheFs.IsValidName(_L("abc>def|ghi"),param)==EFalse);
|
sl@0
|
1084 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1085 |
test(param.InvalidCharPos() == 8);
|
sl@0
|
1086 |
|
sl@0
|
1087 |
test(TheFs.IsValidName(_L("abc>def"),param)==EFalse);
|
sl@0
|
1088 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1089 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
1090 |
|
sl@0
|
1091 |
test(TheFs.IsValidName(_L("abc>def"),param)==EFalse);
|
sl@0
|
1092 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1093 |
test(param.InvalidCharPos() == 4);
|
sl@0
|
1094 |
|
sl@0
|
1095 |
test(!TheFs.IsValidName(_L("C:\\v123456.."),param));
|
sl@0
|
1096 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1097 |
test(param.InvalidCharPos() == 11);
|
sl@0
|
1098 |
|
sl@0
|
1099 |
test(!TheFs.IsValidName(_L("C:\\v123456.."),param));
|
sl@0
|
1100 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter);
|
sl@0
|
1101 |
test(param.InvalidCharPos() == 11);
|
sl@0
|
1102 |
|
sl@0
|
1103 |
test(TheFs.IsValidName(_L("abc"),param)); // Valid name
|
sl@0
|
1104 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1105 |
|
sl@0
|
1106 |
test(TheFs.IsValidName(_L("abc"),param)); // Valid name
|
sl@0
|
1107 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1108 |
|
sl@0
|
1109 |
test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param)); // Valid name
|
sl@0
|
1110 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1111 |
|
sl@0
|
1112 |
test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param)); // Valid name
|
sl@0
|
1113 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1114 |
|
sl@0
|
1115 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param)); // Valid name
|
sl@0
|
1116 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1117 |
|
sl@0
|
1118 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param)); // Valid name
|
sl@0
|
1119 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1120 |
|
sl@0
|
1121 |
test(TheFs.IsValidName(_L("\'"),param)); // Valid name
|
sl@0
|
1122 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1123 |
|
sl@0
|
1124 |
test(TheFs.IsValidName(_L("\'"),param)); // Valid name
|
sl@0
|
1125 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1126 |
|
sl@0
|
1127 |
//testing directory names
|
sl@0
|
1128 |
test(TheFs.IsValidName(_L("\\"),param));
|
sl@0
|
1129 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name
|
sl@0
|
1130 |
|
sl@0
|
1131 |
test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),param));
|
sl@0
|
1132 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name
|
sl@0
|
1133 |
|
sl@0
|
1134 |
|
sl@0
|
1135 |
test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),param));
|
sl@0
|
1136 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name
|
sl@0
|
1137 |
|
sl@0
|
1138 |
test(TheFs.IsValidName(_L("file1.txt\\\\"),param) == EFalse);
|
sl@0
|
1139 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName);
|
sl@0
|
1140 |
|
sl@0
|
1141 |
// test name which exceeds KMaxFileName only on prepending the session path
|
sl@0
|
1142 |
_LIT(KNameLength250, "AAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAA");
|
sl@0
|
1143 |
if(useDefaultSessionPath)
|
sl@0
|
1144 |
{
|
sl@0
|
1145 |
test(TheFs.IsValidName(KNameLength250, param)==EFalse);
|
sl@0
|
1146 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNameTooLong);
|
sl@0
|
1147 |
break;
|
sl@0
|
1148 |
}
|
sl@0
|
1149 |
else
|
sl@0
|
1150 |
{
|
sl@0
|
1151 |
test(TheFs.IsValidName(KNameLength250, param));
|
sl@0
|
1152 |
test(param.ErrorCode() == RFs::TNameValidParam::ErrNone);
|
sl@0
|
1153 |
}
|
sl@0
|
1154 |
useDefaultSessionPath = ETrue;
|
sl@0
|
1155 |
}
|
sl@0
|
1156 |
}
|
sl@0
|
1157 |
|
sl@0
|
1158 |
|
sl@0
|
1159 |
|
sl@0
|
1160 |
void TestGetMediaSerialNumber()
|
sl@0
|
1161 |
{
|
sl@0
|
1162 |
test.Next(_L("Test RFs::GetMediaSerialNumber"));
|
sl@0
|
1163 |
TInt theDrive;
|
sl@0
|
1164 |
TInt r = TheFs.CharToDrive(gDriveToTest,theDrive);
|
sl@0
|
1165 |
test(r == KErrNone);
|
sl@0
|
1166 |
TMediaSerialNumber serNum;
|
sl@0
|
1167 |
r = TheFs.GetMediaSerialNumber(serNum, theDrive);
|
sl@0
|
1168 |
if (r) test.Printf(_L("RFs::GetMediaSerialNumber returned error %d"), r);
|
sl@0
|
1169 |
test(r == KErrNotSupported || r == KErrNotReady || r == KErrNone);
|
sl@0
|
1170 |
if (r == KErrNotSupported)
|
sl@0
|
1171 |
{
|
sl@0
|
1172 |
test.Printf(_L("MediaSerialNumber: Not Supported\n"));
|
sl@0
|
1173 |
}
|
sl@0
|
1174 |
else
|
sl@0
|
1175 |
{
|
sl@0
|
1176 |
test.Printf(_L("MediaSerialNumber: length=%d\n"), serNum.Length());
|
sl@0
|
1177 |
TBuf<20> str;
|
sl@0
|
1178 |
_LIT(KNumberString, "%02X");
|
sl@0
|
1179 |
_LIT(KNewLine, "\n");
|
sl@0
|
1180 |
TInt i;
|
sl@0
|
1181 |
for (i = 0; i < serNum.Length(); i++)
|
sl@0
|
1182 |
{
|
sl@0
|
1183 |
str.AppendFormat(KNumberString, serNum[i]);
|
sl@0
|
1184 |
if (i%8 == 7)
|
sl@0
|
1185 |
{
|
sl@0
|
1186 |
str.Append(KNewLine);
|
sl@0
|
1187 |
test.Printf(_L("%S"), &str);
|
sl@0
|
1188 |
str.SetLength(0);
|
sl@0
|
1189 |
}
|
sl@0
|
1190 |
}
|
sl@0
|
1191 |
if (i%8 != 7)
|
sl@0
|
1192 |
{
|
sl@0
|
1193 |
test.Printf(KNewLine);
|
sl@0
|
1194 |
}
|
sl@0
|
1195 |
}
|
sl@0
|
1196 |
}
|
sl@0
|
1197 |
|
sl@0
|
1198 |
|
sl@0
|
1199 |
//--------------------------------------------------------
|
sl@0
|
1200 |
|
sl@0
|
1201 |
/**
|
sl@0
|
1202 |
Create an empty file of specified size.
|
sl@0
|
1203 |
@param aFs ref. to the FS
|
sl@0
|
1204 |
@param aFileName name of the file
|
sl@0
|
1205 |
@param aFileSize size of the file to be created
|
sl@0
|
1206 |
@return KErrNone on success, system-wide error code otherwise
|
sl@0
|
1207 |
*/
|
sl@0
|
1208 |
TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize)
|
sl@0
|
1209 |
{
|
sl@0
|
1210 |
RFile file;
|
sl@0
|
1211 |
TInt nRes;
|
sl@0
|
1212 |
|
sl@0
|
1213 |
nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite);
|
sl@0
|
1214 |
if(nRes != KErrNone)
|
sl@0
|
1215 |
return nRes;
|
sl@0
|
1216 |
|
sl@0
|
1217 |
nRes = file.SetSize(aFileSize);
|
sl@0
|
1218 |
if(nRes != KErrNone)
|
sl@0
|
1219 |
return nRes;
|
sl@0
|
1220 |
|
sl@0
|
1221 |
file.Close();
|
sl@0
|
1222 |
|
sl@0
|
1223 |
return KErrNone;
|
sl@0
|
1224 |
}
|
sl@0
|
1225 |
|
sl@0
|
1226 |
//--------------------------------------------------------
|
sl@0
|
1227 |
|
sl@0
|
1228 |
/**
|
sl@0
|
1229 |
Create a file of specified size filled with some data pattern.
|
sl@0
|
1230 |
@param aFs ref. to the FS
|
sl@0
|
1231 |
@param aFileName name of the file
|
sl@0
|
1232 |
@param aFileSize size of the file to be created
|
sl@0
|
1233 |
@return KErrNone on success, system-wide error code otherwise
|
sl@0
|
1234 |
*/
|
sl@0
|
1235 |
TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize)
|
sl@0
|
1236 |
{
|
sl@0
|
1237 |
TInt nRes;
|
sl@0
|
1238 |
RFile file;
|
sl@0
|
1239 |
|
sl@0
|
1240 |
//-- create a buffer with some data
|
sl@0
|
1241 |
const TUint KBufLength = 0x100;
|
sl@0
|
1242 |
TBuf8<KBufLength> buffer;
|
sl@0
|
1243 |
buffer.SetLength(KBufLength);
|
sl@0
|
1244 |
|
sl@0
|
1245 |
TUint i;
|
sl@0
|
1246 |
|
sl@0
|
1247 |
for(i = 0; i < KBufLength; i++)
|
sl@0
|
1248 |
buffer[i] = static_cast<TUint8> (i) ;
|
sl@0
|
1249 |
|
sl@0
|
1250 |
//-- create a file
|
sl@0
|
1251 |
nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite);
|
sl@0
|
1252 |
if(nRes != KErrNone)
|
sl@0
|
1253 |
return nRes;
|
sl@0
|
1254 |
|
sl@0
|
1255 |
const TUint n1 = aFileSize / KBufLength;
|
sl@0
|
1256 |
const TUint n2 = aFileSize % KBufLength;
|
sl@0
|
1257 |
|
sl@0
|
1258 |
//-- fill the file with the data from buffer
|
sl@0
|
1259 |
for(i=0; i<n1; ++i)
|
sl@0
|
1260 |
{
|
sl@0
|
1261 |
nRes = file.Write(buffer);
|
sl@0
|
1262 |
if(nRes != KErrNone)
|
sl@0
|
1263 |
return nRes;
|
sl@0
|
1264 |
}
|
sl@0
|
1265 |
|
sl@0
|
1266 |
if(n2)
|
sl@0
|
1267 |
{
|
sl@0
|
1268 |
nRes = file.Write(buffer, n2); //-- write the rest of the data
|
sl@0
|
1269 |
if(nRes != KErrNone)
|
sl@0
|
1270 |
return nRes;
|
sl@0
|
1271 |
}
|
sl@0
|
1272 |
|
sl@0
|
1273 |
file.Close();
|
sl@0
|
1274 |
|
sl@0
|
1275 |
return KErrNone;
|
sl@0
|
1276 |
}
|
sl@0
|
1277 |
|
sl@0
|
1278 |
//--------------------------------------------------------
|
sl@0
|
1279 |
|
sl@0
|
1280 |
/**
|
sl@0
|
1281 |
Check if the specified file contains illegitimate information i.e. something different from 0x00, 0xff, 0x03, 0xcc
|
sl@0
|
1282 |
|
sl@0
|
1283 |
@param aFs ref. to the FS
|
sl@0
|
1284 |
@param aFileName name of the file
|
sl@0
|
1285 |
@return KErrNone on success, KErrCorrupt otherwise
|
sl@0
|
1286 |
*/
|
sl@0
|
1287 |
TInt CheckFileContents(RFs& aFs, const TDesC& aFileName)
|
sl@0
|
1288 |
{
|
sl@0
|
1289 |
TInt nRes = KErrNone;
|
sl@0
|
1290 |
RFile file;
|
sl@0
|
1291 |
|
sl@0
|
1292 |
const TInt KBufLength = 0x100;
|
sl@0
|
1293 |
TBuf8<KBufLength> buffer;
|
sl@0
|
1294 |
buffer.SetLength(0);
|
sl@0
|
1295 |
|
sl@0
|
1296 |
//-- open the file
|
sl@0
|
1297 |
nRes = file.Open(aFs, aFileName, EFileRead);
|
sl@0
|
1298 |
test(nRes == KErrNone);
|
sl@0
|
1299 |
|
sl@0
|
1300 |
//-- check file contents
|
sl@0
|
1301 |
TUint nFilePos=0;
|
sl@0
|
1302 |
for(;;)
|
sl@0
|
1303 |
{
|
sl@0
|
1304 |
//-- read data from the file into the buffer
|
sl@0
|
1305 |
nRes = file.Read(buffer);
|
sl@0
|
1306 |
test(nRes == KErrNone);
|
sl@0
|
1307 |
|
sl@0
|
1308 |
if(buffer.Length() == 0)
|
sl@0
|
1309 |
{
|
sl@0
|
1310 |
nRes = KErrNone; //-- read all the file, no illegitimate information found
|
sl@0
|
1311 |
break; //EOF
|
sl@0
|
1312 |
}
|
sl@0
|
1313 |
|
sl@0
|
1314 |
//-- check if the buffer contains only allowed data (RAM page initialisation data, etc. e.g. 0x00, 0xff, 0x03, 0xcc)
|
sl@0
|
1315 |
if(!CheckBufferContents(buffer, nFilePos))
|
sl@0
|
1316 |
{
|
sl@0
|
1317 |
test.Printf(_L("\nCheckFileContents failed ! The file contains illegitimate information!\n"));
|
sl@0
|
1318 |
nRes = KErrCorrupt; //-- indicate that the read buffer contains illegitimate information
|
sl@0
|
1319 |
break; //-- comment this out if you need a full dump of the file
|
sl@0
|
1320 |
}
|
sl@0
|
1321 |
|
sl@0
|
1322 |
nFilePos+=buffer.Length();
|
sl@0
|
1323 |
}
|
sl@0
|
1324 |
|
sl@0
|
1325 |
file.Close();
|
sl@0
|
1326 |
return nRes;
|
sl@0
|
1327 |
}
|
sl@0
|
1328 |
|
sl@0
|
1329 |
//--------------------------------------------------------
|
sl@0
|
1330 |
|
sl@0
|
1331 |
/**
|
sl@0
|
1332 |
Check if the buffer contains illegitimate information i.e. something different from 0x00, 0xff, 0x03, 0xcc
|
sl@0
|
1333 |
|
sl@0
|
1334 |
@param aBuffer buffer descriptor to check
|
sl@0
|
1335 |
@param aPrintBaseAddr dump base address, used for dumping buffer only
|
sl@0
|
1336 |
@return ETrue on success
|
sl@0
|
1337 |
*/
|
sl@0
|
1338 |
TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr/*=0*/)
|
sl@0
|
1339 |
{
|
sl@0
|
1340 |
TBool bRes = ETrue;
|
sl@0
|
1341 |
|
sl@0
|
1342 |
//-- check if the buffer filled with allowable data (RAM page initialisation data or something similar)
|
sl@0
|
1343 |
//-- but not something meaningful.
|
sl@0
|
1344 |
//-- allowable bytes: 0x00, 0x03, 0xff, 0xcc
|
sl@0
|
1345 |
for(TInt i=0; i<aBuffer.Size(); ++i)
|
sl@0
|
1346 |
{
|
sl@0
|
1347 |
TUint8 byte = aBuffer[i];
|
sl@0
|
1348 |
if(byte != 0x00 && byte != 0x03 && byte != 0xff && byte != 0xcc )
|
sl@0
|
1349 |
{
|
sl@0
|
1350 |
bRes = EFalse;
|
sl@0
|
1351 |
break;
|
sl@0
|
1352 |
}
|
sl@0
|
1353 |
}
|
sl@0
|
1354 |
|
sl@0
|
1355 |
//-- dump the buffer if it contains anything different than allowed data
|
sl@0
|
1356 |
if (!bRes)
|
sl@0
|
1357 |
{
|
sl@0
|
1358 |
for (TInt n=0; n<aBuffer.Size(); )
|
sl@0
|
1359 |
{
|
sl@0
|
1360 |
TBuf16<3> byteBuffer;
|
sl@0
|
1361 |
TBuf16<256> lineBuffer;
|
sl@0
|
1362 |
lineBuffer.Format(_L("%08X: "), aPrintBaseAddr+n);
|
sl@0
|
1363 |
for (TInt m=0; m<16 && n<aBuffer.Size(); m++, n++)
|
sl@0
|
1364 |
{
|
sl@0
|
1365 |
byteBuffer.Format(_L("%02X "), aBuffer[n]);
|
sl@0
|
1366 |
lineBuffer.Append(byteBuffer);
|
sl@0
|
1367 |
}
|
sl@0
|
1368 |
test.Printf(lineBuffer);
|
sl@0
|
1369 |
}
|
sl@0
|
1370 |
}
|
sl@0
|
1371 |
|
sl@0
|
1372 |
return bRes;
|
sl@0
|
1373 |
}
|
sl@0
|
1374 |
|
sl@0
|
1375 |
|
sl@0
|
1376 |
GLDEF_C void CallTestsL()
|
sl@0
|
1377 |
//
|
sl@0
|
1378 |
// Call tests that may leave
|
sl@0
|
1379 |
//
|
sl@0
|
1380 |
{
|
sl@0
|
1381 |
|
sl@0
|
1382 |
Test1();
|
sl@0
|
1383 |
Test2();
|
sl@0
|
1384 |
Test3();
|
sl@0
|
1385 |
Test4();
|
sl@0
|
1386 |
Test5();
|
sl@0
|
1387 |
Test6();
|
sl@0
|
1388 |
Test7();
|
sl@0
|
1389 |
Test8();
|
sl@0
|
1390 |
Test9();
|
sl@0
|
1391 |
Test10();
|
sl@0
|
1392 |
Test11();
|
sl@0
|
1393 |
Test12();
|
sl@0
|
1394 |
Test13();
|
sl@0
|
1395 |
Test14();
|
sl@0
|
1396 |
Test15();
|
sl@0
|
1397 |
TestGetMediaSerialNumber();
|
sl@0
|
1398 |
}
|