Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_chkuid.cpp
24 #define WIN32_LEAN_AND_MEAN
25 #pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
26 #pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union
29 GLDEF_D RTest test(_L("T_CHKUID"));
32 LOCAL_C void CreateUidTestFiles()
34 // Create files with uids for testing
37 // Create \\gSessionPath\\UIDCHKNO.SHT - no uid, zero length
39 TInt r=file.Replace(TheFs,_L("UIDCHKNO.SHT"),EFileRead|EFileWrite);
43 // Create \\gSessionPath\\UIDCHKNO.LNG - no uid, long length
44 r=file.Replace(TheFs,_L("UIDCHKNO.LNG"),EFileRead|EFileWrite);
46 r=file.Write(_L8("Hello World needs to be over 16 bytes"));
49 // Create \\gSessionPath\\UIDCHK.BLG - with uid no data
50 r=file.Replace(TheFs,_L("UIDCHK.BLG"),EFileRead|EFileWrite);
52 TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
53 TCheckedUid checkedUid(uidType);
54 TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
59 // Create \\gSessionPath\\UIDCHK.MSG - with uid and data
60 r=file.Replace(TheFs,_L("UIDCHK.MSG"),EFileRead|EFileWrite);
62 TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
63 checkedUid.Set(uidType2);
64 buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
67 r=file.Write(_L8("More file data"));
71 // Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
72 r=file.Replace(TheFs,_L("UIDCHK.DAT"),EFileRead|EFileWrite);
74 TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
75 checkedUid.Set(uidType3);
76 buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
79 r=file.Write(_L8("More file data"));
83 // Create \\gSessionPath\\UIDCHK.PE - uid stored in WINS PE file header
84 r=file.Replace(TheFs,_L("UIDWINS.PE"),EFileRead|EFileWrite);
91 r=fileSource.Open(TheFs,_L("Z:\\TEST\\T_CHKUID.EXE"),EFileShareReadersOnly|EFileRead);
97 r=fileSource.Read(buffer);
102 while (buffer.Length()==buffer.MaxLength());
108 r=file.Write(_L8("Some zany stuff here!"));
112 r=file.Write(_L8("Some zany stuff here!"));
124 test.Next(_L("Use GetDir to check files"));
126 TInt r=TheFs.GetDir(_L("UID*"),KEntryAttAllowUid,ESortByName,dum);
129 TInt count=dir.Count();
133 test(entry.iName==_L("UIDCHK.BLG"));
134 test(entry.IsTypeValid());
135 test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D'));
138 test(entry.iName==_L("UIDCHK.DAT"));
139 test(entry.IsTypeValid());
140 test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
143 test(entry.iName==_L("UIDCHK.MSG"));
144 test(entry.IsTypeValid());
145 test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z'));
148 test(entry.iName==_L("UIDCHKNO.LNG"));
149 test(entry.IsTypeValid()==EFalse);
152 test(entry.iName==_L("UIDCHKNO.SHT"));
153 test(entry.IsTypeValid()==EFalse);
156 test(entry.iName==_L("UIDWINS.PE"));
157 #if defined(__WINS__)
158 TFileName sessionPath;
159 TheFs.SessionPath(sessionPath);
160 if (sessionPath[0]!='C')
161 test(entry.IsTypeValid()==EFalse);
164 test(entry.IsTypeValid());
165 test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
168 test(entry.IsTypeValid()==EFalse);
179 test.Next(_L("Test KEntryAttAllowUid allows uids"));
181 TInt r=TheFs.GetDir(_L("UID*"),0,ESortByName,dum);
184 TInt count=dir.Count();
188 test(entry.iName==_L("UIDCHK.BLG"));
189 test(!entry.IsTypeValid());
192 test(entry.iName==_L("UIDCHK.DAT"));
193 test(!entry.IsTypeValid());
196 test(entry.iName==_L("UIDCHK.MSG"));
197 test(!entry.IsTypeValid());
200 test(entry.iName==_L("UIDCHKNO.LNG"));
201 test(entry.IsTypeValid()==EFalse);
204 test(entry.iName==_L("UIDCHKNO.SHT"));
205 test(entry.IsTypeValid()==EFalse);
208 test(entry.iName==_L("UIDWINS.PE"));
209 test(entry.IsTypeValid()==EFalse);
219 test.Next(_L("Use RFs::EntryL() to check files"));
221 TInt r=TheFs.Entry(_L("UIDCHKNO.SHT"),entry);
223 test(entry.iName==_L("UIDCHKNO.SHT"));
224 test(entry.IsTypeValid()==EFalse);
226 r=TheFs.Entry(_L("UIDCHKNO.LNG"),entry);
228 test(entry.iName==_L("UIDCHKNO.LNG"));
229 test(entry.IsTypeValid()==EFalse);
231 r=TheFs.Entry(_L("UIDCHK.MSG"),entry);
233 test(entry.iName==_L("UIDCHK.MSG"));
234 test(entry.IsTypeValid());
235 test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z'));
237 r=TheFs.Entry(_L("UIDCHK.BLG"),entry);
239 test(entry.iName==_L("UIDCHK.BLG"));
240 test(entry.IsTypeValid());
241 test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D'));
243 r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
245 test(entry.iName==_L("UIDCHK.DAT"));
246 test(entry.IsTypeValid());
247 test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
249 r=TheFs.Entry(_L("UIDWINS.PE"),entry);
251 test(entry.iName==_L("UIDWINS.PE"));
252 #if defined(__WINS__)
253 TFileName sessionPath;
254 TheFs.SessionPath(sessionPath);
255 if (sessionPath[0]!='C')
256 test(entry.IsTypeValid()==EFalse);
259 test(entry.IsTypeValid());
260 test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
263 test(entry.IsTypeValid()==EFalse);
269 // Test uid's can be read when the file is open
271 // EFileShareExclusive,EFileShareReadersOnly,EFileShareAny,
272 // EFileStream=0,EFileStreamText=0x100,
273 // EFileRead=0,EFileWrite=0x200
277 test.Next(_L("Uids can be read if the file is open"));
280 TInt r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileRead);
282 r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
284 test(entry.iName==_L("UIDCHK.DAT"));
285 test(entry.IsTypeValid());
286 test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
289 r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileWrite);
291 r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
293 test(entry.iName==_L("UIDCHK.DAT"));
294 test(entry.IsTypeValid());
295 test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
300 r=TheFs.ReadFileSection(_L("UIDCHK.DAT"),0,des,16);
305 r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareReadersOnly|EFileRead);
307 r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
309 test(entry.iName==_L("UIDCHK.DAT"));
310 test(entry.IsTypeValid());
311 test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
314 // EFileShareReadersOnly|EFileWrite is illegal
316 r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
318 r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
320 test(entry.iName==_L("UIDCHK.DAT"));
321 test(entry.IsTypeValid());
322 test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
325 r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
329 r=secondFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
333 r=thirdFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
336 r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
338 test(entry.iName==_L("UIDCHK.DAT"));
339 test(entry.IsTypeValid());
340 test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
345 r=f.Open(TheFs,_L("UIDWINS.PE"),EFileShareAny|EFileWrite);
348 r=TheFs.Entry(_L("UIDWINS.PE"),entry);
350 test(entry.iName==_L("UIDWINS.PE"));
351 #if defined(__WINS__)
352 TFileName sessionPath;
353 TheFs.SessionPath(sessionPath);
354 if (sessionPath[0]!='C')
355 test(entry.IsTypeValid()==EFalse);
358 test(entry.IsTypeValid());
359 test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
362 test(entry.IsTypeValid()==EFalse);
369 // Test Rom filesystem
375 TInt r=TheFs.GetDir(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\*"):_L("Z:\\System\\Bin\\*"),KEntryAttAllowUid,0,dum);
379 test.Printf(_L("Error: Unable to open Z:\n"));
384 TInt count=dir.Count();
386 test.Printf(_L("No files present on Z:\\*\n"));
390 if (dir[count].IsTypeValid()==EFalse)
394 UID=dir[count].iType[0].Name();
395 UID.Append(dir[count].iType[1].Name());
396 UID.Append(dir[count].iType[2].Name());
398 test.Printf(_L("FILE: %S UID %S\n"),&dir[count].iName,&UID);
402 r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\ELOCAL.FSY"):_L("Z:\\System\\Bin\\ELOCAL.FSY"),entry);
405 GLDEF_C void CallTestsL(void)
413 TFileName sessionPath;
415 TInt r=TheFs.SessionPath(sessionPath);
417 TChar driveLetter=sessionPath[0];
418 b.Format(_L("Testing filesystem on %c:"),(TText)driveLetter);
421 CreateUidTestFiles();
427 test.Next(_L("Testing filesystem on Z:"));
430 test.Printf(_L("Error: %d\n"),r);