phonebookengines_old/contactsmodel/tsrc/t_currentdb.h
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     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 #ifndef __T_CURRENTDB_H__
       
    17 #define __T_CURRENTDB_H__
       
    18 
       
    19 // System includes
       
    20 #include <cntdb.h>
       
    21 #include <cntitem.h>
       
    22 #include <cntfield.h>
       
    23 #include <cntfldst.h>
       
    24 
       
    25 // Classes referenced
       
    26 class RTest;
       
    27 class CConsoleBase;
       
    28 class CCntTest;
       
    29 class CTestBase;
       
    30 class CTestManager;
       
    31 
       
    32 
       
    33 //
       
    34 // -------> CTestBase (header)
       
    35 //
       
    36 class CTestBase : public CActive, public MContactDbObserver
       
    37 	{
       
    38 //
       
    39 public:							// ENUMERATIONS SHARED BETWEEN DRIVER & TEST
       
    40 //
       
    41 	enum
       
    42 		{
       
    43 		EStartTests = 0,
       
    44 		ETest1 = EStartTests,
       
    45 		ETest2,
       
    46 		ETest3,
       
    47 		ETest4,
       
    48 		ETest5,
       
    49 		ETest6,
       
    50 		ETest7,
       
    51 		ETest8,
       
    52 		ETest9,
       
    53 		EEndTests
       
    54 		};
       
    55 	
       
    56 //
       
    57 public:							// STATIC CONSTRUCT / DESTRUCT
       
    58 //
       
    59 	~CTestBase();
       
    60 
       
    61 //
       
    62 public:							// ACCESS
       
    63 //
       
    64 	void						Complete(TInt aReason);
       
    65 	inline TInt					CurrentTest() const				{ return iCurrentTest; }
       
    66 	inline RThread&				Thread()						{ return iThread; }
       
    67 	inline TBool				Waiting() const					{ return iWaiting || iWaitingForAnyEvent; }
       
    68 
       
    69 //
       
    70 protected:						// INTERNAL CONSTRUCTION
       
    71 //
       
    72 	CTestBase(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority);
       
    73 	virtual void				ConstructL(const TDesC& aName);
       
    74 	//
       
    75 	static TInt					ThreadFunction(TAny *aParam);
       
    76 	void						RunTestsL();
       
    77 
       
    78 //
       
    79 protected:						// TEST FRAMEWORK
       
    80 //
       
    81 	virtual void				OpenDatabaseL() = 0;
       
    82 	virtual TInt				HandleThreadCreationL();
       
    83 	virtual void				HandleThreadDeletionL();
       
    84 
       
    85 //
       
    86 protected:						// FROM MContactDbObserver
       
    87 //
       
    88 	void						HandleDatabaseEventL(TContactDbObserverEvent aEvent);
       
    89 
       
    90 //
       
    91 private:						// FROM CActive
       
    92 //
       
    93 	void						RunL();
       
    94 	void						DoCancel();
       
    95 
       
    96 //
       
    97 protected:						// TEST RELATED
       
    98 //
       
    99 	void						ReadyForNextTest();
       
   100 	void						WaitForContactsEvent(TContactDbObserverEventType aEvent, TInt aTimeInSecondsToWaitFor = 30);
       
   101 	void						WaitForAnyContactsEvent(TInt aTimeInSecondsToWaitFor = 30);
       
   102 
       
   103 	virtual void				DoTestL(TInt aTestNumber) = 0;
       
   104 	void 						OpenSemaphoreL();
       
   105 	void						CloseSemaphore();
       
   106 
       
   107 //
       
   108 protected:						// MEMBER DATA
       
   109 //
       
   110 	CTestManager&				iTestCoordinator;
       
   111 
       
   112 	// Owned by this class after the thread has been created
       
   113 	CCntTest*					iContactsTest;
       
   114 	CConsoleBase*				iConsole;
       
   115 	RTest*						iTest;
       
   116 
       
   117 	//
       
   118 	TInt						iCurrentTest;
       
   119 	TInt						iClientNumber;
       
   120 	RThread						iThread;
       
   121 	TThreadPriority				iThreadPriority;
       
   122 	
       
   123 	//
       
   124 	TBool						iWaiting;
       
   125 	TBool						iWaitingForAnyEvent;
       
   126 	TContactDbObserverEventType	iEvent;
       
   127 	TContactDbObserverEvent		iLastEvent;
       
   128 	RTimer						iWaitTimer;
       
   129 	RSemaphore					iSemaphoreOne;
       
   130 	RSemaphore					iSemaphoreTwo;
       
   131 	};
       
   132 
       
   133 
       
   134 //
       
   135 // -------> CTestThreadOne (header)
       
   136 //
       
   137 class CTestThreadOne : public CTestBase
       
   138 	{
       
   139 //
       
   140 public:							// FROM CTestBase
       
   141 //
       
   142 	static CTestThreadOne*		NewL(TInt aClientNumber, const TDesC& aName, CTestManager& aTester, TThreadPriority aThreadPriority = EPriorityNormal, TInt aPriority = EPriorityStandard);
       
   143 	void						DoTestL(TInt aTestNumber);
       
   144 	void						OpenDatabaseL();
       
   145 	
       
   146 //
       
   147 private:						// INTERNAL
       
   148 //
       
   149 	CTestThreadOne(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority);
       
   150 	//
       
   151 	void						DoTest1L();
       
   152 	void						DoTest2L();
       
   153 	void						DoTest3L();
       
   154 	void						DoTest4L();
       
   155 	void						DoTest5L();
       
   156 	void						DoTest6L();
       
   157 	void						DoTest7L();
       
   158 	void						DoTest8L();
       
   159 	void						DoTest9L();
       
   160 	};
       
   161 
       
   162 
       
   163 //
       
   164 // -------> CTestThreadTwo (header)
       
   165 //
       
   166 class CTestThreadTwo : public CTestBase
       
   167 	{
       
   168 //
       
   169 public:							// FROM CTestBase
       
   170 //
       
   171 	static CTestThreadTwo*		NewL(TInt aClientNumber, const TDesC& aName, CTestManager& aTester, TThreadPriority aThreadPriority, TInt aPriority = EPriorityStandard);
       
   172 	void						DoTestL(TInt aTestNumber);
       
   173 	void						OpenDatabaseL();
       
   174 	
       
   175 //
       
   176 private:						// INTERNAL
       
   177 //
       
   178 	CTestThreadTwo(CTestManager& aTester, TInt aClientNumber, TThreadPriority aThreadPriority, TInt aPriority);
       
   179 	//
       
   180 	void						DoTest1L();
       
   181 	void						DoTest2L();
       
   182 	void						DoTest3L();
       
   183 	void						DoTest4L();
       
   184 	void						DoTest5L();
       
   185 	void						DoTest6L();
       
   186 	void						DoTest7L();
       
   187 	void						DoTest8L();
       
   188 	void						DoTest9L();
       
   189 	};
       
   190 
       
   191 
       
   192 //
       
   193 // -------> CTestManager (header)
       
   194 //
       
   195 class CTestManager : public CTimer
       
   196 	{
       
   197 //
       
   198 public:							// STATIC CONSTRUCT
       
   199 //
       
   200 	static CTestManager*		NewLC();
       
   201 	static CTestManager*		NewL();
       
   202 	~CTestManager();
       
   203 
       
   204 //
       
   205 private:						// INTERNAL CONSTRUCT
       
   206 //
       
   207 	CTestManager(TInt aPriority = EPriorityStandard);
       
   208 	void						ConstructL();
       
   209 
       
   210 //
       
   211 private:						// FROM CActive
       
   212 //
       
   213 	void						RunL();
       
   214 
       
   215 //
       
   216 private:						// NEW FUNCTIONS
       
   217 //
       
   218 	void						IssueTimerRequest();
       
   219 
       
   220 //
       
   221 private:						// MEMBER DATA
       
   222 //
       
   223     TInt						iTestNumber;
       
   224 	//
       
   225 	CTestThreadOne*				iClient1;
       
   226 	CTestThreadTwo*				iClient2;
       
   227 	};
       
   228 
       
   229 
       
   230 
       
   231 #endif