os/security/cryptomgmtlibs/securitytestfw/test/testutil/client/testutilclient.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/testutil/client/testutilclient.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,180 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* TestUtil - client testutils interface implementation
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @test
1.26 + @internalComponent
1.27 +*/
1.28 +
1.29 +#include "testutilclient.h"
1.30 +#include "testutilclientserver.h"
1.31 +
1.32 +static TInt StartTestUtilServer()
1.33 + {
1.34 + const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
1.35 + RProcess server;
1.36 + TInt err = server.Create(KTestUtilServerImg, KNullDesC, serverUid);
1.37 + if (err != KErrNone)
1.38 + {
1.39 + return err;
1.40 + }
1.41 + TRequestStatus stat;
1.42 + server.Rendezvous(stat);
1.43 + if (stat != KRequestPending)
1.44 + {
1.45 + server.Kill(0); // abort startup
1.46 + }
1.47 + else
1.48 + {
1.49 + server.Resume(); // logon OK - start the server
1.50 + }
1.51 + User::WaitForRequest(stat); // wait for start or death
1.52 + // we can't use the 'exit reason' if the server panicked as this
1.53 + // is the panic 'reason' and may be '0' which cannot be distinguished
1.54 + // from KErrNone
1.55 + err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
1.56 + server.Close();
1.57 + return err;
1.58 + }
1.59 +
1.60 +EXPORT_C TInt RTestUtilSession::Connect()
1.61 +//
1.62 +// Connect to the server, attempting to start it if necessary
1.63 +//
1.64 + {
1.65 + TInt retry=2;
1.66 + for (;;)
1.67 + {
1.68 + TInt err = CreateSession(KTestUtilServerName, TVersion(0, 0, 0), 2);
1.69 + if (err != KErrNotFound && err != KErrServerTerminated)
1.70 + {
1.71 + return err;
1.72 + }
1.73 + if (--retry==0)
1.74 + {
1.75 + return err;
1.76 + }
1.77 + err = StartTestUtilServer();
1.78 + if (err != KErrNone && err != KErrAlreadyExists)
1.79 + {
1.80 + return err;
1.81 + }
1.82 + }
1.83 + }
1.84 +
1.85 +EXPORT_C TInt RTestUtilSession::Copy(const TDesC& aSourceFile, const TDesC& aDestinationFile)
1.86 + {
1.87 + return SendReceive(ECopy,TIpcArgs(&aSourceFile, &aDestinationFile));
1.88 + }
1.89 +
1.90 +EXPORT_C TInt RTestUtilSession::Move(const TDesC& aSourceFile, const TDesC& aDestinationFile)
1.91 + {
1.92 + return SendReceive(EMove,TIpcArgs(&aSourceFile, &aDestinationFile));
1.93 + }
1.94 +
1.95 +EXPORT_C TInt RTestUtilSession::Delete(const TDesC& aFileName)
1.96 + {
1.97 + return SendReceive(EDelete,TIpcArgs(&aFileName));
1.98 + }
1.99 +
1.100 +EXPORT_C TInt RTestUtilSession::MkDirAll(const TDesC& aFileName)
1.101 + {
1.102 + return SendReceive(EMkDirAll,TIpcArgs(&aFileName));
1.103 + }
1.104 +
1.105 +EXPORT_C TInt RTestUtilSession::RmDir(const TDesC& aFileName)
1.106 + {
1.107 + return SendReceive(ERmDir,TIpcArgs(&aFileName));
1.108 + }
1.109 +
1.110 +EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName)
1.111 + {
1.112 + return FileExistsL(aFileName, 0);
1.113 + }
1.114 +
1.115 +EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName, TInt aMsecTimeout)
1.116 + {
1.117 + TBool fileExists;
1.118 + TPckg<TBool> exists(fileExists);
1.119 + User::LeaveIfError(SendReceive(EFileExists,TIpcArgs(&aFileName, aMsecTimeout, &exists)));
1.120 + return fileExists;
1.121 + }
1.122 +EXPORT_C TInt RTestUtilSession::FormatDrive(TInt aDrive, TBool aFormatFatTableOnly)
1.123 + {
1.124 + return SendReceive(EFormat,TIpcArgs(aDrive, aFormatFatTableOnly));
1.125 + }
1.126 +EXPORT_C TInt RTestUtilSession::MountDrive(TInt aDrive)
1.127 + {
1.128 + return SendReceive(EMount,TIpcArgs(aDrive));
1.129 + }
1.130 +EXPORT_C TInt RTestUtilSession::UnMountDrive(TInt aDrive)
1.131 + {
1.132 + return SendReceive(EUnMount,TIpcArgs(aDrive));
1.133 + }
1.134 +
1.135 +EXPORT_C TInt RTestUtilSession::Lock(const TDesC& aFileName)
1.136 + {
1.137 + return SendReceive(ELock,TIpcArgs(&aFileName));
1.138 + }
1.139 +
1.140 +EXPORT_C TInt RTestUtilSession::Unlock(const TDesC& aFileName)
1.141 + {
1.142 + return SendReceive(EUnlock,TIpcArgs(&aFileName));
1.143 + }
1.144 +
1.145 +EXPORT_C TInt RTestUtilSession::SetReadOnly(const TDesC& aFileName, TInt aSetReadOnly)
1.146 + {
1.147 + return SendReceive(ESetReadOnly,TIpcArgs(&aFileName, aSetReadOnly));
1.148 + }
1.149 +EXPORT_C TInt RTestUtilSession::GetFileHandle(const TDesC& aFileName, RFile &aRFile)
1.150 + {
1.151 + TPckgBuf<TInt> fh;
1.152 + TInt fsh = SendReceive(EGetFileHandle, TIpcArgs(&aFileName, &fh));
1.153 + if(fsh < 0)
1.154 + {
1.155 + return fsh;
1.156 + }
1.157 + return aRFile.AdoptFromServer(fsh, fh());
1.158 + }
1.159 +EXPORT_C void RTestUtilSession::WatchFile(const TDesC& aFileName, TRequestStatus& aStatus)
1.160 + {
1.161 + aStatus=KRequestPending;
1.162 + SendReceive(EWatchFile, TIpcArgs(&aFileName), aStatus);
1.163 + }
1.164 +EXPORT_C void RTestUtilSession::WatchFileCancelL()
1.165 + {
1.166 + User::LeaveIfError(SendReceive(EWatchFileCancel));
1.167 + }
1.168 +EXPORT_C TInt RTestUtilSession::GetNumFilesL(const TDesC& aDirName)
1.169 + {
1.170 + TInt numFiles;
1.171 + TPckg<TInt> getNum(numFiles);
1.172 +
1.173 + User::LeaveIfError(SendReceive(EGetNumFiles, TIpcArgs(&aDirName, &getNum)));
1.174 +
1.175 + return numFiles;
1.176 + }
1.177 +
1.178 +EXPORT_C TInt RTestUtilSession::SetSecureClock(TInt aTimeOffset)
1.179 + {
1.180 + return SendReceive(ESetSecureClock,TIpcArgs(aTimeOffset));
1.181 + }
1.182 +
1.183 +// End of file