buildverification/smoketest/agenda/Src/TestAgendaBase.cpp
branchRCL_3
changeset 19 4ca382093dae
parent 5 6beaa9cf4752
child 20 493058e57c8c
equal deleted inserted replaced
5:6beaa9cf4752 19:4ca382093dae
     1 // Copyright (c) 2006-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 // This contains CTestAgendaCase which is the base class for all the Agenda TestCase DLL
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 #include <uri16.h>
       
    21 #include <uriutils.h>
       
    22 #include <test/testexecutelog.h>
       
    23 #include "TestAgendabase.h"
       
    24 #include "TestAgendaServerLaunchProgress.h"
       
    25 
       
    26 #include <calsession.h>
       
    27 
       
    28 
       
    29 
       
    30 _LIT(KDef,		"default");
       
    31 _LIT(KFileName,		"filenameSecure");
       
    32 
       
    33 void CTestAgendaPicture::NewPictureL(TPictureHeader& /*aHeader*/,const CStreamStore& /*aDeferredPictureStore*/)const
       
    34 /**
       
    35 Creates a new Picture object for use by agenda model, currently the implementation is empty as our code
       
    36 does not use any the functionality.
       
    37 */
       
    38 	{
       
    39 	//empty implementation
       
    40 	}
       
    41 
       
    42 CTestAgendaPicture::CTestAgendaPicture()
       
    43 /**
       
    44 constructor, currently the implementation is empty
       
    45 */
       
    46 	{
       
    47 	//empty implementation
       
    48 	}
       
    49 
       
    50 CTestAgendaPicture::~CTestAgendaPicture()
       
    51 /**
       
    52 destructor, currently the implementation is empty
       
    53 */
       
    54 	{
       
    55 	//empty implementation
       
    56 	}
       
    57 
       
    58 CTestAgendaBase::CTestAgendaBase()
       
    59 : CTestStep()
       
    60 , iSchedular(NULL)
       
    61 , iEnteredBlocked(EFalse)
       
    62 , iExitedBlocked(EFalse)
       
    63 , iSessionConnected(EFalse)
       
    64 , iCalEntryViewBase(NULL)
       
    65 , iStore(NULL)
       
    66 , iCalSession(NULL)
       
    67 	{
       
    68 	}
       
    69 
       
    70 // destructor
       
    71 CTestAgendaBase::~CTestAgendaBase()
       
    72 	{
       
    73 	delete iSchedular;
       
    74 	iSchedular=NULL;
       
    75 	
       
    76 	}
       
    77 
       
    78 enum TVerdict CTestAgendaBase::doTestStepPreambleL()
       
    79 	{
       
    80 	TVerdict	ret = CTestStep::doTestStepPreambleL();
       
    81 	
       
    82 	INFO_PRINTF1(_L("doTestStepPreambleL"));
       
    83 	iSchedular=new (ELeave) CActiveScheduler();
       
    84 	CActiveScheduler::Install(iSchedular);
       
    85 	
       
    86 	iCalSession = CCalSession::NewL();
       
    87 
       
    88 	return ret;
       
    89 	}
       
    90 
       
    91 enum TVerdict CTestAgendaBase::doTestStepPostambleL()
       
    92 	{
       
    93 	
       
    94 	delete iCalEntryViewBase;
       
    95 	iCalEntryViewBase=NULL;
       
    96 	
       
    97 	delete iSchedular;
       
    98 	iSchedular=NULL;
       
    99 	CActiveScheduler::Install(NULL);
       
   100 	
       
   101 
       
   102 	return CTestStep::doTestStepPostambleL();
       
   103 	}
       
   104 
       
   105 // Create a new database
       
   106 void CTestAgendaBase::CreateDatabaseL( void )
       
   107 	{
       
   108 	TPtrC	ptrFileName;
       
   109 	TBool	returnValue =GetStringFromConfig(ConfigSection(), KFileName, ptrFileName);
       
   110 	if ( !returnValue )
       
   111 		returnValue=GetStringFromConfig(KDef, KFileName, ptrFileName);
       
   112 	
       
   113 	if (returnValue)
       
   114 		{
       
   115 		INFO_PRINTF2(_L("filename = %S"), &ptrFileName);
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		User::Leave(KErrNotFound);
       
   120 		}
       
   121 
       
   122 	//	Connect file server
       
   123 	User::LeaveIfError(iFs.Connect());
       
   124 	iSessionConnected=ETrue;
       
   125 	
       
   126 	TInt r;
       
   127 	if (iCalSession)
       
   128 	    {
       
   129 		TRAP(r, iCalSession->CreateCalFileL(ptrFileName));
       
   130 	    }
       
   131 	    
       
   132 	if (r == KErrAlreadyExists)
       
   133 	    {
       
   134 		TRAP_IGNORE(iCalSession->DeleteCalFileL(ptrFileName));
       
   135 		TRAP(r, iCalSession->CreateCalFileL(ptrFileName));
       
   136 	    }
       
   137 
       
   138         
       
   139 	if (r!=KErrNone && r!=KErrAlreadyExists)
       
   140 		{
       
   141 		ERR_PRINTF2(_L("Creating Agenda file failed with error %d"), r);
       
   142 		SetTestStepResult(EFail);
       
   143 		}
       
   144 	}
       
   145 
       
   146 void CTestAgendaBase::OpenDatabaseL( void )
       
   147 	{
       
   148 	TPtrC	ptrFileName;
       
   149 	TBool	returnValue =GetStringFromConfig(ConfigSection(), KFileName, ptrFileName);
       
   150 	if ( !returnValue )
       
   151 		returnValue=GetStringFromConfig(KDef, KFileName, ptrFileName);
       
   152 	
       
   153 
       
   154 	if (returnValue)
       
   155 		{
       
   156 		INFO_PRINTF2(_L("filename = %S"), &ptrFileName);
       
   157 		}
       
   158 	else
       
   159 		{
       
   160 		User::Leave(KErrNotFound);
       
   161 		}
       
   162 
       
   163 	//	Connect file server
       
   164 	User::LeaveIfError(iFs.Connect());
       
   165 	iSessionConnected=ETrue;
       
   166 
       
   167     
       
   168 	if (iCalSession)
       
   169 	    {
       
   170 		iCalSession->OpenL(ptrFileName);
       
   171 	    }	
       
   172     
       
   173 	//open the database by creating an object of CTestAgendaServerLaunchProgress
       
   174 	CTestAgendaServerLaunchProgress*	progress = CTestAgendaServerLaunchProgress::NewL(this);
       
   175 	CleanupStack::PushL(progress);
       
   176 
       
   177 	//kick start the launching process
       
   178 	progress->Start();
       
   179 	CActiveScheduler::Start();
       
   180 	CleanupStack::PopAndDestroy(progress);
       
   181 
       
   182 	}
       
   183 
       
   184 void CTestAgendaBase::CleanupDatabase( void )
       
   185 	{
       
   186 	if (iCalEntryViewBase)
       
   187 	    {
       
   188 		delete iCalEntryViewBase;
       
   189 		iCalEntryViewBase = NULL;
       
   190 	    }
       
   191 
       
   192 /*	if (iCalSession)
       
   193 		{
       
   194 		delete iCalSession;
       
   195 		iCalSession=NULL;
       
   196 		}*/
       
   197 
       
   198 
       
   199 	if (iSessionConnected)
       
   200 		{
       
   201 		iFs.Close();
       
   202 		iSessionConnected=EFalse;
       
   203 		}
       
   204 	}
       
   205 	
       
   206 void CTestAgendaBase::SetCalEntryView(CCalEntryView* calEntryViewPtr)
       
   207     {
       
   208 	iCalEntryViewBase = calEntryViewPtr;
       
   209     }
       
   210 
       
   211 CCalSession& CTestAgendaBase::CalSession()
       
   212     {
       
   213 	if (iCalSession)
       
   214 	    {
       
   215 		return *iCalSession;
       
   216 	    }
       
   217 	else
       
   218 	    {
       
   219 	    iCalSession = CCalSession::NewL();
       
   220 	    
       
   221 	    return *iCalSession;	
       
   222 	    }
       
   223     }
       
   224 
       
   225