telephonyserverplugins/simtsy/test/Te_SimSms/Te_SimSmsTestStepBase.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2005-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 "Te_SimSmsTestStepBase.h"
       
    17 #include "Te_SimSmsUtil.h"
       
    18 
       
    19 TVerdict CSimSmsTestStepBase::doTestStepPreambleL()
       
    20 	{
       
    21 	__UHEAP_MARK;
       
    22 
       
    23 	TInt ret = RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, 0);
       
    24 	if (ret != KErrNone)
       
    25 		{
       
    26 		INFO_PRINTF1(_L("Failed resetting"));
       
    27 		User::Leave(ret);
       
    28 		}
       
    29 
       
    30 	iTestScheduler=new (ELeave) CActiveScheduler;
       
    31 	CActiveScheduler::Install(iTestScheduler);	
       
    32 
       
    33 	ret = iTelServer.Connect();
       
    34 	if (ret!=KErrNone)
       
    35 		{
       
    36 		INFO_PRINTF1(_L("Failed to connect to telephony server"));
       
    37 		delete iTestScheduler;
       
    38 		User::Leave(ret);
       
    39 		}
       
    40    	ret=iTelServer.LoadPhoneModule(KSimtsyName);
       
    41 	if (ret!=KErrNone)
       
    42 		{
       
    43 		INFO_PRINTF1(_L("Failed to load phone module"));
       
    44 		iTelServer.Close();
       
    45 		delete iTestScheduler;
       
    46 		User::Leave(ret);
       
    47 		}
       
    48 
       
    49 	ret=iPhone.Open(iTelServer,KPhoneName) ;
       
    50 	if (ret!=KErrNone)
       
    51 		{
       
    52 		INFO_PRINTF1(_L("Failed to open phone module"));
       
    53 		iTelServer.UnloadPhoneModule(KSimtsyName);
       
    54 		iTelServer.Close();
       
    55 		delete iTestScheduler;
       
    56 		User::Leave(ret);
       
    57 		}
       
    58 	ret=iPhone.Initialise();
       
    59 	if (ret!=KErrNone)
       
    60 		{
       
    61 		INFO_PRINTF1(_L("Failed to initialise the phone"));
       
    62 		iPhone.Close();
       
    63 		iTelServer.UnloadPhoneModule(KSimtsyName);
       
    64 		iTelServer.Close();
       
    65 		delete iTestScheduler;
       
    66 		User::Leave(ret);
       
    67 		}
       
    68 
       
    69 	ret=iSms.Open(iPhone);
       
    70 	if (ret!=KErrNone)
       
    71 		{
       
    72 		INFO_PRINTF1(_L("Cannot open Sms"));
       
    73 		iPhone.Close();
       
    74 		iTelServer.UnloadPhoneModule(KSimtsyName);
       
    75 		iTelServer.Close();
       
    76 		delete iTestScheduler;
       
    77 		User::Leave(ret);
       
    78 		}
       
    79 
       
    80 	return TestStepResult();
       
    81 	}
       
    82 
       
    83 TVerdict CSimSmsTestStepBase::doTestStepPostambleL()
       
    84 	{
       
    85 	iSms.Close();
       
    86 	iPhone.Close();
       
    87 	iTelServer.UnloadPhoneModule(KSimtsyName);
       
    88 	iTelServer.Close();
       
    89 	delete iTestScheduler;
       
    90 
       
    91 	__UHEAP_MARKEND;
       
    92 	return TestStepResult();
       
    93 	}
       
    94 
       
    95 void CSimSmsTestStepBase::PrintMessageStoreCaps(TUint32 aCaps)
       
    96 	{
       
    97 	if(aCaps & RMobilePhoneStore::KCapsReadAccess)
       
    98 	{
       
    99 		INFO_PRINTF1(_L("Store supports read access"));
       
   100 	}
       
   101 	if(aCaps & RMobilePhoneStore::KCapsWriteAccess)
       
   102 	{
       
   103 		INFO_PRINTF1(_L("Store supports write/delete access"));
       
   104 	}
       
   105 	if(aCaps & RMobilePhoneStore::KCapsDeleteAll)
       
   106 	{
       
   107 		INFO_PRINTF1(_L("Store supports deleting all entries at once"));
       
   108 	}
       
   109 	if(aCaps & RMobilePhoneStore::KCapsNotifyEvent)
       
   110 	{
       
   111 		INFO_PRINTF1(_L("Store supports event notification"));
       
   112 	}
       
   113 	if(aCaps & static_cast<TUint32>(RMobilePhoneStore::KCapsWholeStore))
       
   114 	{
       
   115 		INFO_PRINTF1(_L("Store supports reading whole store in a list"));
       
   116 	}
       
   117 	if(aCaps & RMobilePhoneStore::KCapsIndividualEntry)
       
   118 	{
       
   119 		INFO_PRINTF1(_L("Store supports reading entries one at a time"));
       
   120 	}
       
   121 	if(aCaps & RMobileSmsStore::KCapsUnreadMessages)
       
   122 	{
       
   123 		INFO_PRINTF1(_L("Store contains unread messages"));
       
   124 	}
       
   125 	if(aCaps & RMobileSmsStore::KCapsReadMessages)
       
   126 	{
       
   127 		INFO_PRINTF1(_L("Store contains read messages"));
       
   128 	}
       
   129 	if(aCaps & RMobileSmsStore::KCapsSentMessages)
       
   130 	{
       
   131 		INFO_PRINTF1(_L("Store contains sent messages"));
       
   132 	}
       
   133 	if(aCaps & RMobileSmsStore::KCapsUnsentMessages)
       
   134 	{
       
   135 		INFO_PRINTF1(_L("Store contains unsent messages"));
       
   136 	}
       
   137 	if(aCaps & RMobileSmsStore::KCapsGsmMessages)
       
   138 	{
       
   139 		INFO_PRINTF1(_L("Store contains GSM format messages"));
       
   140 	}
       
   141 	if(aCaps & RMobileSmsStore::KCapsCdmaMessages)
       
   142 	{
       
   143 		INFO_PRINTF1(_L("Store contains CDMA format messages"));
       
   144 	}
       
   145 }
       
   146 
       
   147 TVerdict CSimSmsTestStepBase::SendSms()
       
   148 {
       
   149 	INFO_PRINTF1(_L("Sending SMS."));
       
   150 
       
   151 	// Create message PDU and convert to binary 
       
   152 	TBuf8<400> msgData;
       
   153 	TLex8 lex;
       
   154 	TUint8 val;
       
   155 	TInt i;
       
   156 
       
   157 	TInt ret;
       
   158 	msgData.Zero();
       
   159 
       
   160 	const TInt count_before((&KMsgDataBeforeTargetAddress)->Length()/2);	// Assume length of pdu is always even
       
   161 	for(i=0;i<count_before;++i)
       
   162 		{
       
   163 		lex=(&KMsgDataBeforeTargetAddress)->Mid(i*2,2);
       
   164 		ret = lex.Val(val,EHex);					
       
   165 
       
   166 		if(ret) return EFail;
       
   167 		msgData.Append(TChar(val));
       
   168 		}
       
   169 
       
   170 	TBuf8<20> targetAddressAscii;
       
   171 	targetAddressAscii.Zero();
       
   172 	RMobilePhone::TMobileAddress targetAddress;
       
   173 	targetAddress.iTypeOfNumber=RMobilePhone::EInternationalNumber;
       
   174 	targetAddress.iNumberPlan=RMobilePhone::EIsdnNumberPlan;
       
   175 	targetAddress.iTelNumber.Copy(iTelNumber);
       
   176 	ret = CATSmsUtils::AppendAddressToAscii(targetAddressAscii,targetAddress);
       
   177 
       
   178 	if(ret) return EFail;
       
   179 
       
   180 	const TInt count_address(targetAddressAscii.Length()/2);	// Assume length is always even
       
   181 	for(i=0;i<count_address;++i)
       
   182 		{
       
   183 		lex=targetAddressAscii.Mid(i*2,2);
       
   184 		ret = lex.Val(val,EHex);					
       
   185 
       
   186 		if(ret) return EFail;
       
   187 		msgData.Append(TChar(val));
       
   188 		}
       
   189 
       
   190 	const TInt count_after((&KMsgDataAfterTargetAddress)->Length()/2);	// Assume length of pdu is always even
       
   191 	for(i=0;i<count_after;++i)
       
   192 		{
       
   193 		lex=(&KMsgDataAfterTargetAddress)->Mid(i*2,2);
       
   194 		ret = lex.Val(val,EHex);
       
   195 
       
   196 		if(ret) return EFail;
       
   197 		msgData.Append(TChar(val));
       
   198 		}
       
   199 
       
   200 	// Create message attibutes 
       
   201 	RMobileSmsMessaging::TMobileSmsSendAttributesV1	msgAttr;
       
   202 		
       
   203 	msgAttr.iFlags=0x184;
       
   204 	msgAttr.iDataFormat=RMobileSmsMessaging::EFormatGsmTpdu;
       
   205 	msgAttr.iGsmServiceCentre.iTypeOfNumber=RMobilePhone::EInternationalNumber;
       
   206 	msgAttr.iGsmServiceCentre.iNumberPlan=RMobilePhone::EIsdnNumberPlan;
       
   207 	msgAttr.iGsmServiceCentre.iTelNumber.Copy(iSCANumber);
       
   208 
       
   209 	// Package up data ready for sending to etel
       
   210 	RMobileSmsMessaging::TMobileSmsSendAttributesV1Pckg msgAttrPkg(msgAttr);
       
   211 
       
   212 	// Send the message, try upto 3 times if phone is not ready
       
   213 	TRequestStatus status;
       
   214 	INFO_PRINTF1(_L(".."));
       
   215 	TSmsPdu smsPduSent;
       
   216 
       
   217 	smsPduSent.Copy(KTestSendPduA,sizeof(KTestSendPduA));
       
   218 
       
   219 	iSms.SendMessage(status,smsPduSent,msgAttrPkg);
       
   220 	User::WaitForRequest(status);
       
   221 	if(status==KErrGsmSMSFailureInME || status==KErrGeneral || status==KErrGsmSMSUnknownError)
       
   222 		{
       
   223 		INFO_PRINTF1(_L(".."));
       
   224 		iSms.SendMessage(status,smsPduSent,msgAttrPkg);
       
   225 		User::WaitForRequest(status);
       
   226 		if(status==KErrGsmSMSFailureInME || status==KErrGeneral || status==KErrGsmSMSUnknownError)
       
   227 			{
       
   228 			INFO_PRINTF1(_L(".."));
       
   229 			iSms.SendMessage(status,smsPduSent,msgAttrPkg);
       
   230 			User::WaitForRequest(status);
       
   231 			}
       
   232 		}	
       
   233 	
       
   234 	ret = status.Int();
       
   235 
       
   236 	if(ret) return EFail;
       
   237 
       
   238 	// Validate message reference number has changed 
       
   239 	if(!(msgAttr.iFlags&RMobileSmsMessaging::KMessageReference))
       
   240 		return(EFail);
       
   241 
       
   242 	INFO_PRINTF1(_L("TESTS passed"));
       
   243 	return TestStepResult(); 
       
   244 }