os/kernelhwsrv/kerneltest/e32test/notifier/t_textnotifier.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\notifier\t_textnotifier.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test the RNotifier class.
sl@0
    17
// API Information:
sl@0
    18
// RNotifier
sl@0
    19
// Details:	
sl@0
    20
// - For IPC Ver. 1 and IPC Ver 2, connect to and start anotifier server.
sl@0
    21
// Perform a variety of tests including CancelNotifier, StartNotifier,
sl@0
    22
// UpdateNotifier, UpdateNotifierAndGetResponse, StartNotifierAndGetResponse.
sl@0
    23
// Verify results are as expected. Check for memory leaks and cleanup.
sl@0
    24
// - For IPC Ver. 1 and IPC Ver 2, using MNotifierManager, connect to and 
sl@0
    25
// start anotifier server. Perform a variety of tests including CancelNotifier, 
sl@0
    26
// StartNotifier, UpdateNotifier, UpdateNotifierAndGetResponse, 
sl@0
    27
// StartNotifierAndGetResponse. Verify results are as expected. 
sl@0
    28
// Check for memory leaks and cleanup.
sl@0
    29
// - Do interactive tests as requested.
sl@0
    30
// Platforms/Drives/Compatibility:
sl@0
    31
// Hardware (Automatic).
sl@0
    32
// Assumptions/Requirement/Pre-requisites:
sl@0
    33
// Failures and causes:
sl@0
    34
// Base Port information:
sl@0
    35
// 
sl@0
    36
//
sl@0
    37
sl@0
    38
#include <e32std.h>
sl@0
    39
#include <e32std_private.h>
sl@0
    40
#include <e32test.h>
sl@0
    41
#include "textnotifier.h"
sl@0
    42
#include <e32debug.h>
sl@0
    43
sl@0
    44
LOCAL_D RTest test(_L("T_TEXTNOTIFIER"));
sl@0
    45
sl@0
    46
void DoMemoryLeakTests(TUid aUid,TBool aCheckMNotifierManager)
sl@0
    47
	{
sl@0
    48
	TInt r;
sl@0
    49
	TRequestStatus stat;
sl@0
    50
sl@0
    51
	test.Start(_L("Connect to notifier server"));
sl@0
    52
	RNotifier n;
sl@0
    53
	r = n.Connect();
sl@0
    54
	test(r==KErrNone);
sl@0
    55
sl@0
    56
	test.Next(_L("Get Notifier Server Heap Info"));
sl@0
    57
	static TBuf8<128> heapInfo1;
sl@0
    58
	heapInfo1.Zero();
sl@0
    59
	n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo1);
sl@0
    60
	User::WaitForRequest(stat);
sl@0
    61
	n.CancelNotifier(aUid);
sl@0
    62
	TInt heapCellCount=stat.Int();
sl@0
    63
	test(heapCellCount>0);
sl@0
    64
sl@0
    65
	test.Next(_L("Repeated StartNotifierAndGetResponse"));
sl@0
    66
	for(TInt i=0; i<1000; i++)
sl@0
    67
		{
sl@0
    68
		TBuf8<128> response;
sl@0
    69
		response.SetMax();
sl@0
    70
		response.FillZ();
sl@0
    71
		response.Zero();
sl@0
    72
		n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
sl@0
    73
		User::WaitForRequest(stat);
sl@0
    74
		n.CancelNotifier(aUid);
sl@0
    75
		test(stat==KErrNone);
sl@0
    76
		test(response==KResponseData);
sl@0
    77
		}
sl@0
    78
sl@0
    79
	test.Next(_L("Check Notifier Server Heap Info"));
sl@0
    80
	static TBuf8<128> heapInfo2;
sl@0
    81
	heapInfo2.Zero();
sl@0
    82
	n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo2);
sl@0
    83
	User::WaitForRequest(stat);
sl@0
    84
	n.CancelNotifier(aUid);
sl@0
    85
	test(stat==heapCellCount);
sl@0
    86
	test(heapInfo1==heapInfo2);
sl@0
    87
sl@0
    88
	test.Next(_L("Close connection to notifier server"));
sl@0
    89
	n.Close();
sl@0
    90
sl@0
    91
	test.End();
sl@0
    92
	}
sl@0
    93
sl@0
    94
