phoneclientserver/phoneclient/tsrc/public/basic/ut_ussd/etel_mock.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     1 
       
     2 
       
     3 #include "ut_testenv.h"
       
     4 #include <etel.h>
       
     5 #include <etelmm.h>
       
     6 #include <etelmmcs.h>
       
     7 #include <QTest>
       
     8 
       
     9 
       
    10 // global variables
       
    11 CPeriodic* messageResponseTimer = 0;
       
    12 
       
    13 // ==============================================================================
       
    14 // RMobileUssdMessaging
       
    15 // ==============================================================================
       
    16 
       
    17 RMobileUssdMessaging::RMobileUssdMessaging()
       
    18 {
       
    19 }
       
    20 
       
    21 RMobileUssdMessaging::RMobileUssdMessaging(const RMobileUssdMessaging&)
       
    22 {
       
    23 }
       
    24 
       
    25 void RMobileUssdMessaging::ConstructL()
       
    26 {
       
    27 	QVERIFY(!messageResponseTimer);
       
    28     messageResponseTimer =
       
    29 		CPeriodic::NewL(CActive::EPriorityStandard+1);
       
    30 }
       
    31 
       
    32 TInt RMobileUssdMessaging::Open(RMobilePhone& /*aPhone*/)
       
    33 {
       
    34 	TRAPD(err,ConstructL());
       
    35     return err;
       
    36 }
       
    37 
       
    38 void RMobileUssdMessaging::Close()
       
    39 {
       
    40 	delete messageResponseTimer;
       
    41 	messageResponseTimer = 0;
       
    42 }
       
    43 
       
    44 void RMobileUssdMessaging::Destruct()
       
    45 {
       
    46 }
       
    47 
       
    48 TInt RMobileUssdMessaging::GetCaps(TDes8& aCaps) const
       
    49 {
       
    50     TMobileUssdCapsV1 caps;
       
    51     caps.iUssdFormat = KCapsPackedString;
       
    52     caps.iUssdTypes = KCapsMTUssd | KCapsMOUssd;
       
    53     TMobileUssdCapsV1Pckg pckgCaps( caps );
       
    54     aCaps.Copy( pckgCaps );
       
    55     return KErrNone;
       
    56 }
       
    57 
       
    58 void RMobileUssdMessaging::ReceiveMessage(
       
    59     TRequestStatus& aReqStatus, TDes8& aMsgData,
       
    60     TDes8& aMsgAttributes) const
       
    61 {
       
    62 	EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
    63     QVERIFY2(!loop.mReceiveMessageReqStatus,
       
    64     		"etel_mock: ReceiveMessage called twice!");
       
    65     aReqStatus = KRequestPending;
       
    66     loop.mReceiveMessageReqStatus = &aReqStatus;
       
    67 	loop.mReceiveMessageData = &aMsgData;
       
    68 	loop.mReceiveMessageAttributes = &aMsgAttributes;
       
    69 }
       
    70 
       
    71 TInt SendMessageCallback(TAny* /*aPtr*/)
       
    72 	{
       
    73 	messageResponseTimer->Cancel();
       
    74 
       
    75 	EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
    76     const TestMode& mode = TestEnv::env().testMode();
       
    77     if (mode.m_event == TestMode::Normal)
       
    78     	{
       
    79     	User::RequestComplete(loop.mSendMessageReqStatus, mode.m_error);
       
    80     	}
       
    81     return 0;
       
    82 	}
       
    83 
       
    84 void RMobileUssdMessaging::SendMessage(
       
    85     TRequestStatus& aReqStatus, const TDesC8& /*aMsgData*/,
       
    86     const TDesC8& /*aMsgAttributes*/) const
       
    87 {
       
    88 	EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
    89     QVERIFY2(!loop.mSendMessageReqStatus,
       
    90     		"etel_mock: SendMessage called twice!");
       
    91     aReqStatus = KRequestPending;
       
    92     loop.mSendMessageReqStatus = &aReqStatus;
       
    93 
       
    94     const TestMode& mode = TestEnv::env().testMode();
       
    95     if (mode.m_event != TestMode::NoResp)
       
    96     	{
       
    97 		// start timer to respond
       
    98 		TTimeIntervalMicroSeconds32 delay(
       
    99 				1000*mode.m_timeout);
       
   100 		messageResponseTimer->Start(delay,delay,
       
   101 				TCallBack(SendMessageCallback,(TAny*)this));
       
   102     	}
       
   103 }
       
   104 
       
   105 void RMobileUssdMessaging::SendMessageNoFdnCheck(
       
   106     TRequestStatus& /*aReqStatus*/, const TDesC8& /*aMsgData*/,
       
   107     const TDesC8& /*aMsgAttributes*/) const
       
   108 {
       
   109 	// not used
       
   110 }
       
   111 
       
   112 void RMobileUssdMessaging::SendRelease(
       
   113     TRequestStatus& /*aReqStatus*/, TDes8& /*aReturnResult*/) const
       
   114 {
       
   115 	// not used
       
   116 }
       
   117 
       
   118 void RMobileUssdMessaging::NotifyNetworkRelease(
       
   119     TRequestStatus& aReqStatus, TDes8& aReturnResult) const
       
   120 {
       
   121 	EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
   122     QVERIFY2(!loop.mNetworkReleaseReqStatus,
       
   123     		"etel_mock: NotifyNetworkRelease called twice!");
       
   124     aReqStatus = KRequestPending;
       
   125     loop.mNetworkReleaseReqStatus = &aReqStatus;
       
   126 	loop.mNetworkReleaseMessageData = &aReturnResult;
       
   127 	loop.mNetworkReleaseMessageAttributes = 0;
       
   128 }
       
   129 
       
   130 void RMobileUssdMessaging::NotifyNetworkRelease(
       
   131     TRequestStatus& aReqStatus, TDes8& aMsgData,
       
   132     TDes8& aMsgAttributes) const
       
   133 {
       
   134 	EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
   135     QVERIFY2(!loop.mNetworkReleaseReqStatus,
       
   136     		"etel_mock: NotifyNetworkRelease called twice!");
       
   137     aReqStatus = KRequestPending;
       
   138     loop.mNetworkReleaseReqStatus = &aReqStatus;
       
   139 	loop.mNetworkReleaseMessageData = &aMsgData;
       
   140 	loop.mNetworkReleaseMessageAttributes = &aMsgAttributes;
       
   141 }
       
   142 
       
   143 
       
   144 RMobileUssdMessaging::TMobileUssdAttributesV1::TMobileUssdAttributesV1()
       
   145 {
       
   146     iFlags = 0;
       
   147     iFormat = EFormatUnspecified;
       
   148     iType = EUssdUnknown;
       
   149     iDcs = 0;
       
   150 }
       
   151 
       
   152 RMobileUssdMessaging::TMobileUssdCapsV1::TMobileUssdCapsV1()
       
   153 {
       
   154     iUssdFormat = 0;
       
   155     iUssdTypes = 0;
       
   156 }
       
   157 
       
   158 // ==============================================================================
       
   159 // RMobilePhone
       
   160 // ==============================================================================
       
   161 
       
   162 RMobilePhone::TMobilePhoneSendSSRequestV3::TMobilePhoneSendSSRequestV3()
       
   163 {
       
   164     iOpCode = 0;
       
   165 }
       
   166 
       
   167 RMobilePhone::TMultimodeType::TMultimodeType()
       
   168 {
       
   169     iExtensionId = 0;
       
   170 }
       
   171 
       
   172 // ==============================================================================
       
   173 // RTelSubSessionBase
       
   174 // ==============================================================================
       
   175 
       
   176 RTelSubSessionBase::RTelSubSessionBase()
       
   177 {
       
   178 }
       
   179 
       
   180 void RTelSubSessionBase::CancelAsyncRequest(TInt aReqToCancel) const
       
   181 {
       
   182 	if ( aReqToCancel == EMobileUssdMessagingSendMessage )
       
   183 	{
       
   184 		EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
   185 		if ( loop.mSendMessageReqStatus )
       
   186 		{
       
   187 		User::RequestComplete( loop.mSendMessageReqStatus, KErrCancel );
       
   188 		}
       
   189 	}
       
   190 	else if ( aReqToCancel == EMobileUssdMessagingReceiveMessage )
       
   191 	{
       
   192 		EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
   193 		if ( loop.mReceiveMessageReqStatus )
       
   194     	{
       
   195         User::RequestComplete( loop.mReceiveMessageReqStatus, KErrCancel );
       
   196     	}
       
   197 	}
       
   198 	else if ( aReqToCancel == EMobileUssdMessagingNotifyNetworkRelease )
       
   199 	{
       
   200 		EtelMsgLoop& loop = TestEnv::env().etelMsgLoop();
       
   201 		if ( loop.mNetworkReleaseReqStatus )
       
   202     	{
       
   203         User::RequestComplete( loop.mNetworkReleaseReqStatus, KErrCancel );
       
   204     	}
       
   205 	}
       
   206 	else if ( aReqToCancel == EMobileUssdMessagingSendRelease )
       
   207 	{
       
   208 	// not used
       
   209 	}
       
   210 }
       
   211