serviceproviders/sapi_messaging/tsrc/dev/tmessagingtest/tmsg_sendmessageiter1/src/sendmessage7.cpp
changeset 19 989d2f495d90
child 33 50974a8b132e
equal deleted inserted replaced
14:a36b1e19a461 19:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18  
       
    19 // STLport regression testsuite component.
       
    20 // To compile as a separate example, please #define MAIN.
       
    21 
       
    22 #include<e32base.h>
       
    23 
       
    24 #include "messagingservice.h"
       
    25 #include "sendmessage.h"
       
    26 #include<CMsvAttachment.h>
       
    27 
       
    28 #ifdef MAIN
       
    29 #define sendmessage_test7 main
       
    30 #endif
       
    31 
       
    32 
       
    33 class CTestAsync7: public CActive, public CMsgCallbackBase
       
    34 {
       
    35 public:
       
    36 	static CTestAsync7* NewL();
       
    37 	~CTestAsync7();
       
    38 	void Start();
       
    39 	TInt Result();
       
    40 	
       
    41 private:
       
    42 	void ConstructL();
       
    43 	CTestAsync7();
       
    44 	
       
    45 	virtual void DoCancel();
       
    46 	virtual void RunL();
       
    47 	
       
    48 	
       
    49 	void TestFunc();
       
    50 	void NotifyResultL(TInt aErrCode, TAny* aResult);
       
    51 
       
    52 	
       
    53 	
       
    54 private:	
       
    55 	CActiveSchedulerWait* 	iWaitSchedular;
       
    56 	CMessagingService*		iMessagingService;
       
    57 	TInt 					iResult;	
       
    58 };
       
    59 
       
    60 CTestAsync7* CTestAsync7::NewL()
       
    61 	{
       
    62 	CTestAsync7* self = new(ELeave)CTestAsync7();
       
    63 	self->ConstructL();
       
    64 	return self;
       
    65 	}
       
    66 
       
    67 CTestAsync7::~CTestAsync7()
       
    68 	{
       
    69 	Cancel();
       
    70 	
       
    71 	if(iWaitSchedular->IsStarted())
       
    72 		iWaitSchedular->AsyncStop();
       
    73 	
       
    74 	if(iMessagingService)
       
    75 		delete iMessagingService;
       
    76 	
       
    77 	if(iWaitSchedular)
       
    78 		delete iWaitSchedular;
       
    79 	}
       
    80 
       
    81 void CTestAsync7::ConstructL()
       
    82 	{
       
    83 	CActiveScheduler::Add(this);
       
    84 	iMessagingService = CMessagingService::NewL();
       
    85 	iWaitSchedular = new(ELeave) CActiveSchedulerWait();
       
    86 	}
       
    87 
       
    88 CTestAsync7::CTestAsync7() :
       
    89 CActive(EPriorityStandard)
       
    90 	{
       
    91 	}
       
    92 
       
    93 void CTestAsync7::DoCancel()
       
    94 	{
       
    95 		
       
    96 	}
       
    97 
       
    98 void CTestAsync7::RunL()
       
    99 	{
       
   100 	TestFunc();
       
   101 	}
       
   102 
       
   103 void CTestAsync7::Start()
       
   104 	{
       
   105 	SetActive();
       
   106 	TRequestStatus* temp = &iStatus;
       
   107 	User::RequestComplete(temp, KErrNone);
       
   108 	iWaitSchedular->Start();	
       
   109 	}
       
   110 
       
   111 void CTestAsync7::NotifyResultL(TInt aErrCode, TAny* aResult)
       
   112 	{
       
   113 	//******************* set iResult ****************************
       
   114 	iResult = aErrCode;
       
   115 	//******************* set iResult ****************************
       
   116 	
       
   117 	iWaitSchedular->AsyncStop();
       
   118 	}
       
   119 TInt CTestAsync7::Result()
       
   120 	{
       
   121 	return iResult;
       
   122 	}
       
   123 
       
   124 void CTestAsync7::TestFunc()
       
   125 	{
       
   126  
       
   127 	CSendMessageParams* messageParam = CSendMessageParams::NewL();
       
   128 	CleanupStack::PushL(messageParam);
       
   129 	
       
   130 	messageParam->AddRecipientL(_L("9008032761"));
       
   131 	messageParam->SetMessageTypeL(_L("SMS"));
       
   132 	messageParam->SetLaunchEditor();
       
   133 	messageParam->SetBodyTextL(_L("Hi How are you!!! Its the first sms from imessaging"));
       
   134 	
       
   135 	TRAPD(errcode, iMessagingService->SendMessageL(messageParam, this));
       
   136 	CleanupStack::PopAndDestroy(messageParam);
       
   137 
       
   138  	}
       
   139 
       
   140 
       
   141 int sendmessage_test7(int, char**)
       
   142 	{
       
   143 	__UHEAP_MARK;
       
   144 	CTestAsync7* test = CTestAsync7::NewL();
       
   145 	test->Start();
       
   146 	__UHEAP_MARKEND;
       
   147 
       
   148 	return KErrNone;
       
   149 	}
       
   150 
       
   151