0
|
1 |
// Copyright (c) 1995-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_chkuid.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
189
|
18 |
#define __E32TEST_EXTENSION__
|
0
|
19 |
#include <f32file.h>
|
|
20 |
#include <e32test.h>
|
|
21 |
#include "t_server.h"
|
|
22 |
#include "t_chlffs.h"
|
|
23 |
|
|
24 |
#if defined(__WINS__)
|
|
25 |
#define WIN32_LEAN_AND_MEAN
|
|
26 |
#pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
|
|
27 |
#pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union
|
|
28 |
#endif
|
|
29 |
|
|
30 |
GLDEF_D RTest test(_L("T_CHKUID"));
|
|
31 |
|
|
32 |
|
|
33 |
LOCAL_C void CreateUidTestFiles()
|
|
34 |
//
|
|
35 |
// Create files with uids for testing
|
|
36 |
//
|
|
37 |
{
|
|
38 |
// Create \\gSessionPath\\UIDCHKNO.SHT - no uid, zero length
|
|
39 |
RFile file;
|
|
40 |
TInt r=file.Replace(TheFs,_L("UIDCHKNO.SHT"),EFileRead|EFileWrite);
|
189
|
41 |
test_KErrNone(r);
|
0
|
42 |
file.Close();
|
|
43 |
|
|
44 |
// Create \\gSessionPath\\UIDCHKNO.LNG - no uid, long length
|
|
45 |
r=file.Replace(TheFs,_L("UIDCHKNO.LNG"),EFileRead|EFileWrite);
|
189
|
46 |
test_KErrNone(r);
|
0
|
47 |
r=file.Write(_L8("Hello World needs to be over 16 bytes"));
|
|
48 |
file.Close();
|
|
49 |
|
|
50 |
// Create \\gSessionPath\\UIDCHK.BLG - with uid no data
|
|
51 |
r=file.Replace(TheFs,_L("UIDCHK.BLG"),EFileRead|EFileWrite);
|
189
|
52 |
test_KErrNone(r);
|
0
|
53 |
TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
|
|
54 |
TCheckedUid checkedUid(uidType);
|
|
55 |
TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
|
56 |
r=file.Write(buf);
|
189
|
57 |
test_KErrNone(r);
|
0
|
58 |
file.Close();
|
|
59 |
|
|
60 |
// Create \\gSessionPath\\UIDCHK.MSG - with uid and data
|
|
61 |
r=file.Replace(TheFs,_L("UIDCHK.MSG"),EFileRead|EFileWrite);
|
189
|
62 |
test_KErrNone(r);
|
0
|
63 |
TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
|
|
64 |
checkedUid.Set(uidType2);
|
|
65 |
buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
|
66 |
r=file.Write(buf);
|
189
|
67 |
test_KErrNone(r);
|
0
|
68 |
r=file.Write(_L8("More file data"));
|
189
|
69 |
test_KErrNone(r);
|
0
|
70 |
file.Close();
|
|
71 |
|
|
72 |
// Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
|
|
73 |
r=file.Replace(TheFs,_L("UIDCHK.DAT"),EFileRead|EFileWrite);
|
189
|
74 |
test_KErrNone(r);
|
0
|
75 |
TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
|
|
76 |
checkedUid.Set(uidType3);
|
|
77 |
buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
|
78 |
r=file.Write(buf);
|
189
|
79 |
test_KErrNone(r);
|
0
|
80 |
r=file.Write(_L8("More file data"));
|
189
|
81 |
test_KErrNone(r);
|
0
|
82 |
file.Close();
|
|
83 |
|
|
84 |
// Create \\gSessionPath\\UIDCHK.PE - uid stored in WINS PE file header
|
|
85 |
r=file.Replace(TheFs,_L("UIDWINS.PE"),EFileRead|EFileWrite);
|
189
|
86 |
test_KErrNone(r);
|
0
|
87 |
|
|
88 |
#if defined(__WINS__)
|
|
89 |
if (!IsTestingLFFS())
|
|
90 |
{
|
|
91 |
RFile fileSource;
|
|
92 |
r=fileSource.Open(TheFs,_L("Z:\\TEST\\T_CHKUID.EXE"),EFileShareReadersOnly|EFileRead);
|
189
|
93 |
test_KErrNone(r);
|
0
|
94 |
|
|
95 |
TBuf8<0x100> buffer;
|
|
96 |
do
|
|
97 |
{
|
|
98 |
r=fileSource.Read(buffer);
|
189
|
99 |
test_KErrNone(r);
|
0
|
100 |
r=file.Write(buffer);
|
189
|
101 |
test_KErrNone(r);
|
0
|
102 |
}
|
|
103 |
while (buffer.Length()==buffer.MaxLength());
|
|
104 |
|
|
105 |
fileSource.Close();
|
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
|
109 |
r=file.Write(_L8("Some zany stuff here!"));
|
189
|
110 |
test_KErrNone(r);
|
0
|
111 |
}
|
|
112 |
#else
|
|
113 |
r=file.Write(_L8("Some zany stuff here!"));
|
189
|
114 |
test_KErrNone(r);
|
0
|
115 |
#endif
|
|
116 |
file.Close();
|
|
117 |
}
|
|
118 |
|
|
119 |
LOCAL_C void Test1()
|
|
120 |
//
|
|
121 |
// Test GetDir
|
|
122 |
//
|
|
123 |
{
|
|
124 |
|
|
125 |
test.Next(_L("Use GetDir to check files"));
|
|
126 |
CDir* dum=NULL;
|
|
127 |
TInt r=TheFs.GetDir(_L("UID*"),KEntryAttAllowUid,ESortByName,dum);
|
|
128 |
CDir& dir=*dum;
|
189
|
129 |
test_KErrNone(r);
|
0
|
130 |
TInt count=dir.Count();
|
|
131 |
test(count==6);
|
|
132 |
|
|
133 |
TEntry entry=dir[0];
|
|
134 |
test(entry.iName==_L("UIDCHK.BLG"));
|
|
135 |
test(entry.IsTypeValid());
|
|
136 |
test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D'));
|
|
137 |
|
|
138 |
entry=dir[1];
|
|
139 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
140 |
test(entry.IsTypeValid());
|
|
141 |
test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
|
|
142 |
|
|
143 |
entry=dir[2];
|
|
144 |
test(entry.iName==_L("UIDCHK.MSG"));
|
|
145 |
test(entry.IsTypeValid());
|
|
146 |
test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z'));
|
|
147 |
|
|
148 |
entry=dir[3];
|
|
149 |
test(entry.iName==_L("UIDCHKNO.LNG"));
|
|
150 |
test(entry.IsTypeValid()==EFalse);
|
|
151 |
|
|
152 |
entry=dir[4];
|
|
153 |
test(entry.iName==_L("UIDCHKNO.SHT"));
|
|
154 |
test(entry.IsTypeValid()==EFalse);
|
|
155 |
|
|
156 |
entry=dir[5];
|
|
157 |
test(entry.iName==_L("UIDWINS.PE"));
|
|
158 |
#if defined(__WINS__)
|
|
159 |
TFileName sessionPath;
|
|
160 |
TheFs.SessionPath(sessionPath);
|
|
161 |
if (sessionPath[0]!='C')
|
|
162 |
test(entry.IsTypeValid()==EFalse);
|
|
163 |
else
|
|
164 |
{
|
|
165 |
test(entry.IsTypeValid());
|
|
166 |
test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
|
|
167 |
}
|
|
168 |
#else
|
|
169 |
test(entry.IsTypeValid()==EFalse);
|
|
170 |
#endif
|
|
171 |
delete dum;
|
|
172 |
}
|
|
173 |
|
|
174 |
LOCAL_C void Test2()
|
|
175 |
//
|
|
176 |
// Test GetDir
|
|
177 |
//
|
|
178 |
{
|
|
179 |
|
|
180 |
test.Next(_L("Test KEntryAttAllowUid allows uids"));
|
|
181 |
CDir* dum=NULL;
|
|
182 |
TInt r=TheFs.GetDir(_L("UID*"),0,ESortByName,dum);
|
|
183 |
CDir& dir=*dum;
|
189
|
184 |
test_KErrNone(r);
|
0
|
185 |
TInt count=dir.Count();
|
|
186 |
test(count==6);
|
|
187 |
|
|
188 |
TEntry entry=dir[0];
|
|
189 |
test(entry.iName==_L("UIDCHK.BLG"));
|
|
190 |
test(!entry.IsTypeValid());
|
|
191 |
|
|
192 |
entry=dir[1];
|
|
193 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
194 |
test(!entry.IsTypeValid());
|
|
195 |
|
|
196 |
entry=dir[2];
|
|
197 |
test(entry.iName==_L("UIDCHK.MSG"));
|
|
198 |
test(!entry.IsTypeValid());
|
|
199 |
|
|
200 |
entry=dir[3];
|
|
201 |
test(entry.iName==_L("UIDCHKNO.LNG"));
|
|
202 |
test(entry.IsTypeValid()==EFalse);
|
|
203 |
|
|
204 |
entry=dir[4];
|
|
205 |
test(entry.iName==_L("UIDCHKNO.SHT"));
|
|
206 |
test(entry.IsTypeValid()==EFalse);
|
|
207 |
|
|
208 |
entry=dir[5];
|
|
209 |
test(entry.iName==_L("UIDWINS.PE"));
|
|
210 |
test(entry.IsTypeValid()==EFalse);
|
|
211 |
delete dum;
|
|
212 |
}
|
|
213 |
|
|
214 |
LOCAL_C void Test3()
|
|
215 |
//
|
|
216 |
// Test RFs::Entry()
|
|
217 |
//
|
|
218 |
{
|
|
219 |
|
|
220 |
test.Next(_L("Use RFs::EntryL() to check files"));
|
|
221 |
TEntry entry;
|
|
222 |
TInt r=TheFs.Entry(_L("UIDCHKNO.SHT"),entry);
|
189
|
223 |
test_KErrNone(r);
|
0
|
224 |
test(entry.iName==_L("UIDCHKNO.SHT"));
|
|
225 |
test(entry.IsTypeValid()==EFalse);
|
|
226 |
|
|
227 |
r=TheFs.Entry(_L("UIDCHKNO.LNG"),entry);
|
189
|
228 |
test_KErrNone(r);
|
0
|
229 |
test(entry.iName==_L("UIDCHKNO.LNG"));
|
|
230 |
test(entry.IsTypeValid()==EFalse);
|
|
231 |
|
|
232 |
r=TheFs.Entry(_L("UIDCHK.MSG"),entry);
|
189
|
233 |
test_KErrNone(r);
|
0
|
234 |
test(entry.iName==_L("UIDCHK.MSG"));
|
|
235 |
test(entry.IsTypeValid());
|
|
236 |
test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z'));
|
|
237 |
|
|
238 |
r=TheFs.Entry(_L("UIDCHK.BLG"),entry);
|
189
|
239 |
test_KErrNone(r);
|
0
|
240 |
test(entry.iName==_L("UIDCHK.BLG"));
|
|
241 |
test(entry.IsTypeValid());
|
|
242 |
test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D'));
|
|
243 |
|
|
244 |
r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
|
189
|
245 |
test_KErrNone(r);
|
0
|
246 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
247 |
test(entry.IsTypeValid());
|
|
248 |
test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
|
|
249 |
|
|
250 |
r=TheFs.Entry(_L("UIDWINS.PE"),entry);
|
189
|
251 |
test_KErrNone(r);
|
0
|
252 |
test(entry.iName==_L("UIDWINS.PE"));
|
|
253 |
#if defined(__WINS__)
|
|
254 |
TFileName sessionPath;
|
|
255 |
TheFs.SessionPath(sessionPath);
|
|
256 |
if (sessionPath[0]!='C')
|
|
257 |
test(entry.IsTypeValid()==EFalse);
|
|
258 |
else
|
|
259 |
{
|
|
260 |
test(entry.IsTypeValid());
|
|
261 |
test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
|
|
262 |
}
|
|
263 |
#else
|
|
264 |
test(entry.IsTypeValid()==EFalse);
|
|
265 |
#endif
|
|
266 |
}
|
|
267 |
|
|
268 |
LOCAL_C void Test4()
|
|
269 |
//
|
|
270 |
// Test uid's can be read when the file is open
|
|
271 |
//
|
|
272 |
// EFileShareExclusive,EFileShareReadersOnly,EFileShareAny,
|
|
273 |
// EFileStream=0,EFileStreamText=0x100,
|
|
274 |
// EFileRead=0,EFileWrite=0x200
|
|
275 |
//
|
|
276 |
{
|
|
277 |
|
|
278 |
test.Next(_L("Uids can be read if the file is open"));
|
|
279 |
RFile f;
|
|
280 |
TEntry entry;
|
|
281 |
TInt r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileRead);
|
189
|
282 |
test_KErrNone(r);
|
0
|
283 |
r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
|
189
|
284 |
test_KErrNone(r);
|
0
|
285 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
286 |
test(entry.IsTypeValid());
|
|
287 |
test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
|
|
288 |
f.Close();
|
|
289 |
|
|
290 |
r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileWrite);
|
189
|
291 |
test_KErrNone(r);
|
0
|
292 |
r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
|
189
|
293 |
test_KErrNone(r);
|
0
|
294 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
295 |
test(entry.IsTypeValid());
|
|
296 |
test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
|
|
297 |
|
|
298 |
r=f.SetSize(256);
|
189
|
299 |
test_KErrNone(r);
|
0
|
300 |
TBuf8<16> des;
|
|
301 |
r=TheFs.ReadFileSection(_L("UIDCHK.DAT"),0,des,16);
|
189
|
302 |
test_KErrNone(r);
|
0
|
303 |
|
|
304 |
f.Close();
|
|
305 |
|
|
306 |
r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareReadersOnly|EFileRead);
|
189
|
307 |
test_KErrNone(r);
|
0
|
308 |
r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
|
189
|
309 |
test_KErrNone(r);
|
0
|
310 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
311 |
test(entry.IsTypeValid());
|
|
312 |
test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
|
|
313 |
f.Close();
|
|
314 |
|
|
315 |
// EFileShareReadersOnly|EFileWrite is illegal
|
|
316 |
|
|
317 |
r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
|
189
|
318 |
test_KErrNone(r);
|
0
|
319 |
r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
|
189
|
320 |
test_KErrNone(r);
|
0
|
321 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
322 |
test(entry.IsTypeValid());
|
|
323 |
test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
|
|
324 |
f.Close();
|
|
325 |
|
|
326 |
r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
|
189
|
327 |
test_KErrNone(r);
|
0
|
328 |
|
|
329 |
RFile secondFile;
|
|
330 |
r=secondFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
|
189
|
331 |
test_KErrNone(r);
|
0
|
332 |
|
|
333 |
RFile thirdFile;
|
|
334 |
r=thirdFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
|
189
|
335 |
test_KErrNone(r);
|
0
|
336 |
|
|
337 |
r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
|
189
|
338 |
test_KErrNone(r);
|
0
|
339 |
test(entry.iName==_L("UIDCHK.DAT"));
|
|
340 |
test(entry.IsTypeValid());
|
|
341 |
test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
|
|
342 |
f.Close();
|
|
343 |
secondFile.Close();
|
|
344 |
thirdFile.Close();
|
|
345 |
|
|
346 |
r=f.Open(TheFs,_L("UIDWINS.PE"),EFileShareAny|EFileWrite);
|
189
|
347 |
test_KErrNone(r);
|
0
|
348 |
|
|
349 |
r=TheFs.Entry(_L("UIDWINS.PE"),entry);
|
189
|
350 |
test_KErrNone(r);
|
0
|
351 |
test(entry.iName==_L("UIDWINS.PE"));
|
|
352 |
#if defined(__WINS__)
|
|
353 |
TFileName sessionPath;
|
|
354 |
TheFs.SessionPath(sessionPath);
|
|
355 |
if (sessionPath[0]!='C')
|
|
356 |
test(entry.IsTypeValid()==EFalse);
|
|
357 |
else
|
|
358 |
{
|
|
359 |
test(entry.IsTypeValid());
|
|
360 |
test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
|
|
361 |
}
|
|
362 |
#else
|
|
363 |
test(entry.IsTypeValid()==EFalse);
|
|
364 |
#endif
|
|
365 |
f.Close();
|
|
366 |
}
|
|
367 |
|
|
368 |
LOCAL_C void TestZ()
|
|
369 |
//
|
|
370 |
// Test Rom filesystem
|
|
371 |
//
|
|
372 |
{
|
|
373 |
|
|
374 |
CDir* dum=NULL;
|
|
375 |
|
|
376 |
TInt r=TheFs.GetDir(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\*"):_L("Z:\\System\\Bin\\*"),KEntryAttAllowUid,0,dum);
|
|
377 |
|
|
378 |
if (r==KErrNotReady)
|
|
379 |
{
|
|
380 |
test.Printf(_L("Error: Unable to open Z:\n"));
|
|
381 |
return;
|
|
382 |
}
|
189
|
383 |
test_KErrNone(r);
|
0
|
384 |
CDir& dir=*dum;
|
|
385 |
TInt count=dir.Count();
|
|
386 |
if (count==0)
|
|
387 |
test.Printf(_L("No files present on Z:\\*\n"));
|
|
388 |
while (count--)
|
|
389 |
{
|
|
390 |
TBuf<32> UID;
|
|
391 |
if (dir[count].IsTypeValid()==EFalse)
|
|
392 |
UID=_L("INVALID");
|
|
393 |
else
|
|
394 |
{
|
|
395 |
UID=dir[count].iType[0].Name();
|
|
396 |
UID.Append(dir[count].iType[1].Name());
|
|
397 |
UID.Append(dir[count].iType[2].Name());
|
|
398 |
}
|
|
399 |
test.Printf(_L("FILE: %S UID %S\n"),&dir[count].iName,&UID);
|
|
400 |
}
|
|
401 |
delete &dir;
|
|
402 |
TEntry entry;
|
|
403 |
r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\ELOCAL.FSY"):_L("Z:\\System\\Bin\\ELOCAL.FSY"),entry);
|
|
404 |
}
|
|
405 |
|
|
406 |
GLDEF_C void CallTestsL(void)
|
|
407 |
//
|
|
408 |
// Do all tests
|
|
409 |
//
|
|
410 |
{
|
|
411 |
|
|
412 |
TBuf<64> b;
|
|
413 |
|
|
414 |
TFileName sessionPath;
|
|
415 |
|
|
416 |
TInt r=TheFs.SessionPath(sessionPath);
|
189
|
417 |
test_KErrNone(r);
|
0
|
418 |
TChar driveLetter=sessionPath[0];
|
|
419 |
b.Format(_L("Testing filesystem on %c:"),(TText)driveLetter);
|
|
420 |
test.Next(b);
|
|
421 |
|
|
422 |
CreateUidTestFiles();
|
|
423 |
Test1();
|
|
424 |
Test2();
|
|
425 |
Test3();
|
|
426 |
Test4();
|
|
427 |
|
|
428 |
test.Next(_L("Testing filesystem on Z:"));
|
|
429 |
TRAP(r,TestZ());
|
|
430 |
if (r!=KErrNone)
|
|
431 |
test.Printf(_L("Error: %d\n"),r);
|
|
432 |
}
|