|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 |
|
22 #include <gdi.h> |
|
23 #include <conpics.h> |
|
24 #include <s32file.h> |
|
25 #include <e32test.h> |
|
26 |
|
27 #include <txtrich.h> |
|
28 #include <txtfmlyr.h> |
|
29 #include "TXTMRTSR.H" |
|
30 |
|
31 #include "../incp/T_PMLPAR.H" |
|
32 #include "../spml/T_PMLPAR.CPP" |
|
33 |
|
34 /* this fixes a MSVC link warning */ |
|
35 #ifdef __VC32__ |
|
36 #pragma comment (linker, "/opt:noref") |
|
37 #endif |
|
38 |
|
39 #define UNUSED_VAR(a) a = a |
|
40 |
|
41 const TInt KTestCleanupStack=0x40; |
|
42 |
|
43 _LIT(KExportFileName1, "c:\\etext\\t_para.txg"); |
|
44 _LIT(KExportFileName2, "c:\\etext\\t_para2.txg"); |
|
45 |
|
46 void EnsureFileExists(const TDesC& aName) |
|
47 { |
|
48 RFs fs; |
|
49 fs.Connect(); |
|
50 fs.MkDirAll(aName); |
|
51 RFile file; |
|
52 file.Create(fs, aName, EFileRead|EFileWrite); |
|
53 file.Close(); |
|
54 fs.Close(); |
|
55 } |
|
56 |
|
57 class CContainer : public CBase, public MRichTextStoreResolver |
|
58 { |
|
59 public: |
|
60 static CContainer* NewL(TFileName aFileName); |
|
61 ~CContainer(); |
|
62 // |
|
63 // Mixin |
|
64 // |
|
65 virtual const CStreamStore& StreamStoreL(TInt aPos)const; |
|
66 // Methods |
|
67 TStreamId StoreL(CStreamStore& aStore)const; |
|
68 void RestoreL(const CStreamStore& aStore,TStreamId aId,MPictureFactory* aFctry); |
|
69 protected: |
|
70 CContainer(); |
|
71 void ConstructL(TFileName aFileName); |
|
72 public: |
|
73 CRichText* iText; |
|
74 const CParaFormatLayer* iGlobalParaFormatLayer; |
|
75 const CCharFormatLayer* iGlobalCharFormatLayer; |
|
76 }; |
|
77 |
|
78 |
|
79 LOCAL_D RTest test(_L("Testing Picture Restorer mechanism")); |
|
80 LOCAL_D CTrapCleanup* TheTrapCleanup; |
|
81 LOCAL_D RFs TheFs; // the file server |
|
82 LOCAL_D RFile TheFile; // the data file |
|
83 LOCAL_D CParser* TheParser; |
|
84 LOCAL_D CContainer* TheContainer; |
|
85 LOCAL_D CStreamStore* TheDeferredPictureStore; |
|
86 |
|
87 CContainer* CContainer::NewL(TFileName aFileName) |
|
88 // Create new container & set its components. |
|
89 // |
|
90 { |
|
91 CContainer* self=new(ELeave) CContainer; |
|
92 CleanupStack::PushL(self); |
|
93 self->ConstructL(aFileName); |
|
94 CleanupStack::Pop(); |
|
95 return self; |
|
96 } |
|
97 |
|
98 |
|
99 CContainer::CContainer() |
|
100 { |
|
101 } |
|
102 |
|
103 |
|
104 void CContainer::ConstructL(TFileName aFileName) |
|
105 { |
|
106 TheParser=CParser::NewL(); |
|
107 CleanupStack::PushL(TheParser); |
|
108 iText=TheParser->ParseL(aFileName); |
|
109 CleanupStack::PopAndDestroy(); |
|
110 iGlobalParaFormatLayer=iText->GlobalParaFormatLayer(); |
|
111 iGlobalCharFormatLayer=iText->GlobalCharFormatLayer(); |
|
112 } |
|
113 |
|
114 |
|
115 CContainer::~CContainer() |
|
116 { |
|
117 delete iText; |
|
118 delete (CParaFormatLayer*)iGlobalParaFormatLayer; |
|
119 delete (CCharFormatLayer*)iGlobalCharFormatLayer; |
|
120 } |
|
121 |
|
122 |
|
123 const CStreamStore& CContainer::StreamStoreL(TInt /*aPos*/)const |
|
124 // Return the deferred picture store. |
|
125 // In this instance, the deferred picture store does not vary with document position. |
|
126 // |
|
127 {return *TheDeferredPictureStore;} |
|
128 |
|
129 |
|
130 TStreamId CContainer::StoreL(CStreamStore& aStore)const |
|
131 // Store this component |
|
132 // |
|
133 { |
|
134 CStoreMap* map=CStoreMap::NewLC(aStore); |
|
135 iText->StoreComponentsL(aStore,*map); |
|
136 // |
|
137 RStoreWriteStream stream(*map); |
|
138 TStreamId id=stream.CreateLC(aStore); |
|
139 iGlobalParaFormatLayer->ExternalizeL(stream); |
|
140 iGlobalCharFormatLayer->ExternalizeL(stream); |
|
141 stream<< *iText; |
|
142 stream.CommitL(); |
|
143 // |
|
144 map->Reset(); |
|
145 CleanupStack::PopAndDestroy(2); |
|
146 return id; |
|
147 } |
|
148 |
|
149 |
|
150 void CContainer::RestoreL(const CStreamStore& aStore,TStreamId aId,MPictureFactory* aFactory) |
|
151 // Restore this component |
|
152 // |
|
153 { |
|
154 RStoreReadStream stream; |
|
155 stream.OpenLC(aStore,aId); |
|
156 iGlobalParaFormatLayer=CParaFormatLayer::NewL(stream); |
|
157 iGlobalCharFormatLayer=CCharFormatLayer::NewL(stream); |
|
158 iText=CRichText::NewL(iGlobalParaFormatLayer,iGlobalCharFormatLayer); |
|
159 iText->SetPictureFactory(aFactory,this); |
|
160 stream>> *iText; |
|
161 // |
|
162 CleanupStack::PopAndDestroy(); |
|
163 // |
|
164 iText->RestoreComponentsL(aStore); |
|
165 } |
|
166 |
|
167 |
|
168 /*LOCAL_C void testPictureRestorer(TBool aDeferPictureLoad=ETrue) |
|
169 // Test Picture persistance. |
|
170 // |
|
171 { |
|
172 // |
|
173 TheFs.Connect(); |
|
174 // |
|
175 TheStore=CDirectFileStore::ReplaceL(TheFs,_L("c:\\etext\\t_word.doc"),EFileRead|EFileWrite); |
|
176 TheDeferredPictureStore=TheStore; |
|
177 CleanupStack::PushL(TheStore); |
|
178 TheStore->SetTypeL(KDirectFileStoreLayout); |
|
179 // |
|
180 // Create concrete picture factory. |
|
181 MDemPictureFactory* factory=new(ELeave) MDemPictureFactory; |
|
182 |
|
183 TheContainer->iText->Reset(); |
|
184 TheContainer->iText->InsertL(0,_L("Hello Duncan how")); |
|
185 |
|
186 TheContainer->iText->SetPictureFactory(factory,TheContainer); |
|
187 // Create some pictures. |
|
188 CXzePicture* pic1=CXzePicture::NewL('x'); |
|
189 CleanupStack::PushL(pic1); |
|
190 CXzePicture* pic2=CXzePicture::NewL('z'); |
|
191 CleanupStack::PushL(pic2); |
|
192 CXzePicture* pic3=CXzePicture::NewL('e'); |
|
193 CleanupStack::PushL(pic3); |
|
194 // |
|
195 // Create the picture headers |
|
196 TPictureHeader hdr1; |
|
197 TPictureHeader hdr2; |
|
198 TPictureHeader hdr3; |
|
199 // |
|
200 TSize size; |
|
201 pic1->GetSizeInTwips(size); |
|
202 hdr1.iPictureType=KUidXzePictureType; |
|
203 hdr1.iPicture=pic1; |
|
204 hdr2.iPictureType=KUidXzePictureType; |
|
205 hdr2.iPicture=pic2; |
|
206 hdr3.iPictureType=KUidXzePictureType; |
|
207 hdr3.iPicture=pic3; |
|
208 // |
|
209 // Insert the pictures into the rich text |
|
210 TBool hasMarkupData=TheContainer->iText->HasMarkupData(); |
|
211 test(!hasMarkupData); |
|
212 TheContainer->iText->CancelInsertCharFormat(); |
|
213 TheContainer->iText->InsertL(0,hdr1); |
|
214 TheContainer->iText->InsertL(5,hdr2); |
|
215 TheContainer->iText->InsertL(7,hdr3); |
|
216 TheContainer->iText->InsertL(0,CEditableText::EParagraphDelimiter); |
|
217 TheContainer->iText->CancelInsertCharFormat(); |
|
218 TheContainer->iText->InsertL(2,CEditableText::EParagraphDelimiter); |
|
219 CleanupStack::Pop(3); |
|
220 hasMarkupData=TheContainer->iText->HasMarkupData(); |
|
221 test(hasMarkupData); |
|
222 // |
|
223 // High level Store context |
|
224 TStreamId id=TheContainer->StoreL(*TheStore); |
|
225 // |
|
226 delete TheContainer->iText; |
|
227 delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer; |
|
228 delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer; |
|
229 // |
|
230 // |
|
231 // Now restore the container with rich text |
|
232 TheContainer->RestoreL(*TheStore,id,factory); |
|
233 if (!aDeferPictureLoad) |
|
234 TheContainer->iText->LoadAllPicturesNowL(); |
|
235 // |
|
236 hasMarkupData=TheContainer->iText->HasMarkupData(); |
|
237 test(hasMarkupData); |
|
238 test(TheContainer->iText->ParagraphCount()==3); |
|
239 test(TheContainer->iText->DocumentLength()==21); |
|
240 TPtrC view; |
|
241 TCharFormat format; |
|
242 CPicture* picture; |
|
243 // |
|
244 // TEST THE PICTURE HEADERS, DEPENDING ON WHETHER DEFERRED LOADING IS SET OR NOT |
|
245 TPictureHeader hdrA=TheContainer->iText->PictureHeader(1); |
|
246 test(hdrA.iPictureType==KUidXzePictureType); |
|
247 if (aDeferPictureLoad) |
|
248 { |
|
249 test(hdrA.iPicture.IsId()); |
|
250 } |
|
251 else |
|
252 { |
|
253 test(hdrA.iPicture!=NULL); |
|
254 test(hdrA.iPicture.IsPtr()); |
|
255 test(((CXzePicture*)hdrA.iPicture.AsPtr())->iLabel=='x'); |
|
256 } |
|
257 TPictureHeader hdrB=TheContainer->iText->PictureHeader(7); |
|
258 test(hdrB.iPictureType==KUidXzePictureType); |
|
259 if (aDeferPictureLoad) |
|
260 { |
|
261 test(hdrB.iPicture.IsId()); |
|
262 } |
|
263 else |
|
264 { |
|
265 test(hdrB.iPicture!=NULL); |
|
266 test(hdrB.iPicture.IsPtr()); |
|
267 test(((CXzePicture*)hdrB.iPicture.AsPtr())->iLabel=='z'); |
|
268 } |
|
269 TPictureHeader hdrC=TheContainer->iText->PictureHeader(9); |
|
270 test(hdrC.iPictureType==KUidXzePictureType); |
|
271 if (aDeferPictureLoad) |
|
272 { |
|
273 test(hdrC.iPicture.IsId()); |
|
274 } |
|
275 else |
|
276 { |
|
277 test(hdrC.iPicture!=NULL); |
|
278 test(hdrC.iPicture.IsPtr()); |
|
279 test(((CXzePicture*)hdrC.iPicture.AsPtr())->iLabel=='e'); |
|
280 } |
|
281 TPictureHeader hdrD=TheContainer->iText->PictureHeader(0); // This is not a picture character |
|
282 test(hdrD.iPictureType==KNullUid); |
|
283 test(hdrD.iPicture==NULL); |
|
284 TSize dummySize; |
|
285 test(hdrD.iSize==dummySize); |
|
286 // |
|
287 TheContainer->iText->GetChars(view,format,1); |
|
288 test(view[0]==CEditableText::EPictureCharacter); |
|
289 picture=TheContainer->iText->PictureHandleL(1); |
|
290 test(((CXzePicture*)picture)->iLabel=='x'); |
|
291 |
|
292 TheContainer->iText->GetChars(view,format,7); |
|
293 test(view[0]==CEditableText::EPictureCharacter); |
|
294 picture=TheContainer->iText->PictureHandleL(7); |
|
295 test(((CXzePicture*)picture)->iLabel=='z'); |
|
296 |
|
297 TheContainer->iText->GetChars(view,format,9); |
|
298 test(view[0]==CEditableText::EPictureCharacter); |
|
299 picture=TheContainer->iText->PictureHandleL(9); |
|
300 test(((CXzePicture*)picture)->iLabel=='e'); |
|
301 |
|
302 delete factory; |
|
303 CleanupStack::PopAndDestroy(); // TheStore |
|
304 TheFs.Close(); |
|
305 } |
|
306 |
|
307 |
|
308 LOCAL_C void testPictureRestorer2(TBool aAlwaysFailToLoad=EFalse) |
|
309 // Test Picture persistance. |
|
310 // |
|
311 { |
|
312 // |
|
313 TheFs.Connect(); |
|
314 // |
|
315 TheStore=CDirectFileStore::ReplaceL(TheFs,_L("c:\\etext\\t_word1.doc"),EFileRead|EFileWrite); |
|
316 TheDeferredPictureStore=TheStore; |
|
317 CleanupStack::PushL(TheStore); |
|
318 TheStore->SetTypeL(KDirectFileStoreLayout); |
|
319 // |
|
320 // Create concrete picture factory. |
|
321 MDemPictureFactory* factory=new(ELeave) MDemPictureFactory; |
|
322 |
|
323 TheContainer->iText->Reset(); |
|
324 TheContainer->iText->InsertL(0,_L("Hello Duncan how")); |
|
325 |
|
326 TheContainer->iText->SetPictureFactory(factory,TheContainer); |
|
327 // Create some pictures. |
|
328 CXzeDoor* pic1=CXzeDoor::NewL('x',aAlwaysFailToLoad); |
|
329 CleanupStack::PushL(pic1); |
|
330 CXzeDoor* pic2=CXzeDoor::NewL('z',aAlwaysFailToLoad); |
|
331 CleanupStack::PushL(pic2); |
|
332 CXzePicture* pic3=CXzePicture::NewL('e'); // Control: will always load. |
|
333 CleanupStack::PushL(pic3); |
|
334 // |
|
335 // Create the picture headers |
|
336 TPictureHeader hdr1; |
|
337 TPictureHeader hdr2; |
|
338 TPictureHeader hdr3; |
|
339 // |
|
340 TSize size; |
|
341 pic1->GetSizeInTwips(size); |
|
342 hdr1.iPictureType=KUidXzeDoorType; |
|
343 hdr1.iPicture=pic1; |
|
344 hdr2.iPictureType=KUidXzeDoorType; |
|
345 hdr2.iPicture=pic2; |
|
346 hdr3.iPictureType=KUidXzePictureType; |
|
347 hdr3.iPicture=pic3; |
|
348 // |
|
349 // Insert the pictures into the rich text |
|
350 TBool hasMarkupData=TheContainer->iText->HasMarkupData(); |
|
351 test(!hasMarkupData); |
|
352 TheContainer->iText->CancelInsertCharFormat(); |
|
353 TheContainer->iText->InsertL(0,hdr1); |
|
354 TheContainer->iText->InsertL(5,hdr2); |
|
355 TheContainer->iText->InsertL(7,hdr3); |
|
356 TheContainer->iText->InsertL(0,CEditableText::EParagraphDelimiter); |
|
357 TheContainer->iText->CancelInsertCharFormat(); |
|
358 TheContainer->iText->InsertL(2,CEditableText::EParagraphDelimiter); |
|
359 CleanupStack::Pop(3); // pic1,2,3 - ownership transferred to rich text |
|
360 hasMarkupData=TheContainer->iText->HasMarkupData(); |
|
361 test(hasMarkupData); |
|
362 // |
|
363 // High level Store context - all pictures currently in memory |
|
364 TStreamId id=TheContainer->StoreL(*TheStore); |
|
365 // |
|
366 delete TheContainer->iText; |
|
367 delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer; |
|
368 delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer; |
|
369 // |
|
370 // |
|
371 // Now restore the container with rich text |
|
372 TheContainer->RestoreL(*TheStore,id,factory); |
|
373 // |
|
374 // |
|
375 // Now store the stuff again |
|
376 TInt error=TheContainer->iText->LoadAllPicturesNowL(); |
|
377 if (error==KErrNotFound) |
|
378 test.Printf(_L(" SIMULATION: Some picture data has been removed as no app could be found.")); |
|
379 // if (aAlwaysFailToLoad) |
|
380 // test(error==KErrNotFound); |
|
381 // else |
|
382 // test(error==KErrNone); |
|
383 id=KNullStreamId; |
|
384 TRAP(error, |
|
385 id=TheContainer->StoreL(*TheStore)); |
|
386 test(error==KErrNone); |
|
387 // |
|
388 // ...and restore it to check what we have got. |
|
389 delete TheContainer->iText; |
|
390 delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer; |
|
391 delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer; |
|
392 TheContainer->RestoreL(*TheStore,id,factory); |
|
393 TInt pictureCount=TheContainer->iText->PictureCount(); |
|
394 if (aAlwaysFailToLoad) |
|
395 test(pictureCount==1); |
|
396 else |
|
397 test(pictureCount==3); |
|
398 // |
|
399 delete factory; |
|
400 CleanupStack::PopAndDestroy(); // TheStore |
|
401 TheFs.Close(); |
|
402 }*/ |
|
403 |
|
404 |
|
405 LOCAL_C void CompareRichTextL(CRichText *aDoc1,CRichText *aDoc2) |
|
406 // |
|
407 { |
|
408 test.Start(_L("Comparing Documents")); |
|
409 TInt length; |
|
410 TInt num1,num2; |
|
411 TInt ii=0,len1,len2,pos1,pos2,oldPos; |
|
412 |
|
413 test.Next(_L("Document Length")); |
|
414 length=aDoc1->LdDocumentLength(); |
|
415 num2=aDoc2->LdDocumentLength(); |
|
416 test(length==num2); |
|
417 |
|
418 test.Next(_L("Paragraph Count")); |
|
419 num1=aDoc1->ParagraphCount(); |
|
420 num2=aDoc2->ParagraphCount(); |
|
421 test(num1==num2); |
|
422 |
|
423 test.Next(_L("Paragraph Lengths")); |
|
424 pos1=-1; |
|
425 oldPos=-2; |
|
426 while (pos1>oldPos) |
|
427 { |
|
428 oldPos=pos1; |
|
429 pos1=aDoc1->CharPosOfParagraph(len1,ii); |
|
430 pos2=aDoc2->CharPosOfParagraph(len2,ii); |
|
431 test(len1==len2); |
|
432 test(pos1==pos2); |
|
433 ii++; |
|
434 } |
|
435 |
|
436 test.Next(_L("Word Count")); |
|
437 num1=aDoc1->WordCount(); |
|
438 num2=aDoc2->WordCount(); |
|
439 test(num1==num2); |
|
440 |
|
441 test.Next(_L("Characters")); |
|
442 TCharFormat format1,format2; |
|
443 TPtrC chars1,chars2; |
|
444 len1=1; |
|
445 ii=0; |
|
446 while (ii<=length) |
|
447 { |
|
448 aDoc1->GetChars(chars1,format1,ii); |
|
449 aDoc2->GetChars(chars2,format2,ii); |
|
450 len1=Min(chars1.Length(),chars2.Length()); |
|
451 test(chars1.Left(len1)==chars2.Left(len1)); |
|
452 test(format1.IsEqual(format2)); |
|
453 test(format2.IsEqual(format1)); |
|
454 ii+=len1; |
|
455 } |
|
456 |
|
457 test.End(); |
|
458 } |
|
459 |
|
460 |
|
461 LOCAL_C void GoL() |
|
462 // Run the tests |
|
463 // |
|
464 { |
|
465 CParaFormatLayer* pLayer=CParaFormatLayer::NewL(); |
|
466 CCharFormatLayer* cLayer=CCharFormatLayer::NewL(); |
|
467 CRichText *document=CRichText::NewL(pLayer,cLayer); |
|
468 TInt err; |
|
469 |
|
470 test.Start(_L("Document with single Paragraph")); |
|
471 test.Next(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TRAN-0001 ")); |
|
472 { |
|
473 TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para.pml")); |
|
474 test.Start(_L("Exporting a file by Para")); |
|
475 TFileName exportFile=KExportFileName1(); |
|
476 EnsureFileExists(exportFile); |
|
477 TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByParagraph,0)); |
|
478 test(err==KErrNone); |
|
479 test.Next(_L("Importing a file by Para")); |
|
480 document->Reset(); |
|
481 TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByParagraph); |
|
482 test(charsImported>0); |
|
483 test.Next(_L("Comparing Result")); |
|
484 TRAP(err,CompareRichTextL(TheContainer->iText,document)); |
|
485 test(err==KErrNone); |
|
486 delete TheContainer; |
|
487 } |
|
488 |
|
489 { |
|
490 TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para.pml")); |
|
491 test.Next(_L("Exporting and Importing a file by Line")); |
|
492 test.Start(_L("Line Lengths 25,30,...,95")); |
|
493 TFileName exportFile=KExportFileName1(); |
|
494 TInt ii; |
|
495 for(ii=25;ii<100;ii+=5) |
|
496 { |
|
497 test.Next(_L("With next line length")); |
|
498 EnsureFileExists(exportFile); |
|
499 TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByLine,ii)); |
|
500 test(err==KErrNone); |
|
501 document->Reset(); |
|
502 TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByLine); |
|
503 test(charsImported>0); |
|
504 TRAP(err,CompareRichTextL(TheContainer->iText,document)); |
|
505 test(err==KErrNone); |
|
506 } |
|
507 delete TheContainer; |
|
508 test.End(); |
|
509 } |
|
510 |
|
511 test.End(); |
|
512 test.Next(_L("Document with two Paragraphs")); |
|
513 |
|
514 { |
|
515 TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para2.pml")); |
|
516 test.Start(_L("Exporting a file by Para")); |
|
517 TFileName exportFile=KExportFileName2(); |
|
518 EnsureFileExists(exportFile); |
|
519 TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByParagraph,0)); |
|
520 test(err==KErrNone); |
|
521 test.Next(_L("Importing a file by Para")); |
|
522 document->Reset(); |
|
523 TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByParagraph); |
|
524 test(charsImported>0); |
|
525 test.Next(_L("Comparing Result")); |
|
526 TRAP(err,CompareRichTextL(TheContainer->iText,document)); |
|
527 test(err==KErrNone); |
|
528 delete TheContainer; |
|
529 } |
|
530 |
|
531 { |
|
532 TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para.pml")); |
|
533 test.Next(_L("Exporting and Importing a file by Line")); |
|
534 test.Start(_L("Line Lengths 30,40,...,100")); |
|
535 TFileName exportFile=KExportFileName1(); |
|
536 TInt ii; |
|
537 for(ii=30;ii<105;ii+=10) |
|
538 { |
|
539 test.Next(_L("With next line length")); |
|
540 EnsureFileExists(exportFile); |
|
541 TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByLine,ii)); |
|
542 test(err==KErrNone); |
|
543 document->Reset(); |
|
544 TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByLine); |
|
545 test(charsImported>0); |
|
546 TRAP(err,CompareRichTextL(TheContainer->iText,document)); |
|
547 test(err==KErrNone); |
|
548 } |
|
549 delete TheContainer; |
|
550 test.End(); |
|
551 } |
|
552 |
|
553 delete document; |
|
554 delete cLayer; |
|
555 delete pLayer; |
|
556 |
|
557 test.End(); |
|
558 } |
|
559 |
|
560 |
|
561 LOCAL_C void setupCleanup() |
|
562 // |
|
563 // Initialise the cleanup stack. |
|
564 // |
|
565 { |
|
566 |
|
567 TheTrapCleanup=CTrapCleanup::New(); |
|
568 TRAPD(r,\ |
|
569 {\ |
|
570 for (TInt i=KTestCleanupStack;i>0;i--)\ |
|
571 CleanupStack::PushL((TAny*)1);\ |
|
572 test(r==KErrNone);\ |
|
573 CleanupStack::Pop(KTestCleanupStack);\ |
|
574 }); |
|
575 } |
|
576 |
|
577 |
|
578 LOCAL_C void DeleteDataFile(const TDesC& aFullName) |
|
579 { |
|
580 RFs fsSession; |
|
581 TInt err = fsSession.Connect(); |
|
582 if(err == KErrNone) |
|
583 { |
|
584 TEntry entry; |
|
585 if(fsSession.Entry(aFullName, entry) == KErrNone) |
|
586 { |
|
587 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); |
|
588 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); |
|
589 if(err != KErrNone) |
|
590 { |
|
591 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); |
|
592 } |
|
593 err = fsSession.Delete(aFullName); |
|
594 if(err != KErrNone) |
|
595 { |
|
596 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); |
|
597 } |
|
598 } |
|
599 fsSession.Close(); |
|
600 } |
|
601 else |
|
602 { |
|
603 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); |
|
604 } |
|
605 } |
|
606 |
|
607 GLDEF_C TInt E32Main() |
|
608 // |
|
609 // Test the streaming framework. |
|
610 // |
|
611 { |
|
612 |
|
613 test.Title(); |
|
614 |
|
615 __UHEAP_MARK; |
|
616 setupCleanup(); |
|
617 TRAPD(r,GoL()); |
|
618 test(r == KErrNone); |
|
619 |
|
620 delete TheTrapCleanup; |
|
621 |
|
622 __UHEAP_MARKEND; |
|
623 |
|
624 ::DeleteDataFile(KExportFileName1); //deletion of data files must be before call to End() - DEF047652 |
|
625 ::DeleteDataFile(KExportFileName2); |
|
626 |
|
627 test.End(); |
|
628 test.Close(); |
|
629 |
|
630 return 0; |
|
631 } |