graphicstest/graphicstestharness/src/GraphicsTestUtils.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <e32math.h>
       
    24 #include "GraphicsTestUtils.h"
       
    25 
       
    26 const TUid KServerUid3={0x10281AD9};
       
    27 
       
    28 
       
    29 
       
    30 static TInt StartServer()
       
    31 //
       
    32 // Start the server process. Simultaneous launching
       
    33 // of two such processes should be detected when the second one attempts to
       
    34 // create the server object, failing with KErrAlreadyExists.
       
    35 //
       
    36 	{
       
    37 	const TUidType serverUid(KNullUid,KNullUid,KServerUid3);
       
    38 	TInt r=KErrNone;
       
    39 	RProcess server;
       
    40 	r=server.Create(KTestServerImg,KNullDesC,serverUid);
       
    41 
       
    42 
       
    43 	if (r!=KErrNone)
       
    44 		return r;
       
    45 	TRequestStatus stat;
       
    46 	server.Rendezvous(stat);
       
    47 	if (stat!=KRequestPending)
       
    48 		server.Kill(0);		// abort startup
       
    49 	else
       
    50 		server.Resume();	// logon OK - start the server
       
    51 	User::WaitForRequest(stat);		// wait for start or death
       
    52 	server.Close();
       
    53 	return stat.Int();
       
    54 	}
       
    55 
       
    56 
       
    57 EXPORT_C TInt RSmlTestUtils::Connect()
       
    58 //
       
    59 // Connect to the server, attempting to start it if necessary
       
    60 //
       
    61 	{
       
    62 	TInt retry=2;
       
    63 	for (;;)
       
    64 		{
       
    65 		TInt r=CreateSession(KTestServerName,TVersion(0,0,0),1);
       
    66 		if (r!=KErrNotFound && r!=KErrServerTerminated)
       
    67 			return r;
       
    68 		if (--retry==0)
       
    69 			return r;
       
    70 		r=StartServer();
       
    71 		if (r!=KErrNone && r!=KErrAlreadyExists)
       
    72 			return r;
       
    73 		}
       
    74 	}
       
    75 
       
    76 	
       
    77 EXPORT_C void RSmlTestUtils::SetDevIdL(const TDesC8& aDevId)
       
    78 	{
       
    79 	TIpcArgs args(&aDevId);
       
    80 	User::LeaveIfError(SendReceive(EChangeDevId,args));
       
    81 	}
       
    82 
       
    83 EXPORT_C void RSmlTestUtils::GetDevIdL(TDes8& aDevId)
       
    84 	{
       
    85 	TIpcArgs args(&aDevId);
       
    86 	User::LeaveIfError(SendReceive(EGetDevId, args));
       
    87 	}
       
    88 
       
    89 EXPORT_C TInt RSmlTestUtils::WipeDataStoreL(TWipeItems aItemsToClean)
       
    90 	{
       
    91 	// Package up the items to clean and send to server
       
    92 	TPckgBuf<TWipeItems> temp(aItemsToClean);
       
    93 	TIpcArgs args(&temp);
       
    94 	User::LeaveIfError(SendReceive(EWipeDataStore, args));
       
    95 	return KErrNone;
       
    96 	}
       
    97 	
       
    98 EXPORT_C TInt RSmlTestUtils::RenameDirectoryL(const TDesC16& aSrc,const TDesC16& aDest)
       
    99 	{
       
   100 	TIpcArgs args(&aSrc,&aDest);
       
   101 	TInt ret = SendReceive(ERenameDir, args);
       
   102 	return ret;
       
   103 	}
       
   104 
       
   105 EXPORT_C TInt RSmlTestUtils::CreateDirectoryL(const TDesC& aPath)
       
   106 	{
       
   107 	TIpcArgs args(&aPath);
       
   108 	TInt ret = SendReceive(ECreateDir, args);
       
   109 	return ret;
       
   110 	}
       
   111 
       
   112 EXPORT_C TInt RSmlTestUtils::DeleteDirectoryL(const TDesC& aPath)
       
   113 	{
       
   114 	TIpcArgs args(&aPath);
       
   115 	TInt ret = SendReceive(EDeleteDir, args);
       
   116 	return ret;
       
   117 	}
       
   118 	
       
   119 EXPORT_C TInt RSmlTestUtils::CreateFileL(const TDesC& aPath)
       
   120 	{
       
   121 	TIpcArgs args(&aPath);
       
   122 	TInt ret = SendReceive(ECreateFile, args);
       
   123 	return ret;
       
   124 	}
       
   125 
       
   126 EXPORT_C TInt RSmlTestUtils::DeleteFileL(const TDesC& aPath)
       
   127 	{
       
   128 	TIpcArgs args(&aPath);
       
   129 	TInt ret = SendReceive(EDeleteFile, args);
       
   130 	return ret;
       
   131 	}
       
   132 	
       
   133 EXPORT_C TInt RSmlTestUtils::DeleteFileUsingWildcardL(const TDesC& aPath)
       
   134 	{
       
   135 	TIpcArgs args(&aPath);
       
   136 	TInt ret = SendReceive(EDeleteFileUsingWildcard, args);
       
   137 	return ret;
       
   138 	}
       
   139 	
       
   140 EXPORT_C TInt RSmlTestUtils::CopyFileL(const TDesC& aSrc,const TDesC& aDest)
       
   141 	{
       
   142 	TIpcArgs args(&aSrc,&aDest);
       
   143 	TInt ret = SendReceive(ECopyFile, args);
       
   144 	return ret;
       
   145 	}
       
   146 	
       
   147 EXPORT_C void RSmlTestUtils::SetHomeTimeL(const TTime aTime)
       
   148 	{
       
   149 	TPckgBuf<TTime> temp(aTime);
       
   150 	TIpcArgs args(&temp);
       
   151 	User::LeaveIfError(SendReceive(ESetHomeTime, args));
       
   152 	}
       
   153 
       
   154 EXPORT_C TInt RSmlTestUtils::ReplaceFileL(const TDesC& aName,TUint aFileMode)
       
   155 	{
       
   156 	TPckgBuf<TUint> temp(aFileMode);
       
   157 	TIpcArgs args(&aName,&temp);
       
   158 	TInt ret = SendReceive(EReplaceFile, args);
       
   159 	return ret;
       
   160 	}
       
   161 
       
   162 EXPORT_C TInt RSmlTestUtils::IsFilePresent(const TDesC& aName, TBool &aPresent)
       
   163 	{
       
   164 	TPckgBuf<TBool> present(aPresent);
       
   165 	TIpcArgs args(&aName,&present);
       
   166 	TInt ret = SendReceive(EIsFilePresent, args);
       
   167 	aPresent = present();
       
   168 	return ret;
       
   169 	}
       
   170 
       
   171 EXPORT_C TInt RSmlTestUtils::SetReadOnly(const TDesC& aName,TUint aSetAttMask)
       
   172 	{
       
   173 	TPckgBuf<TUint> temp(aSetAttMask);
       
   174 	TIpcArgs args(&aName,&temp);
       
   175 	TInt ret = SendReceive(ESetReadOnly,args);
       
   176 	return ret;
       
   177 	}
       
   178 
       
   179 	
       
   180 EXPORT_C TInt RSmlTestUtils::GetAtt( const TDesC& aName, TUint& aAttValue )
       
   181 	{
       
   182 	TPckgBuf<TUint> attPckg( aAttValue ); 
       
   183 	TIpcArgs args( &aName, &attPckg );	
       
   184 	TInt ret = SendReceive( EGetAttributes, args );
       
   185 	aAttValue = attPckg();
       
   186 	return ret;	
       
   187 	}
       
   188 		
       
   189 EXPORT_C TInt RSmlTestUtils::SetAtt( const TDesC &aName, TUint aSetAttMask, TUint aClearAttMask )
       
   190 	{
       
   191 	TIpcArgs args( &aName, &aSetAttMask, &aClearAttMask );
       
   192 	TInt ret = SendReceive( ESetAttributes, args );
       
   193 	return ret;		
       
   194 	}
       
   195 
       
   196 EXPORT_C TInt RSmlTestUtils::CopyDirectoryL(const TDesC& aSource,const TDesC& aTarget)
       
   197 	{
       
   198 	TIpcArgs args(&aSource,&aTarget);
       
   199 	TInt ret = SendReceive(ECopyDirectory, args);
       
   200 	return ret;
       
   201 	}
       
   202 
       
   203 
       
   204 //clears the read-only attribute of the given filename	
       
   205 EXPORT_C TInt RSmlTestUtils::ChangeFilePermissionL(const TDesC& aPath)
       
   206 	{
       
   207 	TIpcArgs args(&aPath);
       
   208 	TInt ret = SendReceive(EChangeFilePermission, args);
       
   209 	return ret;	
       
   210 	}