void DoCleanumpTests(TUid aUid,TBool aCheckMNotifierManager)
sl@0
    95
	{
sl@0
    96
	TInt r;
sl@0
    97
sl@0
    98
	test.Start(_L("Connect to notifier server"));
sl@0
    99
	RNotifier n;
sl@0
   100
	r = n.Connect();
sl@0
   101
	test(r==KErrNone);
sl@0
   102
sl@0
   103
	test.Next(_L("StartNotifierAndGetResponse"));
sl@0
   104
	TBuf8<128> response;
sl@0
   105
	response.SetMax();
sl@0
   106
	response.FillZ();
sl@0
   107
	response.Zero();
sl@0
   108
	TRequestStatus stat;
sl@0
   109
	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
sl@0
   110
	User::WaitForRequest(stat);
sl@0
   111
	test(stat==KErrNone);
sl@0
   112
	test(response==KResponseData);
sl@0
   113
sl@0
   114
	test.Next(_L("Close connection to notifier server"));
sl@0
   115
	n.Close();
sl@0
   116
sl@0
   117
	test.Next(_L("Connect to notifier server"));
sl@0
   118
	r = n.Connect();
sl@0
   119
	test(r==KErrNone);
sl@0
   120
sl@0
   121
	test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
sl@0
   122
	response.SetMax();
sl@0
   123
	response.FillZ();
sl@0
   124
	response.Zero();
sl@0
   125
	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
sl@0
   126
	User::WaitForRequest(stat);
sl@0
   127
	test(stat==KTestNotifierWasPreviouselyCanceled);
sl@0
   128
	test(response==KResponseData);
sl@0
   129
sl@0
   130
	test.Next(_L("Close connection to notifier server"));
sl@0
   131
	n.Close();
sl@0
   132
sl@0
   133
	test.End();
sl@0
   134
	}
sl@0
   135
sl@0
   136
sl@0
   137
sl@0
   138
void DoTests(TUid aUid,TBool aCheckMNotifierManager)
sl@0
   139
	{	
sl@0
   140
	TInt r;
sl@0
   141
	
sl@0
   142
	test.Start(_L("Connect to notifier server"));
sl@0
   143
	RNotifier n;
sl@0
   144
	r = n.Connect();
sl@0
   145
	test(r==KErrNone);
sl@0
   146
sl@0
   147
	test.Next(_L("StartNotifier (without response)"));
sl@0
   148
	r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData);
sl@0
   149
	RDebug::Printf("r=%d", r);
sl@0
   150
	test(r==KErrNone);
sl@0
   151
sl@0
   152
	test.Next(_L("CancelNotifier"));
sl@0
   153
	r = n.CancelNotifier(aUid);
sl@0
   154
	test(r==KErrNone);
sl@0
   155
sl@0
   156
	test.Next(_L("StartNotifier"));
sl@0
   157
	TBuf8<128> response;
sl@0
   158
	response.SetMax();
sl@0
   159
	response.FillZ();
sl@0
   160
	response.Zero();
sl@0
   161
	r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
sl@0
   162
	test(r==KErrNone);
sl@0
   163
	test(response==KResponseData);
sl@0
   164
sl@0
   165
	test.Next(_L("UpdateNotifier"));
sl@0
   166
	response.SetMax();
sl@0
   167
	response.FillZ();
sl@0
   168
	response.Zero();   // EKA1 text notifier dies if current length < length of response
sl@0
   169
	r = n.UpdateNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
sl@0
   170
	test(r==KErrNone);
sl@0
   171
	test(response==KResponseData);
sl@0
   172
sl@0
   173
	test.Next(_L("UpdateNotifierAndGetResponse"));
sl@0
   174
	response.SetMax();
sl@0
   175
	response.FillZ();
sl@0
   176
	response.Zero();   // EKA1 text notifier dies if current length < length of response
sl@0
   177
	TRequestStatus updateStat;
sl@0
   178
	n.UpdateNotifierAndGetResponse(updateStat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
sl@0
   179
	User::WaitForRequest(updateStat);
sl@0
   180
	test(updateStat==KErrNone);
sl@0
   181
	test(response==KResponseData);
sl@0
   182
sl@0
   183
	test.Next(_L("CancelNotifier"));
sl@0
   184
	r = n.CancelNotifier(aUid);
sl@0
   185
	test(r==KErrNone);
sl@0
   186
sl@0
   187
	test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
sl@0
   188
	response.SetMax();
sl@0
   189
	response.FillZ();
sl@0
   190
	response.Zero();
sl@0
   191
	TRequestStatus stat;
sl@0
   192
	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
sl@0
   193
	User::WaitForRequest(stat);
sl@0
   194
	test(stat==KTestNotifierWasPreviouselyCanceled);
sl@0
   195
	test(response==KResponseData);
sl@0
   196
sl@0
   197
	test.Next(_L("CancelNotifier"));
sl@0
   198
	r = n.CancelNotifier(aUid);
sl@0
   199
	test(r==KErrNone);
sl@0
   200
sl@0
   201
	test.Next(_L("Close connection to notifier server"));
sl@0
   202
	n.Close();
sl@0
   203
sl@0
   204
	test.Next(_L("Memory leak tests"));
sl@0
   205
	DoMemoryLeakTests(aUid,aCheckMNotifierManager);
sl@0
   206
sl@0
   207
	test.Next(_L("Session cleanup test"));
sl@0
   208
	DoCleanumpTests(aUid,aCheckMNotifierManager);
sl@0
   209
sl@0
   210
	test.End();
sl@0
   211
	}
