|
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 // This contains CTestMessStoreProcessUtil. Base class process what is in the message store |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file TestMessStoreProcessUtil.cpp |
|
20 */ |
|
21 |
|
22 #include "TestMessStoreProcessUtil.h" |
|
23 |
|
24 // EPOC include |
|
25 #include <txtrich.h> |
|
26 |
|
27 /** |
|
28 * @name Constant Literals used. |
|
29 */ |
|
30 /*@{*/ |
|
31 // Literal constants used for the character set |
|
32 _LIT(KChineseGB2312, "ChineseGB2312"); |
|
33 _LIT(KChineseHz, "ChineseHz"); |
|
34 _LIT(KChineseBig5, "ChineseBig5"); |
|
35 /*@}*/ |
|
36 |
|
37 CTestMessStoreProcessUtil::CTestMessStoreProcessUtil(CTestMessBase& aTestStep, TBool aReadOnly) |
|
38 : CBase() |
|
39 , iTestStep(aTestStep) |
|
40 , iReadOnly(aReadOnly) |
|
41 { |
|
42 } |
|
43 |
|
44 /** |
|
45 * Process the message entry |
|
46 * @param TMsvId aMsvId - Id of message to edit |
|
47 * @return TInt - return TErrNone if all worked |
|
48 * |
|
49 */ |
|
50 TInt CTestMessStoreProcessUtil::ProcessEntryL(TMsvId aMsvId) |
|
51 { |
|
52 TInt ret=KErrNone; |
|
53 CMsvEntry* msvEntry=iTestStep.Session().GetEntryL(aMsvId); |
|
54 CleanupStack::PushL(msvEntry); |
|
55 |
|
56 if ( msvEntry->HasStoreL() ) |
|
57 { |
|
58 CMsvStore* store=NULL; |
|
59 if ( iReadOnly ) |
|
60 { |
|
61 store=msvEntry->ReadStoreL(); |
|
62 } |
|
63 else |
|
64 { |
|
65 store=msvEntry->EditStoreL(); |
|
66 } |
|
67 CleanupStack::PushL(store); |
|
68 |
|
69 RArray<TUid> ids; |
|
70 ids.Append(KUidMsgFileIMailHeader); |
|
71 ids.Append(KUidMsgFileMimeHeader); |
|
72 ids.Append(KUidMsgFileInternetAccessPreferences); |
|
73 ids.Append(KUidMsvSMSHeaderStream); |
|
74 ids.Append(KUidMsvDefaultServices); |
|
75 ids.Append(KMsvEntryRichTextBody); |
|
76 for ( TUint uidIndex=ids.Count(); uidIndex>0; ) |
|
77 { |
|
78 TUid uid=ids[--uidIndex]; |
|
79 |
|
80 if ( store->IsPresentL(uid) ) |
|
81 { |
|
82 if ( uid==KUidMsgFileIMailHeader ) |
|
83 { |
|
84 // Process the CImHeader info |
|
85 ProcessImHeaderL(*store); |
|
86 } |
|
87 else if ( uid==KUidMsgFileMimeHeader ) |
|
88 { |
|
89 // Process the CImMimeHeader info |
|
90 ProcessImMimeHeaderL(*store); |
|
91 } |
|
92 else if ( uid==KUidMsgFileInternetAccessPreferences ) |
|
93 { |
|
94 } |
|
95 else if ( uid==KUidMsvSMSHeaderStream ) |
|
96 { |
|
97 // Process the CSmsHeader info |
|
98 ProcessSmsHeaderStreamL(*store); |
|
99 } |
|
100 else if ( uid==KUidMsvDefaultServices ) |
|
101 { |
|
102 } |
|
103 else if ( uid==KMsvEntryRichTextBody ) |
|
104 { |
|
105 // Process the CRichText info |
|
106 ProcessRichTextBodyL(*store); |
|
107 } |
|
108 else |
|
109 { |
|
110 iTestStep.INFO_PRINTF2(_L("Cannot process %x"), uid.iUid); |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 // Commit to the store |
|
116 if ( !iReadOnly ) |
|
117 { |
|
118 store->CommitL(); |
|
119 } |
|
120 CleanupStack::PopAndDestroy(store); |
|
121 } |
|
122 |
|
123 CleanupStack::PopAndDestroy(msvEntry); |
|
124 |
|
125 return ret; |
|
126 } |
|
127 |
|
128 // Process the CImHeader information |
|
129 void CTestMessStoreProcessUtil::ProcessImHeaderL(CMsvStore& aStore) |
|
130 { |
|
131 CImHeader* header=CImHeader::NewLC(); |
|
132 TRAPD(err, header->RestoreL(aStore)); |
|
133 |
|
134 if ( err==KErrNone ) |
|
135 { |
|
136 ProcessImHeaderL(*header); |
|
137 if ( !iReadOnly ) |
|
138 { |
|
139 header->StoreL(aStore); |
|
140 } |
|
141 } |
|
142 |
|
143 CleanupStack::PopAndDestroy(header); |
|
144 } |
|
145 |
|
146 // Process the CImMimeHeader information |
|
147 void CTestMessStoreProcessUtil::ProcessImMimeHeaderL(CMsvStore& aStore) |
|
148 { |
|
149 CImMimeHeader* header=CImMimeHeader::NewLC(); |
|
150 TRAPD(err, header->RestoreL(aStore)); |
|
151 |
|
152 if ( err==KErrNone ) |
|
153 { |
|
154 ProcessImMimeHeaderL(*header); |
|
155 if ( !iReadOnly ) |
|
156 { |
|
157 header->StoreL(aStore); |
|
158 } |
|
159 } |
|
160 |
|
161 CleanupStack::PopAndDestroy(header); |
|
162 } |
|
163 |
|
164 |
|
165 // Process the CSmsHeader information |
|
166 void CTestMessStoreProcessUtil::ProcessSmsHeaderStreamL(CMsvStore& aStore) |
|
167 { |
|
168 CParaFormatLayer* paraFormatLayer=CParaFormatLayer::NewL(); |
|
169 CleanupStack::PushL(paraFormatLayer); |
|
170 |
|
171 CCharFormatLayer* charFormatLayer=CCharFormatLayer::NewL(); |
|
172 CleanupStack::PushL(charFormatLayer); |
|
173 |
|
174 CRichText* bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer); |
|
175 CleanupStack::PushL(bodyText); |
|
176 |
|
177 CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *bodyText); |
|
178 CleanupStack::PushL(header); |
|
179 |
|
180 TRAPD(err, header->RestoreL(aStore)); |
|
181 if ( err == KErrNone ) |
|
182 { |
|
183 ProcessSmsHeaderStreamL(*header); |
|
184 if ( !iReadOnly ) |
|
185 { |
|
186 header->StoreL(aStore); |
|
187 } |
|
188 } |
|
189 |
|
190 CleanupStack::PopAndDestroy(4, paraFormatLayer); |
|
191 } |
|
192 |
|
193 |
|
194 // Process the CRichText information |
|
195 void CTestMessStoreProcessUtil::ProcessRichTextBodyL(CMsvStore& aStore) |
|
196 { |
|
197 CParaFormatLayer* paraFormatLayer=CParaFormatLayer::NewL(); |
|
198 CleanupStack::PushL(paraFormatLayer); |
|
199 |
|
200 CCharFormatLayer* charFormatLayer=CCharFormatLayer::NewL(); |
|
201 CleanupStack::PushL(charFormatLayer); |
|
202 |
|
203 CRichText* bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer); |
|
204 CleanupStack::PushL(bodyText); |
|
205 |
|
206 TRAPD(err, aStore.RestoreBodyTextL(*bodyText)); |
|
207 if ( err == KErrNone ) |
|
208 { |
|
209 ProcessRichTextBodyL(*bodyText); |
|
210 if ( !iReadOnly ) |
|
211 { |
|
212 aStore.StoreBodyTextL(*bodyText); |
|
213 } |
|
214 } |
|
215 |
|
216 CleanupStack::PopAndDestroy(3, paraFormatLayer); |
|
217 } |
|
218 |
|
219 /** |
|
220 * Saves the new character set to the message |
|
221 * @param TPtrC aCharacterSetType - New Character set type to be stored for the received message |
|
222 * @param TUint &aCharSetVal - character set value |
|
223 * @return TBool |
|
224 * @panic None |
|
225 * @leave None |
|
226 * |
|
227 */ |
|
228 TBool CTestMessStoreProcessUtil::ValidCharacterSetInfo(const TPtrC& aCharacterSetType, TUint &aCharSetVal) |
|
229 { |
|
230 TBool hasSet = ETrue; |
|
231 |
|
232 if ( aCharacterSetType.Compare(KChineseGB2312) == 0 ) |
|
233 { |
|
234 iTestStep.INFO_PRINTF1(_L("Character set set to Chinese GB2312")); |
|
235 aCharSetVal = KCharacterSetIdentifierGb2312; |
|
236 } |
|
237 else if (aCharacterSetType.Compare(KChineseHz) == 0) |
|
238 { |
|
239 iTestStep.INFO_PRINTF1(_L("Character set set to Chinese Hz")); |
|
240 aCharSetVal = KCharacterSetIdentifierHz; |
|
241 } |
|
242 else if ( aCharacterSetType.Compare(KChineseBig5) == 0 ) |
|
243 { |
|
244 iTestStep.INFO_PRINTF1(_L("Character set set to Chinese Big5")); |
|
245 aCharSetVal = KCharacterSetIdentifierBig5; |
|
246 } |
|
247 else |
|
248 { |
|
249 // To be updated later |
|
250 hasSet= EFalse; |
|
251 iTestStep.ERR_PRINTF2(_L("Character not supported in test code: %S"), &aCharacterSetType); |
|
252 iTestStep.SetTestStepResult(EFail); |
|
253 } |
|
254 |
|
255 return hasSet; |
|
256 } |