0
|
1 |
// Copyright (c) 2003-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 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,
|
|
27 |
// StartNotifierAndGetResponse. Verify results are as expected.
|
|
28 |
// Check for memory leaks and cleanup.
|
|
29 |
// - Do interactive tests as requested.
|
|
30 |
// Platforms/Drives/Compatibility:
|
|
31 |
// Hardware (Automatic).
|
|
32 |
// Assumptions/Requirement/Pre-requisites:
|
|
33 |
// Failures and causes:
|
|
34 |
// Base Port information:
|
|
35 |
//
|
|
36 |
//
|
|
37 |
|
|
38 |
#include <e32std.h>
|
|
39 |
#include <e32std_private.h>
|
|
40 |
#include <e32test.h>
|
|
41 |
#include "textnotifier.h"
|
|
42 |
#include <e32debug.h>
|
|
43 |
|
|
44 |
LOCAL_D RTest test(_L("T_TEXTNOTIFIER"));
|
|
45 |
|
|
46 |
void DoMemoryLeakTests(TUid aUid,TBool aCheckMNotifierManager)
|
|
47 |
{
|
|
48 |
TInt r;
|
|
49 |
TRequestStatus stat;
|
|
50 |
|
|
51 |
test.Start(_L("Connect to notifier server"));
|
|
52 |
RNotifier n;
|
|
53 |
r = n.Connect();
|
|
54 |
test(r==KErrNone);
|
|
55 |
|
|
56 |
test.Next(_L("Get Notifier Server Heap Info"));
|
|
57 |
static TBuf8<128> heapInfo1;
|
|
58 |
heapInfo1.Zero();
|
|
59 |
n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo1);
|
|
60 |
User::WaitForRequest(stat);
|
|
61 |
n.CancelNotifier(aUid);
|
|
62 |
TInt heapCellCount=stat.Int();
|
|
63 |
test(heapCellCount>0);
|
|
64 |
|
|
65 |
test.Next(_L("Repeated StartNotifierAndGetResponse"));
|
|
66 |
for(TInt i=0; i<1000; i++)
|
|
67 |
{
|
|
68 |
TBuf8<128> response;
|
|
69 |
response.SetMax();
|
|
70 |
response.FillZ();
|
|
71 |
response.Zero();
|
|
72 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
|
|
73 |
User::WaitForRequest(stat);
|
|
74 |
n.CancelNotifier(aUid);
|
|
75 |
test(stat==KErrNone);
|
|
76 |
test(response==KResponseData);
|
|
77 |
}
|
|
78 |
|
|
79 |
test.Next(_L("Check Notifier Server Heap Info"));
|
|
80 |
static TBuf8<128> heapInfo2;
|
|
81 |
heapInfo2.Zero();
|
|
82 |
n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo2);
|
|
83 |
User::WaitForRequest(stat);
|
|
84 |
n.CancelNotifier(aUid);
|
|
85 |
test(stat==heapCellCount);
|
189
|
86 |
|
|
87 |
TInt size1, size2;
|
|
88 |
TLex8 lex(heapInfo1);
|
|
89 |
r = lex.Val(size1);
|
|
90 |
test(r==KErrNone);
|
|
91 |
lex.Assign(heapInfo2);
|
|
92 |
r = lex.Val(size2);
|
|
93 |
test(r==KErrNone);
|
|
94 |
//allocated size after should not be greater than before BUT may be less with new allocator
|
|
95 |
test(size2 <= size1);
|
0
|
96 |
|
|
97 |
test.Next(_L("Close connection to notifier server"));
|
|
98 |
n.Close();
|
|
99 |
|
|
100 |
test.End();
|
|
101 |
}
|
|
102 |
|
|
103 |
void DoCleanumpTests(TUid aUid,TBool aCheckMNotifierManager)
|
|
104 |
{
|
|
105 |
TInt r;
|
|
106 |
|
|
107 |
test.Start(_L("Connect to notifier server"));
|
|
108 |
RNotifier n;
|
|
109 |
r = n.Connect();
|
|
110 |
test(r==KErrNone);
|
|
111 |
|
|
112 |
test.Next(_L("StartNotifierAndGetResponse"));
|
|
113 |
TBuf8<128> response;
|
|
114 |
response.SetMax();
|
|
115 |
response.FillZ();
|
|
116 |
response.Zero();
|
|
117 |
TRequestStatus stat;
|
|
118 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
|
|
119 |
User::WaitForRequest(stat);
|
|
120 |
test(stat==KErrNone);
|
|
121 |
test(response==KResponseData);
|
|
122 |
|
|
123 |
test.Next(_L("Close connection to notifier server"));
|
|
124 |
n.Close();
|
|
125 |
|
|
126 |
test.Next(_L("Connect to notifier server"));
|
|
127 |
r = n.Connect();
|
|
128 |
test(r==KErrNone);
|
|
129 |
|
|
130 |
test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
|
|
131 |
response.SetMax();
|
|
132 |
response.FillZ();
|
|
133 |
response.Zero();
|
|
134 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
|
|
135 |
User::WaitForRequest(stat);
|
|
136 |
test(stat==KTestNotifierWasPreviouselyCanceled);
|
|
137 |
test(response==KResponseData);
|
|
138 |
|
|
139 |
test.Next(_L("Close connection to notifier server"));
|
|
140 |
n.Close();
|
|
141 |
|
|
142 |
test.End();
|
|
143 |
}
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
void DoTests(TUid aUid,TBool aCheckMNotifierManager)
|
|
148 |
{
|
|
149 |
TInt r;
|
|
150 |
|
|
151 |
test.Start(_L("Connect to notifier server"));
|
|
152 |
RNotifier n;
|
|
153 |
r = n.Connect();
|
|
154 |
test(r==KErrNone);
|
|
155 |
|
|
156 |
test.Next(_L("StartNotifier (without response)"));
|
|
157 |
r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData);
|
|
158 |
RDebug::Printf("r=%d", r);
|
|
159 |
test(r==KErrNone);
|
|
160 |
|
|
161 |
test.Next(_L("CancelNotifier"));
|
|
162 |
r = n.CancelNotifier(aUid);
|
|
163 |
test(r==KErrNone);
|
|
164 |
|
|
165 |
test.Next(_L("StartNotifier"));
|
|
166 |
TBuf8<128> response;
|
|
167 |
response.SetMax();
|
|
168 |
response.FillZ();
|
|
169 |
response.Zero();
|
|
170 |
r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
|
|
171 |
test(r==KErrNone);
|
|
172 |
test(response==KResponseData);
|
|
173 |
|
|
174 |
test.Next(_L("UpdateNotifier"));
|
|
175 |
response.SetMax();
|
|
176 |
response.FillZ();
|
|
177 |
response.Zero(); // EKA1 text notifier dies if current length < length of response
|
|
178 |
r = n.UpdateNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
|
|
179 |
test(r==KErrNone);
|
|
180 |
test(response==KResponseData);
|
|
181 |
|
|
182 |
test.Next(_L("UpdateNotifierAndGetResponse"));
|
|
183 |
response.SetMax();
|
|
184 |
response.FillZ();
|
|
185 |
response.Zero(); // EKA1 text notifier dies if current length < length of response
|
|
186 |
TRequestStatus updateStat;
|
|
187 |
n.UpdateNotifierAndGetResponse(updateStat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
|
|
188 |
User::WaitForRequest(updateStat);
|
|
189 |
test(updateStat==KErrNone);
|
|
190 |
test(response==KResponseData);
|
|
191 |
|
|
192 |
test.Next(_L("CancelNotifier"));
|
|
193 |
r = n.CancelNotifier(aUid);
|
|
194 |
test(r==KErrNone);
|
|
195 |
|
|
196 |
test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
|
|
197 |
response.SetMax();
|
|
198 |
response.FillZ();
|
|
199 |
response.Zero();
|
|
200 |
TRequestStatus stat;
|
|
201 |
n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
|
|
202 |
User::WaitForRequest(stat);
|
|
203 |
test(stat==KTestNotifierWasPreviouselyCanceled);
|
|
204 |
test(response==KResponseData);
|
|
205 |
|
|
206 |
test.Next(_L("CancelNotifier"));
|
|
207 |
r = n.CancelNotifier(aUid);
|
|
208 |
test(r==KErrNone);
|
|
209 |
|
|
210 |
test.Next(_L("Close connection to notifier server"));
|
|
211 |
n.Close();
|
|
212 |
|
|
213 |
test.Next(_L("Memory leak tests"));
|
|
214 |
DoMemoryLeakTests(aUid,aCheckMNotifierManager);
|
|
215 |
|
|
216 |
test.Next(_L("Session cleanup test"));
|
|
217 |
DoCleanumpTests(aUid,aCheckMNotifierManager);
|
|
218 |
|
|
219 |
test.End();
|
|
220 |
}
|
|
221 |
|
|
222 |
void DoInteractiveTests()
|
|
223 |
{
|
|
224 |
TInt r;
|
|
225 |
|
|
226 |
test.Start(_L("Connect to notifier server"));
|
|
227 |
RNotifier n;
|
|
228 |
r = n.Connect();
|
|
229 |
test(r==KErrNone);
|
|
230 |
|
|
231 |
test.Next(_L("Launching simple notifier"));
|
|
232 |
_LIT(KLine1,"Line1 - Select Button2");
|
|
233 |
_LIT(KLine2,"Line2 - or press enter");
|
|
234 |
_LIT(KButton1,"Button1");
|
|
235 |
_LIT(KButton2,"Button2");
|
|
236 |
TInt button=-1;
|
|
237 |
TRequestStatus stat;
|
|
238 |
n.Notify(KLine1,KLine2,KButton1,KButton2,button,stat);
|
|
239 |
User::WaitForRequest(stat);
|
|
240 |
test(button==1);
|
|
241 |
|
|
242 |
test.Next(_L("Close connection to notifier server"));
|
|
243 |
n.Close();
|
|
244 |
|
|
245 |
test.End();
|
|
246 |
}
|
|
247 |
|
|
248 |
#include <e32svr.h>
|
|
249 |
|
|
250 |
GLDEF_C TInt E32Main()
|
|
251 |
{
|
|
252 |
test.Title();
|
|
253 |
|
|
254 |
test.Start(_L("Test V1 notifier"));
|
|
255 |
if(UserSvr::IpcV1Available())
|
|
256 |
DoTests(KUidTestTextNotifier1,EFalse);
|
|
257 |
else
|
|
258 |
test.Printf(_L("IPC V1 not supported"));
|
|
259 |
|
|
260 |
test.Next(_L("Test V2 notifier"));
|
|
261 |
DoTests(KUidTestTextNotifier2,EFalse);
|
|
262 |
|
|
263 |
test.Next(_L("Test V1 notifier using MNotifierManager"));
|
|
264 |
if(UserSvr::IpcV1Available())
|
|
265 |
DoTests(KUidTestTextNotifier1,ETrue);
|
|
266 |
else
|
|
267 |
test.Printf(_L("IPC V1 not supported"));
|
|
268 |
|
|
269 |
test.Next(_L("Test V2 notifier using MNotifierManager"));
|
|
270 |
if(UserSvr::IpcV1Available())
|
|
271 |
DoTests(KUidTestTextNotifier2,ETrue);
|
|
272 |
else
|
|
273 |
test.Printf(_L("FIX ME! - Can't run because IPC V1 not supported\n"));
|
|
274 |
|
|
275 |
test.Next(_L("Interactive Tests"));
|
|
276 |
test.Printf(_L(" Do you want to test notifiers interactively? y/n\n"));
|
|
277 |
test.Printf(_L(" Waiting 10 seconds for answer...\n"));
|
|
278 |
TRequestStatus keyStat;
|
|
279 |
test.Console()->Read(keyStat);
|
|
280 |
RTimer timer;
|
|
281 |
test(timer.CreateLocal()==KErrNone);
|
|
282 |
TRequestStatus timerStat;
|
|
283 |
timer.After(timerStat,10*1000000);
|
|
284 |
User::WaitForRequest(timerStat,keyStat);
|
|
285 |
TInt key = 0;
|
|
286 |
if(keyStat!=KRequestPending)
|
|
287 |
key = test.Console()->KeyCode();
|
|
288 |
timer.Cancel();
|
|
289 |
test.Console()->ReadCancel();
|
|
290 |
User::WaitForAnyRequest();
|
|
291 |
if(key=='y' || key=='Y')
|
|
292 |
DoInteractiveTests();
|
|
293 |
else
|
|
294 |
test.Printf(_L(" Interactive Tests Not Run\n"));
|
|
295 |
|
|
296 |
test.End();
|
|
297 |
return(0);
|
|
298 |
}
|