|
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 <txtrich.h> |
|
20 #include "TSTCLIPB.H" |
|
21 #include <txtstyle.h> |
|
22 #include <e32test.h> |
|
23 #include <gdi.h> |
|
24 #include <conpics.h> |
|
25 #include <flddef.h> |
|
26 #include <fldbltin.h> |
|
27 #include <s32mem.h> |
|
28 #include <s32file.h> |
|
29 #include "../incp/T_PMLPAR.H" |
|
30 |
|
31 const TInt KTestCleanupStack=0x500; |
|
32 GLDEF_C RTest test(_L("TRICHOOM")); |
|
33 LOCAL_D RFs theFs; |
|
34 LOCAL_D CParaFormatLayer* GlobalParaFormatLayer; |
|
35 LOCAL_D CCharFormatLayer* GlobalCharFormatLayer; |
|
36 LOCAL_D MPictureFactory* GlobalPictureFactory; |
|
37 LOCAL_D CTrapCleanup* TheTrapCleanup; |
|
38 LOCAL_D CParser* TheParser; |
|
39 LOCAL_D RFs TheSession; |
|
40 |
|
41 |
|
42 LOCAL_C CRichText* LoadIntoTextL(TFileName& aFileName) |
|
43 // |
|
44 { |
|
45 TRAPD(ret, |
|
46 TheParser=CParser::NewL()); |
|
47 CRichText* text=NULL; |
|
48 TRAP(ret, |
|
49 text=TheParser->ParseL(aFileName)); |
|
50 delete GlobalParaFormatLayer; |
|
51 delete GlobalCharFormatLayer; |
|
52 GlobalParaFormatLayer=(CParaFormatLayer*)text->GlobalParaFormatLayer(); |
|
53 GlobalCharFormatLayer=(CCharFormatLayer*)text->GlobalCharFormatLayer(); |
|
54 delete TheParser; |
|
55 TheParser=NULL; |
|
56 return text; |
|
57 } |
|
58 |
|
59 |
|
60 LOCAL_D void ConstructOOM() |
|
61 // Test CRichText construction, (and index), forcing a leave error at each |
|
62 // possible stage of the process. |
|
63 // |
|
64 { |
|
65 test.Start(_L("Construction under low memory conditions")); |
|
66 |
|
67 CParaFormatLayer* paraLayer=CParaFormatLayer::NewL(); |
|
68 CCharFormatLayer* charLayer=CCharFormatLayer::NewL(); |
|
69 TInt failRate=0; |
|
70 CRichText* doc=NULL; |
|
71 for (failRate=1;;failRate++) |
|
72 { |
|
73 __UHEAP_RESET; |
|
74 __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); |
|
75 __UHEAP_MARK; |
|
76 TRAPD(ret,doc=CRichText::NewL(paraLayer,charLayer)); |
|
77 if (ret!=KErrNone) |
|
78 { |
|
79 __UHEAP_MARKEND; |
|
80 test(doc==NULL); |
|
81 } |
|
82 else |
|
83 { |
|
84 test(doc!=NULL); |
|
85 // test(!doc->HasMarkupData()); |
|
86 delete doc; |
|
87 __UHEAP_MARKEND; |
|
88 break; |
|
89 } |
|
90 } |
|
91 __UHEAP_RESET; |
|
92 delete paraLayer; |
|
93 delete charLayer; |
|
94 TBuf<36> answer; |
|
95 answer.Format(_L(" #allocs for full c'tion: %d\n"),failRate-1); |
|
96 test.Printf(answer); |
|
97 } |
|
98 |
|
99 |
|
100 LOCAL_D void CopyPasteOOM() |
|
101 { |
|
102 // Set up the framework |
|
103 test.Next(_L("Copy/Paste OOM")); |
|
104 CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
105 TFileName file=_L("z:\\test\\app-framework\\etext\\climb.txt"); |
|
106 /*TInt count=*/richText1->ImportTextFileL(0,file,CPlainText::EOrganiseByParagraph); |
|
107 // |
|
108 // Insert some picture components |
|
109 CXzePicture* pic1=CXzePicture::NewL('p'); |
|
110 CXzePicture* pic2=CXzePicture::NewL('l'); |
|
111 CXzePicture* pic3=CXzePicture::NewL('l'); |
|
112 TPictureHeader hdr1; |
|
113 TPictureHeader hdr2; |
|
114 TPictureHeader hdr3; |
|
115 hdr1.iPictureType = KUidXzePictureType; |
|
116 hdr2.iPictureType = KUidXzePictureType; |
|
117 hdr3.iPictureType = KUidXzePictureType; |
|
118 hdr1.iPicture = pic1; |
|
119 hdr2.iPicture = pic2; |
|
120 hdr3.iPicture = pic3; |
|
121 richText1->InsertL(richText1->DocumentLength(),hdr3); |
|
122 richText1->InsertL(richText1->DocumentLength(),hdr2); |
|
123 richText1->InsertL(richText1->DocumentLength(),hdr1); |
|
124 // |
|
125 // Apply some random formatting |
|
126 TCharFormat charFormat; TCharFormatMask charMask; |
|
127 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
128 charMask.SetAttrib(EAttFontStrokeWeight); |
|
129 richText1->ApplyCharFormatL(charFormat,charMask,10,37); |
|
130 // |
|
131 // Copy to clipboard normally. |
|
132 test.Start(_L("Copy Normally")); |
|
133 User::LeaveIfError(TheSession.Connect()); |
|
134 CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession); |
|
135 richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),0,richText1->DocumentLength()-1); // forces virtual trailing phrase |
|
136 writeBoard->CommitL(); |
|
137 CleanupStack::PopAndDestroy(); // writeboard |
|
138 writeBoard=NULL; |
|
139 delete richText1; |
|
140 richText1=NULL; |
|
141 // |
|
142 // Paste from clipboard normally. |
|
143 test.Next(_L("Paste Normally")); |
|
144 __UHEAP_MARK; |
|
145 CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
146 MDemPictureFactory pictureFactory; |
|
147 empty->SetPictureFactory(&pictureFactory,NULL); |
|
148 CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession); |
|
149 TRAPD(ret, |
|
150 empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),0)); |
|
151 test(ret==KErrNone); |
|
152 delete empty; |
|
153 empty=NULL; |
|
154 CleanupStack::PopAndDestroy(); // readBoard |
|
155 readBoard=NULL; |
|
156 __UHEAP_MARKEND; |
|
157 // |
|
158 // Paste from clipboard with OOM |
|
159 test.Next(_L("Paste with OOM")); |
|
160 test.Next(_L("...please wait")); |
|
161 __UHEAP_MARK; |
|
162 empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
163 for (TInt ii=1; ;ii++) |
|
164 { |
|
165 readBoard=CClipboard::NewForReadingLC(TheSession); |
|
166 __UHEAP_SETFAIL(RHeap::EDeterministic,ii); |
|
167 TRAP(ret,empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),0)); |
|
168 __UHEAP_RESET; |
|
169 empty->Reset(); |
|
170 CleanupStack::PopAndDestroy(); |
|
171 if (ret==KErrNone) |
|
172 break; |
|
173 } |
|
174 readBoard=NULL; |
|
175 |
|
176 // |
|
177 delete empty; |
|
178 empty=NULL; |
|
179 TheSession.Close(); |
|
180 __UHEAP_MARKEND; |
|
181 test.End(); |
|
182 } |
|
183 |
|
184 |
|
185 LOCAL_D void CopyPasteOOM2() |
|
186 // Test case for defect HA-282 - simple case |
|
187 // |
|
188 { |
|
189 __UHEAP_MARK; |
|
190 // Set up the framework |
|
191 test.Next(_L("Copy/Paste OOM 2")); |
|
192 CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
193 richText1->InsertL(0,_L("HelloHello")); |
|
194 richText1->InsertL(5,CEditableText::EParagraphDelimiter); |
|
195 // |
|
196 // Format the first paragraph |
|
197 TCharFormat charFormat; TCharFormatMask charMask; |
|
198 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
199 charMask.SetAttrib(EAttFontStrokeWeight); |
|
200 richText1->ApplyCharFormatL(charFormat,charMask,0,6); |
|
201 // |
|
202 // Copy to clipboard normally. |
|
203 test.Start(_L("Copy Normally")); |
|
204 User::LeaveIfError(TheSession.Connect()); |
|
205 CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession); |
|
206 richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),2,6); // forces virtual trailing phrase |
|
207 writeBoard->CommitL(); |
|
208 CleanupStack::PopAndDestroy(); // writeboard |
|
209 writeBoard=NULL; |
|
210 // |
|
211 // Paste from clipboard normally. |
|
212 test.Next(_L("Paste Normally")); |
|
213 // __UHEAP_MARK; |
|
214 CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
215 empty->AppendTakingSolePictureOwnershipL(*richText1); |
|
216 CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession); |
|
217 TRAPD(ret, |
|
218 empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),empty->DocumentLength())); |
|
219 test(ret==KErrNone); |
|
220 delete empty; |
|
221 empty=NULL; |
|
222 CleanupStack::PopAndDestroy(); // readBoard |
|
223 readBoard=NULL; |
|
224 // __UHEAP_MARKEND; |
|
225 // |
|
226 // Paste from clipboard with OOM |
|
227 test.Next(_L("Paste with OOM")); |
|
228 test.Next(_L("...please wait")); |
|
229 __UHEAP_MARK; |
|
230 empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
231 empty->AppendTakingSolePictureOwnershipL(*richText1); |
|
232 delete richText1; |
|
233 richText1=NULL; |
|
234 for (TInt ii=1; ;ii++) |
|
235 { |
|
236 readBoard=CClipboard::NewForReadingLC(TheSession); |
|
237 __UHEAP_SETFAIL(RHeap::EDeterministic,ii); |
|
238 TRAP(ret,empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),empty->DocumentLength())); |
|
239 __UHEAP_RESET; |
|
240 // empty->Reset(); |
|
241 CleanupStack::PopAndDestroy(); |
|
242 if (ret==KErrNone) |
|
243 break; |
|
244 } |
|
245 readBoard=NULL; |
|
246 // |
|
247 delete empty; |
|
248 empty=NULL; |
|
249 __UHEAP_MARKEND; |
|
250 TheSession.Close(); |
|
251 __UHEAP_MARKEND; |
|
252 test.End(); |
|
253 } |
|
254 |
|
255 |
|
256 LOCAL_D void WriteInlineL(RWriteStream& aStream,CRichText* aRichText) |
|
257 { |
|
258 aRichText->ExternalizeStyleDataL(aStream); |
|
259 aRichText->ExternalizeMarkupDataL(aStream); |
|
260 aRichText->ExternalizePlainTextL(aStream); |
|
261 } |
|
262 |
|
263 LOCAL_D void ReadInlineL(RReadStream& aStream,CRichText* aRichText) |
|
264 { |
|
265 aRichText->InternalizeStyleDataL(aStream); |
|
266 aRichText->InternalizeMarkupDataL(aStream); |
|
267 aRichText->InternalizePlainTextL(aStream); |
|
268 } |
|
269 |
|
270 |
|
271 LOCAL_C CStyleList* CreatePopulatedStyleList() |
|
272 // |
|
273 { |
|
274 // |
|
275 // Create style aswell. |
|
276 CStyleList* list=CStyleList::NewL(); |
|
277 CParagraphStyle* style1=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer); |
|
278 CParagraphStyle* style2=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer); |
|
279 CParagraphStyle* style3=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer); |
|
280 RParagraphStyleInfo info1(style1); |
|
281 RParagraphStyleInfo info2(style2); |
|
282 RParagraphStyleInfo info3(style3); |
|
283 list->AppendL(&info1); |
|
284 list->AppendL(&info2); |
|
285 list->AppendL(&info3); |
|
286 return list; |
|
287 } |
|
288 _LIT(KTRichOutputFile,"c:\\etext\\TRICH.DAT"); |
|
289 |
|
290 LOCAL_C void SaveLoadOOM() |
|
291 { |
|
292 // Set up the framework |
|
293 theFs.Delete(KTRichOutputFile); |
|
294 theFs.MkDirAll(KTRichOutputFile); |
|
295 CFileStore* store = CPermanentFileStore::CreateLC(theFs,KTRichOutputFile,EFileRead|EFileWrite); |
|
296 store->SetTypeL(store->Layout()); |
|
297 CStyleList* list=CreatePopulatedStyleList(); |
|
298 CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list); |
|
299 TBool hasMarkupData=richText1->HasMarkupData(); |
|
300 test(hasMarkupData); // because of owned style list. |
|
301 richText1->InsertL(0,_L("hello")); |
|
302 richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter); |
|
303 richText1->InsertL(richText1->DocumentLength(),_L("there")); |
|
304 |
|
305 RStoreWriteStream out; |
|
306 TStreamId id1 = out.CreateLC(*store); |
|
307 |
|
308 test.Next(_L("Store/Restore OOM")); |
|
309 test.Start(_L("Writing Inline noramlly")); |
|
310 // Write out inline normally |
|
311 WriteInlineL(out,richText1); |
|
312 delete richText1; |
|
313 out.CommitL(); |
|
314 CleanupStack::PopAndDestroy(); // out |
|
315 store->CommitL(); |
|
316 RStoreReadStream in; |
|
317 in.OpenLC(*store,id1); |
|
318 CRichText* empty = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
319 |
|
320 test.Next(_L("Reading Inline noramlly")); |
|
321 // Read in inline normally: |
|
322 TRAPD(ret,ReadInlineL(in,empty)); |
|
323 test(ret==KErrNone); |
|
324 CleanupStack::PopAndDestroy(); // in |
|
325 delete empty; |
|
326 empty=NULL; |
|
327 |
|
328 test.Next(_L("Reading Inline with OOM")); |
|
329 // Read in inline with OOM: |
|
330 empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
331 |
|
332 for (TInt jj = 1; ;++jj) |
|
333 { |
|
334 RStoreReadStream in2; |
|
335 in2.OpenLC(*store,id1); |
|
336 __UHEAP_SETFAIL(RHeap::EDeterministic,jj); |
|
337 TRAPD(ret,ReadInlineL(in2,empty)); |
|
338 __UHEAP_RESET; |
|
339 CleanupStack::PopAndDestroy(); // in2 |
|
340 if (ret!=KErrNone) |
|
341 empty->Reset(); |
|
342 else |
|
343 { |
|
344 test(empty->HasMarkupData()); |
|
345 break; |
|
346 } |
|
347 } |
|
348 |
|
349 test.Next(_L("Writing Inline with OOM")); |
|
350 // Write out inline with OOM: |
|
351 CStyleList* list2=CreatePopulatedStyleList(); |
|
352 CRichText* richText2 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list2); |
|
353 richText2->InsertL(0,_L("hello")); |
|
354 TStreamId i = store->ExtendL(); |
|
355 for (TInt ii = 1; ;++ii) |
|
356 { |
|
357 RStoreWriteStream out2; |
|
358 out2.ReplaceLC(*store,i); |
|
359 __UHEAP_SETFAIL(RHeap::EDeterministic,ii); |
|
360 TRAP(ret,WriteInlineL(out2,richText2)); |
|
361 __UHEAP_RESET; |
|
362 if (ret==KErrNone) |
|
363 { |
|
364 out2.CommitL(); |
|
365 CleanupStack::PopAndDestroy(); // out2 |
|
366 delete richText2; |
|
367 break; |
|
368 } |
|
369 else |
|
370 CleanupStack::PopAndDestroy(); // out2 |
|
371 } |
|
372 store->CommitL(); |
|
373 |
|
374 test.Next(_L("Reading Inline after OOM write")); |
|
375 // Read in inline normally following a write out with OOM |
|
376 RStoreReadStream in3; |
|
377 in3.OpenLC(*store,i); |
|
378 empty->Reset(); |
|
379 TRAP(ret,ReadInlineL(in3,empty)); // unhandled exception |
|
380 test(ret==KErrNone); |
|
381 CleanupStack::PopAndDestroy(); |
|
382 empty->Reset(); |
|
383 |
|
384 // |
|
385 // |
|
386 // |
|
387 |
|
388 // Set up new component framework |
|
389 CXzePicture* pic1=CXzePicture::NewL('p'); |
|
390 CXzePicture* pic2=CXzePicture::NewL('l'); |
|
391 CXzePicture* pic3=CXzePicture::NewL('l'); |
|
392 TPictureHeader hdr1; |
|
393 TPictureHeader hdr2; |
|
394 TPictureHeader hdr3; |
|
395 hdr1.iPictureType = KUidXzePictureType; |
|
396 hdr2.iPictureType = KUidXzePictureType; |
|
397 hdr3.iPictureType = KUidXzePictureType; |
|
398 hdr1.iPicture = pic1; |
|
399 hdr2.iPicture = pic2; |
|
400 hdr3.iPicture = pic3; |
|
401 CRichText* richText3 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
402 richText3->InsertL(0,hdr3); |
|
403 richText3->InsertL(0,hdr2); |
|
404 richText3->InsertL(0,hdr1); |
|
405 richText3->InsertL(2,_L("hello")); |
|
406 |
|
407 test.Next(_L("Writing Outline noramlly")); |
|
408 // Write outline normally: |
|
409 TStreamId id2 = richText3->StoreL(*store); |
|
410 store->CommitL(); |
|
411 delete richText3; |
|
412 |
|
413 test.Next(_L("Reading Outline noramlly")); |
|
414 // Read outline normally: |
|
415 empty->Reset(); |
|
416 TRAP(ret,empty->RestoreL(*store,id2)); |
|
417 test(ret==KErrNone); |
|
418 empty->Reset(); |
|
419 |
|
420 test.Next(_L("Reading Outline with OOM")); |
|
421 // Read outline with OOM: |
|
422 CRichText* inText2=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
423 for (TInt kk = 1; ;++kk) |
|
424 { |
|
425 __UHEAP_SETFAIL(RHeap::EDeterministic,kk); |
|
426 // |
|
427 TRAP(ret,inText2->RestoreL(*store,id2)); |
|
428 // |
|
429 __UHEAP_RESET; |
|
430 if (ret!=KErrNone) |
|
431 inText2->Reset(); |
|
432 else |
|
433 { |
|
434 delete inText2; |
|
435 break; |
|
436 } |
|
437 } |
|
438 |
|
439 CRichText* richText4 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
440 CXzePicture* pic4=CXzePicture::NewL('P'); |
|
441 CXzePicture* pic5=CXzePicture::NewL('P'); |
|
442 CXzePicture* pic6=CXzePicture::NewL('P'); |
|
443 TPictureHeader hdr4; |
|
444 TPictureHeader hdr5; |
|
445 TPictureHeader hdr6; |
|
446 hdr4.iPictureType=KUidXzePictureType; |
|
447 hdr5.iPictureType=KUidXzePictureType; |
|
448 hdr6.iPictureType=KUidXzePictureType; |
|
449 hdr4.iPicture=pic4; |
|
450 hdr5.iPicture=pic5; |
|
451 hdr6.iPicture=pic6; |
|
452 richText4->InsertL(0,hdr4); |
|
453 richText4->InsertL(0,hdr5); |
|
454 richText4->InsertL(0,hdr6); |
|
455 richText4->InsertL(1,_L("hello")); |
|
456 |
|
457 test.Next(_L("Writing Outline with OOM")); |
|
458 // Wtite outline with OOM: |
|
459 TStreamId id3(0); |
|
460 for (TInt mm=1; ;++mm) |
|
461 { |
|
462 __UHEAP_SETFAIL(RHeap::EDeterministic,mm); |
|
463 TRAPD(ret,id3 = richText4->StoreL(*store)); |
|
464 if (ret==KErrNone) |
|
465 { |
|
466 __UHEAP_RESET; |
|
467 delete richText4; |
|
468 store->CommitL(); |
|
469 break; |
|
470 } |
|
471 } |
|
472 |
|
473 test.Next(_L("Reading Outline after OOM write")); |
|
474 // Read outline normally folliwng a write with OOM: |
|
475 empty->Reset(); |
|
476 TRAP(ret,empty->RestoreL(*store,id3)); |
|
477 test(ret==KErrNone); |
|
478 |
|
479 CleanupStack::PopAndDestroy(); // store |
|
480 delete empty; |
|
481 test.End(); |
|
482 } |
|
483 |
|
484 |
|
485 LOCAL_C void CheckTextIntegrity(const CRichText* aText) |
|
486 // Simply invokes a method to run the text (& component's) onvariants. |
|
487 // |
|
488 { |
|
489 __UHEAP_RESET; |
|
490 CParaFormat* paraFormat=CParaFormat::NewLC(); |
|
491 aText->GetParagraphFormatL(paraFormat,0); // forces CRichTextIndex::__DbgTextInvariant() to run. |
|
492 CleanupStack::PopAndDestroy(); // paraFormat |
|
493 } |
|
494 |
|
495 |
|
496 LOCAL_C void BasicEditOOM() |
|
497 // Tests basic editing functions under OOM conditions. |
|
498 // |
|
499 { |
|
500 test.Next(_L("Basic Editing methods under OOM")); |
|
501 test.Start(_L("InsertL(TChar)")); |
|
502 // |
|
503 // Insert a single character |
|
504 const TInt insertCharLoop=10; |
|
505 const TInt KSmallTextBufferSize=1; |
|
506 CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
507 richText1->SetPictureFactory(NULL,NULL); // forces index generation |
|
508 for (TInt mm=1;mm<=insertCharLoop;mm++) |
|
509 { |
|
510 __UHEAP_SETFAIL(RHeap::EDeterministic,mm); |
|
511 for (TInt nn=1;nn<=insertCharLoop;nn++) |
|
512 { |
|
513 TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),'x')); |
|
514 if (ret!=KErrNone) |
|
515 { |
|
516 test(richText1->DocumentLength()+1==nn); |
|
517 CheckTextIntegrity(richText1); |
|
518 break; |
|
519 } |
|
520 } |
|
521 __UHEAP_RESET; |
|
522 richText1->Reset(); |
|
523 } |
|
524 __UHEAP_RESET; |
|
525 delete richText1; |
|
526 // |
|
527 // |
|
528 test.Next(_L("InsertL(TDesC&)")); |
|
529 // |
|
530 // Insert a descriptor |
|
531 const TInt insertDescriptorLoop=10; |
|
532 richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
533 richText1->SetPictureFactory(NULL,NULL); // forces index generation |
|
534 TPtrC buf(_L("1234567890")); |
|
535 |
|
536 for (TInt nn=1;nn<=insertDescriptorLoop+1;nn++) |
|
537 { |
|
538 __UHEAP_SETFAIL(RHeap::EDeterministic,nn); |
|
539 TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),buf)); |
|
540 if (ret!=KErrNone) |
|
541 test(richText1->DocumentLength()==0); |
|
542 else |
|
543 test(richText1->DocumentLength()==buf.Length()); |
|
544 CheckTextIntegrity(richText1); |
|
545 richText1->Reset(); |
|
546 } |
|
547 __UHEAP_RESET; |
|
548 delete richText1; |
|
549 |
|
550 // |
|
551 // |
|
552 test.Next(_L("InsertL(TPictureHeader&)")); |
|
553 // |
|
554 // Insert a picture header |
|
555 richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
556 // |
|
557 for (TInt ii=18; ;ii++) |
|
558 { |
|
559 // create the picture header |
|
560 __UHEAP_RESET; |
|
561 CXzePicture* pic1=CXzePicture::NewL('o'); |
|
562 TPictureHeader hdr1; |
|
563 hdr1.iPictureType=KUidXzePictureType; |
|
564 hdr1.iPicture=pic1; |
|
565 __UHEAP_SETFAIL(RHeap::EDeterministic,ii); |
|
566 TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),hdr1)); |
|
567 if (ret!=KErrNone) |
|
568 { |
|
569 test(richText1->DocumentLength()==0); |
|
570 // if (ii<19) |
|
571 // delete pic1; |
|
572 /* |
|
573 THE ABOVE 2 LINES ARE WRONG NOW, SINCE THE PICTURE IS DELETED AUTOMATICALLY, IF THE INSERTION FAILS. |
|
574 |
|
575 */ |
|
576 richText1->Reset(); |
|
577 } |
|
578 else |
|
579 { |
|
580 test(richText1->DocumentLength()==1); |
|
581 break; |
|
582 } |
|
583 } |
|
584 __UHEAP_RESET; |
|
585 delete richText1; |
|
586 |
|
587 |
|
588 test.End(); |
|
589 __UHEAP_RESET; |
|
590 // delete richText1; |
|
591 } |
|
592 |
|
593 |
|
594 LOCAL_C void AppendTest1L() |
|
595 { |
|
596 // Insert a single character |
|
597 const TInt insertDescriptorLoop=10; |
|
598 const TInt KSmallTextBufferSize=1; |
|
599 CRichText* source=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
600 CRichText* target=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
601 source->InsertL(source->DocumentLength(),_L("1234567890")); |
|
602 target->InsertL(target->DocumentLength(),_L("abcdef")); |
|
603 TInt targetStartLength=target->DocumentLength(); |
|
604 for (TInt nn=1;nn<=insertDescriptorLoop+2;nn++) // +1 for the last para delim, +1 to force a suceed |
|
605 { |
|
606 __UHEAP_SETFAIL(RHeap::EDeterministic,nn); |
|
607 TRAPD(ret,target->AppendTakingSolePictureOwnershipL(*source)); |
|
608 if (ret!=KErrNone) |
|
609 test(target->DocumentLength()==targetStartLength); |
|
610 else |
|
611 { |
|
612 TInt targetLength=target->DocumentLength(); |
|
613 test(targetLength==targetStartLength+source->DocumentLength()+1); |
|
614 break; |
|
615 } |
|
616 CheckTextIntegrity(target); |
|
617 } |
|
618 __UHEAP_RESET; |
|
619 delete target; |
|
620 delete source; |
|
621 // test.End(); |
|
622 } |
|
623 |
|
624 |
|
625 LOCAL_C void AppendTest2L(CRichText* aTarget) |
|
626 { |
|
627 __UHEAP_RESET; |
|
628 const TInt KSmallTextBufferSize=1; |
|
629 TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml"); |
|
630 CRichText* source=LoadIntoTextL(filename); |
|
631 if (!aTarget) |
|
632 aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
633 TInt targetStartLength=aTarget->DocumentLength(); |
|
634 for (TInt ii = 1; ;++ii) |
|
635 { |
|
636 __UHEAP_SETFAIL(RHeap::EDeterministic,ii); |
|
637 TRAPD(ret, |
|
638 aTarget->AppendTakingSolePictureOwnershipL(*source)); |
|
639 __UHEAP_RESET; |
|
640 if (ret!=KErrNone) |
|
641 test(aTarget->DocumentLength()==targetStartLength); |
|
642 else |
|
643 {// We have succeeded in appending the document. |
|
644 TInt paraDelimiter=(targetStartLength>0) ? 1 : 0; |
|
645 test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength()); |
|
646 break; |
|
647 } |
|
648 } |
|
649 delete source; |
|
650 delete aTarget; |
|
651 } |
|
652 |
|
653 |
|
654 LOCAL_C void AppendTestNewL(CRichText* aTarget) |
|
655 { |
|
656 const TInt KSmallTextBufferSize=4; |
|
657 TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml"); |
|
658 CRichText* source=LoadIntoTextL(filename); |
|
659 if (!aTarget) |
|
660 { |
|
661 aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
662 aTarget->InsertL(0,_L("This is paragraph number one")); |
|
663 aTarget->InsertL(1,CEditableText::EParagraphDelimiter); |
|
664 } |
|
665 TInt targetStartLength=aTarget->DocumentLength(); |
|
666 for (TInt ii = 1; ;++ii) |
|
667 { |
|
668 __UHEAP_SETFAIL(RHeap::EDeterministic,ii); |
|
669 TRAPD(ret, |
|
670 aTarget->AppendTakingSolePictureOwnershipL(*source)); |
|
671 __UHEAP_RESET; |
|
672 if (ret!=KErrNone) |
|
673 test(aTarget->DocumentLength()==targetStartLength); |
|
674 else |
|
675 {// We have succeeded in appending the document. |
|
676 TInt paraDelimiter=(targetStartLength>0) ? 1 : 0; |
|
677 test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength()); |
|
678 break; |
|
679 } |
|
680 } |
|
681 delete source; |
|
682 delete aTarget; |
|
683 } |
|
684 |
|
685 |
|
686 LOCAL_C void AppendTest3L(CRichText* aTarget) |
|
687 { |
|
688 const TInt KSmallTextBufferSize=31; |
|
689 TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml"); |
|
690 CRichText* source=LoadIntoTextL(filename); |
|
691 if (!aTarget) |
|
692 aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); |
|
693 TInt targetStartLength=aTarget->DocumentLength(); |
|
694 for (TInt ii = 1; ;++ii) |
|
695 { |
|
696 __UHEAP_SETFAIL(RHeap::EDeterministic,ii); |
|
697 TRAPD(ret, |
|
698 aTarget->AppendTakingSolePictureOwnershipL(*source)); |
|
699 __UHEAP_RESET; |
|
700 if (ret!=KErrNone) |
|
701 test(aTarget->DocumentLength()==targetStartLength); |
|
702 else |
|
703 {// We have succeeded in appending the document. |
|
704 TInt paraDelimiter=(targetStartLength>0) ? 1 : 0; |
|
705 test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength()); |
|
706 break; |
|
707 } |
|
708 } |
|
709 delete source; |
|
710 delete aTarget; |
|
711 } |
|
712 |
|
713 |
|
714 LOCAL_C void AppendTakingSolePictureOwnershipOOM() |
|
715 // |
|
716 { |
|
717 test.Next(_L("AppendTakingSolePictureOwnershipL() under OOM")); |
|
718 // |
|
719 test.Start(_L("Plain text only")); |
|
720 TRAPD(ret, |
|
721 AppendTest1L()); |
|
722 test(ret==KErrNone); |
|
723 // |
|
724 test.Next(_L("Plain text + phrase markup, with empty target")); |
|
725 TRAP(ret, |
|
726 AppendTest2L(STATIC_CAST(CRichText*,NULL))); |
|
727 test(ret==KErrNone); |
|
728 // |
|
729 test.Next(_L("Plain text + phrase markup, with non-empty target")); |
|
730 TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml"); |
|
731 CRichText* target=LoadIntoTextL(filename); |
|
732 TRAP(ret, |
|
733 AppendTest2L(target)); |
|
734 test(ret==KErrNone); |
|
735 // |
|
736 // test.Next(_L("Plain text + shared markup, with empty target")); |
|
737 // TRAP(ret, |
|
738 // AppendTest3L(STATIC_CAST(CRichText*,NULL))); |
|
739 // test(ret==KErrNone); |
|
740 // |
|
741 test.Next(_L("Plain text + shared markup, non-empty target")); |
|
742 TRAP(ret, |
|
743 AppendTestNewL(STATIC_CAST(CRichText*,NULL))); |
|
744 test(ret==KErrNone); |
|
745 // |
|
746 test.Next(_L("Plain text + shared markup, with non-empty target")); |
|
747 filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml"); |
|
748 target=LoadIntoTextL(filename); |
|
749 TRAP(ret, |
|
750 AppendTest3L(target)); |
|
751 test(ret==KErrNone); |
|
752 // |
|
753 test.End(); |
|
754 } |
|
755 |
|
756 |
|
757 LOCAL_C void DoAppendParagraphOOM(CRichText* aRichText,TBool aUnderOOM,TInt aReplicas) |
|
758 { |
|
759 if (!aUnderOOM) |
|
760 { |
|
761 aRichText->AppendParagraphL(aReplicas); |
|
762 return; |
|
763 } |
|
764 // |
|
765 // Append testing for OOM |
|
766 TInt charCount=aRichText->DocumentLength(); |
|
767 TInt paraCount=aRichText->ParagraphCount(); |
|
768 for (TInt jj = 1; ;++jj) |
|
769 { |
|
770 __UHEAP_SETFAIL(RHeap::EDeterministic,jj); |
|
771 TRAPD(ret, |
|
772 aRichText->AppendParagraphL(aReplicas)); |
|
773 __UHEAP_RESET; |
|
774 TInt newCharCount=aRichText->DocumentLength(); |
|
775 TInt newParaCount=aRichText->ParagraphCount(); |
|
776 if (ret!=KErrNone) |
|
777 { |
|
778 test(newCharCount==charCount); |
|
779 test(newParaCount==paraCount); |
|
780 } |
|
781 else |
|
782 { |
|
783 test(newCharCount==charCount+aReplicas); |
|
784 test(newParaCount==paraCount+aReplicas); |
|
785 TBuf<30> buf; |
|
786 buf.Format(_L(" allocs=%d\n"),jj); |
|
787 test.Printf(buf); |
|
788 break; |
|
789 } |
|
790 } |
|
791 } |
|
792 |
|
793 |
|
794 LOCAL_C void AppendParagraphOOM() |
|
795 // |
|
796 { |
|
797 TInt manyParas=5; |
|
798 TInt singlePara=1; |
|
799 test.Next(_L("AppendParagraphL() under OOM")); |
|
800 // |
|
801 test.Start(_L("appending normally - text has markup - single para")); |
|
802 TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml"); |
|
803 CRichText* text=LoadIntoTextL(filename); |
|
804 DoAppendParagraphOOM(text,EFalse,singlePara); |
|
805 delete text; |
|
806 text=NULL; |
|
807 |
|
808 test.Next(_L("appending with OOM - text has markup - single para")); |
|
809 text=LoadIntoTextL(filename); |
|
810 DoAppendParagraphOOM(text,ETrue,singlePara); |
|
811 delete text; |
|
812 text=NULL; |
|
813 |
|
814 test.Next(_L("appending normally - text has markup - many paras")); |
|
815 text=LoadIntoTextL(filename); |
|
816 DoAppendParagraphOOM(text,EFalse,manyParas); |
|
817 delete text; |
|
818 text=NULL; |
|
819 |
|
820 test.Next(_L("appending with OOM - text has markup - many paras")); |
|
821 text=LoadIntoTextL(filename); |
|
822 DoAppendParagraphOOM(text,ETrue,manyParas); |
|
823 delete text; |
|
824 text=NULL; |
|
825 |
|
826 test.End(); |
|
827 } |
|
828 |
|
829 |
|
830 LOCAL_C void ApplyCharFormatOOM1() |
|
831 { |
|
832 // Set up the framework |
|
833 test.Next(_L("ApplyCharFormatL() OOM - no markup")); |
|
834 CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
835 richText1->InsertL(0,_L("SOME VERY FINE TEXT")); |
|
836 |
|
837 // Apply some random formatting |
|
838 TCharFormat charFormat; TCharFormatMask charMask; |
|
839 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
840 charMask.SetAttrib(EAttFontStrokeWeight); |
|
841 |
|
842 for (TInt jj=1; ;jj++) |
|
843 { |
|
844 __UHEAP_SETFAIL(RHeap::EDeterministic,jj); |
|
845 TRAPD(ret, |
|
846 richText1->ApplyCharFormatL(charFormat,charMask,5,11)); |
|
847 __UHEAP_RESET; |
|
848 TPtrC buf; |
|
849 if (ret==KErrNone) |
|
850 { |
|
851 TCharFormat newFormat; |
|
852 richText1->GetChars(buf,newFormat,5); |
|
853 test(newFormat.IsEqual(charFormat,charMask)); |
|
854 test(buf.Length() < richText1->DocumentLength()); |
|
855 break; |
|
856 } |
|
857 else |
|
858 { |
|
859 |
|
860 } |
|
861 |
|
862 } |
|
863 delete richText1; |
|
864 richText1=NULL; |
|
865 } |
|
866 |
|
867 |
|
868 LOCAL_C void ApplyCharFormatOOM2() |
|
869 { |
|
870 // Set up the framework |
|
871 test.Next(_L("ApplyCharFormatL() OOM - with markup")); |
|
872 CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); |
|
873 richText1->InsertL(0,_L("SOME TEXT")); |
|
874 |
|
875 // Generate some markup |
|
876 TCharFormat cF; |
|
877 TCharFormatMask cM; |
|
878 cF.iFontSpec.iFontStyle.SetPosture(EPostureItalic); |
|
879 cM.SetAttrib(EAttFontPosture); |
|
880 richText1->ApplyCharFormatL(cF,cM,3,3); |
|
881 |
|
882 // Apply some random formatting |
|
883 TCharFormat charFormat; TCharFormatMask charMask; |
|
884 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
885 charMask.SetAttrib(EAttFontStrokeWeight); |
|
886 |
|
887 for (TInt jj=1; ;jj++) |
|
888 { |
|
889 __UHEAP_SETFAIL(RHeap::EDeterministic,jj); |
|
890 TRAPD(ret, |
|
891 richText1->ApplyCharFormatL(charFormat,charMask,3,3)); |
|
892 __UHEAP_RESET; |
|
893 TPtrC buf; |
|
894 if (ret==KErrNone) |
|
895 { |
|
896 TCharFormat newFormat; |
|
897 richText1->GetChars(buf,newFormat,3); |
|
898 test(newFormat.iFontSpec.iFontStyle.Posture()==EPostureItalic); |
|
899 test(newFormat.iFontSpec.iFontStyle.StrokeWeight()==EStrokeWeightBold); |
|
900 test(buf.Length()==3); |
|
901 break; |
|
902 } |
|
903 else |
|
904 { |
|
905 |
|
906 } |
|
907 |
|
908 } |
|
909 delete richText1; |
|
910 richText1=NULL; |
|
911 } |
|
912 |
|
913 |
|
914 LOCAL_C void doMainL() |
|
915 { |
|
916 |
|
917 GlobalPictureFactory=new(ELeave) MDemPictureFactory; |
|
918 GlobalParaFormatLayer=CParaFormatLayer::NewL(); |
|
919 GlobalCharFormatLayer=CCharFormatLayer::NewL(); |
|
920 theFs.Connect(); |
|
921 // |
|
922 TRAPD(ret,ConstructOOM()); |
|
923 test(ret==KErrNone); |
|
924 TRAP(ret,SaveLoadOOM()); |
|
925 test(ret==KErrNone); |
|
926 TRAP(ret,CopyPasteOOM()); |
|
927 test(ret==KErrNone); |
|
928 TRAP(ret,BasicEditOOM()); |
|
929 test(ret==KErrNone); |
|
930 TRAP(ret,AppendTakingSolePictureOwnershipOOM()); |
|
931 test(ret==KErrNone); |
|
932 TRAP(ret,CopyPasteOOM2()); |
|
933 test(ret==KErrNone); |
|
934 TRAP(ret,AppendParagraphOOM()); |
|
935 test(ret==KErrNone); |
|
936 TRAP(ret,ApplyCharFormatOOM1()); |
|
937 test(ret==KErrNone); |
|
938 TRAP(ret,ApplyCharFormatOOM2()); |
|
939 test(ret==KErrNone); |
|
940 test.End(); |
|
941 // |
|
942 delete GlobalPictureFactory; |
|
943 delete GlobalParaFormatLayer; |
|
944 delete GlobalCharFormatLayer; |
|
945 theFs.Close(); |
|
946 } |
|
947 |
|
948 |
|
949 LOCAL_C void setupCleanup() |
|
950 // |
|
951 // Initialise the cleanup stack. |
|
952 // |
|
953 { |
|
954 TheTrapCleanup=CTrapCleanup::New(); |
|
955 test(TheTrapCleanup!=NULL); |
|
956 TRAPD(r,\ |
|
957 {\ |
|
958 for (TInt i=KTestCleanupStack;i>0;i--)\ |
|
959 CleanupStack::PushL((TAny*)0);\ |
|
960 CleanupStack::Pop(KTestCleanupStack);\ |
|
961 }); |
|
962 test(r==KErrNone); |
|
963 } |
|
964 |
|
965 |
|
966 LOCAL_C void DeleteDataFile(const TDesC& aFullName) |
|
967 { |
|
968 RFs fsSession; |
|
969 TInt err = fsSession.Connect(); |
|
970 if(err == KErrNone) |
|
971 { |
|
972 TEntry entry; |
|
973 if(fsSession.Entry(aFullName, entry) == KErrNone) |
|
974 { |
|
975 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); |
|
976 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); |
|
977 if(err != KErrNone) |
|
978 { |
|
979 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); |
|
980 } |
|
981 err = fsSession.Delete(aFullName); |
|
982 if(err != KErrNone) |
|
983 { |
|
984 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); |
|
985 } |
|
986 } |
|
987 fsSession.Close(); |
|
988 } |
|
989 else |
|
990 { |
|
991 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); |
|
992 } |
|
993 } |
|
994 |
|
995 GLDEF_C TInt E32Main() |
|
996 // |
|
997 // Test permanent file store. |
|
998 // |
|
999 { |
|
1000 test.Title(); |
|
1001 setupCleanup(); |
|
1002 |
|
1003 __UHEAP_MARK; |
|
1004 // |
|
1005 test.Start(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TRICHOOM-0001 RichText OOM Testing ")); |
|
1006 TRAPD(ret,doMainL()); |
|
1007 test(ret==KErrNone); |
|
1008 |
|
1009 ::DeleteDataFile(KTRichOutputFile); //deletion of data files must be before call to End() - DEF047652 |
|
1010 test.End(); |
|
1011 // |
|
1012 __UHEAP_MARKEND; |
|
1013 delete TheTrapCleanup; |
|
1014 test.Close(); |
|
1015 |
|
1016 return KErrNone; |
|
1017 } |
|
1018 |