|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #include <e32std.h> |
|
17 #include <e32test.h> |
|
18 #include <conlist.h> |
|
19 #include <conarc.h> |
|
20 #include <txtrich.h> |
|
21 #include <s32file.h> |
|
22 #include <s32mem.h> |
|
23 #include <ecom/ecom.h> |
|
24 |
|
25 const TUid KCrt2HTMLConverterUid = {0x1000071c}; |
|
26 |
|
27 static RTest TheTest(_L("Rich text to HTML converter ")); |
|
28 |
|
29 _LIT(KCnvEPOCSmallDocumentDriveC, "C:\\ConvTest"); |
|
30 _LIT(KTestFile, "Z:\\Test\\RT2HtmlConv.html"); |
|
31 _LIT(KHtmlOutput, "C:\\HtmlOutput.html"); |
|
32 _LIT(KHtmlOutputStream, "C:\\HtmlOutputStream.html"); |
|
33 |
|
34 _LIT(KTextToConvert_ParagraphDelimiterTest, "*********Test Started:Converting rich text paragraphs to HTML *********"); |
|
35 _LIT(KTextToConvert_Line01, "line1 followed by 1 rich text paragraph delimiter "); |
|
36 _LIT(KTextToConvert_Line02, "line2 followed by 2 rich text paragraphs delimiter"); |
|
37 _LIT(KTextToConvert_Line04, "line3 followed by 3 rich text paragraphs delimiter"); |
|
38 _LIT(KTextToConvert_Line06, "line4"); |
|
39 _LIT(KEndTest, "*********Test completed*********"); |
|
40 |
|
41 _LIT(KLeftAlignText, "LEFT"); |
|
42 _LIT(KCenterAlignText, "CENTRE"); |
|
43 _LIT(KRightAlignText, "RIGHT"); |
|
44 _LIT(KFmtdRTCnvTestFile, "C:\\FmtRTConvTestFile"); |
|
45 _LIT(KFmtdRT2HtmlConvOutputFile, "C:\\FmtdRT2HtmlConvOutputFile.html"); |
|
46 _LIT(KFmtdRT2HtmlConvExpectedFile, "Z:\\Test\\FmtdRT2HtmlConvExpectedFile.html"); |
|
47 |
|
48 _LIT(KItem1, "Item 1"); |
|
49 _LIT(KItem2, "Item 2"); |
|
50 _LIT(KItem3, "Item 3"); |
|
51 _LIT(KBulletConvOutputFile1, "C:\\bulletconvexpectedfile1.html"); |
|
52 _LIT(KBulletConvExpectedFile1, "Z:\\Test\\bulletconvexpectedfile1.html"); |
|
53 |
|
54 _LIT(KTranslateConvOutputFile1, "C:\\translateconvoutputfile1.html"); |
|
55 _LIT(KTranslateConvExpectedFile1, "Z:\\Test\\translateconvexpectedfile1.html"); |
|
56 |
|
57 _LIT(KTextStyleConvOutputFile1, "C:\\textstyleconvoutputfile1.html"); |
|
58 _LIT(KTextStyleConvExpectedFile1, "Z:\\Test\\textstyleconvexpectedfile1.html"); |
|
59 |
|
60 /** |
|
61 |
|
62 |
|
63 Reads data in from a file and stores the information |
|
64 into an HBuf pointer. If there is an error the function will return an empty buffer |
|
65 |
|
66 @return HBufC8* - containing the data read from the file |
|
67 @internalComponent |
|
68 @param aFileName - the filename to read from e.g.C:\test.html' |
|
69 */ |
|
70 HBufC8* ReadFileLC(const TDesC& aFileName) |
|
71 { |
|
72 RFs fs; |
|
73 User::LeaveIfError(fs.Connect()); |
|
74 CleanupClosePushL(fs); |
|
75 |
|
76 RFile myFile; |
|
77 CleanupClosePushL(myFile); |
|
78 |
|
79 TInt err = myFile.Open(fs, aFileName, EFileRead|EFileShareReadersOnly); |
|
80 if (err != KErrNone) |
|
81 { |
|
82 User::Leave(err); |
|
83 } |
|
84 TEntry entry; |
|
85 fs.Entry(aFileName, entry); |
|
86 TInt streamSize = entry.iSize; // Find the size of the file |
|
87 HBufC8* data = HBufC8::NewLC(streamSize); |
|
88 TPtr8 ptrData(data->Des()); // Sets a pointer to the HBufC data |
|
89 myFile.Read(0, ptrData); |
|
90 |
|
91 CleanupStack::Pop(data); |
|
92 CleanupStack::PopAndDestroy(&myFile); |
|
93 CleanupStack::PopAndDestroy(&fs); |
|
94 CleanupStack::PushL(data); |
|
95 return data; // Return the buffer |
|
96 } |
|
97 |
|
98 |
|
99 static CRichText* CreateTestTextL() |
|
100 { |
|
101 // Variable definitions |
|
102 CRichText* richText = NULL; |
|
103 CParaFormatLayer* paragraphFormatLayer = NULL; |
|
104 CCharFormatLayer* charFormatLayer = NULL; |
|
105 |
|
106 // Create Paragraph and Char format layers |
|
107 paragraphFormatLayer = CParaFormatLayer::NewL( ); |
|
108 CleanupStack::PushL( paragraphFormatLayer ); |
|
109 charFormatLayer = CCharFormatLayer::NewL(); |
|
110 CleanupStack::PushL(charFormatLayer); |
|
111 // Create Rich Text object |
|
112 richText = CRichText::NewL(paragraphFormatLayer, charFormatLayer, CEditableText::EFlatStorage); |
|
113 CleanupStack::PushL( richText ); |
|
114 |
|
115 // start |
|
116 richText->InsertL( richText->DocumentLength(), KTextToConvert_ParagraphDelimiterTest ); |
|
117 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
118 |
|
119 richText->InsertL( richText->DocumentLength(), KTextToConvert_Line01 ); |
|
120 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
121 richText->InsertL( richText->DocumentLength(), KTextToConvert_Line02 ); |
|
122 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
123 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
124 richText->InsertL( richText->DocumentLength(), KTextToConvert_Line04 ); |
|
125 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
126 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
127 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
128 richText->InsertL( richText->DocumentLength(), KTextToConvert_Line06 ); |
|
129 |
|
130 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
131 richText->InsertL( richText->DocumentLength(), KEndTest ); |
|
132 |
|
133 CleanupStack::Pop( richText ); |
|
134 CleanupStack::PopAndDestroy( charFormatLayer ); |
|
135 CleanupStack::PopAndDestroy( paragraphFormatLayer ); |
|
136 |
|
137 return richText; |
|
138 } |
|
139 |
|
140 static void ConstructTestSourceL() |
|
141 { |
|
142 // Variable definitions |
|
143 CDirectFileStore* fileStore = NULL; |
|
144 |
|
145 TStreamId streamID; |
|
146 |
|
147 CRichText* richText = CreateTestTextL(); |
|
148 CleanupStack::PushL(richText); |
|
149 |
|
150 // write this out to a file |
|
151 // Grab a file session |
|
152 RFs fs; |
|
153 User::LeaveIfError(fs.Connect()); |
|
154 CleanupClosePushL(fs); |
|
155 // Create file store. |
|
156 fileStore = CDirectFileStore::ReplaceL(fs, KCnvEPOCSmallDocumentDriveC(), EFileWrite|EFileShareAny); |
|
157 CleanupStack::PushL( fileStore ); |
|
158 fileStore->SetTypeL( KDirectFileStoreLayoutUid ); |
|
159 streamID = richText->StoreL(*fileStore); |
|
160 fileStore->SetRootL(streamID); |
|
161 fileStore->CommitL(); |
|
162 |
|
163 // Start cleanup of stack |
|
164 CleanupStack::PopAndDestroy( fileStore ); |
|
165 CleanupStack::PopAndDestroy(&fs ); |
|
166 CleanupStack::PopAndDestroy( richText ); |
|
167 } |
|
168 |
|
169 |
|
170 static CRichText* CreateBulletedAndFormattedTextL() |
|
171 { |
|
172 // Variable definitions |
|
173 CRichText* richText = NULL; |
|
174 CParaFormatLayer* paragraphFormatLayer = NULL; |
|
175 CCharFormatLayer* charFormatLayer = NULL; |
|
176 |
|
177 // Create Paragraph and Char format layers |
|
178 CParaFormat paraFormat; |
|
179 TParaFormatMask paraFormatMask; |
|
180 paragraphFormatLayer = CParaFormatLayer::NewL(¶Format,paraFormatMask); |
|
181 CleanupStack::PushL( paragraphFormatLayer ); |
|
182 charFormatLayer = CCharFormatLayer::NewL(); |
|
183 CleanupStack::PushL(charFormatLayer); |
|
184 // Create Rich Text object |
|
185 richText = CRichText::NewL(paragraphFormatLayer, charFormatLayer, CEditableText::EFlatStorage); |
|
186 CleanupStack::PushL( richText ); |
|
187 |
|
188 // Left Align bulleted text |
|
189 paraFormat.iHorizontalAlignment=CParaFormat::ELeftAlign; |
|
190 paraFormatMask.SetAttrib(EAttAlignment); |
|
191 richText->InsertL( richText->DocumentLength(), CEditableText::EBullet ); |
|
192 richText->InsertL( richText->DocumentLength(), KLeftAlignText); |
|
193 richText->ApplyParaFormatL(¶Format, paraFormatMask,richText->DocumentLength(),0); |
|
194 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
195 // Center Align bulleted text |
|
196 richText->InsertL( richText->DocumentLength(), CEditableText::EBullet ); |
|
197 richText->InsertL( richText->DocumentLength(), KCenterAlignText); |
|
198 paraFormat.iHorizontalAlignment=CParaFormat::ECenterAlign; |
|
199 paraFormatMask.SetAttrib(EAttAlignment); |
|
200 richText->ApplyParaFormatL(¶Format, paraFormatMask,richText->DocumentLength(),0); |
|
201 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
202 // Right Align bulleted text |
|
203 richText->InsertL( richText->DocumentLength(), CEditableText::EBullet ); |
|
204 richText->InsertL( richText->DocumentLength(), KRightAlignText); |
|
205 paraFormat.iHorizontalAlignment=CParaFormat::ERightAlign; |
|
206 paraFormatMask.SetAttrib(EAttAlignment); |
|
207 richText->ApplyParaFormatL(¶Format, paraFormatMask,richText->DocumentLength(),0); |
|
208 |
|
209 CleanupStack::Pop( richText ); |
|
210 CleanupStack::PopAndDestroy( charFormatLayer ); |
|
211 CleanupStack::PopAndDestroy( paragraphFormatLayer ); |
|
212 |
|
213 return richText; |
|
214 } |
|
215 |
|
216 |
|
217 static void ConstructTestSourceForBulletedAndFormattedTextL() |
|
218 { |
|
219 // Variable definitions |
|
220 CDirectFileStore* fileStore = NULL; |
|
221 |
|
222 TStreamId streamID; |
|
223 |
|
224 CRichText* richText = CreateBulletedAndFormattedTextL(); |
|
225 CleanupStack::PushL(richText); |
|
226 |
|
227 // write this Bulleted and formatted richtext to a file c:\HtmlOutputFile.html |
|
228 // Grab a file session |
|
229 RFs fs; |
|
230 User::LeaveIfError(fs.Connect()); |
|
231 CleanupClosePushL(fs); |
|
232 // Create file store. |
|
233 fileStore = CDirectFileStore::ReplaceL(fs, KFmtdRTCnvTestFile(), EFileWrite|EFileShareAny); |
|
234 CleanupStack::PushL( fileStore ); |
|
235 fileStore->SetTypeL( KDirectFileStoreLayoutUid ); |
|
236 streamID = richText->StoreL(*fileStore); |
|
237 fileStore->SetRootL(streamID); |
|
238 fileStore->CommitL(); |
|
239 |
|
240 // Start cleanup of stack |
|
241 CleanupStack::PopAndDestroy( fileStore ); |
|
242 CleanupStack::PopAndDestroy(&fs ); |
|
243 CleanupStack::PopAndDestroy( richText ); |
|
244 } |
|
245 |
|
246 typedef TPckgBuf<CRichText*> TRTPtrBuffer; |
|
247 |
|
248 static void DoUidAndCapabilitiesTest(CConverterBase& aConv) |
|
249 { |
|
250 TheTest(aConv.Capabilities() == CConverterBase::EConvertsFiles); |
|
251 TheTest(aConv.Uid() == KCrt2HTMLConverterUid); |
|
252 } |
|
253 |
|
254 static void DoStreamingTestL(CConverterBase& aConv) |
|
255 { |
|
256 CRichText* text = CreateTestTextL(); |
|
257 CleanupStack::PushL(text); |
|
258 TRTPtrBuffer buffer(text); |
|
259 RDesReadStream readStream(buffer); |
|
260 CleanupClosePushL(readStream); |
|
261 |
|
262 RFs fs; |
|
263 User::LeaveIfError(fs.Connect()); |
|
264 CleanupClosePushL(fs); |
|
265 RFileWriteStream writeStream; |
|
266 User::LeaveIfError(writeStream.Replace(fs, KHtmlOutputStream(), EFileStream|EFileWrite|EFileShareExclusive)); |
|
267 CleanupClosePushL(writeStream); |
|
268 |
|
269 TTime started; started.UniversalTime(); |
|
270 aConv.ConvertObjectL(readStream, writeStream,NULL); |
|
271 HBufC8* htmlOutput = ReadFileLC(KHtmlOutputStream); |
|
272 HBufC8* testFile = ReadFileLC(KTestFile); |
|
273 TheTest(htmlOutput->Compare(*testFile)==KErrNone); |
|
274 TTime finished; finished.UniversalTime(); |
|
275 TTimeIntervalMicroSeconds interval = finished.MicroSecondsFrom(started); |
|
276 TheTest.Printf(_L("\tEPOC => HTML (Streaming) %4dms\n"), interval.Int64()); |
|
277 |
|
278 CleanupStack::PopAndDestroy(testFile); |
|
279 CleanupStack::PopAndDestroy(htmlOutput); |
|
280 CleanupStack::PopAndDestroy(&writeStream); |
|
281 CleanupStack::PopAndDestroy(&fs); |
|
282 CleanupStack::PopAndDestroy(&readStream); |
|
283 CleanupStack::PopAndDestroy(text); |
|
284 } |
|
285 |
|
286 static void DoFmtdStreamingTestL(CConverterBase& aConv) |
|
287 { |
|
288 CRichText* text = CreateBulletedAndFormattedTextL(); |
|
289 CleanupStack::PushL(text); |
|
290 TRTPtrBuffer buffer(text); |
|
291 RDesReadStream readStream(buffer); |
|
292 CleanupClosePushL(readStream); |
|
293 |
|
294 RFs fs; |
|
295 User::LeaveIfError(fs.Connect()); |
|
296 CleanupClosePushL(fs); |
|
297 RFileWriteStream writeStream; |
|
298 User::LeaveIfError(writeStream.Replace(fs, KFmtdRT2HtmlConvOutputFile(), EFileStream|EFileWrite|EFileShareExclusive)); |
|
299 CleanupClosePushL(writeStream); |
|
300 |
|
301 TTime started; started.UniversalTime(); |
|
302 aConv.ConvertObjectL(readStream, writeStream, NULL); |
|
303 HBufC8* htmlOutputFile = ReadFileLC(KFmtdRT2HtmlConvOutputFile); |
|
304 HBufC8* htmlExpectedFile = ReadFileLC(KFmtdRT2HtmlConvExpectedFile); |
|
305 TheTest(htmlOutputFile->Compare(*htmlExpectedFile)==KErrNone); |
|
306 TTime finished; finished.UniversalTime(); |
|
307 TTimeIntervalMicroSeconds interval = finished.MicroSecondsFrom(started); |
|
308 TheTest.Printf(_L("\tEPOC Bulleted and Formatted richtext => HTML (Streaming) %4dms\n"), interval.Int64()); |
|
309 |
|
310 CleanupStack::PopAndDestroy(htmlExpectedFile); |
|
311 CleanupStack::PopAndDestroy(htmlOutputFile); |
|
312 CleanupStack::PopAndDestroy(&writeStream); |
|
313 CleanupStack::PopAndDestroy(&fs); |
|
314 CleanupStack::PopAndDestroy(&readStream); |
|
315 CleanupStack::PopAndDestroy(text); |
|
316 } |
|
317 |
|
318 static CRichText* CreateBulletedTextL() |
|
319 { |
|
320 // Variable definitions |
|
321 CRichText* richText = NULL; |
|
322 CParaFormatLayer* paragraphFormatLayer = NULL; |
|
323 CCharFormatLayer* charFormatLayer = NULL; |
|
324 |
|
325 // Create Paragraph and Char format layers |
|
326 CParaFormat paraFormat; |
|
327 TParaFormatMask paraFormatMask; |
|
328 paragraphFormatLayer = CParaFormatLayer::NewL(¶Format,paraFormatMask); |
|
329 CleanupStack::PushL( paragraphFormatLayer ); |
|
330 charFormatLayer = CCharFormatLayer::NewL(); |
|
331 CleanupStack::PushL(charFormatLayer); |
|
332 // Create Rich Text object |
|
333 richText = CRichText::NewL(paragraphFormatLayer, charFormatLayer, CEditableText::EFlatStorage); |
|
334 CleanupStack::PushL( richText ); |
|
335 |
|
336 // Left Align bulleted text |
|
337 TBullet* bullet = new(ELeave) TBullet(); |
|
338 bullet->iCharacterCode=0x2022; |
|
339 bullet->iHeightInTwips=300; |
|
340 paraFormat.iBullet=bullet; |
|
341 paraFormatMask.SetAttrib(EAttBullet); |
|
342 |
|
343 richText->InsertL( richText->DocumentLength(), KItem1); |
|
344 richText->ApplyParaFormatL(¶Format, paraFormatMask, richText->DocumentLength(), 0); |
|
345 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
346 |
|
347 richText->InsertL( richText->DocumentLength(), KItem2); |
|
348 richText->ApplyParaFormatL(¶Format, paraFormatMask,richText->DocumentLength(),0); |
|
349 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
350 |
|
351 richText->InsertL( richText->DocumentLength(), KItem3); |
|
352 richText->ApplyParaFormatL(¶Format, paraFormatMask, richText->DocumentLength(),0); |
|
353 |
|
354 CleanupStack::Pop( richText ); |
|
355 CleanupStack::PopAndDestroy( charFormatLayer ); |
|
356 CleanupStack::PopAndDestroy( paragraphFormatLayer ); |
|
357 |
|
358 return richText; |
|
359 } |
|
360 |
|
361 static void DoBulletTestL(CConverterBase& aConv) |
|
362 { |
|
363 CRichText* text = CreateBulletedTextL(); |
|
364 CleanupStack::PushL(text); |
|
365 TRTPtrBuffer buffer(text); |
|
366 RDesReadStream readStream(buffer); |
|
367 CleanupClosePushL(readStream); |
|
368 |
|
369 RFs fs; |
|
370 User::LeaveIfError(fs.Connect()); |
|
371 CleanupClosePushL(fs); |
|
372 RFileWriteStream writeStream; |
|
373 User::LeaveIfError(writeStream.Replace(fs, KBulletConvOutputFile1(), EFileStream|EFileWrite|EFileShareExclusive)); |
|
374 CleanupClosePushL(writeStream); |
|
375 |
|
376 TTime started; started.UniversalTime(); |
|
377 aConv.ConvertObjectL(readStream, writeStream, NULL); |
|
378 HBufC8* outputFile = ReadFileLC(KBulletConvOutputFile1); |
|
379 HBufC8* expectedFile = ReadFileLC(KBulletConvExpectedFile1); |
|
380 TheTest(outputFile->Compare(*expectedFile)==KErrNone); |
|
381 TTime finished; finished.UniversalTime(); |
|
382 TTimeIntervalMicroSeconds interval = finished.MicroSecondsFrom(started); |
|
383 TheTest.Printf(_L("\tEPOC Bulleted richtext => HTML (Streaming) %4dms\n"), interval.Int64()); |
|
384 |
|
385 CleanupStack::PopAndDestroy(expectedFile); |
|
386 CleanupStack::PopAndDestroy(outputFile); |
|
387 CleanupStack::PopAndDestroy(&writeStream); |
|
388 CleanupStack::PopAndDestroy(&fs); |
|
389 CleanupStack::PopAndDestroy(&readStream); |
|
390 CleanupStack::PopAndDestroy(text); |
|
391 } |
|
392 |
|
393 static CRichText* CreateTranslateTextL() |
|
394 { |
|
395 // Variable definitions |
|
396 CRichText* richText = NULL; |
|
397 CParaFormatLayer* paragraphFormatLayer = NULL; |
|
398 CCharFormatLayer* charFormatLayer = NULL; |
|
399 |
|
400 // Create Paragraph and Char format layers |
|
401 CParaFormat paraFormat; |
|
402 TParaFormatMask paraFormatMask; |
|
403 paragraphFormatLayer = CParaFormatLayer::NewL(¶Format,paraFormatMask); |
|
404 CleanupStack::PushL( paragraphFormatLayer ); |
|
405 charFormatLayer = CCharFormatLayer::NewL(); |
|
406 CleanupStack::PushL(charFormatLayer); |
|
407 // Create Rich Text object |
|
408 richText = CRichText::NewL(paragraphFormatLayer, charFormatLayer, CEditableText::EFlatStorage); |
|
409 CleanupStack::PushL( richText ); |
|
410 |
|
411 // Left Align bulleted text |
|
412 _LIT(KSpecialCharactersString, "<>&"); |
|
413 richText->InsertL( richText->DocumentLength(), KSpecialCharactersString); |
|
414 richText->InsertL( richText->DocumentLength(), CEditableText::EPageBreak); |
|
415 richText->InsertL( richText->DocumentLength(), CEditableText::EPotentialHyphen); |
|
416 richText->InsertL( richText->DocumentLength(), CEditableText::ELineBreak); |
|
417 richText->InsertL( richText->DocumentLength(), CEditableText::ENonBreakingSpace); |
|
418 richText->InsertL( richText->DocumentLength(), CEditableText::ETabCharacter); |
|
419 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
420 |
|
421 CleanupStack::Pop( richText ); |
|
422 CleanupStack::PopAndDestroy( charFormatLayer ); |
|
423 CleanupStack::PopAndDestroy( paragraphFormatLayer ); |
|
424 |
|
425 return richText; |
|
426 } |
|
427 |
|
428 static void DoTranslateTestL(CConverterBase& aConv) |
|
429 { |
|
430 CRichText* text = CreateTranslateTextL(); |
|
431 CleanupStack::PushL(text); |
|
432 TRTPtrBuffer buffer(text); |
|
433 RDesReadStream readStream(buffer); |
|
434 CleanupClosePushL(readStream); |
|
435 |
|
436 RFs fs; |
|
437 User::LeaveIfError(fs.Connect()); |
|
438 CleanupClosePushL(fs); |
|
439 RFileWriteStream writeStream; |
|
440 User::LeaveIfError(writeStream.Replace(fs, KTranslateConvOutputFile1(), EFileStream|EFileWrite|EFileShareExclusive)); |
|
441 CleanupClosePushL(writeStream); |
|
442 |
|
443 TTime started; started.UniversalTime(); |
|
444 aConv.ConvertObjectL(readStream, writeStream, NULL); |
|
445 HBufC8* outputFile = ReadFileLC(KTranslateConvOutputFile1); |
|
446 HBufC8* expectedFile = ReadFileLC(KTranslateConvExpectedFile1); |
|
447 TheTest(outputFile->Compare(*expectedFile)==KErrNone); |
|
448 TTime finished; finished.UniversalTime(); |
|
449 TTimeIntervalMicroSeconds interval = finished.MicroSecondsFrom(started); |
|
450 TheTest.Printf(_L("\tEPOC Bulleted richtext => HTML (Streaming) %4dms\n"), interval.Int64()); |
|
451 |
|
452 CleanupStack::PopAndDestroy(expectedFile); |
|
453 CleanupStack::PopAndDestroy(outputFile); |
|
454 CleanupStack::PopAndDestroy(&writeStream); |
|
455 CleanupStack::PopAndDestroy(&fs); |
|
456 CleanupStack::PopAndDestroy(&readStream); |
|
457 CleanupStack::PopAndDestroy(text); |
|
458 } |
|
459 |
|
460 static CRichText* CreateTextStyleTextL() |
|
461 { |
|
462 // Variable definitions |
|
463 CRichText* richText = NULL; |
|
464 CParaFormatLayer* paragraphFormatLayer = NULL; |
|
465 CCharFormatLayer* charFormatLayer = NULL; |
|
466 |
|
467 // Create Paragraph and Char format layers |
|
468 CParaFormat paraFormat; |
|
469 TParaFormatMask paraFormatMask; |
|
470 paragraphFormatLayer = CParaFormatLayer::NewL(¶Format,paraFormatMask); |
|
471 CleanupStack::PushL( paragraphFormatLayer ); |
|
472 charFormatLayer = CCharFormatLayer::NewL(); |
|
473 CleanupStack::PushL(charFormatLayer); |
|
474 // Create Rich Text object |
|
475 richText = CRichText::NewL(paragraphFormatLayer, charFormatLayer, CEditableText::EFlatStorage); |
|
476 CleanupStack::PushL( richText ); |
|
477 |
|
478 // Left Align bulleted text |
|
479 richText->InsertL( richText->DocumentLength(), _L("This bit is italic, this one is bold, and this one is both.")); |
|
480 TCharFormat format; |
|
481 format.iFontSpec.iFontStyle.SetPosture(EPostureItalic); |
|
482 TCharFormatMask formatMask; |
|
483 formatMask.SetAttrib(EAttFontPosture); |
|
484 richText->ApplyCharFormatL(format,formatMask,12,6); |
|
485 format.iFontSpec.iFontStyle.SetPosture(EPostureUpright); |
|
486 format.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
487 formatMask.SetAttrib(EAttFontStrokeWeight); |
|
488 formatMask.SetAttrib(EAttFontPosture); |
|
489 richText->ApplyCharFormatL(format,formatMask,32,4); |
|
490 format.iFontSpec.iFontStyle.SetPosture(EPostureItalic); |
|
491 richText->ApplyCharFormatL(format,formatMask,54,4); |
|
492 |
|
493 richText->InsertL( richText->DocumentLength(), CEditableText::ELineBreak); |
|
494 richText->InsertL( richText->DocumentLength(), _L("This bit is underlined and this one strikethrough.")); |
|
495 format.iFontPresentation.iUnderline = EUnderlineOn; |
|
496 formatMask.ClearAll(); |
|
497 formatMask.SetAttrib(EAttFontUnderline); |
|
498 richText->ApplyCharFormatL(format,formatMask,72,10); |
|
499 format.iFontPresentation.iStrikethrough = EStrikethroughOn; |
|
500 formatMask.ClearAll(); |
|
501 formatMask.SetAttrib(EAttFontStrikethrough); |
|
502 richText->ApplyCharFormatL(format,formatMask,96,13); |
|
503 |
|
504 richText->InsertL( richText->DocumentLength(), CEditableText::EParagraphDelimiter ); |
|
505 |
|
506 CleanupStack::Pop( richText ); |
|
507 CleanupStack::PopAndDestroy( charFormatLayer ); |
|
508 CleanupStack::PopAndDestroy( paragraphFormatLayer ); |
|
509 |
|
510 return richText; |
|
511 } |
|
512 |
|
513 static void DoTextStyleTestL(CConverterBase& aConv) |
|
514 { |
|
515 CRichText* text = CreateTextStyleTextL(); |
|
516 CleanupStack::PushL(text); |
|
517 TRTPtrBuffer buffer(text); |
|
518 RDesReadStream readStream(buffer); |
|
519 CleanupClosePushL(readStream); |
|
520 |
|
521 RFs fs; |
|
522 User::LeaveIfError(fs.Connect()); |
|
523 CleanupClosePushL(fs); |
|
524 RFileWriteStream writeStream; |
|
525 User::LeaveIfError(writeStream.Replace(fs, KTextStyleConvOutputFile1(), EFileStream|EFileWrite|EFileShareExclusive)); |
|
526 CleanupClosePushL(writeStream); |
|
527 |
|
528 TTime started; started.UniversalTime(); |
|
529 aConv.ConvertObjectL(readStream, writeStream, NULL); |
|
530 HBufC8* outputFile = ReadFileLC(KTextStyleConvOutputFile1); |
|
531 HBufC8* expectedFile = ReadFileLC(KTextStyleConvExpectedFile1); |
|
532 TheTest(outputFile->Compare(*expectedFile)==KErrNone); |
|
533 TTime finished; finished.UniversalTime(); |
|
534 TTimeIntervalMicroSeconds interval = finished.MicroSecondsFrom(started); |
|
535 TheTest.Printf(_L("\tEPOC Bulleted richtext => HTML (Streaming) %4dms\n"), interval.Int64()); |
|
536 |
|
537 CleanupStack::PopAndDestroy(expectedFile); |
|
538 CleanupStack::PopAndDestroy(outputFile); |
|
539 CleanupStack::PopAndDestroy(&writeStream); |
|
540 CleanupStack::PopAndDestroy(&fs); |
|
541 CleanupStack::PopAndDestroy(&readStream); |
|
542 CleanupStack::PopAndDestroy(text); |
|
543 } |
|
544 |
|
545 static void DoTestsL(CCnaConverterList& aList) |
|
546 { |
|
547 CConverterBase* conv = NULL; |
|
548 ConstructTestSourceL(); |
|
549 ConstructTestSourceForBulletedAndFormattedTextL(); |
|
550 // |
|
551 // EPOC ==> HTML |
|
552 // |
|
553 |
|
554 TheTest.Next(_L("Converting EPOC rich text to HTML ")); |
|
555 conv = aList.NewConverterL(KCrt2HTMLConverterUid); |
|
556 TheTest(conv!=NULL); |
|
557 CleanupStack::PushL(conv); |
|
558 |
|
559 TheTest.Next(_L("Testing Uid() and Capabilities() functions")); |
|
560 DoUidAndCapabilitiesTest(*conv); |
|
561 |
|
562 |
|
563 TheTest.Next(_L("Converting simple rich text to HTML using the streaming interface")); |
|
564 DoStreamingTestL(*conv); |
|
565 |
|
566 TheTest.Next(_L("Converting formatted rich text to HTML using the streaming interface")); |
|
567 DoFmtdStreamingTestL(*conv); |
|
568 |
|
569 TheTest.Next(_L("Converting simple rich text to HTML using the file-file interface")); |
|
570 TTime started; started.UniversalTime(); |
|
571 conv->ConvertL(KCnvEPOCSmallDocumentDriveC(), KHtmlOutput(),NULL); |
|
572 HBufC8* htmlOutput = ReadFileLC(KHtmlOutput); |
|
573 HBufC8* testFile = ReadFileLC(KTestFile); |
|
574 TheTest(htmlOutput->Compare(*testFile)==KErrNone); |
|
575 TTime finished; finished.UniversalTime(); |
|
576 TTimeIntervalMicroSeconds interval = finished.MicroSecondsFrom(started); |
|
577 TheTest.Printf(_L("\tEPOC => HTML (Writing) %4dms\n"), interval.Int64()); |
|
578 CleanupStack::PopAndDestroy(testFile); |
|
579 CleanupStack::PopAndDestroy(htmlOutput); |
|
580 |
|
581 //INC042516 - Email, S90_REL_1.1_HK_W02: Wrong format of receipting e-mail |
|
582 // from proto when bullet marks with alignments |
|
583 // |
|
584 // EPOC Bulleted and Formatted richtext to HTML Conversion test |
|
585 // |
|
586 |
|
587 |
|
588 TheTest.Next(_L("Converting formatted rich text to HTML using the file-file interface")); |
|
589 started.UniversalTime(); |
|
590 conv->ConvertL(KFmtdRTCnvTestFile(), KFmtdRT2HtmlConvOutputFile(),NULL); |
|
591 HBufC8* htmlOutputFile = ReadFileLC(KFmtdRT2HtmlConvOutputFile); |
|
592 HBufC8* htmlExpectedFile = ReadFileLC(KFmtdRT2HtmlConvExpectedFile); |
|
593 TheTest(htmlOutputFile->Compare(*htmlExpectedFile)==KErrNone); |
|
594 finished.UniversalTime(); |
|
595 interval = finished.MicroSecondsFrom(started); |
|
596 TheTest.Printf(_L("\tEPOC Bulleted and Formatted richtext => HTML (Writing) %4dms\n"), interval.Int64()); |
|
597 CleanupStack::PopAndDestroy(htmlExpectedFile); |
|
598 CleanupStack::PopAndDestroy(htmlOutputFile); |
|
599 |
|
600 |
|
601 TheTest.Next(_L("Converting bulleted text")); |
|
602 DoBulletTestL(*conv); |
|
603 |
|
604 TheTest.Next(_L("Testing TranslateL function")); |
|
605 DoTranslateTestL(*conv); |
|
606 |
|
607 TheTest.Next(_L("Testing text styles conversion")); |
|
608 DoTextStyleTestL(*conv); |
|
609 |
|
610 CleanupStack::PopAndDestroy(conv); |
|
611 } |
|
612 |
|
613 void doMainL() |
|
614 { |
|
615 /** |
|
616 @SYMTestCaseID PIM-CNVHTMLTEST-0001 |
|
617 */ |
|
618 TheTest.Start(_L("@SYMTestCaseID PIM-CNVHTMLTEST-0001 Preparing to start...")); |
|
619 |
|
620 TheTest.Next(_L("Create converter list")); |
|
621 CCnaConverterList* convList = CCnaConverterList::NewLC(); |
|
622 DoTestsL(*convList); |
|
623 CleanupStack::PopAndDestroy(); // convList |
|
624 REComSession::FinalClose(); //needed, otherwise you will get a memory leak |
|
625 TheTest.Printf(_L("\nTests complete\n")); |
|
626 TheTest.End(); |
|
627 TheTest.Close(); |
|
628 } |
|
629 |
|
630 GLDEF_C TInt E32Main() |
|
631 { |
|
632 __UHEAP_MARK; |
|
633 |
|
634 CTrapCleanup* theCleanup=CTrapCleanup::New(); |
|
635 TRAPD(ret,doMainL()); |
|
636 TheTest(ret==KErrNone); |
|
637 delete theCleanup; |
|
638 |
|
639 __UHEAP_MARKEND; |
|
640 return(KErrNone); |
|
641 } |