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 <txtstyle.h>
|
sl@0
|
21 |
#include "TXTMRTSR.H"
|
sl@0
|
22 |
#include <gdi.h>
|
sl@0
|
23 |
#include <conpics.h>
|
sl@0
|
24 |
#include <s32mem.h>
|
sl@0
|
25 |
#include <s32file.h>
|
sl@0
|
26 |
#include <flddef.h>
|
sl@0
|
27 |
#include <fldbltin.h>
|
sl@0
|
28 |
#include <fldset.h>
|
sl@0
|
29 |
#include "TRTCUSTM.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 |
LOCAL_D RFs theFs;
|
sl@0
|
43 |
LOCAL_D CFileStore* TheStore;
|
sl@0
|
44 |
LOCAL_D CParaFormatLayer* GlobalParaFormatLayer;
|
sl@0
|
45 |
LOCAL_D CCharFormatLayer* GlobalCharFormatLayer;
|
sl@0
|
46 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
47 |
const TInt KTestCleanupStack=0x500;
|
sl@0
|
48 |
|
sl@0
|
49 |
|
sl@0
|
50 |
class TStoreResolver : public MRichTextStoreResolver
|
sl@0
|
51 |
{
|
sl@0
|
52 |
public:
|
sl@0
|
53 |
virtual const CStreamStore& StreamStoreL(TInt /*aPos*/)const {return *iStore;}
|
sl@0
|
54 |
public:
|
sl@0
|
55 |
CStreamStore* iStore;
|
sl@0
|
56 |
};
|
sl@0
|
57 |
|
sl@0
|
58 |
|
sl@0
|
59 |
////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
60 |
class TTestFieldFactoryTRTCUSTM : public MTextFieldFactory
|
sl@0
|
61 |
{
|
sl@0
|
62 |
public:
|
sl@0
|
63 |
// from MTextFieldFactory
|
sl@0
|
64 |
virtual CTextField* NewFieldL(TUid aFieldType);
|
sl@0
|
65 |
// Creates a field of the type specified
|
sl@0
|
66 |
// Returns NULL if it does not recognise/support the field type
|
sl@0
|
67 |
};
|
sl@0
|
68 |
|
sl@0
|
69 |
CTextField* TTestFieldFactoryTRTCUSTM::NewFieldL(TUid aFieldType)
|
sl@0
|
70 |
// Creates a field (in aHeader) of the type specified in aHeader
|
sl@0
|
71 |
//
|
sl@0
|
72 |
{
|
sl@0
|
73 |
CTextField* field=NULL;
|
sl@0
|
74 |
if (aFieldType==KDateTimeFieldUid)
|
sl@0
|
75 |
field = (CTextField*)new(ELeave) CDateTimeField();
|
sl@0
|
76 |
return field;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
79 |
|
sl@0
|
80 |
void CT_TRTCUSTM::WriteInlineL(RWriteStream& aStream,CRichText* aRichText)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
aRichText->CancelInsertCharFormat();
|
sl@0
|
83 |
aRichText->ExternalizeFieldDataL(aStream);
|
sl@0
|
84 |
aRichText->ExternalizeStyleDataL(aStream);
|
sl@0
|
85 |
TBool hasMarkupData=aRichText->HasMarkupData();
|
sl@0
|
86 |
aStream.WriteUint8L((TUint8)hasMarkupData!=EFalse);
|
sl@0
|
87 |
if (hasMarkupData)
|
sl@0
|
88 |
aRichText->ExternalizeMarkupDataL(aStream);
|
sl@0
|
89 |
aRichText->ExternalizePlainTextL(aStream);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
void CT_TRTCUSTM::ReadInlineL(RReadStream& aStream,CRichText* aRichText)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
aRichText->InternalizeFieldDataL(aStream);
|
sl@0
|
95 |
aRichText->InternalizeStyleDataL(aStream);
|
sl@0
|
96 |
TBool hasMarkupData=(TBool)aStream.ReadUint8L();
|
sl@0
|
97 |
if (hasMarkupData)
|
sl@0
|
98 |
aRichText->InternalizeMarkupDataL(aStream);
|
sl@0
|
99 |
aRichText->InternalizePlainTextL(aStream);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
TStreamId CT_TRTCUSTM::PerformSaveL(CRichText* aRichText)
|
sl@0
|
104 |
//
|
sl@0
|
105 |
{
|
sl@0
|
106 |
RStoreWriteStream out;
|
sl@0
|
107 |
TStreamId id1=out.CreateLC(*TheStore);
|
sl@0
|
108 |
WriteInlineL(out,aRichText);
|
sl@0
|
109 |
delete aRichText;
|
sl@0
|
110 |
out.CommitL();
|
sl@0
|
111 |
CleanupStack::PopAndDestroy(); // out
|
sl@0
|
112 |
TheStore->CommitL();
|
sl@0
|
113 |
return id1;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
|
sl@0
|
117 |
CRichText* CT_TRTCUSTM::PerformLoadL(TStreamId aId)
|
sl@0
|
118 |
//
|
sl@0
|
119 |
{
|
sl@0
|
120 |
CRichText* text=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
121 |
RStoreReadStream in;
|
sl@0
|
122 |
in.OpenLC(*TheStore,aId);
|
sl@0
|
123 |
TRAPD(ret,
|
sl@0
|
124 |
ReadInlineL(in,text));
|
sl@0
|
125 |
test(ret==KErrNone);
|
sl@0
|
126 |
CleanupStack::PopAndDestroy(); // in
|
sl@0
|
127 |
return text;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
|
sl@0
|
131 |
CStyleList* CT_TRTCUSTM::CreatePopulatedStyleList()
|
sl@0
|
132 |
//
|
sl@0
|
133 |
{
|
sl@0
|
134 |
//
|
sl@0
|
135 |
// Create style aswell.
|
sl@0
|
136 |
CStyleList* list=CStyleList::NewL();
|
sl@0
|
137 |
CParagraphStyle* style1=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer);
|
sl@0
|
138 |
CParagraphStyle* style2=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer);
|
sl@0
|
139 |
CParagraphStyle* style3=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer);
|
sl@0
|
140 |
RParagraphStyleInfo info1(style1);
|
sl@0
|
141 |
RParagraphStyleInfo info2(style2);
|
sl@0
|
142 |
RParagraphStyleInfo info3(style3);
|
sl@0
|
143 |
list->AppendL(&info1);
|
sl@0
|
144 |
list->AppendL(&info2);
|
sl@0
|
145 |
list->AppendL(&info3);
|
sl@0
|
146 |
return list;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
_LIT(KTRtCustOutputFile,"c:\\etext\\TRTCUSTM.DAT");
|
sl@0
|
150 |
|
sl@0
|
151 |
void CT_TRTCUSTM::CustomLoadSave()
|
sl@0
|
152 |
{
|
sl@0
|
153 |
// Set up the framework
|
sl@0
|
154 |
theFs.Delete(KTRtCustOutputFile);
|
sl@0
|
155 |
theFs.MkDirAll(KTRtCustOutputFile);
|
sl@0
|
156 |
TheStore=CPermanentFileStore::CreateLC(theFs,KTRtCustOutputFile,EFileRead|EFileWrite);
|
sl@0
|
157 |
TheStore->SetTypeL(TheStore->Layout());
|
sl@0
|
158 |
|
sl@0
|
159 |
//
|
sl@0
|
160 |
// Case (1) Rich text with owned style list. - no markup data
|
sl@0
|
161 |
//
|
sl@0
|
162 |
INFO_PRINTF1(_L("RT + no markup + style list owned"));
|
sl@0
|
163 |
//
|
sl@0
|
164 |
// Setup the rich text
|
sl@0
|
165 |
CStyleList* list=CreatePopulatedStyleList();
|
sl@0
|
166 |
CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
|
sl@0
|
167 |
TBool hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
168 |
test(hasMarkupData);
|
sl@0
|
169 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
170 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
171 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
172 |
//
|
sl@0
|
173 |
// Save the rich text
|
sl@0
|
174 |
TStreamId id1=PerformSaveL(richText1);
|
sl@0
|
175 |
//
|
sl@0
|
176 |
// Load the rich text
|
sl@0
|
177 |
CRichText* empty=NULL;
|
sl@0
|
178 |
TRAPD(ret,
|
sl@0
|
179 |
empty=PerformLoadL(id1));
|
sl@0
|
180 |
test(ret==KErrNone);
|
sl@0
|
181 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
182 |
test(hasMarkupData);
|
sl@0
|
183 |
delete empty;
|
sl@0
|
184 |
empty=NULL;
|
sl@0
|
185 |
//
|
sl@0
|
186 |
// Case (2) Rich text with referenced style list. - no markup data
|
sl@0
|
187 |
//
|
sl@0
|
188 |
INFO_PRINTF1(_L("RT + no markup + style list externally owned"));
|
sl@0
|
189 |
//
|
sl@0
|
190 |
// Setup the rich text
|
sl@0
|
191 |
list=CreatePopulatedStyleList();
|
sl@0
|
192 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list,CEditableText::ESegmentedStorage,2);
|
sl@0
|
193 |
richText1->SetStyleListExternallyOwned(ETrue);
|
sl@0
|
194 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
195 |
test(!hasMarkupData);
|
sl@0
|
196 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
197 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
198 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
199 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
200 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
201 |
test(!hasMarkupData);
|
sl@0
|
202 |
//
|
sl@0
|
203 |
// Save the rich text
|
sl@0
|
204 |
id1=PerformSaveL(richText1);
|
sl@0
|
205 |
//
|
sl@0
|
206 |
// Load the rich text
|
sl@0
|
207 |
empty=PerformLoadL(id1);
|
sl@0
|
208 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
209 |
test(!hasMarkupData);
|
sl@0
|
210 |
TInt paragraphCount=empty->ParagraphCount();
|
sl@0
|
211 |
test(paragraphCount==3);
|
sl@0
|
212 |
test(list->Count()==3); // the style list is now externally owned.
|
sl@0
|
213 |
delete empty;
|
sl@0
|
214 |
test(list->Count()==3); // the style list should not have been destroyed by the rich text
|
sl@0
|
215 |
delete list;
|
sl@0
|
216 |
empty=NULL;
|
sl@0
|
217 |
//
|
sl@0
|
218 |
// Case (3) Rich text with referenced style list. - with markup
|
sl@0
|
219 |
//
|
sl@0
|
220 |
INFO_PRINTF1(_L("RT + markup + style list externally owned"));
|
sl@0
|
221 |
// Setup the rich text
|
sl@0
|
222 |
list=CreatePopulatedStyleList();
|
sl@0
|
223 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
|
sl@0
|
224 |
richText1->SetStyleListExternallyOwned(ETrue);
|
sl@0
|
225 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
226 |
test(!hasMarkupData);
|
sl@0
|
227 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
228 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
229 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
230 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
231 |
CParaFormat* paraFormat=CParaFormat::NewLC();
|
sl@0
|
232 |
TParaFormatMask paraMask;
|
sl@0
|
233 |
paraFormat->iHorizontalAlignment=CParaFormat::ERightAlign;
|
sl@0
|
234 |
paraMask.SetAttrib(EAttAlignment);
|
sl@0
|
235 |
richText1->ApplyParaFormatL(paraFormat,paraMask,8,0);
|
sl@0
|
236 |
CleanupStack::PopAndDestroy(); // paraFormat
|
sl@0
|
237 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
238 |
test(hasMarkupData);
|
sl@0
|
239 |
//
|
sl@0
|
240 |
// Save the rich text
|
sl@0
|
241 |
id1=PerformSaveL(richText1);
|
sl@0
|
242 |
//
|
sl@0
|
243 |
// Load the rich text
|
sl@0
|
244 |
empty=PerformLoadL(id1);
|
sl@0
|
245 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
246 |
test(hasMarkupData);
|
sl@0
|
247 |
paragraphCount=empty->ParagraphCount();
|
sl@0
|
248 |
test(paragraphCount==3);
|
sl@0
|
249 |
test(list->Count()==3); // the style list is now externally owned.
|
sl@0
|
250 |
delete empty;
|
sl@0
|
251 |
test(list->Count()==3); // the style list should not have been destroyed by the rich text
|
sl@0
|
252 |
delete list;
|
sl@0
|
253 |
empty=NULL;
|
sl@0
|
254 |
//
|
sl@0
|
255 |
// Case (4) Rich text with no style list. - no effective markup
|
sl@0
|
256 |
//
|
sl@0
|
257 |
INFO_PRINTF1(_L("RT + delete picture + no style list"));
|
sl@0
|
258 |
// Setup the rich text
|
sl@0
|
259 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
260 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
261 |
test(!hasMarkupData);
|
sl@0
|
262 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
263 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
264 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
265 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
266 |
//
|
sl@0
|
267 |
// Create & insert a picture
|
sl@0
|
268 |
CXzePicture* pic1=CXzePicture::NewL('o');
|
sl@0
|
269 |
TPictureHeader header1;
|
sl@0
|
270 |
TSize size;
|
sl@0
|
271 |
pic1->GetSizeInTwips(size);
|
sl@0
|
272 |
header1.iPictureType=KUidXzePictureType;
|
sl@0
|
273 |
header1.iPicture=pic1;
|
sl@0
|
274 |
header1.iSize=size;
|
sl@0
|
275 |
richText1->InsertL(3,header1);
|
sl@0
|
276 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
277 |
test(hasMarkupData);
|
sl@0
|
278 |
richText1->DeleteL(3,1);
|
sl@0
|
279 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
280 |
test(!hasMarkupData);
|
sl@0
|
281 |
//
|
sl@0
|
282 |
// Save the rich text
|
sl@0
|
283 |
id1=PerformSaveL(richText1);
|
sl@0
|
284 |
//
|
sl@0
|
285 |
// Load the rich text
|
sl@0
|
286 |
empty=PerformLoadL(id1);
|
sl@0
|
287 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
288 |
test(!hasMarkupData);
|
sl@0
|
289 |
paragraphCount=empty->ParagraphCount();
|
sl@0
|
290 |
test(paragraphCount==3);
|
sl@0
|
291 |
delete empty;
|
sl@0
|
292 |
empty=NULL;
|
sl@0
|
293 |
//
|
sl@0
|
294 |
// Case (5) Rich text with SetInsertCharFormat()
|
sl@0
|
295 |
//
|
sl@0
|
296 |
INFO_PRINTF1(_L("RT + SetInsertCharFormatL()"));
|
sl@0
|
297 |
// Setup the rich text
|
sl@0
|
298 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
299 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
300 |
test(!hasMarkupData);
|
sl@0
|
301 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
302 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
303 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
304 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
305 |
TCharFormat charFormat;
|
sl@0
|
306 |
TCharFormatMask charMask;
|
sl@0
|
307 |
charFormat.iFontPresentation.iStrikethrough=EStrikethroughOn;
|
sl@0
|
308 |
charMask.SetAttrib(EAttFontStrikethrough);
|
sl@0
|
309 |
richText1->SetInsertCharFormatL(charFormat,charMask,3);
|
sl@0
|
310 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
311 |
test(hasMarkupData);
|
sl@0
|
312 |
//
|
sl@0
|
313 |
// Save the rich text
|
sl@0
|
314 |
id1=PerformSaveL(richText1);
|
sl@0
|
315 |
//
|
sl@0
|
316 |
// Load the rich text
|
sl@0
|
317 |
empty=PerformLoadL(id1);
|
sl@0
|
318 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
319 |
test(!hasMarkupData);
|
sl@0
|
320 |
paragraphCount=empty->ParagraphCount();
|
sl@0
|
321 |
test(paragraphCount==3);
|
sl@0
|
322 |
delete empty;
|
sl@0
|
323 |
empty=NULL;
|
sl@0
|
324 |
//
|
sl@0
|
325 |
// Case (6) Rich text with components - default re/store used.
|
sl@0
|
326 |
//
|
sl@0
|
327 |
|
sl@0
|
328 |
INFO_PRINTF1(_L("RT + components"));
|
sl@0
|
329 |
// Setup the rich text
|
sl@0
|
330 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
331 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
332 |
test(!hasMarkupData);
|
sl@0
|
333 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
334 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
335 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
336 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
337 |
//
|
sl@0
|
338 |
// Create & insert some fields
|
sl@0
|
339 |
TTestFieldFactoryTRTCUSTM factory;
|
sl@0
|
340 |
richText1->SetFieldFactory(&factory);
|
sl@0
|
341 |
CTextField* field=NULL;
|
sl@0
|
342 |
CTextField* field2=NULL;
|
sl@0
|
343 |
TRAP(ret,
|
sl@0
|
344 |
field=factory.NewFieldL(KDateTimeFieldUid)); test(ret==KErrNone);
|
sl@0
|
345 |
TRAP(ret,
|
sl@0
|
346 |
field2=factory.NewFieldL(KDateTimeFieldUid)); test(ret==KErrNone);
|
sl@0
|
347 |
TRAP(ret,
|
sl@0
|
348 |
richText1->InsertFieldL(0,field,KDateTimeFieldUid)); test(ret==KErrNone);
|
sl@0
|
349 |
TRAP(ret,
|
sl@0
|
350 |
richText1->UpdateFieldL(0));
|
sl@0
|
351 |
test(ret==KErrNone);
|
sl@0
|
352 |
TRAP(ret,
|
sl@0
|
353 |
richText1->InsertFieldL(0,field2,KDateTimeFieldUid));
|
sl@0
|
354 |
test(ret==KErrNone);
|
sl@0
|
355 |
TRAP(ret,
|
sl@0
|
356 |
richText1->UpdateFieldL(0));
|
sl@0
|
357 |
test(ret==KErrNone);
|
sl@0
|
358 |
//
|
sl@0
|
359 |
// Create & insert a picture
|
sl@0
|
360 |
pic1=CXzePicture::NewL('o');
|
sl@0
|
361 |
pic1->GetSizeInTwips(size);
|
sl@0
|
362 |
header1.iPictureType=KUidXzePictureType;
|
sl@0
|
363 |
header1.iPicture=pic1;
|
sl@0
|
364 |
header1.iSize=size;
|
sl@0
|
365 |
richText1->InsertL(0,header1);
|
sl@0
|
366 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
367 |
test(hasMarkupData);
|
sl@0
|
368 |
//
|
sl@0
|
369 |
// Save the rich text
|
sl@0
|
370 |
TStreamId head=richText1->StoreL(*TheStore);
|
sl@0
|
371 |
delete richText1;
|
sl@0
|
372 |
//
|
sl@0
|
373 |
// Load the rich text
|
sl@0
|
374 |
empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
375 |
empty->SetFieldFactory(&factory);
|
sl@0
|
376 |
empty->RestoreL(*TheStore,head);
|
sl@0
|
377 |
//
|
sl@0
|
378 |
// Create the correct factories
|
sl@0
|
379 |
TStoreResolver storeResolver;
|
sl@0
|
380 |
storeResolver.iStore=TheStore;
|
sl@0
|
381 |
MDemPictureFactory* pictureFactory=new(ELeave) MDemPictureFactory;
|
sl@0
|
382 |
|
sl@0
|
383 |
empty->SetPictureFactory(pictureFactory,&storeResolver);
|
sl@0
|
384 |
CXzePicture* rPic=(CXzePicture*)empty->PictureHandleL(0);
|
sl@0
|
385 |
test(rPic->iLabel=='o');
|
sl@0
|
386 |
//
|
sl@0
|
387 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
388 |
test(hasMarkupData);
|
sl@0
|
389 |
paragraphCount=empty->ParagraphCount();
|
sl@0
|
390 |
test(paragraphCount==3);
|
sl@0
|
391 |
delete empty;
|
sl@0
|
392 |
empty=NULL;
|
sl@0
|
393 |
delete pictureFactory;
|
sl@0
|
394 |
//
|
sl@0
|
395 |
// Case (7) Rich text with fields with referenced style list with markup
|
sl@0
|
396 |
//
|
sl@0
|
397 |
INFO_PRINTF1(_L("RT + fields + markup + style list"));
|
sl@0
|
398 |
// Setup the rich text
|
sl@0
|
399 |
list=CreatePopulatedStyleList();
|
sl@0
|
400 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
|
sl@0
|
401 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
402 |
test(hasMarkupData);
|
sl@0
|
403 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
404 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
405 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
406 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
407 |
paraFormat=CParaFormat::NewLC();
|
sl@0
|
408 |
paraMask.ClearAll();
|
sl@0
|
409 |
paraFormat->iHorizontalAlignment=CParaFormat::ERightAlign;
|
sl@0
|
410 |
paraMask.SetAttrib(EAttAlignment);
|
sl@0
|
411 |
richText1->ApplyParaFormatL(paraFormat,paraMask,8,0);
|
sl@0
|
412 |
CleanupStack::PopAndDestroy(); // paraFormat
|
sl@0
|
413 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
414 |
test(hasMarkupData);
|
sl@0
|
415 |
//
|
sl@0
|
416 |
// Now add a text field to this.
|
sl@0
|
417 |
richText1->SetFieldFactory(&factory);
|
sl@0
|
418 |
field=NULL;
|
sl@0
|
419 |
TRAP(ret,
|
sl@0
|
420 |
field=factory.NewFieldL(KDateTimeFieldUid));
|
sl@0
|
421 |
test(ret==KErrNone);
|
sl@0
|
422 |
TRAP(ret,
|
sl@0
|
423 |
richText1->InsertFieldL(0,field,KDateTimeFieldUid));
|
sl@0
|
424 |
test(ret==KErrNone);
|
sl@0
|
425 |
TRAP(ret,
|
sl@0
|
426 |
richText1->UpdateFieldL(0));
|
sl@0
|
427 |
test(ret==KErrNone);
|
sl@0
|
428 |
//
|
sl@0
|
429 |
// Save the rich text
|
sl@0
|
430 |
//
|
sl@0
|
431 |
// 1st the components.
|
sl@0
|
432 |
CStoreMap* map=CStoreMap::NewLC(*TheStore);
|
sl@0
|
433 |
richText1->StoreFieldComponentsL(*TheStore,*map);
|
sl@0
|
434 |
//
|
sl@0
|
435 |
RStoreWriteStream out(*map);
|
sl@0
|
436 |
id1=out.CreateLC(*TheStore);
|
sl@0
|
437 |
//
|
sl@0
|
438 |
richText1->CancelInsertCharFormat();
|
sl@0
|
439 |
richText1->ExternalizeFieldDataL(out);
|
sl@0
|
440 |
richText1->ExternalizeStyleDataL(out);
|
sl@0
|
441 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
442 |
out.WriteUint8L((TUint8)hasMarkupData!=EFalse);
|
sl@0
|
443 |
if (hasMarkupData)
|
sl@0
|
444 |
richText1->ExternalizeMarkupDataL(out);
|
sl@0
|
445 |
richText1->ExternalizePlainTextL(out);
|
sl@0
|
446 |
//
|
sl@0
|
447 |
delete richText1;
|
sl@0
|
448 |
out.CommitL();
|
sl@0
|
449 |
//
|
sl@0
|
450 |
map->Reset();
|
sl@0
|
451 |
CleanupStack::PopAndDestroy(2); // map,out
|
sl@0
|
452 |
TheStore->CommitL();
|
sl@0
|
453 |
//
|
sl@0
|
454 |
// Load the rich text
|
sl@0
|
455 |
empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
456 |
empty->SetFieldFactory(&factory);
|
sl@0
|
457 |
RStoreReadStream in;
|
sl@0
|
458 |
in.OpenLC(*TheStore,id1);
|
sl@0
|
459 |
empty->InternalizeFieldDataL(in);
|
sl@0
|
460 |
empty->InternalizeStyleDataL(in);
|
sl@0
|
461 |
hasMarkupData=(TBool)in.ReadUint8L();
|
sl@0
|
462 |
if (hasMarkupData)
|
sl@0
|
463 |
empty->InternalizeMarkupDataL(in);
|
sl@0
|
464 |
empty->InternalizePlainTextL(in);
|
sl@0
|
465 |
CleanupStack::PopAndDestroy(); // in
|
sl@0
|
466 |
//
|
sl@0
|
467 |
empty->RestoreFieldComponentsL(*TheStore);
|
sl@0
|
468 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
469 |
test(hasMarkupData);
|
sl@0
|
470 |
paragraphCount=empty->ParagraphCount();
|
sl@0
|
471 |
test(paragraphCount==3);
|
sl@0
|
472 |
test(empty->StyleList()->Count()==3); // the style list is now externally owned.
|
sl@0
|
473 |
delete empty;
|
sl@0
|
474 |
empty=NULL;
|
sl@0
|
475 |
//
|
sl@0
|
476 |
// Case (8) Rich text with fields with referenced style list with markup - default store
|
sl@0
|
477 |
//
|
sl@0
|
478 |
INFO_PRINTF1(_L("RT + fields + markup + style list - default store"));
|
sl@0
|
479 |
// Setup the rich text
|
sl@0
|
480 |
list=CreatePopulatedStyleList();
|
sl@0
|
481 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
|
sl@0
|
482 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
483 |
test(hasMarkupData);
|
sl@0
|
484 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
485 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
486 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
487 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
488 |
paraFormat=CParaFormat::NewLC();
|
sl@0
|
489 |
paraMask.ClearAll();
|
sl@0
|
490 |
paraFormat->iHorizontalAlignment=CParaFormat::ERightAlign;
|
sl@0
|
491 |
paraMask.SetAttrib(EAttAlignment);
|
sl@0
|
492 |
richText1->ApplyParaFormatL(paraFormat,paraMask,8,0);
|
sl@0
|
493 |
CleanupStack::PopAndDestroy(); // paraFormat
|
sl@0
|
494 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
495 |
test(hasMarkupData);
|
sl@0
|
496 |
//
|
sl@0
|
497 |
// Now add a text field to this.
|
sl@0
|
498 |
richText1->SetFieldFactory(&factory);
|
sl@0
|
499 |
field=NULL;
|
sl@0
|
500 |
TRAP(ret,
|
sl@0
|
501 |
field=factory.NewFieldL(KDateTimeFieldUid));
|
sl@0
|
502 |
test(ret==KErrNone);
|
sl@0
|
503 |
TRAP(ret,
|
sl@0
|
504 |
richText1->InsertFieldL(0,field,KDateTimeFieldUid));
|
sl@0
|
505 |
test(ret==KErrNone);
|
sl@0
|
506 |
TRAP(ret,
|
sl@0
|
507 |
richText1->UpdateFieldL(0));
|
sl@0
|
508 |
test(ret==KErrNone);
|
sl@0
|
509 |
//
|
sl@0
|
510 |
// Save the rich text
|
sl@0
|
511 |
id1=richText1->StoreL(*TheStore);
|
sl@0
|
512 |
delete richText1;
|
sl@0
|
513 |
//
|
sl@0
|
514 |
// Load the rich text
|
sl@0
|
515 |
empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
516 |
empty->SetFieldFactory(&factory);
|
sl@0
|
517 |
empty->RestoreL(*TheStore,id1);
|
sl@0
|
518 |
//
|
sl@0
|
519 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
520 |
test(hasMarkupData);
|
sl@0
|
521 |
paragraphCount=empty->ParagraphCount();
|
sl@0
|
522 |
test(paragraphCount==3);
|
sl@0
|
523 |
TEtextComponentInfo ci=empty->ComponentInfo();
|
sl@0
|
524 |
test(ci.iFieldCount==1);
|
sl@0
|
525 |
test(ci.iStyleCount==3);
|
sl@0
|
526 |
delete empty;
|
sl@0
|
527 |
empty=NULL; //
|
sl@0
|
528 |
//
|
sl@0
|
529 |
// Case (9) Rich text with no components whatsoever - default store
|
sl@0
|
530 |
//
|
sl@0
|
531 |
INFO_PRINTF1(_L("RT + no markup whatsoever - default store"));
|
sl@0
|
532 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
533 |
hasMarkupData=richText1->HasMarkupData();
|
sl@0
|
534 |
test(!hasMarkupData);
|
sl@0
|
535 |
richText1->InsertL(0,_L("hello"));
|
sl@0
|
536 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
537 |
richText1->InsertL(richText1->DocumentLength(),_L("there"));
|
sl@0
|
538 |
richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
539 |
//
|
sl@0
|
540 |
// Save the rich text
|
sl@0
|
541 |
id1=richText1->StoreL(*TheStore);
|
sl@0
|
542 |
delete richText1;
|
sl@0
|
543 |
//
|
sl@0
|
544 |
// Load the rich text
|
sl@0
|
545 |
empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
546 |
empty->RestoreL(*TheStore,id1);
|
sl@0
|
547 |
//
|
sl@0
|
548 |
hasMarkupData=empty->HasMarkupData();
|
sl@0
|
549 |
test(!hasMarkupData);
|
sl@0
|
550 |
paragraphCount=empty->ParagraphCount();
|
sl@0
|
551 |
test(paragraphCount==3);
|
sl@0
|
552 |
ci=empty->ComponentInfo();
|
sl@0
|
553 |
test(ci.iFieldCount==0);
|
sl@0
|
554 |
test(ci.iStyleCount==0);
|
sl@0
|
555 |
test(ci.iPictureCount==0);
|
sl@0
|
556 |
delete empty;
|
sl@0
|
557 |
empty=NULL;
|
sl@0
|
558 |
//
|
sl@0
|
559 |
//
|
sl@0
|
560 |
CleanupStack::PopAndDestroy(); // TheStore
|
sl@0
|
561 |
}
|
sl@0
|
562 |
|
sl@0
|
563 |
/**
|
sl@0
|
564 |
@SYMTestCaseID SYSLIB-ETEXT-CT-3380
|
sl@0
|
565 |
@SYMTestCaseDesc Inserting and deleting rich text and verify behaviours of DeleteParagraph(), Delete() and NotifyDelete();
|
sl@0
|
566 |
ie. when encounter paragraph delimiter and hidden character
|
sl@0
|
567 |
@SYMTestPriority High
|
sl@0
|
568 |
@SYMTestActions 1. Insert and delete a whole paragraph of rich text
|
sl@0
|
569 |
2. Insert a paragraph and delete some text
|
sl@0
|
570 |
3. Insert 2nd paragraph and DeleteParagraph() both
|
sl@0
|
571 |
4. Insert field to rich text object and delete field
|
sl@0
|
572 |
5. Insert field to rich text object after some plain text and delete it
|
sl@0
|
573 |
6. Insert field to rich text object in between two plain texts then delete the field to merge the texts
|
sl@0
|
574 |
7. Insert plain text in between two fields to rich text object then delete plain text to merge two fields
|
sl@0
|
575 |
@SYMTestExpectedResults CTextFieldSet, CPlainText, CRichText's APIs for performing various types of deletion function properly when
|
sl@0
|
576 |
dealing with paragraph delimiter and hidden characters in a paragraph
|
sl@0
|
577 |
@SYMDEF PDEF101757
|
sl@0
|
578 |
*/
|
sl@0
|
579 |
void CT_TRTCUSTM::TestDEF101757()
|
sl@0
|
580 |
{
|
sl@0
|
581 |
TFindFieldInfo info;
|
sl@0
|
582 |
TTestFieldFactoryTRTCUSTM factory;
|
sl@0
|
583 |
CTextField* field=NULL;
|
sl@0
|
584 |
CTextField* field1=NULL;
|
sl@0
|
585 |
CTextField* field2=NULL;
|
sl@0
|
586 |
CTextField* field3=NULL;
|
sl@0
|
587 |
CTextField* field4=NULL;
|
sl@0
|
588 |
|
sl@0
|
589 |
_LIT(KSample1, "Hello"); // length:5
|
sl@0
|
590 |
_LIT(KSample2, "How are you"); // length:11
|
sl@0
|
591 |
|
sl@0
|
592 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-CT-3380 Insertion and deletion to rich text object "));
|
sl@0
|
593 |
|
sl@0
|
594 |
CRichText* richText=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
595 |
CleanupStack::PushL(richText);
|
sl@0
|
596 |
|
sl@0
|
597 |
// Case1
|
sl@0
|
598 |
// Insert and delete a whole paragraph of rich text
|
sl@0
|
599 |
richText->InsertL(0, KSample1);
|
sl@0
|
600 |
richText->InsertL(richText->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
601 |
test(richText->DocumentLength()==6);
|
sl@0
|
602 |
|
sl@0
|
603 |
richText->DeleteParagraph(0, 5); //do not delete para delimiter
|
sl@0
|
604 |
|
sl@0
|
605 |
richText->InsertL(0, KSample1);
|
sl@0
|
606 |
richText->InsertL(richText->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
607 |
test(richText->DocumentLength()==7);
|
sl@0
|
608 |
|
sl@0
|
609 |
richText->DeleteParagraph(0, 7); //delete para delimiter
|
sl@0
|
610 |
|
sl@0
|
611 |
test(richText->DocumentLength()==0);
|
sl@0
|
612 |
test(richText->ParagraphCount()==1);
|
sl@0
|
613 |
|
sl@0
|
614 |
// Case2
|
sl@0
|
615 |
// Insert a paragraph and delete some text
|
sl@0
|
616 |
richText->InsertL(0, KSample2);
|
sl@0
|
617 |
richText->InsertL(richText->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
618 |
test(richText->DocumentLength()==12);
|
sl@0
|
619 |
|
sl@0
|
620 |
richText->DeleteParagraph(10, 1); //delete last char 'u' and not para delimter
|
sl@0
|
621 |
test(richText->DocumentLength()==11);
|
sl@0
|
622 |
|
sl@0
|
623 |
richText->DeleteParagraph(9, 2); //delete last char 'o' and also para delimter
|
sl@0
|
624 |
test(richText->DocumentLength()==9);
|
sl@0
|
625 |
//should not panic due to fix for PDEF101757
|
sl@0
|
626 |
|
sl@0
|
627 |
test(richText->ParagraphCount()==1);
|
sl@0
|
628 |
|
sl@0
|
629 |
// Case3
|
sl@0
|
630 |
// Insert 2nd paragraph and DeleteParagraph() both
|
sl@0
|
631 |
richText->InsertL(richText->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
632 |
test(richText->ParagraphCount()==2);
|
sl@0
|
633 |
richText->InsertL(richText->DocumentLength(),KSample1);
|
sl@0
|
634 |
richText->InsertL(richText->DocumentLength(),CEditableText::EParagraphDelimiter);
|
sl@0
|
635 |
test(richText->DocumentLength()==16);
|
sl@0
|
636 |
test(richText->ParagraphCount()==3); //2 paragraph delimiters including EOD delimiter (always there)
|
sl@0
|
637 |
|
sl@0
|
638 |
richText->DeleteParagraph(0, 16);
|
sl@0
|
639 |
test(richText->DocumentLength()==0);
|
sl@0
|
640 |
test(richText->ParagraphCount()==1); //2 paragrsphs deleted
|
sl@0
|
641 |
|
sl@0
|
642 |
// Case4
|
sl@0
|
643 |
// Insert field to rich text object and delete field
|
sl@0
|
644 |
richText->SetFieldFactory(&factory);
|
sl@0
|
645 |
field=factory.NewFieldL(KDateTimeFieldUid); // TUid KDateTimeFieldUid: length:10
|
sl@0
|
646 |
CleanupStack::PushL(field);
|
sl@0
|
647 |
richText->InsertFieldL(0,field,KDateTimeFieldUid);
|
sl@0
|
648 |
CleanupStack::Pop(field);//richtext has taken ownership successfully
|
sl@0
|
649 |
|
sl@0
|
650 |
richText->UpdateFieldL(0);
|
sl@0
|
651 |
test(richText->FieldCount()==1);
|
sl@0
|
652 |
richText->DeleteParagraph(0, 10);
|
sl@0
|
653 |
richText->UpdateFieldL(0);
|
sl@0
|
654 |
test(richText->FieldCount()==0);
|
sl@0
|
655 |
|
sl@0
|
656 |
// Case5
|
sl@0
|
657 |
// Insert field to rich text object after some plain text and delete it
|
sl@0
|
658 |
richText->InsertL(0, KSample1);
|
sl@0
|
659 |
field1=factory.NewFieldL(KDateTimeFieldUid);
|
sl@0
|
660 |
CleanupStack::PushL(field1);
|
sl@0
|
661 |
richText->InsertFieldL(5, field1, KDateTimeFieldUid);
|
sl@0
|
662 |
CleanupStack::Pop(field1);
|
sl@0
|
663 |
richText->UpdateFieldL(5);
|
sl@0
|
664 |
test(richText->FieldCount()==1);
|
sl@0
|
665 |
richText->DeleteParagraph(5, 10);
|
sl@0
|
666 |
test(richText->FieldCount()==0);
|
sl@0
|
667 |
|
sl@0
|
668 |
// Case6
|
sl@0
|
669 |
// Insert field to rich text object in between two plain texts then delete the field to merge the texts
|
sl@0
|
670 |
field2=factory.NewFieldL(KDateTimeFieldUid);
|
sl@0
|
671 |
CleanupStack::PushL(field2);
|
sl@0
|
672 |
richText->InsertFieldL(5, field2, KDateTimeFieldUid);
|
sl@0
|
673 |
CleanupStack::Pop(field2);
|
sl@0
|
674 |
richText->UpdateFieldL(5);
|
sl@0
|
675 |
richText->InsertL(14, KSample1);
|
sl@0
|
676 |
richText->DeleteParagraph(5, 10);
|
sl@0
|
677 |
test(richText->DocumentLength()==10); //two plain texts merged
|
sl@0
|
678 |
richText->DeleteParagraph(0, 10);
|
sl@0
|
679 |
test(richText->FieldCount()==0);
|
sl@0
|
680 |
test(richText->DocumentLength()==0);
|
sl@0
|
681 |
|
sl@0
|
682 |
// Case7
|
sl@0
|
683 |
// Insert plain text in between two fields to rich text object then delete plain text to merge two fields
|
sl@0
|
684 |
field3=factory.NewFieldL(KDateTimeFieldUid);
|
sl@0
|
685 |
field4=factory.NewFieldL(KDateTimeFieldUid);
|
sl@0
|
686 |
|
sl@0
|
687 |
CleanupStack::PushL(field3);
|
sl@0
|
688 |
richText->InsertFieldL(0, field3, KDateTimeFieldUid);
|
sl@0
|
689 |
CleanupStack::Pop(field3);
|
sl@0
|
690 |
richText->UpdateFieldL(0);
|
sl@0
|
691 |
|
sl@0
|
692 |
richText->InsertL(10, KSample1);
|
sl@0
|
693 |
|
sl@0
|
694 |
CleanupStack::PushL(field4);
|
sl@0
|
695 |
richText->InsertFieldL(15, field4, KDateTimeFieldUid);
|
sl@0
|
696 |
CleanupStack::Pop(field4);
|
sl@0
|
697 |
richText->UpdateFieldL(15);
|
sl@0
|
698 |
richText->DeleteParagraph(10, 5);
|
sl@0
|
699 |
|
sl@0
|
700 |
richText->FindFields(info,5);
|
sl@0
|
701 |
test(info.iFirstFieldLen==10);
|
sl@0
|
702 |
test(info.iFirstFieldPos==0);
|
sl@0
|
703 |
richText->FindFields(info,15);
|
sl@0
|
704 |
test(info.iFirstFieldLen==10);
|
sl@0
|
705 |
test(info.iFirstFieldPos==10);
|
sl@0
|
706 |
test(richText->FieldCount()==2);
|
sl@0
|
707 |
|
sl@0
|
708 |
CleanupStack::PopAndDestroy(richText);
|
sl@0
|
709 |
}
|
sl@0
|
710 |
|
sl@0
|
711 |
|
sl@0
|
712 |
//Testcode for INC054540
|
sl@0
|
713 |
void CT_TRTCUSTM::TestINC054540()
|
sl@0
|
714 |
{
|
sl@0
|
715 |
theFs.Delete(KTRtCustOutputFile);
|
sl@0
|
716 |
theFs.MkDirAll(KTRtCustOutputFile);
|
sl@0
|
717 |
TheStore=CPermanentFileStore::CreateLC(theFs,KTRtCustOutputFile,EFileRead|EFileWrite);
|
sl@0
|
718 |
TheStore->SetTypeL(TheStore->Layout());
|
sl@0
|
719 |
//
|
sl@0
|
720 |
//test 1: Test INC054540 fix for 255 fields
|
sl@0
|
721 |
//
|
sl@0
|
722 |
INFO_PRINTF1(_L("test"));
|
sl@0
|
723 |
|
sl@0
|
724 |
CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
725 |
//
|
sl@0
|
726 |
// Now add a text field to this.
|
sl@0
|
727 |
TTestFieldFactoryTRTCUSTM factory;
|
sl@0
|
728 |
richText1->SetFieldFactory(&factory);
|
sl@0
|
729 |
CTextField* field=NULL;
|
sl@0
|
730 |
TInt x=0;
|
sl@0
|
731 |
//add 255 fields
|
sl@0
|
732 |
while(x<255)
|
sl@0
|
733 |
{
|
sl@0
|
734 |
TRAPD(ret,field=factory.NewFieldL(KDateTimeFieldUid));
|
sl@0
|
735 |
test(ret==KErrNone);
|
sl@0
|
736 |
TRAP(ret,richText1->InsertFieldL(0,field,KDateTimeFieldUid));
|
sl@0
|
737 |
test(ret==KErrNone);
|
sl@0
|
738 |
TRAP(ret,richText1->UpdateFieldL(0));
|
sl@0
|
739 |
test(ret==KErrNone);
|
sl@0
|
740 |
x++;
|
sl@0
|
741 |
}
|
sl@0
|
742 |
// Save the rich text
|
sl@0
|
743 |
//
|
sl@0
|
744 |
CStoreMap* map=CStoreMap::NewLC(*TheStore);
|
sl@0
|
745 |
richText1->StoreFieldComponentsL(*TheStore,*map);
|
sl@0
|
746 |
//
|
sl@0
|
747 |
RStoreWriteStream out1(*map);
|
sl@0
|
748 |
TStreamId id1=out1.CreateLC(*TheStore);
|
sl@0
|
749 |
//
|
sl@0
|
750 |
richText1->ExternalizeFieldDataL(out1);
|
sl@0
|
751 |
//
|
sl@0
|
752 |
delete richText1;
|
sl@0
|
753 |
out1.CommitL();
|
sl@0
|
754 |
//
|
sl@0
|
755 |
map->Reset();
|
sl@0
|
756 |
CleanupStack::PopAndDestroy(2); // map,out1
|
sl@0
|
757 |
TheStore->CommitL();
|
sl@0
|
758 |
//
|
sl@0
|
759 |
// Load the rich text
|
sl@0
|
760 |
CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
761 |
empty->SetFieldFactory(&factory);
|
sl@0
|
762 |
RStoreReadStream in;
|
sl@0
|
763 |
in.OpenLC(*TheStore,id1);
|
sl@0
|
764 |
empty->InternalizeFieldDataL(in);
|
sl@0
|
765 |
CleanupStack::PopAndDestroy(); // in
|
sl@0
|
766 |
//
|
sl@0
|
767 |
empty->RestoreFieldComponentsL(*TheStore);
|
sl@0
|
768 |
test(empty->FieldCount()==255);
|
sl@0
|
769 |
delete empty;
|
sl@0
|
770 |
empty=NULL;
|
sl@0
|
771 |
|
sl@0
|
772 |
//
|
sl@0
|
773 |
//test 2: Test INC054540 fix for more than 255 fields
|
sl@0
|
774 |
//
|
sl@0
|
775 |
INFO_PRINTF1(_L("test for more than 255 fields"));
|
sl@0
|
776 |
richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
777 |
// Add the text fields
|
sl@0
|
778 |
richText1->SetFieldFactory(&factory);
|
sl@0
|
779 |
field=NULL;
|
sl@0
|
780 |
x=0;
|
sl@0
|
781 |
//add 256 fields
|
sl@0
|
782 |
while(x<256)
|
sl@0
|
783 |
{
|
sl@0
|
784 |
TRAPD(ret,field=factory.NewFieldL(KDateTimeFieldUid));
|
sl@0
|
785 |
test(ret==KErrNone);
|
sl@0
|
786 |
TRAP(ret,richText1->InsertFieldL(0,field,KDateTimeFieldUid));
|
sl@0
|
787 |
test(ret==KErrNone);
|
sl@0
|
788 |
TRAP(ret,richText1->UpdateFieldL(0));
|
sl@0
|
789 |
test(ret==KErrNone);
|
sl@0
|
790 |
x++;
|
sl@0
|
791 |
}
|
sl@0
|
792 |
// Save the rich text
|
sl@0
|
793 |
//
|
sl@0
|
794 |
map=CStoreMap::NewLC(*TheStore);
|
sl@0
|
795 |
richText1->StoreFieldComponentsL(*TheStore,*map);
|
sl@0
|
796 |
//
|
sl@0
|
797 |
RStoreWriteStream out2(*map);
|
sl@0
|
798 |
id1=out2.CreateLC(*TheStore);
|
sl@0
|
799 |
//
|
sl@0
|
800 |
richText1->ExternalizeFieldDataL(out2);
|
sl@0
|
801 |
//
|
sl@0
|
802 |
delete richText1;
|
sl@0
|
803 |
out2.CommitL();
|
sl@0
|
804 |
//
|
sl@0
|
805 |
map->Reset();
|
sl@0
|
806 |
CleanupStack::PopAndDestroy(2); // map,out2
|
sl@0
|
807 |
TheStore->CommitL();
|
sl@0
|
808 |
//
|
sl@0
|
809 |
// Load the rich text
|
sl@0
|
810 |
empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
|
sl@0
|
811 |
empty->SetFieldFactory(&factory);
|
sl@0
|
812 |
in.OpenLC(*TheStore,id1);
|
sl@0
|
813 |
empty->InternalizeFieldDataL(in);
|
sl@0
|
814 |
CleanupStack::PopAndDestroy(); // in
|
sl@0
|
815 |
//
|
sl@0
|
816 |
empty->RestoreFieldComponentsL(*TheStore);
|
sl@0
|
817 |
test(empty->FieldCount()==256);
|
sl@0
|
818 |
delete empty;
|
sl@0
|
819 |
empty=NULL;
|
sl@0
|
820 |
//
|
sl@0
|
821 |
//
|
sl@0
|
822 |
CleanupStack::PopAndDestroy(); // TheStore
|
sl@0
|
823 |
}
|
sl@0
|
824 |
|
sl@0
|
825 |
|
sl@0
|
826 |
void CT_TRTCUSTM::doMainL()
|
sl@0
|
827 |
{
|
sl@0
|
828 |
GlobalParaFormatLayer=CParaFormatLayer::NewL();
|
sl@0
|
829 |
GlobalCharFormatLayer=CCharFormatLayer::NewL();
|
sl@0
|
830 |
theFs.Connect();
|
sl@0
|
831 |
//
|
sl@0
|
832 |
CustomLoadSave();
|
sl@0
|
833 |
TestDEF101757();
|
sl@0
|
834 |
TestINC054540();
|
sl@0
|
835 |
//
|
sl@0
|
836 |
delete GlobalParaFormatLayer;
|
sl@0
|
837 |
delete GlobalCharFormatLayer;
|
sl@0
|
838 |
theFs.Close();
|
sl@0
|
839 |
}
|
sl@0
|
840 |
|
sl@0
|
841 |
|
sl@0
|
842 |
void CT_TRTCUSTM::setupCleanup()
|
sl@0
|
843 |
//
|
sl@0
|
844 |
// Initialise the cleanup stack.
|
sl@0
|
845 |
//
|
sl@0
|
846 |
{
|
sl@0
|
847 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
848 |
test(TheTrapCleanup!=NULL);
|
sl@0
|
849 |
TRAPD(r,\
|
sl@0
|
850 |
{\
|
sl@0
|
851 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
852 |
CleanupStack::PushL((TAny*)0);\
|
sl@0
|
853 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
854 |
});
|
sl@0
|
855 |
test(r==KErrNone);
|
sl@0
|
856 |
}
|
sl@0
|
857 |
|
sl@0
|
858 |
|
sl@0
|
859 |
void CT_TRTCUSTM::DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
860 |
{
|
sl@0
|
861 |
RFs fsSession;
|
sl@0
|
862 |
TInt err = fsSession.Connect();
|
sl@0
|
863 |
if(err == KErrNone)
|
sl@0
|
864 |
{
|
sl@0
|
865 |
TEntry entry;
|
sl@0
|
866 |
if(fsSession.Entry(aFullName, entry) == KErrNone)
|
sl@0
|
867 |
{
|
sl@0
|
868 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
869 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
870 |
if(err != KErrNone)
|
sl@0
|
871 |
{
|
sl@0
|
872 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
873 |
}
|
sl@0
|
874 |
err = fsSession.Delete(aFullName);
|
sl@0
|
875 |
if(err != KErrNone)
|
sl@0
|
876 |
{
|
sl@0
|
877 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
878 |
}
|
sl@0
|
879 |
}
|
sl@0
|
880 |
fsSession.Close();
|
sl@0
|
881 |
}
|
sl@0
|
882 |
else
|
sl@0
|
883 |
{
|
sl@0
|
884 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
885 |
}
|
sl@0
|
886 |
}
|
sl@0
|
887 |
|
sl@0
|
888 |
|
sl@0
|
889 |
CT_TRTCUSTM::CT_TRTCUSTM()
|
sl@0
|
890 |
{
|
sl@0
|
891 |
SetTestStepName(KTestStep_T_TRTCUSTM);
|
sl@0
|
892 |
}
|
sl@0
|
893 |
|
sl@0
|
894 |
TVerdict CT_TRTCUSTM::doTestStepL()
|
sl@0
|
895 |
{
|
sl@0
|
896 |
SetTestStepResult(EFail);
|
sl@0
|
897 |
|
sl@0
|
898 |
setupCleanup();
|
sl@0
|
899 |
__UHEAP_MARK;
|
sl@0
|
900 |
|
sl@0
|
901 |
INFO_PRINTF1(_L("TRTCUSTM"));
|
sl@0
|
902 |
INFO_PRINTF1(_L("Testing custom save/load optimization"));
|
sl@0
|
903 |
TRAPD(error1, doMainL());
|
sl@0
|
904 |
DeleteDataFile(KTRtCustOutputFile); //deletion of data files must be before call to End() - DEF047652
|
sl@0
|
905 |
|
sl@0
|
906 |
__UHEAP_MARKEND;
|
sl@0
|
907 |
delete TheTrapCleanup;
|
sl@0
|
908 |
|
sl@0
|
909 |
if(error1 == KErrNone)
|
sl@0
|
910 |
{
|
sl@0
|
911 |
SetTestStepResult(EPass);
|
sl@0
|
912 |
}
|
sl@0
|
913 |
|
sl@0
|
914 |
return TestStepResult();
|
sl@0
|
915 |
}
|