os/kernelhwsrv/kerneltest/e32test/notifier/t_textnotifier.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/notifier/t_textnotifier.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,289 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\notifier\t_textnotifier.cpp
    1.18 +// Overview:
    1.19 +// Test the RNotifier class.
    1.20 +// API Information:
    1.21 +// RNotifier
    1.22 +// Details:	
    1.23 +// - For IPC Ver. 1 and IPC Ver 2, connect to and start anotifier server.
    1.24 +// Perform a variety of tests including CancelNotifier, StartNotifier,
    1.25 +// UpdateNotifier, UpdateNotifierAndGetResponse, StartNotifierAndGetResponse.
    1.26 +// Verify results are as expected. Check for memory leaks and cleanup.
    1.27 +// - For IPC Ver. 1 and IPC Ver 2, using MNotifierManager, connect to and 
    1.28 +// start anotifier server. Perform a variety of tests including CancelNotifier, 
    1.29 +// StartNotifier, UpdateNotifier, UpdateNotifierAndGetResponse, 
    1.30 +// StartNotifierAndGetResponse. Verify results are as expected. 
    1.31 +// Check for memory leaks and cleanup.
    1.32 +// - Do interactive tests as requested.
    1.33 +// Platforms/Drives/Compatibility:
    1.34 +// Hardware (Automatic).
    1.35 +// Assumptions/Requirement/Pre-requisites:
    1.36 +// Failures and causes:
    1.37 +// Base Port information:
    1.38 +// 
    1.39 +//
    1.40 +
    1.41 +#include <e32std.h>
    1.42 +#include <e32std_private.h>
    1.43 +#include <e32test.h>
    1.44 +#include "textnotifier.h"
    1.45 +#include <e32debug.h>
    1.46 +
    1.47 +LOCAL_D RTest test(_L("T_TEXTNOTIFIER"));
    1.48 +
    1.49 +void DoMemoryLeakTests(TUid aUid,TBool aCheckMNotifierManager)
    1.50 +	{
    1.51 +	TInt r;
    1.52 +	TRequestStatus stat;
    1.53 +
    1.54 +	test.Start(_L("Connect to notifier server"));
    1.55 +	RNotifier n;
    1.56 +	r = n.Connect();
    1.57 +	test(r==KErrNone);
    1.58 +
    1.59 +	test.Next(_L("Get Notifier Server Heap Info"));
    1.60 +	static TBuf8<128> heapInfo1;
    1.61 +	heapInfo1.Zero();
    1.62 +	n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo1);
    1.63 +	User::WaitForRequest(stat);
    1.64 +	n.CancelNotifier(aUid);
    1.65 +	TInt heapCellCount=stat.Int();
    1.66 +	test(heapCellCount>0);
    1.67 +
    1.68 +	test.Next(_L("Repeated StartNotifierAndGetResponse"));
    1.69 +	for(TInt i=0; i<1000; i++)
    1.70 +		{
    1.71 +		TBuf8<128> response;
    1.72 +		response.SetMax();
    1.73 +		response.FillZ();
    1.74 +		response.Zero();
    1.75 +		n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
    1.76 +		User::WaitForRequest(stat);
    1.77 +		n.CancelNotifier(aUid);
    1.78 +		test(stat==KErrNone);
    1.79 +		test(response==KResponseData);
    1.80 +		}
    1.81 +
    1.82 +	test.Next(_L("Check Notifier Server Heap Info"));
    1.83 +	static TBuf8<128> heapInfo2;
    1.84 +	heapInfo2.Zero();
    1.85 +	n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo2);
    1.86 +	User::WaitForRequest(stat);
    1.87 +	n.CancelNotifier(aUid);
    1.88 +	test(stat==heapCellCount);
    1.89 +	test(heapInfo1==heapInfo2);
    1.90 +
    1.91 +	test.Next(_L("Close connection to notifier server"));
    1.92 +	n.Close();
    1.93 +
    1.94 +	test.End();
    1.95 +	}
    1.96 +
    1.97 +void DoCleanumpTests(TUid aUid,TBool aCheckMNotifierManager)
    1.98 +	{
    1.99 +	TInt r;
   1.100 +
   1.101 +	test.Start(_L("Connect to notifier server"));
   1.102 +	RNotifier n;
   1.103 +	r = n.Connect();
   1.104 +	test(r==KErrNone);
   1.105 +
   1.106 +	test.Next(_L("StartNotifierAndGetResponse"));
   1.107 +	TBuf8<128> response;
   1.108 +	response.SetMax();
   1.109 +	response.FillZ();
   1.110 +	response.Zero();
   1.111 +	TRequestStatus stat;
   1.112 +	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
   1.113 +	User::WaitForRequest(stat);
   1.114 +	test(stat==KErrNone);
   1.115 +	test(response==KResponseData);
   1.116 +
   1.117 +	test.Next(_L("Close connection to notifier server"));
   1.118 +	n.Close();
   1.119 +
   1.120 +	test.Next(_L("Connect to notifier server"));
   1.121 +	r = n.Connect();
   1.122 +	test(r==KErrNone);
   1.123 +
   1.124 +	test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
   1.125 +	response.SetMax();
   1.126 +	response.FillZ();
   1.127 +	response.Zero();
   1.128 +	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
   1.129 +	User::WaitForRequest(stat);
   1.130 +	test(stat==KTestNotifierWasPreviouselyCanceled);
   1.131 +	test(response==KResponseData);
   1.132 +
   1.133 +	test.Next(_L("Close connection to notifier server"));
   1.134 +	n.Close();
   1.135 +
   1.136 +	test.End();
   1.137 +	}
   1.138 +
   1.139 +
   1.140 +
   1.141 +void DoTests(TUid aUid,TBool aCheckMNotifierManager)
   1.142 +	{	
   1.143 +	TInt r;
   1.144 +	
   1.145 +	test.Start(_L("Connect to notifier server"));
   1.146 +	RNotifier n;
   1.147 +	r = n.Connect();
   1.148 +	test(r==KErrNone);
   1.149 +
   1.150 +	test.Next(_L("StartNotifier (without response)"));
   1.151 +	r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData);
   1.152 +	RDebug::Printf("r=%d", r);
   1.153 +	test(r==KErrNone);
   1.154 +
   1.155 +	test.Next(_L("CancelNotifier"));
   1.156 +	r = n.CancelNotifier(aUid);
   1.157 +	test(r==KErrNone);
   1.158 +
   1.159 +	test.Next(_L("StartNotifier"));
   1.160 +	TBuf8<128> response;
   1.161 +	response.SetMax();
   1.162 +	response.FillZ();
   1.163 +	response.Zero();
   1.164 +	r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
   1.165 +	test(r==KErrNone);
   1.166 +	test(response==KResponseData);
   1.167 +
   1.168 +	test.Next(_L("UpdateNotifier"));
   1.169 +	response.SetMax();
   1.170 +	response.FillZ();
   1.171 +	response.Zero();   // EKA1 text notifier dies if current length < length of response
   1.172 +	r = n.UpdateNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
   1.173 +	test(r==KErrNone);
   1.174 +	test(response==KResponseData);
   1.175 +
   1.176 +	test.Next(_L("UpdateNotifierAndGetResponse"));
   1.177 +	response.SetMax();
   1.178 +	response.FillZ();
   1.179 +	response.Zero();   // EKA1 text notifier dies if current length < length of response
   1.180 +	TRequestStatus updateStat;
   1.181 +	n.UpdateNotifierAndGetResponse(updateStat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
   1.182 +	User::WaitForRequest(updateStat);
   1.183 +	test(updateStat==KErrNone);
   1.184 +	test(response==KResponseData);
   1.185 +
   1.186 +	test.Next(_L("CancelNotifier"));
   1.187 +	r = n.CancelNotifier(aUid);
   1.188 +	test(r==KErrNone);
   1.189 +
   1.190 +	test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
   1.191 +	response.SetMax();
   1.192 +	response.FillZ();
   1.193 +	response.Zero();
   1.194 +	TRequestStatus stat;
   1.195 +	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
   1.196 +	User::WaitForRequest(stat);
   1.197 +	test(stat==KTestNotifierWasPreviouselyCanceled);
   1.198 +	test(response==KResponseData);
   1.199 +
   1.200 +	test.Next(_L("CancelNotifier"));
   1.201 +	r = n.CancelNotifier(aUid);
   1.202 +	test(r==KErrNone);
   1.203 +
   1.204 +	test.Next(_L("Close connection to notifier server"));
   1.205 +	n.Close();
   1.206 +
   1.207 +	test.Next(_L("Memory leak tests"));
   1.208 +	DoMemoryLeakTests(aUid,aCheckMNotifierManager);
   1.209 +
   1.210 +	test.Next(_L("Session cleanup test"));
   1.211 +	DoCleanumpTests(aUid,aCheckMNotifierManager);
   1.212 +
   1.213 +	test.End();
   1.214 +	}
   1.215 +
   1.216 +void DoInteractiveTests()
   1.217 +	{
   1.218 +	TInt r;
   1.219 +
   1.220 +	test.Start(_L("Connect to notifier server"));
   1.221 +	RNotifier n;
   1.222 +	r = n.Connect();
   1.223 +	test(r==KErrNone);
   1.224 +
   1.225 +	test.Next(_L("Launching simple notifier"));
   1.226 +	_LIT(KLine1,"Line1 - Select Button2");
   1.227 +	_LIT(KLine2,"Line2 - or press enter");
   1.228 +	_LIT(KButton1,"Button1");
   1.229 +	_LIT(KButton2,"Button2");
   1.230 +	TInt button=-1;
   1.231 +	TRequestStatus stat;
   1.232 +	n.Notify(KLine1,KLine2,KButton1,KButton2,button,stat);
   1.233 +	User::WaitForRequest(stat);
   1.234 +	test(button==1);
   1.235 +
   1.236 +	test.Next(_L("Close connection to notifier server"));
   1.237 +	n.Close();
   1.238 +
   1.239 +	test.End();
   1.240 +	}
   1.241 +
   1.242 +#include <e32svr.h>
   1.243 +
   1.244 +GLDEF_C TInt E32Main()
   1.245 +    {
   1.246 +	test.Title();
   1.247 +
   1.248 +	test.Start(_L("Test V1 notifier"));
   1.249 +	if(UserSvr::IpcV1Available())
   1.250 +		DoTests(KUidTestTextNotifier1,EFalse);
   1.251 +	else
   1.252 +		test.Printf(_L("IPC V1 not supported"));
   1.253 +
   1.254 +	test.Next(_L("Test V2 notifier"));
   1.255 +	DoTests(KUidTestTextNotifier2,EFalse);
   1.256 +
   1.257 +	test.Next(_L("Test V1 notifier using MNotifierManager"));
   1.258 +	if(UserSvr::IpcV1Available())
   1.259 +		DoTests(KUidTestTextNotifier1,ETrue);
   1.260 +	else
   1.261 +		test.Printf(_L("IPC V1 not supported"));
   1.262 +
   1.263 +	test.Next(_L("Test V2 notifier using MNotifierManager"));
   1.264 +	if(UserSvr::IpcV1Available())
   1.265 +		DoTests(KUidTestTextNotifier2,ETrue);
   1.266 +	else
   1.267 +		test.Printf(_L("FIX ME! - Can't run because IPC V1 not supported\n"));
   1.268 +
   1.269 +	test.Next(_L("Interactive Tests"));
   1.270 +	test.Printf(_L("  Do you want to test notifiers interactively? y/n\n"));
   1.271 +	test.Printf(_L("  Waiting 10 seconds for answer...\n"));
   1.272 +	TRequestStatus keyStat;
   1.273 +	test.Console()->Read(keyStat);
   1.274 +	RTimer timer;
   1.275 +	test(timer.CreateLocal()==KErrNone);
   1.276 +	TRequestStatus timerStat;
   1.277 +	timer.After(timerStat,10*1000000);
   1.278 +	User::WaitForRequest(timerStat,keyStat);
   1.279 +	TInt key = 0;
   1.280 +	if(keyStat!=KRequestPending)
   1.281 +		key = test.Console()->KeyCode();
   1.282 +	timer.Cancel();
   1.283 +	test.Console()->ReadCancel();
   1.284 +	User::WaitForAnyRequest();
   1.285 +	if(key=='y' || key=='Y')
   1.286 +		DoInteractiveTests();
   1.287 +	else
   1.288 +		test.Printf(_L("  Interactive Tests Not Run\n"));
   1.289 +
   1.290 +	test.End();
   1.291 +	return(0);
   1.292 +	}