windowing/windowserver/test/t_stress/inc/utils.h
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-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  @test
       
    19  @internalComponent
       
    20 */
       
    21 
       
    22 #ifndef UTILS_H
       
    23 #define UTILS_H
       
    24 
       
    25 #include <e32math.h>
       
    26 #include <w32std.h>
       
    27 
       
    28 /*******************************************************************************
       
    29  This is a wrapper round the horrific Math::Rand interface
       
    30  *******************************************************************************/
       
    31 
       
    32 const TInt KPosLimit = 350;
       
    33 
       
    34 _LIT(KLogFileName, "logging.log"); //to be used to replay the same testrun
       
    35 _LIT(KAnimDllName, "a0005924.dll");
       
    36 
       
    37 class CTestExecWatchCat;
       
    38 
       
    39 class CExecutionContext : public CBase
       
    40 	{
       
    41 	friend class CTestExecWatchCat;
       
    42 	
       
    43 public:
       
    44 	class CLogMediator : public CBase
       
    45 		{
       
    46 	public:
       
    47 		TInt PlaybackInt ();
       
    48 		void RecordInt (TInt aIntToBeRecorded);
       
    49 		static CLogMediator* NewLC (CExecutionContext& aExecutionContext, RFs& aFs,	const TDesC& aFileName);
       
    50 		~CLogMediator ();
       
    51 	
       
    52 	private:
       
    53 		CLogMediator (CExecutionContext& aExecutionContext);
       
    54 		void ConstructL (RFs& aFs, const TDesC& aFileName);
       
    55 	
       
    56 	private:
       
    57 		RFile iLog;
       
    58 		CExecutionContext& iExecutionContext;
       
    59 		TInt64 iEntryNo;
       
    60 		TBool iStalled;
       
    61 		};
       
    62 	
       
    63 	enum TExecutionMode
       
    64 		{
       
    65 		ECtxRandom,
       
    66 		ECtxRandomAndRecord,
       
    67 		ECtxPlayback
       
    68 		};
       
    69 
       
    70 	static CExecutionContext* NewL (TExecutionMode aExecutionMode, CTestExecWatchCat& aWatchCat);
       
    71 	TExecutionMode ContextMode ();
       
    72 	~CExecutionContext ();
       
    73 	void MediatorDestroyed (CLogMediator* aMediator);
       
    74 	void MediatorEmptied (CLogMediator* aMediator);
       
    75 
       
    76 private:
       
    77 	CExecutionContext (TExecutionMode aExecutionMode, CTestExecWatchCat& aWatchCat);
       
    78 	void ConstructL ();
       
    79 	CLogMediator& CreateLogMediatorL (const TDesC& aLogName);
       
    80 
       
    81 private:
       
    82 	RFs iFs;
       
    83 	RPointerArray<CLogMediator> iMediators;
       
    84 	CTestExecWatchCat& iWatchCat;
       
    85 	TExecutionMode iContextMode;
       
    86 	};
       
    87 
       
    88 class CTestExecWatchCat : public CBase
       
    89 	{
       
    90 	friend class CExecutionContext;
       
    91 	
       
    92 public:
       
    93 	static CTestExecWatchCat* NewL (CExecutionContext::TExecutionMode aExecutionMode);
       
    94 	void SetLoggingPathL(const TDesC& aPath);
       
    95 
       
    96 private:
       
    97 	CTestExecWatchCat ( );
       
    98 	~CTestExecWatchCat ( );
       
    99 
       
   100 	void ConstructL (CExecutionContext::TExecutionMode aExecutionMode );
       
   101 	void ExecutionContextRunOut (CExecutionContext* aContext );
       
   102 
       
   103 private:
       
   104 	CExecutionContext* iExecutionContext;
       
   105 	};
       
   106 
       
   107 class TRnd
       
   108 	{
       
   109 public:
       
   110 	static TInt rnd ( TInt x = 0 );
       
   111 	static TInt64 Seed();
       
   112 	static void SetSeed(TInt64 aSeed);
       
   113 	static void SetLogMediator(CExecutionContext::CLogMediator* aMediator);
       
   114 	static void SetExecutionContext(CExecutionContext* aExecutionContext);
       
   115 private:
       
   116 	static TInt GenRand (TInt x );
       
   117 
       
   118 private:
       
   119 	static CExecutionContext::CLogMediator* iMediator;
       
   120 	static CExecutionContext* iExecutionContext;
       
   121 	static TInt64 iSeed;
       
   122 	
       
   123 	friend class CTestExecWatchCat;
       
   124 	};
       
   125 
       
   126 class TTickUtils
       
   127 	{
       
   128 public:
       
   129 	static TUint32 CalcTickDelta (TUint32 tick1, TUint32 tick2 );
       
   130 
       
   131 	};
       
   132 
       
   133 /*******************************************************************************
       
   134  This is a small helper function for drawing regions
       
   135  *******************************************************************************/
       
   136 static void DrawRegion (const TRegion& aRegion, CGraphicsContext& aGc)
       
   137 	{
       
   138 	const TRect * rect = aRegion.RectangleList ();
       
   139 	for (TInt r = 0; r < aRegion.Count (); ++r)
       
   140 		{
       
   141 		aGc.DrawRect (*rect);
       
   142 		++rect;
       
   143 		}
       
   144 	}
       
   145 
       
   146 #endif // UTILS_H