sl@0: /* 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 the License "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: * TestUtil - client testutils interface implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent sl@0: */ sl@0: sl@0: #include "testutilclient.h" sl@0: #include "testutilclientserver.h" sl@0: sl@0: static TInt StartTestUtilServer() sl@0: { sl@0: const TUidType serverUid(KNullUid, KNullUid, KServerUid3); sl@0: RProcess server; sl@0: TInt err = server.Create(KTestUtilServerImg, KNullDesC, serverUid); sl@0: if (err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: TRequestStatus stat; sl@0: server.Rendezvous(stat); sl@0: if (stat != KRequestPending) sl@0: { sl@0: server.Kill(0); // abort startup sl@0: } sl@0: else sl@0: { sl@0: server.Resume(); // logon OK - start the server sl@0: } sl@0: User::WaitForRequest(stat); // wait for start or death sl@0: // we can't use the 'exit reason' if the server panicked as this sl@0: // is the panic 'reason' and may be '0' which cannot be distinguished sl@0: // from KErrNone sl@0: err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); sl@0: server.Close(); sl@0: return err; sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::Connect() sl@0: // sl@0: // Connect to the server, attempting to start it if necessary sl@0: // sl@0: { sl@0: TInt retry=2; sl@0: for (;;) sl@0: { sl@0: TInt err = CreateSession(KTestUtilServerName, TVersion(0, 0, 0), 2); sl@0: if (err != KErrNotFound && err != KErrServerTerminated) sl@0: { sl@0: return err; sl@0: } sl@0: if (--retry==0) sl@0: { sl@0: return err; sl@0: } sl@0: err = StartTestUtilServer(); sl@0: if (err != KErrNone && err != KErrAlreadyExists) sl@0: { sl@0: return err; sl@0: } sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::Copy(const TDesC& aSourceFile, const TDesC& aDestinationFile) sl@0: { sl@0: return SendReceive(ECopy,TIpcArgs(&aSourceFile, &aDestinationFile)); sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::Move(const TDesC& aSourceFile, const TDesC& aDestinationFile) sl@0: { sl@0: return SendReceive(EMove,TIpcArgs(&aSourceFile, &aDestinationFile)); sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::Delete(const TDesC& aFileName) sl@0: { sl@0: return SendReceive(EDelete,TIpcArgs(&aFileName)); sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::MkDirAll(const TDesC& aFileName) sl@0: { sl@0: return SendReceive(EMkDirAll,TIpcArgs(&aFileName)); sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::RmDir(const TDesC& aFileName) sl@0: { sl@0: return SendReceive(ERmDir,TIpcArgs(&aFileName)); sl@0: } sl@0: sl@0: EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName) sl@0: { sl@0: return FileExistsL(aFileName, 0); sl@0: } sl@0: sl@0: EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName, TInt aMsecTimeout) sl@0: { sl@0: TBool fileExists; sl@0: TPckg exists(fileExists); sl@0: User::LeaveIfError(SendReceive(EFileExists,TIpcArgs(&aFileName, aMsecTimeout, &exists))); sl@0: return fileExists; sl@0: } sl@0: EXPORT_C TInt RTestUtilSession::FormatDrive(TInt aDrive, TBool aFormatFatTableOnly) sl@0: { sl@0: return SendReceive(EFormat,TIpcArgs(aDrive, aFormatFatTableOnly)); sl@0: } sl@0: EXPORT_C TInt RTestUtilSession::MountDrive(TInt aDrive) sl@0: { sl@0: return SendReceive(EMount,TIpcArgs(aDrive)); sl@0: } sl@0: EXPORT_C TInt RTestUtilSession::UnMountDrive(TInt aDrive) sl@0: { sl@0: return SendReceive(EUnMount,TIpcArgs(aDrive)); sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::Lock(const TDesC& aFileName) sl@0: { sl@0: return SendReceive(ELock,TIpcArgs(&aFileName)); sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::Unlock(const TDesC& aFileName) sl@0: { sl@0: return SendReceive(EUnlock,TIpcArgs(&aFileName)); sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::SetReadOnly(const TDesC& aFileName, TInt aSetReadOnly) sl@0: { sl@0: return SendReceive(ESetReadOnly,TIpcArgs(&aFileName, aSetReadOnly)); sl@0: } sl@0: EXPORT_C TInt RTestUtilSession::GetFileHandle(const TDesC& aFileName, RFile &aRFile) sl@0: { sl@0: TPckgBuf fh; sl@0: TInt fsh = SendReceive(EGetFileHandle, TIpcArgs(&aFileName, &fh)); sl@0: if(fsh < 0) sl@0: { sl@0: return fsh; sl@0: } sl@0: return aRFile.AdoptFromServer(fsh, fh()); sl@0: } sl@0: EXPORT_C void RTestUtilSession::WatchFile(const TDesC& aFileName, TRequestStatus& aStatus) sl@0: { sl@0: aStatus=KRequestPending; sl@0: SendReceive(EWatchFile, TIpcArgs(&aFileName), aStatus); sl@0: } sl@0: EXPORT_C void RTestUtilSession::WatchFileCancelL() sl@0: { sl@0: User::LeaveIfError(SendReceive(EWatchFileCancel)); sl@0: } sl@0: EXPORT_C TInt RTestUtilSession::GetNumFilesL(const TDesC& aDirName) sl@0: { sl@0: TInt numFiles; sl@0: TPckg getNum(numFiles); sl@0: sl@0: User::LeaveIfError(SendReceive(EGetNumFiles, TIpcArgs(&aDirName, &getNum))); sl@0: sl@0: return numFiles; sl@0: } sl@0: sl@0: EXPORT_C TInt RTestUtilSession::SetSecureClock(TInt aTimeOffset) sl@0: { sl@0: return SendReceive(ESetSecureClock,TIpcArgs(aTimeOffset)); sl@0: } sl@0: sl@0: // End of file