First public contribution.
1 // Copyright (c) 2006-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 // e32test\dll\t_loadfail.cpp
16 // Tests failure codes when loading a RProcess or RLibrary.
17 // Introduced as test for defect DEF092502
21 // - Test attempting to open a non-existent DLL fails gracefully
22 // - Test attempting to open a DLL of an invalid name fails gracefully
23 // - Test attempting to open a non-existent EXE fails gracefully
24 // - Test attempting to open an EXE of an invalid name fails gracefully
25 // - Test loading a dll with an incorrect version number as part of it name
26 // will return KErrCorupt
27 // Platforms/Drives/Compatibility:
29 // Assumptions/Requirement/Pre-requisites:
30 // Assumes drive 'z' always contains \img\t_ver1{00010001}.dll
31 // Assumes drive 'c' is writeable
32 // Failures and causes:
33 // Base Port information:
34 // Error codes returned on h/w and emulator should be the same
41 RTest test(_L("T_LOADFAIL"));
43 // Test loading dll with incorrect version number in the name returns KErrCorrupt
44 // as the loader will compare the image header version number against that in the
46 LOCAL_D TInt TestVersionL()
48 // Test only valid on target h/w as emulator uses MS Windows loader which doesn't allow verison
49 // no. to be in part of the dll name.
53 CFileMan *fileman = CFileMan::NewL(rfs);
54 _LIT(KCorrectDll,"z:\\img\\t_ver1{00010001}.dll");
55 _LIT(KWrongDll,"c:\\sys\\bin\\t_ver1{00010011}.dll");
56 test(KErrNone == fileman->Copy(KCorrectDll,KWrongDll,CFileMan::ERecurse));
58 test(KErrCorrupt == lib.Load(KWrongDll));
69 test.Printf(_L("Test failure modes/codes when loading bad & absent libraries and processes\n"));
71 test.Start(_L("Test DLL loading fails gracefully"));
74 // test non-existent DLL loading
75 test(library.Load(_L("t_asdasdsadsasd.dll"))==KErrNotFound);
77 // test invalid name loading
78 test(library.Load(_L("z:\\sys\\bin\\")) == KErrNotFound);
79 test(library.Load(_L("\\sys\\bin\\")) == KErrNotFound);
80 test(library.Load(_L("..")) == KErrNotFound);
81 test(library.Load(_L(".")) == KErrNotFound);
82 TInt r = library.Load(_L("\\."));
83 test(r == KErrNotFound || r == KErrAccessDenied);
84 test(library.Load(_L(".\\")) == KErrNotFound);
85 test(library.Load(_L("\\")) == KErrNotFound);
86 test(library.Load(_L("")) == KErrNotFound);
88 // test loading from odd/bad paths
89 test(library.Load(_L("t_foo.dll"), _L("..")) == KErrNotFound);
90 test(library.Load(_L("t_foo.dll"), _L(".")) == KErrNotFound);
91 test(library.Load(_L("t_foo.dll"), _L("\\;")) == KErrNotFound);
92 test(library.Load(_L("t_foo.dll"), _L(";\\")) == KErrNotFound);
93 test(library.Load(_L("t_foo.dll"), _L(";")) == KErrNotFound);
94 test(library.Load(_L("t_foo.dll"), _L("\\")) == KErrNotFound);
95 test(library.Load(_L("t_foo.dll"), _L("")) == KErrNotFound);
97 // test loading a too long name fails
98 TBufC16<KMaxFileName+1> buf;
99 TPtr16 ptr = buf.Des();
100 ptr.SetLength(KMaxFileName+1);
101 test(library.Load(ptr) == KErrBadName);
103 test.Next(_L("Test EXE loading fails gracefully"));
106 // test non-existent EXE loading
107 test(process.Create(_L("t_safcxvxcvsw.exe"), _L("x")) == KErrNotFound);
110 // test invalid name loading
111 test(process.Create(_L("z:\\sys\\bin\\"),_L("x")) == KErrNotFound);
112 test(process.Create(_L("\\sys\\bin\\"),_L("x")) == KErrNotFound);
113 test(process.Create(_L(".."), _L("x")) == KErrNotFound);
114 test(process.Create(_L("."), _L("x")) == KErrNotFound);
115 r = process.Create(_L("\\."), _L("x"));
116 test(r == KErrNotFound || r == KErrAccessDenied);
117 test(process.Create(_L(".\\"), _L("x")) == KErrNotFound);
118 test(process.Create(_L("\\"), _L("x")) == KErrNotFound);
119 test(process.Create(_L(""), _L("x")) == KErrNotFound);
121 // test loading a too long name fails
122 test(process.Create(ptr, _L("x")) == KErrBadName);
124 test.Next(_L("Test loading dll with incorrect verison number as part of its name"));
126 CTrapCleanup* cleanup=CTrapCleanup::New();
127 TRAPD(ret,TestVersionL());