Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\notifier\t_textnotifier.cpp
16 // Test the RNotifier class.
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:
39 #include <e32std_private.h>
41 #include "textnotifier.h"
44 LOCAL_D RTest test(_L("T_TEXTNOTIFIER"));
46 void DoMemoryLeakTests(TUid aUid,TBool aCheckMNotifierManager)
51 test.Start(_L("Connect to notifier server"));
56 test.Next(_L("Get Notifier Server Heap Info"));
57 static TBuf8<128> heapInfo1;
59 n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo1);
60 User::WaitForRequest(stat);
61 n.CancelNotifier(aUid);
62 TInt heapCellCount=stat.Int();
63 test(heapCellCount>0);
65 test.Next(_L("Repeated StartNotifierAndGetResponse"));
66 for(TInt i=0; i<1000; i++)
72 n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
73 User::WaitForRequest(stat);
74 n.CancelNotifier(aUid);
76 test(response==KResponseData);
79 test.Next(_L("Check Notifier Server Heap Info"));
80 static TBuf8<128> heapInfo2;
82 n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo2);
83 User::WaitForRequest(stat);
84 n.CancelNotifier(aUid);
85 test(stat==heapCellCount);
86 test(heapInfo1==heapInfo2);
88 test.Next(_L("Close connection to notifier server"));
94 void DoCleanumpTests(TUid aUid,TBool aCheckMNotifierManager)
98 test.Start(_L("Connect to notifier server"));
103 test.Next(_L("StartNotifierAndGetResponse"));
109 n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
110 User::WaitForRequest(stat);
111 test(stat==KErrNone);
112 test(response==KResponseData);
114 test.Next(_L("Close connection to notifier server"));
117 test.Next(_L("Connect to notifier server"));
121 test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
125 n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
126 User::WaitForRequest(stat);
127 test(stat==KTestNotifierWasPreviouselyCanceled);
128 test(response==KResponseData);
130 test.Next(_L("Close connection to notifier server"));
138 void DoTests(TUid aUid,TBool aCheckMNotifierManager)
142 test.Start(_L("Connect to notifier server"));
147 test.Next(_L("StartNotifier (without response)"));
148 r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData);
149 RDebug::Printf("r=%d", r);
152 test.Next(_L("CancelNotifier"));
153 r = n.CancelNotifier(aUid);
156 test.Next(_L("StartNotifier"));
161 r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
163 test(response==KResponseData);
165 test.Next(_L("UpdateNotifier"));
168 response.Zero(); // EKA1 text notifier dies if current length < length of response
169 r = n.UpdateNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
171 test(response==KResponseData);
173 test.Next(_L("UpdateNotifierAndGetResponse"));
176 response.Zero(); // EKA1 text notifier dies if current length < length of response
177 TRequestStatus updateStat;
178 n.UpdateNotifierAndGetResponse(updateStat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
179 User::WaitForRequest(updateStat);
180 test(updateStat==KErrNone);
181 test(response==KResponseData);
183 test.Next(_L("CancelNotifier"));
184 r = n.CancelNotifier(aUid);
187 test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
192 n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
193 User::WaitForRequest(stat);
194 test(stat==KTestNotifierWasPreviouselyCanceled);
195 test(response==KResponseData);
197 test.Next(_L("CancelNotifier"));
198 r = n.CancelNotifier(aUid);
201 test.Next(_L("Close connection to notifier server"));
204 test.Next(_L("Memory leak tests"));
205 DoMemoryLeakTests(aUid,aCheckMNotifierManager);
207 test.Next(_L("Session cleanup test"));
208 DoCleanumpTests(aUid,aCheckMNotifierManager);
213 void DoInteractiveTests()
217 test.Start(_L("Connect to notifier server"));
222 test.Next(_L("Launching simple notifier"));
223 _LIT(KLine1,"Line1 - Select Button2");
224 _LIT(KLine2,"Line2 - or press enter");
225 _LIT(KButton1,"Button1");
226 _LIT(KButton2,"Button2");
229 n.Notify(KLine1,KLine2,KButton1,KButton2,button,stat);
230 User::WaitForRequest(stat);
233 test.Next(_L("Close connection to notifier server"));
241 GLDEF_C TInt E32Main()
245 test.Start(_L("Test V1 notifier"));
246 if(UserSvr::IpcV1Available())
247 DoTests(KUidTestTextNotifier1,EFalse);
249 test.Printf(_L("IPC V1 not supported"));
251 test.Next(_L("Test V2 notifier"));
252 DoTests(KUidTestTextNotifier2,EFalse);
254 test.Next(_L("Test V1 notifier using MNotifierManager"));
255 if(UserSvr::IpcV1Available())
256 DoTests(KUidTestTextNotifier1,ETrue);
258 test.Printf(_L("IPC V1 not supported"));
260 test.Next(_L("Test V2 notifier using MNotifierManager"));
261 if(UserSvr::IpcV1Available())
262 DoTests(KUidTestTextNotifier2,ETrue);
264 test.Printf(_L("FIX ME! - Can't run because IPC V1 not supported\n"));
266 test.Next(_L("Interactive Tests"));
267 test.Printf(_L(" Do you want to test notifiers interactively? y/n\n"));
268 test.Printf(_L(" Waiting 10 seconds for answer...\n"));
269 TRequestStatus keyStat;
270 test.Console()->Read(keyStat);
272 test(timer.CreateLocal()==KErrNone);
273 TRequestStatus timerStat;
274 timer.After(timerStat,10*1000000);
275 User::WaitForRequest(timerStat,keyStat);
277 if(keyStat!=KRequestPending)
278 key = test.Console()->KeyCode();
280 test.Console()->ReadCancel();
281 User::WaitForAnyRequest();
282 if(key=='y' || key=='Y')
283 DoInteractiveTests();
285 test.Printf(_L(" Interactive Tests Not Run\n"));