1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_chkuid.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,431 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\server\t_chkuid.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include "t_server.h"
1.24 +#include "t_chlffs.h"
1.25 +
1.26 +#if defined(__WINS__)
1.27 +#define WIN32_LEAN_AND_MEAN
1.28 +#pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
1.29 +#pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union
1.30 +#endif
1.31 +
1.32 +GLDEF_D RTest test(_L("T_CHKUID"));
1.33 +
1.34 +
1.35 +LOCAL_C void CreateUidTestFiles()
1.36 +//
1.37 +// Create files with uids for testing
1.38 +//
1.39 + {
1.40 + // Create \\gSessionPath\\UIDCHKNO.SHT - no uid, zero length
1.41 + RFile file;
1.42 + TInt r=file.Replace(TheFs,_L("UIDCHKNO.SHT"),EFileRead|EFileWrite);
1.43 + test(r==KErrNone);
1.44 + file.Close();
1.45 +
1.46 + // Create \\gSessionPath\\UIDCHKNO.LNG - no uid, long length
1.47 + r=file.Replace(TheFs,_L("UIDCHKNO.LNG"),EFileRead|EFileWrite);
1.48 + test(r==KErrNone);
1.49 + r=file.Write(_L8("Hello World needs to be over 16 bytes"));
1.50 + file.Close();
1.51 +
1.52 + // Create \\gSessionPath\\UIDCHK.BLG - with uid no data
1.53 + r=file.Replace(TheFs,_L("UIDCHK.BLG"),EFileRead|EFileWrite);
1.54 + test(r==KErrNone);
1.55 + TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
1.56 + TCheckedUid checkedUid(uidType);
1.57 + TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
1.58 + r=file.Write(buf);
1.59 + test(r==KErrNone);
1.60 + file.Close();
1.61 +
1.62 + // Create \\gSessionPath\\UIDCHK.MSG - with uid and data
1.63 + r=file.Replace(TheFs,_L("UIDCHK.MSG"),EFileRead|EFileWrite);
1.64 + test(r==KErrNone);
1.65 + TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
1.66 + checkedUid.Set(uidType2);
1.67 + buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
1.68 + r=file.Write(buf);
1.69 + test(r==KErrNone);
1.70 + r=file.Write(_L8("More file data"));
1.71 + test(r==KErrNone);
1.72 + file.Close();
1.73 +
1.74 + // Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
1.75 + r=file.Replace(TheFs,_L("UIDCHK.DAT"),EFileRead|EFileWrite);
1.76 + test(r==KErrNone);
1.77 + TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
1.78 + checkedUid.Set(uidType3);
1.79 + buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
1.80 + r=file.Write(buf);
1.81 + test(r==KErrNone);
1.82 + r=file.Write(_L8("More file data"));
1.83 + test(r==KErrNone);
1.84 + file.Close();
1.85 +
1.86 + // Create \\gSessionPath\\UIDCHK.PE - uid stored in WINS PE file header
1.87 + r=file.Replace(TheFs,_L("UIDWINS.PE"),EFileRead|EFileWrite);
1.88 + test(r==KErrNone);
1.89 +
1.90 +#if defined(__WINS__)
1.91 + if (!IsTestingLFFS())
1.92 + {
1.93 + RFile fileSource;
1.94 + r=fileSource.Open(TheFs,_L("Z:\\TEST\\T_CHKUID.EXE"),EFileShareReadersOnly|EFileRead);
1.95 + test(r==KErrNone);
1.96 +
1.97 + TBuf8<0x100> buffer;
1.98 + do
1.99 + {
1.100 + r=fileSource.Read(buffer);
1.101 + test(r==KErrNone);
1.102 + r=file.Write(buffer);
1.103 + test(r==KErrNone);
1.104 + }
1.105 + while (buffer.Length()==buffer.MaxLength());
1.106 +
1.107 + fileSource.Close();
1.108 + }
1.109 + else
1.110 + {
1.111 + r=file.Write(_L8("Some zany stuff here!"));
1.112 + test(r==KErrNone);
1.113 + }
1.114 +#else
1.115 + r=file.Write(_L8("Some zany stuff here!"));
1.116 + test(r==KErrNone);
1.117 +#endif
1.118 + file.Close();
1.119 + }
1.120 +
1.121 +LOCAL_C void Test1()
1.122 +//
1.123 +// Test GetDir
1.124 +//
1.125 + {
1.126 +
1.127 + test.Next(_L("Use GetDir to check files"));
1.128 + CDir* dum=NULL;
1.129 + TInt r=TheFs.GetDir(_L("UID*"),KEntryAttAllowUid,ESortByName,dum);
1.130 + CDir& dir=*dum;
1.131 + test(r==KErrNone);
1.132 + TInt count=dir.Count();
1.133 + test(count==6);
1.134 +
1.135 + TEntry entry=dir[0];
1.136 + test(entry.iName==_L("UIDCHK.BLG"));
1.137 + test(entry.IsTypeValid());
1.138 + test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D'));
1.139 +
1.140 + entry=dir[1];
1.141 + test(entry.iName==_L("UIDCHK.DAT"));
1.142 + test(entry.IsTypeValid());
1.143 + test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
1.144 +
1.145 + entry=dir[2];
1.146 + test(entry.iName==_L("UIDCHK.MSG"));
1.147 + test(entry.IsTypeValid());
1.148 + test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z'));
1.149 +
1.150 + entry=dir[3];
1.151 + test(entry.iName==_L("UIDCHKNO.LNG"));
1.152 + test(entry.IsTypeValid()==EFalse);
1.153 +
1.154 + entry=dir[4];
1.155 + test(entry.iName==_L("UIDCHKNO.SHT"));
1.156 + test(entry.IsTypeValid()==EFalse);
1.157 +
1.158 + entry=dir[5];
1.159 + test(entry.iName==_L("UIDWINS.PE"));
1.160 +#if defined(__WINS__)
1.161 + TFileName sessionPath;
1.162 + TheFs.SessionPath(sessionPath);
1.163 + if (sessionPath[0]!='C')
1.164 + test(entry.IsTypeValid()==EFalse);
1.165 + else
1.166 + {
1.167 + test(entry.IsTypeValid());
1.168 + test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
1.169 + }
1.170 +#else
1.171 + test(entry.IsTypeValid()==EFalse);
1.172 +#endif
1.173 + delete dum;
1.174 + }
1.175 +
1.176 +LOCAL_C void Test2()
1.177 +//
1.178 +// Test GetDir
1.179 +//
1.180 + {
1.181 +
1.182 + test.Next(_L("Test KEntryAttAllowUid allows uids"));
1.183 + CDir* dum=NULL;
1.184 + TInt r=TheFs.GetDir(_L("UID*"),0,ESortByName,dum);
1.185 + CDir& dir=*dum;
1.186 + test(r==KErrNone);
1.187 + TInt count=dir.Count();
1.188 + test(count==6);
1.189 +
1.190 + TEntry entry=dir[0];
1.191 + test(entry.iName==_L("UIDCHK.BLG"));
1.192 + test(!entry.IsTypeValid());
1.193 +
1.194 + entry=dir[1];
1.195 + test(entry.iName==_L("UIDCHK.DAT"));
1.196 + test(!entry.IsTypeValid());
1.197 +
1.198 + entry=dir[2];
1.199 + test(entry.iName==_L("UIDCHK.MSG"));
1.200 + test(!entry.IsTypeValid());
1.201 +
1.202 + entry=dir[3];
1.203 + test(entry.iName==_L("UIDCHKNO.LNG"));
1.204 + test(entry.IsTypeValid()==EFalse);
1.205 +
1.206 + entry=dir[4];
1.207 + test(entry.iName==_L("UIDCHKNO.SHT"));
1.208 + test(entry.IsTypeValid()==EFalse);
1.209 +
1.210 + entry=dir[5];
1.211 + test(entry.iName==_L("UIDWINS.PE"));
1.212 + test(entry.IsTypeValid()==EFalse);
1.213 + delete dum;
1.214 + }
1.215 +
1.216 +LOCAL_C void Test3()
1.217 +//
1.218 +// Test RFs::Entry()
1.219 +//
1.220 + {
1.221 +
1.222 + test.Next(_L("Use RFs::EntryL() to check files"));
1.223 + TEntry entry;
1.224 + TInt r=TheFs.Entry(_L("UIDCHKNO.SHT"),entry);
1.225 + test(r==KErrNone);
1.226 + test(entry.iName==_L("UIDCHKNO.SHT"));
1.227 + test(entry.IsTypeValid()==EFalse);
1.228 +
1.229 + r=TheFs.Entry(_L("UIDCHKNO.LNG"),entry);
1.230 + test(r==KErrNone);
1.231 + test(entry.iName==_L("UIDCHKNO.LNG"));
1.232 + test(entry.IsTypeValid()==EFalse);
1.233 +
1.234 + r=TheFs.Entry(_L("UIDCHK.MSG"),entry);
1.235 + test(r==KErrNone);
1.236 + test(entry.iName==_L("UIDCHK.MSG"));
1.237 + test(entry.IsTypeValid());
1.238 + test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z'));
1.239 +
1.240 + r=TheFs.Entry(_L("UIDCHK.BLG"),entry);
1.241 + test(r==KErrNone);
1.242 + test(entry.iName==_L("UIDCHK.BLG"));
1.243 + test(entry.IsTypeValid());
1.244 + test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D'));
1.245 +
1.246 + r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
1.247 + test(r==KErrNone);
1.248 + test(entry.iName==_L("UIDCHK.DAT"));
1.249 + test(entry.IsTypeValid());
1.250 + test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
1.251 +
1.252 + r=TheFs.Entry(_L("UIDWINS.PE"),entry);
1.253 + test(r==KErrNone);
1.254 + test(entry.iName==_L("UIDWINS.PE"));
1.255 +#if defined(__WINS__)
1.256 + TFileName sessionPath;
1.257 + TheFs.SessionPath(sessionPath);
1.258 + if (sessionPath[0]!='C')
1.259 + test(entry.IsTypeValid()==EFalse);
1.260 + else
1.261 + {
1.262 + test(entry.IsTypeValid());
1.263 + test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
1.264 + }
1.265 +#else
1.266 + test(entry.IsTypeValid()==EFalse);
1.267 +#endif
1.268 + }
1.269 +
1.270 +LOCAL_C void Test4()
1.271 +//
1.272 +// Test uid's can be read when the file is open
1.273 +//
1.274 +// EFileShareExclusive,EFileShareReadersOnly,EFileShareAny,
1.275 +// EFileStream=0,EFileStreamText=0x100,
1.276 +// EFileRead=0,EFileWrite=0x200
1.277 +//
1.278 + {
1.279 +
1.280 + test.Next(_L("Uids can be read if the file is open"));
1.281 + RFile f;
1.282 + TEntry entry;
1.283 + TInt r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileRead);
1.284 + test(r==KErrNone);
1.285 + r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
1.286 + test(r==KErrNone);
1.287 + test(entry.iName==_L("UIDCHK.DAT"));
1.288 + test(entry.IsTypeValid());
1.289 + test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
1.290 + f.Close();
1.291 +
1.292 + r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileWrite);
1.293 + test(r==KErrNone);
1.294 + r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
1.295 + test(r==KErrNone);
1.296 + test(entry.iName==_L("UIDCHK.DAT"));
1.297 + test(entry.IsTypeValid());
1.298 + test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
1.299 +
1.300 + r=f.SetSize(256);
1.301 + test(r==KErrNone);
1.302 + TBuf8<16> des;
1.303 + r=TheFs.ReadFileSection(_L("UIDCHK.DAT"),0,des,16);
1.304 + test(r==KErrNone);
1.305 +
1.306 + f.Close();
1.307 +
1.308 + r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareReadersOnly|EFileRead);
1.309 + test(r==KErrNone);
1.310 + r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
1.311 + test(r==KErrNone);
1.312 + test(entry.iName==_L("UIDCHK.DAT"));
1.313 + test(entry.IsTypeValid());
1.314 + test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
1.315 + f.Close();
1.316 +
1.317 +// EFileShareReadersOnly|EFileWrite is illegal
1.318 +
1.319 + r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
1.320 + test(r==KErrNone);
1.321 + r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
1.322 + test(r==KErrNone);
1.323 + test(entry.iName==_L("UIDCHK.DAT"));
1.324 + test(entry.IsTypeValid());
1.325 + test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
1.326 + f.Close();
1.327 +
1.328 + r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
1.329 + test(r==KErrNone);
1.330 +
1.331 + RFile secondFile;
1.332 + r=secondFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
1.333 + test(r==KErrNone);
1.334 +
1.335 + RFile thirdFile;
1.336 + r=thirdFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
1.337 + test(r==KErrNone);
1.338 +
1.339 + r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
1.340 + test(r==KErrNone);
1.341 + test(entry.iName==_L("UIDCHK.DAT"));
1.342 + test(entry.IsTypeValid());
1.343 + test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
1.344 + f.Close();
1.345 + secondFile.Close();
1.346 + thirdFile.Close();
1.347 +
1.348 + r=f.Open(TheFs,_L("UIDWINS.PE"),EFileShareAny|EFileWrite);
1.349 + test(r==KErrNone);
1.350 +
1.351 + r=TheFs.Entry(_L("UIDWINS.PE"),entry);
1.352 + test(r==KErrNone);
1.353 + test(entry.iName==_L("UIDWINS.PE"));
1.354 +#if defined(__WINS__)
1.355 + TFileName sessionPath;
1.356 + TheFs.SessionPath(sessionPath);
1.357 + if (sessionPath[0]!='C')
1.358 + test(entry.IsTypeValid()==EFalse);
1.359 + else
1.360 + {
1.361 + test(entry.IsTypeValid());
1.362 + test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
1.363 + }
1.364 +#else
1.365 + test(entry.IsTypeValid()==EFalse);
1.366 +#endif
1.367 + f.Close();
1.368 + }
1.369 +
1.370 +LOCAL_C void TestZ()
1.371 +//
1.372 +// Test Rom filesystem
1.373 +//
1.374 + {
1.375 +
1.376 + CDir* dum=NULL;
1.377 +
1.378 + TInt r=TheFs.GetDir(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\*"):_L("Z:\\System\\Bin\\*"),KEntryAttAllowUid,0,dum);
1.379 +
1.380 + if (r==KErrNotReady)
1.381 + {
1.382 + test.Printf(_L("Error: Unable to open Z:\n"));
1.383 + return;
1.384 + }
1.385 + test(r==KErrNone);
1.386 + CDir& dir=*dum;
1.387 + TInt count=dir.Count();
1.388 + if (count==0)
1.389 + test.Printf(_L("No files present on Z:\\*\n"));
1.390 + while (count--)
1.391 + {
1.392 + TBuf<32> UID;
1.393 + if (dir[count].IsTypeValid()==EFalse)
1.394 + UID=_L("INVALID");
1.395 + else
1.396 + {
1.397 + UID=dir[count].iType[0].Name();
1.398 + UID.Append(dir[count].iType[1].Name());
1.399 + UID.Append(dir[count].iType[2].Name());
1.400 + }
1.401 + test.Printf(_L("FILE: %S UID %S\n"),&dir[count].iName,&UID);
1.402 + }
1.403 + delete &dir;
1.404 + TEntry entry;
1.405 + r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\ELOCAL.FSY"):_L("Z:\\System\\Bin\\ELOCAL.FSY"),entry);
1.406 + }
1.407 +
1.408 +GLDEF_C void CallTestsL(void)
1.409 +//
1.410 +// Do all tests
1.411 +//
1.412 + {
1.413 +
1.414 + TBuf<64> b;
1.415 +
1.416 + TFileName sessionPath;
1.417 +
1.418 + TInt r=TheFs.SessionPath(sessionPath);
1.419 + test(r==KErrNone);
1.420 + TChar driveLetter=sessionPath[0];
1.421 + b.Format(_L("Testing filesystem on %c:"),(TText)driveLetter);
1.422 + test.Next(b);
1.423 +
1.424 + CreateUidTestFiles();
1.425 + Test1();
1.426 + Test2();
1.427 + Test3();
1.428 + Test4();
1.429 +
1.430 + test.Next(_L("Testing filesystem on Z:"));
1.431 + TRAP(r,TestZ());
1.432 + if (r!=KErrNone)
1.433 + test.Printf(_L("Error: %d\n"),r);
1.434 + }