pimappservices/calendar/tsrc/TFAILDEL.CPP
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 1997-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 <s32file.h>
       
    17 #include <conpics.h>
       
    18 #include <e32test.h>
       
    19 #include <badesca.h>
       
    20 
       
    21 #include <calentryview.h>
       
    22 
       
    23 #include "caltestlib.h"
       
    24 
       
    25 RTest test(_L("TFAILDEL"));
       
    26 
       
    27 static const TInt KMyError(-12345);
       
    28 
       
    29 _LIT(KTestCalendarFile, "tfaildel");
       
    30 
       
    31 class CTestApp : public CBase
       
    32 	{
       
    33 public:
       
    34 	static CTestApp* NewL();
       
    35 	~CTestApp();
       
    36 	
       
    37 	void AddEntriesL();
       
    38 	void TestFailL(TInt aEntryToDelete);
       
    39 	void StoreEntryL(const CCalEntry* aEntry);
       
    40 
       
    41 private:
       
    42 	void ConstructL();
       
    43 
       
    44 private:
       
    45 	CCalTestLibrary* iCalTestLib;
       
    46 	CDesC8Array* iGuids;
       
    47 
       
    48 	};
       
    49 	
       
    50 CTestApp* CTestApp::NewL()
       
    51 	{
       
    52 	CTestApp* self = new(ELeave) CTestApp;
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL();
       
    55 	CleanupStack::Pop(self);
       
    56 	return self;
       
    57 	}
       
    58 	
       
    59 void CTestApp::ConstructL()
       
    60 	{
       
    61 	iCalTestLib = CCalTestLibrary::NewL();
       
    62 	iCalTestLib->ReplaceFileL(KTestCalendarFile);
       
    63 	iCalTestLib->OpenFileL(KTestCalendarFile);
       
    64 	
       
    65 	iGuids = new(ELeave) CDesC8ArrayFlat(8);
       
    66 	}
       
    67 		
       
    68 CTestApp::~CTestApp()
       
    69 	{
       
    70 	delete iGuids;
       
    71 	delete iCalTestLib;
       
    72 	}
       
    73 	
       
    74 void CTestApp::StoreEntryL(const CCalEntry* aEntry)
       
    75 	{
       
    76 	RPointerArray<CCalEntry> entryArray;
       
    77 	CleanupClosePushL(entryArray);
       
    78 	entryArray.AppendL(aEntry);
       
    79 	TInt numSuc;
       
    80 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
    81 	test(numSuc == entryArray.Count());
       
    82 	CleanupStack::PopAndDestroy(&entryArray);
       
    83 	}
       
    84 
       
    85 void CTestApp::AddEntriesL()
       
    86 	{
       
    87 	HBufC8* guid = NULL;
       
    88 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guid);
       
    89 	CleanupStack::PushL(entry);
       
    90 	iGuids->AppendL(*guid);
       
    91 	TTime now;
       
    92 	now.HomeTime();
       
    93 	iCalTestLib->SetEntryStartAndEndTimeL(entry, now, now + TTimeIntervalMinutes(60));
       
    94 	entry->SetSummaryL(_L("an appt"));
       
    95 	StoreEntryL(entry);
       
    96 	CleanupStack::PopAndDestroy(entry);
       
    97 	
       
    98 	guid = NULL;
       
    99 	entry = iCalTestLib->CreateCalEntryL(CCalEntry::ETodo, guid);
       
   100 	CleanupStack::PushL(entry);
       
   101 	iGuids->AppendL(*guid);
       
   102 	entry->SetSummaryL(_L("todo"));
       
   103 	StoreEntryL(entry);
       
   104 	CleanupStack::PopAndDestroy(entry);
       
   105 	}
       
   106 
       
   107 
       
   108 void CTestApp::TestFailL(TInt aEntryToDelete)
       
   109 	{
       
   110 #if defined(_DEBUG)
       
   111 	TInt failAt(0);
       
   112 #endif
       
   113 	
       
   114 	FOREVER
       
   115 		{
       
   116 		CDesC8Array* guids = new(ELeave) CDesC8ArrayFlat(1);
       
   117 		CleanupStack::PushL(guids);
       
   118 		
       
   119 		guids->AppendL((*iGuids)[aEntryToDelete]);
       
   120 		
       
   121 #if defined(_DEBUG)
       
   122 		iCalTestLib->FileSession().SetErrorCondition(KMyError, ++failAt);
       
   123 #endif
       
   124 		TRAPD(ret, iCalTestLib->SynCGetEntryViewL().DeleteL(*guids));
       
   125 #if defined(_DEBUG)
       
   126 		iCalTestLib->FileSession().SetErrorCondition(KErrNone);
       
   127 #endif
       
   128 		CleanupStack::PopAndDestroy(guids);
       
   129 		
       
   130 		test(ret == KErrNone || ret == KMyError || ret == KErrNotFound);
       
   131 		
       
   132 		// if the entry gets deleted from the store, then commit fails but the subsequnet revert fails also
       
   133 		// then the entry cannot be found in the store next time around
       
   134 		if (ret == KErrNone || ret == KErrNotFound)
       
   135 			{
       
   136 			break;
       
   137 			}
       
   138 		
       
   139 		}
       
   140 	}
       
   141 
       
   142 
       
   143 
       
   144 static void doMainL()
       
   145 	{
       
   146 	CTestApp* testApp = CTestApp::NewL();
       
   147 	CleanupStack::PushL(testApp);
       
   148 	
       
   149 	testApp->AddEntriesL();
       
   150 
       
   151 	test.Next(_L("Test 1 - Delete Appointment"));
       
   152 
       
   153 	testApp->TestFailL(0);
       
   154 	
       
   155 	test.Next(_L("Test 2 - Delete Todo"));
       
   156 
       
   157 	testApp->TestFailL(1);
       
   158 	
       
   159 	CleanupStack::PopAndDestroy(testApp);
       
   160 	}
       
   161 
       
   162 /**
       
   163 
       
   164 @SYMTestCaseID     PIM-TFAILDEL-0001
       
   165 
       
   166 */
       
   167 
       
   168 TInt E32Main()
       
   169 	{	
       
   170 	__UHEAP_MARK;
       
   171 	test.Start(_L("@SYMTESTCaseID:PIM-TFAILDEL-0001 TFAILDEL.CPP"));
       
   172 
       
   173 	test.Title();
       
   174 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   175 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   176 	CActiveScheduler::Install(scheduler);
       
   177 	TRAPD(ret,doMainL());	
       
   178 	delete scheduler;
       
   179 	test(ret==KErrNone);
       
   180 	delete theCleanup;
       
   181 	test.End();
       
   182 	test.Close();
       
   183 	__UHEAP_MARKEND;
       
   184 	return(KErrNone);
       
   185 	}
       
   186