|
1 // Copyright (c) 2000-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 MSV_TEST_UTILS_BASE_H_ |
|
17 #define MSV_TEST_UTILS_BASE_H_ |
|
18 |
|
19 #include <f32file.h> |
|
20 #include <e32test.h> |
|
21 #include <msventry.h> |
|
22 #include <msvapi.h> |
|
23 #include <flogger.h> |
|
24 #include <cntdef.h> |
|
25 #include <simtsy.h> |
|
26 |
|
27 // Forward Declarations |
|
28 |
|
29 class RResourceFile; |
|
30 class CLogFilter; |
|
31 class CLogEvent; |
|
32 class CMsvSession; |
|
33 class CMsvEntry; |
|
34 class CContactItem; |
|
35 |
|
36 // Constants |
|
37 |
|
38 //Test Harness Logging |
|
39 |
|
40 #define KLogsDir _L("c:\\logs\\") |
|
41 #define KMsgLogsDirName _L("MsgTest") |
|
42 |
|
43 #define KTestHeader _L("Test Results") |
|
44 #define KTestStarting _L("Test %d Starting") |
|
45 #define KTestStartingWithDesc _L("Test %d Starting (%S)") |
|
46 #define KTestPassed _L("Test %d OK") |
|
47 #define KTestFailed _L("Test %d FAILED (error = %d)") |
|
48 #define KTestHarnessCompleted _L("Tests Completed") |
|
49 #define KTestHarnessFailed _L("Tests FAILED (error = %d)") |
|
50 #define KTestCommentPrepend _L(" ") |
|
51 |
|
52 #define KTestShowMenu _L("/manual") |
|
53 |
|
54 #define KPeriod 10000 // period of timer |
|
55 |
|
56 #define KUidSASimTsyTestNumberValue (KUidSASimTsyValue+1) // < UID value for test number. |
|
57 const TUid KUidSASimTsyTestNumber = {KUidSASimTsyTestNumberValue}; // < UID for test number. |
|
58 |
|
59 // |
|
60 // |
|
61 // TMsvDummyObserver |
|
62 // |
|
63 // |
|
64 |
|
65 class TMsvDummyObserver : public MMsvSessionObserver |
|
66 { |
|
67 |
|
68 public: |
|
69 void HandleSessionEventL(TMsvSessionEvent, TAny*, TAny*, TAny*) |
|
70 {} |
|
71 }; |
|
72 |
|
73 |
|
74 // |
|
75 // |
|
76 // CTestActive |
|
77 // |
|
78 // |
|
79 |
|
80 class CTestActive : public CActive |
|
81 { |
|
82 public: |
|
83 IMPORT_C CTestActive(); |
|
84 IMPORT_C ~CTestActive(); |
|
85 IMPORT_C void StartL(); |
|
86 protected: |
|
87 IMPORT_C void DoCancel(); |
|
88 IMPORT_C void RunL(); |
|
89 }; |
|
90 |
|
91 |
|
92 // |
|
93 // |
|
94 // CTestTimer |
|
95 // |
|
96 // |
|
97 |
|
98 class CTestTimer : public CTimer |
|
99 { |
|
100 public: |
|
101 IMPORT_C static CTestTimer* NewL(); |
|
102 IMPORT_C void AfterReq(TTimeIntervalMicroSeconds32 aSec, TRequestStatus& aStatus); |
|
103 protected: |
|
104 IMPORT_C CTestTimer(); |
|
105 IMPORT_C void RunL(); |
|
106 |
|
107 private: |
|
108 TRequestStatus* iReport; |
|
109 }; |
|
110 |
|
111 // |
|
112 // |
|
113 // CTestUtils |
|
114 // |
|
115 // |
|
116 |
|
117 class CTestUtils : public CBase |
|
118 { |
|
119 public: |
|
120 //File Logging |
|
121 |
|
122 IMPORT_C void TestStart(TInt aTest); |
|
123 IMPORT_C void TestStart(TInt aTest, const TDesC& aTestDescription); |
|
124 IMPORT_C void TestFinish(TInt aTest, TInt aError = KErrNone); |
|
125 IMPORT_C void TestHarnessCompleted(); |
|
126 IMPORT_C void TestHarnessFailed(TInt aError); |
|
127 IMPORT_C void WriteComment(const TDesC& aComment); |
|
128 IMPORT_C TInt SeekLogFile(TSeek aMode,TInt& aPos); |
|
129 |
|
130 //Test Utils |
|
131 |
|
132 IMPORT_C virtual void CreateAllTestDirectories(); |
|
133 IMPORT_C void DisplayLogL(const CLogFilter& aFilter, TBool aForward = ETrue); |
|
134 IMPORT_C void ClearLogL(const CLogFilter& aFilter); |
|
135 |
|
136 // File location |
|
137 |
|
138 IMPORT_C TInt ResolveFile(const TDesC& aComponent, const TDesC& aFileName, TParse& aParseOut); |
|
139 IMPORT_C TInt ResolveLogFile(const TDesC& aFileName, TParse& aParseOut); |
|
140 |
|
141 //File writing |
|
142 // inline void Write(const TDesC& aTxt, RFile& aFile); |
|
143 IMPORT_C TInt DisplayFile(const TDesC& aFileName); //not tested |
|
144 void AppendEol(TDes& aTxt, TBool aToFile = ETrue); |
|
145 |
|
146 inline RFs& FileSession(); |
|
147 |
|
148 //Display a menu. |
|
149 //NOTE: These functions should not be used by most test harnesses |
|
150 // as test harnesses should run through automatically. |
|
151 IMPORT_C TInt DisplayMenu(const TDesC& aTitle, TInt aMaxAttempts = 3, TBool aAllowExit = ETrue, TBool aClearScreenBefore = ETrue, TBool aClearScreenAfter = ETrue); |
|
152 IMPORT_C void ResetMenu(); |
|
153 IMPORT_C void AppendToMenuL(const TDesC& aOption); |
|
154 IMPORT_C TInt MenuCount() const; |
|
155 IMPORT_C void ClearScreen(TBool aClearScreen = ETrue); |
|
156 |
|
157 IMPORT_C void Printf(TRefByValue<const TDesC> aFmt,...); //prints to RTest and LogFile, depending on iLogToConsole and iLogToFile |
|
158 |
|
159 IMPORT_C TBool SetLogToConsole(TBool aLogToConsole = ETrue); |
|
160 IMPORT_C TBool SetLogToFile(TBool aLogToFile = ETrue); |
|
161 |
|
162 inline RTest& Test() const; |
|
163 inline void operator()(TInt aResult,TInt aLineNum); |
|
164 inline void operator()(TInt aResult); |
|
165 |
|
166 IMPORT_C TBool RunAuto() const; |
|
167 IMPORT_C void SetRunAuto(TBool aRunAuto = ETrue); |
|
168 |
|
169 //Add item to the contacts DB |
|
170 IMPORT_C TContactItemId CreateContactL(const TDesC& aGivenName, const TDesC& aFamilyName, const TDesC& aPhoneNumber, const TDesC& aEmailAddress, TBool aReplaceContactsDb = EFalse); |
|
171 IMPORT_C void SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName, TBool aAddField); |
|
172 IMPORT_C void DeleteContactsFileL(); |
|
173 |
|
174 IMPORT_C HBufC8* ReadFileLC(const TDesC& aFile); |
|
175 |
|
176 IMPORT_C void PrintHex(const TDesC& aDes); |
|
177 IMPORT_C void PrintHex(const TDesC8& aDes); |
|
178 |
|
179 IMPORT_C void OpenResourceFileL(const TDesC& aResFileName, RResourceFile& aResFile); |
|
180 IMPORT_C void ReadResourceStringL(RResourceFile& aResFile, TInt aId, TDes& rString); |
|
181 IMPORT_C void ReadResourceStringL(const TDesC& aResFileName, TInt aId, TDes& rString); |
|
182 |
|
183 IMPORT_C static void SetSimTsyTestNumberL(TInt aTestNumber); |
|
184 IMPORT_C static void CopyToSimTsyConfigFileL(RFs& aFs, const TDesC& aFilename); |
|
185 |
|
186 public: |
|
187 |
|
188 protected: |
|
189 IMPORT_C virtual void ConstructL(); |
|
190 IMPORT_C CTestUtils(RTest& aRTest); |
|
191 IMPORT_C ~CTestUtils(); |
|
192 |
|
193 IMPORT_C void DoBuf(TDes8& buf, const TDesC& label, const TDesC& data); |
|
194 IMPORT_C void DoBuf(TDes8& buf, const TDesC& label, const TDesC8& data); |
|
195 |
|
196 IMPORT_C void AppendText(const TDesC& aToken, TDes& aTxt, TInt aMaxTokenLength); |
|
197 IMPORT_C void WriteToFileL(RFile& aFile, TDesC8& aInputLine); |
|
198 IMPORT_C void WriteToFileL(RFile& aFile, const TDesC& aInputLine); |
|
199 IMPORT_C void RemoveRichtextFormating(TDes& aSourceLine); |
|
200 |
|
201 void ConstructKeepLogFileL(); |
|
202 |
|
203 virtual void DisplayLogEventData(const CLogEvent& /*aEvent*/) {}; |
|
204 void GetEventType(TUid aEventType, TDes& rOutput); |
|
205 virtual void Panic(TInt aPanic) = 0; |
|
206 |
|
207 void AppendTestName(TDes &aFileName); |
|
208 void AppendVariantName(TDes& aFileName); |
|
209 |
|
210 TInt OpenMainLogL(); |
|
211 TInt AppendMainLogL(); |
|
212 void CloseMainLog(); |
|
213 void WriteToLog(TRefByValue<const TDesC> aFmt,...); |
|
214 |
|
215 |
|
216 private: |
|
217 TBool CheckLogStatus(const TBool aEventViewRet, const TRequestStatus& aStatus); |
|
218 TInt DoDisplayMenu(const TDesC& aTitle, TInt& aMaxAttempts, TBool aAllowExit, TBool aClearScreenBefore = ETrue, TBool aClearScreenAfter = ETrue); |
|
219 |
|
220 protected: |
|
221 |
|
222 CArrayPtrFlat<HBufC>* iMenu; |
|
223 |
|
224 RFs iFs; |
|
225 RFile iFile; |
|
226 RTest& iRTest; |
|
227 |
|
228 TFileName iTestLogFile; |
|
229 TBool iLogToConsole; |
|
230 TBool iLogToFile; |
|
231 |
|
232 TBool iRunAuto; |
|
233 HBufC* iLogBuf; |
|
234 HBufC8* iLogBuf8; |
|
235 }; |
|
236 |
|
237 class TTestOverflow : public TDes16Overflow |
|
238 { |
|
239 public: |
|
240 TTestOverflow(CTestUtils& aTest) |
|
241 : iTest(aTest) {}; |
|
242 |
|
243 // TDes16Overflow pure virtual |
|
244 virtual void Overflow(TDes16& /*aDes*/) {iTest.Printf(_L("ERROR: Printf Overflow\n")); iTest.Test()(EFalse);}; |
|
245 |
|
246 private: |
|
247 CTestUtils& iTest; |
|
248 }; |
|
249 |
|
250 |
|
251 // |
|
252 // CTestUtilsWatcherStarter |
|
253 // |
|
254 |
|
255 const TInt KTestUtilsWatcherStarterMin = 5000000; |
|
256 class CWatcher; |
|
257 |
|
258 class CTestUtilsWatcherStarter : public CActive |
|
259 { |
|
260 public: |
|
261 IMPORT_C static CTestUtilsWatcherStarter* NewL(TRequestStatus& aStatus, TTimeIntervalMicroSeconds32 aWaitToStart = KTestUtilsWatcherStarterMin, TInt aPriority = EPriorityStandard); |
|
262 IMPORT_C static CTestUtilsWatcherStarter* NewL(TInt aPriority = EPriorityStandard); |
|
263 IMPORT_C ~CTestUtilsWatcherStarter(); |
|
264 |
|
265 private: |
|
266 CTestUtilsWatcherStarter(TInt aPriority); |
|
267 void RunL(); |
|
268 void DoCancel(); |
|
269 void ConstructL(); |
|
270 void ConstructL(TRequestStatus& aStatus, TTimeIntervalMicroSeconds32 aWaitToStart); |
|
271 |
|
272 private: |
|
273 RTimer iTimer; |
|
274 |
|
275 RProcess iWatcher; |
|
276 TBool iConstructed; |
|
277 TRequestStatus* iObserver; |
|
278 }; |
|
279 |
|
280 |
|
281 #include <msvtestutilsbase.inl> |
|
282 |
|
283 #endif |