1 // Copyright (c) 2002-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 __TEST_H__ |
|
17 #define __TEST_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 |
|
37 #ifdef LOGGING_ENABLED |
|
38 |
|
39 #include <f32file.h> |
|
40 #include <flogger.h> |
|
41 |
|
42 |
|
43 |
|
44 _LIT(KLogFileName, "LogEng.txt"); |
|
45 _LIT(KLogFolder, "LogEng"); |
|
46 _LIT(KTimeFormat, "%02d.%02d:%02d:%06d "); |
|
47 _LIT(KTextFormat, "%S"); |
|
48 const TInt KLogEngLogBufferSize = 256; |
|
49 |
|
50 class Log : public RFileLogger |
|
51 { |
|
52 public: |
|
53 static void New(); |
|
54 static void Write(const TDesC& aText); |
|
55 static void WriteFormat(TRefByValue<const TDesC> aFmt, ...); |
|
56 private: |
|
57 static void PruneLogFile(); |
|
58 }; |
|
59 |
|
60 #define LOGNEW Log::New() |
|
61 #define LOGTEXT(AAA) { _LIT(KString, AAA); Log::Write(KString); } |
|
62 #define LOGTEXT2(AAA, BBB) { _LIT(KString, AAA); Log::WriteFormat(TRefByValue<const TDesC>(KString()), BBB); } |
|
63 #define LOGTEXT3(AAA, BBB, CCC) { _LIT(KString, AAA); Log::WriteFormat(TRefByValue<const TDesC>(KString()), BBB, CCC); } |
|
64 #define LOGTEXT4(AAA, BBB, CCC, DDD) { _LIT(KString, AAA); Log::WriteFormat(TRefByValue<const TDesC>(KString()), BBB, CCC, DDD); } |
|
65 |
|
66 #else//LOGGING_ENABLED |
|
67 |
|
68 #define LOGNEW |
|
69 #define LOGTEXT(AAA) |
|
70 #define LOGTEXT2(AAA, BBB) |
|
71 #define LOGTEXT3(AAA, BBB, CCC) |
|
72 #define LOGTEXT4(AAA, BBB, CCC, DDD) |
|
73 |
|
74 #endif//LOGGING_ENABLED |
|
75 |
|
76 //====================================================================================================== |
|
77 |
|
78 #define TEST_STRING(s) _S(s) |
|
79 |
|
80 //====================================================================================================== |
|
81 |
|
82 //TheTest object must be defined in the main test cpp file. |
|
83 GLREF_D RTest test; |
|
84 |
|
85 void LogTestBoolExpr(TBool aRes, const TText* aFile, TInt aLine); |
|
86 void LogCheck(TInt aValue, TInt aExpected, const TText* aFile, TInt aLine); |
|
87 void LogCheckU(TUint aValue, TUint aExpected, const TText* aFile, TInt aLine); |
|
88 |
|
89 #define TEST(arg) LogTestBoolExpr(arg, TEST_STRING(__FILE__), __LINE__) |
|
90 #define TEST2(aValue, aExpected) LogCheck(aValue, aExpected, TEST_STRING(__FILE__), __LINE__) |
|
91 #define TEST2U(aValue, aExpected) LogCheckU(aValue, aExpected, TEST_STRING(__FILE__), __LINE__) |
|
92 |
|
93 //====================================================================================================== |
|
94 |
|
95 void LogLeave(TInt aErr, const TText* aFile, TInt aLine); |
|
96 |
|
97 #define LEAVE(err) LogLeave(err, TEST_STRING(__FILE__), __LINE__) |
|
98 #define LEAVE_IF_ERROR(err) do {if(err < KErrNone) LogLeave(err, TEST_STRING(__FILE__), __LINE__);} while(0) |
|
99 |
|
100 //====================================================================================================== |
|
101 |
|
102 void LogPanic(const TDesC& aCategory, TInt aErr, const TText* aFile, TInt aLine); |
|
103 |
|
104 #define PANIC(cat, err) LogPanic(cat, err, TEST_STRING(__FILE__), __LINE__) |
|
105 |
|
106 //====================================================================================================== |
|
107 |
|
108 // Globals |
|
109 GLREF_D CTrapCleanup* theCleanup; |
|
110 GLREF_D CActiveScheduler *testScheduler; |
|
111 GLREF_D RFs theFs; |
|
112 GLREF_D TFileName theLogName; |
|
113 GLREF_D RFile theLog; |
|
114 GLREF_D RLogTestSession theLogServ; |
|
115 |
|
116 #define __FILE_FAILNEXT(X) theFs.SetErrorCondition(KErrGeneral, X) |
|
117 #define __FILE_RESET theFs.SetErrorCondition(KErrNone, 0) |
|
118 |
|
119 #if defined(_UNICODE) |
|
120 _LIT(KLogDatabaseName,"c:\\private\\101f401d\\Logdbu.dat"); |
|
121 #else |
|
122 _LIT(KLogDatabaseName,"c:\\private\\101f401d\\Logdb.dat"); |
|
123 #endif |
|
124 |
|
125 |
|
126 //********************************** |
|
127 // CTestActive |
|
128 //********************************** |
|
129 |
|
130 class CTestActive : public CActive |
|
131 { |
|
132 public: |
|
133 CTestActive(TInt aPriority = EPriorityIdle-100); |
|
134 ~CTestActive(); |
|
135 void StartL(); |
|
136 void StartL(TInt); |
|
137 protected: |
|
138 void DoCancel(); |
|
139 void RunL(); |
|
140 private: |
|
141 TBool iDelayCompletion; |
|
142 TRequestStatus iStoredStatus; |
|
143 TInt iDelayTime; |
|
144 }; |
|
145 |
|
146 void doTestsL(); |
|
147 |
|
148 |
|
149 //********************************** |
|
150 // CTestTimer |
|
151 //********************************** |
|
152 |
|
153 class CTestTimer : public CTimer |
|
154 { |
|
155 public: |
|
156 static CTestTimer* NewL(); |
|
157 private: |
|
158 CTestTimer(); |
|
159 void RunL(); |
|
160 }; |
|
161 |
|
162 //********************************** |
|
163 // TestUtils |
|
164 //********************************** |
|
165 |
|
166 class TestUtils |
|
167 { |
|
168 public: |
|
169 static void Initialize(const TDesC& aName); |
|
170 static void DeleteDatabaseL(TBool aCloseBeforeDelete = ETrue); |
|
171 static HBufC* CreateBufLC(TInt aLength); |
|
172 static HBufC8* CreateBuf8LC(TInt aLength); |
|
173 static TBool FiltersEqual(const CLogFilter& aFilter1, const CLogFilter& aFilter2); |
|
174 static TBool EventsEqual(const CLogEvent& aEvent1, const CLogEvent& aEvent2); |
|
175 static TBool TypesEqual(const CLogEventType& aType1, const CLogEventType& aType2); |
|
176 static TBool WaitForKeyL(TTimeIntervalMicroSeconds32 aDelay, TKeyCode& aKeyCode); |
|
177 static TBool FileExists(const TDesC& aFile); |
|
178 static void SetLogServHeapFailureL(RHeap::TAllocFail aType, TInt aRate); |
|
179 static TBool IsDatabaseOpenL(); |
|
180 static TInt DatabaseSizeL(); |
|
181 static TInt AddEventL(); |
|
182 static void AddViewTestEventsL(); |
|
183 static void AddEventTypeL(); |
|
184 static void CopyCorruptDbL(); |
|
185 static void CopyCorruptDamagedDbL(); |
|
186 static void CopyOldDbL(); |
|
187 static void TestInvalidSchemaL(); |
|
188 static TBool MatchingEnabledL(); |
|
189 |
|
190 private: |
|
191 // starts t_HiCapHelper.exe which has sufficient capability |
|
192 static TInt ExecuteRemoteL(const TDesC& aCommandLineArg); |
|
193 }; |
|
194 |
|
195 #define __LOGSERV_UHEAP_FAILNEXT(X) TestUtils::SetLogServHeapFailureL(RHeap::EFailNext, X) |
|
196 #define __LOGSERV_UHEAP_RESET TestUtils::SetLogServHeapFailureL(RHeap::ENone, 0) |
|
197 |
|
198 //********************************** |
|
199 // CLogViewChangeObserver |
|
200 //********************************** |
|
201 |
|
202 class CLogViewChangeObserver : public CActive, public MLogViewChangeObserver |
|
203 { |
|
204 public: |
|
205 enum TStopType |
|
206 { |
|
207 EStopOnChanges = 0, |
|
208 EStopOnRunL, |
|
209 EStopOnBoth, |
|
210 EStopOnCount, |
|
211 EDontStopScheduler |
|
212 }; |
|
213 public: |
|
214 static CLogViewChangeObserver* NewLC(); |
|
215 ~CLogViewChangeObserver(); |
|
216 |
|
217 protected: |
|
218 CLogViewChangeObserver(); |
|
219 |
|
220 public: |
|
221 inline void StartCollectingChanges() |
|
222 { |
|
223 Reset(); |
|
224 iType = EDontStopScheduler; |
|
225 } |
|
226 CLogChangeDefinition* WaitForChangesLC(TStopType aType = EStopOnChanges, TInt aCount = 0); |
|
227 CLogChangeDefinition* WaitForChangesLC(TCallBack aCallBack, TStopType aType, TInt aCount = 0); |
|
228 inline TBool HaveChanges() const |
|
229 { |
|
230 return iChanges != NULL; |
|
231 } |
|
232 inline const CLogChangeDefinition& Changes() const |
|
233 { |
|
234 __ASSERT_ALWAYS(iChanges, User::Invariant()); |
|
235 return *iChanges; |
|
236 } |
|
237 inline void SetActive() |
|
238 { |
|
239 CActive::SetActive(); |
|
240 iStatus = KRequestPending; |
|
241 } |
|
242 inline void ResetChanges() |
|
243 { |
|
244 __ASSERT_ALWAYS(iChanges, User::Invariant()); |
|
245 iChanges->Reset(); |
|
246 } |
|
247 |
|
248 public: |
|
249 void HandleLogViewChangeEventAddedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount); |
|
250 void HandleLogViewChangeEventChangedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount); |
|
251 void HandleLogViewChangeEventDeletedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount); |
|
252 |
|
253 private: |
|
254 void RunL(); |
|
255 void DoCancel(); |
|
256 |
|
257 private: |
|
258 void Reset(); |
|
259 |
|
260 protected: |
|
261 void CheckForSchedulerStop(); |
|
262 void AddChangeL(TLogDatabaseChangeType aType, TLogId aId, TInt aViewIndex); |
|
263 |
|
264 private: |
|
265 TInt iExpectedChangeCount; |
|
266 TBool iHaveFinishedOperation; |
|
267 TBool iHaveObtainedChanges; |
|
268 TBool iSchedulerStarted; |
|
269 TStopType iType; |
|
270 CLogChangeDefinition* iChanges; |
|
271 TBool iHaveCallBack; |
|
272 TCallBack iCallBack; |
|
273 }; |
|
274 |
|
275 //********************************** |
|
276 // CLogViewChangeObserverErrorTest |
|
277 //********************************** |
|
278 |
|
279 class CLogViewChangeObserverErrorTest : public CLogViewChangeObserver |
|
280 { |
|
281 public: |
|
282 static CLogViewChangeObserverErrorTest* NewLC(); |
|
283 |
|
284 private: |
|
285 CLogViewChangeObserverErrorTest(); |
|
286 |
|
287 public: |
|
288 void HandleLogViewChangeEventAddedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount); |
|
289 }; |
|
290 |
|
291 |
|
292 //********************************** |
|
293 // CLogSchedulerTimer |
|
294 //********************************** |
|
295 |
|
296 class CLogSchedulerTimer : public CTimer |
|
297 { |
|
298 public: |
|
299 static CLogSchedulerTimer* NewLC(); |
|
300 ~CLogSchedulerTimer(); |
|
301 |
|
302 private: |
|
303 CLogSchedulerTimer(); |
|
304 void ConstructL(); |
|
305 |
|
306 public: |
|
307 void Wait(TTimeIntervalMicroSeconds32 aTime); |
|
308 |
|
309 private: |
|
310 void RunL(); |
|
311 }; |
|
312 |
|
313 //********************************** |
|
314 // CLogChangeNotifier |
|
315 //********************************** |
|
316 |
|
317 class CLogChangeNotifier : public CActive |
|
318 { |
|
319 public: |
|
320 static CLogChangeNotifier* NewL(); |
|
321 ~CLogChangeNotifier(); |
|
322 // |
|
323 private: |
|
324 CLogChangeNotifier(); |
|
325 void ConstructL(); |
|
326 // |
|
327 void RunL(); |
|
328 void DoCancel(); |
|
329 // |
|
330 private: |
|
331 CLogClient* iClient; |
|
332 TTime iStart; |
|
333 }; |
|
334 |
|
335 //********************************** |
|
336 // Global |
|
337 //********************************** |
|
338 |
|
339 void SetupSchedulerL(); |
|
340 void CloseScheduler(); |
|
341 void doMainL(); |
|
342 TInt E32Main(); |
|
343 void DeleteDataFile(const TDesC& aFullName); |
|
344 void LogCheck(TInt aValue, TInt aExpected, TInt aLine); |
|
345 void LogCheckU(TUint aValue, TUint aExpected, TInt aLine); |
|
346 |
|
347 #endif//__TEST_H__ |
|