phonebookengines/contactsmodel/tsrc/cntmodel2/t_requeststoretest.h
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2007-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_REQUESTSTOREFAILURE_H__
       
    17 #define __T_REQUESTSTOREFAILURE_H__
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <cntdb.h>
       
    21 
       
    22 enum TTestCodes
       
    23     {
       
    24     ELockDatabase,
       
    25     EDeleteInvalidCnt
       
    26     };
       
    27 
       
    28 const TTimeIntervalMicroSeconds32 KOneHalfSecondTimeOut =   500000;
       
    29 const TTimeIntervalMicroSeconds32 KSixtySecondsTimeOut  = 60000000;
       
    30 
       
    31 // forward declaration
       
    32 class CConcurrentTester;
       
    33 class CConcurrentController;
       
    34 
       
    35 
       
    36 //===========================================================
       
    37 // CLockDatabase Class
       
    38 //===========================================================
       
    39 //
       
    40 class CLockDatabase: private CActive
       
    41     {
       
    42     public:
       
    43         ~CLockDatabase();
       
    44         static CLockDatabase* NewLC();
       
    45 
       
    46     public:
       
    47         // from CActive
       
    48         void DoCancel();
       
    49         TInt RunError(TInt aError);
       
    50         void RunL();
       
    51 
       
    52     private:
       
    53         // constructor & 2nd phase constructor
       
    54         CLockDatabase();
       
    55         void ConstructL();
       
    56         
       
    57         void OpenDatabaseL();        
       
    58 
       
    59     private:
       
    60         CContactDatabase* iContactDatabase;
       
    61         RTest* iTest;
       
    62         TBool iLocked;
       
    63     };
       
    64 
       
    65 //===========================================================
       
    66 // CDeleteInvalidCnt Class
       
    67 //===========================================================
       
    68 //
       
    69 class CDeleteInvalidCnt: public CActive
       
    70     {
       
    71 public:
       
    72     ~CDeleteInvalidCnt();
       
    73     static CDeleteInvalidCnt* NewLC();
       
    74 
       
    75 public:
       
    76     // from CActive
       
    77     void DoCancel();
       
    78     TInt RunError(TInt aError);
       
    79     void RunL();
       
    80 
       
    81 private:
       
    82     // constructor and 2nd phase constructor
       
    83     CDeleteInvalidCnt();
       
    84     void ConstructL();
       
    85 
       
    86     void OpenDatabaseL();
       
    87 
       
    88 private:
       
    89     TInt iStep;
       
    90     CContactDatabase* iContactDatabase;
       
    91     RTest* iTest;
       
    92     };
       
    93 
       
    94 
       
    95 //===========================================================
       
    96 // CEventResponse Class
       
    97 //
       
    98 // Responsible for signalling the controller.
       
    99 // It is created by the controller, passed into the Tester.
       
   100 // The tester contains the response, and destroys it.
       
   101 // The response is "completed" by the ThreadTest.
       
   102 //===========================================================
       
   103 //
       
   104 class CEventResponse : CActive
       
   105     {
       
   106 public:
       
   107     static CEventResponse* NewL(CConcurrentController& aController);
       
   108     ~CEventResponse();
       
   109     void CompleteRequest(TInt aError);
       
   110     TRequestStatus& RequestStatus();
       
   111 
       
   112 private:
       
   113     TInt RunError(TInt aError);
       
   114     void RunL();
       
   115     void DoCancel();
       
   116     CEventResponse (CConcurrentController& aController);
       
   117 
       
   118 private:
       
   119     CConcurrentController& iController;
       
   120     };
       
   121 
       
   122 
       
   123 //===========================================================
       
   124 // CConcurrentController Class
       
   125 //===========================================================
       
   126 //
       
   127 class CConcurrentController : CBase
       
   128     {
       
   129 public:
       
   130     ~CConcurrentController();
       
   131     static CConcurrentController* NewLC();
       
   132     void  StartTestL();
       
   133     void  PublishError(TInt aError);
       
   134 
       
   135 private:
       
   136     void CreateContactsL(TInt aNumContacts);
       
   137 
       
   138     void CreateTestersL(TInt aNoOfTesters);
       
   139     void StartRequestStoreFailureTestL();
       
   140 
       
   141     // constructor & 2nd-phase constructor
       
   142     CConcurrentController();
       
   143     void ConstructL();
       
   144 
       
   145     TBool Completed();
       
   146 
       
   147 private:
       
   148     RPointerArray<CConcurrentTester> iStore;
       
   149     };
       
   150 
       
   151 
       
   152 //===========================================================
       
   153 // CConcurrentTester Class
       
   154 //===========================================================
       
   155 //
       
   156 class CConcurrentTester : CBase
       
   157     {
       
   158 public:
       
   159     ~CConcurrentTester();
       
   160     static CConcurrentTester* NewL(CEventResponse* aResponse, const TDesC& aThreadName);
       
   161     static TInt ThreadFunction(TAny* aResponse);
       
   162     void RunTestThreadL(TInt iTestCode);
       
   163     TBool IsCompleted();
       
   164 
       
   165 private:
       
   166     inline CConcurrentTester(CEventResponse* aResponse, const TDesC& aThreadName) :
       
   167                             iResponse(aResponse),
       
   168                             iThreadName(aThreadName),
       
   169                             iTestCode(-1) {}
       
   170     void RunTestL();
       
   171 
       
   172 private:
       
   173     RThread                 iThread;
       
   174     CEventResponse*         iResponse;
       
   175     TBuf<256>                iThreadName;
       
   176     TInt                     iTestCode;
       
   177     };
       
   178 
       
   179 #endif //__T_REQUESTSTOREFAILURE_H__