|
1 // Copyright (c) 2004-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 // __ACTION_INFO_BEGIN__ |
|
15 // [Action Name] |
|
16 // CreateSmsMessage |
|
17 // [Action Parameters] |
|
18 // Session <input>: Reference to the session. |
|
19 // ParentId <input>: Value of the parent id. |
|
20 // ServiceId <input>: Value of the the service id. |
|
21 // (ConfigIndexHeader) <input>: Value of config index for SMS header settings. Default is 0. |
|
22 // MessageId <output>: Value of the created message id. |
|
23 // [Action Description] |
|
24 // Creates a message on the specified parent. |
|
25 // [APIs Used] |
|
26 // TMsvEntry::iMtm |
|
27 // TMsvEntry::iServiceId |
|
28 // TMsvEntry::iDate |
|
29 // TMsvEntry::Id |
|
30 // CMsvEntry::SetEntryL |
|
31 // CMsvEntry::CreateL |
|
32 // CSmsHeader::NewL |
|
33 // CSmsHeader::StoreL |
|
34 // __ACTION_INFO_END__ |
|
35 // |
|
36 // |
|
37 |
|
38 // |
|
39 #include "CMtfTestActionCreateSmsMessage.h" |
|
40 #include "CMtfTestCase.h" |
|
41 #include "CMtfTestActionParameters.h" |
|
42 #include "CMtfTestActionUtilsConfigFileParser.h" |
|
43 #include <msvapi.h> |
|
44 #include <msvuids.h> |
|
45 #include <txtrich.h> |
|
46 #include <smuthdr.h> |
|
47 |
|
48 |
|
49 _LIT(KSentToAddress, "SentToAddress"); |
|
50 _LIT(KBodyText, "BodyText"); |
|
51 |
|
52 CMtfTestAction* CMtfTestActionCreateSmsMessage::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
53 { |
|
54 CMtfTestActionCreateSmsMessage* self = new (ELeave) CMtfTestActionCreateSmsMessage(aTestCase); |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(aActionParameters); |
|
57 CleanupStack::Pop(self); |
|
58 return self; |
|
59 } |
|
60 |
|
61 |
|
62 CMtfTestActionCreateSmsMessage::CMtfTestActionCreateSmsMessage(CMtfTestCase& aTestCase) |
|
63 : CMtfSynchronousTestAction(aTestCase) |
|
64 { |
|
65 } |
|
66 |
|
67 void CMtfTestActionCreateSmsMessage::ExecuteActionL() |
|
68 { |
|
69 TestCase().Logger().Write(_L("CMtfTestActionCreateSmsMessage::ExecuteActionL IN")); |
|
70 TInt paramCount = ActionParameters().Count(); |
|
71 if( paramCount != 5) |
|
72 { |
|
73 User::Leave(KErrArgument); |
|
74 } |
|
75 |
|
76 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
77 TMsvId paramParentId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
78 TMsvId paramServiceId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(2)); |
|
79 |
|
80 |
|
81 TMsvEntry indexEntry; |
|
82 indexEntry.iType = KUidMsvMessageEntry; |
|
83 indexEntry.iMtm = KUidMsgTypeSMS; |
|
84 indexEntry.iServiceId = paramServiceId; |
|
85 indexEntry.SetVisible(ETrue); |
|
86 // indexEntry.iDate.HomeTime(); |
|
87 indexEntry.iDate.UniversalTime(); |
|
88 indexEntry.SetSendingState(KMsvSendStateWaiting); |
|
89 CMsvEntry* entry = paramSession->GetEntryL(paramParentId); |
|
90 CleanupStack::PushL(entry); |
|
91 entry->CreateL(indexEntry); |
|
92 TMsvId paramMessageId = indexEntry.Id(); |
|
93 paramSession->CleanupEntryPushL(paramMessageId); |
|
94 entry->SetEntryL(paramMessageId); |
|
95 |
|
96 InitializeHeaderFromConfigL(entry); |
|
97 |
|
98 paramSession->CleanupEntryPop(); |
|
99 CleanupStack::PopAndDestroy(entry); |
|
100 |
|
101 StoreParameterL<TMsvId>(TestCase(),paramMessageId,ActionParameters().Parameter(4)); |
|
102 |
|
103 TestCase().Logger().Write(_L("CMtfTestActionCreateSmsMessage::ExecuteActionL OUT")); |
|
104 TestCase().ActionCompletedL(*this); |
|
105 } |
|
106 |
|
107 |
|
108 void CMtfTestActionCreateSmsMessage::InitializeHeaderFromConfigL(CMsvEntry* aEntry) |
|
109 { |
|
110 TInt paramConfigIndexHeader = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(3),0); |
|
111 TPtrC smsMessageFileName = TestCase().GetConfigurationFileL(CMtfConfigurationType::EMtfSmsMessage,paramConfigIndexHeader); |
|
112 CMtfTestActionUtilsConfigFileParser* configParser = CMtfTestActionUtilsConfigFileParser::NewL(smsMessageFileName); |
|
113 CleanupStack::PushL(configParser); |
|
114 |
|
115 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
116 CleanupStack::PushL(paraFormatLayer); |
|
117 |
|
118 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
119 CleanupStack::PushL(charFormatLayer); |
|
120 |
|
121 CRichText* richText = CRichText::NewL(paraFormatLayer,charFormatLayer); |
|
122 CleanupStack::PushL(richText); |
|
123 |
|
124 CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *richText); |
|
125 CleanupStack::PushL(header); |
|
126 |
|
127 CMsvStore* store = aEntry->EditStoreL(); |
|
128 CleanupStack::PushL(store); |
|
129 |
|
130 TPtrC toAddress; |
|
131 if(configParser->GetFieldAsString(KSentToAddress,toAddress) != KErrNotFound) |
|
132 { |
|
133 CArrayPtrFlat<CSmsNumber>& recipientList = header->Recipients(); |
|
134 CSmsNumber* recipient = CSmsNumber::NewL(); |
|
135 CleanupStack::PushL(recipient); |
|
136 recipient->SetAddressL(toAddress); |
|
137 CleanupStack::Pop(recipient); |
|
138 recipientList.AppendL(recipient); |
|
139 } |
|
140 TestCase().Logger().WriteFormat(_L("CMtfTestActionCreateSmsMessage:: recipient: %S"), &toAddress); |
|
141 |
|
142 TPtrC bodyText; |
|
143 if(configParser->GetFieldAsString(KBodyText, bodyText) != KErrNotFound) |
|
144 { |
|
145 richText->InsertL(0, bodyText); |
|
146 } |
|
147 TestCase().Logger().WriteFormat(_L("CMtfTestActionCreateSmsMessage:: body text: %S"), &bodyText); |
|
148 |
|
149 header->StoreL(*store); |
|
150 store->StoreBodyTextL(*richText); |
|
151 store->CommitL(); |
|
152 |
|
153 CleanupStack::PopAndDestroy(6, configParser); |
|
154 } |
|
155 |