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