os/ossrv/genericservices/taskscheduler/Test/TSUtils/TSetHomeTime.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/TSUtils/TSetHomeTime.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,114 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32debug.h>
    1.20 +#include <tz.h>
    1.21 +	
    1.22 +// This function is used to update month and day in aBufLocalTime
    1.23 +// to actual month and day to be passed to TTime() constructor.
    1.24 +// Remember using TTime::FormatL() in thelpers.cpp 
    1.25 +// has added extra month and a day to aBufLocalTime.
    1.26 +// aBufLocalTime is in format YYMMDD:HHMMSS.MMMMMM
    1.27 +// see TTime::Set() for aBufLocalTime expected format details.
    1.28 +TInt UpdateToActualMonthAndDay(TDes& aBufLocalTime)
    1.29 +	{	
    1.30 +	TInt mVal 	= 0;
    1.31 +	TInt dVal 	= 0;
    1.32 +	
    1.33 +	TBuf <4> tempBuf;
    1.34 +	_LIT(KFormat, "%02d");
    1.35 +	
    1.36 +	//Get the position of colon separator	
    1.37 +	TInt colon 	= aBufLocalTime.Locate(':');
    1.38 +	
    1.39 +	// Get Month & Day if Present	
    1.40 +	switch(colon)
    1.41 +		{
    1.42 +		case 0: break;
    1.43 +		case 8:
    1.44 +			{
    1.45 +			TLex month 	= aBufLocalTime.Mid(4,2);
    1.46 +			TLex day 	= aBufLocalTime.Mid(6,2);
    1.47 +			month.Val(mVal);
    1.48 +			day.Val(dVal);			
    1.49 +			}
    1.50 +			break;
    1.51 +		default:
    1.52 +			{
    1.53 +			// If the colon is at the wrong position.
    1.54 +			return (KErrArgument);
    1.55 +			}
    1.56 +				
    1.57 +		}
    1.58 +		
    1.59 +		// Deduct extra month and a day and update aBufLocalTime
    1.60 +		if(mVal > 0 && dVal > 0)
    1.61 +			{
    1.62 +			mVal-=1;
    1.63 +			dVal-=1;
    1.64 +				
    1.65 +			tempBuf.Format(KFormat, mVal);
    1.66 +			aBufLocalTime.Replace(4,2, tempBuf);
    1.67 +				
    1.68 +			tempBuf.Format(KFormat, dVal);
    1.69 +			aBufLocalTime.Replace(6,2, tempBuf);				
    1.70 +			}
    1.71 +			
    1.72 +		return(KErrNone);
    1.73 +	}
    1.74 +	
    1.75 +//This function is used in the test code to Set the system time to the given local time.
    1.76 +static TInt SetHomeTimeL(TTime& aLocalTime)
    1.77 +	{
    1.78 +	TInt retVal = KErrNone;
    1.79 +	RTz theTzSrv;
    1.80 +	
    1.81 +	User::LeaveIfError(theTzSrv.Connect());
    1.82 +	CleanupClosePushL(theTzSrv);	
    1.83 +	
    1.84 +	retVal = theTzSrv.SetHomeTime(aLocalTime);
    1.85 +		
    1.86 +	CleanupStack::PopAndDestroy(); //theTzSrv.Close()
    1.87 +	return retVal;
    1.88 +	}
    1.89 +
    1.90 +GLDEF_C TInt E32Main()
    1.91 +	{	
    1.92 +	TInt err = KErrNone;
    1.93 +	TInt retVal = KErrNone;
    1.94 +	TBuf<64> bufLocalTime;
    1.95 +	
    1.96 +	User::CommandLine(bufLocalTime);	
    1.97 +	
    1.98 +	retVal = UpdateToActualMonthAndDay(bufLocalTime);
    1.99 +	
   1.100 +	if(retVal == KErrNone)
   1.101 +		{
   1.102 +		TTime localTime(bufLocalTime);		
   1.103 +		
   1.104 +		CTrapCleanup* cleanup = CTrapCleanup::New(); //can fail
   1.105 +		if (cleanup)
   1.106 +			{		
   1.107 +			TRAP(err, retVal = SetHomeTimeL(localTime))
   1.108 +			if(err != KErrNone)
   1.109 +				{
   1.110 +				retVal = err;
   1.111 +				}
   1.112 +			delete cleanup;
   1.113 +			}
   1.114 +		}	
   1.115 +	
   1.116 +	return retVal;
   1.117 +	}