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