phonebookengines/contactsmodel/tsrc/Integration/PerfFuncSuite/src/StateMachineStep.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedAll
       
    19  @released
       
    20  */
       
    21 
       
    22 #include "StateMachineStep.h"
       
    23 #include "PerformanceFunctionalityDefs.h"
       
    24 #include <cntfilt.h>
       
    25 
       
    26 const static TInt KNumberOfContacts = 10;
       
    27 
       
    28 _LIT(KTestCase1,"OpeningRecovery");
       
    29 _LIT(KTestCase2,"OpeningAsync");
       
    30 _LIT(KTestCase3,"Writable");
       
    31 _LIT(KTestCase4,"DefaultRecovery");
       
    32 _LIT(KTestCase5,"DefaultCompress");
       
    33 _LIT(KTestCase6,"AsyncInteg");
       
    34 _LIT(KTestCase7,"TablesClosed");
       
    35 _LIT(KTestCase8,"WritableSpeed");
       
    36 
       
    37 _LIT(KTestCasePrint1, "Opening State statemachine Recovery tests");
       
    38 _LIT(KTestCasePrint2, "Opening State statemachine Asynchronous open tests");
       
    39 _LIT(KTestCasePrint3, "Writable State statemachine tests");
       
    40 _LIT(KTestCasePrint4, "Default State recovery statemachine tests");
       
    41 _LIT(KTestCasePrint5, "Default State compression statemachine tests");
       
    42 _LIT(KTestCasePrint6, "Asynchronous Integrity tests");
       
    43 _LIT(KTestCasePrint7, "Tables Closed State statemachine tests");
       
    44 _LIT(KTestCasePrint8, "Writable State statemachine speed dial tests");
       
    45 
       
    46 /**
       
    47  * This class tests the internal implementation of the contact model server
       
    48  * specifically it is designed to stress test the state machine
       
    49  * so that all the major functionality of the state machine is exercised
       
    50  * each test function usually encompasses one test case, the description for
       
    51  * the test case is defined in the related test script file (StateMachineStep.script)
       
    52  * each test step in the test script file usually call this test class with a non
       
    53  * existent ini file section name, the section name correspond to the test case
       
    54  * name stored within this class. The reasoning behind this is that each test case
       
    55  * does not need to store any additional data within the ini file and as such a reference
       
    56  * to an actual ini file section would be redundent.
       
    57  */
       
    58 CStateMachineStep::CStateMachineStep()
       
    59                         : CPerformanceFunctionalityBase( KNumberOfContacts )
       
    60 	{
       
    61 	SetTestStepName(KStateMachineStep);
       
    62 	}
       
    63 
       
    64 TVerdict CStateMachineStep::doTestStepPostambleL()
       
    65 	{
       
    66 	return CPerformanceFunctionalityBase::doTestStepPostambleL();
       
    67 	}
       
    68 
       
    69 void CStateMachineStep::InitializeL()
       
    70 	{
       
    71 	CPerformanceFunctionalityBase::InitializeL();
       
    72 	//set timeout to 0, to minimize waits within the test
       
    73 	iContactsDatabase->SetOperationTimeOutL(0);
       
    74 	}
       
    75 
       
    76 void CStateMachineStep::Cleanup()
       
    77 	{
       
    78     //unload async opens
       
    79     CLEAR( iContactOpenOperation1 );
       
    80     CLEAR( iContactOpenOperation2 );
       
    81 	CPerformanceFunctionalityBase::Cleanup();
       
    82 	}
       
    83 
       
    84 void CStateMachineStep::PreTestL()
       
    85 	{
       
    86 	//does nothing
       
    87 	}
       
    88 
       
    89 TVerdict CStateMachineStep::doTestStepL()
       
    90 	{
       
    91 	__UHEAP_MARK;
       
    92 	InitializeL();
       
    93 	_LIT(KPrintStart, "CStateMachineStep::doTestStepL()");
       
    94 	INFO_PRINTF1(KPrintStart);  //Block start
       
    95 	iIterate->Reset();
       
    96 
       
    97 	const TDesC &KSection = ConfigSection();
       
    98 
       
    99 	if( KSection ==  KTestCase1 )
       
   100 		{
       
   101 		INFO_PRINTF1( KTestCasePrint1 );
       
   102 		OpeningStateRecoverTestsL();
       
   103 		}
       
   104 	else if( KSection ==  KTestCase2 )
       
   105 		{
       
   106 		INFO_PRINTF1( KTestCasePrint2 );
       
   107 		OpeningStateAsyncOpenTestsL();
       
   108 		}
       
   109 	else if( KSection ==  KTestCase3 )
       
   110 		{
       
   111 		INFO_PRINTF1( KTestCasePrint3 );
       
   112 		WritableStateTestsL();
       
   113 		}
       
   114 	else if( KSection ==  KTestCase4 )
       
   115 		{
       
   116 		INFO_PRINTF1( KTestCasePrint4 );
       
   117 		DefaultStateCompressionTestsL();
       
   118 		}
       
   119 	else if( KSection ==  KTestCase5 )
       
   120 		{
       
   121 		INFO_PRINTF1( KTestCasePrint5 );
       
   122 		DefaultStateRecoveryTestsL();
       
   123 		}
       
   124 	else if( KSection ==  KTestCase6 )
       
   125 		{
       
   126 		INFO_PRINTF1( KTestCasePrint6 );
       
   127 		AsynchronousIntegrityTestL();
       
   128 		}
       
   129 	else if( KSection ==  KTestCase7 )
       
   130 		{
       
   131 		INFO_PRINTF1( KTestCasePrint7 );
       
   132 		TablesClosedStateTestsL();
       
   133 		}
       
   134 	else if( KSection ==  KTestCase8 )
       
   135 		{
       
   136 		INFO_PRINTF1( KTestCasePrint8 );
       
   137 		WritableStateSpeedDialTestsL();
       
   138 		}
       
   139 	else
       
   140 		{
       
   141 		MissingTestPanic();
       
   142 		}
       
   143 
       
   144 	Cleanup();
       
   145 	__UHEAP_MARKEND;
       
   146 
       
   147 	return TestStepResult();
       
   148 
       
   149 	}
       
   150 
       
   151 void CStateMachineStep::OpeningStateRecoverTestsL()
       
   152     {
       
   153 	TContactItemId con1 = iIterate->NextL();
       
   154     CContactDatabase *database = CContactDatabase::OpenL();
       
   155 
       
   156     iCompleteSteps = ETrue;
       
   157     TInt error = KErrNone;
       
   158     
       
   159     //transition to opening state
       
   160     TRAP( error, StartRecoverL() );
       
   161     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   162     
       
   163     //open tables while in opening state
       
   164     TRAP( error, database->OpenTablesL() );
       
   165     #ifdef _DEBUG
       
   166     	#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   167     	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   168     	#else
       
   169       	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   170      	#endif     
       
   171     #else
       
   172     INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   173     #endif
       
   174     
       
   175     //transition out of opening state
       
   176     TRAP( error, EndRecoverL() );
       
   177     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   178     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   179     CLEAR( database );
       
   180 
       
   181     iCompleteSteps = ETrue;
       
   182     //transition to opening state
       
   183     TRAP( error, StartRecoverL() );
       
   184     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   185     //transition out of opening state, completing all recovery steps
       
   186     TRAP( error, EndRecoverL() );
       
   187     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   188     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   189 
       
   190     iCompleteSteps = EFalse;
       
   191     //transition to opening state
       
   192     TRAP( error, StartRecoverL() );
       
   193     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   194     //transition out of opening state, cancelling recovery
       
   195     TRAP( error, EndRecoverL() );
       
   196     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   197     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   198 
       
   199     iCompleteSteps = EFalse;
       
   200     //transition to opening state
       
   201     TRAP( error, StartRecoverL() );
       
   202     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   203     //can't access contacts as database is in recovery state
       
   204     TRAP( error,
       
   205             ReadL(con1);
       
   206             CloseL( EFalse );
       
   207         );
       
   208 
       
   209     #ifdef _DEBUG
       
   210     	#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   211 	    INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   212     	#else
       
   213 	    INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   214      	#endif     
       
   215     #else
       
   216     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   217     #endif
       
   218 
       
   219     TRAP( error,
       
   220             OpenL(con1);
       
   221             CloseL( ETrue );
       
   222         );
       
   223     #ifdef _DEBUG
       
   224     	#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   225 	    INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   226     	#else
       
   227 	    INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   228      	#endif         
       
   229     #else
       
   230     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   231     #endif
       
   232     
       
   233     //transition out of opening state, cancelling recovery
       
   234     TRAP( error, EndRecoverL() );
       
   235     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   236     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   237 
       
   238     //after recovery is complete it should be possible to access contact normally
       
   239     TRAP( error,
       
   240             ReadL(con1);
       
   241             CloseL( EFalse );
       
   242         );
       
   243     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   244     TRAP( error,
       
   245             OpenL(con1);
       
   246             CloseL( ETrue );
       
   247         );
       
   248     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   249 
       
   250     }
       
   251 
       
   252 void CStateMachineStep::OpeningStateAsyncOpenTestsL()
       
   253     {
       
   254     CContactDatabase *database1 = NULL;
       
   255     CContactDatabase *database2 = NULL;
       
   256 
       
   257     CLEAR( iContactsDatabase );
       
   258     WaitForServerToExitL();
       
   259 
       
   260     //open databases asynchronously *2
       
   261     iContactOpenOperation1 = CContactDatabase::Open(iStatus1);
       
   262     iContactOpenOperation2 = CContactDatabase::Open(iStatus2);
       
   263     //cancel second async open first
       
   264     CLEAR( iContactOpenOperation2 );
       
   265     CLEAR( iContactOpenOperation1 );
       
   266     //check that async opens were cancelled
       
   267     if( iStatus1.Int() != KErrNone )
       
   268         {
       
   269         INTCOMPARE( KErrCancel, ==, iStatus1.Int(), 0, 0 );
       
   270         }
       
   271     if( iStatus2.Int() != KErrNone )
       
   272         {
       
   273         INTCOMPARE( KErrCancel, ==, iStatus2.Int(), 0, 0 );
       
   274         }
       
   275 
       
   276     //open databases asynchronously *2
       
   277     iContactOpenOperation1 = CContactDatabase::Open(iStatus1);
       
   278     iContactOpenOperation2 = CContactDatabase::Open(iStatus2);
       
   279     //cancel first async open
       
   280     CLEAR( iContactOpenOperation1 );
       
   281     User::WaitForRequest(iStatus2);
       
   282     //get opened database sessions
       
   283     database1 = iContactOpenOperation2->TakeDatabase();
       
   284     //check that databases have been opened
       
   285     INTCOMPARE( reinterpret_cast<TInt>(database1), !=, NULL, 0, 0 );
       
   286     //check that first async open was cancelled
       
   287     INTCOMPARE( KErrCancel, ==, iStatus1.Int(), 0, 0 );
       
   288     //check that second async opened was successful
       
   289     INTCOMPARE( KErrNone, ==, iStatus2.Int(), 0, 0 );
       
   290     //unload opened database sessions
       
   291     CLEAR( database1 );
       
   292     CLEAR( iContactOpenOperation2 );
       
   293 
       
   294     WaitForServerToExitL();
       
   295     //open databases asynchronously *2
       
   296     iContactOpenOperation1 = CContactDatabase::Open(iStatus1);
       
   297     iContactOpenOperation2 = CContactDatabase::Open(iStatus2);
       
   298     //wait for async opens to complete
       
   299     User::WaitForRequest(iStatus1);
       
   300     User::WaitForRequest(iStatus2);
       
   301 
       
   302     //get opened database sessions
       
   303     database1 = iContactOpenOperation1->TakeDatabase();
       
   304     database2 = iContactOpenOperation2->TakeDatabase();
       
   305 
       
   306     //check that databases have been opened
       
   307     INTCOMPARE( reinterpret_cast<TInt>(database1), !=, NULL, 0, 0 );
       
   308     INTCOMPARE( reinterpret_cast<TInt>(database2), !=, NULL, 0, 0 );
       
   309     //unload async opens
       
   310     CLEAR( iContactOpenOperation1 );
       
   311     CLEAR( iContactOpenOperation2 );
       
   312     //unload opened database sessions
       
   313     CLEAR( database1 );
       
   314     CLEAR( database2 );
       
   315     //check that async opens completed successfully
       
   316     INTCOMPARE( KErrNone, ==, iStatus1.Int(), 0, 0 );
       
   317     INTCOMPARE( KErrNone, ==, iStatus2.Int(), 0, 0 );
       
   318 
       
   319 
       
   320     iContactsDatabase = CContactDatabase::OpenL();
       
   321    	#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   322    		iContactsDatabase->DamageDatabaseL(0x666);
       
   323  	#endif
       
   324     CLEAR( iContactsDatabase );
       
   325 
       
   326     WaitForServerToExitL();
       
   327     iActiveRecoverObserver.iCompressOrRecoverError = KErrNone;
       
   328 
       
   329     //open databases asynchronously
       
   330     iContactOpenOperation1 = CContactDatabase::Open(iStatus1);
       
   331     //get partially opened database session
       
   332     database1= iContactOpenOperation1->TakeDatabase();
       
   333     //start async recovery
       
   334     CContactActiveRecover*  recover = database1->CreateRecoverLC();
       
   335 	recover->SetObserver( &iActiveRecoverObserver );
       
   336 	//complete async recovery
       
   337 	while(recover->Step()){}
       
   338 	CleanupStack::PopAndDestroy( recover );
       
   339 	recover = NULL;
       
   340 
       
   341     //unload async opens
       
   342     CLEAR( iContactOpenOperation1 );
       
   343     //unload opened database sessions
       
   344     CLEAR( database1 );
       
   345 
       
   346     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   347 
       
   348     iContactsDatabase = CContactDatabase::OpenL();
       
   349     }
       
   350 
       
   351 void CStateMachineStep::WritableStateTestsL()
       
   352     {
       
   353 	const TContactItemId KContactId = iIterate->NextL();
       
   354 	const TContactItemId KContactId2 = iIterate->NextL();
       
   355     TInt error = KErrNone;
       
   356 
       
   357     //set contact as own card
       
   358     OpenL( KContactId );
       
   359 	TRAP( error, iContactsDatabase->SetOwnCardL( *iContactItem ) );
       
   360     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   361     CommitL( ETrue );
       
   362     //check contact is set as own card
       
   363     INTCOMPARE( iContactsDatabase->OwnCardId(), ==, KContactId, 0, 0 );
       
   364 
       
   365     //set contact as own card again, to test internal functionality of state machine
       
   366     OpenL( KContactId );
       
   367 	TRAP( error, iContactsDatabase->SetOwnCardL( *iContactItem ) );
       
   368     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   369     CommitL( ETrue );
       
   370     //contact is still marked as own card
       
   371     INTCOMPARE( iContactsDatabase->OwnCardId(), ==, KContactId, 0, 0 );
       
   372 
       
   373     //read contact
       
   374     ReadL( KContactId2 );
       
   375     //set contact as own card using read contact
       
   376 	TRAP( error, iContactsDatabase->SetOwnCardL( *iContactItem ) );
       
   377     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   378     CloseL( EFalse );
       
   379     //check that contact is set as own card
       
   380     INTCOMPARE( iContactsDatabase->OwnCardId(), ==, KContactId2, 0, 0 );
       
   381 
       
   382     //Perform recovery while in writeable state and database not damaged
       
   383     TRAP( error,
       
   384             //start async recovery
       
   385             CContactActiveRecover*  recover = iContactsDatabase->CreateRecoverLC();
       
   386         	recover->SetObserver( &iActiveRecoverObserver );
       
   387         	//complete async recovery
       
   388         	while(recover->Step()){}
       
   389         	CleanupStack::PopAndDestroy( recover );
       
   390         	recover = NULL;
       
   391         );
       
   392     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   393     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   394 
       
   395     TRAP( error, iContactsDatabase->RecoverL() );
       
   396     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   397     }
       
   398 
       
   399 void CStateMachineStep::WritableStateSpeedDialTestsL()
       
   400     {
       
   401     _LIT(KFieldValue, "FieldValue");
       
   402 	const TContactItemId KContactId = iIterate->NextL();
       
   403     TInt error = KErrNone;
       
   404     iActiveRecoverObserver.iCompressOrRecoverError = KErrNone;
       
   405 
       
   406     OpenL( KContactId );
       
   407     const TInt KFieldCount = iFields->Count();
       
   408     CloseL( ETrue );
       
   409 
       
   410 
       
   411 	OpenL( KContactId );
       
   412     
       
   413     //try setting an empty field as a SpeedDial
       
   414     //no error should ensue
       
   415     TRAP( error, iContactsDatabase->SetFieldAsSpeedDialL(*iContactItem, 1, 1) );
       
   416 
       
   417     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   418 
       
   419     //write some test data into all fields of the contact item
       
   420     //parameter is used only for Text and Store type fields - others are created on the fly
       
   421     SetAllFieldsL(KFieldValue);
       
   422     CommitL( EFalse );    
       
   423 
       
   424     for( TInt i = 0; i < KFieldCount; ++i)
       
   425         {
       
   426         OpenL( KContactId );
       
   427         TRAP( error, iContactsDatabase->SetFieldAsSpeedDialL(*iContactItem, i, 1) );
       
   428 
       
   429         //if field is text, set speed dial should be successful
       
   430         if( (*iFields)[i].StorageType() == KStorageTypeText)
       
   431             {
       
   432             CloseL( ETrue );
       
   433             INTCOMPARE( KErrNone, ==, error, i, 0 );
       
   434             ReadL( KContactId );
       
   435             TESTPRINTI( (*iFields)[i].IsSpeedDial(), i );
       
   436             CloseL( EFalse );
       
   437             }
       
   438         //if field not text, set speed dial should fail
       
   439         else
       
   440             {
       
   441             CloseL( ETrue );
       
   442             INTCOMPARE( KErrArgument, ==, error, i, 0 );
       
   443             ReadL( KContactId );
       
   444             TESTPRINTI( !(*iFields)[i].IsSpeedDial(),  i );
       
   445             CloseL( EFalse );
       
   446             }
       
   447         }
       
   448 
       
   449     ReadL( KContactId );
       
   450     //set speed dial for unopened/read contact
       
   451     TRAP( error, iContactsDatabase->SetFieldAsSpeedDialL(*iContactItem, 1, 1) );
       
   452     CloseL( EFalse );
       
   453     //set speed dial should fail
       
   454     INTCOMPARE( KErrAccessDenied, ==, error, 0, 0 );
       
   455     ReadL( KContactId );
       
   456     TESTPRINT( !(*iFields)[1].IsSpeedDial() );
       
   457     CloseL( EFalse );
       
   458 
       
   459     //set speed dial for system template - expect error here
       
   460     CContactCard* contact = CContactCard::NewLC( iTemplate );
       
   461     TRAP( error, iContactsDatabase->SetFieldAsSpeedDialL(*contact, 1, 1) );
       
   462     INTCOMPARE( KErrArgument, ==, error, 0, 0 );
       
   463     CleanupStack::PopAndDestroy(contact);
       
   464 
       
   465     //set speed dial for contact with empty field set - expect error here too
       
   466     contact = CContactCard::NewLC();
       
   467     TRAP( error, iContactsDatabase->SetFieldAsSpeedDialL(*contact, 1, 1) );
       
   468     INTCOMPARE( KErrArgument, ==, error, 0, 0 );
       
   469     CleanupStack::PopAndDestroy(contact);
       
   470     }
       
   471 
       
   472 /**
       
   473 Perform operations that are not supported by current state, so that default state is used
       
   474 all operations should be unsuccessfull
       
   475 */
       
   476 void CStateMachineStep::DefaultStateCompressionTestsL()
       
   477     {
       
   478 	const TContactItemId KContactId = iIterate->NextL();
       
   479     TInt error = KErrNone;
       
   480 
       
   481 	OpenL( KContactId );
       
   482     //transition into compress state
       
   483     StartCompressL();
       
   484 
       
   485     //perform unsupported operations
       
   486     TRAP( error, iContactsDatabase->CloseTables() );//non leaving function
       
   487     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   488 
       
   489     TRAP( error, iContactsDatabase->OpenTablesL() );
       
   490 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   491    	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   492 #else
       
   493    	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   494 #endif
       
   495    	
       
   496     TRAP( error, iContactsDatabase->RecoverL() );
       
   497 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   498    	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   499 #else
       
   500    	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   501 #endif
       
   502 
       
   503 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   504 	// only do this with the DBMS version of the contacts model as DamageDatabaseL
       
   505 	// doesn't do anything in the SQLite version and so the test will always fail.
       
   506     TRAP( error, iContactsDatabase->DamageDatabaseL(0x666); );
       
   507     INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   508 #endif
       
   509 
       
   510     TRAP( error,
       
   511         CContactActiveRecover*  recover = iContactsDatabase->CreateRecoverLC();
       
   512         CleanupStack::PopAndDestroy(recover);
       
   513         );
       
   514 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   515    	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   516 #else
       
   517    	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   518 #endif
       
   519     
       
   520 	TRAP( error, iContactsDatabase->SetOwnCardL( *iContactItem ) );
       
   521 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   522    	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   523 #else
       
   524    	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   525 #endif
       
   526       	
       
   527     TRAP( error, iContactsDatabase->SetFieldAsSpeedDialL(*iContactItem, 1, 1) );
       
   528 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   529    	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   530 #else
       
   531    	INTCOMPARE( KErrInUse, ==, error, 0, 0 );
       
   532 #endif
       
   533    	
       
   534     EndCompressL();
       
   535     //end compress state
       
   536 
       
   537     CloseL( ETrue );
       
   538 
       
   539 
       
   540     }
       
   541 
       
   542 /**
       
   543 Perform operations that are not supported by current state, so that default state is used
       
   544 all operations should be unsuccessfull
       
   545 */
       
   546 void CStateMachineStep::DefaultStateRecoveryTestsL()
       
   547     {
       
   548     TInt error = KErrNone;
       
   549 
       
   550     //transition into opening state
       
   551     StartRecoverL();
       
   552 
       
   553     //perform usupported operations
       
   554     TRAP( error, iContactsDatabase->CompactL() );
       
   555 
       
   556     #ifdef _DEBUG
       
   557     	#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   558     	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   559     	#else
       
   560       	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   561      	#endif     
       
   562     #else
       
   563     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   564     #endif
       
   565 
       
   566 
       
   567     TRAP( error,
       
   568             CContactActiveCompress*  compress = iContactsDatabase->CreateCompressorLC();
       
   569             CleanupStack::PopAndDestroy( compress );
       
   570      );
       
   571 
       
   572     #ifdef _DEBUG
       
   573     	#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   574     	INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   575     	#else
       
   576       	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   577      	#endif     
       
   578     #else
       
   579     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   580     #endif
       
   581 
       
   582     EndRecoverL();
       
   583     //end opening stat
       
   584     }
       
   585 
       
   586 void CStateMachineStep::AsynchronousIntegrityTestL()
       
   587     {
       
   588 	const TContactItemId KContactId = iIterate->NextL();
       
   589     TInt error = KErrNone;
       
   590 
       
   591     //test that it is possible to create multiple active compressor
       
   592     iActiveRecoverObserver.iCompressOrRecoverError = KErrNone;
       
   593     CContactActiveCompress*  compress1 = iContactsDatabase->CreateCompressorLC();
       
   594 	compress1->SetObserver( &iActiveRecoverObserver );
       
   595     CContactActiveCompress*  compress2 = iContactsDatabase->CreateCompressorLC();
       
   596 	compress2->SetObserver( &iActiveRecoverObserver );
       
   597     while(compress1->Step()){}
       
   598     while(compress2->Step()){}
       
   599     CleanupStack::PopAndDestroy( compress2 );
       
   600     CleanupStack::PopAndDestroy( compress1 );
       
   601     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   602 
       
   603 
       
   604     //test that it is possible to create multiple active recoverers
       
   605     iActiveRecoverObserver.iCompressOrRecoverError = KErrNone;
       
   606     CContactActiveRecover*  recover1 = iContactsDatabase->CreateRecoverLC();
       
   607 	recover1->SetObserver( &iActiveRecoverObserver );
       
   608     CContactActiveRecover*  recover2 = iContactsDatabase->CreateRecoverLC();
       
   609 	recover2->SetObserver( &iActiveRecoverObserver );
       
   610     while(recover1->Step()){}
       
   611     while(recover2->Step()){}
       
   612     CleanupStack::PopAndDestroy( recover2 );
       
   613     CleanupStack::PopAndDestroy( recover1 );
       
   614     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   615 
       
   616     //transition into compress state
       
   617 
       
   618     iCompleteSteps = EFalse;
       
   619     StartCompressL();
       
   620     TRAP( error,
       
   621             CContactActiveRecover*  recover = iContactsDatabase->CreateRecoverLC();
       
   622             CleanupStack::PopAndDestroy( recover );
       
   623         );
       
   624 #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   625     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   626 #else    
       
   627     INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   628 #endif   
       
   629 
       
   630     EndCompressL();
       
   631     //end compress state
       
   632 
       
   633     //test that we have transitioned out of compress state
       
   634     TRAP( error, ReadL( KContactId ) );
       
   635     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   636     CloseL( EFalse );
       
   637 
       
   638     iCompleteSteps = EFalse;
       
   639     //transition into opening state
       
   640     StartRecoverL();
       
   641     TRAP( error,
       
   642             CContactActiveCompress*  compress = iContactsDatabase->CreateCompressorLC();
       
   643             CleanupStack::PopAndDestroy( compress );
       
   644         );
       
   645 
       
   646     #ifdef _DEBUG
       
   647    	    #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   648    		INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   649    		#else
       
   650    		INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   651    		#endif     
       
   652     #else
       
   653     	INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   654     #endif
       
   655     
       
   656     EndRecoverL();
       
   657     //transition out of opening state
       
   658 
       
   659     //test that we have transitioned out of compress state
       
   660     TRAP( error, ReadL( KContactId ) );
       
   661     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   662     CloseL( EFalse );
       
   663     }
       
   664 
       
   665 void CStateMachineStep::TablesClosedStateTestsL()
       
   666     {
       
   667 	const TContactItemId KContactId = iIterate->NextL();
       
   668     TInt error = KErrNone;
       
   669 
       
   670     iActiveRecoverObserver.iCompressOrRecoverError = KErrNone;
       
   671     //transition to tables closed state
       
   672     iContactsDatabase->CloseTables();
       
   673 
       
   674 
       
   675     TRAP( error,
       
   676             CContactActiveCompress*  compress = iContactsDatabase->CreateCompressorLC();
       
   677             compress->SetObserver( &iActiveRecoverObserver );
       
   678             CleanupStack::PopAndDestroy( compress );//dont complete all steps
       
   679      );
       
   680     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   681     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   682 
       
   683     //test that we are still in tables closed state
       
   684     TRAP( error, ReadL( KContactId ) );
       
   685     INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   686     CloseL( EFalse );
       
   687 
       
   688     TRAP( error,
       
   689             CContactActiveCompress*  compress = iContactsDatabase->CreateCompressorLC();
       
   690             compress->SetObserver( &iActiveRecoverObserver );
       
   691             while(compress->Step()){}//complete all steps
       
   692             CleanupStack::PopAndDestroy( compress );
       
   693      );
       
   694     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   695     INTCOMPARE( KErrNone, ==, iActiveRecoverObserver.iCompressOrRecoverError, 0, 0 );
       
   696 
       
   697     //test that we are still in tables closed state
       
   698     TRAP( error, ReadL( KContactId ) );
       
   699     INTCOMPARE( KErrNotReady, ==, error, 0, 0 );
       
   700     CloseL( EFalse );
       
   701 
       
   702     //transition to writeable state
       
   703     CContactDatabase *database = NULL;
       
   704     TRAP( error, database = CContactDatabase::OpenL() );
       
   705     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   706 
       
   707     //test that we have transitioned out of tables closed state
       
   708     TRAP( error, ReadL( KContactId ) );
       
   709     INTCOMPARE( KErrNone, ==, error, 0, 0 );
       
   710     CloseL( EFalse );
       
   711 
       
   712     CLEAR( database );
       
   713 
       
   714     }