messagingappbase/smsmtm/test/src/T_SmsSendWap.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     1 // Copyright (c) 1999-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 "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 //
       
    15 
       
    16 #include "T_SmsSendWap.h"
       
    17 #include <smsuaddr.h>
       
    18 
       
    19 RTest test(_L("T_SmsSendWap Testrig"));
       
    20 CTrapCleanup* theCleanup;
       
    21 
       
    22 
       
    23 void CSmsSendWapTest::TestSendingL()
       
    24 /**
       
    25 	Tests Sending
       
    26  */
       
    27 	{
       
    28 	DoTestSendingL(iScriptFile);
       
    29 	}
       
    30 
       
    31 void CSmsSendWapTest::TestSchedulingL()
       
    32 /**
       
    33 	Tests schedule sending
       
    34  */
       
    35 	{
       
    36 //	DoTestSchedulingL(KWapScript);
       
    37 	}
       
    38 
       
    39 void CSmsSendWapTest::ConstructL()
       
    40 	{
       
    41 	CSmsSendTestBase::ConstructL();
       
    42 	iSmsTest.SetCommDbServiceCenterFromScriptL(KWapScript);
       
    43 	}
       
    44 
       
    45 
       
    46 CSmsSendWapTest::CSmsSendWapTest(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aCurrentTest)
       
    47 : CSmsSendTestBase(aSmsTest, aScriptFile, aCurrentTest)
       
    48 	{
       
    49 	}
       
    50 
       
    51 LOCAL_C void doMainL()
       
    52 	{
       
    53 	RSocketServ serv;
       
    54 	RSocket socket;
       
    55 
       
    56 	User::LeaveIfError(serv.Connect());
       
    57 	CleanupClosePushL(serv);
       
    58 	
       
    59 	TProtocolDesc protoinfo;
       
    60 	TProtocolName protocolname(KSmsDatagram);
       
    61 	User::LeaveIfError(serv.FindProtocol(protocolname,protoinfo));
       
    62 	User::LeaveIfError(socket.Open(serv,protoinfo.iAddrFamily,protoinfo.iSockType,protoinfo.iProtocol));
       
    63 
       
    64 	TSmsAddr smsaddr;
       
    65 	smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly);
       
    66 	User::LeaveIfError(socket.Bind(smsaddr));
       
    67 
       
    68 	CleanupClosePushL(socket);
       
    69 	
       
    70 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
    71 	CleanupStack::PushL(scheduler);
       
    72 	CActiveScheduler::Install( scheduler );
       
    73 
       
    74 	CSmsTestUtils* smsTest = CSmsTestUtils::NewL(test);
       
    75 	CleanupStack::PushL(smsTest);
       
    76 	TInt nextTest = 0;
       
    77 
       
    78 	smsTest->NotifySaPhoneOnL();
       
    79 	smsTest->WaitForInitializeL();
       
    80 
       
    81 	CSmsSendWapTest* wapTest = CSmsSendWapTest::NewL(*smsTest, KWapScript, nextTest);
       
    82 	CleanupStack::PushL(wapTest);
       
    83 
       
    84 	wapTest->StartL();
       
    85 
       
    86 	CleanupStack::PopAndDestroy(3); //SmsTest, scheduler, wapTest
       
    87 	
       
    88 	CleanupStack::PopAndDestroy(&socket);
       
    89 	CleanupStack::PopAndDestroy(&serv);
       
    90 	}
       
    91 
       
    92 GLDEF_C TInt E32Main()
       
    93 	{	
       
    94 	__UHEAP_MARK;
       
    95 	test.Start(_L("Setup"));
       
    96 	theCleanup = CTrapCleanup::New();
       
    97 	TRAPD(ret,doMainL());		
       
    98 	test(ret==KErrNone);
       
    99 	delete theCleanup;	
       
   100 	test.Console()->SetPos(0, 13);
       
   101 	test.End();
       
   102 	test.Close();
       
   103 	__UHEAP_MARKEND;
       
   104 	return(KErrNone);
       
   105 	}
       
   106 
       
   107 CSmsSendWapTest* CSmsSendWapTest::NewL(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aCurrentTest)
       
   108 	{
       
   109 	CSmsSendWapTest* self = new (ELeave) CSmsSendWapTest(aSmsTest, aScriptFile, aCurrentTest);
       
   110 	CleanupStack::PushL(self);
       
   111 
       
   112 	self->ConstructL();
       
   113 
       
   114 	CleanupStack::Pop();
       
   115 	return self;
       
   116 	}
       
   117 
       
   118 void CSmsSendWapTest::DoRunSendingL()
       
   119 /**
       
   120 	Checks status. 
       
   121 	The message is rescheduled if sending failed.
       
   122  */
       
   123 	{
       
   124 	if (iStatus == KErrNone)
       
   125 		iStatus = iSmsTest.iProgress.iError;
       
   126 
       
   127 	iSmsTest.Printf(_L("WAP sending completed with error %d\n"), iStatus.Int());
       
   128 
       
   129 	iState = EStateWaiting;
       
   130 	TInt err = KErrNone;
       
   131 
       
   132 	if (!iSmsTest.SendingCompleteL(*iSelection, err))
       
   133 		{
       
   134 		iSmsTest.Printf(_L("Waiting for all messages to send or fail\n"), iStatus);
       
   135 		iStatus = KRequestPending;
       
   136 		SetActive();
       
   137 		iState = EStateSchedulingThenSend;
       
   138 		}
       
   139 	else
       
   140 		{
       
   141 		CActiveScheduler::Stop();
       
   142 
       
   143 		iStatus = err;
       
   144 		iSmsTest.Printf(_L("Sending completed with error %d\n"), iStatus);
       
   145 
       
   146 		if (iStatus == KErrNone)
       
   147 			{
       
   148 			TTimeIntervalMicroSeconds32 wait = KWaitForMsgToSend.Int() * iSelection->Count();
       
   149 			iSmsTest.Printf(_L("Waiting %d seconds for sending to complete\nGo have a cup of tea. You deserve a break!\n"), wait.Int() / 1000000);
       
   150 			User::After(wait);
       
   151 			}
       
   152 
       
   153 		if (!iSmsTest.RunAuto())
       
   154 			{
       
   155 			iSmsTest.Test().Printf(_L("\nPress any key to continue...\n"));
       
   156 			iSmsTest.Test().Getch();
       
   157 			}
       
   158 		}
       
   159 	}
       
   160