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 <e32std.h>
|
sl@0
|
20 |
#include <e32base.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <gdi.h>
|
sl@0
|
23 |
#include <conpics.h>
|
sl@0
|
24 |
#include <s32file.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <txtrich.h>
|
sl@0
|
27 |
#include <txtfmlyr.h>
|
sl@0
|
28 |
#include "TXTMRTSR.H"
|
sl@0
|
29 |
|
sl@0
|
30 |
#include "../incp/T_PMLPAR.H"
|
sl@0
|
31 |
#include "T_PICRES.h"
|
sl@0
|
32 |
|
sl@0
|
33 |
LOCAL_D CTestStep *pTestStep = NULL;
|
sl@0
|
34 |
#define test(cond) \
|
sl@0
|
35 |
{ \
|
sl@0
|
36 |
TBool __bb = (cond); \
|
sl@0
|
37 |
pTestStep->TEST(__bb); \
|
sl@0
|
38 |
if (!__bb) \
|
sl@0
|
39 |
{ \
|
sl@0
|
40 |
pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed")); \
|
sl@0
|
41 |
User::Leave(1); \
|
sl@0
|
42 |
} \
|
sl@0
|
43 |
}
|
sl@0
|
44 |
#undef INFO_PRINTF1
|
sl@0
|
45 |
#undef INFO_PRINTF2
|
sl@0
|
46 |
// copy from tefexportconst.h
|
sl@0
|
47 |
#define INFO_PRINTF1(p1) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1))
|
sl@0
|
48 |
#define INFO_PRINTF2(p1, p2) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2))
|
sl@0
|
49 |
|
sl@0
|
50 |
|
sl@0
|
51 |
#define UNUSED_VAR(a) a = a
|
sl@0
|
52 |
|
sl@0
|
53 |
const TInt KTestCleanupStack=0x40;
|
sl@0
|
54 |
|
sl@0
|
55 |
class CContainer : public CBase, public MRichTextStoreResolver
|
sl@0
|
56 |
{
|
sl@0
|
57 |
public:
|
sl@0
|
58 |
static CContainer* NewL();
|
sl@0
|
59 |
~CContainer();
|
sl@0
|
60 |
//
|
sl@0
|
61 |
// Mixin
|
sl@0
|
62 |
//
|
sl@0
|
63 |
virtual const CStreamStore& StreamStoreL(TInt aPos)const;
|
sl@0
|
64 |
// Methods
|
sl@0
|
65 |
TStreamId StoreL(CStreamStore& aStore)const;
|
sl@0
|
66 |
void RestoreL(const CStreamStore& aStore,TStreamId aId,MPictureFactory* aFctry);
|
sl@0
|
67 |
protected:
|
sl@0
|
68 |
CContainer();
|
sl@0
|
69 |
void ConstructL();
|
sl@0
|
70 |
public:
|
sl@0
|
71 |
CRichText* iText;
|
sl@0
|
72 |
const CParaFormatLayer* iGlobalParaFormatLayer;
|
sl@0
|
73 |
const CCharFormatLayer* iGlobalCharFormatLayer;
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
77 |
LOCAL_D RFs TheFs; // the file server
|
sl@0
|
78 |
LOCAL_D RFile TheFile; // the data file
|
sl@0
|
79 |
LOCAL_D CFileStore* TheStore; // concrete CStreamStore
|
sl@0
|
80 |
LOCAL_D CParser* TheParser;
|
sl@0
|
81 |
LOCAL_D CContainer* TheContainer;
|
sl@0
|
82 |
LOCAL_D CStreamStore* TheDeferredPictureStore;
|
sl@0
|
83 |
|
sl@0
|
84 |
CContainer* CContainer::NewL()
|
sl@0
|
85 |
// Create new container & set its components.
|
sl@0
|
86 |
//
|
sl@0
|
87 |
{
|
sl@0
|
88 |
CContainer* self=new(ELeave) CContainer;
|
sl@0
|
89 |
CleanupStack::PushL(self);
|
sl@0
|
90 |
self->ConstructL();
|
sl@0
|
91 |
CleanupStack::Pop();
|
sl@0
|
92 |
return self;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
|
sl@0
|
96 |
CContainer::CContainer()
|
sl@0
|
97 |
{
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
|
sl@0
|
101 |
void CContainer::ConstructL()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
TFileName theFileName = _L("z:\\test\\app-framework\\etext\\t_picres.pml");
|
sl@0
|
104 |
TheParser=CParser::NewL();
|
sl@0
|
105 |
CleanupStack::PushL(TheParser);
|
sl@0
|
106 |
iText=TheParser->ParseL(theFileName);
|
sl@0
|
107 |
CleanupStack::PopAndDestroy();
|
sl@0
|
108 |
iGlobalParaFormatLayer=iText->GlobalParaFormatLayer();
|
sl@0
|
109 |
iGlobalCharFormatLayer=iText->GlobalCharFormatLayer();
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
|
sl@0
|
113 |
CContainer::~CContainer()
|
sl@0
|
114 |
{
|
sl@0
|
115 |
delete iText;
|
sl@0
|
116 |
delete (CParaFormatLayer*)iGlobalParaFormatLayer;
|
sl@0
|
117 |
delete (CCharFormatLayer*)iGlobalCharFormatLayer;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
|
sl@0
|
121 |
const CStreamStore& CContainer::StreamStoreL(TInt /*aPos*/)const
|
sl@0
|
122 |
// Return the deferred picture store.
|
sl@0
|
123 |
// In this instance, the deferred picture store does not vary with document position.
|
sl@0
|
124 |
//
|
sl@0
|
125 |
{return *TheDeferredPictureStore;}
|
sl@0
|
126 |
|
sl@0
|
127 |
|
sl@0
|
128 |
TStreamId CContainer::StoreL(CStreamStore& aStore)const
|
sl@0
|
129 |
// Store this component
|
sl@0
|
130 |
//
|
sl@0
|
131 |
{
|
sl@0
|
132 |
CStoreMap* map=CStoreMap::NewLC(aStore);
|
sl@0
|
133 |
iText->StoreComponentsL(aStore,*map);
|
sl@0
|
134 |
//
|
sl@0
|
135 |
RStoreWriteStream stream(*map);
|
sl@0
|
136 |
TStreamId id=stream.CreateLC(aStore);
|
sl@0
|
137 |
iGlobalParaFormatLayer->ExternalizeL(stream);
|
sl@0
|
138 |
iGlobalCharFormatLayer->ExternalizeL(stream);
|
sl@0
|
139 |
stream<< *iText;
|
sl@0
|
140 |
stream.CommitL();
|
sl@0
|
141 |
//
|
sl@0
|
142 |
map->Reset();
|
sl@0
|
143 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
144 |
return id;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
|
sl@0
|
148 |
void CContainer::RestoreL(const CStreamStore& aStore,TStreamId aId,MPictureFactory* aFactory)
|
sl@0
|
149 |
// Restore this component
|
sl@0
|
150 |
//
|
sl@0
|
151 |
{
|
sl@0
|
152 |
RStoreReadStream stream;
|
sl@0
|
153 |
stream.OpenLC(aStore,aId);
|
sl@0
|
154 |
iGlobalParaFormatLayer=CParaFormatLayer::NewL(stream);
|
sl@0
|
155 |
iGlobalCharFormatLayer=CCharFormatLayer::NewL(stream);
|
sl@0
|
156 |
iText=CRichText::NewL(iGlobalParaFormatLayer,iGlobalCharFormatLayer);
|
sl@0
|
157 |
iText->SetPictureFactory(aFactory,this);
|
sl@0
|
158 |
stream>> *iText;
|
sl@0
|
159 |
//
|
sl@0
|
160 |
CleanupStack::PopAndDestroy();
|
sl@0
|
161 |
//
|
sl@0
|
162 |
iText->RestoreComponentsL(aStore);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
_LIT(KOutputFile, "c:\\etext\\t_word.doc");
|
sl@0
|
166 |
LOCAL_C void testPictureRestorer(TBool aDeferPictureLoad=ETrue)
|
sl@0
|
167 |
// Test Picture persistance.
|
sl@0
|
168 |
//
|
sl@0
|
169 |
{
|
sl@0
|
170 |
//
|
sl@0
|
171 |
TheFs.Connect();
|
sl@0
|
172 |
//
|
sl@0
|
173 |
TheFs.Delete(KOutputFile);
|
sl@0
|
174 |
TheFs.MkDirAll(KOutputFile);
|
sl@0
|
175 |
TheStore=CDirectFileStore::CreateL(TheFs,KOutputFile,EFileRead|EFileWrite);
|
sl@0
|
176 |
TheDeferredPictureStore=TheStore;
|
sl@0
|
177 |
CleanupStack::PushL(TheStore);
|
sl@0
|
178 |
TheStore->SetTypeL(KDirectFileStoreLayoutUid);
|
sl@0
|
179 |
//
|
sl@0
|
180 |
// Create concrete picture factory.
|
sl@0
|
181 |
MDemPictureFactory* factory=new(ELeave) MDemPictureFactory;
|
sl@0
|
182 |
|
sl@0
|
183 |
TheContainer->iText->Reset();
|
sl@0
|
184 |
TheContainer->iText->InsertL(0,_L("Hello Duncan how"));
|
sl@0
|
185 |
|
sl@0
|
186 |
TheContainer->iText->SetPictureFactory(factory,TheContainer);
|
sl@0
|
187 |
// Create some pictures.
|
sl@0
|
188 |
CXzePicture* pic1=CXzePicture::NewL('x');
|
sl@0
|
189 |
CleanupStack::PushL(pic1);
|
sl@0
|
190 |
CXzePicture* pic2=CXzePicture::NewL('z');
|
sl@0
|
191 |
CleanupStack::PushL(pic2);
|
sl@0
|
192 |
CXzePicture* pic3=CXzePicture::NewL('e');
|
sl@0
|
193 |
CleanupStack::PushL(pic3);
|
sl@0
|
194 |
//
|
sl@0
|
195 |
// Create the picture headers
|
sl@0
|
196 |
TPictureHeader hdr1;
|
sl@0
|
197 |
TPictureHeader hdr2;
|
sl@0
|
198 |
TPictureHeader hdr3;
|
sl@0
|
199 |
//
|
sl@0
|
200 |
TSize size;
|
sl@0
|
201 |
pic1->GetSizeInTwips(size);
|
sl@0
|
202 |
hdr1.iPictureType=KUidXzePictureType;
|
sl@0
|
203 |
hdr1.iPicture=pic1;
|
sl@0
|
204 |
hdr2.iPictureType=KUidXzePictureType;
|
sl@0
|
205 |
hdr2.iPicture=pic2;
|
sl@0
|
206 |
hdr3.iPictureType=KUidXzePictureType;
|
sl@0
|
207 |
hdr3.iPicture=pic3;
|
sl@0
|
208 |
//
|
sl@0
|
209 |
// Insert the pictures into the rich text
|
sl@0
|
210 |
TBool hasMarkupData=TheContainer->iText->HasMarkupData();
|
sl@0
|
211 |
test(!hasMarkupData);
|
sl@0
|
212 |
TheContainer->iText->CancelInsertCharFormat();
|
sl@0
|
213 |
TheContainer->iText->InsertL(0,hdr1);
|
sl@0
|
214 |
TheContainer->iText->InsertL(5,hdr2);
|
sl@0
|
215 |
TheContainer->iText->InsertL(7,hdr3);
|
sl@0
|
216 |
TheContainer->iText->InsertL(0,CEditableText::EParagraphDelimiter);
|
sl@0
|
217 |
TheContainer->iText->CancelInsertCharFormat();
|
sl@0
|
218 |
TheContainer->iText->InsertL(2,CEditableText::EParagraphDelimiter);
|
sl@0
|
219 |
CleanupStack::Pop(3);
|
sl@0
|
220 |
hasMarkupData=TheContainer->iText->HasMarkupData();
|
sl@0
|
221 |
test(hasMarkupData);
|
sl@0
|
222 |
//
|
sl@0
|
223 |
// High level Store context
|
sl@0
|
224 |
TStreamId id=TheContainer->StoreL(*TheStore);
|
sl@0
|
225 |
//
|
sl@0
|
226 |
delete TheContainer->iText;
|
sl@0
|
227 |
delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer;
|
sl@0
|
228 |
delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer;
|
sl@0
|
229 |
//
|
sl@0
|
230 |
//
|
sl@0
|
231 |
// Now restore the container with rich text
|
sl@0
|
232 |
TheContainer->RestoreL(*TheStore,id,factory);
|
sl@0
|
233 |
if (!aDeferPictureLoad)
|
sl@0
|
234 |
TheContainer->iText->DetachFromStoreL(CPicture::EDetachFull);
|
sl@0
|
235 |
//
|
sl@0
|
236 |
hasMarkupData=TheContainer->iText->HasMarkupData();
|
sl@0
|
237 |
test(hasMarkupData);
|
sl@0
|
238 |
test(TheContainer->iText->ParagraphCount()==3);
|
sl@0
|
239 |
test(TheContainer->iText->DocumentLength()==21);
|
sl@0
|
240 |
TPtrC view;
|
sl@0
|
241 |
TCharFormat format;
|
sl@0
|
242 |
CPicture* picture;
|
sl@0
|
243 |
//
|
sl@0
|
244 |
// TEST THE PICTURE HEADERS, DEPENDING ON WHETHER DEFERRED LOADING IS SET OR NOT
|
sl@0
|
245 |
TPictureHeader hdrA=TheContainer->iText->PictureHeader(1);
|
sl@0
|
246 |
test(hdrA.iPictureType==KUidXzePictureType);
|
sl@0
|
247 |
if (aDeferPictureLoad)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
test(hdrA.iPicture.IsId());
|
sl@0
|
250 |
}
|
sl@0
|
251 |
else
|
sl@0
|
252 |
{
|
sl@0
|
253 |
test(hdrA.iPicture!=NULL);
|
sl@0
|
254 |
test(hdrA.iPicture.IsPtr());
|
sl@0
|
255 |
test(((CXzePicture*)hdrA.iPicture.AsPtr())->iLabel=='x');
|
sl@0
|
256 |
}
|
sl@0
|
257 |
TPictureHeader hdrB=TheContainer->iText->PictureHeader(7);
|
sl@0
|
258 |
test(hdrB.iPictureType==KUidXzePictureType);
|
sl@0
|
259 |
if (aDeferPictureLoad)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
test(hdrB.iPicture.IsId());
|
sl@0
|
262 |
}
|
sl@0
|
263 |
else
|
sl@0
|
264 |
{
|
sl@0
|
265 |
test(hdrB.iPicture!=NULL);
|
sl@0
|
266 |
test(hdrB.iPicture.IsPtr());
|
sl@0
|
267 |
test(((CXzePicture*)hdrB.iPicture.AsPtr())->iLabel=='z');
|
sl@0
|
268 |
}
|
sl@0
|
269 |
TPictureHeader hdrC=TheContainer->iText->PictureHeader(9);
|
sl@0
|
270 |
test(hdrC.iPictureType==KUidXzePictureType);
|
sl@0
|
271 |
if (aDeferPictureLoad)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
test(hdrC.iPicture.IsId());
|
sl@0
|
274 |
}
|
sl@0
|
275 |
else
|
sl@0
|
276 |
{
|
sl@0
|
277 |
test(hdrC.iPicture!=NULL);
|
sl@0
|
278 |
test(hdrC.iPicture.IsPtr());
|
sl@0
|
279 |
test(((CXzePicture*)hdrC.iPicture.AsPtr())->iLabel=='e');
|
sl@0
|
280 |
}
|
sl@0
|
281 |
TPictureHeader hdrD=TheContainer->iText->PictureHeader(0); // This is not a picture character
|
sl@0
|
282 |
test(hdrD.iPictureType==KNullUid);
|
sl@0
|
283 |
test(hdrD.iPicture==NULL);
|
sl@0
|
284 |
TSize dummySize;
|
sl@0
|
285 |
test(hdrD.iSize==dummySize);
|
sl@0
|
286 |
//
|
sl@0
|
287 |
TheContainer->iText->GetChars(view,format,1);
|
sl@0
|
288 |
test(view[0]==CEditableText::EPictureCharacter);
|
sl@0
|
289 |
picture=TheContainer->iText->PictureHandleL(1);
|
sl@0
|
290 |
test(((CXzePicture*)picture)->iLabel=='x');
|
sl@0
|
291 |
|
sl@0
|
292 |
TheContainer->iText->GetChars(view,format,7);
|
sl@0
|
293 |
test(view[0]==CEditableText::EPictureCharacter);
|
sl@0
|
294 |
picture=TheContainer->iText->PictureHandleL(7);
|
sl@0
|
295 |
test(((CXzePicture*)picture)->iLabel=='z');
|
sl@0
|
296 |
|
sl@0
|
297 |
TheContainer->iText->GetChars(view,format,9);
|
sl@0
|
298 |
test(view[0]==CEditableText::EPictureCharacter);
|
sl@0
|
299 |
picture=TheContainer->iText->PictureHandleL(9);
|
sl@0
|
300 |
test(((CXzePicture*)picture)->iLabel=='e');
|
sl@0
|
301 |
|
sl@0
|
302 |
delete factory;
|
sl@0
|
303 |
CleanupStack::PopAndDestroy(); // TheStore
|
sl@0
|
304 |
TheFs.Close();
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
_LIT(KOutputFile1, "c:\\etext\\t_word1.doc");
|
sl@0
|
308 |
LOCAL_C void testPictureRestorer2(TBool aAlwaysFailToLoad=EFalse)
|
sl@0
|
309 |
// Test Picture persistance.
|
sl@0
|
310 |
//
|
sl@0
|
311 |
{
|
sl@0
|
312 |
//
|
sl@0
|
313 |
TheFs.Connect();
|
sl@0
|
314 |
//
|
sl@0
|
315 |
TheFs.Delete(KOutputFile1);
|
sl@0
|
316 |
TheFs.MkDirAll(KOutputFile1);
|
sl@0
|
317 |
TheStore=CDirectFileStore::CreateL(TheFs,KOutputFile1,EFileRead|EFileWrite);
|
sl@0
|
318 |
TheDeferredPictureStore=TheStore;
|
sl@0
|
319 |
CleanupStack::PushL(TheStore);
|
sl@0
|
320 |
TheStore->SetTypeL(KDirectFileStoreLayoutUid);
|
sl@0
|
321 |
//
|
sl@0
|
322 |
// Create concrete picture factory.
|
sl@0
|
323 |
MDemPictureFactory* factory=new(ELeave) MDemPictureFactory;
|
sl@0
|
324 |
|
sl@0
|
325 |
TheContainer->iText->Reset();
|
sl@0
|
326 |
TheContainer->iText->InsertL(0,_L("Hello Duncan how"));
|
sl@0
|
327 |
|
sl@0
|
328 |
TheContainer->iText->SetPictureFactory(factory,TheContainer);
|
sl@0
|
329 |
// Create some pictures.
|
sl@0
|
330 |
CXzeDoor* pic1=CXzeDoor::NewL('x',aAlwaysFailToLoad);
|
sl@0
|
331 |
CleanupStack::PushL(pic1);
|
sl@0
|
332 |
CXzeDoor* pic2=CXzeDoor::NewL('z',aAlwaysFailToLoad);
|
sl@0
|
333 |
CleanupStack::PushL(pic2);
|
sl@0
|
334 |
CXzePicture* pic3=CXzePicture::NewL('e'); // Control: will always load.
|
sl@0
|
335 |
CleanupStack::PushL(pic3);
|
sl@0
|
336 |
//
|
sl@0
|
337 |
// Create the picture headers
|
sl@0
|
338 |
TPictureHeader hdr1;
|
sl@0
|
339 |
TPictureHeader hdr2;
|
sl@0
|
340 |
TPictureHeader hdr3;
|
sl@0
|
341 |
//
|
sl@0
|
342 |
TSize size;
|
sl@0
|
343 |
pic1->GetSizeInTwips(size);
|
sl@0
|
344 |
hdr1.iPictureType=KUidXzeDoorType;
|
sl@0
|
345 |
hdr1.iPicture=pic1;
|
sl@0
|
346 |
hdr2.iPictureType=KUidXzeDoorType;
|
sl@0
|
347 |
hdr2.iPicture=pic2;
|
sl@0
|
348 |
hdr3.iPictureType=KUidXzePictureType;
|
sl@0
|
349 |
hdr3.iPicture=pic3;
|
sl@0
|
350 |
//
|
sl@0
|
351 |
// Insert the pictures into the rich text
|
sl@0
|
352 |
TBool hasMarkupData=TheContainer->iText->HasMarkupData();
|
sl@0
|
353 |
test(!hasMarkupData);
|
sl@0
|
354 |
TheContainer->iText->CancelInsertCharFormat();
|
sl@0
|
355 |
TheContainer->iText->InsertL(0,hdr1);
|
sl@0
|
356 |
TheContainer->iText->InsertL(5,hdr2);
|
sl@0
|
357 |
TheContainer->iText->InsertL(7,hdr3);
|
sl@0
|
358 |
TheContainer->iText->InsertL(0,CEditableText::EParagraphDelimiter);
|
sl@0
|
359 |
TheContainer->iText->CancelInsertCharFormat();
|
sl@0
|
360 |
TheContainer->iText->InsertL(2,CEditableText::EParagraphDelimiter);
|
sl@0
|
361 |
CleanupStack::Pop(3); // pic1,2,3 - ownership transferred to rich text
|
sl@0
|
362 |
hasMarkupData=TheContainer->iText->HasMarkupData();
|
sl@0
|
363 |
test(hasMarkupData);
|
sl@0
|
364 |
//
|
sl@0
|
365 |
// High level Store context - all pictures currently in memory
|
sl@0
|
366 |
TStreamId id=TheContainer->StoreL(*TheStore);
|
sl@0
|
367 |
//
|
sl@0
|
368 |
delete TheContainer->iText;
|
sl@0
|
369 |
delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer;
|
sl@0
|
370 |
delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer;
|
sl@0
|
371 |
//
|
sl@0
|
372 |
//
|
sl@0
|
373 |
// Now restore the container with rich text
|
sl@0
|
374 |
TheContainer->RestoreL(*TheStore,id,factory);
|
sl@0
|
375 |
//
|
sl@0
|
376 |
//
|
sl@0
|
377 |
// Now store the stuff again
|
sl@0
|
378 |
TRAPD(ret,
|
sl@0
|
379 |
TheContainer->iText->DetachFromStoreL(CPicture::EDetachFull));
|
sl@0
|
380 |
if (ret==KErrNotSupported)
|
sl@0
|
381 |
INFO_PRINTF1(_L(" SIMULATION: Some picture data is not supported by the current factory."));
|
sl@0
|
382 |
// if (aAlwaysFailToLoad)
|
sl@0
|
383 |
// test(error==KErrNotFound);
|
sl@0
|
384 |
// else
|
sl@0
|
385 |
// test(error==KErrNone);
|
sl@0
|
386 |
id=KNullStreamId;
|
sl@0
|
387 |
TRAP(ret,
|
sl@0
|
388 |
id=TheContainer->StoreL(*TheStore));
|
sl@0
|
389 |
test(ret==KErrNone);
|
sl@0
|
390 |
//
|
sl@0
|
391 |
// ...and restore it to check what we have got.
|
sl@0
|
392 |
delete TheContainer->iText;
|
sl@0
|
393 |
delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer;
|
sl@0
|
394 |
delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer;
|
sl@0
|
395 |
TheContainer->RestoreL(*TheStore,id,factory);
|
sl@0
|
396 |
TInt pictureCount=TheContainer->iText->PictureCount();
|
sl@0
|
397 |
if (aAlwaysFailToLoad)
|
sl@0
|
398 |
{
|
sl@0
|
399 |
test(pictureCount==1);
|
sl@0
|
400 |
}
|
sl@0
|
401 |
else
|
sl@0
|
402 |
{
|
sl@0
|
403 |
test(pictureCount==3);
|
sl@0
|
404 |
}
|
sl@0
|
405 |
//
|
sl@0
|
406 |
delete factory;
|
sl@0
|
407 |
CleanupStack::PopAndDestroy(); // TheStore
|
sl@0
|
408 |
TheFs.Close();
|
sl@0
|
409 |
}
|
sl@0
|
410 |
|
sl@0
|
411 |
|
sl@0
|
412 |
LOCAL_C void GoL()
|
sl@0
|
413 |
// Run the tests
|
sl@0
|
414 |
//
|
sl@0
|
415 |
{
|
sl@0
|
416 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_PICRES-0001 RichText Storing - with pictures deferred loading "));
|
sl@0
|
417 |
TheContainer=CContainer::NewL();
|
sl@0
|
418 |
TRAPD(r,
|
sl@0
|
419 |
testPictureRestorer());
|
sl@0
|
420 |
test(r==KErrNone);
|
sl@0
|
421 |
delete TheContainer; // deletes the rich text, which deletes the contained pictures.
|
sl@0
|
422 |
//
|
sl@0
|
423 |
//
|
sl@0
|
424 |
INFO_PRINTF1(_L("RichText Storing - with pictures auto loading"));
|
sl@0
|
425 |
TheContainer=CContainer::NewL();
|
sl@0
|
426 |
TRAP(r,
|
sl@0
|
427 |
testPictureRestorer(EFalse)); // DO NOT DEFER PICTURE LOADING
|
sl@0
|
428 |
test(r==KErrNone);
|
sl@0
|
429 |
delete TheContainer; // deletes the rich text, which deletes the contained pictures.
|
sl@0
|
430 |
//
|
sl@0
|
431 |
//
|
sl@0
|
432 |
//
|
sl@0
|
433 |
INFO_PRINTF1(_L("Testing no missing picture app's"));
|
sl@0
|
434 |
TheContainer=CContainer::NewL();
|
sl@0
|
435 |
TRAP(r,
|
sl@0
|
436 |
testPictureRestorer2());
|
sl@0
|
437 |
test(r==KErrNone);
|
sl@0
|
438 |
delete TheContainer; // deletes the rich text, which deletes the contained pictures.
|
sl@0
|
439 |
//
|
sl@0
|
440 |
//
|
sl@0
|
441 |
/*
|
sl@0
|
442 |
TEST NOW REDUNDANT AS OF NEW PICTURE CONTAINMENT MECHANISM AS AT RELEASE 073
|
sl@0
|
443 |
|
sl@0
|
444 |
INFO_PRINTF1(_L("Testing missing picture app's"));
|
sl@0
|
445 |
TheContainer=CContainer::NewL();
|
sl@0
|
446 |
TRAP(r,
|
sl@0
|
447 |
testPictureRestorer2(ETrue)); // ALWAYS FAIL TO DETACH FROM STORE
|
sl@0
|
448 |
test(r==KErrNone);
|
sl@0
|
449 |
delete TheContainer; // deletes the rich text, which deletes the contained pictures.
|
sl@0
|
450 |
*/
|
sl@0
|
451 |
}
|
sl@0
|
452 |
|
sl@0
|
453 |
|
sl@0
|
454 |
LOCAL_C void setupCleanup()
|
sl@0
|
455 |
//
|
sl@0
|
456 |
// Initialise the cleanup stack.
|
sl@0
|
457 |
//
|
sl@0
|
458 |
{
|
sl@0
|
459 |
|
sl@0
|
460 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
461 |
TRAPD(r,\
|
sl@0
|
462 |
{\
|
sl@0
|
463 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
464 |
CleanupStack::PushL((TAny*)1);\
|
sl@0
|
465 |
test(r==KErrNone);\
|
sl@0
|
466 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
467 |
});
|
sl@0
|
468 |
}
|
sl@0
|
469 |
|
sl@0
|
470 |
|
sl@0
|
471 |
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
472 |
{
|
sl@0
|
473 |
RFs fsSession;
|
sl@0
|
474 |
TInt err = fsSession.Connect();
|
sl@0
|
475 |
if(err == KErrNone)
|
sl@0
|
476 |
{
|
sl@0
|
477 |
TEntry entry;
|
sl@0
|
478 |
if(fsSession.Entry(aFullName, entry) == KErrNone)
|
sl@0
|
479 |
{
|
sl@0
|
480 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
481 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
482 |
if(err != KErrNone)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
485 |
}
|
sl@0
|
486 |
err = fsSession.Delete(aFullName);
|
sl@0
|
487 |
if(err != KErrNone)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
490 |
}
|
sl@0
|
491 |
}
|
sl@0
|
492 |
fsSession.Close();
|
sl@0
|
493 |
}
|
sl@0
|
494 |
else
|
sl@0
|
495 |
{
|
sl@0
|
496 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
497 |
}
|
sl@0
|
498 |
}
|
sl@0
|
499 |
|
sl@0
|
500 |
CT_PICRES::CT_PICRES()
|
sl@0
|
501 |
{
|
sl@0
|
502 |
SetTestStepName(KTestStep_T_PICRES);
|
sl@0
|
503 |
pTestStep = this;
|
sl@0
|
504 |
}
|
sl@0
|
505 |
|
sl@0
|
506 |
TVerdict CT_PICRES::doTestStepL()
|
sl@0
|
507 |
{
|
sl@0
|
508 |
SetTestStepResult(EFail);
|
sl@0
|
509 |
|
sl@0
|
510 |
INFO_PRINTF1(_L("Testing Picture Restorer mechanism"));
|
sl@0
|
511 |
__UHEAP_MARK;
|
sl@0
|
512 |
setupCleanup();
|
sl@0
|
513 |
TRAPD(r,GoL());
|
sl@0
|
514 |
|
sl@0
|
515 |
delete TheTrapCleanup;
|
sl@0
|
516 |
|
sl@0
|
517 |
__UHEAP_MARKEND;
|
sl@0
|
518 |
|
sl@0
|
519 |
::DeleteDataFile(KOutputFile); //deletion of data files must be before call to End() - DEF047652
|
sl@0
|
520 |
::DeleteDataFile(KOutputFile1);
|
sl@0
|
521 |
|
sl@0
|
522 |
if (r == KErrNone)
|
sl@0
|
523 |
{
|
sl@0
|
524 |
SetTestStepResult(EPass);
|
sl@0
|
525 |
}
|
sl@0
|
526 |
|
sl@0
|
527 |
return TestStepResult();
|
sl@0
|
528 |
}
|