|
1 // Copyright (c) 2005-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 "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 // t_validateRegistrty.cpp |
|
15 // This file contains the code to test the feature of validate registry for ECom when only a |
|
16 // RSC file is removed. It is for DEF073338: ECom Incorrectly Validates Registry using DLL Existence |
|
17 // |
|
18 // |
|
19 |
|
20 #include <e32test.h> |
|
21 #include <e32panic.h> |
|
22 #include <f32file.h> |
|
23 #include <bautils.h> |
|
24 #include "../EcomTestUtils/EcomTestUtils.h" |
|
25 |
|
26 #include <ecom/ecom.h> |
|
27 #include "EComUidCodes.h" |
|
28 #include "Interface.h" // interface to Plugins |
|
29 #define UNUSED_VAR(a) a = a |
|
30 |
|
31 // RAM Only RSC and DLL for testing purpose. |
|
32 _LIT(KEComPluginDLL, "Z:\\RAMOnly\\DefectPlugin.dll"); |
|
33 _LIT(KEComPluginRSC, "Z:\\RAMOnly\\DefectPlugin.rsc"); |
|
34 |
|
35 _LIT(KEComPluginDLLOnC, "C:\\sys\\bin\\DefectPlugin.dll"); |
|
36 _LIT(KEComPluginRSCOnC, "C:\\Resource\\Plugins\\DefectPlugin.rsc"); |
|
37 // This Rsc file is just used to trigger a ECom rediscovery. |
|
38 _LIT(KEComInvalidRscOnZ, "z:\\RAMOnly\\InvalidSIDPlugin.rsc"); |
|
39 _LIT(KEComInvalidRscOnC, "c:\\resource\\plugins\\InvalidSIDPlugin.rsc"); |
|
40 |
|
41 const TInt KOneSecond = 1000000; |
|
42 |
|
43 LOCAL_D RTest test(_L("t_validateRegistry.exe")); |
|
44 |
|
45 /** |
|
46 Kill Ecom Server for testing purposes |
|
47 */ |
|
48 static void KillEComServerL() |
|
49 { |
|
50 //Need to ensure that the EComServer process is killed before even starting this test by using |
|
51 //the EComTestUtils library |
|
52 _LIT(KEComServerProcessName,"ecomserver"); |
|
53 TRAPD(error, EComTestUtils::KillProcessL(KEComServerProcessName)); |
|
54 UNUSED_VAR(error); |
|
55 } |
|
56 |
|
57 /** |
|
58 Copies the Plugins to specific folder for testing purpose |
|
59 */ |
|
60 LOCAL_C void CopyPlugin() |
|
61 { |
|
62 test.Printf(_L("\nCopying plugins into C drive... ")); |
|
63 TInt err=KErrNone; |
|
64 TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginDLL, KEComPluginDLLOnC)); |
|
65 test(err==KErrNone); |
|
66 TRAP(err, EComTestUtils::FileManCopyFileL(KEComPluginRSC, KEComPluginRSCOnC)); |
|
67 test(err==KErrNone); |
|
68 // Give ECOM a chance to discover new plugins. |
|
69 // Otherwise ListImplementationsL could fail to find requested implementations. |
|
70 User::After(KOneSecond * 3); |
|
71 } |
|
72 |
|
73 /** |
|
74 Deletes Plugin from the RAM for cleanup purpose |
|
75 */ |
|
76 LOCAL_C void DeletePlugin() |
|
77 { |
|
78 test.Printf(_L("\nRemoving plugins to clean environment... ")); |
|
79 TInt err=KErrNone; |
|
80 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginDLLOnC)); |
|
81 test(err==KErrNone || err==KErrNotFound); |
|
82 TRAP(err, EComTestUtils::FileManDeleteFileL(KEComPluginRSCOnC)); |
|
83 test(err==KErrNone || err==KErrNotFound); |
|
84 } |
|
85 |
|
86 /** |
|
87 @SYMTestCaseID SYSLIB-ECOM-CT-1489 |
|
88 @SYMTestCaseDesc Tests to ensure that only the RSC file is deleted, then the corresponding |
|
89 DLL should be deleted from the registry. |
|
90 |
|
91 @SYMTestPriority High |
|
92 @SYMTestActions First kill the ECom Server, then copy the plugin to C drive. |
|
93 Next call REComSession::ListImplementations() to start up ecom server |
|
94 and check the discovery result. delete the plugin RSC file, which |
|
95 triggers ecom rediscovery. |
|
96 Now call REComSession::ListImplementations() and check if the |
|
97 plugin is deleted. |
|
98 @SYMTestExpectedResults The test must not fail. |
|
99 */ |
|
100 |
|
101 /** |
|
102 The following plugin will be used for test and copied to the C drive. |
|
103 |
|
104 Interface UID DLL UID Imp. UID Version DllFile RSCFile |
|
105 ------------------------------------------------------------------------------------------------------------------------------------------ |
|
106 0x102797A1 0x102797A0 0x102797A2 1 C:\\sys\\bin\\DefectPlugin.dll C:\\resource\\plugins\\DefectPlugin.RSC |
|
107 |
|
108 **/ |
|
109 |
|
110 LOCAL_C void ValidateRegistryAgainstRscL() |
|
111 { |
|
112 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1489 ")); |
|
113 __UHEAP_MARK; |
|
114 // before strating the test, kill the EcomServer which is probably running from |
|
115 // the previous tests. |
|
116 KillEComServerL(); |
|
117 DeletePlugin(); |
|
118 // copy the plugin to C drive. |
|
119 CopyPlugin(); |
|
120 |
|
121 TUid interfaceUid={0x102797A1}; |
|
122 RImplInfoPtrArray implArray; |
|
123 // normal discovery, ECom should discover the plugin |
|
124 REComSession::ListImplementationsL(interfaceUid, implArray); |
|
125 |
|
126 test(implArray.Count()==1); |
|
127 //Check that the implementation uid returned matched the specs above |
|
128 TUid implUid = implArray[0]->ImplementationUid(); |
|
129 TInt version = implArray[0]->Version(); |
|
130 TInt drive = implArray[0]->Drive(); |
|
131 // imp. uid |
|
132 test(implUid.iUid == 0x102797A2); |
|
133 // version |
|
134 test(version == 1); |
|
135 // C drive |
|
136 test(drive == EDriveC); |
|
137 |
|
138 // ECom Server is running. |
|
139 // Delete the plugin RSC file but not the corresponding DLL file, ECom rediscovery is triggered. |
|
140 TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComPluginRSCOnC)); |
|
141 test(err==KErrNone); |
|
142 |
|
143 // Give ECOM a chance to do the rediscovery. |
|
144 // Otherwise ListImplementationsL could fail. |
|
145 User::After(KOneSecond * 3); |
|
146 REComSession::ListImplementationsL(interfaceUid, implArray); |
|
147 // Since the RSC file is deleted, the corresponding DLL should be deleted |
|
148 // from the ECom registry. |
|
149 test(implArray.Count()==0); |
|
150 |
|
151 //clean up |
|
152 implArray.ResetAndDestroy(); |
|
153 REComSession::FinalClose(); |
|
154 KillEComServerL(); |
|
155 __UHEAP_MARKEND; |
|
156 } |
|
157 |
|
158 /** |
|
159 @SYMTestCaseID SYSLIB-ECOM-CT-1490 |
|
160 @SYMTestCaseDesc Tests to ensure that if the DLL file is deleted and trigger a ECom rediscovery, then the corresponding |
|
161 DLL should be deleted from the registry. |
|
162 |
|
163 @SYMTestPriority High |
|
164 @SYMTestActions First kill the ECom Server, then copy the plugin to C drive. |
|
165 Next call REComSession::ListImplementations() to start up ecom server |
|
166 and check the discovery result. delete the plugin DLL file, and copy a RSC file to |
|
167 c:\resource\plugins\,which triggers ecom rediscovery. |
|
168 Now call REComSession::ListImplementations() and check if the |
|
169 plugin is deleted. |
|
170 @SYMTestExpectedResults The test must not fail. |
|
171 */ |
|
172 |
|
173 /** |
|
174 The following plugin will be used for test and copied to the C drive. |
|
175 |
|
176 Interface UID DLL UID Imp. UID Version DllFile RSCFile |
|
177 ------------------------------------------------------------------------------------------------------------------------------------------ |
|
178 0x102797A1 0x102797A0 0x102797A2 1 C:\\sys\\bin\\DefectPlugin.dll C:\\resource\\plugins\\DefectPlugin.RSC |
|
179 |
|
180 **/ |
|
181 LOCAL_C void ValidateRegistryAgainstDllL() |
|
182 { |
|
183 test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1490 ")); |
|
184 __UHEAP_MARK; |
|
185 // before strating the test, kill the EcomServer which is probably running from |
|
186 // the previous tests. |
|
187 KillEComServerL(); |
|
188 // copy the plugin to C drive. |
|
189 CopyPlugin(); |
|
190 |
|
191 TUid interfaceUid={0x102797A1}; |
|
192 RImplInfoPtrArray implArray; |
|
193 // normal discovery, ECom should discover the plugin |
|
194 REComSession::ListImplementationsL(interfaceUid, implArray); |
|
195 |
|
196 test(implArray.Count()==1); |
|
197 //Check that the implementation uid returned matched the specs above |
|
198 TUid implUid = implArray[0]->ImplementationUid(); |
|
199 TInt version = implArray[0]->Version(); |
|
200 TInt drive = implArray[0]->Drive(); |
|
201 // imp. uid |
|
202 test(implUid.iUid == 0x102797A2); |
|
203 // version |
|
204 test(version == 1); |
|
205 // C drive |
|
206 test(drive == EDriveC); |
|
207 |
|
208 // ECom Server is running. |
|
209 // delete the plugin DLL file not the RSC file, ECom rediscovery is NOT triggered. |
|
210 TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComPluginDLLOnC)); |
|
211 test(err==KErrNone); |
|
212 |
|
213 // copy a RSC file to C:\resource\plugin\ to cause a ECom rediscovery. |
|
214 TRAP(err, EComTestUtils::FileManCopyFileL(KEComInvalidRscOnZ, KEComInvalidRscOnC)); |
|
215 test(err==KErrNone); |
|
216 // Give ECOM a chance to do the rediscovery. |
|
217 // Otherwise ListImplementationsL could fail. |
|
218 User::After(KOneSecond * 3); |
|
219 |
|
220 REComSession::ListImplementationsL(interfaceUid, implArray); |
|
221 // Since the DLL file is deleted, the corresponding DLL should be deleted |
|
222 // from the ECom registry. |
|
223 test(implArray.Count()==0); |
|
224 |
|
225 //clean up |
|
226 implArray.ResetAndDestroy(); |
|
227 REComSession::FinalClose(); |
|
228 KillEComServerL(); |
|
229 __UHEAP_MARKEND; |
|
230 } |
|
231 |
|
232 typedef void (*ClassFuncPtrL) (void); |
|
233 |
|
234 /** |
|
235 Wrapper function to call all test functions |
|
236 |
|
237 @param testFuncL pointer to test function |
|
238 @param aTestDesc test function name |
|
239 */ |
|
240 LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc) |
|
241 { |
|
242 test.Next(aTestDesc); |
|
243 |
|
244 __UHEAP_MARK; |
|
245 // find out the number of open handles |
|
246 TInt startProcessHandleCount; |
|
247 TInt startThreadHandleCount; |
|
248 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
249 |
|
250 //Call the test function |
|
251 (*testFuncL)(); |
|
252 |
|
253 // check that no handles have leaked |
|
254 TInt endProcessHandleCount; |
|
255 TInt endThreadHandleCount; |
|
256 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
257 |
|
258 test(startThreadHandleCount == endThreadHandleCount); |
|
259 |
|
260 __UHEAP_MARKEND; |
|
261 } |
|
262 |
|
263 |
|
264 LOCAL_C void DoTestsL() |
|
265 { |
|
266 //don't change the order of the tests! |
|
267 __UHEAP_MARK; |
|
268 // Basic tests |
|
269 DoBasicTestL(&ValidateRegistryAgainstRscL, _L("ValidateRegistryAgainstRscL")); |
|
270 DoBasicTestL(&ValidateRegistryAgainstDllL, _L("ValidateRegistryAgainstDllL")); |
|
271 __UHEAP_MARKEND; |
|
272 } |
|
273 |
|
274 |
|
275 GLDEF_C TInt E32Main() |
|
276 { |
|
277 __UHEAP_MARK; |
|
278 |
|
279 test.Title(); |
|
280 test.Start(_L("Validate Registry Tests.")); |
|
281 |
|
282 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
283 CActiveScheduler* scheduler = new(ELeave)CActiveScheduler; |
|
284 CActiveScheduler::Install(scheduler); |
|
285 |
|
286 TRAPD(err,DoTestsL()); |
|
287 // Cleanup files |
|
288 if(err != KErrNone) |
|
289 { |
|
290 DeletePlugin(); |
|
291 REComSession::FinalClose(); |
|
292 } |
|
293 |
|
294 test(err==KErrNone); |
|
295 DeletePlugin(); |
|
296 TRAPD(error,EComTestUtils::FileManDeleteFileL(KEComInvalidRscOnC)); |
|
297 UNUSED_VAR(error); |
|
298 delete scheduler; |
|
299 delete cleanup; |
|
300 |
|
301 test.End(); |
|
302 test.Close(); |
|
303 |
|
304 __UHEAP_MARKEND; |
|
305 return(0); |
|
306 } |