organizer_pub/calendar_interim_utils2_api/tsrc/stiff/src/caleninterimutils2testblocks.cpp
changeset 18 c198609911f9
parent 0 f979ecb2b13e
child 89 b57382753122
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include <e32svr.h>
    19 #include <e32svr.h>
    20 #include <StifParser.h>
    20 #include <StifParser.h>
    21 #include <Stiftestinterface.h>
    21 #include <Stiftestinterface.h>
    22 
    22 
    23 #include "caleninterimutils2test.h"
    23 #include "caleninterimutils2test.h"
    24 #include "CalProgressCallBackListener.h"
    24 #include <calentry.h>
    25 #include "calenglobaldata.h"
       
    26 
       
    27 
    25 
    28 //  LOCAL CONSTANTS AND MACROS
    26 //  LOCAL CONSTANTS AND MACROS
    29 const TInt KDefaultStartTime( 8 );
    27 const TInt KDefaultStartTime( 8 );
    30 
    28 
    31 // ============================= LOCAL FUNCTIONS ===============================
    29 // ============================= LOCAL FUNCTIONS ===============================
    37 // Delete here all resources allocated and opened from test methods. 
    35 // Delete here all resources allocated and opened from test methods. 
    38 // Called from destructor. 
    36 // Called from destructor. 
    39 // -----------------------------------------------------------------------------
    37 // -----------------------------------------------------------------------------
    40 //
    38 //
    41 void CCalenInterimUtils2Test::Delete() 
    39 void CCalenInterimUtils2Test::Delete() 
    42     {
    40 {
    43     // Nothing.
    41     // Nothing.
    44     }
    42 	if(iCalenInterimUtils)
       
    43 	{
       
    44 		delete iCalenInterimUtils;
       
    45 		iCalenInterimUtils = NULL;
       
    46 	}
       
    47 	
       
    48 	if(iCalEntryView)
       
    49 	{
       
    50 		delete iCalEntryView;
       
    51 		iCalEntryView = NULL;
       
    52 	}
       
    53 	
       
    54 	if(iWait)
       
    55 	{
       
    56 		delete iWait;
       
    57 		iWait = NULL;
       
    58 	}
       
    59 	
       
    60 	if(iCalSession)
       
    61 	{
       
    62 		delete iCalSession;
       
    63 		iCalSession = NULL;
       
    64 	}
       
    65 }
    45 
    66 
    46 // -----------------------------------------------------------------------------
    67 // -----------------------------------------------------------------------------
    47 // CCalendarCommonUtilsTest::RunMethodL
    68 // CCalendarCommonUtilsTest::RunMethodL
    48 // Run specified method. Contains also table of test mothods and their names.
    69 // Run specified method. Contains also table of test mothods and their names.
    49 // -----------------------------------------------------------------------------
    70 // -----------------------------------------------------------------------------
    50 //
    71 //
    51 TInt CCalenInterimUtils2Test::RunMethodL( 
    72 TInt CCalenInterimUtils2Test::RunMethodL( 
    52         CStifItemParser& aItem ) 
    73         CStifItemParser& aItem ) 
    53     {
    74     {
    54 
    75 	TRAP(iError, iCalSession = CCalSession::NewL(););
       
    76 	const TDesC& file = iCalSession->DefaultFileNameL(); 
       
    77 	TRAP(iError, iCalSession->OpenL(file));
       
    78 	iCalenInterimUtils = CCalenInterimUtils2::NewL();
    55     static TStifFunctionInfo const KFunctions[] =
    79     static TStifFunctionInfo const KFunctions[] =
    56         {
    80         {
    57         // Copy this line for every implemented function.
    81         // Copy this line for every implemented function.
    58         // First string is the function name used in TestScripter script file.
    82         // First string is the function name used in TestScripter script file.
    59         // Second is the actual implementation member function. 
    83         // Second is the actual implementation member function. 
    60         // Example: ENTRY( "Example", CCalenInterimUtils2Test::ExampleL ),
    84         // Example: ENTRY( "Example", CCalenInterimUtils2Test::ExampleL ),
    61 
    85 
    62         /** Test functions for API CalenDateUtils */
    86         /** Test functions for API CalenDateUtils */
    63         ENTRY( "TestGlobalUUID", 
    87         ENTRY( "TestGlobalUUID", 
    64                 CCalenInterimUtils2Test::TestGlobalUUIDL ),
    88                 CCalenInterimUtils2Test::TestGlobalUUIDL ),
       
    89 		ENTRY( "TestPopulateChildEntry", 
       
    90 					   CCalenInterimUtils2Test::TestPopulateChildEntryL ),
       
    91 	    ENTRY( "TestStore", 
       
    92 					  CCalenInterimUtils2Test::TestStoreL ),
    65         //ADD NEW ENTRY HERE
    93         //ADD NEW ENTRY HERE
    66         // [test cases entries] - Do not remove
    94         // [test cases entries] - Do not remove
    67         };
    95         };
    68 
    96 
    69     const TInt count = sizeof( KFunctions ) / sizeof( TStifFunctionInfo );
    97     const TInt count = sizeof( KFunctions ) / sizeof( TStifFunctionInfo );
    75 // CCalenInterimUtils2Test::TestGlobalUUIDL
   103 // CCalenInterimUtils2Test::TestGlobalUUIDL
    76 // Test funtion to test the API CCalenInterimUtils2::GlobalUidL
   104 // Test funtion to test the API CCalenInterimUtils2::GlobalUidL
    77 // (other items were commented in a header).
   105 // (other items were commented in a header).
    78 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
    79 //
   107 //
    80 TInt CCalenInterimUtils2Test::TestGlobalUUIDL( CStifItemParser& aItem )
   108 TInt CCalenInterimUtils2Test::TestGlobalUUIDL( CStifItemParser& /*aItem*/ )
    81     {
   109     {
    82     TInt retValue = KErrNone;
   110     TInt retValue = KErrNone;
    83     // Print to UI
   111     // Print to UI
    84     _LIT( KCalenInterimUtils2Test, "CalenInterimUtils2Test" );
   112     _LIT( KCalenInterimUtils2Test, "CalenInterimUtils2Test" );
    85     _LIT( KDuplicateUids, "Uids are duplicate" );
   113     _LIT( KDuplicateUids, "Uids are duplicate" );
    88     
   116     
    89     TestModuleIf().Printf( 0, KCalenInterimUtils2Test, KTestGlobalUUID );
   117     TestModuleIf().Printf( 0, KCalenInterimUtils2Test, KTestGlobalUUID );
    90     // Print to log file
   118     // Print to log file
    91     iLog->Log( KTestGlobalUUID );
   119     iLog->Log( KTestGlobalUUID );
    92     iLog->Log( KTestGlobalUUIDs );
   120     iLog->Log( KTestGlobalUUIDs );
    93         // Construct the calendar global data.
       
    94     CCalProgressCallBackListener *callBack = NULL;
       
    95     callBack = CCalProgressCallBackListener::NewL();
       
    96     CCalenGlobalData* globalData = CCalenGlobalData::NewL( *callBack );
       
    97     // Make the call to the API.
   121     // Make the call to the API.
    98     // Create unique ID.
   122     // Create unique ID.
    99     RPointerArray<HBufC8> guids;
   123     RPointerArray<HBufC8> guids;
   100 
       
   101     TInt i = 0;
   124     TInt i = 0;
   102     
       
   103     for( ; i<20; i++ )
   125     for( ; i<20; i++ )
   104         {
   126         {
   105         HBufC8* guid = globalData->InterimUtilsL().GlobalUidL();
   127         HBufC8* guid = iCalenInterimUtils->GlobalUidL();
   106         iLog->Log( *guid );
   128         iLog->Log( *guid );
   107         guids.AppendL(guid);
   129         guids.AppendL(guid);
   108         }
   130         }
   109     
   131     
       
   132     // Validate the guids so that none of them will be duplicates
   110     for(i=1; i < 20; i++)
   133     for(i=1; i < 20; i++)
   111         {
   134         {
   112         for(TInt j = 0; j < i; j++)
   135         for(TInt j = 0; j < i; j++)
   113             {
   136             {
   114             if( guids[j] == guids[i] )
   137             if( guids[j] == guids[i] )
   118                 break;
   141                 break;
   119                 }
   142                 }
   120             }
   143             }
   121         }
   144         }
   122     guids.ResetAndDestroy();
   145     guids.ResetAndDestroy();
   123     globalData->Release();
       
   124 
       
   125     // Validate the result.
       
   126 
   146 
   127     return retValue;
   147     return retValue;
   128 
       
   129     }
   148     }
   130 
   149 
   131 
   150 // -----------------------------------------------------------------------------
   132 
   151 // CCalenInterimUtils2Test::TestPopulateChildEntryL
       
   152 // Test funtion to test the API CCalenInterimUtils2::PopulateChildEntryL
       
   153 // (other items were commented in a header).
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 TInt CCalenInterimUtils2Test::TestPopulateChildEntryL( CStifItemParser& /*aItem*/ )
       
   157 {
       
   158 	TInt retValue = KErrNone;
       
   159 	_LIT8( KTestUid, "123547");
       
   160 	// Print to UI
       
   161 	_LIT( KCalenInterimUtils2Test, "CalenInterimUtils2Test" );
       
   162 	_LIT( KTestGlobalUUID, "In TestPopulateChildEntryL" );
       
   163 	
       
   164 	TestModuleIf().Printf( 0, KCalenInterimUtils2Test, KTestGlobalUUID );
       
   165 	
       
   166 	// Create a parent entry
       
   167 	//entry
       
   168 	CCalEntry* parentEntry = NULL;
       
   169 	
       
   170 	parentEntry = CCalEntry::NewL(CCalEntry::EEvent, KTestUid().AllocL(), CCalEntry::EMethodNone, 0 );
       
   171 	// Set necessary field
       
   172 	parentEntry->SetSummaryL(_L("test Entry"));
       
   173 	parentEntry->SetLocationL(_L("test Location"));
       
   174 	parentEntry->SetStatusL(CCalEntry::EConfirmed);
       
   175 	CleanupStack::PushL( parentEntry );
       
   176 	
       
   177 	// Create the child entry
       
   178 	CCalEntry* childEntry = NULL;
       
   179 		
       
   180 	childEntry = CCalEntry::NewL(CCalEntry::EEvent, KTestUid().AllocL(), CCalEntry::EMethodNone, 0 );
       
   181 	CleanupStack::PushL( childEntry );
       
   182 	// Call the api so that all the parent attributes gets transfered to child 
       
   183 	iCalenInterimUtils->PopulateChildFromParentL(*childEntry, *parentEntry);
       
   184 	
       
   185 	// Validation
       
   186 	if(childEntry->SummaryL().Compare(parentEntry->SummaryL()))
       
   187 	{
       
   188 		retValue = KErrGeneral;
       
   189 	}
       
   190 	else if(childEntry->LocationL().Compare(parentEntry->LocationL()))
       
   191 	{
       
   192 		retValue = KErrGeneral;
       
   193 	}
       
   194 	else if(childEntry->StatusL() != parentEntry->StatusL())
       
   195 	{
       
   196 		retValue = KErrGeneral;
       
   197 	}
       
   198 	CleanupStack::PopAndDestroy(childEntry);
       
   199 	CleanupStack::PopAndDestroy(parentEntry);
       
   200 	return retValue;
       
   201 }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CCalenInterimUtils2Test::TestStoreL
       
   205 // Test funtion to test the API CCalenInterimUtils2::StoreL
       
   206 // (other items were commented in a header).
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt CCalenInterimUtils2Test::TestStoreL( CStifItemParser& /*aItem*/ )
       
   210 {
       
   211 	TInt retValue = KErrNone;
       
   212 	// Print to UI
       
   213 	_LIT( KCalenInterimUtils2Test, "CalenInterimUtils2Test" );
       
   214 	_LIT( KTestGlobalUUID, "In TestStoreL" );
       
   215 	TestModuleIf().Printf( 0, KCalenInterimUtils2Test, KTestGlobalUUID );
       
   216 	
       
   217 	// Create the entry view
       
   218 	TRAPD(error, iCalEntryView = CCalEntryView::NewL(*iCalSession, *this);) 
       
   219 	if(!iWait)
       
   220 	{
       
   221 		TRAP(error, iWait = new (ELeave) CActiveSchedulerWait;);
       
   222 		if(!iWait->IsStarted())
       
   223 		{
       
   224 			iWait->Start();
       
   225 		}
       
   226 	}
       
   227 	if(iError != KErrNone)
       
   228 	{
       
   229 		return KErrGeneral;
       
   230 	} 
       
   231 	else
       
   232 	{
       
   233 		// Entry view creation is complete
       
   234 		// Create the CcalEntry and store it
       
   235 		_LIT8( KTestUid, "123548");
       
   236 		CCalEntry* parentEntry = NULL;
       
   237 			
       
   238 		parentEntry = CCalEntry::NewL(CCalEntry::EEvent, KTestUid().AllocL(), CCalEntry::EMethodNone, 0 );
       
   239 		// Set necessary field
       
   240 		parentEntry->SetSummaryL(_L("test Entry"));
       
   241 		parentEntry->SetLocationL(_L("test Location"));
       
   242 		TCalTime startTime;
       
   243 		TDateTime dateTime;
       
   244 		dateTime.Set(2010, TMonth(1), 1, 10, 0, 0, 0);
       
   245 		TTime time(dateTime);
       
   246 		startTime.SetTimeLocalL(time);
       
   247 		parentEntry->SetStartAndEndTimeL(startTime, startTime);
       
   248 		parentEntry->SetStatusL(CCalEntry::EConfirmed);
       
   249 		CleanupStack::PushL( parentEntry );
       
   250 		
       
   251 		// Store it
       
   252 		iCalenInterimUtils->StoreL(*iCalEntryView, *parentEntry, false);
       
   253 		CleanupStack::PopAndDestroy(parentEntry);
       
   254 	}
       
   255 	return retValue;
       
   256 }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CCalenInterimUtils2Test::Completed
       
   260 // Callback function for entry view creation.
       
   261 // (other items were commented in a header).
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CCalenInterimUtils2Test::Completed(TInt aError)
       
   265 {
       
   266 	iError = aError;
       
   267 	// Stop the wait timer
       
   268 	if( iWait && iWait->IsStarted())
       
   269 	{
       
   270 		iWait->AsyncStop();
       
   271 	}
       
   272 }
   133 // ========================== OTHER EXPORTED FUNCTIONS =========================
   273 // ========================== OTHER EXPORTED FUNCTIONS =========================
   134 // None
   274 // None
   135 
   275 
   136 //  [End of File] - Do not remove
   276 //  [End of File] - Do not remove