271
|
1 |
// Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "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 |
// e32test\notifier\t_textnotifier.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test the RNotifier class.
|
|
17 |
// API Information:
|
|
18 |
// RNotifier
|
|
19 |
// Details:
|
|
20 |
// - For IPC Ver. 1 and IPC Ver 2, connect to and start anotifier server.
|
|
21 |
// Perform a variety of tests including CancelNotifier, StartNotifier,
|
|
22 |
// UpdateNotifier, UpdateNotifierAndGetResponse, StartNotifierAndGetResponse.
|
|
23 |
// Verify results are as expected. Check for memory leaks and cleanup.
|
|
24 |
// - For IPC Ver. 1 and IPC Ver 2, using MNotifierManager, connect to and
|
|
25 |
// start anotifier server. Perform a variety of tests including CancelNotifier,
|
|
26 |
// StartNotifier, UpdateNotifier, UpdateNotifierAndGetResponse,
|
271
|
27 |
// StartNotifierAndGetResponse, Notify and NotifyCancnel.
|
|
28 |
// Verify results are as expected. Check for memory leaks and cleanup.
|
|
29 |
// - Tests also removed but exported methods that they return expected values
|
0
|
30 |
// - Do interactive tests as requested.
|
|
31 |
// Platforms/Drives/Compatibility:
|
|
32 |
// Hardware (Automatic).
|
|
33 |
// Assumptions/Requirement/Pre-requisites:
|
|
34 |
// Failures and causes:
|
|
35 |
// Base Port information:
|
|
36 |
//
|
|
37 |
//
|
|
38 |
|
|
39 |
#include <e32std.h>
|
|
40 |
#include <e32std_private.h>
|
|
41 |
#include <e32test.h>
|
|
42 |
#include "textnotifier.h"
|
|
43 |
#include <e32debug.h>
|
271
|
44 |
#include <e32event.h>
|
|
45 |
#include <e32svr.h>
|
0
|
46 |
|
|
47 |
LOCAL_D RTest test(_L("T_TEXTNOTIFIER"));
|
|
48 |
|
271
|
49 |
const TUint KTimeOut=3000000; // 3 seconds
|
|
50 |
|
0
|
51 |
void DoMemoryLeakTests(TUid aUid,TBool aCheckMNotifierManager)
|
|
52 |
{
|
|
53 |
TInt r;
|
|
54 |
TRequestStatus stat;
|
|
55 |
|
|
56 |
test.Start(_L("Connect to notifier server"));
|
|
57 |
RNotifier n;
|
|
58 |
r = n.Connect();
|
|
59 |
test(r==KErrNone);
|
|
60 |
|
|
61 |
test.Next(_L("Get Notifier Server Heap Info"));
|
|
62 |
static TBuf8<128> heapInfo1;
|
|
63 |
heapInfo1.Zero();
|
|
64 |
n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo1);
|
|
65 |
User::WaitForRequest(stat);
|
|
66 |
n.CancelNotifier(aUid);
|
|
67 |
TInt heapCellCount=stat.Int();
|
|
68 |
test(heapCellCount>0);
|
|
69 |
|
|
70 |
test.Next(_L("Repeated StartNotifierAndGetResponse"));
|
|
71 |
for(TInt i=0; i<1000; i++)
|
|
72 |
{
|
|
73 |
TBuf8<128> response;
|
|
74 |
response.SetMax();
|
|
75 |
response.FillZ();
|
|
76 |
response.Zero();
|
|
77 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
|
|
78 |
User::WaitForRequest(stat);
|
|
79 |
n.CancelNotifier(aUid);
|
|
80 |
test(stat==KErrNone);
|
|
81 |
test(response==KResponseData);
|
|
82 |
}
|
|
83 |
|
|
84 |
test.Next(_L("Check Notifier Server Heap Info"));
|
|
85 |
static TBuf8<128> heapInfo2;
|
|
86 |
heapInfo2.Zero();
|
|
87 |
n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo2);
|
|
88 |
User::WaitForRequest(stat);
|
|
89 |
n.CancelNotifier(aUid);
|
|
90 |
test(stat==heapCellCount);
|
189
|
91 |
|
|
92 |
TInt size1, size2;
|
|
93 |
TLex8 lex(heapInfo1);
|
|
94 |
r = lex.Val(size1);
|
|
95 |
test(r==KErrNone);
|
|
96 |
lex.Assign(heapInfo2);
|
|
97 |
r = lex.Val(size2);
|
|
98 |
test(r==KErrNone);
|
|
99 |
//allocated size after should not be greater than before BUT may be less with new allocator
|
|
100 |
test(size2 <= size1);
|
0
|
101 |
|
|
102 |
test.Next(_L("Close connection to notifier server"));
|
|
103 |
n.Close();
|
|
104 |
|
|
105 |
test.End();
|
|
106 |
}
|
|
107 |
|
|
108 |
void DoCleanumpTests(TUid aUid,TBool aCheckMNotifierManager)
|
|
109 |
{
|
|
110 |
TInt r;
|
|
111 |
|
|
112 |
test.Start(_L("Connect to notifier server"));
|
|
113 |
RNotifier n;
|
|
114 |
r = n.Connect();
|
|
115 |
test(r==KErrNone);
|
|
116 |
|
|
117 |
test.Next(_L("StartNotifierAndGetResponse"));
|
|
118 |
TBuf8<128> response;
|
|
119 |
response.SetMax();
|
|
120 |
response.FillZ();
|
|
121 |
response.Zero();
|
|
122 |
TRequestStatus stat;
|
|
123 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
|
|
124 |
User::WaitForRequest(stat);
|
|
125 |
test(stat==KErrNone);
|
|
126 |
test(response==KResponseData);
|
|
127 |
|
|
128 |
test.Next(_L("Close connection to notifier server"));
|
|
129 |
n.Close();
|
|
130 |
|
|
131 |
test.Next(_L("Connect to notifier server"));
|
|
132 |
r = n.Connect();
|
|
133 |
test(r==KErrNone);
|
|
134 |
|
|
135 |
test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
|
|
136 |
response.SetMax();
|
|
137 |
response.FillZ();
|
|
138 |
response.Zero();
|
|
139 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
|
|
140 |
User::WaitForRequest(stat);
|
|
141 |
test(stat==KTestNotifierWasPreviouselyCanceled);
|
|
142 |
test(response==KResponseData);
|
|
143 |
|
|
144 |
test.Next(_L("Close connection to notifier server"));
|
|
145 |
n.Close();
|
|
146 |
|
|
147 |
test.End();
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
void DoTests(TUid aUid,TBool aCheckMNotifierManager)
|
|
153 |
{
|
|
154 |
TInt r;
|
|
155 |
|
|
156 |
test.Start(_L("Connect to notifier server"));
|
|
157 |
RNotifier n;
|
|
158 |
r = n.Connect();
|
|
159 |
test(r==KErrNone);
|
|
160 |
|
|
161 |
test.Next(_L("StartNotifier (without response)"));
|
|
162 |
r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData);
|
|
163 |
RDebug::Printf("r=%d", r);
|
|
164 |
test(r==KErrNone);
|
|
165 |
|
|
166 |
test.Next(_L("CancelNotifier"));
|
|
167 |
r = n.CancelNotifier(aUid);
|
|
168 |
test(r==KErrNone);
|
|
169 |
|
|
170 |
test.Next(_L("StartNotifier"));
|
|
171 |
TBuf8<128> response;
|
|
172 |
response.SetMax();
|
|
173 |
response.FillZ();
|
|
174 |
response.Zero();
|
|
175 |
r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
|
|
176 |
test(r==KErrNone);
|
|
177 |
test(response==KResponseData);
|
|
178 |
|
|
179 |
test.Next(_L("UpdateNotifier"));
|
|
180 |
response.SetMax();
|
|
181 |
response.FillZ();
|
|
182 |
response.Zero(); // EKA1 text notifier dies if current length < length of response
|
|
183 |
r = n.UpdateNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
|
|
184 |
test(r==KErrNone);
|
|
185 |
test(response==KResponseData);
|
|
186 |
|
|
187 |
test.Next(_L("UpdateNotifierAndGetResponse"));
|
|
188 |
response.SetMax();
|
|
189 |
response.FillZ();
|
|
190 |
response.Zero(); // EKA1 text notifier dies if current length < length of response
|
|
191 |
TRequestStatus updateStat;
|
|
192 |
n.UpdateNotifierAndGetResponse(updateStat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
|
|
193 |
User::WaitForRequest(updateStat);
|
|
194 |
test(updateStat==KErrNone);
|
|
195 |
test(response==KResponseData);
|
271
|
196 |
|
0
|
197 |
test.Next(_L("CancelNotifier"));
|
|
198 |
r = n.CancelNotifier(aUid);
|
|
199 |
test(r==KErrNone);
|
|
200 |
|
|
201 |
test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
|
|
202 |
response.SetMax();
|
|
203 |
response.FillZ();
|
|
204 |
response.Zero();
|
|
205 |
TRequestStatus stat;
|
|
206 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
|
|
207 |
User::WaitForRequest(stat);
|
|
208 |
test(stat==KTestNotifierWasPreviouselyCanceled);
|
|
209 |
test(response==KResponseData);
|
|
210 |
|
|
211 |
test.Next(_L("CancelNotifier"));
|
|
212 |
r = n.CancelNotifier(aUid);
|
|
213 |
test(r==KErrNone);
|
|
214 |
|
|
215 |
test.Next(_L("Close connection to notifier server"));
|
|
216 |
n.Close();
|
|
217 |
|
|
218 |
test.Next(_L("Memory leak tests"));
|
|
219 |
DoMemoryLeakTests(aUid,aCheckMNotifierManager);
|
|
220 |
|
|
221 |
test.Next(_L("Session cleanup test"));
|
|
222 |
DoCleanumpTests(aUid,aCheckMNotifierManager);
|
|
223 |
|
|
224 |
test.End();
|
|
225 |
}
|
|
226 |
|
271
|
227 |
|
|
228 |
void TestNotify()
|
|
229 |
//
|
|
230 |
// Test Notify by launching a simple notifier. Gets closed
|
|
231 |
// using timer and simulated keypress.
|
|
232 |
//
|
|
233 |
{
|
|
234 |
TInt r;
|
|
235 |
test.Start(_L("Connect to notifier server"));
|
|
236 |
RNotifier n;
|
|
237 |
r = n.Connect();
|
|
238 |
test(r==KErrNone);
|
|
239 |
TInt button=0;
|
|
240 |
TRequestStatus status;
|
|
241 |
TRequestStatus timerStatus;
|
|
242 |
RTimer timer;
|
|
243 |
timer.CreateLocal();
|
|
244 |
|
|
245 |
test.Next(_L("Launching simple notifier"));
|
|
246 |
_LIT(KLine1,"Line1 - Select Button2");
|
|
247 |
_LIT(KLine2,"Line2 - or press enter");
|
|
248 |
_LIT(KButton1,"Button1");
|
|
249 |
_LIT(KButton2,"Button2");
|
|
250 |
|
|
251 |
n.Notify(KLine1,KLine2,KButton1,KButton2,button,status);
|
|
252 |
timer.After(timerStatus,KTimeOut); // launch timer for getting control back after timeout
|
|
253 |
User::WaitForRequest(status, timerStatus);
|
|
254 |
if (status==KRequestPending)
|
|
255 |
{
|
|
256 |
test.Printf(_L("Timeout in waiting for keypress, continuing\n"));
|
|
257 |
|
|
258 |
// make the notifier to disappear
|
|
259 |
TRawEvent eventDown;
|
|
260 |
eventDown.Set(TRawEvent::EKeyDown,EStdKeyEnter);
|
|
261 |
TRawEvent eventUp;
|
|
262 |
eventUp.Set(TRawEvent::EKeyUp,EStdKeyEnter);
|
|
263 |
UserSvr::AddEvent(eventDown);
|
|
264 |
UserSvr::AddEvent(eventUp);
|
|
265 |
User::WaitForRequest(status); // wait again
|
|
266 |
}
|
|
267 |
else
|
|
268 |
{
|
|
269 |
timer.Cancel();
|
|
270 |
}
|
|
271 |
|
|
272 |
timer.Close();
|
|
273 |
|
|
274 |
test(status.Int()==KErrNone);
|
|
275 |
|
|
276 |
test.Next(_L("Close connection to notifier server"));
|
|
277 |
n.Close();
|
|
278 |
|
|
279 |
test.End();
|
|
280 |
}
|
|
281 |
|
|
282 |
void TestNotifyCancel()
|
|
283 |
//
|
|
284 |
// Simple test to just call NotifyCancel. Just sends a message
|
|
285 |
// which goes to window server. Window server ignores the cancel event
|
|
286 |
// and because of this, no notification to be canceled is started.
|
|
287 |
//
|
|
288 |
{
|
|
289 |
TInt r;
|
|
290 |
test.Start(_L("Connect to notifier server"));
|
|
291 |
RNotifier n;
|
|
292 |
r = n.Connect();
|
|
293 |
test(r==KErrNone);
|
|
294 |
|
|
295 |
test.Next(_L("Call NotifyCancel"));
|
|
296 |
n.NotifyCancel();
|
|
297 |
|
|
298 |
test.Next(_L("Close connection to notifier server"));
|
|
299 |
n.Close();
|
|
300 |
|
|
301 |
test.End();
|
|
302 |
}
|
|
303 |
|
|
304 |
|
|
305 |
void TestRemovedMethods()
|
|
306 |
//
|
|
307 |
// Test deprecated but exported methods
|
|
308 |
//
|
|
309 |
{
|
|
310 |
test.Start(_L("Test removed methods of RNotifier class"));
|
|
311 |
|
|
312 |
// connect to server
|
|
313 |
RNotifier n;
|
|
314 |
TInt r = n.Connect();
|
|
315 |
test(r==KErrNone);
|
|
316 |
|
|
317 |
test.Next(_L("StartNotifierAndGetResponse (5-params with dllUid)"));
|
|
318 |
TBuf8<128> response;
|
|
319 |
response.SetMax();
|
|
320 |
response.FillZ();
|
|
321 |
response.Zero();
|
|
322 |
TRequestStatus stat;
|
|
323 |
n.StartNotifierAndGetResponse(stat,KUidTestTextNotifier1,KUidTestTextNotifier2,*&KStartData,response);
|
|
324 |
User::WaitForRequest(stat);
|
|
325 |
test(stat==KErrNotSupported);
|
|
326 |
|
|
327 |
test.Next(_L("StartNotifier (4-params with dllUid)"));
|
|
328 |
test(n.StartNotifier(KUidTestTextNotifier2,KUidTestTextNotifier1,*&KStartData,response)==KErrNotSupported);
|
|
329 |
|
|
330 |
test.Next(_L("Test removed method LoadNotifiers()"));
|
|
331 |
test(n.LoadNotifiers(KUidTestTextNotifier1)==KErrNotSupported);
|
|
332 |
|
|
333 |
test.Next(_L("Test removed method UnloadNotifiers()"));
|
|
334 |
test(n.UnloadNotifiers(KUidTestTextNotifier1)==KErrNotSupported);
|
|
335 |
|
|
336 |
test.Next(_L("Close connection to notifier server"));
|
|
337 |
n.Close();
|
|
338 |
test.End();
|
|
339 |
}
|
|
340 |
|
|
341 |
|
0
|
342 |
void DoInteractiveTests()
|
|
343 |
{
|
|
344 |
TInt r;
|
|
345 |
|
|
346 |
test.Start(_L("Connect to notifier server"));
|
|
347 |
RNotifier n;
|
|
348 |
r = n.Connect();
|
|
349 |
test(r==KErrNone);
|
|
350 |
|
|
351 |
test.Next(_L("Launching simple notifier"));
|
|
352 |
_LIT(KLine1,"Line1 - Select Button2");
|
|
353 |
_LIT(KLine2,"Line2 - or press enter");
|
|
354 |
_LIT(KButton1,"Button1");
|
|
355 |
_LIT(KButton2,"Button2");
|
|
356 |
TInt button=-1;
|
|
357 |
TRequestStatus stat;
|
|
358 |
n.Notify(KLine1,KLine2,KButton1,KButton2,button,stat);
|
|
359 |
User::WaitForRequest(stat);
|
|
360 |
test(button==1);
|
|
361 |
|
|
362 |
test.Next(_L("Close connection to notifier server"));
|
|
363 |
n.Close();
|
|
364 |
|
|
365 |
test.End();
|
|
366 |
}
|
|
367 |
|
|
368 |
#include <e32svr.h>
|
|
369 |
|
|
370 |
GLDEF_C TInt E32Main()
|
|
371 |
{
|
|
372 |
test.Title();
|
|
373 |
|
|
374 |
test.Start(_L("Test V1 notifier"));
|
|
375 |
if(UserSvr::IpcV1Available())
|
|
376 |
DoTests(KUidTestTextNotifier1,EFalse);
|
|
377 |
else
|
|
378 |
test.Printf(_L("IPC V1 not supported"));
|
|
379 |
|
|
380 |
test.Next(_L("Test V2 notifier"));
|
|
381 |
DoTests(KUidTestTextNotifier2,EFalse);
|
|
382 |
|
|
383 |
test.Next(_L("Test V1 notifier using MNotifierManager"));
|
|
384 |
if(UserSvr::IpcV1Available())
|
|
385 |
DoTests(KUidTestTextNotifier1,ETrue);
|
|
386 |
else
|
|
387 |
test.Printf(_L("IPC V1 not supported"));
|
|
388 |
|
|
389 |
test.Next(_L("Test V2 notifier using MNotifierManager"));
|
|
390 |
if(UserSvr::IpcV1Available())
|
|
391 |
DoTests(KUidTestTextNotifier2,ETrue);
|
|
392 |
else
|
|
393 |
test.Printf(_L("FIX ME! - Can't run because IPC V1 not supported\n"));
|
|
394 |
|
271
|
395 |
|
|
396 |
test.Next(_L("TestNotify"));
|
|
397 |
TestNotify();
|
|
398 |
|
|
399 |
test.Next(_L("TestNotifyCancel"));
|
|
400 |
TestNotifyCancel();
|
|
401 |
|
|
402 |
test.Next(_L("Test removed methods"));
|
|
403 |
TestRemovedMethods();
|
|
404 |
|
0
|
405 |
test.Next(_L("Interactive Tests"));
|
|
406 |
test.Printf(_L(" Do you want to test notifiers interactively? y/n\n"));
|
|
407 |
test.Printf(_L(" Waiting 10 seconds for answer...\n"));
|
|
408 |
TRequestStatus keyStat;
|
|
409 |
test.Console()->Read(keyStat);
|
|
410 |
RTimer timer;
|
|
411 |
test(timer.CreateLocal()==KErrNone);
|
|
412 |
TRequestStatus timerStat;
|
|
413 |
timer.After(timerStat,10*1000000);
|
|
414 |
User::WaitForRequest(timerStat,keyStat);
|
|
415 |
TInt key = 0;
|
|
416 |
if(keyStat!=KRequestPending)
|
|
417 |
key = test.Console()->KeyCode();
|
|
418 |
timer.Cancel();
|
|
419 |
test.Console()->ReadCancel();
|
|
420 |
User::WaitForAnyRequest();
|
|
421 |
if(key=='y' || key=='Y')
|
|
422 |
DoInteractiveTests();
|
|
423 |
else
|
|
424 |
test.Printf(_L(" Interactive Tests Not Run\n"));
|
|
425 |
|
|
426 |
test.End();
|
|
427 |
return(0);
|
|
428 |
}
|