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.
     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);
    86 	test(heapInfo1==heapInfo2);
    87 
    88 	test.Next(_L("Close connection to notifier server"));
    89 	n.Close();
    90 
    91 	test.End();
    92 	}
    93 
    94 void DoCleanumpTests(TUid aUid,TBool aCheckMNotifierManager)
    95 	{
    96 	TInt r;
    97 
    98 	test.Start(_L("Connect to notifier server"));
    99 	RNotifier n;
   100 	r = n.Connect();
   101 	test(r==KErrNone);
   102 
   103 	test.Next(_L("StartNotifierAndGetResponse"));
   104 	TBuf8<128> response;
   105 	response.SetMax();
   106 	response.FillZ();
   107 	response.Zero();
   108 	TRequestStatus stat;
   109 	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
   110 	User::WaitForRequest(stat);
   111 	test(stat==KErrNone);
   112 	test(response==KResponseData);
   113 
   114 	test.Next(_L("Close connection to notifier server"));
   115 	n.Close();
   116 
   117 	test.Next(_L("Connect to notifier server"));
   118 	r = n.Connect();
   119 	test(r==KErrNone);
   120 
   121 	test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
   122 	response.SetMax();
   123 	response.FillZ();
   124 	response.Zero();
   125 	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
   126 	User::WaitForRequest(stat);
   127 	test(stat==KTestNotifierWasPreviouselyCanceled);
   128 	test(response==KResponseData);
   129 
   130 	test.Next(_L("Close connection to notifier server"));
   131 	n.Close();
   132 
   133 	test.End();
   134 	}
   135 
   136 
   137 
   138 void DoTests(TUid aUid,TBool aCheckMNotifierManager)
   139 	{	
   140 	TInt r;
   141 	
   142 	test.Start(_L("Connect to notifier server"));
   143 	RNotifier n;
   144 	r = n.Connect();
   145 	test(r==KErrNone);
   146 
   147 	test.Next(_L("StartNotifier (without response)"));
   148 	r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData);
   149 	RDebug::Printf("r=%d", r);
   150 	test(r==KErrNone);
   151 
   152 	test.Next(_L("CancelNotifier"));
   153 	r = n.CancelNotifier(aUid);
   154 	test(r==KErrNone);
   155 
   156 	test.Next(_L("StartNotifier"));
   157 	TBuf8<128> response;
   158 	response.SetMax();
   159 	response.FillZ();
   160 	response.Zero();
   161 	r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response);
   162 	test(r==KErrNone);
   163 	test(response==KResponseData);
   164 
   165 	test.Next(_L("UpdateNotifier"));
   166 	response.SetMax();
   167 	response.FillZ();
   168 	response.Zero();   // EKA1 text notifier dies if current length < length of response
   169 	r = n.UpdateNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response);
   170 	test(r==KErrNone);
   171 	test(response==KResponseData);
   172 
   173 	test.Next(_L("UpdateNotifierAndGetResponse"));
   174 	response.SetMax();
   175 	response.FillZ();
   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);
   182 
   183 	test.Next(_L("CancelNotifier"));
   184 	r = n.CancelNotifier(aUid);
   185 	test(r==KErrNone);
   186 
   187 	test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)"));
   188 	response.SetMax();
   189 	response.FillZ();
   190 	response.Zero();
   191 	TRequestStatus stat;
   192 	n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response);
   193 	User::WaitForRequest(stat);
   194 	test(stat==KTestNotifierWasPreviouselyCanceled);
   195 	test(response==KResponseData);
   196 
   197 	test.Next(_L("CancelNotifier"));
   198 	r = n.CancelNotifier(aUid);
   199 	test(r==KErrNone);
   200 
   201 	test.Next(_L("Close connection to notifier server"));
   202 	n.Close();
   203 
   204 	test.Next(_L("Memory leak tests"));
   205 	DoMemoryLeakTests(aUid,aCheckMNotifierManager);
   206 
   207 	test.Next(_L("Session cleanup test"));
   208 	DoCleanumpTests(aUid,aCheckMNotifierManager);
   209 
   210 	test.End();
   211 	}
   212 
   213 void DoInteractiveTests()
   214 	{
   215 	TInt r;
   216 
   217 	test.Start(_L("Connect to notifier server"));
   218 	RNotifier n;
   219 	r = n.Connect();
   220 	test(r==KErrNone);
   221 
   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");
   227 	TInt button=-1;
   228 	TRequestStatus stat;
   229 	n.Notify(KLine1,KLine2,KButton1,KButton2,button,stat);
   230 	User::WaitForRequest(stat);
   231 	test(button==1);
   232 
   233 	test.Next(_L("Close connection to notifier server"));
   234 	n.Close();
   235 
   236 	test.End();
   237 	}
   238 
   239 #include <e32svr.h>
   240 
   241 GLDEF_C TInt E32Main()
   242     {
   243 	test.Title();
   244 
   245 	test.Start(_L("Test V1 notifier"));
   246 	if(UserSvr::IpcV1Available())
   247 		DoTests(KUidTestTextNotifier1,EFalse);
   248 	else
   249 		test.Printf(_L("IPC V1 not supported"));
   250 
   251 	test.Next(_L("Test V2 notifier"));
   252 	DoTests(KUidTestTextNotifier2,EFalse);
   253 
   254 	test.Next(_L("Test V1 notifier using MNotifierManager"));
   255 	if(UserSvr::IpcV1Available())
   256 		DoTests(KUidTestTextNotifier1,ETrue);
   257 	else
   258 		test.Printf(_L("IPC V1 not supported"));
   259 
   260 	test.Next(_L("Test V2 notifier using MNotifierManager"));
   261 	if(UserSvr::IpcV1Available())
   262 		DoTests(KUidTestTextNotifier2,ETrue);
   263 	else
   264 		test.Printf(_L("FIX ME! - Can't run because IPC V1 not supported\n"));
   265 
   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);
   271 	RTimer timer;
   272 	test(timer.CreateLocal()==KErrNone);
   273 	TRequestStatus timerStat;
   274 	timer.After(timerStat,10*1000000);
   275 	User::WaitForRequest(timerStat,keyStat);
   276 	TInt key = 0;
   277 	if(keyStat!=KRequestPending)
   278 		key = test.Console()->KeyCode();
   279 	timer.Cancel();
   280 	test.Console()->ReadCancel();
   281 	User::WaitForAnyRequest();
   282 	if(key=='y' || key=='Y')
   283 		DoInteractiveTests();
   284 	else
   285 		test.Printf(_L("  Interactive Tests Not Run\n"));
   286 
   287 	test.End();
   288 	return(0);
   289 	}