sl@0
   212
sl@0
   213
void DoInteractiveTests()
sl@0
   214
	{
sl@0
   215
	TInt r;
sl@0
   216
sl@0
   217
	test.Start(_L("Connect to notifier server"));
sl@0
   218
	RNotifier n;
sl@0
   219
	r = n.Connect();
sl@0
   220
	test(r==KErrNone);
sl@0
   221
sl@0
   222
	test.Next(_L("Launching simple notifier"));
sl@0
   223
	_LIT(KLine1,"Line1 - Select Button2");
sl@0
   224
	_LIT(KLine2,"Line2 - or press enter");
sl@0
   225
	_LIT(KButton1,"Button1");
sl@0
   226
	_LIT(KButton2,"Button2");
sl@0
   227
	TInt button=-1;
sl@0
   228
	TRequestStatus stat;
sl@0
   229
	n.Notify(KLine1,KLine2,KButton1,KButton2,button,stat);
sl@0
   230
	User::WaitForRequest(stat);
sl@0
   231
	test(button==1);
sl@0
   232
sl@0
   233
	test.Next(_L("Close connection to notifier server"));
sl@0
   234
	n.Close();
sl@0
   235
sl@0
   236
	test.End();
sl@0
   237
	}
sl@0
   238
sl@0
   239
#include <e32svr.h>
sl@0
   240
sl@0
   241
GLDEF_C TInt E32Main()
sl@0
   242
    {
sl@0
   243
	test.Title();
sl@0
   244
sl@0
   245
	test.Start(_L("Test V1 notifier"));
sl@0
   246
	if(UserSvr::IpcV1Available())
sl@0
   247
		DoTests(KUidTestTextNotifier1,EFalse);
sl@0
   248
	else
sl@0
   249
		test.Printf(_L("IPC V1 not supported"));
sl@0
   250
sl@0
   251
	test.Next(_L("Test V2 notifier"));
sl@0
   252
	DoTests(KUidTestTextNotifier2,EFalse);
sl@0
   253
sl@0
   254
	test.Next(_L("Test V1 notifier using MNotifierManager"));
sl@0
   255
	if(UserSvr::IpcV1Available())
sl@0
   256
		DoTests(KUidTestTextNotifier1,ETrue);
sl@0
   257
	else
sl@0
   258
		test.Printf(_L("IPC V1 not supported"));
sl@0
   259
sl@0
   260
	test.Next(_L("Test V2 notifier using MNotifierManager"));
sl@0
   261
	if(UserSvr::IpcV1Available())
sl@0
   262
		DoTests(KUidTestTextNotifier2,ETrue);
sl@0
   263
	else
sl@0
   264
		test.Printf(_L("FIX ME! - Can't run because IPC V1 not supported\n"));
sl@0
   265
sl@0
   266
	test.Next(_L("Interactive Tests"));
sl@0
   267
	test.Printf(_L("  Do you want to test notifiers interactively? y/n\n"));
sl@0
   268
	test.Printf(_L("  Waiting 10 seconds for answer...\n"));
sl@0
   269
	TRequestStatus keyStat;
sl@0
   270
	test.Console()->Read(keyStat);
sl@0
   271
	RTimer timer;
sl@0
   272
	test(timer.CreateLocal()==KErrNone);
sl@0
   273
	TRequestStatus timerStat;
sl@0
   274
	timer.After(timerStat,10*1000000);
sl@0
   275
	User::WaitForRequest(timerStat,keyStat);
sl@0
   276
	TInt key = 0;
sl@0
   277
	if(keyStat!=KRequestPending)
sl@0
   278
		key = test.Console()->KeyCode();
sl@0
   279
	timer.Cancel();
sl@0
   280
	test.Console()->ReadCancel();
sl@0
   281
	User::WaitForAnyRequest();
sl@0
   282
	if(key=='y' || key=='Y')
sl@0
   283
		DoInteractiveTests();
sl@0
   284
	else
sl@0
   285
		test.Printf(_L("  Interactive Tests Not Run\n"));
sl@0
   286
sl@0
   287
	test.End();
sl@0
   288
	return(0);
sl@0
   289
	}