|
1 // Copyright (c) 2003-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 // CreateSmsMessageFromFile |
|
17 // [Action Parameters] |
|
18 // CMsvSession SessionId <input>: Reference to the session |
|
19 // TMsvId ServiceId <input>: Value of the SMS service id |
|
20 // TMsvId FolderId <input>: Id of Folder path where the message is to be created |
|
21 // TInt FileIndex <input>: Value of index for SMS data file. Default is 0 |
|
22 // CMsvEntrySelection IdSelection <output-initiation>: ID of the created Sms Message |
|
23 // TMsvID SmsMessageId <output-initiation>: ID of the created Sms Message |
|
24 // [Action Description] |
|
25 // Reads the information required for creating SMS message from the Sms Data File, |
|
26 // creates a SMS message and stores it in the folder FolderId which is provided as input |
|
27 // to the test action. |
|
28 // The test action currently supports creation of one message using the data file. Future |
|
29 // enhancements will be done to support creation of multiple Sms messages from the data file. |
|
30 // Currently, only one recipient address is supported while creating the SMS. Further enhancements |
|
31 // will support multiple recipient addresses. |
|
32 // [APIs Used] |
|
33 // __ACTION_INFO_END__ |
|
34 // |
|
35 // |
|
36 |
|
37 /** |
|
38 @file |
|
39 */ |
|
40 |
|
41 |
|
42 #include <msvapi.h> |
|
43 #include <gsmuelem.h> |
|
44 #include <smuthdr.h> |
|
45 #include <smutset.h> |
|
46 #include <e32def.h> |
|
47 #include <e32std.h> |
|
48 #include <msvuids.h> |
|
49 #include <txtfmlyr.h> |
|
50 #include <txtrich.h> |
|
51 |
|
52 #include <csmsaccount.h> |
|
53 |
|
54 #include "CMtfTestActionCreateSmsMessageFromFile.h" |
|
55 #include "CMtfTestCase.h" |
|
56 #include "CMtfTestActionParameters.h" |
|
57 #include "TestFrameworkActionsUtils.h" |
|
58 #include "CMtfTestActionUtilsSmsScripts.h" |
|
59 |
|
60 |
|
61 |
|
62 CMtfTestAction* CMtfTestActionCreateSmsMessageFromFile::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
63 { |
|
64 CMtfTestActionCreateSmsMessageFromFile* self = new (ELeave) CMtfTestActionCreateSmsMessageFromFile(aTestCase); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(aActionParameters); |
|
67 CleanupStack::Pop(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 CMtfTestActionCreateSmsMessageFromFile::CMtfTestActionCreateSmsMessageFromFile(CMtfTestCase& aTestCase) |
|
73 :CMtfSynchronousTestAction(aTestCase) |
|
74 { |
|
75 } |
|
76 |
|
77 |
|
78 CMtfTestActionCreateSmsMessageFromFile::~CMtfTestActionCreateSmsMessageFromFile() |
|
79 { |
|
80 } |
|
81 |
|
82 |
|
83 void CMtfTestActionCreateSmsMessageFromFile::ExecuteActionL() |
|
84 { |
|
85 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCreateSmsMessageFromFile); |
|
86 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
87 TMsvId paramServiceId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
88 TMsvId paramFolderId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(2)); |
|
89 TInt paramFileIndex = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(3),0); //Default value is 0 |
|
90 |
|
91 // Check if the input paramFolderId is a local folder, leave otherwise |
|
92 if(!(paramFolderId == KMsvLocalServiceIndexEntryId || |
|
93 paramFolderId == KMsvGlobalInBoxIndexEntryId || |
|
94 paramFolderId == KMsvGlobalOutBoxIndexEntryId || |
|
95 paramFolderId == KMsvDraftEntryId)) |
|
96 { |
|
97 User::Leave(KErrNotFound); // Check on changing the error retured value |
|
98 } |
|
99 |
|
100 const TPtrC smsDataFile = TestCase().GetConfigurationFileL(CMtfConfigurationType::EMtfSmsMessage,paramFileIndex); |
|
101 |
|
102 TMsvEntry indexEntry; |
|
103 indexEntry.iType = KUidMsvMessageEntry; |
|
104 indexEntry.iMtm = KUidMsgTypeSMS; |
|
105 indexEntry.iServiceId = paramServiceId; |
|
106 |
|
107 // Get Message Body |
|
108 TPtrC messageBodyPtr; |
|
109 User::LeaveIfError(CMtfTestActionUtilsSmsScripts::GetSmsMessageBodyL(smsDataFile,messageBodyPtr)); |
|
110 |
|
111 if(messageBodyPtr.Length() <=0) |
|
112 { |
|
113 User::Leave(KErrGeneral); |
|
114 } |
|
115 |
|
116 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
117 CleanupStack::PushL(paraFormatLayer); |
|
118 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
119 CleanupStack::PushL(charFormatLayer); |
|
120 CRichText* bodyText = CRichText::NewL(paraFormatLayer, charFormatLayer); |
|
121 CleanupStack::PushL(bodyText); |
|
122 bodyText->InsertL(0,messageBodyPtr); |
|
123 CleanupStack::Pop(3,paraFormatLayer); |
|
124 |
|
125 // Create Sms Header |
|
126 CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit,*bodyText); |
|
127 CleanupStack::PushL(smsHeader); |
|
128 User::LeaveIfError(CMtfTestActionUtilsSmsScripts::SetSmsHeaderInfoFromConfigurationFileL(TestCase(), smsDataFile,*smsHeader)); |
|
129 |
|
130 // Create Sms Settings |
|
131 CSmsSettings* smsSettings = CSmsSettings::NewL(); |
|
132 CleanupStack::PushL(smsSettings); |
|
133 |
|
134 // Create a CMsvEntry pointing at the SMS service |
|
135 CMsvEntry* entry = CMsvEntry::NewL(*paramSession, paramServiceId, TMsvSelectionOrdering()); |
|
136 CleanupStack::PushL(entry); |
|
137 |
|
138 |
|
139 CSmsAccount* smsAccount = CSmsAccount::NewLC(); |
|
140 smsAccount->LoadSettingsL(*smsSettings); |
|
141 CleanupStack::PopAndDestroy(smsAccount); |
|
142 |
|
143 |
|
144 // Override the setting with any values that might be specified for the Sms Message |
|
145 CMtfTestActionUtilsSmsScripts::ReadSmsSettingsFromConfigurationFileL(TestCase(),smsDataFile,*smsSettings); |
|
146 smsHeader->SetSmsSettingsL(*smsSettings); |
|
147 |
|
148 entry->SetEntryL(paramFolderId); |
|
149 entry->CreateL(indexEntry); |
|
150 |
|
151 TMsvId smsMessageId = indexEntry.Id(); |
|
152 entry->SetEntryL(smsMessageId); |
|
153 |
|
154 CMsvStore* store = entry->EditStoreL(); |
|
155 CleanupStack::PushL(store); |
|
156 store->StoreBodyTextL(*bodyText); |
|
157 |
|
158 smsHeader->StoreL(*store); |
|
159 store->CommitL(); |
|
160 CleanupStack::PopAndDestroy(store); |
|
161 |
|
162 CMsvEntrySelection* smsIds = new (ELeave) CMsvEntrySelection; |
|
163 CleanupStack::PushL(smsIds); |
|
164 smsIds->AppendL(smsMessageId); |
|
165 |
|
166 StoreParameterL<CMsvEntrySelection>(TestCase(),*smsIds,ActionParameters().Parameter(4)); |
|
167 StoreParameterL<TMsvId>(TestCase(),smsMessageId,ActionParameters().Parameter(5)); |
|
168 |
|
169 CleanupStack::Pop(4); |
|
170 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCreateSmsMessageFromFile); |
|
171 TestCase().ActionCompletedL(*this); |
|
172 } |