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