First public contribution.
1 // Copyright (c) 2004-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_sysbin.cpp
18 #define __E32TEST_EXTENSION__
22 #include <e32ldr_private.h>
24 _LIT(KCheckFailed,"Check failed %d != %d\n");
26 #define CHECK_EQ(a,b) { if(a!=b) { test.Printf(KCheckFailed,a,b); test(0); } }
28 RTest test(_L("T_SYSBIN"));
30 TBool SysBinEnforced = 0;
36 void CheckFileName(RProcess aProcess, const TDesC& aFileName)
38 TFileName fileName = aProcess.FileName();
39 test(fileName.MatchF(aFileName)==0);
42 _LIT(KExeAInSysBin,"z:\\sys\\bin\\t_sysbina.exe");
43 _LIT(KExeBInSystemPrograms,"z:\\system\\programs\\t_sysbinb.exe");
44 _LIT(KDllAInSysBin,"z:\\sys\\bin\\t_sysbin_dlla.dll");
45 _LIT(KDllBInSystemLibs,"z:\\system\\libs\\t_sysbin_dllb.dll");
47 _LIT(KExeBInSysBin,"z:\\sys\\bin\\t_sysbinb.exe");
48 _LIT(KDllBInSysBin,"z:\\sys\\bin\\t_sysbin_dllb.dll");
50 _LIT(KRamDll,"z:\\sys\\bin\\t_sysbin_dll_ram.dll");
51 _LIT(KDllCInCTest,"c:\\sysbin_test\\t_sysbin_dllc.dll");
52 _LIT(KDllC,"t_sysbin_dllc.dll");
53 _LIT(KDllDInCSysBinTest,"c:\\sys\\bin\\test\\t_sysbin_dlld.dll");
54 _LIT(KDllD,"t_sysbin_dlld.dll");
57 void CheckFileName(RLibrary aLibrary, const TDesC& aFileName)
59 TFileName fileName = aLibrary.FileName();
60 test(fileName.MatchF(aFileName)==0);
65 void TestExeB(const TDesC& aFileName)
68 TInt r = p.Create(aFileName,KNullDesC);
72 CHECK_EQ(r,KErrNotFound)
75 CheckFileName(p,KExeBInSysBin);
83 CheckFileName(p,KExeBInSystemPrograms);
91 void TestDllB(const TDesC& aFileName)
94 TInt r = l.Load(aFileName);
98 CHECK_EQ(r,KErrNotFound)
101 CheckFileName(l,KDllBInSysBin);
108 CheckFileName(l,KDllBInSystemLibs);
115 void TestDllC(const TDesC& aFileName,const TDesC& aPath)
118 test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
119 TInt r = l.Load(aFileName,aPath);
121 CHECK_EQ(r,KErrNotFound)
125 CheckFileName(l,KDllCInCTest);
132 void TestDllD(const TDesC& aFileName,const TDesC& aPath)
135 test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
136 TInt r = l.Load(aFileName,aPath);
138 CheckFileName(l,KDllDInCSysBinTest);
144 GLDEF_C TInt E32Main()
146 SysBinEnforced=PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin);
154 test( KErrNone == TheFs.Connect() );
155 RunningFromROM = TheFs.IsFileInRom(RProcess().FileName())!=0;
157 // Turn off evil lazy dll unloading
160 test_KErrNone(l.Connect());
161 test_KErrNone(l.CancelLazyDllUnload());
165 CTrapCleanup* ct = CTrapCleanup::New();
167 TRAP(r, TheFileMan=CFileMan::NewL(TheFs));
170 test.Start(_L("Check loading an EXE which lives in \\SYS\\BIN"));
172 test.Start(_L("Load without path or ext"));
173 r = p.Create(_L("T_SYSBINa"),KNullDesC);
175 CheckFileName(p,KExeAInSysBin);
179 test.Next(_L("Load without path"));
180 r = p.Create(_L("T_SYSBINa.EXE"),KNullDesC);
182 CheckFileName(p,KExeAInSysBin);
186 test.Next(_L("Load with path but without ext"));
187 r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa"),KNullDesC);
189 CheckFileName(p,KExeAInSysBin);
193 test.Next(_L("Load with path and ext"));
194 r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa.EXE"),KNullDesC);
196 CheckFileName(p,KExeAInSysBin);
200 test.Next(_L("Load with SYSTEM\\PROGRAMS path and without ext"));
201 r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa"),KNullDesC);
203 CHECK_EQ(r,KErrNotFound)
207 CheckFileName(p,KExeAInSysBin);
212 test.Next(_L("Load with SYSTEM\\PROGRAMS path and with ext"));
213 r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa.EXE"),KNullDesC);
215 CHECK_EQ(r,KErrNotFound)
219 CheckFileName(p,KExeAInSysBin);
226 test.Next(_L("Check loading an EXE which lives in \\SYSTEM\\PROGRAMS"));
230 test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
234 test.Start(_L("Load without path or ext"));
235 TestExeB(_L("T_SYSBINb"));
237 test.Next(_L("Load without path"));
238 TestExeB(_L("T_SYSBINb.EXE"));
240 test.Next(_L("Load with path but without ext"));
241 TestExeB(_L("\\System\\programs\\T_SYSBINb"));
243 test.Next(_L("Load with path and ext"));
244 TestExeB(_L("\\System\\programs\\T_SYSBINb.EXE"));
249 test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN"));
251 test.Start(_L("Load without path or ext"));
252 r = l.Load(_L("T_SYSBIN_DLLa"));
254 CheckFileName(l,KDllAInSysBin);
257 test.Next(_L("Load without path"));
258 r = l.Load(_L("T_SYSBIN_DLLa.DLL"));
260 CheckFileName(l,KDllAInSysBin);
263 test.Next(_L("Load with path but without ext"));
264 r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa"));
266 CheckFileName(l,KDllAInSysBin);
269 test.Next(_L("Load with path and ext"));
270 r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa.DLL"));
272 CheckFileName(l,KDllAInSysBin);
275 test.Next(_L("Load with SYSTEM\\LIBS path and without ext"));
276 r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa"));
278 CHECK_EQ(r,KErrNotFound)
282 CheckFileName(l,KDllAInSysBin);
286 test.Next(_L("Load with SYSTEM\\LIBS path and with ext"));
287 r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa.DLL"));
289 CHECK_EQ(r,KErrNotFound)
293 CheckFileName(l,KDllAInSysBin);
299 test.Next(_L("Check loading an DLL which lives in \\SYSTEM\\LIBS"));
303 test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
307 test.Start(_L("Load without path or ext"));
308 TestDllB(_L("T_SYSBIN_DLLb"));
310 test.Next(_L("Load without path"));
311 TestDllB(_L("T_SYSBIN_DLLb.DLL"));
313 test.Next(_L("Load with path but without ext"));
314 TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb"));
316 test.Next(_L("Load with path and ext"));
317 TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb.DLL"));
322 test.Next(_L("Check loading an DLL which lives in \\SYSBIN_TEST"));
324 r = TheFileMan->Copy(KRamDll,KDllCInCTest,CFileMan::ERecurse);
327 test.Start(_L("Load using full path+name"));
328 TestDllC(KDllCInCTest,KNullDesC);
330 test.Next(_L("Load using separate search path"));
331 TestDllC(KDllC,_L("\\sysbin_test\\"));
333 TestDllC(KDllC,_L("\\sysbin_test"));
334 TestDllC(KDllC,_L("sysbin_test\\"));
335 TestDllC(KDllC,_L("sysbin_test"));
338 TestDllC(KDllC,_L("c:\\sysbin_test\\"));
340 TestDllC(KDllC,_L("c:\\sysbin_test"));
341 TestDllC(KDllC,_L("c:sysbin_test\\"));
342 TestDllC(KDllC,_L("c:sysbin_test"));
347 _LIT(KCTestPath,"c:\\sysbin_test\\");
348 r = TheFileMan->RmDir(KCTestPath);
351 test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN\\TEST"));
353 r = TheFileMan->Copy(KRamDll,KDllDInCSysBinTest,CFileMan::ERecurse);
356 test.Start(_L("Load using full path+name"));
357 TestDllD(KDllDInCSysBinTest,KNullDesC);
359 test.Next(_L("Load using separate search path"));
360 TestDllD(KDllD,_L("\\sys\\bin\\test\\"));
362 TestDllD(KDllD,_L("\\sys\\bin\\test"));
363 TestDllD(KDllD,_L("sys\\bin\\test"));
364 TestDllD(KDllD,_L("sys\\bin\\test\\"));
367 TestDllD(KDllD,_L("c:\\sys\\bin\\test\\"));
369 TestDllD(KDllD,_L("c:\\sys\\bin\\test"));
370 TestDllD(KDllD,_L("c:sys\\bin\\test\\"));
371 TestDllD(KDllD,_L("c:sys\\bin\\test"));
374 TestDllD(KDllD,_L("\\dummy;\\sys\\bin\\test\\"));
375 TestDllD(KDllD,_L("\\sys\\bin\\test\\;\\dummy2"));
376 TestDllD(KDllD,_L("\\dummy1;\\sys\\bin\\test2;\\sys\\bin\\test\\"));
378 TestDllD(KDllD,_L("c:\\dummy;c:\\sys\\bin\\test\\"));
379 TestDllD(KDllD,_L("c:\\sys\\bin\\test\\;c:\\dummy2"));
380 TestDllD(KDllD,_L("c:\\dummy1;c:\\sys\\bin\\test2;c:\\sys\\bin\\test\\"));
384 _LIT(KCTestPath2,"c:\\sys\\bin\\test\\");
385 r = TheFileMan->RmDir(KCTestPath2);