1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/EcomTestUtils.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,315 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Helper class for ECom test code. Allows various file manipulation operations
1.18 +// that require higher Capabilities than shoud be given to test harnesses.
1.19 +//
1.20 +//
1.21 +
1.22 +#include "EcomTestUtils.h"
1.23 +#include "hal.h"
1.24 +#include <e32rom.h>
1.25 +
1.26 +_LIT(KEcomTestUtilsHelperPanic, "EComTestUtilsHelperPanic");
1.27 +_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
1.28 +const TInt KMAxProcessNameLength = 50; // Max process name length.
1.29 +
1.30 +// Processes with high Capablilities to perform restricted operations.
1.31 +_LIT(KProcessMakeWriteable, "t_makefilewriteable");
1.32 +_LIT(KProcessMakeReadOnly, "t_makefilereadonly");
1.33 +_LIT(KProcessFileManDeleteFile, "t_processfilemandeletefile.exe");
1.34 +_LIT(KProcessFileManCopyFile, "t_processfilemancopyfile.exe");
1.35 +_LIT(KProcessFileManRename, "t_processfilemanrename.exe");
1.36 +_LIT(KProcessRfsDeleteFile, "t_processrfsdeletefile.exe");
1.37 +_LIT(KProcessRfsReplaceFile, "t_processrfsreplacefile.exe");
1.38 +_LIT(KProcessKillProcess, "t_processkillprocess.exe");
1.39 +_LIT(KProcessFileManDeleteDir, "t_processfilemandeletedir.exe");
1.40 +_LIT(KProcessRLoaderDeleteFile, "t_processrloaderdeletefile.exe");
1.41 +
1.42 +/** Name format for locale DLLs. */
1.43 +_LIT(KLocaleDLLNameFormat, "ELOCL.%02d");
1.44 +
1.45 +
1.46 +// Start the high capability helper process
1.47 +void LaunchProcessL(const TDesC& aProcessName, const TDesC& aCmdLine)
1.48 +{
1.49 + TRequestStatus stat;
1.50 + RProcess p;
1.51 + User::LeaveIfError(p.Create(aProcessName, aCmdLine));
1.52 +
1.53 + // Asynchronous logon: completes when process terminates with process
1.54 + // exit code
1.55 + p.Logon(stat);
1.56 + p.Resume();
1.57 + User::WaitForRequest(stat);
1.58 +
1.59 + TExitType exitType = p.ExitType();
1.60 + TInt exitReason = p.ExitReason();
1.61 + __ASSERT_ALWAYS(exitType == EExitKill, User::Panic(KEcomTestUtilsHelperPanic, exitReason));
1.62 +
1.63 + p.Close();
1.64 + User::LeaveIfError(exitReason);
1.65 +}
1.66 +
1.67 +/**
1.68 +CFileMan
1.69 +*/
1.70 +EXPORT_C void EComTestUtils::FileManCopyFileL(const TDesC& anOld,const TDesC& aNew)
1.71 + {
1.72 + TBuf<KMaxFileName*2> fileNames(anOld);
1.73 + fileNames.Append(KSeparator);
1.74 + fileNames.Append(aNew);
1.75 + TBufC<KMAxProcessNameLength> copyProcess(KProcessFileManCopyFile);
1.76 + LaunchProcessL(copyProcess, fileNames);
1.77 + }
1.78 +
1.79 +EXPORT_C void EComTestUtils::FileManDeleteFileL(const TDesC& aFile)
1.80 + {
1.81 + TBufC<KMAxProcessNameLength> deleteProcess(KProcessFileManDeleteFile);
1.82 + LaunchProcessL(deleteProcess, aFile);
1.83 + }
1.84 +
1.85 +EXPORT_C void EComTestUtils::FileManRenameL(const TDesC& anOld,const TDesC& aNew)
1.86 + {
1.87 + TBuf<KMaxFileName*2> fileNames(anOld);
1.88 + fileNames.Append(KSeparator);
1.89 + fileNames.Append(aNew);
1.90 + TBufC<KMAxProcessNameLength> renameProcess(KProcessFileManRename);
1.91 + LaunchProcessL(renameProcess, fileNames);
1.92 + }
1.93 +
1.94 +EXPORT_C void EComTestUtils::FileManDeleteDirL(const TDesC& aPath)
1.95 + {
1.96 + TBufC<KMAxProcessNameLength> deleteDirProcess(KProcessFileManDeleteDir);
1.97 + LaunchProcessL(deleteDirProcess, aPath);
1.98 + }
1.99 +
1.100 +/**
1.101 +RFs
1.102 +*/
1.103 +EXPORT_C void EComTestUtils::RfsDeleteFileL(const TDesC& aFile)
1.104 + {
1.105 + TBufC<KMAxProcessNameLength> deleteProcess(KProcessRfsDeleteFile);
1.106 + LaunchProcessL(deleteProcess, aFile);
1.107 + }
1.108 +
1.109 +EXPORT_C void EComTestUtils::RfsReplaceFileL(const TDesC& anOld,const TDesC& aNew)
1.110 + {
1.111 + TBuf<KMaxFileName*2> fileNames(anOld);
1.112 + fileNames.Append(KSeparator);
1.113 + fileNames.Append(aNew);
1.114 + TBufC<KMAxProcessNameLength> replaceProcess(KProcessRfsReplaceFile);
1.115 + LaunchProcessL(replaceProcess, fileNames);
1.116 + }
1.117 +
1.118 +
1.119 +EXPORT_C void EComTestUtils::MakeFileWriteableL(const TDesC& aFile)
1.120 + {
1.121 + TBufC<KMAxProcessNameLength> makeWriteable(KProcessMakeWriteable);
1.122 + LaunchProcessL(makeWriteable, aFile);
1.123 + }
1.124 +
1.125 +EXPORT_C void EComTestUtils::MakeFileReadOnlyL(const TDesC& aFile)
1.126 + {
1.127 + TBufC<KMAxProcessNameLength> makeReadOnly(KProcessMakeReadOnly);
1.128 + LaunchProcessL(makeReadOnly, aFile);
1.129 + }
1.130 +
1.131 +EXPORT_C void EComTestUtils::KillProcessL(const TDesC& aProcessName)
1.132 + {
1.133 + TBuf<KMAxProcessNameLength> killProcess(KProcessKillProcess);
1.134 + LaunchProcessL(killProcess, aProcessName);
1.135 + }
1.136 +
1.137 +
1.138 +/**
1.139 +Switch the current locale to the given language.
1.140 +@param aLang The language to switch to.
1.141 +@leave KErrNotFound If locale DLL corresponding to the language cannot be found.
1.142 +*/
1.143 +EXPORT_C void EComTestUtils::SwitchToLanguageL(TLanguage aLang)
1.144 + {
1.145 + RLibrary library;
1.146 + TBuf<50> libraryName;
1.147 + libraryName.Format(KLocaleDLLNameFormat,aLang);
1.148 + User::LeaveIfError(library.Load(libraryName));
1.149 + CleanupClosePushL(library);
1.150 + User::LeaveIfError(UserSvr::ChangeLocale(libraryName));
1.151 + CleanupStack::PopAndDestroy(); // library
1.152 + }
1.153 +
1.154 +
1.155 +/**
1.156 +Ask the loader to delete an file. This function should be used instead
1.157 +of RFs::Delete where the supplied file may be a paged executable, although
1.158 +it can be used for any file.
1.159 +@param aFile The file to be deleted
1.160 +@leave KErrBadName If the supplied filename is not fully qualified. Else any of the Symbian OS error code
1.161 +*/
1.162 +EXPORT_C void EComTestUtils::RLoaderDeleteFileL(const TDesC& aFile)
1.163 + {
1.164 + TBufC<KMAxProcessNameLength> deleteTheProcess(KProcessRLoaderDeleteFile);
1.165 + LaunchProcessL(deleteTheProcess, aFile);
1.166 + }
1.167 +
1.168 +/**
1.169 +Get Rom Build Type i.e. NAND or Default Rom build.
1.170 +This function is created since in some test one needs to find if its a
1.171 +NAND or a Non-Nand build. It returns enum "TRomBuildOption" that states the rom build type.
1.172 +Enum "TRomBuildOption" is defined so that this function can be enhanced for a new Rom build type
1.173 +@param aRfs Input Parameter RFs reference is passed so that we don't need to
1.174 +connect to the file server again.
1.175 +*/
1.176 +EXPORT_C TRomBuildOption EComTestUtils::RomBuildType(const RFs& aRfs)
1.177 + {
1.178 +
1.179 + TRomBuildOption romBuildOption;
1.180 + TDriveInfo driveInfo;
1.181 +
1.182 + aRfs.Drive(driveInfo, EDriveC);
1.183 +
1.184 + //C drive determines if its a NAND or a Non-NAND ROM build as per the
1.185 + //H4-hrp-UserGuide, Thus CDrive's media type is checked if it is
1.186 + //EMediaNANDFlash, EMediaRam or EMediaFlash...
1.187 + //If it is EMediaRam or EMediaFlash it is considered as Default Rom Build.
1.188 + if(driveInfo.iType==EMediaNANDFlash)
1.189 + {
1.190 + romBuildOption = ENandRomBuild;
1.191 + }
1.192 + else
1.193 + {
1.194 + romBuildOption = EDefaultRomBuild;
1.195 + }
1.196 +
1.197 + return romBuildOption;
1.198 + }
1.199 +
1.200 +/*
1.201 +Method is used to detect the hardware configuration of the platform running the tests,
1.202 +including both machine UID and C-drive type.
1.203 +*/
1.204 +EXPORT_C THardwareConfiguration EComTestUtils::GetHardwareConfiguration()
1.205 + {
1.206 + //get the platform type
1.207 + TInt muid;
1.208 + if (KErrNone != HAL::Get(HAL::EMachineUid, muid))
1.209 + {
1.210 + return EPlatformUnknown;
1.211 + }
1.212 +
1.213 + //determine the ROM confguration (NAND or non-NAND)
1.214 + TInt r = KErrNone;
1.215 + RFs fs;
1.216 + r = fs.Connect();
1.217 + if (r != KErrNone)
1.218 + {
1.219 + return r;
1.220 + }
1.221 + TBool nandBuild = (EComTestUtils::RomBuildType(fs)==ENandRomBuild);
1.222 + fs.Close();
1.223 +
1.224 + //determine whether this ROM is Demand-Paging enabled
1.225 + TBool DP_rom = false;
1.226 + if (nandBuild)
1.227 + {
1.228 + TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
1.229 + DP_rom = romHeader->iPageableRomStart;
1.230 + }
1.231 +
1.232 + if (muid == HAL::EMachineUid_OmapH2)
1.233 + {
1.234 + if (!nandBuild)
1.235 + {
1.236 + return EPlatformH2RAM;
1.237 + }
1.238 + else
1.239 + {
1.240 + if (DP_rom)
1.241 + {
1.242 + return EPlatformH2NANDDP;
1.243 + }
1.244 + else
1.245 + {
1.246 + return EPlatformH2NAND;
1.247 + }
1.248 + }
1.249 + }
1.250 + else if (muid == HAL::EMachineUid_OmapH4)
1.251 + {
1.252 + if (!nandBuild)
1.253 + {
1.254 + //Incase the ROM is not a nandBuild,
1.255 + //then there could be a chance that it is a WDP enabled system.
1.256 + //WDP enabled configuration is checked by checking for Media Type of C drive.
1.257 + //Under WDP enabled configuration, the C drive is of type 'Hard Disk'
1.258 + //This is done since the function EComTestUtils::RomBuildType, above, used for a similar purpose,
1.259 + //is also checking the media type of C drive to determine the same.
1.260 + //Currently added this check for WDP enabled in case of H4 'muid == HAL::EMachineUid_OmapH4' only
1.261 + TDriveInfo driveInfo;
1.262 + TInt rf = KErrNone;
1.263 + rf = fs.Connect();
1.264 + if (rf != KErrNone)
1.265 + {
1.266 + return rf;
1.267 + }
1.268 + fs.Drive(driveInfo, EDriveC);
1.269 + fs.Close();
1.270 +
1.271 + if (EMediaHardDisk == driveInfo.iType)
1.272 + {
1.273 + return EPlatformH4MMC; //The system is WDP enabled
1.274 + }
1.275 +
1.276 + return EPlatformH4RAM;
1.277 + }
1.278 + else
1.279 + {
1.280 + if (DP_rom)
1.281 + {
1.282 + return EPlatformH4NANDDP;
1.283 + }
1.284 + else
1.285 + {
1.286 + return EPlatformH4NAND;
1.287 + }
1.288 + }
1.289 + }
1.290 + //For H6 board OMAP3430
1.291 + else if (muid == HAL::EMachineUid_OmapH6)
1.292 + {
1.293 + if (!nandBuild)
1.294 + {
1.295 + return EPlatformH6RAM;
1.296 + }
1.297 + else
1.298 + {
1.299 + if (DP_rom)
1.300 + {
1.301 + return EPlatformH6NANDDP;
1.302 + }
1.303 + else
1.304 + {
1.305 + return EPlatformH6NAND;
1.306 + }
1.307 + }
1.308 + } // H6 board 3430 ends here
1.309 + else if (muid == HAL::EMachineUid_Win32Emulator)
1.310 + {
1.311 + return EPlatformWINSCW;
1.312 + }
1.313 + else
1.314 + {
1.315 + return EPlatformUnknown;
1.316 + }
1.317 + }
1.318 +