|
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 // CompareSmsMessages |
|
17 // [Action Parameters] |
|
18 // TMsvId FolderId1 <input> : Value of Folder Id to be compared with. |
|
19 // TMsvId FolderId2 <input> : Value of Folder Id to be compared |
|
20 // CMsvSession session <input> : Reference to the session. |
|
21 // TInt Result <output-initiation> : Value of enumerated constants if not |
|
22 // identical(zero if one folder has |
|
23 // corresponding same message in other folder). |
|
24 // [Action Description] |
|
25 // Compare and check the whether the messages in one folder has corresponding same message |
|
26 // in other folder. The output of the Test action should be zero if all parts of |
|
27 // the message in both folders are identical, otherwise the corresponding |
|
28 // enumerated value of the non-identical part of the message. |
|
29 // [APIs Used] |
|
30 // CMsvEntrySelection::ChildrenL |
|
31 // CMsvEntrySelection::Count |
|
32 // CMsvSession::GetEntryL |
|
33 // CMsvEntry::Entry |
|
34 // CMsvStore::RestoreBodyTextL |
|
35 // CSmsHeader::RestoreL |
|
36 // __ACTION_INFO_END__ |
|
37 // |
|
38 // |
|
39 |
|
40 /** |
|
41 @file |
|
42 */ |
|
43 |
|
44 // system includes |
|
45 #include <smut.h> |
|
46 #include <msvapi.h> |
|
47 #include <txtrich.h> |
|
48 #include <smuthdr.h> |
|
49 |
|
50 |
|
51 // user includes |
|
52 #include "CmtfTestActionCompareSmsMessages.h" |
|
53 #include "CMtfTestCase.h" |
|
54 #include "CMtfTestActionParameters.h" |
|
55 |
|
56 CMtfTestAction* CMtfTestActionCompareSmsMessages::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
57 { |
|
58 CMtfTestActionCompareSmsMessages* self = new (ELeave) CMtfTestActionCompareSmsMessages(aTestCase); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(aActionParameters); |
|
61 CleanupStack::Pop(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 |
|
66 CMtfTestActionCompareSmsMessages::CMtfTestActionCompareSmsMessages(CMtfTestCase& aTestCase) |
|
67 :CMtfSynchronousTestAction(aTestCase) |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 CMtfTestActionCompareSmsMessages::~CMtfTestActionCompareSmsMessages() |
|
73 { |
|
74 } |
|
75 |
|
76 void CMtfTestActionCompareSmsMessages::ExecuteActionL() |
|
77 { |
|
78 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCompareSmsMessages); |
|
79 TMsvId paramFolderId1 = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(0)); |
|
80 TMsvId paramFolderId2 = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
81 |
|
82 iParamSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(2)); |
|
83 |
|
84 CMsvEntry* folderEntry1 = CMsvEntry::NewL(*iParamSession,paramFolderId1,TMsvSelectionOrdering()); |
|
85 CleanupStack::PushL(folderEntry1); |
|
86 CMsvEntrySelection* folder1Selection =folderEntry1->ChildrenWithMtmL(KUidMsgTypeSMS); |
|
87 CleanupStack::PushL(folder1Selection); |
|
88 folderEntry1->SetEntryL(paramFolderId2); |
|
89 CMsvEntrySelection* folder2Selection =folderEntry1->ChildrenWithMtmL(KUidMsgTypeSMS); |
|
90 CleanupStack::PushL(folder2Selection); |
|
91 TInt count1 = folder1Selection->Count(); |
|
92 TInt resCount=0; |
|
93 TInt enumVal; |
|
94 TInt folder1Count=count1; |
|
95 TInt count2 = folder2Selection->Count(); |
|
96 if((count1 <= 0)||(count2 < count1)) |
|
97 { |
|
98 User::Leave(KErrGeneral); |
|
99 } |
|
100 TMsvId msgId1 = KMsvRootIndexEntryId; |
|
101 CMsvEntry* f1Entry = iParamSession->GetEntryL(KMsvRootIndexEntryId); |
|
102 CleanupStack::PushL(f1Entry); |
|
103 TMsvId msgId2 = KMsvRootIndexEntryId; |
|
104 CMsvEntry* f2Entry = iParamSession->GetEntryL(KMsvRootIndexEntryId); |
|
105 CleanupStack::PushL(f2Entry); |
|
106 |
|
107 while (count1--) |
|
108 { |
|
109 msgId1 = (*folder1Selection)[count1]; |
|
110 f1Entry->SetEntryL(msgId1); |
|
111 TMsvEntry msgEntry1 = f1Entry->Entry(); |
|
112 while (count2--) |
|
113 { |
|
114 msgId2 = (*folder2Selection)[count2]; |
|
115 f2Entry->SetEntryL(msgId2); |
|
116 TMsvEntry msgEntry2 = f2Entry->Entry(); |
|
117 |
|
118 if (IsMatchHeaderL(*f1Entry, *f2Entry)) |
|
119 { |
|
120 enumVal = EFailedToMatchHeader; |
|
121 } |
|
122 else if (!IsMatchL(*f1Entry, *f2Entry)) |
|
123 { |
|
124 enumVal = EFailedToMatchBody; |
|
125 } |
|
126 else |
|
127 { |
|
128 resCount++; |
|
129 if(resCount == folder1Count) |
|
130 { |
|
131 enumVal = EAllMatched; |
|
132 } |
|
133 break; |
|
134 } |
|
135 } |
|
136 } |
|
137 StoreParameterL<TInt>(TestCase(),enumVal,ActionParameters().Parameter(3)); |
|
138 CleanupStack::PopAndDestroy(f2Entry); |
|
139 CleanupStack::PopAndDestroy(f1Entry); |
|
140 CleanupStack::PopAndDestroy(folder2Selection); |
|
141 CleanupStack::PopAndDestroy(folder1Selection); |
|
142 CleanupStack::PopAndDestroy(folderEntry1); |
|
143 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCompareSmsMessages); |
|
144 TestCase().ActionCompletedL(*this); |
|
145 } |
|
146 |
|
147 |
|
148 |
|
149 TBool CMtfTestActionCompareSmsMessages::IsMatchL(CMsvEntry& aFolder1Msg, CMsvEntry& aFolder2Msg) |
|
150 /** |
|
151 * Compares the body text of Folder1 and Folder2 |
|
152 * |
|
153 * @return Returns ETrue if the body text matches |
|
154 */ |
|
155 { |
|
156 HBufC* folder1MsgBody = GetBodyTextL(aFolder1Msg); |
|
157 HBufC* folder2MsgBody = GetBodyTextL(aFolder2Msg); |
|
158 TBool retVal = (*folder1MsgBody == *folder2MsgBody); |
|
159 return retVal; |
|
160 } |
|
161 |
|
162 TBool CMtfTestActionCompareSmsMessages::IsMatchHeaderL(CMsvEntry& aFolder1Msg, CMsvEntry& aFolder2Msg) |
|
163 /** |
|
164 * Compares the Message Header of Folder1 and Folder2 |
|
165 * |
|
166 * @return Returns ETrue if the body text matches |
|
167 */ |
|
168 { |
|
169 CSmsHeader* folder1MsgHeader = GetSubmitHeaderL(aFolder1Msg); |
|
170 CleanupStack::PushL(folder1MsgHeader); |
|
171 CSmsHeader* folder2MsgHeader = GetDeliverHeaderL(aFolder2Msg); |
|
172 CleanupStack::PushL(folder2MsgHeader); |
|
173 |
|
174 CArrayPtrFlat<CSmsNumber>& f1Recipients = folder1MsgHeader->Recipients(); |
|
175 CArrayPtrFlat<CSmsNumber>& f2Recipients = folder2MsgHeader->Recipients(); |
|
176 |
|
177 TInt f1Count = f1Recipients.Count(); |
|
178 TInt f2Count = f2Recipients.Count(); |
|
179 TBool retVal = ETrue; |
|
180 if((f1Count == f2Count)&&(folder1MsgHeader->Type()==folder2MsgHeader->Type())) |
|
181 { |
|
182 for(TInt i=0;i<f1Count;i++) |
|
183 { |
|
184 retVal = (f1Recipients[i] == f2Recipients[i]); |
|
185 if((retVal==EFalse)) |
|
186 break; |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 retVal = EFalse; |
|
192 } |
|
193 CleanupStack::PopAndDestroy(folder2MsgHeader); |
|
194 CleanupStack::PopAndDestroy(folder1MsgHeader); |
|
195 return retVal; |
|
196 } |
|
197 |
|
198 CSmsHeader* CMtfTestActionCompareSmsMessages::GetSubmitHeaderL(CMsvEntry& aMessage) |
|
199 /** |
|
200 * Returns the CSmsHeader restored from message aMessage. |
|
201 */ |
|
202 { |
|
203 CSmsHeader* header = CSmsHeader::NewL(CSmsMessage::NewL(iParamSession->FileSession(), CSmsPDU::ESmsSubmit, CSmsBuffer::NewL())); |
|
204 CleanupStack::PushL(header); |
|
205 |
|
206 CMsvStore* store = aMessage.ReadStoreL(); |
|
207 CleanupStack::PushL(store); |
|
208 header->RestoreL(*store); |
|
209 CleanupStack::PopAndDestroy(store); |
|
210 |
|
211 CleanupStack::Pop(header); |
|
212 return header; |
|
213 } |
|
214 |
|
215 CSmsHeader* CMtfTestActionCompareSmsMessages::GetDeliverHeaderL(CMsvEntry& aMessage) |
|
216 /** |
|
217 * Returns the CSmsHeader restored from message aMessage. |
|
218 */ |
|
219 { |
|
220 CSmsHeader* header = CSmsHeader::NewL(CSmsMessage::NewL(iParamSession->FileSession(), CSmsPDU::ESmsDeliver, CSmsBuffer::NewL())); |
|
221 CleanupStack::PushL(header); |
|
222 |
|
223 CMsvStore* store = aMessage.ReadStoreL(); |
|
224 CleanupStack::PushL(store); |
|
225 header->RestoreL(*store); |
|
226 CleanupStack::PopAndDestroy(store); |
|
227 |
|
228 CleanupStack::Pop(header); |
|
229 return header; |
|
230 } |
|
231 |
|
232 |
|
233 HBufC* CMtfTestActionCompareSmsMessages::GetBodyTextL(CMsvEntry& aMessage) |
|
234 /** |
|
235 * @return The body text of message aMessage |
|
236 */ |
|
237 { |
|
238 CMsvStore* store = aMessage.ReadStoreL(); |
|
239 CleanupStack::PushL(store); |
|
240 |
|
241 CRichText* richText; |
|
242 CParaFormatLayer* paraFormatLayer; |
|
243 CCharFormatLayer* charFormatLayer; |
|
244 paraFormatLayer=CParaFormatLayer::NewL(); |
|
245 CleanupStack::PushL(paraFormatLayer); |
|
246 charFormatLayer=CCharFormatLayer::NewL(); |
|
247 CleanupStack::PushL(charFormatLayer); |
|
248 |
|
249 richText=CRichText::NewL(paraFormatLayer, charFormatLayer); |
|
250 CleanupStack::PushL(richText); |
|
251 store->RestoreBodyTextL(*richText); |
|
252 const TInt len =richText->DocumentLength(); |
|
253 HBufC* buf = HBufC::NewL(len); |
|
254 TPtr ptr(buf->Des()); |
|
255 richText->Extract(ptr); |
|
256 CleanupStack::PopAndDestroy(richText); |
|
257 CleanupStack::PopAndDestroy(charFormatLayer); |
|
258 CleanupStack::PopAndDestroy(paraFormatLayer); |
|
259 CleanupStack::PopAndDestroy(store); |
|
260 return buf; |
|
261 } |