|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\dll\t_loadfail.cpp |
|
15 // Overview: |
|
16 // Tests failure codes when loading a RProcess or RLibrary. |
|
17 // Introduced as test for defect DEF092502 |
|
18 // API Information: |
|
19 // RProcess, RLibrary |
|
20 // Details: |
|
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: |
|
28 // All |
|
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 |
|
35 // |
|
36 // |
|
37 |
|
38 #include <e32test.h> |
|
39 #include <f32file.h> |
|
40 |
|
41 RTest test(_L("T_LOADFAIL")); |
|
42 |
|
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 |
|
45 // image file's name |
|
46 LOCAL_D TInt TestVersionL() |
|
47 { |
|
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. |
|
50 #ifndef __WINS__ |
|
51 RFs rfs; |
|
52 rfs.Connect(); |
|
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)); |
|
57 RLibrary lib; |
|
58 test(KErrCorrupt == lib.Load(KWrongDll)); |
|
59 delete fileman; |
|
60 rfs.Close(); |
|
61 #endif |
|
62 return KErrNone; |
|
63 } |
|
64 |
|
65 TInt E32Main() |
|
66 { |
|
67 test.Title(); |
|
68 |
|
69 test.Printf(_L("Test failure modes/codes when loading bad & absent libraries and processes\n")); |
|
70 |
|
71 test.Start(_L("Test DLL loading fails gracefully")); |
|
72 RLibrary library; |
|
73 |
|
74 // test non-existent DLL loading |
|
75 test(library.Load(_L("t_asdasdsadsasd.dll"))==KErrNotFound); |
|
76 |
|
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); |
|
87 |
|
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); |
|
96 |
|
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); |
|
102 |
|
103 test.Next(_L("Test EXE loading fails gracefully")); |
|
104 RProcess process; |
|
105 |
|
106 // test non-existent EXE loading |
|
107 test(process.Create(_L("t_safcxvxcvsw.exe"), _L("x")) == KErrNotFound); |
|
108 |
|
109 |
|
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); |
|
120 |
|
121 // test loading a too long name fails |
|
122 test(process.Create(ptr, _L("x")) == KErrBadName); |
|
123 |
|
124 test.Next(_L("Test loading dll with incorrect verison number as part of its name")); |
|
125 __UHEAP_MARK; |
|
126 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
127 TRAPD(ret,TestVersionL()); |
|
128 test(ret==KErrNone); |
|
129 delete cleanup; |
|
130 __UHEAP_MARKEND; |
|
131 test.End(); |
|
132 |
|
133 return KErrNone; |
|
134 } |