os/security/cryptomgmtlibs/securitytestfw/test/testutil/client/testutilclient.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * TestUtil - client testutils interface implementation
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @test
    23  @internalComponent
    24 */
    25  
    26 #include "testutilclient.h"
    27 #include "testutilclientserver.h"
    28 
    29 static TInt StartTestUtilServer()
    30 	{
    31 	const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
    32 	RProcess server;
    33 	TInt err = server.Create(KTestUtilServerImg, KNullDesC, serverUid);
    34 	if (err != KErrNone)
    35 		{
    36 		return err;
    37 		}
    38 	TRequestStatus stat;
    39 	server.Rendezvous(stat);
    40 	if (stat != KRequestPending)
    41 		{
    42 		server.Kill(0);		// abort startup
    43 		}
    44 	else
    45 		{
    46 		server.Resume();	// logon OK - start the server
    47 		}
    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
    51 	// from KErrNone
    52 	err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
    53 	server.Close();
    54 	return err;
    55 	}
    56 
    57 EXPORT_C TInt RTestUtilSession::Connect()
    58 //
    59 // Connect to the server, attempting to start it if necessary
    60 //
    61 	{
    62 	TInt retry=2;
    63 	for (;;)
    64 		{
    65 		TInt err = CreateSession(KTestUtilServerName, TVersion(0, 0, 0), 2);
    66 		if (err != KErrNotFound && err != KErrServerTerminated)
    67 			{
    68 			return err;
    69 			}
    70 		if (--retry==0)
    71 			{
    72 			return err;
    73 			}
    74 		err = StartTestUtilServer();
    75 		if (err != KErrNone && err != KErrAlreadyExists)
    76 			{
    77 			return err;
    78 			}
    79 		}
    80 	}
    81 
    82 EXPORT_C TInt RTestUtilSession::Copy(const TDesC& aSourceFile, const TDesC& aDestinationFile)
    83 	{
    84 	return SendReceive(ECopy,TIpcArgs(&aSourceFile, &aDestinationFile));
    85 	}
    86 
    87 EXPORT_C TInt RTestUtilSession::Move(const TDesC& aSourceFile, const TDesC& aDestinationFile)
    88 	{
    89 	return SendReceive(EMove,TIpcArgs(&aSourceFile, &aDestinationFile));
    90 	}
    91 
    92 EXPORT_C TInt RTestUtilSession::Delete(const TDesC& aFileName)
    93 	{
    94 	return SendReceive(EDelete,TIpcArgs(&aFileName));
    95 	}
    96 
    97 EXPORT_C TInt RTestUtilSession::MkDirAll(const TDesC& aFileName)
    98 	{
    99 	return SendReceive(EMkDirAll,TIpcArgs(&aFileName));
   100 	}
   101 
   102 EXPORT_C TInt RTestUtilSession::RmDir(const TDesC& aFileName)
   103 	{
   104 	return SendReceive(ERmDir,TIpcArgs(&aFileName));
   105 	}
   106 
   107 EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName)
   108 	{
   109 	return FileExistsL(aFileName, 0);
   110 	}
   111 
   112 EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName, TInt aMsecTimeout)
   113 	{
   114 	TBool fileExists;
   115 	TPckg<TBool> exists(fileExists);
   116 	User::LeaveIfError(SendReceive(EFileExists,TIpcArgs(&aFileName, aMsecTimeout, &exists)));
   117 	return fileExists;
   118 	}
   119 EXPORT_C TInt RTestUtilSession::FormatDrive(TInt aDrive, TBool aFormatFatTableOnly)
   120 	{
   121 	return SendReceive(EFormat,TIpcArgs(aDrive, aFormatFatTableOnly));
   122 	}
   123 EXPORT_C TInt RTestUtilSession::MountDrive(TInt aDrive)
   124 	{
   125 	return SendReceive(EMount,TIpcArgs(aDrive));
   126 	}
   127 EXPORT_C TInt RTestUtilSession::UnMountDrive(TInt aDrive)
   128 	{
   129 	return SendReceive(EUnMount,TIpcArgs(aDrive));
   130 	}
   131 	
   132 EXPORT_C TInt RTestUtilSession::Lock(const TDesC& aFileName)
   133 	{
   134 	return SendReceive(ELock,TIpcArgs(&aFileName));
   135 	}
   136 	
   137 EXPORT_C TInt RTestUtilSession::Unlock(const TDesC& aFileName)
   138 	{
   139 	return SendReceive(EUnlock,TIpcArgs(&aFileName));
   140 	}
   141 
   142 EXPORT_C TInt RTestUtilSession::SetReadOnly(const TDesC& aFileName, TInt aSetReadOnly)
   143 	{
   144 	return SendReceive(ESetReadOnly,TIpcArgs(&aFileName, aSetReadOnly));
   145 	}
   146 EXPORT_C TInt RTestUtilSession::GetFileHandle(const TDesC& aFileName, RFile &aRFile)
   147 	{
   148 	TPckgBuf<TInt> fh;
   149 	TInt fsh = SendReceive(EGetFileHandle, TIpcArgs(&aFileName, &fh));
   150 	if(fsh < 0)
   151 		{
   152 		return fsh;
   153 		}
   154 	return aRFile.AdoptFromServer(fsh, fh());
   155 	}
   156 EXPORT_C void RTestUtilSession::WatchFile(const TDesC& aFileName, TRequestStatus& aStatus)
   157 	{
   158 	aStatus=KRequestPending;
   159 	SendReceive(EWatchFile, TIpcArgs(&aFileName), aStatus);
   160 	}
   161 EXPORT_C void RTestUtilSession::WatchFileCancelL()
   162 	{
   163 	User::LeaveIfError(SendReceive(EWatchFileCancel));
   164 	}
   165 EXPORT_C TInt RTestUtilSession::GetNumFilesL(const TDesC& aDirName)
   166 	{
   167 	TInt numFiles;
   168 	TPckg<TInt> getNum(numFiles);
   169 	
   170 	User::LeaveIfError(SendReceive(EGetNumFiles, TIpcArgs(&aDirName, &getNum)));
   171 	
   172 	return numFiles;
   173 	}
   174 
   175 EXPORT_C TInt RTestUtilSession::SetSecureClock(TInt aTimeOffset)
   176 	{
   177 	return SendReceive(ESetSecureClock,TIpcArgs(aTimeOffset));
   178 	}
   179 
   180 // End of file