|
1 // Copyright (c) 2007-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 // T_PLAINTEXTSTORE.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 #include "t_CImplaintextstore.h" |
|
19 #include "cactivewaiter.h" |
|
20 |
|
21 LOCAL_D TMsvId pop3Service; |
|
22 LOCAL_D TMsvId smtpService; |
|
23 LOCAL_D TMsvId newMessageId; |
|
24 LOCAL_D CTrapCleanup* theCleanup; |
|
25 |
|
26 |
|
27 #define KTestMessageDir _L("") |
|
28 |
|
29 RTest test(KCImPlainBodyTest); |
|
30 |
|
31 class CImPlainBodyText; |
|
32 |
|
33 CTestCImPlainTextStore::CTestCImPlainTextStore() |
|
34 { |
|
35 iCImPlainBodyTextStore= NULL; |
|
36 iRequestCount = 0; |
|
37 iActiveWaiter = NULL; |
|
38 } |
|
39 |
|
40 |
|
41 /** |
|
42 Initialises the tests. |
|
43 */ |
|
44 void CTestCImPlainTextStore::SetupL() |
|
45 { |
|
46 |
|
47 |
|
48 iActiveWaiter = new (ELeave) CActiveWaiter(); |
|
49 |
|
50 testUtils = CEmailTestUtils::NewL(test); |
|
51 testUtils->CreateAllTestDirectories(); |
|
52 testUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
53 testUtils->ClearEmailAccountsL(); |
|
54 testUtils->CleanMessageFolderL(); |
|
55 testUtils->GoServerSideL(); |
|
56 |
|
57 TBuf<KMaxFilePathLength>emailbodyfile(KEmail40kBodyFile); |
|
58 RFs fsSession; |
|
59 RFile infile; |
|
60 |
|
61 |
|
62 |
|
63 User::LeaveIfError(fsSession.Connect()); |
|
64 User::LeaveIfError(infile.Open(fsSession, emailbodyfile, EFileRead)); |
|
65 |
|
66 TInt size = 0; |
|
67 infile.Size(size); |
|
68 |
|
69 //read the 8 bit data from the file |
|
70 TInt chunkLength = size / 3; |
|
71 |
|
72 HBufC8* tempBuf1 = HBufC8::NewL(chunkLength); |
|
73 TPtr8 tempBufPtr1(tempBuf1->Des()); |
|
74 infile.Read(tempBufPtr1,chunkLength); |
|
75 iFilebuf1 = HBufC16::NewL(chunkLength); |
|
76 TPtr16 ptr1=iFilebuf1->Des(); |
|
77 ptr1.Copy(tempBufPtr1); |
|
78 |
|
79 HBufC8* tempBuf2 = HBufC8::NewL(chunkLength); |
|
80 TPtr8 tempBufPtr2(tempBuf2->Des()); |
|
81 infile.Read(tempBufPtr2,chunkLength); |
|
82 iFilebuf2 = HBufC16::NewL(chunkLength); |
|
83 TPtr16 ptr2=iFilebuf2->Des(); |
|
84 ptr2.Copy(tempBufPtr2); |
|
85 |
|
86 HBufC8* tempBuf3 = HBufC8::NewL(chunkLength); |
|
87 TPtr8 tempBufPtr3(tempBuf3->Des()); |
|
88 infile.Read(tempBufPtr3,chunkLength); |
|
89 iFilebuf3 = HBufC16::NewL(chunkLength); |
|
90 TPtr16 ptr3=iFilebuf3->Des(); |
|
91 ptr3.Copy(tempBufPtr3); |
|
92 |
|
93 infile.Close(); |
|
94 |
|
95 |
|
96 testUtils->GoClientSideL(); |
|
97 testUtils->ClearEmailAccountsL(); |
|
98 smtpService = testUtils->CreateSmtpServiceL(); |
|
99 pop3Service = testUtils->CreatePopServiceL(); |
|
100 testUtils->GoServerSideL(); |
|
101 |
|
102 testUtils->FileSession().SetSessionPath(_L("c:\\")); |
|
103 |
|
104 test.Printf(_L("\nPerforming Tests\n")); |
|
105 |
|
106 testUtils->GoClientSideL(); |
|
107 |
|
108 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
109 TSmtpAccount smtpAccount; |
|
110 accounts->GetSmtpAccountL(smtpService, smtpAccount); |
|
111 accounts->SetDefaultSmtpAccountL(smtpAccount); |
|
112 CleanupStack::PopAndDestroy(accounts); |
|
113 |
|
114 TParse parsedFileName; |
|
115 TFileName name(KTestMessageDir); |
|
116 testUtils->ResolveLogFile(name, parsedFileName); |
|
117 |
|
118 |
|
119 // Get the default charset |
|
120 CCnvCharacterSetConverter* characterConverter = CCnvCharacterSetConverter::NewL(); |
|
121 CleanupStack::PushL(characterConverter); |
|
122 CImConvertCharconv* charConv = CImConvertCharconv::NewL(*characterConverter,fsSession ); |
|
123 CleanupStack::PushL(charConv); |
|
124 |
|
125 iDefaultCharset = charConv->SystemDefaultCharset(); |
|
126 CleanupStack::PopAndDestroy(2); |
|
127 fsSession.Close(); |
|
128 |
|
129 } |
|
130 |
|
131 |
|
132 void CTestCImPlainTextStore::TearDownL() |
|
133 //virtual |
|
134 { |
|
135 delete iCImPlainBodyTextStore; |
|
136 delete iFilebuf1; |
|
137 delete iFilebuf2; |
|
138 delete iFilebuf3; |
|
139 delete testUtils; |
|
140 delete iActiveWaiter; |
|
141 test.Close(); |
|
142 |
|
143 } |
|
144 |
|
145 |
|
146 |
|
147 /** |
|
148 Create new Plaintext message |
|
149 */ |
|
150 |
|
151 void CTestCImPlainTextStore::CreateNewPlaintextMessageL() |
|
152 { |
|
153 TMsvEmailTypeList msvEmailTypeList = 0; |
|
154 TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments); |
|
155 CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(iActiveWaiter->iStatus, *(testUtils->iMsvSession), KMsvGlobalOutBoxIndexEntryId,KMsvNullIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP, CActive::EPriorityStandard, ETrue); |
|
156 CleanupStack::PushL(emailOperation); |
|
157 iActiveWaiter->WaitActive(); |
|
158 |
|
159 //check progres |
|
160 TMsvId temp; |
|
161 TPckgC<TMsvId> paramPack(temp); |
|
162 const TDesC8& progBuf = emailOperation->ProgressL(); |
|
163 paramPack.Set(progBuf); |
|
164 newMessageId=paramPack(); |
|
165 CleanupStack::PopAndDestroy(emailOperation); |
|
166 } |
|
167 |
|
168 void CTestCImPlainTextStore::TestStoreRestore16BitChunkSynchL() |
|
169 { |
|
170 CreateNewPlaintextMessageL(); |
|
171 CMsvEntry* entry = testUtils->iMsvSession->GetEntryL(newMessageId); |
|
172 CImEmailMessage* imEmailMessage = CImEmailMessage::NewLC(*entry); |
|
173 iCImPlainBodyTextStore = imEmailMessage->OpenPlainBodyTextForWriteL(); |
|
174 iCImPlainBodyTextStore->StoreChunkL(iFilebuf1->Des()); |
|
175 |
|
176 TInt bodyTextSize = iFilebuf1->Length(); |
|
177 |
|
178 iCImPlainBodyTextStore->StoreChunkL(iFilebuf2->Des()); |
|
179 bodyTextSize += iFilebuf2->Length(); |
|
180 |
|
181 iCImPlainBodyTextStore->StoreChunkL(iFilebuf3->Des()); |
|
182 bodyTextSize += iFilebuf3->Length(); |
|
183 |
|
184 iCImPlainBodyTextStore->CommitL(iActiveWaiter->iStatus); |
|
185 iActiveWaiter->WaitActive(); |
|
186 |
|
187 delete iCImPlainBodyTextStore; |
|
188 iCImPlainBodyTextStore = NULL; |
|
189 |
|
190 //Restore the data in chunks. |
|
191 HBufC16* filebuf11 = HBufC16::NewL(100+KTestStringLength ); |
|
192 |
|
193 |
|
194 TInt origSize = bodyTextSize; |
|
195 TInt sizeOfRestoredText = 0; |
|
196 |
|
197 TPtr bufPtr = filebuf11->Des(); |
|
198 TInt pos = 0; |
|
199 |
|
200 iCImPlainBodyTextStore = imEmailMessage->OpenPlainBodyTextForReadL(CImEmailMessage::EThisMessageOnly,100); |
|
201 iCImPlainBodyTextStore->NextChunkL(bufPtr); |
|
202 |
|
203 RArray<TPtr> chunkArray; |
|
204 chunkArray.Append(bufPtr); |
|
205 |
|
206 sizeOfRestoredText += bufPtr.Length(); |
|
207 |
|
208 while(bufPtr.Length() > 0 && bufPtr.Length() == 100) |
|
209 { |
|
210 iCImPlainBodyTextStore->NextChunkL(bufPtr); |
|
211 // put retrived buffer in a array. |
|
212 chunkArray.Append(bufPtr); |
|
213 sizeOfRestoredText += bufPtr.Length(); |
|
214 } |
|
215 |
|
216 ASSERT_EQUALS(bodyTextSize, sizeOfRestoredText); |
|
217 |
|
218 for(TInt j=chunkArray.Count() - 1;j >0; --j ) |
|
219 { |
|
220 bufPtr.SetLength(0); |
|
221 iCImPlainBodyTextStore->PreviousChunkL(bufPtr); |
|
222 // Compare chunk retrieved with chunk retrieved by NextChunkL |
|
223 TInt comp = bufPtr.Compare(chunkArray[j-1]); |
|
224 ASSERT_EQUALS(comp, 0); |
|
225 } |
|
226 |
|
227 CleanupStack::PopAndDestroy(imEmailMessage); |
|
228 } |
|
229 |
|
230 void CTestCImPlainTextStore::TestStoreRestore16BitChunkAsyncL() |
|
231 { |
|
232 CreateNewPlaintextMessageL(); |
|
233 |
|
234 CMsvEntry* entry = testUtils->iMsvSession->GetEntryL(newMessageId); |
|
235 CImEmailMessage* imEmailMessage = CImEmailMessage::NewLC(*entry); |
|
236 |
|
237 iCImPlainBodyTextStore = imEmailMessage->OpenPlainBodyTextForWriteL(); |
|
238 |
|
239 iCImPlainBodyTextStore->StoreChunkL(iFilebuf1->Des(),iActiveWaiter->iStatus); |
|
240 iActiveWaiter->WaitActive(); |
|
241 TInt bodyTextSize = iFilebuf1->Length(); |
|
242 |
|
243 iCImPlainBodyTextStore->StoreChunkL(iFilebuf2->Des(),iActiveWaiter->iStatus); |
|
244 iActiveWaiter->WaitActive(); |
|
245 bodyTextSize += iFilebuf2->Length(); |
|
246 |
|
247 iCImPlainBodyTextStore->StoreChunkL(iFilebuf3->Des(),iActiveWaiter->iStatus); |
|
248 iActiveWaiter->WaitActive(); |
|
249 bodyTextSize += iFilebuf3->Length(); |
|
250 |
|
251 iCImPlainBodyTextStore->CommitL(iActiveWaiter->iStatus); |
|
252 iActiveWaiter->WaitActive(); |
|
253 |
|
254 delete iCImPlainBodyTextStore; |
|
255 iCImPlainBodyTextStore = NULL; |
|
256 |
|
257 //Restore the data in chunks. |
|
258 HBufC16* filebuf11 = HBufC16::NewL(100+KTestStringLength); |
|
259 |
|
260 |
|
261 TInt origSize = bodyTextSize; |
|
262 TInt sizeOfRestoredText = 0; |
|
263 |
|
264 TPtr bufPtr = filebuf11->Des(); |
|
265 TInt pos = 0; |
|
266 |
|
267 iCImPlainBodyTextStore = imEmailMessage->OpenPlainBodyTextForReadL(CImEmailMessage::EThisMessageOnly,100); |
|
268 iCImPlainBodyTextStore->NextChunkL(bufPtr,iActiveWaiter->iStatus); |
|
269 iActiveWaiter->WaitActive(); |
|
270 |
|
271 RArray<TPtr> chunkArray; |
|
272 chunkArray.Append(bufPtr); |
|
273 |
|
274 sizeOfRestoredText += bufPtr.Length(); |
|
275 |
|
276 while(bufPtr.Length() > 0 && bufPtr.Length() == 100) |
|
277 { |
|
278 iCImPlainBodyTextStore->NextChunkL(bufPtr,iActiveWaiter->iStatus); |
|
279 iActiveWaiter->WaitActive(); |
|
280 // put retrived buffer in a array. |
|
281 chunkArray.Append(bufPtr); |
|
282 sizeOfRestoredText += bufPtr.Length(); |
|
283 } |
|
284 |
|
285 ASSERT_EQUALS(bodyTextSize, sizeOfRestoredText); |
|
286 |
|
287 for(TInt j=chunkArray.Count() - 1;j >0; --j ) |
|
288 { |
|
289 bufPtr.SetLength(0); |
|
290 iCImPlainBodyTextStore->PreviousChunkL(bufPtr,iActiveWaiter->iStatus); |
|
291 iActiveWaiter->WaitActive(); |
|
292 // Compare chunk retrieved with chunk retrieved by NextChunkL |
|
293 TInt comp = bufPtr.Compare(chunkArray[j-1]); |
|
294 ASSERT_EQUALS(comp, 0); |
|
295 } |
|
296 CleanupStack::PopAndDestroy(imEmailMessage); |
|
297 } |
|
298 |
|
299 void CTestCImPlainTextStore::TestStoreRichTextAsPlainTextL() |
|
300 { |
|
301 CreateNewPlaintextMessageL(); |
|
302 |
|
303 CMsvEntry* entry = testUtils->iMsvSession->GetEntryL(newMessageId); |
|
304 CImEmailMessage* imEmailMessage = CImEmailMessage::NewLC(*entry); |
|
305 |
|
306 iCImPlainBodyTextStore = imEmailMessage->OpenPlainBodyTextForWriteL(); |
|
307 |
|
308 CParaFormatLayer* paraLayer = CParaFormatLayer::NewL(); |
|
309 |
|
310 CCharFormatLayer* charLayer = CCharFormatLayer::NewL(); |
|
311 |
|
312 CRichText* richText=CRichText::NewL(paraLayer, charLayer, CEditableText::EFlatStorage, KBufferGranularity); |
|
313 |
|
314 |
|
315 TBuf<50> theMessageContents = _L("Test message contents"); |
|
316 richText->InsertL(0, theMessageContents); |
|
317 TInt textLength = richText->DocumentLength(); |
|
318 |
|
319 iCImPlainBodyTextStore->StoreRichTextAsPlainTextL(*richText); |
|
320 iCImPlainBodyTextStore->CommitL(iActiveWaiter->iStatus); |
|
321 iActiveWaiter->WaitActive(); |
|
322 |
|
323 delete richText; |
|
324 |
|
325 richText=CRichText::NewL(paraLayer, charLayer, CEditableText::EFlatStorage, KBufferGranularity); |
|
326 imEmailMessage->GetBodyTextL(newMessageId, CImEmailMessage::EThisMessageOnly, *richText, *paraLayer, *charLayer); |
|
327 richText->DocumentLength(); |
|
328 ASSERT_EQUALS(richText->DocumentLength(), textLength); |
|
329 |
|
330 delete richText; |
|
331 delete charLayer; |
|
332 delete paraLayer; |
|
333 CleanupStack::PopAndDestroy(imEmailMessage); |
|
334 } |
|
335 |
|
336 CTestSuite* CTestCImPlainTextStore::CreateSuiteL(const TDesC& aName) |
|
337 { |
|
338 SUB_SUITE; |
|
339 ADD_ASYNC_TEST_STEP(TestStoreRestore16BitChunkSynchL); |
|
340 ADD_ASYNC_TEST_STEP(TestStoreRestore16BitChunkAsyncL); |
|
341 ADD_ASYNC_TEST_STEP(TestStoreRichTextAsPlainTextL); |
|
342 END_SUITE; |
|
343 } |
|
344 |
|
345 |
|
346 |
|
347 |