|
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 #include <e32std.h> |
|
17 #include <e32test.h> |
|
18 #include <push/pushmessage.h> |
|
19 #include <push/cpushhandlerbase.h> |
|
20 #include <push/pushlog.h> |
|
21 #include "testlog.h" |
|
22 #include "t_failure.h" |
|
23 |
|
24 _LIT(KTestTitle,"T_Failure"); |
|
25 _LIT8(KHeader,"This is a dummy header"); |
|
26 _LIT8(KBody,"This is a dummy message body"); |
|
27 _LIT(KAppIdBufFormat, "0x%08x"); |
|
28 |
|
29 // Setting up parameters for CPushHandlerBase::NewL() |
|
30 const TInt KAppId = 2; |
|
31 const TInt KAppIdLength = 10; |
|
32 |
|
33 // Global variables |
|
34 RTest gTest(_L("t_Failure Test Harness")); |
|
35 |
|
36 CPushMessageTester* CPushMessageTester::NewL() |
|
37 { |
|
38 CPushMessageTester* self = new (ELeave) CPushMessageTester(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CPushMessageTester::CPushMessageTester() |
|
43 { |
|
44 } |
|
45 |
|
46 CPushMessageTester::~CPushMessageTester() |
|
47 { |
|
48 delete iHeader; |
|
49 delete iBody; |
|
50 delete iMessage; |
|
51 } |
|
52 |
|
53 void CPushMessageTester::PluginFailureTestL() |
|
54 { |
|
55 TBuf<KAppIdLength> AppIdBuf; |
|
56 AppIdBuf.Format(KAppIdBufFormat, KAppId); |
|
57 CPushHandlerBase* pushHandler = NULL; |
|
58 pushHandler = CPushHandlerBase::NewL(AppIdBuf, KUidPushHandlerBase); |
|
59 delete pushHandler; |
|
60 } |
|
61 |
|
62 void CPushMessageTester::FailureTestL() |
|
63 { |
|
64 // constructing CPushMessage with the arguments as member variables |
|
65 iHeader = KHeader().AllocL(); |
|
66 iBody = KBody().AllocL(); |
|
67 |
|
68 iMessage = CPushMessage::NewL(iHeader, iBody); |
|
69 iHeader = NULL; |
|
70 iBody = NULL; |
|
71 } |
|
72 |
|
73 CFailureTester* CFailureTester::NewL(CWapPushLog& aLog) |
|
74 { |
|
75 CFailureTester* self = new (ELeave) CFailureTester(aLog); |
|
76 return self; |
|
77 } |
|
78 |
|
79 CFailureTester::CFailureTester(CWapPushLog& aLog) |
|
80 :iLog(aLog) |
|
81 { |
|
82 } |
|
83 |
|
84 CFailureTester::~CFailureTester() |
|
85 { |
|
86 delete iScheduler; |
|
87 } |
|
88 |
|
89 void CFailureTester::LogFormatInt(const TDesC& aFormat, TInt aInt) |
|
90 { |
|
91 iFormatBuffer.Format(aFormat, aInt); |
|
92 iLog.WPLPrintf(iFormatBuffer); |
|
93 } |
|
94 |
|
95 void CFailureTester::LogFormatInt(const TDesC& aFormat, TInt aInt1, TInt aInt2) |
|
96 { |
|
97 iFormatBuffer.Format(aFormat, aInt1, aInt2); |
|
98 iLog.WPLPrintf(iFormatBuffer); |
|
99 } |
|
100 |
|
101 void CFailureTester::LogFormatStr(const TDesC& aFormat, const TDesC& aDes) |
|
102 { |
|
103 iFormatBuffer.Format(aFormat, &aDes); |
|
104 iLog.WPLPrintf(iFormatBuffer); |
|
105 } |
|
106 |
|
107 void CFailureTester::LogStr(const TDesC& aDes) |
|
108 { |
|
109 iLog.WPLPrintf(aDes); |
|
110 } |
|
111 |
|
112 void CFailureTester::HeapFailureTest() |
|
113 { |
|
114 __LOG_ALWAYS("Test Results"); |
|
115 __LOG_ALWAYS(" "); |
|
116 |
|
117 __LOG_ALWAYS("***** HEAP FAILURE TEST FOR PUSH MESSAGE *****"); |
|
118 |
|
119 TInt error; |
|
120 TBool finished = EFalse; |
|
121 TInt failCount = 0; |
|
122 CPushMessageTester* push = NULL; |
|
123 while(!finished) |
|
124 { |
|
125 __UHEAP_FAILNEXT(failCount++); |
|
126 __UHEAP_MARK; |
|
127 TRAP(error, push = DoPushMessageTestL()); |
|
128 if (error == KErrNone) |
|
129 { |
|
130 delete push; |
|
131 __UHEAP_RESET; |
|
132 LogFormatInt(_L("Made %d attempts at calling DoPushMessageTestL()"), failCount); |
|
133 finished = ETrue; |
|
134 } |
|
135 else // Handle error |
|
136 { |
|
137 // Check if error is out of memory |
|
138 gTest(error == KErrNoMemory); |
|
139 __UHEAP_RESET; |
|
140 } |
|
141 __UHEAP_MARKEND; |
|
142 } |
|
143 |
|
144 __LOG_ALWAYS("RTEST: SUCCESS ***** PUSH MESSAGE TEST SUCCESSFUL ******"); |
|
145 __LOG_ALWAYS(" "); |
|
146 } |
|
147 |
|
148 void CFailureTester::PluginHeapFailureTest() |
|
149 { |
|
150 __LOG_ALWAYS("***** HEAP FAILURE TEST FOR PLUGIN *****"); |
|
151 |
|
152 TInt error; |
|
153 TBool finished = EFalse; |
|
154 TInt failCount = 0; |
|
155 CPushMessageTester* push = NULL; |
|
156 while(!finished) |
|
157 { |
|
158 __UHEAP_FAILNEXT(failCount++); |
|
159 __UHEAP_MARK; |
|
160 TRAP(error, push = CreatePushHandlerBaseL()); |
|
161 if (error == KErrNone) |
|
162 { |
|
163 delete push; |
|
164 __UHEAP_RESET; |
|
165 LogFormatInt(_L("Made %d attempts at calling CreatePushHandlerBaseL()"), failCount); |
|
166 finished = ETrue; |
|
167 } |
|
168 else // Handle error |
|
169 { |
|
170 // Check if error is out of memory |
|
171 gTest(error == KErrNoMemory); |
|
172 __UHEAP_RESET; |
|
173 } |
|
174 REComSession::FinalClose(); |
|
175 __UHEAP_MARKEND; |
|
176 } |
|
177 |
|
178 __LOG_ALWAYS("RTEST: SUCCESS ***** PLUGIN TEST SUCCESSFUL ******"); |
|
179 __LOG_ALWAYS(" "); |
|
180 __LOG_ALWAYS("Tests Completed"); |
|
181 } |
|
182 |
|
183 |
|
184 CPushMessageTester* CFailureTester::DoPushMessageTestL() |
|
185 { |
|
186 // First case |
|
187 CPushMessageTester* tester = CPushMessageTester::NewL(); |
|
188 CleanupStack::PushL(tester); |
|
189 tester->FailureTestL(); |
|
190 |
|
191 // Second case |
|
192 CPushMessage* message = DoPushMessageTest2L(); |
|
193 delete message; |
|
194 |
|
195 CleanupStack::Pop(tester); |
|
196 return tester; |
|
197 } |
|
198 |
|
199 |
|
200 CPushMessageTester* CFailureTester::CreatePushHandlerBaseL() |
|
201 { |
|
202 CPushMessageTester* tester = CPushMessageTester::NewL(); |
|
203 CleanupStack::PushL(tester); |
|
204 tester->PluginFailureTestL(); |
|
205 CleanupStack::Pop(tester); |
|
206 return tester; |
|
207 } |
|
208 |
|
209 |
|
210 CPushMessage* CFailureTester::DoPushMessageTest2L() |
|
211 { |
|
212 // constructing CPushMessage with the arguments put on the cleanupstack |
|
213 |
|
214 HBufC8* header = KHeader().AllocLC(); |
|
215 HBufC8* body = KBody().AllocLC(); |
|
216 |
|
217 CPushMessage* push = CPushMessage::NewL(header, body); |
|
218 |
|
219 CleanupStack::Pop(2); //Header, Body |
|
220 return push; |
|
221 } |
|
222 |
|
223 void CFailureTester::InitSchedulerL() |
|
224 { |
|
225 iScheduler = new (ELeave) CActiveScheduler(); |
|
226 CActiveScheduler::Install( iScheduler ); |
|
227 } |
|
228 |
|
229 |
|
230 /** |
|
231 * setup test environment, create CFailureTester object and run tests. |
|
232 * |
|
233 * This is an OOM test. |
|
234 * It tests 3 cases: |
|
235 * (i) constructing CPushMessage with the arguments as member variables. |
|
236 * (ii) constructing CPushMessage with the arguments put on the cleanupstack. |
|
237 * (iii) constructing CPushHandlerBase |
|
238 * Running Instructions: |
|
239 * 1. Build this test harness: cd \wappush\pushutils\group |
|
240 * bldmake bldfiles |
|
241 * abld test build wins udeb t_failure |
|
242 * 2. Create log directories in c:\logs\push |
|
243 * 3. Run TFailure.exe: cd \epoc32\release\wins\udeb |
|
244 * tfailure -dtextshell -- |
|
245 */ |
|
246 LOCAL_C void doMainL() |
|
247 { |
|
248 gTest.Start(KTestTitle); |
|
249 |
|
250 gTest.Printf(_L("@SYMTestCaseID IWS-WAPBROWSER-PUSHUTILS-T_FAILURE-0001 ")); |
|
251 |
|
252 CWapPushLog* log = CWapPushLog::NewL(*gTest.Console()); |
|
253 log->SetLogFileName(_L("TFailure.txt")); |
|
254 CleanupStack::PushL(log); |
|
255 |
|
256 CFailureTester* myTester = CFailureTester::NewL(*log); |
|
257 CleanupStack::PushL(myTester); |
|
258 myTester->HeapFailureTest(); |
|
259 myTester->InitSchedulerL(); |
|
260 myTester->PluginHeapFailureTest(); |
|
261 |
|
262 |
|
263 CleanupStack::PopAndDestroy(2, log); //log, myTester |
|
264 gTest.End(); |
|
265 gTest.Close(); |
|
266 } |
|
267 |
|
268 |
|
269 /** entry point for test executable */ |
|
270 GLDEF_C TInt E32Main() |
|
271 { |
|
272 __UHEAP_MARK; |
|
273 |
|
274 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
275 TRAPD(ret,doMainL()); |
|
276 gTest(ret==KErrNone); |
|
277 delete theCleanup; |
|
278 |
|
279 __UHEAP_MARKEND; |
|
280 return(KErrNone); |
|
281 } |