pimappservices/calendar/tsrc/interop/src/alldayevents.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 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 "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 *
       
    16 */
       
    17 
       
    18 //  Include Files  
       
    19 
       
    20 #include "alldayevents.h"
       
    21 #include "../../caltestlib.h"
       
    22 #include <caltime.h>
       
    23 #include <caldataformat.h>
       
    24 #include <versit.h>
       
    25 #include <e32base.h>
       
    26 #include <e32std.h>
       
    27 #include <f32file.h>        // RDir etc.
       
    28 #include <e32cons.h>	    // Console
       
    29 #include <e32test.h>        // RTest
       
    30 #include <s32file.h>        // RFileReadStream
       
    31 
       
    32 
       
    33 //  Constants
       
    34 _LIT(KCalendarFile, "alldayevent");
       
    35 _LIT(KDataDir, "z:\\alldayevents\\");
       
    36 _LIT(KWriteDataDir,"c:\\alldayevents\\");
       
    37 _LIT8(KDTSTART, "DTSTART");
       
    38 _LIT8(KDTEND, "DTEND");
       
    39 
       
    40 //  Global Variables
       
    41 
       
    42 LOCAL_D CCalTestLibrary* calTestLibrary; //calendar utility library
       
    43 RTest test(_L("all_dayevents"));
       
    44 
       
    45 //  Local Functions
       
    46 void  ImportEntriesL(const TDesC& aFileName, RPointerArray<CCalEntry>& aCalEntries)
       
    47     {
       
    48     RFileReadStream fileReadStream;
       
    49     CleanupClosePushL(fileReadStream);
       
    50     TInt err = fileReadStream.Open(calTestLibrary->FileSession(), aFileName, EFileRead);
       
    51     
       
    52     calTestLibrary->DataExchangeL().ImportL(KUidVCalendar, fileReadStream, aCalEntries);
       
    53 	
       
    54 	CleanupStack::PopAndDestroy(&fileReadStream);
       
    55     }
       
    56     
       
    57     
       
    58 void ExportEntriesL(RPointerArray<CCalEntry>& aCalEntries, const TDesC& aFileName)
       
    59     {
       
    60     TEntry dirEntry;
       
    61     
       
    62     // Create a directory if not present
       
    63     if (calTestLibrary->FileSession().Entry(KWriteDataDir(), dirEntry) != KErrNone)
       
    64         {
       
    65     	calTestLibrary->FileSession().MkDir(KWriteDataDir());
       
    66         }
       
    67 	RFileWriteStream fileWriteStream;
       
    68 	CleanupClosePushL(fileWriteStream);
       
    69 	User::LeaveIfError(fileWriteStream.Replace(calTestLibrary->FileSession(), aFileName, EFileWrite));
       
    70 	calTestLibrary->DataExchangeL().ExportL(KUidVCalendar, fileWriteStream, aCalEntries);
       
    71 	
       
    72 	CleanupStack::PopAndDestroy(&fileWriteStream);
       
    73     }
       
    74     
       
    75 TBool TestExportedFile(const TDesC& aFilename)
       
    76     {
       
    77 	//Check for DTSTART and DTEND
       
    78 	//Check it is in DATE-TIME format
       
    79 	TBool DTSTART_patternFound = EFalse;
       
    80 	TBool DTEND_patternFound = EFalse;    
       
    81     
       
    82 	
       
    83 	RFile fileHandle;
       
    84 	CleanupClosePushL(fileHandle);
       
    85 	fileHandle.Open(calTestLibrary->FileSession(),aFilename, 0);
       
    86 	
       
    87 	
       
    88 	TBuf8<256> line;
       
    89 	TInt KDateLength = 8;
       
    90 	TInt KColon = 1;
       
    91 	while (fileHandle.Read(line) == KErrNone && line.Length() != 0)
       
    92 	{
       
    93 	    TInt pos = line.Find(KDTSTART());
       
    94 		if (pos != KErrNotFound)
       
    95 		    {
       
    96 		    DTSTART_patternFound = ETrue;
       
    97 		    TText time;
       
    98 		    time = line[pos + KDTSTART().Length() + KColon + KDateLength ];
       
    99 		    test (time == 'T');	
       
   100 	  	    }
       
   101 	  	pos = line.Find(KDTEND());
       
   102 	    if ( pos != KErrNotFound)
       
   103 		    {
       
   104 			DTEND_patternFound = ETrue;
       
   105 			TText time;
       
   106 		    time = line[pos + KDTEND().Length() + KColon + KDateLength ];
       
   107 			test (time == 'T');
       
   108 			
       
   109 			if (DTSTART_patternFound && DTEND_patternFound)
       
   110 			break;
       
   111 		    }
       
   112 	} 
       
   113 	CleanupStack::PopAndDestroy(&fileHandle);
       
   114 	return (DTSTART_patternFound && DTEND_patternFound);
       
   115 	
       
   116     }
       
   117 
       
   118 TInt CheckTimezoneRules(const CCalEntry& aCalEntry)
       
   119 	{
       
   120 	//See if timezone rules are present, if they are then times should be UTC and not floating
       
   121 	//
       
   122 	CTzRules* tzRules = aCalEntry.TzRulesL();
       
   123 	TCalTime startTime = aCalEntry.StartTimeL();
       
   124 	if (tzRules)
       
   125 		{
       
   126 		test (startTime.TimeMode() !=  TCalTime::EFloating);
       
   127 		}
       
   128 	
       
   129 	return KErrNone;
       
   130 	}
       
   131 
       
   132 
       
   133 /**
       
   134 
       
   135 @SYMTestCaseID     PIM-ALLDAYEVENTS-0001
       
   136 
       
   137 */
       
   138 
       
   139 LOCAL_C void MainL()
       
   140 	{
       
   141 	test.Start(_L("@SYMTESTCaseID:PIM-ALLDAYEVENTS-0001 Getting list of all day events data...."));
       
   142 
       
   143 	RDir dataDir;
       
   144 	CleanupClosePushL(dataDir);
       
   145 	//Open the Data directory and read the file entries
       
   146 	User::LeaveIfError(dataDir.Open(calTestLibrary->FileSession(), KDataDir, KEntryAttNormal));
       
   147 	
       
   148 	TEntryArray* dataArray = new (ELeave) TEntryArray();
       
   149 
       
   150 	CleanupStack::PushL(dataArray);
       
   151 	
       
   152 	dataDir.Read(*dataArray);
       
   153 	
       
   154 	TInt count = dataArray->Count();
       
   155 	test (count != 0);
       
   156 		
       
   157 	for (TInt i=0; i < count; ++i)
       
   158 	    {
       
   159 	    test.Next(_L("ALLDAYEVENTS-0002"));
       
   160 
       
   161 	    TBuf<256> name;
       
   162 	    name = KDataDir;
       
   163 	    name.Append((*dataArray)[i].iName);
       
   164 	    
       
   165 	    RPointerArray<CCalEntry> calEntries;
       
   166 	    CleanupResetAndDestroyPushL(calEntries);
       
   167 	    ImportEntriesL(name, calEntries);
       
   168 	    TInt calEntriesCount = calEntries.Count();
       
   169 	    if (calEntriesCount)	
       
   170 	        {
       
   171 	        //Test entry for the presence of timzone rules and UTC
       
   172 	        CheckTimezoneRules(*calEntries[0]);
       
   173 	        }
       
   174 	    name = KWriteDataDir;
       
   175 	    name.Append((*dataArray)[i].iName);
       
   176 	    
       
   177 	    ExportEntriesL(calEntries, name);
       
   178 	    
       
   179 	    TBool result = TestExportedFile(name);
       
   180 	    
       
   181 	    if (result)
       
   182 	        {
       
   183 	    	calTestLibrary->FileSession().Delete(name);
       
   184 	        }
       
   185 	    
       
   186 	    CleanupStack::PopAndDestroy(&calEntries);
       
   187 	    }
       
   188 	
       
   189 	CleanupStack::PopAndDestroy(dataArray);
       
   190 	CleanupStack::PopAndDestroy(&dataDir);
       
   191 	// This will fail if there was a parsing error in one or more of the data files
       
   192 	// which will still be then present in the directory for inspecting.
       
   193 	test (calTestLibrary->FileSession().RmDir(KWriteDataDir) == KErrNone);
       
   194 	
       
   195 	test.End();
       
   196 	test.Close();
       
   197 	}
       
   198 
       
   199 
       
   200 LOCAL_C void DoStartL()
       
   201 	{
       
   202 	// Create active scheduler (to run active objects)
       
   203 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
       
   204 	CleanupStack::PushL(scheduler);
       
   205 	CActiveScheduler::Install(scheduler);
       
   206 	
       
   207     calTestLibrary = CCalTestLibrary::NewL();
       
   208 	CleanupStack::PushL(calTestLibrary);
       
   209 	calTestLibrary->ReplaceFileL(KCalendarFile);
       
   210 	calTestLibrary->OpenFileL(KCalendarFile);
       
   211 	
       
   212 	MainL();
       
   213     CleanupStack::PopAndDestroy(calTestLibrary);
       
   214 	// Delete active scheduler
       
   215 	CleanupStack::PopAndDestroy(scheduler);
       
   216 	}
       
   217 
       
   218 
       
   219 //  Global Functions
       
   220 
       
   221 GLDEF_C TInt E32Main()
       
   222 	{
       
   223 	// Create cleanup stack
       
   224 	__UHEAP_MARK;
       
   225 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   226 
       
   227 	TRAPD(mainError, DoStartL());
       
   228 	
       
   229 	delete cleanup;
       
   230 	__UHEAP_MARKEND;
       
   231 	return mainError;
       
   232 	}
       
   233 
       
   234 
       
   235