tzservices/tzserver/test/Integration/src/DstIntUtils.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2004-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 #include "DstIntUtils.h"
       
    17 #include <tz.h>
       
    18 
       
    19 #include <caldataexchange.h>
       
    20 #include <caldataformat.h>
       
    21 #include <s32file.h>
       
    22 
       
    23 TInt CDstIntUtils::SetHomeTimeZoneL(const TDesC8& aLocation, const RTz &aServer)
       
    24 	{
       
    25 	CTzId *timezoneid = CTzId::NewL(aLocation);
       
    26 	CleanupStack::PushL(timezoneid);
       
    27 	TInt err;
       
    28 	TRAP(err, aServer.SetTimeZoneL(*timezoneid));
       
    29 	CleanupStack::PopAndDestroy(timezoneid);
       
    30 
       
    31 	return err;
       
    32 	}
       
    33 
       
    34 TInt CDstIntUtils::CheckHomeTimeZoneL(const RTz &aServer, const TDesC8& aLocation)
       
    35 	{
       
    36 	TInt err = KErrBadName;
       
    37 	CTzId *timezoneid = aServer.GetTimeZoneIdL();
       
    38 	if(timezoneid->TimeZoneNameID() == aLocation)
       
    39 		{
       
    40 		err = KErrNone;
       
    41 		}
       
    42 	delete timezoneid;
       
    43 	return err;
       
    44 	}
       
    45 
       
    46 
       
    47 void CDstIntUtils::AppendTimeParamStringL(TTime aTime, TDes& aParamString)
       
    48 	{
       
    49 	// This writes TTime according to a format specification, and this takes produces proper
       
    50 	// month and day values (ie they start with 1)
       
    51 	TBuf<15> dateString;
       
    52 	_LIT(KDateFormat, "%F%Y%M%D:%H%T%S");
       
    53 	aTime.FormatL(dateString, KDateFormat);
       
    54 	aParamString.Append(dateString);
       
    55 	}
       
    56 
       
    57 void ResetAndDestroyArrayOfEntries(TAny* aObject)
       
    58 	{
       
    59 	RPointerArray<CCalEntry>* array=static_cast<RPointerArray<CCalEntry>*>(aObject);
       
    60 	if (array)
       
    61 		{
       
    62 		array->ResetAndDestroy();
       
    63 		}
       
    64 	}
       
    65 
       
    66 void CDstIntUtils::OpenAgendaFileL(CCalSession& aSession, const TDesC& aFilename)
       
    67 	{
       
    68 	// Create the agenda file if does not exist
       
    69 	TRAPD(err, aSession.CreateCalFileL(aFilename));
       
    70 	if (err != KErrAlreadyExists)
       
    71 		{
       
    72 		User::LeaveIfError(err);
       
    73 		}
       
    74 		
       
    75 	// Now open it	
       
    76 	aSession.OpenL(aFilename);
       
    77 	}
       
    78 
       
    79 
       
    80 TCalLocalUid CDstIntUtils::ImportVCalL(RFs& aFs, CCalSession& aSession, CCalEntryView& aEntryView, const TDesC& aFileName)
       
    81 	{
       
    82 	RFileReadStream readStream;
       
    83 	User::LeaveIfError(readStream.Open(aFs, aFileName, EFileRead));
       
    84 	CleanupClosePushL(readStream);
       
    85 
       
    86 	// Create ptr array for new entries
       
    87 	RPointerArray<CCalEntry> entryArray;
       
    88 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfEntries, &entryArray));
       
    89 
       
    90 	CCalDataExchange* dataExchange = CCalDataExchange::NewL(aSession);
       
    91 	CleanupStack::PushL(dataExchange);
       
    92 	dataExchange->ImportL(KUidVCalendar, readStream, entryArray);
       
    93 
       
    94 	TInt elements = entryArray.Count();
       
    95 	TCalLocalUid id = 0;
       
    96 
       
    97 	if(elements > 0)
       
    98 		{
       
    99 		CCalEntry* entry = entryArray[0];
       
   100 		// add the first entry only
       
   101 		while (entryArray.Count() > 1)
       
   102 			{
       
   103 			delete entryArray[1];
       
   104 			entryArray.Remove(1);
       
   105 			}
       
   106 		TInt success = 0;
       
   107 		aEntryView.StoreL(entryArray, success);
       
   108 		id = entryArray[0]->LocalUidL();
       
   109 		}
       
   110 
       
   111 	CleanupStack::PopAndDestroy(dataExchange);
       
   112 	CleanupStack::PopAndDestroy();	// ResetAndDestroyArrayOfEntries(entryArray)
       
   113 	CleanupStack::PopAndDestroy();	// readStream.Close()
       
   114 
       
   115 	return id;
       
   116 	}
       
   117 
       
   118 
       
   119 TInt CDstIntUtils::CheckAgendaEntryL(CCalEntryView& aEntryView, const TCalLocalUid& aId, const TTime& aStart, const TTime& aEnd)
       
   120 	{
       
   121 	TInt err = KErrArgument;
       
   122 	CCalEntry* entry = aEntryView.FetchL(aId);
       
   123 	CleanupStack::PushL(entry);
       
   124 
       
   125 	TTime start = entry->StartTimeL().TimeLocalL();
       
   126 	TTime end   = entry->EndTimeL().TimeLocalL();
       
   127 
       
   128 #ifdef _DEBUG
       
   129 	TDateTime startDateTime = start.DateTime();
       
   130 	TDateTime aStartDateTime = aStart.DateTime();
       
   131 	TDateTime endDateTime = end.DateTime();
       
   132 	TDateTime aEndDateTime = aEnd.DateTime();
       
   133 #endif
       
   134 
       
   135 	if((aStart == start) && (aEnd == end))
       
   136 		{
       
   137 		err = KErrNone;
       
   138 		}
       
   139 	
       
   140 	CleanupStack::PopAndDestroy(entry);
       
   141 	return err;
       
   142 	}
       
   143 
       
   144 void CDstIntUtils::GenerateVCalL(RFs& aFs, const TDesC& aFileName, const TDesC& aStartTime, const TDesC& aEndTime)
       
   145 	{
       
   146 	RFile file;
       
   147 	file.Replace(aFs, aFileName, EFileWrite);
       
   148 
       
   149 	TBuf8<64> buf;
       
   150 
       
   151 	file.Write(_L8("BEGIN:VCALENDAR\r\n"));
       
   152 	file.Write(_L8("VERSION:1.0\r\n"));
       
   153 	file.Write(_L8("BEGIN:VEVENT\r\n"));
       
   154 	file.Write(_L8("CATEGORIES:MEETING\r\n"));
       
   155 	file.Write(_L8("DTSTART:"));
       
   156 	buf.Copy(aStartTime);
       
   157 	file.Write(buf);
       
   158 	file.Write(_L8("\r\n"));
       
   159 	file.Write(_L8("DTEND:"));
       
   160 	buf.Copy(aEndTime);
       
   161 	file.Write(buf);
       
   162 	file.Write(_L8("\r\n"));
       
   163 	file.Write(_L8("SUMMARY:TestMeeting\r\n"));
       
   164 	file.Write(_L8("DESCRIPTION:Test\r\n"));
       
   165 	file.Write(_L8("END:VEVENT\r\n"));
       
   166 	file.Write(_L8("END:VCALENDAR\r\n"));
       
   167 
       
   168 	file.Flush();
       
   169 	file.Close();
       
   170 	}