appfw/uiftestfw/src/appfwk_test_utils.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     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 
       
    25 #include "appfwk_test_utils.h"
       
    26 
       
    27 
       
    28 
       
    29 const TUid KServerUid3 = {0x10009FBD};
       
    30 
       
    31 
       
    32 /**
       
    33   Start the server process. Simultaneous launching of two such processes should be detected when the second one attempts to
       
    34   create the server object, failing with KErrAlreadyExists.
       
    35 */
       
    36 static TInt StartServer()
       
    37 	{
       
    38 	const TUidType serverUid(KNullUid,KNullUid,KServerUid3);
       
    39 	RProcess server;
       
    40 	TInt r = server.Create(KTestServerImg,KNullDesC,serverUid);
       
    41 	if (r!=KErrNone)
       
    42 		{
       
    43 		return r;
       
    44 		}
       
    45 	
       
    46 	TRequestStatus stat;
       
    47 	server.Rendezvous(stat);
       
    48 	if (stat!=KRequestPending)
       
    49 		{
       
    50 		server.Kill(0);
       
    51 		}
       
    52 	else
       
    53 		{
       
    54 		server.Resume();
       
    55 		}
       
    56 
       
    57 	// wait for start or death
       
    58 	User::WaitForRequest(stat);	
       
    59 	server.Close();
       
    60 	
       
    61 	return stat.Int();
       
    62 	}
       
    63 
       
    64 
       
    65 /**
       
    66   Connect to the server, attempting to start it if necessary
       
    67 */
       
    68 EXPORT_C TInt RSmlTestUtils::Connect()
       
    69 	{
       
    70 	TInt retry=2;
       
    71 	for (;;)
       
    72 		{
       
    73 		TInt r=CreateSession(KTestServerName,TVersion(0,0,0),1);
       
    74 		if (r!=KErrNotFound && r!=KErrServerTerminated)
       
    75 			{
       
    76 			return r;
       
    77 			}
       
    78 		if (--retry==0)
       
    79 			{
       
    80 			return r;
       
    81 			}
       
    82 		r=StartServer();
       
    83 		if (r!=KErrNone && r!=KErrAlreadyExists)
       
    84 			{
       
    85 			return r;
       
    86 			}
       
    87 		}
       
    88 	}
       
    89 
       
    90 	
       
    91 EXPORT_C void RSmlTestUtils::SetDevIdL(const TDesC8& aDevId)
       
    92 	{
       
    93 	TIpcArgs args(&aDevId);
       
    94 	User::LeaveIfError(SendReceive(EChangeDevId,args));
       
    95 	}
       
    96 
       
    97 
       
    98 EXPORT_C void RSmlTestUtils::GetDevIdL(TDes8& aDevId)
       
    99 	{
       
   100 	TIpcArgs args(&aDevId);
       
   101 	User::LeaveIfError(SendReceive(EGetDevId, args));
       
   102 	}
       
   103 
       
   104 
       
   105 EXPORT_C TInt RSmlTestUtils::WipeDataStoreL(TWipeItems aItemsToClean)
       
   106 	{
       
   107 	TPckgBuf<TWipeItems> temp(aItemsToClean);
       
   108 	TIpcArgs args(&temp);
       
   109 	User::LeaveIfError(SendReceive(EWipeDataStore, args));
       
   110 	return KErrNone;
       
   111 	}
       
   112 	
       
   113 	
       
   114 EXPORT_C TInt RSmlTestUtils::RenameDirectoryL(const TDesC16& aSrc,const TDesC16& aDest)
       
   115 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   116 	TIpcArgs args(&aSrc,&aDest);
       
   117 	TInt ret = SendReceive(ERenameDir, args);
       
   118 	return ret;
       
   119 	}
       
   120 
       
   121 
       
   122 EXPORT_C TInt RSmlTestUtils::CreateDirectoryL(const TDesC& aPath)
       
   123 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   124 	TIpcArgs args(&aPath);
       
   125 	TInt ret = SendReceive(ECreateDir, args);
       
   126 	return ret;
       
   127 	}
       
   128 	
       
   129 
       
   130 EXPORT_C TInt RSmlTestUtils::DeleteDirectoryL(const TDesC& aPath)
       
   131 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   132 	TIpcArgs args(&aPath);
       
   133 	TInt ret = SendReceive(EDeleteDir, args);
       
   134 	return ret;
       
   135 	}
       
   136 	
       
   137 	
       
   138 EXPORT_C TInt RSmlTestUtils::CreateFileL(const TDesC& aPath)
       
   139 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   140 	TIpcArgs args(&aPath);
       
   141 	TInt ret = SendReceive(ECreateFile, args);
       
   142 	return ret;
       
   143 	}
       
   144 
       
   145 
       
   146 EXPORT_C TInt RSmlTestUtils::DeleteFileL(const TDesC& aPath)
       
   147 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   148 	TIpcArgs args(&aPath);
       
   149 	TInt ret = SendReceive(EDeleteFile, args);
       
   150 	return ret;
       
   151 	}
       
   152 	
       
   153 	
       
   154 EXPORT_C TInt RSmlTestUtils::DeleteFileUsingWildcardL(const TDesC& aPath)
       
   155 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   156 	TIpcArgs args(&aPath);
       
   157 	TInt ret = SendReceive(EDeleteFileUsingWildcard, args);
       
   158 	return ret;
       
   159 	}
       
   160 	
       
   161 	
       
   162 EXPORT_C TInt RSmlTestUtils::CopyFileL(const TDesC& aSrc,const TDesC& aDest)
       
   163 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   164 	TIpcArgs args(&aSrc,&aDest);
       
   165 	TInt ret = SendReceive(ECopyFile, args);
       
   166 	return ret;
       
   167 	}
       
   168 	
       
   169 // lint warning stating that aTime could be a const reference,
       
   170 // but since this is derived from product code, it cannot be
       
   171 // changed here, and hence the warning is suppressed
       
   172 //lint -efunc(1746,RSmlTestUtils::SetHomeTimeL)	
       
   173 EXPORT_C void RSmlTestUtils::SetHomeTimeL(const TTime aTime)
       
   174 	{
       
   175 	TPckgBuf<TTime> temp(aTime);
       
   176 	TIpcArgs args(&temp);
       
   177 	User::LeaveIfError(SendReceive(ESetHomeTime, args));
       
   178 	}
       
   179 
       
   180 
       
   181 EXPORT_C TInt RSmlTestUtils::ReplaceFileL(const TDesC& aName,TUint aFileMode)
       
   182 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   183 	TPckgBuf<TUint> temp(aFileMode);
       
   184 	TIpcArgs args(&aName,&temp);
       
   185 	TInt ret = SendReceive(EReplaceFile, args);
       
   186 	return ret;
       
   187 	}
       
   188 	
       
   189 
       
   190 EXPORT_C TInt RSmlTestUtils::IsFilePresent(const TDesC& aName, TBool &aPresent)
       
   191 	{
       
   192 	TPckgBuf<TBool> present(aPresent);
       
   193 	TIpcArgs args(&aName,&present);
       
   194 	TInt ret = SendReceive(EIsFilePresent, args);
       
   195 	aPresent = present();
       
   196 	return ret;
       
   197 	}
       
   198 
       
   199 
       
   200 EXPORT_C TInt RSmlTestUtils::SetReadOnly(const TDesC& aName,TUint aSetAttMask)
       
   201 	{
       
   202 	TPckgBuf<TUint> temp(aSetAttMask);
       
   203 	TIpcArgs args(&aName,&temp);
       
   204 	TInt ret = SendReceive(ESetReadOnly,args);
       
   205 	return ret;
       
   206 	}
       
   207 
       
   208 	
       
   209 EXPORT_C TInt RSmlTestUtils::GetAtt( const TDesC& aName, TUint& aAttValue )
       
   210 	{
       
   211 	TPckgBuf<TUint> attPckg( aAttValue ); 
       
   212 	TIpcArgs args( &aName, &attPckg );	
       
   213 	TInt ret = SendReceive( EGetAttributes, args );
       
   214 	aAttValue = attPckg();
       
   215 	return ret;	
       
   216 	}
       
   217 		
       
   218 		
       
   219 EXPORT_C TInt RSmlTestUtils::SetAtt( const TDesC &aName, TUint aSetAttMask, TUint aClearAttMask )
       
   220 	{
       
   221 	TIpcArgs args( &aName, &aSetAttMask, &aClearAttMask );
       
   222 	TInt ret = SendReceive( ESetAttributes, args );
       
   223 	return ret;		
       
   224 	}
       
   225 
       
   226 
       
   227 EXPORT_C TInt RSmlTestUtils::CopyDirectoryL(const TDesC& aSource,const TDesC& aTarget)
       
   228 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   229 	TIpcArgs args(&aSource,&aTarget);
       
   230 	TInt ret = SendReceive(ECopyDirectory, args);
       
   231 	return ret;
       
   232 	}
       
   233 
       
   234 
       
   235 EXPORT_C TInt RSmlTestUtils::ChangeFilePermissionL(const TDesC& aPath)
       
   236 	{ // this implementation of this method does not leave but further derived implementations may if they choose
       
   237 	TIpcArgs args(&aPath);
       
   238 	TInt ret = SendReceive(EChangeFilePermission, args);
       
   239 	return ret;	
       
   240 	}
       
   241