sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\notifier\t_textnotifier.cpp sl@0: // Overview: sl@0: // Test the RNotifier class. sl@0: // API Information: sl@0: // RNotifier sl@0: // Details: sl@0: // - For IPC Ver. 1 and IPC Ver 2, connect to and start anotifier server. sl@0: // Perform a variety of tests including CancelNotifier, StartNotifier, sl@0: // UpdateNotifier, UpdateNotifierAndGetResponse, StartNotifierAndGetResponse. sl@0: // Verify results are as expected. Check for memory leaks and cleanup. sl@0: // - For IPC Ver. 1 and IPC Ver 2, using MNotifierManager, connect to and sl@0: // start anotifier server. Perform a variety of tests including CancelNotifier, sl@0: // StartNotifier, UpdateNotifier, UpdateNotifierAndGetResponse, sl@0: // StartNotifierAndGetResponse. Verify results are as expected. sl@0: // Check for memory leaks and cleanup. sl@0: // - Do interactive tests as requested. sl@0: // Platforms/Drives/Compatibility: sl@0: // Hardware (Automatic). sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "textnotifier.h" sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("T_TEXTNOTIFIER")); sl@0: sl@0: void DoMemoryLeakTests(TUid aUid,TBool aCheckMNotifierManager) sl@0: { sl@0: TInt r; sl@0: TRequestStatus stat; sl@0: sl@0: test.Start(_L("Connect to notifier server")); sl@0: RNotifier n; sl@0: r = n.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Get Notifier Server Heap Info")); sl@0: static TBuf8<128> heapInfo1; sl@0: heapInfo1.Zero(); sl@0: n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo1); sl@0: User::WaitForRequest(stat); sl@0: n.CancelNotifier(aUid); sl@0: TInt heapCellCount=stat.Int(); sl@0: test(heapCellCount>0); sl@0: sl@0: test.Next(_L("Repeated StartNotifierAndGetResponse")); sl@0: for(TInt i=0; i<1000; i++) sl@0: { sl@0: TBuf8<128> response; sl@0: response.SetMax(); sl@0: response.FillZ(); sl@0: response.Zero(); sl@0: n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response); sl@0: User::WaitForRequest(stat); sl@0: n.CancelNotifier(aUid); sl@0: test(stat==KErrNone); sl@0: test(response==KResponseData); sl@0: } sl@0: sl@0: test.Next(_L("Check Notifier Server Heap Info")); sl@0: static TBuf8<128> heapInfo2; sl@0: heapInfo2.Zero(); sl@0: n.StartNotifierAndGetResponse(stat,aUid,KHeapData,heapInfo2); sl@0: User::WaitForRequest(stat); sl@0: n.CancelNotifier(aUid); sl@0: test(stat==heapCellCount); sl@0: test(heapInfo1==heapInfo2); sl@0: sl@0: test.Next(_L("Close connection to notifier server")); sl@0: n.Close(); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void DoCleanumpTests(TUid aUid,TBool aCheckMNotifierManager) sl@0: { sl@0: TInt r; sl@0: sl@0: test.Start(_L("Connect to notifier server")); sl@0: RNotifier n; sl@0: r = n.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("StartNotifierAndGetResponse")); sl@0: TBuf8<128> response; sl@0: response.SetMax(); sl@0: response.FillZ(); sl@0: response.Zero(); sl@0: TRequestStatus stat; sl@0: n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response); sl@0: User::WaitForRequest(stat); sl@0: test(stat==KErrNone); sl@0: test(response==KResponseData); sl@0: sl@0: test.Next(_L("Close connection to notifier server")); sl@0: n.Close(); sl@0: sl@0: test.Next(_L("Connect to notifier server")); sl@0: r = n.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)")); sl@0: response.SetMax(); sl@0: response.FillZ(); sl@0: response.Zero(); sl@0: n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response); sl@0: User::WaitForRequest(stat); sl@0: test(stat==KTestNotifierWasPreviouselyCanceled); sl@0: test(response==KResponseData); sl@0: sl@0: test.Next(_L("Close connection to notifier server")); sl@0: n.Close(); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: sl@0: void DoTests(TUid aUid,TBool aCheckMNotifierManager) sl@0: { sl@0: TInt r; sl@0: sl@0: test.Start(_L("Connect to notifier server")); sl@0: RNotifier n; sl@0: r = n.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("StartNotifier (without response)")); sl@0: r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData); sl@0: RDebug::Printf("r=%d", r); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("CancelNotifier")); sl@0: r = n.CancelNotifier(aUid); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("StartNotifier")); sl@0: TBuf8<128> response; sl@0: response.SetMax(); sl@0: response.FillZ(); sl@0: response.Zero(); sl@0: r = n.StartNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KStartData,response); sl@0: test(r==KErrNone); sl@0: test(response==KResponseData); sl@0: sl@0: test.Next(_L("UpdateNotifier")); sl@0: response.SetMax(); sl@0: response.FillZ(); sl@0: response.Zero(); // EKA1 text notifier dies if current length < length of response sl@0: r = n.UpdateNotifier(aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response); sl@0: test(r==KErrNone); sl@0: test(response==KResponseData); sl@0: sl@0: test.Next(_L("UpdateNotifierAndGetResponse")); sl@0: response.SetMax(); sl@0: response.FillZ(); sl@0: response.Zero(); // EKA1 text notifier dies if current length < length of response sl@0: TRequestStatus updateStat; sl@0: n.UpdateNotifierAndGetResponse(updateStat,aUid,aCheckMNotifierManager?*&KMNotifierManager:*&KUpdateData,response); sl@0: User::WaitForRequest(updateStat); sl@0: test(updateStat==KErrNone); sl@0: test(response==KResponseData); sl@0: sl@0: test.Next(_L("CancelNotifier")); sl@0: r = n.CancelNotifier(aUid); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("StartNotifierAndGetResponse (to check previous notifier was cancelled)")); sl@0: response.SetMax(); sl@0: response.FillZ(); sl@0: response.Zero(); sl@0: TRequestStatus stat; sl@0: n.StartNotifierAndGetResponse(stat,aUid,aCheckMNotifierManager?*&KMNotifierManagerWithCancelCheck:*&KStartWithCancelCheckData,response); sl@0: User::WaitForRequest(stat); sl@0: test(stat==KTestNotifierWasPreviouselyCanceled); sl@0: test(response==KResponseData); sl@0: sl@0: test.Next(_L("CancelNotifier")); sl@0: r = n.CancelNotifier(aUid); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Close connection to notifier server")); sl@0: n.Close(); sl@0: sl@0: test.Next(_L("Memory leak tests")); sl@0: DoMemoryLeakTests(aUid,aCheckMNotifierManager); sl@0: sl@0: test.Next(_L("Session cleanup test")); sl@0: DoCleanumpTests(aUid,aCheckMNotifierManager); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void DoInteractiveTests() sl@0: { sl@0: TInt r; sl@0: sl@0: test.Start(_L("Connect to notifier server")); sl@0: RNotifier n; sl@0: r = n.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Launching simple notifier")); sl@0: _LIT(KLine1,"Line1 - Select Button2"); sl@0: _LIT(KLine2,"Line2 - or press enter"); sl@0: _LIT(KButton1,"Button1"); sl@0: _LIT(KButton2,"Button2"); sl@0: TInt button=-1; sl@0: TRequestStatus stat; sl@0: n.Notify(KLine1,KLine2,KButton1,KButton2,button,stat); sl@0: User::WaitForRequest(stat); sl@0: test(button==1); sl@0: sl@0: test.Next(_L("Close connection to notifier server")); sl@0: n.Close(); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: #include sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: sl@0: test.Start(_L("Test V1 notifier")); sl@0: if(UserSvr::IpcV1Available()) sl@0: DoTests(KUidTestTextNotifier1,EFalse); sl@0: else sl@0: test.Printf(_L("IPC V1 not supported")); sl@0: sl@0: test.Next(_L("Test V2 notifier")); sl@0: DoTests(KUidTestTextNotifier2,EFalse); sl@0: sl@0: test.Next(_L("Test V1 notifier using MNotifierManager")); sl@0: if(UserSvr::IpcV1Available()) sl@0: DoTests(KUidTestTextNotifier1,ETrue); sl@0: else sl@0: test.Printf(_L("IPC V1 not supported")); sl@0: sl@0: test.Next(_L("Test V2 notifier using MNotifierManager")); sl@0: if(UserSvr::IpcV1Available()) sl@0: DoTests(KUidTestTextNotifier2,ETrue); sl@0: else sl@0: test.Printf(_L("FIX ME! - Can't run because IPC V1 not supported\n")); sl@0: sl@0: test.Next(_L("Interactive Tests")); sl@0: test.Printf(_L(" Do you want to test notifiers interactively? y/n\n")); sl@0: test.Printf(_L(" Waiting 10 seconds for answer...\n")); sl@0: TRequestStatus keyStat; sl@0: test.Console()->Read(keyStat); sl@0: RTimer timer; sl@0: test(timer.CreateLocal()==KErrNone); sl@0: TRequestStatus timerStat; sl@0: timer.After(timerStat,10*1000000); sl@0: User::WaitForRequest(timerStat,keyStat); sl@0: TInt key = 0; sl@0: if(keyStat!=KRequestPending) sl@0: key = test.Console()->KeyCode(); sl@0: timer.Cancel(); sl@0: test.Console()->ReadCancel(); sl@0: User::WaitForAnyRequest(); sl@0: if(key=='y' || key=='Y') sl@0: DoInteractiveTests(); sl@0: else sl@0: test.Printf(_L(" Interactive Tests Not Run\n")); sl@0: sl@0: test.End(); sl@0: return(0); sl@0: }