os/textandloc/textrendering/texthandling/ttext/T_TRAN.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/texthandling/ttext/T_TRAN.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,654 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <e32std.h>
    1.23 +#include <e32base.h>
    1.24 +
    1.25 +#include <gdi.h>
    1.26 +#include <conpics.h>
    1.27 +#include <s32file.h>
    1.28 +
    1.29 +#include <txtrich.h>
    1.30 +#include <txtfmlyr.h>
    1.31 +#include "TXTMRTSR.H"
    1.32 +
    1.33 +#include "../incp/T_PMLPAR.H"
    1.34 +//#include "../spml/T_PMLPAR.CPP"
    1.35 +#include "T_TRAN.h"
    1.36 +
    1.37 +LOCAL_D CTestStep *pTestStep = NULL;
    1.38 +#define test(cond)											\
    1.39 +	{														\
    1.40 +	TBool __bb = (cond);									\
    1.41 +	pTestStep->TEST(__bb);									\
    1.42 +	if (!__bb)												\
    1.43 +		{													\
    1.44 +		pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed"));	\
    1.45 +		User::Leave(1);										\
    1.46 +		}													\
    1.47 +	}
    1.48 +#undef INFO_PRINTF1
    1.49 +#undef INFO_PRINTF2
    1.50 +// copy from tefexportconst.h
    1.51 +#define INFO_PRINTF1(p1)        pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1))
    1.52 +#define INFO_PRINTF2(p1, p2)    pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2))
    1.53 +
    1.54 +// included in a namespace, to avoid confliction
    1.55 +namespace T_TRAN {
    1.56 +/* this fixes a MSVC link warning */
    1.57 +#ifdef __VC32__
    1.58 +#pragma comment (linker, "/opt:noref") 
    1.59 +#endif
    1.60 +
    1.61 +#define UNUSED_VAR(a) a = a
    1.62 +
    1.63 +const TInt KTestCleanupStack=0x40;
    1.64 +
    1.65 +_LIT(KExportFileName1, "c:\\etext\\t_para.txg");
    1.66 +_LIT(KExportFileName2, "c:\\etext\\t_para2.txg");
    1.67 +
    1.68 +void EnsureFileExists(const TDesC& aName)
    1.69 +	{
    1.70 +	RFs fs;
    1.71 +	fs.Connect();
    1.72 +	fs.MkDirAll(aName);
    1.73 +	RFile file;
    1.74 +	file.Create(fs, aName, EFileRead|EFileWrite);
    1.75 +	file.Close();
    1.76 +	fs.Close();
    1.77 +	}
    1.78 +
    1.79 +class CContainer : public CBase, public MRichTextStoreResolver
    1.80 +	{
    1.81 +public:
    1.82 +	static CContainer* NewL(TFileName aFileName);
    1.83 +	~CContainer();
    1.84 +	//
    1.85 +	// Mixin
    1.86 +	//
    1.87 +	virtual const CStreamStore& StreamStoreL(TInt aPos)const;
    1.88 +	// Methods
    1.89 +	TStreamId StoreL(CStreamStore& aStore)const;
    1.90 +	void RestoreL(const CStreamStore& aStore,TStreamId aId,MPictureFactory* aFctry);
    1.91 +protected:
    1.92 +	CContainer();
    1.93 +	void ConstructL(TFileName aFileName);
    1.94 +public:
    1.95 +	CRichText* iText;
    1.96 +	const CParaFormatLayer* iGlobalParaFormatLayer;
    1.97 +	const CCharFormatLayer* iGlobalCharFormatLayer;
    1.98 +	};
    1.99 +
   1.100 +LOCAL_D CTrapCleanup* TheTrapCleanup;
   1.101 +LOCAL_D RFs TheFs;  // the file server
   1.102 +LOCAL_D RFile TheFile;  // the data file
   1.103 +LOCAL_D CParser* TheParser;
   1.104 +LOCAL_D CContainer* TheContainer;
   1.105 +LOCAL_D CStreamStore* TheDeferredPictureStore;
   1.106 +
   1.107 +CContainer* CContainer::NewL(TFileName aFileName)
   1.108 +// Create new container & set its components.
   1.109 +//
   1.110 +	{
   1.111 +	CContainer* self=new(ELeave) CContainer;
   1.112 +	CleanupStack::PushL(self);
   1.113 +	self->ConstructL(aFileName);
   1.114 +	CleanupStack::Pop();
   1.115 +	return self;
   1.116 +	}
   1.117 +
   1.118 +
   1.119 +CContainer::CContainer()
   1.120 +	{
   1.121 +	}
   1.122 +
   1.123 +
   1.124 +void CContainer::ConstructL(TFileName aFileName)
   1.125 +	{
   1.126 +	TheParser=CParser::NewL();
   1.127 +	CleanupStack::PushL(TheParser);
   1.128 +	iText=TheParser->ParseL(aFileName);
   1.129 +	CleanupStack::PopAndDestroy();
   1.130 +	iGlobalParaFormatLayer=iText->GlobalParaFormatLayer();
   1.131 +	iGlobalCharFormatLayer=iText->GlobalCharFormatLayer();
   1.132 +	}
   1.133 +
   1.134 +
   1.135 +CContainer::~CContainer()
   1.136 +	{
   1.137 +	delete iText;
   1.138 +	delete (CParaFormatLayer*)iGlobalParaFormatLayer;
   1.139 +	delete (CCharFormatLayer*)iGlobalCharFormatLayer;
   1.140 +	}
   1.141 +
   1.142 +
   1.143 +const CStreamStore& CContainer::StreamStoreL(TInt /*aPos*/)const
   1.144 +// Return the deferred picture store.
   1.145 +// In this instance, the deferred picture store does not vary with document position.
   1.146 +//
   1.147 +	{return *TheDeferredPictureStore;}
   1.148 +
   1.149 +
   1.150 +TStreamId CContainer::StoreL(CStreamStore& aStore)const
   1.151 +// Store this component
   1.152 +//
   1.153 +	{
   1.154 +	CStoreMap* map=CStoreMap::NewLC(aStore);
   1.155 +	iText->StoreComponentsL(aStore,*map);
   1.156 +	//
   1.157 +	RStoreWriteStream stream(*map);
   1.158 +	TStreamId id=stream.CreateLC(aStore);
   1.159 +	iGlobalParaFormatLayer->ExternalizeL(stream);
   1.160 +	iGlobalCharFormatLayer->ExternalizeL(stream);
   1.161 +	stream<< *iText;
   1.162 +	stream.CommitL();
   1.163 +	//
   1.164 +	map->Reset();
   1.165 +	CleanupStack::PopAndDestroy(2);
   1.166 +	return id;
   1.167 +	}
   1.168 +
   1.169 +
   1.170 +void CContainer::RestoreL(const CStreamStore& aStore,TStreamId aId,MPictureFactory* aFactory)
   1.171 +// Restore this component
   1.172 +//
   1.173 +	{
   1.174 +	RStoreReadStream stream;
   1.175 +	stream.OpenLC(aStore,aId);
   1.176 +	iGlobalParaFormatLayer=CParaFormatLayer::NewL(stream);
   1.177 +	iGlobalCharFormatLayer=CCharFormatLayer::NewL(stream);
   1.178 +	iText=CRichText::NewL(iGlobalParaFormatLayer,iGlobalCharFormatLayer);
   1.179 +	iText->SetPictureFactory(aFactory,this);
   1.180 +	stream>> *iText;
   1.181 +	//
   1.182 +	CleanupStack::PopAndDestroy();
   1.183 +	//
   1.184 +	iText->RestoreComponentsL(aStore);
   1.185 +	}
   1.186 +
   1.187 +
   1.188 +/*LOCAL_C void testPictureRestorer(TBool aDeferPictureLoad=ETrue)
   1.189 +// Test Picture persistance.
   1.190 +//
   1.191 +    {
   1.192 +	//
   1.193 +	TheFs.Connect();
   1.194 +	//
   1.195 +	TheStore=CDirectFileStore::ReplaceL(TheFs,_L("c:\\etext\\t_word.doc"),EFileRead|EFileWrite);
   1.196 +	TheDeferredPictureStore=TheStore;
   1.197 +	CleanupStack::PushL(TheStore);
   1.198 +	TheStore->SetTypeL(KDirectFileStoreLayout);
   1.199 +	//
   1.200 +	// Create concrete picture factory.
   1.201 +	MDemPictureFactory* factory=new(ELeave) MDemPictureFactory;
   1.202 +
   1.203 +	TheContainer->iText->Reset();
   1.204 +	TheContainer->iText->InsertL(0,_L("Hello Duncan how"));
   1.205 +
   1.206 +	TheContainer->iText->SetPictureFactory(factory,TheContainer);
   1.207 +	// Create some pictures.
   1.208 +	CXzePicture* pic1=CXzePicture::NewL('x');
   1.209 +		CleanupStack::PushL(pic1);
   1.210 +	CXzePicture* pic2=CXzePicture::NewL('z');
   1.211 +		CleanupStack::PushL(pic2);
   1.212 +	CXzePicture* pic3=CXzePicture::NewL('e');
   1.213 +		CleanupStack::PushL(pic3);
   1.214 +	//
   1.215 +	// Create the picture headers
   1.216 +	TPictureHeader hdr1;
   1.217 +	TPictureHeader hdr2;
   1.218 +	TPictureHeader hdr3;
   1.219 +	//
   1.220 +	TSize size;
   1.221 +	pic1->GetSizeInTwips(size);
   1.222 +	hdr1.iPictureType=KUidXzePictureType;
   1.223 +	hdr1.iPicture=pic1;
   1.224 +	hdr2.iPictureType=KUidXzePictureType;
   1.225 +	hdr2.iPicture=pic2;
   1.226 +	hdr3.iPictureType=KUidXzePictureType;
   1.227 +	hdr3.iPicture=pic3;
   1.228 +	//
   1.229 +	// Insert the pictures into the rich text
   1.230 +	TBool hasMarkupData=TheContainer->iText->HasMarkupData();
   1.231 +	test(!hasMarkupData);
   1.232 +	TheContainer->iText->CancelInsertCharFormat();
   1.233 +	TheContainer->iText->InsertL(0,hdr1);
   1.234 +	TheContainer->iText->InsertL(5,hdr2);
   1.235 +	TheContainer->iText->InsertL(7,hdr3);
   1.236 +	TheContainer->iText->InsertL(0,CEditableText::EParagraphDelimiter);
   1.237 +	TheContainer->iText->CancelInsertCharFormat();
   1.238 +	TheContainer->iText->InsertL(2,CEditableText::EParagraphDelimiter);
   1.239 +	CleanupStack::Pop(3);
   1.240 +	hasMarkupData=TheContainer->iText->HasMarkupData();
   1.241 +	test(hasMarkupData);
   1.242 +	//
   1.243 +	// High level Store context
   1.244 +	TStreamId id=TheContainer->StoreL(*TheStore);
   1.245 +//
   1.246 +	delete TheContainer->iText;
   1.247 +	delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer;
   1.248 +	delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer;
   1.249 +//
   1.250 +//
   1.251 +//	Now restore the container with rich text
   1.252 +	TheContainer->RestoreL(*TheStore,id,factory);
   1.253 +	if (!aDeferPictureLoad)
   1.254 +		TheContainer->iText->LoadAllPicturesNowL();
   1.255 +	//
   1.256 +	hasMarkupData=TheContainer->iText->HasMarkupData();
   1.257 +	test(hasMarkupData);
   1.258 +	test(TheContainer->iText->ParagraphCount()==3);
   1.259 +	test(TheContainer->iText->DocumentLength()==21);
   1.260 +	TPtrC view;
   1.261 +	TCharFormat format;
   1.262 +	CPicture* picture;
   1.263 +	//
   1.264 +	// TEST THE PICTURE HEADERS, DEPENDING ON WHETHER DEFERRED LOADING IS SET OR NOT
   1.265 +	TPictureHeader hdrA=TheContainer->iText->PictureHeader(1);
   1.266 +	test(hdrA.iPictureType==KUidXzePictureType);
   1.267 +	if (aDeferPictureLoad)
   1.268 +		{
   1.269 +		test(hdrA.iPicture.IsId());
   1.270 +		}
   1.271 +	else
   1.272 +		{
   1.273 +		test(hdrA.iPicture!=NULL);
   1.274 +		test(hdrA.iPicture.IsPtr());
   1.275 +		test(((CXzePicture*)hdrA.iPicture.AsPtr())->iLabel=='x');
   1.276 +		}
   1.277 +	TPictureHeader hdrB=TheContainer->iText->PictureHeader(7);
   1.278 +	test(hdrB.iPictureType==KUidXzePictureType);
   1.279 +	if (aDeferPictureLoad)
   1.280 +		{
   1.281 +		test(hdrB.iPicture.IsId());
   1.282 +		}
   1.283 +	else
   1.284 +		{
   1.285 +		test(hdrB.iPicture!=NULL);
   1.286 +		test(hdrB.iPicture.IsPtr());
   1.287 +		test(((CXzePicture*)hdrB.iPicture.AsPtr())->iLabel=='z');
   1.288 +		}
   1.289 +	TPictureHeader hdrC=TheContainer->iText->PictureHeader(9);
   1.290 +	test(hdrC.iPictureType==KUidXzePictureType);
   1.291 +	if (aDeferPictureLoad)
   1.292 +		{
   1.293 +		test(hdrC.iPicture.IsId());
   1.294 +		}
   1.295 +	else
   1.296 +		{
   1.297 +		test(hdrC.iPicture!=NULL);
   1.298 +		test(hdrC.iPicture.IsPtr());
   1.299 +		test(((CXzePicture*)hdrC.iPicture.AsPtr())->iLabel=='e');
   1.300 +		}
   1.301 +	TPictureHeader hdrD=TheContainer->iText->PictureHeader(0);  // This is not a picture character
   1.302 +	test(hdrD.iPictureType==KNullUid);
   1.303 +	test(hdrD.iPicture==NULL);
   1.304 +	TSize dummySize;
   1.305 +	test(hdrD.iSize==dummySize);
   1.306 +	//
   1.307 +	TheContainer->iText->GetChars(view,format,1);
   1.308 +	test(view[0]==CEditableText::EPictureCharacter);
   1.309 +	picture=TheContainer->iText->PictureHandleL(1);
   1.310 +	test(((CXzePicture*)picture)->iLabel=='x');
   1.311 +	
   1.312 +	TheContainer->iText->GetChars(view,format,7);
   1.313 +	test(view[0]==CEditableText::EPictureCharacter);
   1.314 +	picture=TheContainer->iText->PictureHandleL(7);
   1.315 +	test(((CXzePicture*)picture)->iLabel=='z');
   1.316 +	
   1.317 +	TheContainer->iText->GetChars(view,format,9);
   1.318 +	test(view[0]==CEditableText::EPictureCharacter);
   1.319 +	picture=TheContainer->iText->PictureHandleL(9);
   1.320 +	test(((CXzePicture*)picture)->iLabel=='e');
   1.321 +
   1.322 +	delete factory;
   1.323 +	CleanupStack::PopAndDestroy();  // TheStore
   1.324 +	TheFs.Close();
   1.325 +    }
   1.326 +
   1.327 +
   1.328 +LOCAL_C void testPictureRestorer2(TBool aAlwaysFailToLoad=EFalse)
   1.329 +// Test Picture persistance.
   1.330 +//
   1.331 +    {
   1.332 +	//
   1.333 +	TheFs.Connect();
   1.334 +	//
   1.335 +	TheStore=CDirectFileStore::ReplaceL(TheFs,_L("c:\\etext\\t_word1.doc"),EFileRead|EFileWrite);
   1.336 +	TheDeferredPictureStore=TheStore;
   1.337 +	CleanupStack::PushL(TheStore);
   1.338 +	TheStore->SetTypeL(KDirectFileStoreLayout);
   1.339 +	//
   1.340 +	// Create concrete picture factory.
   1.341 +	MDemPictureFactory* factory=new(ELeave) MDemPictureFactory;
   1.342 +
   1.343 +	TheContainer->iText->Reset();
   1.344 +	TheContainer->iText->InsertL(0,_L("Hello Duncan how"));
   1.345 +
   1.346 +	TheContainer->iText->SetPictureFactory(factory,TheContainer);
   1.347 +	// Create some pictures.
   1.348 +	CXzeDoor* pic1=CXzeDoor::NewL('x',aAlwaysFailToLoad);
   1.349 +		CleanupStack::PushL(pic1);
   1.350 +	CXzeDoor* pic2=CXzeDoor::NewL('z',aAlwaysFailToLoad);
   1.351 +		CleanupStack::PushL(pic2);
   1.352 +	CXzePicture* pic3=CXzePicture::NewL('e');  // Control: will always load.
   1.353 +		CleanupStack::PushL(pic3);
   1.354 +	//
   1.355 +	// Create the picture headers
   1.356 +	TPictureHeader hdr1;
   1.357 +	TPictureHeader hdr2;
   1.358 +	TPictureHeader hdr3;
   1.359 +	//
   1.360 +	TSize size;
   1.361 +	pic1->GetSizeInTwips(size);
   1.362 +	hdr1.iPictureType=KUidXzeDoorType;
   1.363 +	hdr1.iPicture=pic1;
   1.364 +	hdr2.iPictureType=KUidXzeDoorType;
   1.365 +	hdr2.iPicture=pic2;
   1.366 +	hdr3.iPictureType=KUidXzePictureType;
   1.367 +	hdr3.iPicture=pic3;
   1.368 +	//
   1.369 +	// Insert the pictures into the rich text
   1.370 +	TBool hasMarkupData=TheContainer->iText->HasMarkupData();
   1.371 +	test(!hasMarkupData);
   1.372 +	TheContainer->iText->CancelInsertCharFormat();
   1.373 +	TheContainer->iText->InsertL(0,hdr1);
   1.374 +	TheContainer->iText->InsertL(5,hdr2);
   1.375 +	TheContainer->iText->InsertL(7,hdr3);
   1.376 +	TheContainer->iText->InsertL(0,CEditableText::EParagraphDelimiter);
   1.377 +	TheContainer->iText->CancelInsertCharFormat();
   1.378 +	TheContainer->iText->InsertL(2,CEditableText::EParagraphDelimiter);
   1.379 +	CleanupStack::Pop(3);  // pic1,2,3 - ownership transferred to rich text
   1.380 +	hasMarkupData=TheContainer->iText->HasMarkupData();
   1.381 +	test(hasMarkupData);
   1.382 +	//
   1.383 +	// High level Store context - all pictures currently in memory
   1.384 +	TStreamId id=TheContainer->StoreL(*TheStore);
   1.385 +//
   1.386 +	delete TheContainer->iText;
   1.387 +	delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer;
   1.388 +	delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer;
   1.389 +//
   1.390 +//
   1.391 +//	Now restore the container with rich text
   1.392 +	TheContainer->RestoreL(*TheStore,id,factory);
   1.393 +//
   1.394 +//
   1.395 +//  Now store the stuff again
   1.396 +	TInt error=TheContainer->iText->LoadAllPicturesNowL();
   1.397 +	if (error==KErrNotFound)
   1.398 +		INFO_PRINTF1(_L("   SIMULATION: Some picture data has been removed as no app could be found."));
   1.399 +//	if (aAlwaysFailToLoad)
   1.400 +//		test(error==KErrNotFound);
   1.401 +//	else
   1.402 +//		test(error==KErrNone);
   1.403 +	id=KNullStreamId;
   1.404 +	TRAP(error,
   1.405 +	id=TheContainer->StoreL(*TheStore));
   1.406 +	test(error==KErrNone);
   1.407 +//
   1.408 +// ...and restore it to check what we have got.
   1.409 +	delete TheContainer->iText;
   1.410 +	delete (CParaFormatLayer*)TheContainer->iGlobalParaFormatLayer;
   1.411 +	delete (CCharFormatLayer*)TheContainer->iGlobalCharFormatLayer;
   1.412 +    TheContainer->RestoreL(*TheStore,id,factory);
   1.413 +	TInt pictureCount=TheContainer->iText->PictureCount();
   1.414 +	if (aAlwaysFailToLoad)
   1.415 +		test(pictureCount==1);
   1.416 +	else
   1.417 +		test(pictureCount==3);
   1.418 +//
   1.419 +	delete factory;
   1.420 +	CleanupStack::PopAndDestroy();  // TheStore
   1.421 +	TheFs.Close();
   1.422 +    }*/
   1.423 +
   1.424 +
   1.425 +LOCAL_C void CompareRichTextL(CRichText *aDoc1,CRichText *aDoc2)
   1.426 +//
   1.427 +	{
   1.428 +	INFO_PRINTF1(_L("Comparing Documents"));
   1.429 +	TInt length;
   1.430 +	TInt num1,num2;
   1.431 + 	TInt ii=0,len1,len2,pos1,pos2,oldPos;
   1.432 +
   1.433 +	INFO_PRINTF1(_L("Document Length"));
   1.434 +	length=aDoc1->LdDocumentLength();
   1.435 +	num2=aDoc2->LdDocumentLength();
   1.436 +	test(length==num2);
   1.437 +
   1.438 +	INFO_PRINTF1(_L("Paragraph Count"));
   1.439 +	num1=aDoc1->ParagraphCount();
   1.440 +	num2=aDoc2->ParagraphCount();
   1.441 +	test(num1==num2);
   1.442 +
   1.443 +	INFO_PRINTF1(_L("Paragraph Lengths"));
   1.444 +	pos1=-1;
   1.445 +	oldPos=-2;
   1.446 +	while (pos1>oldPos)
   1.447 +		{
   1.448 +		oldPos=pos1;
   1.449 +		pos1=aDoc1->CharPosOfParagraph(len1,ii);
   1.450 +		pos2=aDoc2->CharPosOfParagraph(len2,ii);
   1.451 +		test(len1==len2);
   1.452 +		test(pos1==pos2);
   1.453 +		ii++;
   1.454 +		}
   1.455 + 
   1.456 +	INFO_PRINTF1(_L("Word Count"));
   1.457 +	num1=aDoc1->WordCount();
   1.458 +	num2=aDoc2->WordCount();
   1.459 +	test(num1==num2);
   1.460 +
   1.461 +	INFO_PRINTF1(_L("Characters"));
   1.462 +	TCharFormat format1,format2;
   1.463 +	TPtrC chars1,chars2;
   1.464 +	len1=1;
   1.465 +	ii=0;
   1.466 +	while (ii<=length)
   1.467 +		{
   1.468 +		aDoc1->GetChars(chars1,format1,ii);
   1.469 +		aDoc2->GetChars(chars2,format2,ii);
   1.470 +		len1=Min(chars1.Length(),chars2.Length());
   1.471 +		test(chars1.Left(len1)==chars2.Left(len1));
   1.472 +		test(format1.IsEqual(format2));
   1.473 +		test(format2.IsEqual(format1));
   1.474 +		ii+=len1;
   1.475 +		}
   1.476 +	
   1.477 +	
   1.478 +	}
   1.479 +
   1.480 +
   1.481 +LOCAL_C  void GoL()
   1.482 +// Run the tests
   1.483 +//
   1.484 +	{
   1.485 +	CParaFormatLayer* pLayer=CParaFormatLayer::NewL();
   1.486 +	CCharFormatLayer* cLayer=CCharFormatLayer::NewL();
   1.487 +	CRichText *document=CRichText::NewL(pLayer,cLayer);
   1.488 +	TInt err;
   1.489 +	
   1.490 +	INFO_PRINTF1(_L("Document with single Paragraph"));
   1.491 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TRAN-0001 "));
   1.492 +	{	
   1.493 +	TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para.pml"));
   1.494 +	INFO_PRINTF1(_L("Exporting a file by Para"));
   1.495 +	TFileName exportFile=KExportFileName1();
   1.496 +	EnsureFileExists(exportFile);
   1.497 +	TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByParagraph,0));
   1.498 +	test(err==KErrNone);
   1.499 +	INFO_PRINTF1(_L("Importing a file by Para"));
   1.500 +	document->Reset();
   1.501 +	TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByParagraph);
   1.502 +	test(charsImported>0);
   1.503 +	INFO_PRINTF1(_L("Comparing Result"));
   1.504 +	TRAP(err,CompareRichTextL(TheContainer->iText,document));
   1.505 + 	test(err==KErrNone);
   1.506 +	delete TheContainer;
   1.507 +	}
   1.508 +	
   1.509 +	{
   1.510 +	TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para.pml"));
   1.511 +	INFO_PRINTF1(_L("Exporting and Importing a file by Line"));
   1.512 +	INFO_PRINTF1(_L("Line Lengths 25,30,...,95"));
   1.513 +	TFileName exportFile=KExportFileName1();
   1.514 +	TInt ii;
   1.515 +	for(ii=25;ii<100;ii+=5)
   1.516 +		{
   1.517 +		INFO_PRINTF1(_L("With next line length"));
   1.518 +		EnsureFileExists(exportFile);
   1.519 +		TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByLine,ii));
   1.520 +		test(err==KErrNone);
   1.521 +		document->Reset();
   1.522 +		TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByLine);
   1.523 +		test(charsImported>0);
   1.524 +		TRAP(err,CompareRichTextL(TheContainer->iText,document));
   1.525 + 		test(err==KErrNone);
   1.526 +		}
   1.527 +	delete TheContainer;
   1.528 +	
   1.529 +	}
   1.530 +
   1.531 +	
   1.532 +	INFO_PRINTF1(_L("Document with two Paragraphs"));
   1.533 +	
   1.534 +	{	
   1.535 +	TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para2.pml"));
   1.536 +	INFO_PRINTF1(_L("Exporting a file by Para"));
   1.537 +	TFileName exportFile=KExportFileName2();
   1.538 +	EnsureFileExists(exportFile);
   1.539 +	TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByParagraph,0));
   1.540 +	test(err==KErrNone);
   1.541 +	INFO_PRINTF1(_L("Importing a file by Para"));
   1.542 +	document->Reset();
   1.543 +	TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByParagraph);
   1.544 +	test(charsImported>0);
   1.545 +	INFO_PRINTF1(_L("Comparing Result"));
   1.546 +	TRAP(err,CompareRichTextL(TheContainer->iText,document));
   1.547 + 	test(err==KErrNone);
   1.548 +	delete TheContainer;
   1.549 +	}
   1.550 +	
   1.551 +	{
   1.552 +	TheContainer=CContainer::NewL(_L("z:\\test\\app-framework\\etext\\t_para.pml"));
   1.553 +	INFO_PRINTF1(_L("Exporting and Importing a file by Line"));
   1.554 +	INFO_PRINTF1(_L("Line Lengths 30,40,...,100"));
   1.555 +	TFileName exportFile=KExportFileName1();
   1.556 +	TInt ii;
   1.557 +	for(ii=30;ii<105;ii+=10)
   1.558 +		{
   1.559 +		INFO_PRINTF1(_L("With next line length"));
   1.560 +		EnsureFileExists(exportFile);
   1.561 +		TRAP(err,TheContainer->iText->ExportAsTextL(exportFile,CPlainText::EOrganiseByLine,ii));
   1.562 +		test(err==KErrNone);
   1.563 +		document->Reset();
   1.564 +		TInt charsImported=document->ImportTextFileL(0,exportFile,CPlainText::EOrganiseByLine);
   1.565 +		test(charsImported>0);
   1.566 +		TRAP(err,CompareRichTextL(TheContainer->iText,document));
   1.567 + 		test(err==KErrNone);
   1.568 +		}
   1.569 +	delete TheContainer;
   1.570 +	
   1.571 +	}
   1.572 +
   1.573 +	delete document;
   1.574 +	delete cLayer;
   1.575 +	delete pLayer;
   1.576 +
   1.577 +	
   1.578 +	}
   1.579 +
   1.580 +
   1.581 +LOCAL_C void setupCleanup()
   1.582 +//
   1.583 +// Initialise the cleanup stack.
   1.584 +//
   1.585 +    {
   1.586 +
   1.587 +	TheTrapCleanup=CTrapCleanup::New();
   1.588 +	TRAPD(r,\
   1.589 +		{\
   1.590 +		for (TInt i=KTestCleanupStack;i>0;i--)\
   1.591 +			CleanupStack::PushL((TAny*)1);\
   1.592 +		test(r==KErrNone);\
   1.593 +		CleanupStack::Pop(KTestCleanupStack);\
   1.594 +		});
   1.595 +	}
   1.596 +
   1.597 +
   1.598 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   1.599 +	{
   1.600 +	RFs fsSession;
   1.601 +	TInt err = fsSession.Connect();
   1.602 +	if(err == KErrNone)
   1.603 +		{
   1.604 +		TEntry entry;
   1.605 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
   1.606 +			{
   1.607 +			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   1.608 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   1.609 +			if(err != KErrNone) 
   1.610 +				{
   1.611 +				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   1.612 +				}
   1.613 +			err = fsSession.Delete(aFullName);
   1.614 +			if(err != KErrNone) 
   1.615 +				{
   1.616 +				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   1.617 +				}
   1.618 +			}
   1.619 +		fsSession.Close();
   1.620 +		}
   1.621 +	else
   1.622 +		{
   1.623 +		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   1.624 +		}
   1.625 +	}
   1.626 +}
   1.627 +
   1.628 +CT_TRAN::CT_TRAN()
   1.629 +    {
   1.630 +    SetTestStepName(KTestStep_T_TRAN);
   1.631 +    pTestStep = this;
   1.632 +    }
   1.633 +
   1.634 +TVerdict CT_TRAN::doTestStepL()
   1.635 +    {
   1.636 +    SetTestStepResult(EFail);
   1.637 +
   1.638 +    INFO_PRINTF1(_L("Testing Picture Restorer mechanism"));
   1.639 +    
   1.640 +    __UHEAP_MARK;
   1.641 +    T_TRAN::setupCleanup();
   1.642 +    TRAPD(r, T_TRAN::GoL());
   1.643 +
   1.644 +    delete T_TRAN::TheTrapCleanup;
   1.645 +    
   1.646 +    __UHEAP_MARKEND;
   1.647 +    
   1.648 +    T_TRAN::DeleteDataFile(T_TRAN::KExportFileName1);     //deletion of data files must be before call to End() - DEF047652
   1.649 +    T_TRAN::DeleteDataFile(T_TRAN::KExportFileName2); 
   1.650 +    
   1.651 +    if (r == KErrNone)
   1.652 +        {
   1.653 +        SetTestStepResult(EPass);
   1.654 +        }
   1.655 +
   1.656 +    return TestStepResult();
   1.657 +    }