textrendering/texthandling/ttext/T_CONVRT.CPP
changeset 51 a7c938434754
parent 0 1fb32624e06b
child 55 336bee5c2d35
equal deleted inserted replaced
44:601ab138ba0b 51:a7c938434754
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20 #include <txtfmlyr.h>
    20 #include <txtfmlyr.h>
    21 #include <s32mem.h>
    21 #include <s32mem.h>
    22 #include <s32file.h>
    22 #include <s32file.h>
    23 #include <flddef.h>
    23 #include <flddef.h>
    24 #include <fldbltin.h>
    24 #include <fldbltin.h>
    25 #include <e32test.h>
       
    26 #include "../incp/T_PMLPAR.H"
    25 #include "../incp/T_PMLPAR.H"
       
    26 #include "T_CONVRT.h"
       
    27 
       
    28 #define test(cond)											\
       
    29 	{														\
       
    30 	TBool __bb = (cond);									\
       
    31 	TEST(__bb);												\
       
    32 	if (!__bb)												\
       
    33 		{													\
       
    34 		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
       
    35 		User::Leave(1);										\
       
    36 		}													\
       
    37 	}
    27 
    38 
    28 #define UNUSED_VAR(a) a = a
    39 #define UNUSED_VAR(a) a = a
    29 
    40 
    30 const TInt KTestCleanupStack=0x20;
    41 const TInt KTestCleanupStack=0x20;
    31 
    42 
    32 LOCAL_D CTrapCleanup* TheTrapCleanup;
    43 LOCAL_D CTrapCleanup* TheTrapCleanup;
    33 LOCAL_D RTest test(_L("T_CONVRT - Rich Text Persistence"));
       
    34 //
    44 //
    35 LOCAL_D CRichText* TheText=NULL;
    45 LOCAL_D CRichText* TheText=NULL;
    36 LOCAL_D CParaFormatLayer* TheGlobalParaLayer=NULL;
    46 LOCAL_D CParaFormatLayer* TheGlobalParaLayer=NULL;
    37 LOCAL_D CCharFormatLayer* TheGlobalCharLayer=NULL;
    47 LOCAL_D CCharFormatLayer* TheGlobalCharLayer=NULL;
    38 
    48 
    39 
    49 
    40 ////////////////////////////////////////////////////////////////////////////////////////////
    50 ////////////////////////////////////////////////////////////////////////////////////////////
    41 class TTestFieldFactory : public MTextFieldFactory
    51 class TTestFieldFactoryCONVRT : public MTextFieldFactory
    42 	{
    52 	{
    43 public:
    53 public:
    44 	// from MTextFieldFactory
    54 	// from MTextFieldFactory
    45 	virtual CTextField* NewFieldL(TUid aFieldType); 
    55 	virtual CTextField* NewFieldL(TUid aFieldType); 
    46 	// Creates a field of the type specified
    56 	// Creates a field of the type specified
    47 	// Returns NULL if it does not recognise/support the field type
    57 	// Returns NULL if it does not recognise/support the field type
    48 	};
    58 	};
    49 
    59 
    50 CTextField* TTestFieldFactory::NewFieldL(TUid aFieldType)
    60 CTextField* TTestFieldFactoryCONVRT::NewFieldL(TUid aFieldType)
    51 // Creates a field (in aHeader) of the type specified in aHeader
    61 // Creates a field (in aHeader) of the type specified in aHeader
    52 // 
    62 // 
    53 	{
    63 	{
    54 	CTextField* field=NULL;
    64 	CTextField* field=NULL;
    55 	if (aFieldType==KDateTimeFieldUid)
    65 	if (aFieldType==KDateTimeFieldUid)
    58 	}
    68 	}
    59 /////////////////////////////////////////////////////////////////////////////////////////////
    69 /////////////////////////////////////////////////////////////////////////////////////////////
    60 
    70 
    61 _LIT(KOutputFile, "c:\\etext\\t_convrt.tst");
    71 _LIT(KOutputFile, "c:\\etext\\t_convrt.tst");
    62 template <class T>
    72 template <class T>
    63 void testStoreRestoreL(T& aCopy,const T& aOriginal)
    73 void CT_CONVRT::testStoreRestoreL(T& aCopy,const T& aOriginal)
    64 // Test document persistance.
    74 // Test document persistance.
    65 //
    75 //
    66     {
    76     {
    67 	// set up the store
    77 	// set up the store
    68 	RFs	theFs;
    78 	RFs	theFs;
    87 	CleanupStack::PopAndDestroy();  // theStore
    97 	CleanupStack::PopAndDestroy();  // theStore
    88 	theFs.Close();
    98 	theFs.Close();
    89     }
    99     }
    90 
   100 
    91 
   101 
    92 LOCAL_C TInt IsEqual(const CEditableText* aCopy,const CEditableText* aOriginal)
   102 TInt CT_CONVRT::IsEqual(const CEditableText* aCopy,const CEditableText* aOriginal)
    93 //
   103 //
    94 // Returns true if aCopy contents matches aOriginal contents.
   104 // Returns true if aCopy contents matches aOriginal contents.
    95 // Takes account of multiple segments of a segmented text component.
   105 // Takes account of multiple segments of a segmented text component.
    96 //
   106 //
    97 	{
   107 	{
   113 	test(lengthRead==lengthOfOriginal+1);
   123 	test(lengthRead==lengthOfOriginal+1);
   114 	return 1;
   124 	return 1;
   115 	}
   125 	}
   116 
   126 
   117 
   127 
   118 LOCAL_C void DoTestRichTextL()
   128 void CT_CONVRT::DoTestRichTextL()
   119 //
   129 //
   120 // Test streaming CRichText.
   130 // Test streaming CRichText.
   121 //
   131 //
   122 	{// Create the global text components.
   132 	{// Create the global text components.
   123 	const TInt KSmallestTextBuffer=1;
   133 	const TInt KSmallestTextBuffer=1;
   141 	gText=CGlobalText::NewL(paraLayer,charLayer,CEditableText::ESegmentedStorage,KSmallestTextBuffer));
   151 	gText=CGlobalText::NewL(paraLayer,charLayer,CEditableText::ESegmentedStorage,KSmallestTextBuffer));
   142 	newsize=User::Available(biggest);
   152 	newsize=User::Available(biggest);
   143 	TInt globalPrint=size-newsize;
   153 	TInt globalPrint=size-newsize;
   144 	TBuf<50> buf;
   154 	TBuf<50> buf;
   145 	buf.Format(_L("Empty rich text takes: %d bytes\n"),footprint);
   155 	buf.Format(_L("Empty rich text takes: %d bytes\n"),footprint);
   146 	test.Printf(buf);
   156 	INFO_PRINTF1(buf);
   147 	buf.Format(_L("Empty global text takes: %d bytes\n"),globalPrint);
   157 	buf.Format(_L("Empty global text takes: %d bytes\n"),globalPrint);
   148 	test.Printf(buf);
   158 	INFO_PRINTF1(buf);
   149 //	test.Getch();
   159 //	test.Getch();
   150 	delete gText;
   160 	delete gText;
   151 	//
   161 	//
   152 	// Now add a text field to this.
   162 	// Now add a text field to this.
   153 	TTestFieldFactory factory;
   163 	TTestFieldFactoryCONVRT factory;
   154 	TheText->SetFieldFactory(&factory);
   164 	TheText->SetFieldFactory(&factory);
   155 	theCopy->SetFieldFactory(&factory);
   165 	theCopy->SetFieldFactory(&factory);
   156 	CTextField* field=NULL;
   166 	CTextField* field=NULL;
   157 	TRAP(ret,
   167 	TRAP(ret,
   158 	field=factory.NewFieldL(KDateTimeFieldUid));
   168 	field=factory.NewFieldL(KDateTimeFieldUid));
   173 	delete paraLayer;
   183 	delete paraLayer;
   174 	delete charLayer;
   184 	delete charLayer;
   175 	}
   185 	}
   176 
   186 
   177 
   187 
   178 LOCAL_C void LoadIntoText(TFileName& aFileName)
   188 void CT_CONVRT::LoadIntoText(TFileName& aFileName)
   179 //
   189 //
   180 	{
   190 	{
   181 	CParser* myParser=NULL;
   191 	CParser* myParser=NULL;
   182 	TRAPD(ret,
   192 	TRAPD(ret,
   183 	myParser=CParser::NewL());
   193 	myParser=CParser::NewL());
   189 	TheGlobalCharLayer=(CCharFormatLayer*)TheText->GlobalCharFormatLayer();
   199 	TheGlobalCharLayer=(CCharFormatLayer*)TheText->GlobalCharFormatLayer();
   190 	delete myParser;
   200 	delete myParser;
   191 	}
   201 	}
   192 
   202 
   193 
   203 
   194 LOCAL_C void KillText()
   204 void CT_CONVRT::KillText()
   195 //
   205 //
   196 	{
   206 	{
   197 	delete TheText;
   207 	delete TheText;
   198 	}
   208 	}
   199 
   209 
   200 
   210 
   201 LOCAL_C void KillLayers()
   211 void CT_CONVRT::KillLayers()
   202 	{
   212 	{
   203 	delete TheGlobalParaLayer;
   213 	delete TheGlobalParaLayer;
   204 	delete TheGlobalCharLayer;
   214 	delete TheGlobalCharLayer;
   205 	}
   215 	}
   206 
   216 
   207 
   217 
   208 LOCAL_C void Reset()
   218 void CT_CONVRT::Reset()
   209 //
   219 //
   210 	{
   220 	{
   211 	KillText();
   221 	KillText();
   212 	KillLayers();
   222 	KillLayers();
   213 	}
   223 	}
   214 
   224 
   215 
   225 
   216 LOCAL_C void GoL()
   226 void CT_CONVRT::GoL()
   217 //
   227 //
   218 	{
   228 	{
   219 	test.Start(_L("Rich Text of Shared Para Formats Only"));
   229 	INFO_PRINTF1(_L("Rich Text of Shared Para Formats Only"));
   220 	TFileName fileName=_L("z:\\test\\app-framework\\etext\\shared.pml");
   230 	TFileName fileName=_L("z:\\test\\app-framework\\etext\\shared.pml");
   221 	LoadIntoText(fileName);
   231 	LoadIntoText(fileName);
   222 	TBool hasMarkupData=TheText->HasMarkupData();
   232 	TBool hasMarkupData=TheText->HasMarkupData();
   223 	test(hasMarkupData);
   233 	test(hasMarkupData);
   224 	DoTestRichTextL();
   234 	DoTestRichTextL();
   225 	Reset();
   235 	Reset();
   226 	//
   236 	//
   227 	test.Next(_L("Rich Text with specific character formatting"));
   237 	INFO_PRINTF1(_L("Rich Text with specific character formatting"));
   228 	fileName=_L("z:\\test\\app-framework\\etext\\test1.pml");
   238 	fileName=_L("z:\\test\\app-framework\\etext\\test1.pml");
   229 	LoadIntoText(fileName);
   239 	LoadIntoText(fileName);
   230 	hasMarkupData=TheText->HasMarkupData();
   240 	hasMarkupData=TheText->HasMarkupData();
   231 	test(hasMarkupData);
   241 	test(hasMarkupData);
   232 	DoTestRichTextL();
   242 	DoTestRichTextL();
   233 	Reset();
   243 	Reset();
   234 	//
   244 	}
   235 	test.End();
   245 
   236 	}
   246 
   237 
   247 void CT_CONVRT::setupCleanup()
   238 
       
   239 LOCAL_C void setupCleanup()
       
   240 //
   248 //
   241 // Initialise the cleanup stack.
   249 // Initialise the cleanup stack.
   242 //
   250 //
   243     {
   251     {
   244 
   252 
   251 		CleanupStack::Pop(KTestCleanupStack);\
   259 		CleanupStack::Pop(KTestCleanupStack);\
   252 		});
   260 		});
   253 	}
   261 	}
   254 
   262 
   255 
   263 
   256 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   264 void CT_CONVRT::DeleteDataFile(const TDesC& aFullName)
   257 	{
   265 	{
   258 	RFs fsSession;
   266 	RFs fsSession;
   259 	TInt err = fsSession.Connect();
   267 	TInt err = fsSession.Connect();
   260 	if(err == KErrNone)
   268 	if(err == KErrNone)
   261 		{
   269 		{
   280 		{
   288 		{
   281 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   289 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   282 		}
   290 		}
   283 	}
   291 	}
   284 
   292 
   285 GLDEF_C TInt E32Main()
   293 CT_CONVRT::CT_CONVRT()
   286 //
       
   287 // Test streaming conversions.
       
   288 //
       
   289     {
   294     {
   290 	setupCleanup();
   295     SetTestStepName(KTestStep_T_CONVRT);
   291 	test.Title();
       
   292 	test.Start(_L("Persisting Rich Text")); 
       
   293 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-T_CONVRT-0001 "));
       
   294  	__UHEAP_MARK;
       
   295 	TRAPD(ret, GoL());
       
   296 	__UHEAP_MARKEND;
       
   297     test(ret == KErrNone);
       
   298 
       
   299 	//deletion of data files must be before call to End() - DEF047652	
       
   300 	::DeleteDataFile(KOutputFile);
       
   301 	test.End();
       
   302 	test.Close();
       
   303 
       
   304 	delete TheTrapCleanup;
       
   305 	return 0;
       
   306     }
   296     }
   307 
   297 
       
   298 TVerdict CT_CONVRT::doTestStepL()
       
   299     {
       
   300     SetTestStepResult(EFail);
       
   301 
       
   302     setupCleanup();
       
   303     __UHEAP_MARK;
       
   304 
       
   305     INFO_PRINTF1(_L("T_CONVRT - Rich Text Persistence"));
       
   306     INFO_PRINTF1(_L("Persisting Rich Text"));
       
   307     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-T_CONVRT-0001 "));
       
   308     TRAPD(error1, GoL());
       
   309 
       
   310     __UHEAP_MARKEND;
       
   311     delete TheTrapCleanup;
       
   312 
       
   313     if(error1 == KErrNone)
       
   314         {
       
   315         SetTestStepResult(EPass);
       
   316         }
       
   317 
       
   318     return TestStepResult();
       
   319     }