organizer_pub/calendar_interim_utils2_api/tsrc/stiff/src/caleninterimutils2testblocks.cpp
changeset 18 c198609911f9
parent 0 f979ecb2b13e
child 89 b57382753122
--- a/organizer_pub/calendar_interim_utils2_api/tsrc/stiff/src/caleninterimutils2testblocks.cpp	Tue Feb 02 10:12:19 2010 +0200
+++ b/organizer_pub/calendar_interim_utils2_api/tsrc/stiff/src/caleninterimutils2testblocks.cpp	Fri Apr 16 14:57:40 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -21,9 +21,7 @@
 #include <Stiftestinterface.h>
 
 #include "caleninterimutils2test.h"
-#include "CalProgressCallBackListener.h"
-#include "calenglobaldata.h"
-
+#include <calentry.h>
 
 //  LOCAL CONSTANTS AND MACROS
 const TInt KDefaultStartTime( 8 );
@@ -39,9 +37,32 @@
 // -----------------------------------------------------------------------------
 //
 void CCalenInterimUtils2Test::Delete() 
-    {
+{
     // Nothing.
-    }
+	if(iCalenInterimUtils)
+	{
+		delete iCalenInterimUtils;
+		iCalenInterimUtils = NULL;
+	}
+	
+	if(iCalEntryView)
+	{
+		delete iCalEntryView;
+		iCalEntryView = NULL;
+	}
+	
+	if(iWait)
+	{
+		delete iWait;
+		iWait = NULL;
+	}
+	
+	if(iCalSession)
+	{
+		delete iCalSession;
+		iCalSession = NULL;
+	}
+}
 
 // -----------------------------------------------------------------------------
 // CCalendarCommonUtilsTest::RunMethodL
@@ -51,7 +72,10 @@
 TInt CCalenInterimUtils2Test::RunMethodL( 
         CStifItemParser& aItem ) 
     {
-
+	TRAP(iError, iCalSession = CCalSession::NewL(););
+	const TDesC& file = iCalSession->DefaultFileNameL(); 
+	TRAP(iError, iCalSession->OpenL(file));
+	iCalenInterimUtils = CCalenInterimUtils2::NewL();
     static TStifFunctionInfo const KFunctions[] =
         {
         // Copy this line for every implemented function.
@@ -62,6 +86,10 @@
         /** Test functions for API CalenDateUtils */
         ENTRY( "TestGlobalUUID", 
                 CCalenInterimUtils2Test::TestGlobalUUIDL ),
+		ENTRY( "TestPopulateChildEntry", 
+					   CCalenInterimUtils2Test::TestPopulateChildEntryL ),
+	    ENTRY( "TestStore", 
+					  CCalenInterimUtils2Test::TestStoreL ),
         //ADD NEW ENTRY HERE
         // [test cases entries] - Do not remove
         };
@@ -77,7 +105,7 @@
 // (other items were commented in a header).
 // -----------------------------------------------------------------------------
 //
-TInt CCalenInterimUtils2Test::TestGlobalUUIDL( CStifItemParser& aItem )
+TInt CCalenInterimUtils2Test::TestGlobalUUIDL( CStifItemParser& /*aItem*/ )
     {
     TInt retValue = KErrNone;
     // Print to UI
@@ -90,23 +118,18 @@
     // Print to log file
     iLog->Log( KTestGlobalUUID );
     iLog->Log( KTestGlobalUUIDs );
-        // Construct the calendar global data.
-    CCalProgressCallBackListener *callBack = NULL;
-    callBack = CCalProgressCallBackListener::NewL();
-    CCalenGlobalData* globalData = CCalenGlobalData::NewL( *callBack );
     // Make the call to the API.
     // Create unique ID.
     RPointerArray<HBufC8> guids;
-
     TInt i = 0;
-    
     for( ; i<20; i++ )
         {
-        HBufC8* guid = globalData->InterimUtilsL().GlobalUidL();
+        HBufC8* guid = iCalenInterimUtils->GlobalUidL();
         iLog->Log( *guid );
         guids.AppendL(guid);
         }
     
+    // Validate the guids so that none of them will be duplicates
     for(i=1; i < 20; i++)
         {
         for(TInt j = 0; j < i; j++)
@@ -120,16 +143,133 @@
             }
         }
     guids.ResetAndDestroy();
-    globalData->Release();
-
-    // Validate the result.
 
     return retValue;
-
     }
 
