sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Helper class for ECom test code. Allows various file manipulation operations sl@0: // that require higher Capabilities than shoud be given to test harnesses. sl@0: // sl@0: // sl@0: sl@0: #include "EcomTestUtils.h" sl@0: #include "hal.h" sl@0: #include sl@0: sl@0: _LIT(KEcomTestUtilsHelperPanic, "EComTestUtilsHelperPanic"); sl@0: _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames sl@0: const TInt KMAxProcessNameLength = 50; // Max process name length. sl@0: sl@0: // Processes with high Capablilities to perform restricted operations. sl@0: _LIT(KProcessMakeWriteable, "t_makefilewriteable"); sl@0: _LIT(KProcessMakeReadOnly, "t_makefilereadonly"); sl@0: _LIT(KProcessFileManDeleteFile, "t_processfilemandeletefile.exe"); sl@0: _LIT(KProcessFileManCopyFile, "t_processfilemancopyfile.exe"); sl@0: _LIT(KProcessFileManRename, "t_processfilemanrename.exe"); sl@0: _LIT(KProcessRfsDeleteFile, "t_processrfsdeletefile.exe"); sl@0: _LIT(KProcessRfsReplaceFile, "t_processrfsreplacefile.exe"); sl@0: _LIT(KProcessKillProcess, "t_processkillprocess.exe"); sl@0: _LIT(KProcessFileManDeleteDir, "t_processfilemandeletedir.exe"); sl@0: _LIT(KProcessRLoaderDeleteFile, "t_processrloaderdeletefile.exe"); sl@0: sl@0: /** Name format for locale DLLs. */ sl@0: _LIT(KLocaleDLLNameFormat, "ELOCL.%02d"); sl@0: sl@0: sl@0: // Start the high capability helper process sl@0: void LaunchProcessL(const TDesC& aProcessName, const TDesC& aCmdLine) sl@0: { sl@0: TRequestStatus stat; sl@0: RProcess p; sl@0: User::LeaveIfError(p.Create(aProcessName, aCmdLine)); sl@0: sl@0: // Asynchronous logon: completes when process terminates with process sl@0: // exit code sl@0: p.Logon(stat); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: sl@0: TExitType exitType = p.ExitType(); sl@0: TInt exitReason = p.ExitReason(); sl@0: __ASSERT_ALWAYS(exitType == EExitKill, User::Panic(KEcomTestUtilsHelperPanic, exitReason)); sl@0: sl@0: p.Close(); sl@0: User::LeaveIfError(exitReason); sl@0: } sl@0: sl@0: /** sl@0: CFileMan sl@0: */ sl@0: EXPORT_C void EComTestUtils::FileManCopyFileL(const TDesC& anOld,const TDesC& aNew) sl@0: { sl@0: TBuf fileNames(anOld); sl@0: fileNames.Append(KSeparator); sl@0: fileNames.Append(aNew); sl@0: TBufC copyProcess(KProcessFileManCopyFile); sl@0: LaunchProcessL(copyProcess, fileNames); sl@0: } sl@0: sl@0: EXPORT_C void EComTestUtils::FileManDeleteFileL(const TDesC& aFile) sl@0: { sl@0: TBufC deleteProcess(KProcessFileManDeleteFile); sl@0: LaunchProcessL(deleteProcess, aFile); sl@0: } sl@0: sl@0: EXPORT_C void EComTestUtils::FileManRenameL(const TDesC& anOld,const TDesC& aNew) sl@0: { sl@0: TBuf fileNames(anOld); sl@0: fileNames.Append(KSeparator); sl@0: fileNames.Append(aNew); sl@0: TBufC renameProcess(KProcessFileManRename); sl@0: LaunchProcessL(renameProcess, fileNames); sl@0: } sl@0: sl@0: EXPORT_C void EComTestUtils::FileManDeleteDirL(const TDesC& aPath) sl@0: { sl@0: TBufC deleteDirProcess(KProcessFileManDeleteDir); sl@0: LaunchProcessL(deleteDirProcess, aPath); sl@0: } sl@0: sl@0: /** sl@0: RFs sl@0: */ sl@0: EXPORT_C void EComTestUtils::RfsDeleteFileL(const TDesC& aFile) sl@0: { sl@0: TBufC deleteProcess(KProcessRfsDeleteFile); sl@0: LaunchProcessL(deleteProcess, aFile); sl@0: } sl@0: sl@0: EXPORT_C void EComTestUtils::RfsReplaceFileL(const TDesC& anOld,const TDesC& aNew) sl@0: { sl@0: TBuf fileNames(anOld); sl@0: fileNames.Append(KSeparator); sl@0: fileNames.Append(aNew); sl@0: TBufC replaceProcess(KProcessRfsReplaceFile); sl@0: LaunchProcessL(replaceProcess, fileNames); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void EComTestUtils::MakeFileWriteableL(const TDesC& aFile) sl@0: { sl@0: TBufC makeWriteable(KProcessMakeWriteable); sl@0: LaunchProcessL(makeWriteable, aFile); sl@0: } sl@0: sl@0: EXPORT_C void EComTestUtils::MakeFileReadOnlyL(const TDesC& aFile) sl@0: { sl@0: TBufC makeReadOnly(KProcessMakeReadOnly); sl@0: LaunchProcessL(makeReadOnly, aFile); sl@0: } sl@0: sl@0: EXPORT_C void EComTestUtils::KillProcessL(const TDesC& aProcessName) sl@0: { sl@0: TBuf killProcess(KProcessKillProcess); sl@0: LaunchProcessL(killProcess, aProcessName); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Switch the current locale to the given language. sl@0: @param aLang The language to switch to. sl@0: @leave KErrNotFound If locale DLL corresponding to the language cannot be found. sl@0: */ sl@0: EXPORT_C void EComTestUtils::SwitchToLanguageL(TLanguage aLang) sl@0: { sl@0: RLibrary library; sl@0: TBuf<50> libraryName; sl@0: libraryName.Format(KLocaleDLLNameFormat,aLang); sl@0: User::LeaveIfError(library.Load(libraryName)); sl@0: CleanupClosePushL(library); sl@0: User::LeaveIfError(UserSvr::ChangeLocale(libraryName)); sl@0: CleanupStack::PopAndDestroy(); // library sl@0: } sl@0: sl@0: sl@0: /** sl@0: Ask the loader to delete an file. This function should be used instead sl@0: of RFs::Delete where the supplied file may be a paged executable, although sl@0: it can be used for any file. sl@0: @param aFile The file to be deleted sl@0: @leave KErrBadName If the supplied filename is not fully qualified. Else any of the Symbian OS error code sl@0: */ sl@0: EXPORT_C void EComTestUtils::RLoaderDeleteFileL(const TDesC& aFile) sl@0: { sl@0: TBufC deleteTheProcess(KProcessRLoaderDeleteFile); sl@0: LaunchProcessL(deleteTheProcess, aFile); sl@0: } sl@0: sl@0: /** sl@0: Get Rom Build Type i.e. NAND or Default Rom build. sl@0: This function is created since in some test one needs to find if its a sl@0: NAND or a Non-Nand build. It returns enum "TRomBuildOption" that states the rom build type. sl@0: Enum "TRomBuildOption" is defined so that this function can be enhanced for a new Rom build type sl@0: @param aRfs Input Parameter RFs reference is passed so that we don't need to sl@0: connect to the file server again. sl@0: */ sl@0: EXPORT_C TRomBuildOption EComTestUtils::RomBuildType(const RFs& aRfs) sl@0: { sl@0: sl@0: TRomBuildOption romBuildOption; sl@0: TDriveInfo driveInfo; sl@0: sl@0: aRfs.Drive(driveInfo, EDriveC); sl@0: sl@0: //C drive determines if its a NAND or a Non-NAND ROM build as per the sl@0: //H4-hrp-UserGuide, Thus CDrive's media type is checked if it is sl@0: //EMediaNANDFlash, EMediaRam or EMediaFlash... sl@0: //If it is EMediaRam or EMediaFlash it is considered as Default Rom Build. sl@0: if(driveInfo.iType==EMediaNANDFlash) sl@0: { sl@0: romBuildOption = ENandRomBuild; sl@0: } sl@0: else sl@0: { sl@0: romBuildOption = EDefaultRomBuild; sl@0: } sl@0: sl@0: return romBuildOption; sl@0: } sl@0: sl@0: /* sl@0: Method is used to detect the hardware configuration of the platform running the tests, sl@0: including both machine UID and C-drive type. sl@0: */ sl@0: EXPORT_C THardwareConfiguration EComTestUtils::GetHardwareConfiguration() sl@0: { sl@0: //get the platform type sl@0: TInt muid; sl@0: if (KErrNone != HAL::Get(HAL::EMachineUid, muid)) sl@0: { sl@0: return EPlatformUnknown; sl@0: } sl@0: sl@0: //determine the ROM confguration (NAND or non-NAND) sl@0: TInt r = KErrNone; sl@0: RFs fs; sl@0: r = fs.Connect(); sl@0: if (r != KErrNone) sl@0: { sl@0: return r; sl@0: } sl@0: TBool nandBuild = (EComTestUtils::RomBuildType(fs)==ENandRomBuild); sl@0: fs.Close(); sl@0: sl@0: //determine whether this ROM is Demand-Paging enabled sl@0: TBool DP_rom = false; sl@0: if (nandBuild) sl@0: { sl@0: TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); sl@0: DP_rom = romHeader->iPageableRomStart; sl@0: } sl@0: sl@0: if (muid == HAL::EMachineUid_OmapH2) sl@0: { sl@0: if (!nandBuild) sl@0: { sl@0: return EPlatformH2RAM; sl@0: } sl@0: else sl@0: { sl@0: if (DP_rom) sl@0: { sl@0: return EPlatformH2NANDDP; sl@0: } sl@0: else sl@0: { sl@0: return EPlatformH2NAND; sl@0: } sl@0: } sl@0: } sl@0: else if (muid == HAL::EMachineUid_OmapH4) sl@0: { sl@0: if (!nandBuild) sl@0: { sl@0: //Incase the ROM is not a nandBuild, sl@0: //then there could be a chance that it is a WDP enabled system. sl@0: //WDP enabled configuration is checked by checking for Media Type of C drive. sl@0: //Under WDP enabled configuration, the C drive is of type 'Hard Disk' sl@0: //This is done since the function EComTestUtils::RomBuildType, above, used for a similar purpose, sl@0: //is also checking the media type of C drive to determine the same. sl@0: //Currently added this check for WDP enabled in case of H4 'muid == HAL::EMachineUid_OmapH4' only sl@0: TDriveInfo driveInfo; sl@0: TInt rf = KErrNone; sl@0: rf = fs.Connect(); sl@0: if (rf != KErrNone) sl@0: { sl@0: return rf; sl@0: } sl@0: fs.Drive(driveInfo, EDriveC); sl@0: fs.Close(); sl@0: sl@0: if (EMediaHardDisk == driveInfo.iType) sl@0: { sl@0: return EPlatformH4MMC; //The system is WDP enabled sl@0: } sl@0: sl@0: return EPlatformH4RAM; sl@0: } sl@0: else sl@0: { sl@0: if (DP_rom) sl@0: { sl@0: return EPlatformH4NANDDP; sl@0: } sl@0: else sl@0: { sl@0: return EPlatformH4NAND; sl@0: } sl@0: } sl@0: } sl@0: //For H6 board OMAP3430 sl@0: else if (muid == HAL::EMachineUid_OmapH6) sl@0: { sl@0: if (!nandBuild) sl@0: { sl@0: return EPlatformH6RAM; sl@0: } sl@0: else sl@0: { sl@0: if (DP_rom) sl@0: { sl@0: return EPlatformH6NANDDP; sl@0: } sl@0: else sl@0: { sl@0: return EPlatformH6NAND; sl@0: } sl@0: } sl@0: } // H6 board 3430 ends here sl@0: else if (muid == HAL::EMachineUid_Win32Emulator) sl@0: { sl@0: return EPlatformWINSCW; sl@0: } sl@0: else sl@0: { sl@0: return EPlatformUnknown; sl@0: } sl@0: } sl@0: