loggingservices/eventlogger/test/inc/t_logutil2.h
branchRCL_3
changeset 9 667e88a979d7
child 23 26645d81f48d
equal deleted inserted replaced
8:fa9941cf3867 9:667e88a979d7
       
     1 // Copyright (c) 2002-2010 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_logutil2_h
       
    17 #define t_logutil2_h
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <s32file.h>
       
    21 #include <logcli.h>
       
    22 #include <logengdurations.h>
       
    23 #include <logengevents.h>
       
    24 #include <logwraplimits.h>
       
    25 #include <logfilterandeventconstants.hrh>
       
    26 #include <e32base.h>
       
    27 #include <f32file.h>
       
    28 #include <logviewchangeobserver.h>
       
    29 #include <logclientchangeobserver.h>
       
    30 #include "LogChangeDefinition.h"
       
    31 #include "LogServShared.h"
       
    32 #include "LogCliServShared.h"
       
    33 #include <babackup.h>
       
    34 #include "t_logservsession.h"
       
    35 #include "logcntdef.h"
       
    36 #include "t_logutil.h"
       
    37 
       
    38 #ifdef LOGGING_ENABLED
       
    39 
       
    40 #include <f32file.h>
       
    41 #include <flogger.h>
       
    42 
       
    43 
       
    44 
       
    45 _LIT(KLogFileName, "LogEng.txt");
       
    46 _LIT(KLogFolder,   "LogEng");
       
    47 _LIT(KTimeFormat, "%02d.%02d:%02d:%06d    ");
       
    48 _LIT(KTextFormat, "%S");
       
    49 const TInt KLogEngLogBufferSize = 256;
       
    50 
       
    51 class Log : public RFileLogger
       
    52 	{
       
    53 public:
       
    54 	static void New();
       
    55 	static void Write(const TDesC& aText);
       
    56 	static void WriteFormat(TRefByValue<const TDesC> aFmt, ...);
       
    57 private:
       
    58 	static void PruneLogFile();
       
    59   };
       
    60 
       
    61 #define LOGNEW							Log::New()
       
    62 #define LOGTEXT(AAA)					{ _LIT(KString, AAA); Log::Write(KString); }
       
    63 #define LOGTEXT2(AAA, BBB)				{ _LIT(KString, AAA); Log::WriteFormat(TRefByValue<const TDesC>(KString()), BBB); }
       
    64 #define LOGTEXT3(AAA, BBB, CCC)			{ _LIT(KString, AAA); Log::WriteFormat(TRefByValue<const TDesC>(KString()), BBB, CCC); }
       
    65 #define LOGTEXT4(AAA, BBB, CCC, DDD)	{ _LIT(KString, AAA); Log::WriteFormat(TRefByValue<const TDesC>(KString()), BBB, CCC, DDD); }
       
    66 
       
    67 #else//LOGGING_ENABLED
       
    68 
       
    69 #define LOGNEW
       
    70 #define LOGTEXT(AAA)
       
    71 #define LOGTEXT2(AAA, BBB)
       
    72 #define LOGTEXT3(AAA, BBB, CCC)
       
    73 #define LOGTEXT4(AAA, BBB, CCC, DDD)
       
    74 
       
    75 #endif//LOGGING_ENABLED
       
    76 
       
    77 // Globals 
       
    78 GLREF_D CTrapCleanup* theCleanup;
       
    79 GLREF_D CActiveScheduler *testScheduler;
       
    80 GLREF_D RFs theFs;
       
    81 GLREF_D TFileName theLogName;
       
    82 GLREF_D RFile theLog;
       
    83 GLREF_D RLogTestSession theLogServ;
       
    84 
       
    85 #define __FILE_FAILNEXT(X) theFs.SetErrorCondition(KErrGeneral, X)
       
    86 #define __FILE_RESET theFs.SetErrorCondition(KErrNone, 0)
       
    87 
       
    88 #if defined(_UNICODE)
       
    89 	_LIT(KLogDatabaseName,"c:\\private\\101f401d\\Logdbu.dat");
       
    90 #else
       
    91 	_LIT(KLogDatabaseName,"c:\\private\\101f401d\\Logdb.dat");
       
    92 #endif
       
    93 
       
    94 
       
    95 //**********************************
       
    96 // CTestActive
       
    97 //**********************************
       
    98 
       
    99 class CTestActive : public CActive
       
   100 	{
       
   101 public:
       
   102 	CTestActive(TInt aPriority = EPriorityIdle-100);
       
   103 	~CTestActive();
       
   104 	void StartL();
       
   105 	void StartL(TInt);
       
   106 protected:
       
   107 	void DoCancel();
       
   108 	void RunL();
       
   109 private:
       
   110 	TBool iDelayCompletion;
       
   111 	TRequestStatus iStoredStatus;
       
   112 	TInt iDelayTime;
       
   113 	};
       
   114 
       
   115 void doTestsL();
       
   116 
       
   117 
       
   118 //**********************************
       
   119 // CTestTimer
       
   120 //**********************************
       
   121 
       
   122 class CTestTimer : public CTimer
       
   123 	{
       
   124 public:
       
   125 	static CTestTimer* NewL();
       
   126 private:
       
   127 	CTestTimer();
       
   128 	void RunL();	
       
   129 	};
       
   130 
       
   131 //**********************************
       
   132 // TestUtils
       
   133 //**********************************
       
   134 
       
   135 class TestUtils
       
   136 	{
       
   137 public:
       
   138 	static void Initialize(const TDesC& aName);
       
   139 	static void DeleteDatabaseL(TBool aCloseBeforeDelete = ETrue);
       
   140 	static HBufC* CreateBufLC(TInt aLength);
       
   141 	static HBufC8* CreateBuf8LC(TInt aLength);
       
   142 	static TBool FiltersEqual(const CLogFilter& aFilter1, const CLogFilter& aFilter2);
       
   143 	static TBool EventsEqual(const CLogEvent& aEvent1, const CLogEvent& aEvent2);
       
   144 	static TBool TypesEqual(const CLogEventType& aType1, const CLogEventType& aType2);
       
   145 	static TBool WaitForKeyL(TTimeIntervalMicroSeconds32 aDelay, TKeyCode& aKeyCode);
       
   146 	static TBool FileExists(const TDesC& aFile);
       
   147 	static void SetLogServHeapFailureL(RHeap::TAllocFail aType, TInt aRate);
       
   148 	static TBool IsDatabaseOpenL();
       
   149 	static TInt DatabaseSizeL();
       
   150 	static TInt AddEventL();
       
   151 	static void AddViewTestEventsL();
       
   152 	static void AddEventTypeL();
       
   153 	static void CopyCorruptDbL();
       
   154 	static void CopyCorruptDamagedDbL();
       
   155 	static void CopyOldDbL();
       
   156 	static void TestInvalidSchemaL();
       
   157 	static TBool MatchingEnabledL();
       
   158 
       
   159 private:
       
   160 	// starts t_HiCapHelper.exe which has sufficient capability
       
   161     static TInt ExecuteRemoteL(const TDesC& aCommandLineArg);
       
   162 	};
       
   163 
       
   164 #define __LOGSERV_UHEAP_FAILNEXT(X) TestUtils::SetLogServHeapFailureL(RHeap::EFailNext, X)
       
   165 #define __LOGSERV_UHEAP_RESET TestUtils::SetLogServHeapFailureL(RHeap::ENone, 0)
       
   166 
       
   167 //**********************************
       
   168 // CLogViewChangeObserver
       
   169 //**********************************
       
   170 
       
   171 class CLogViewChangeObserver : public CActive, public MLogViewChangeObserver
       
   172 	{
       
   173 public:
       
   174 	enum TStopType
       
   175 		{
       
   176 		EStopOnChanges = 0,
       
   177 		EStopOnRunL,
       
   178 		EStopOnBoth,
       
   179 		EStopOnCount,
       
   180 		EDontStopScheduler
       
   181 		};
       
   182 public:
       
   183 	static CLogViewChangeObserver* NewLC();
       
   184 	~CLogViewChangeObserver();
       
   185 
       
   186 protected:
       
   187 	CLogViewChangeObserver();
       
   188 
       
   189 public:
       
   190 	inline void StartCollectingChanges() 
       
   191 		{ 
       
   192 		Reset(); 
       
   193 		iType = EDontStopScheduler; 
       
   194 		}
       
   195 	CLogChangeDefinition* WaitForChangesLC(TStopType aType = EStopOnChanges, TInt aCount = 0);
       
   196 	CLogChangeDefinition* WaitForChangesLC(TCallBack aCallBack, TStopType aType, TInt aCount = 0);
       
   197 	inline TBool HaveChanges() const 
       
   198 		{ 
       
   199 		return iChanges != NULL; 
       
   200 		}
       
   201 	inline const CLogChangeDefinition& Changes() const 
       
   202 		{ 
       
   203 		__ASSERT_ALWAYS(iChanges, User::Invariant()); 
       
   204 		return *iChanges; 
       
   205 		}
       
   206 	inline void SetActive() 
       
   207 		{ 
       
   208 		CActive::SetActive(); 
       
   209 		iStatus = KRequestPending; 
       
   210 		}
       
   211 	inline void ResetChanges() 
       
   212 		{ 
       
   213 		__ASSERT_ALWAYS(iChanges, User::Invariant()); 
       
   214 		iChanges->Reset(); 
       
   215 		}
       
   216 
       
   217 public:
       
   218 	void HandleLogViewChangeEventAddedL(TLogId aId,   TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount);
       
   219 	void HandleLogViewChangeEventChangedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount);
       
   220 	void HandleLogViewChangeEventDeletedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount);
       
   221 
       
   222 private:
       
   223 	void RunL();
       
   224 	void DoCancel();
       
   225 
       
   226 private:
       
   227 	void Reset();	 
       
   228 
       
   229 protected:
       
   230 	void CheckForSchedulerStop();
       
   231 	void AddChangeL(TLogDatabaseChangeType aType, TLogId aId, TInt aViewIndex);
       
   232  	
       
   233 private:
       
   234 	TInt iExpectedChangeCount;
       
   235 	TBool iHaveFinishedOperation;
       
   236 	TBool iHaveObtainedChanges;
       
   237 	TBool iSchedulerStarted;
       
   238 	TStopType iType;
       
   239 	CLogChangeDefinition* iChanges;
       
   240 	TBool iHaveCallBack;
       
   241 	TCallBack iCallBack;
       
   242 	};
       
   243 
       
   244 //**********************************
       
   245 // CLogViewChangeObserverErrorTest
       
   246 //**********************************
       
   247 
       
   248 class CLogViewChangeObserverErrorTest : public  CLogViewChangeObserver 
       
   249 	{
       
   250 public:
       
   251 	static CLogViewChangeObserverErrorTest* NewLC();
       
   252 
       
   253 private:
       
   254 	CLogViewChangeObserverErrorTest();
       
   255 
       
   256 public:
       
   257 	void HandleLogViewChangeEventAddedL(TLogId aId,   TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount);
       
   258 	};
       
   259 
       
   260 
       
   261 //**********************************
       
   262 // CLogSchedulerTimer
       
   263 //**********************************
       
   264 
       
   265 class CLogSchedulerTimer : public CTimer
       
   266 	{
       
   267 public:
       
   268 	static CLogSchedulerTimer* NewLC();
       
   269 	~CLogSchedulerTimer();
       
   270 
       
   271 private:
       
   272 	CLogSchedulerTimer();
       
   273 	void ConstructL();
       
   274 
       
   275 public:
       
   276 	void Wait(TTimeIntervalMicroSeconds32 aTime);
       
   277 
       
   278 private:
       
   279 	void RunL();
       
   280 	};
       
   281 
       
   282 //**********************************
       
   283 // CLogChangeNotifier
       
   284 //**********************************
       
   285 
       
   286 class CLogChangeNotifier : public CActive
       
   287 	{
       
   288 public:
       
   289 	static CLogChangeNotifier* NewL();
       
   290 	~CLogChangeNotifier();
       
   291 	//
       
   292 private:
       
   293 	CLogChangeNotifier();
       
   294 	void ConstructL();
       
   295 	//
       
   296 	void RunL();
       
   297 	void DoCancel();
       
   298 	//
       
   299 private:
       
   300 	CLogClient* iClient;
       
   301 	TTime iStart;
       
   302 	};
       
   303 
       
   304 //**********************************
       
   305 // Global
       
   306 //**********************************
       
   307 
       
   308 void SetupSchedulerL();
       
   309 void CloseScheduler();
       
   310 void doMainL();
       
   311 TInt E32Main();
       
   312 void DeleteDataFile(const TDesC& aFullName);
       
   313 
       
   314 #endif//t_logutil2_h