|
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 "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 // Helper class for ECom test code. Allows various file manipulation operations |
|
15 // that require higher Capabilities than shoud be given to test harnesses. |
|
16 // |
|
17 // |
|
18 |
|
19 #include "EcomTestUtils.h" |
|
20 #include "hal.h" |
|
21 #include <e32rom.h> |
|
22 |
|
23 _LIT(KEcomTestUtilsHelperPanic, "EComTestUtilsHelperPanic"); |
|
24 _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames |
|
25 const TInt KMAxProcessNameLength = 50; // Max process name length. |
|
26 |
|
27 // Processes with high Capablilities to perform restricted operations. |
|
28 _LIT(KProcessMakeWriteable, "t_makefilewriteable"); |
|
29 _LIT(KProcessMakeReadOnly, "t_makefilereadonly"); |
|
30 _LIT(KProcessFileManDeleteFile, "t_processfilemandeletefile.exe"); |
|
31 _LIT(KProcessFileManCopyFile, "t_processfilemancopyfile.exe"); |
|
32 _LIT(KProcessFileManRename, "t_processfilemanrename.exe"); |
|
33 _LIT(KProcessRfsDeleteFile, "t_processrfsdeletefile.exe"); |
|
34 _LIT(KProcessRfsReplaceFile, "t_processrfsreplacefile.exe"); |
|
35 _LIT(KProcessKillProcess, "t_processkillprocess.exe"); |
|
36 _LIT(KProcessFileManDeleteDir, "t_processfilemandeletedir.exe"); |
|
37 _LIT(KProcessRLoaderDeleteFile, "t_processrloaderdeletefile.exe"); |
|
38 |
|
39 /** Name format for locale DLLs. */ |
|
40 _LIT(KLocaleDLLNameFormat, "ELOCL.%02d"); |
|
41 |
|
42 |
|
43 // Start the high capability helper process |
|
44 void LaunchProcessL(const TDesC& aProcessName, const TDesC& aCmdLine) |
|
45 { |
|
46 TRequestStatus stat; |
|
47 RProcess p; |
|
48 User::LeaveIfError(p.Create(aProcessName, aCmdLine)); |
|
49 |
|
50 // Asynchronous logon: completes when process terminates with process |
|
51 // exit code |
|
52 p.Logon(stat); |
|
53 p.Resume(); |
|
54 User::WaitForRequest(stat); |
|
55 |
|
56 TExitType exitType = p.ExitType(); |
|
57 TInt exitReason = p.ExitReason(); |
|
58 __ASSERT_ALWAYS(exitType == EExitKill, User::Panic(KEcomTestUtilsHelperPanic, exitReason)); |
|
59 |
|
60 p.Close(); |
|
61 User::LeaveIfError(exitReason); |
|
62 } |
|
63 |
|
64 /** |
|
65 CFileMan |
|
66 */ |
|
67 EXPORT_C void EComTestUtils::FileManCopyFileL(const TDesC& anOld,const TDesC& aNew) |
|
68 { |
|
69 TBuf<KMaxFileName*2> fileNames(anOld); |
|
70 fileNames.Append(KSeparator); |
|
71 fileNames.Append(aNew); |
|
72 TBufC<KMAxProcessNameLength> copyProcess(KProcessFileManCopyFile); |
|
73 LaunchProcessL(copyProcess, fileNames); |
|
74 } |
|
75 |
|
76 EXPORT_C void EComTestUtils::FileManDeleteFileL(const TDesC& aFile) |
|
77 { |
|
78 TBufC<KMAxProcessNameLength> deleteProcess(KProcessFileManDeleteFile); |
|
79 LaunchProcessL(deleteProcess, aFile); |
|
80 } |
|
81 |
|
82 EXPORT_C void EComTestUtils::FileManRenameL(const TDesC& anOld,const TDesC& aNew) |
|
83 { |
|
84 TBuf<KMaxFileName*2> fileNames(anOld); |
|
85 fileNames.Append(KSeparator); |
|
86 fileNames.Append(aNew); |
|
87 TBufC<KMAxProcessNameLength> renameProcess(KProcessFileManRename); |
|
88 LaunchProcessL(renameProcess, fileNames); |
|
89 } |
|
90 |
|
91 EXPORT_C void EComTestUtils::FileManDeleteDirL(const TDesC& aPath) |
|
92 { |
|
93 TBufC<KMAxProcessNameLength> deleteDirProcess(KProcessFileManDeleteDir); |
|
94 LaunchProcessL(deleteDirProcess, aPath); |
|
95 } |
|
96 |
|
97 /** |
|
98 RFs |
|
99 */ |
|
100 EXPORT_C void EComTestUtils::RfsDeleteFileL(const TDesC& aFile) |
|
101 { |
|
102 TBufC<KMAxProcessNameLength> deleteProcess(KProcessRfsDeleteFile); |
|
103 LaunchProcessL(deleteProcess, aFile); |
|
104 } |
|
105 |
|
106 EXPORT_C void EComTestUtils::RfsReplaceFileL(const TDesC& anOld,const TDesC& aNew) |
|
107 { |
|
108 TBuf<KMaxFileName*2> fileNames(anOld); |
|
109 fileNames.Append(KSeparator); |
|
110 fileNames.Append(aNew); |
|
111 TBufC<KMAxProcessNameLength> replaceProcess(KProcessRfsReplaceFile); |
|
112 LaunchProcessL(replaceProcess, fileNames); |
|
113 } |
|
114 |
|
115 |
|
116 EXPORT_C void EComTestUtils::MakeFileWriteableL(const TDesC& aFile) |
|
117 { |
|
118 TBufC<KMAxProcessNameLength> makeWriteable(KProcessMakeWriteable); |
|
119 LaunchProcessL(makeWriteable, aFile); |
|
120 } |
|
121 |
|
122 EXPORT_C void EComTestUtils::MakeFileReadOnlyL(const TDesC& aFile) |
|
123 { |
|
124 TBufC<KMAxProcessNameLength> makeReadOnly(KProcessMakeReadOnly); |
|
125 LaunchProcessL(makeReadOnly, aFile); |
|
126 } |
|
127 |
|
128 EXPORT_C void EComTestUtils::KillProcessL(const TDesC& aProcessName) |
|
129 { |
|
130 TBuf<KMAxProcessNameLength> killProcess(KProcessKillProcess); |
|
131 LaunchProcessL(killProcess, aProcessName); |
|
132 } |
|
133 |
|
134 |
|
135 /** |
|
136 Switch the current locale to the given language. |
|
137 @param aLang The language to switch to. |
|
138 @leave KErrNotFound If locale DLL corresponding to the language cannot be found. |
|
139 */ |
|
140 EXPORT_C void EComTestUtils::SwitchToLanguageL(TLanguage aLang) |
|
141 { |
|
142 RLibrary library; |
|
143 TBuf<50> libraryName; |
|
144 libraryName.Format(KLocaleDLLNameFormat,aLang); |
|
145 User::LeaveIfError(library.Load(libraryName)); |
|
146 CleanupClosePushL(library); |
|
147 User::LeaveIfError(UserSvr::ChangeLocale(libraryName)); |
|
148 CleanupStack::PopAndDestroy(); // library |
|
149 } |
|
150 |
|
151 |
|
152 /** |
|
153 Ask the loader to delete an file. This function should be used instead |
|
154 of RFs::Delete where the supplied file may be a paged executable, although |
|
155 it can be used for any file. |
|
156 @param aFile The file to be deleted |
|
157 @leave KErrBadName If the supplied filename is not fully qualified. Else any of the Symbian OS error code |
|
158 */ |
|
159 EXPORT_C void EComTestUtils::RLoaderDeleteFileL(const TDesC& aFile) |
|
160 { |
|
161 TBufC<KMAxProcessNameLength> deleteTheProcess(KProcessRLoaderDeleteFile); |
|
162 LaunchProcessL(deleteTheProcess, aFile); |
|
163 } |
|
164 |
|
165 /** |
|
166 Get Rom Build Type i.e. NAND or Default Rom build. |
|
167 This function is created since in some test one needs to find if its a |
|
168 NAND or a Non-Nand build. It returns enum "TRomBuildOption" that states the rom build type. |
|
169 Enum "TRomBuildOption" is defined so that this function can be enhanced for a new Rom build type |
|
170 @param aRfs Input Parameter RFs reference is passed so that we don't need to |
|
171 connect to the file server again. |
|
172 */ |
|
173 EXPORT_C TRomBuildOption EComTestUtils::RomBuildType(const RFs& aRfs) |
|
174 { |
|
175 |
|
176 TRomBuildOption romBuildOption; |
|
177 TDriveInfo driveInfo; |
|
178 |
|
179 aRfs.Drive(driveInfo, EDriveC); |
|
180 |
|
181 //C drive determines if its a NAND or a Non-NAND ROM build as per the |
|
182 //H4-hrp-UserGuide, Thus CDrive's media type is checked if it is |
|
183 //EMediaNANDFlash, EMediaRam or EMediaFlash... |
|
184 //If it is EMediaRam or EMediaFlash it is considered as Default Rom Build. |
|
185 if(driveInfo.iType==EMediaNANDFlash) |
|
186 { |
|
187 romBuildOption = ENandRomBuild; |
|
188 } |
|
189 else |
|
190 { |
|
191 romBuildOption = EDefaultRomBuild; |
|
192 } |
|
193 |
|
194 return romBuildOption; |
|
195 } |
|
196 |
|
197 /* |
|
198 Method is used to detect the hardware configuration of the platform running the tests, |
|
199 including both machine UID and C-drive type. |
|
200 */ |
|
201 EXPORT_C THardwareConfiguration EComTestUtils::GetHardwareConfiguration() |
|
202 { |
|
203 //get the platform type |
|
204 TInt muid; |
|
205 if (KErrNone != HAL::Get(HAL::EMachineUid, muid)) |
|
206 { |
|
207 return EPlatformUnknown; |
|
208 } |
|
209 |
|
210 //determine the ROM confguration (NAND or non-NAND) |
|
211 RFs fs; |
|
212 fs.Connect(); |
|
213 TBool nandBuild = (EComTestUtils::RomBuildType(fs)==ENandRomBuild); |
|
214 fs.Close(); |
|
215 |
|
216 //determine whether this ROM is Demand-Paging enabled |
|
217 TBool DP_rom = false; |
|
218 if (nandBuild) |
|
219 { |
|
220 TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); |
|
221 DP_rom = romHeader->iPageableRomStart; |
|
222 } |
|
223 |
|
224 if (muid == HAL::EMachineUid_OmapH2) |
|
225 { |
|
226 if (!nandBuild) |
|
227 { |
|
228 return EPlatformH2RAM; |
|
229 } |
|
230 else |
|
231 { |
|
232 if (DP_rom) |
|
233 { |
|
234 return EPlatformH2NANDDP; |
|
235 } |
|
236 else |
|
237 { |
|
238 return EPlatformH2NAND; |
|
239 } |
|
240 } |
|
241 } |
|
242 else if (muid == HAL::EMachineUid_OmapH4) |
|
243 { |
|
244 if (!nandBuild) |
|
245 { |
|
246 //Incase the ROM is not a nandBuild, |
|
247 //then there could be a chance that it is a WDP enabled system. |
|
248 //WDP enabled configuration is checked by checking for Media Type of C drive. |
|
249 //Under WDP enabled configuration, the C drive is of type 'Hard Disk' |
|
250 //This is done since the function EComTestUtils::RomBuildType, above, used for a similar purpose, |
|
251 //is also checking the media type of C drive to determine the same. |
|
252 //Currently added this check for WDP enabled in case of H4 'muid == HAL::EMachineUid_OmapH4' only |
|
253 TDriveInfo driveInfo; |
|
254 |
|
255 fs.Connect(); |
|
256 fs.Drive(driveInfo, EDriveC); |
|
257 fs.Close(); |
|
258 |
|
259 if (EMediaHardDisk == driveInfo.iType) |
|
260 { |
|
261 return EPlatformH4MMC; //The system is WDP enabled |
|
262 } |
|
263 |
|
264 return EPlatformH4RAM; |
|
265 } |
|
266 else |
|
267 { |
|
268 if (DP_rom) |
|
269 { |
|
270 return EPlatformH4NANDDP; |
|
271 } |
|
272 else |
|
273 { |
|
274 return EPlatformH4NAND; |
|
275 } |
|
276 } |
|
277 } |
|
278 //For H6 board OMAP3430 |
|
279 else if (muid == HAL::EMachineUid_OmapH6) |
|
280 { |
|
281 if (!nandBuild) |
|
282 { |
|
283 return EPlatformH6RAM; |
|
284 } |
|
285 else |
|
286 { |
|
287 if (DP_rom) |
|
288 { |
|
289 return EPlatformH6NANDDP; |
|
290 } |
|
291 else |
|
292 { |
|
293 return EPlatformH6NAND; |
|
294 } |
|
295 } |
|
296 } // H6 board 3430 ends here |
|
297 else if (muid == HAL::EMachineUid_Win32Emulator) |
|
298 { |
|
299 return EPlatformWINSCW; |
|
300 } |
|
301 else |
|
302 { |
|
303 return EPlatformUnknown; |
|
304 } |
|
305 } |
|
306 |