+// -----------------------------------------------------------------------------
+// CCalenInterimUtils2Test::TestPopulateChildEntryL
+// Test funtion to test the API CCalenInterimUtils2::PopulateChildEntryL
+// (other items were commented in a header).
+// -----------------------------------------------------------------------------
+//
+TInt CCalenInterimUtils2Test::TestPopulateChildEntryL( CStifItemParser& /*aItem*/ )
+{
+	TInt retValue = KErrNone;
+	_LIT8( KTestUid, "123547");
+	// Print to UI
+	_LIT( KCalenInterimUtils2Test, "CalenInterimUtils2Test" );
+	_LIT( KTestGlobalUUID, "In TestPopulateChildEntryL" );
+	
+	TestModuleIf().Printf( 0, KCalenInterimUtils2Test, KTestGlobalUUID );
+	
+	// Create a parent entry
+	//entry
+	CCalEntry* parentEntry = NULL;
+	
+	parentEntry = CCalEntry::NewL(CCalEntry::EEvent, KTestUid().AllocL(), CCalEntry::EMethodNone, 0 );
+	// Set necessary field
+	parentEntry->SetSummaryL(_L("test Entry"));
+	parentEntry->SetLocationL(_L("test Location"));
+	parentEntry->SetStatusL(CCalEntry::EConfirmed);
+	CleanupStack::PushL( parentEntry );
+	
+	// Create the child entry
+	CCalEntry* childEntry = NULL;
+		
+	childEntry = CCalEntry::NewL(CCalEntry::EEvent, KTestUid().AllocL(), CCalEntry::EMethodNone, 0 );
+	CleanupStack::PushL( childEntry );
+	// Call the api so that all the parent attributes gets transfered to child 
+	iCalenInterimUtils->PopulateChildFromParentL(*childEntry, *parentEntry);
+	
+	// Validation
+	if(childEntry->SummaryL().Compare(parentEntry->SummaryL()))
+	{
+		retValue = KErrGeneral;
+	}
+	else if(childEntry->LocationL().Compare(parentEntry->LocationL()))
+	{
+		retValue = KErrGeneral;
+	}
+	else if(childEntry->StatusL() != parentEntry->StatusL())
+	{
+		retValue = KErrGeneral;
+	}
+	CleanupStack::PopAndDestroy(childEntry);
+	CleanupStack::PopAndDestroy(parentEntry);
+	return retValue;
+}
 
+// -----------------------------------------------------------------------------
+// CCalenInterimUtils2Test::TestStoreL
+// Test funtion to test the API CCalenInterimUtils2::StoreL
+// (other items were commented in a header).
+// -----------------------------------------------------------------------------
+//
+TInt CCalenInterimUtils2Test::TestStoreL( CStifItemParser& /*aItem*/ )
+{
+	TInt retValue = KErrNone;
+	// Print to UI
+	_LIT( KCalenInterimUtils2Test, "CalenInterimUtils2Test" );
+	_LIT( KTestGlobalUUID, "In TestStoreL" );
+	TestModuleIf().Printf( 0, KCalenInterimUtils2Test, KTestGlobalUUID );
+	
+	// Create the entry view
+	TRAPD(error, iCalEntryView = CCalEntryView::NewL(*iCalSession, *this);) 
+	if(!iWait)
+	{
+		TRAP(error, iWait = new (ELeave) CActiveSchedulerWait;);
+		if(!iWait->IsStarted())
+		{
+			iWait->Start();
+		}
+	}
+	if(iError != KErrNone)
+	{
+		return KErrGeneral;
+	} 
+	else
+	{
+		// Entry view creation is complete
+		// Create the CcalEntry and store it
+		_LIT8( KTestUid, "123548");
+		CCalEntry* parentEntry = NULL;
+			
+		parentEntry = CCalEntry::NewL(CCalEntry::EEvent, KTestUid().AllocL(), CCalEntry::EMethodNone, 0 );
+		// Set necessary field
+		parentEntry->SetSummaryL(_L("test Entry"));
+		parentEntry->SetLocationL(_L("test Location"));
+		TCalTime startTime;
+		TDateTime dateTime;
+		dateTime.Set(2010, TMonth(1), 1, 10, 0, 0, 0);
+		TTime time(dateTime);
+		startTime.SetTimeLocalL(time);
+		parentEntry->SetStartAndEndTimeL(startTime, startTime);
+		parentEntry->SetStatusL(CCalEntry::EConfirmed);
+		CleanupStack::PushL( parentEntry );
+		
+		// Store it
+		iCalenInterimUtils->StoreL(*iCalEntryView, *parentEntry, false);
+		CleanupStack::PopAndDestroy(parentEntry);
+	}
+	return retValue;
+}
 
+// -----------------------------------------------------------------------------
+// CCalenInterimUtils2Test::Completed
+// Callback function for entry view creation.
+// (other items were commented in a header).
+// -----------------------------------------------------------------------------
+//
+void CCalenInterimUtils2Test::Completed(TInt aError)
+{
+	iError = aError;
+	// Stop the wait timer
+	if( iWait && iWait->IsStarted())
+	{
+		iWait->AsyncStop();
+	}
+}
 // ========================== OTHER EXPORTED FUNCTIONS =========================
 // None