os/security/cryptomgmtlibs/securitytestfw/test/testutil/client/testutilclient.cpp
Update contrib.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * TestUtil - client testutils interface implementation
26 #include "testutilclient.h"
27 #include "testutilclientserver.h"
29 static TInt StartTestUtilServer()
31 const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
33 TInt err = server.Create(KTestUtilServerImg, KNullDesC, serverUid);
39 server.Rendezvous(stat);
40 if (stat != KRequestPending)
42 server.Kill(0); // abort startup
46 server.Resume(); // logon OK - start the server
48 User::WaitForRequest(stat); // wait for start or death
49 // we can't use the 'exit reason' if the server panicked as this
50 // is the panic 'reason' and may be '0' which cannot be distinguished
52 err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
57 EXPORT_C TInt RTestUtilSession::Connect()
59 // Connect to the server, attempting to start it if necessary
65 TInt err = CreateSession(KTestUtilServerName, TVersion(0, 0, 0), 2);
66 if (err != KErrNotFound && err != KErrServerTerminated)
74 err = StartTestUtilServer();
75 if (err != KErrNone && err != KErrAlreadyExists)
82 EXPORT_C TInt RTestUtilSession::Copy(const TDesC& aSourceFile, const TDesC& aDestinationFile)
84 return SendReceive(ECopy,TIpcArgs(&aSourceFile, &aDestinationFile));
87 EXPORT_C TInt RTestUtilSession::Move(const TDesC& aSourceFile, const TDesC& aDestinationFile)
89 return SendReceive(EMove,TIpcArgs(&aSourceFile, &aDestinationFile));
92 EXPORT_C TInt RTestUtilSession::Delete(const TDesC& aFileName)
94 return SendReceive(EDelete,TIpcArgs(&aFileName));
97 EXPORT_C TInt RTestUtilSession::MkDirAll(const TDesC& aFileName)
99 return SendReceive(EMkDirAll,TIpcArgs(&aFileName));
102 EXPORT_C TInt RTestUtilSession::RmDir(const TDesC& aFileName)
104 return SendReceive(ERmDir,TIpcArgs(&aFileName));
107 EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName)
109 return FileExistsL(aFileName, 0);
112 EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName, TInt aMsecTimeout)
115 TPckg<TBool> exists(fileExists);
116 User::LeaveIfError(SendReceive(EFileExists,TIpcArgs(&aFileName, aMsecTimeout, &exists)));
119 EXPORT_C TInt RTestUtilSession::FormatDrive(TInt aDrive, TBool aFormatFatTableOnly)
121 return SendReceive(EFormat,TIpcArgs(aDrive, aFormatFatTableOnly));
123 EXPORT_C TInt RTestUtilSession::MountDrive(TInt aDrive)
125 return SendReceive(EMount,TIpcArgs(aDrive));
127 EXPORT_C TInt RTestUtilSession::UnMountDrive(TInt aDrive)
129 return SendReceive(EUnMount,TIpcArgs(aDrive));
132 EXPORT_C TInt RTestUtilSession::Lock(const TDesC& aFileName)
134 return SendReceive(ELock,TIpcArgs(&aFileName));
137 EXPORT_C TInt RTestUtilSession::Unlock(const TDesC& aFileName)
139 return SendReceive(EUnlock,TIpcArgs(&aFileName));
142 EXPORT_C TInt RTestUtilSession::SetReadOnly(const TDesC& aFileName, TInt aSetReadOnly)
144 return SendReceive(ESetReadOnly,TIpcArgs(&aFileName, aSetReadOnly));
146 EXPORT_C TInt RTestUtilSession::GetFileHandle(const TDesC& aFileName, RFile &aRFile)
149 TInt fsh = SendReceive(EGetFileHandle, TIpcArgs(&aFileName, &fh));
154 return aRFile.AdoptFromServer(fsh, fh());
156 EXPORT_C void RTestUtilSession::WatchFile(const TDesC& aFileName, TRequestStatus& aStatus)
158 aStatus=KRequestPending;
159 SendReceive(EWatchFile, TIpcArgs(&aFileName), aStatus);
161 EXPORT_C void RTestUtilSession::WatchFileCancelL()
163 User::LeaveIfError(SendReceive(EWatchFileCancel));
165 EXPORT_C TInt RTestUtilSession::GetNumFilesL(const TDesC& aDirName)
168 TPckg<TInt> getNum(numFiles);
170 User::LeaveIfError(SendReceive(EGetNumFiles, TIpcArgs(&aDirName, &getNum)));
175 EXPORT_C TInt RTestUtilSession::SetSecureClock(TInt aTimeOffset)
177 return SendReceive(ESetSecureClock,TIpcArgs(aTimeOffset));