textrendering/texthandling/ttext/TTIMES1.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".
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <e32test.h>
       
    20 #include <e32svr.h>
    19 #include <e32svr.h>
    21 
    20 
    22 #include <s32mem.h>
    21 #include <s32mem.h>
    23 
    22 
    24 #include <txtrich.h>
    23 #include <txtrich.h>
    25 #include <txtglobl.h>
    24 #include <txtglobl.h>
    26 
    25 
    27 #include "../incp/T_PMLPAR.H"
    26 #include "../incp/T_PMLPAR.H"
       
    27 #include "TTIMES1.h"
       
    28 
       
    29 #define test(cond)											\
       
    30 	{														\
       
    31 	TBool __bb = (cond);									\
       
    32 	TEST(__bb);												\
       
    33 	if (!__bb)												\
       
    34 		{													\
       
    35 		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
       
    36 		User::Leave(1);										\
       
    37 		}													\
       
    38 	}
    28 
    39 
    29 #define UNUSED_VAR(a) a = a
    40 #define UNUSED_VAR(a) a = a
    30 
    41 
    31 LOCAL_D CTrapCleanup* TheTrapCleanup;
    42 LOCAL_D CTrapCleanup* TheTrapCleanup;
    32 LOCAL_D RTest test(_L("CRichText Document"));
       
    33 LOCAL_D CParaFormatLayer* TheGlobalParaFormatLayer;
    43 LOCAL_D CParaFormatLayer* TheGlobalParaFormatLayer;
    34 LOCAL_D CCharFormatLayer* TheGlobalCharFormatLayer;
    44 LOCAL_D CCharFormatLayer* TheGlobalCharFormatLayer;
    35 LOCAL_D CParser* TheParser;
    45 LOCAL_D CParser* TheParser;
    36 
    46 
    37 LOCAL_D const TInt KTestCleanupStack=0x200;
    47 LOCAL_D const TInt KTestCleanupStack=0x200;
    38 LOCAL_D const TInt KCreateRichTextCount=1000;
    48 LOCAL_D const TInt KCreateRichTextCount=1000;
    39 
    49 
    40 LOCAL_D CRichText* TheText[KCreateRichTextCount];
    50 LOCAL_D CRichText* TheText[KCreateRichTextCount];
    41 
    51 
    42 LOCAL_C void GenerateGlobalLayersL()
    52 void CT_TTIMES1::GenerateGlobalLayersL()
    43 // Provides the base layers for globl text and below
    53 // Provides the base layers for globl text and below
    44 //
    54 //
    45 	{
    55 	{
    46 	TParaFormatMask paraMask;
    56 	TParaFormatMask paraMask;
    47 	TheGlobalParaFormatLayer=CParaFormatLayer::NewL((CParaFormat*)NULL,paraMask);
    57 	TheGlobalParaFormatLayer=CParaFormatLayer::NewL((CParaFormat*)NULL,paraMask);
    49 	TCharFormatMask charMask;
    59 	TCharFormatMask charMask;
    50 	TheGlobalCharFormatLayer=CCharFormatLayer::NewL(charFormat,charMask);
    60 	TheGlobalCharFormatLayer=CCharFormatLayer::NewL(charFormat,charMask);
    51 	}
    61 	}
    52 
    62 
    53 
    63 
    54 LOCAL_C void KillGlobalLayers()
    64 void CT_TTIMES1::KillGlobalLayers()
    55 // Destroy the base layers for global text and below
    65 // Destroy the base layers for global text and below
    56 //
    66 //
    57 	{
    67 	{
    58 	delete TheGlobalParaFormatLayer;
    68 	delete TheGlobalParaFormatLayer;
    59 	delete TheGlobalCharFormatLayer;
    69 	delete TheGlobalCharFormatLayer;
    60 	TheGlobalParaFormatLayer=NULL;
    70 	TheGlobalParaFormatLayer=NULL;
    61 	TheGlobalCharFormatLayer=NULL;
    71 	TheGlobalCharFormatLayer=NULL;
    62 	}
    72 	}
    63 
    73 
    64 LOCAL_C void KillText()
    74 void CT_TTIMES1::KillText()
    65 	{
    75 	{
    66 	for (TInt ii=0; ii<KCreateRichTextCount;ii++)
    76 	for (TInt ii=0; ii<KCreateRichTextCount;ii++)
    67 		{
    77 		{
    68 		delete TheText[ii];
    78 		delete TheText[ii];
    69 		TheText[ii]=NULL;
    79 		TheText[ii]=NULL;
    74 struct TNow : public TTime 
    84 struct TNow : public TTime 
    75 	{
    85 	{
    76 	TNow() { HomeTime(); }
    86 	TNow() { HomeTime(); }
    77 	};
    87 	};
    78 
    88 
    79 LOCAL_C void CreationTestsL()
    89 void CT_TTIMES1::CreationTestsL()
    80 //
    90 //
    81 	{
    91 	{
    82 	GenerateGlobalLayersL();
    92 	GenerateGlobalLayersL();
    83 
    93 
    84 	TNow start;
    94 	TNow start;
    92 	test(ii==KCreateRichTextCount);
   102 	test(ii==KCreateRichTextCount);
    93 	//
   103 	//
    94 	// Display the metric
   104 	// Display the metric
    95 	TBuf<60> context;
   105 	TBuf<60> context;
    96 	context.Format(_L("        Create rich text %d times: %d\n"),KCreateRichTextCount,finish.MicroSecondsFrom(start).Int64());
   106 	context.Format(_L("        Create rich text %d times: %d\n"),KCreateRichTextCount,finish.MicroSecondsFrom(start).Int64());
    97 	test.Printf(context);
   107 	INFO_PRINTF1(context);
    98 	//
   108 	//
    99 	// Tidy up
   109 	// Tidy up
   100 	KillText();
   110 	KillText();
   101 	KillGlobalLayers();
   111 	KillGlobalLayers();
   102 	}
   112 	}
   103 
   113 
   104 
   114 
   105 LOCAL_C CRichText* LoadIntoTextL(TFileName& aFileName)
   115 CRichText* CT_TTIMES1::LoadIntoTextL(TFileName& aFileName)
   106 //
   116 //
   107 	{
   117 	{
   108 	TRAPD(ret,
   118 	TRAPD(ret,
   109 	TheParser=CParser::NewL());
   119 	TheParser=CParser::NewL());
   110 	CRichText* text=NULL;
   120 	CRichText* text=NULL;
   116 	TheParser=NULL;
   126 	TheParser=NULL;
   117 	return text;
   127 	return text;
   118 	}
   128 	}
   119 
   129 
   120 
   130 
   121 LOCAL_C void GetAppendTestTimeL(const CRichText* aSource,TInt aTestLoopCount)
   131 void CT_TTIMES1::GetAppendTestTimeL(const CRichText* aSource,TInt aTestLoopCount)
   122 	{
   132 	{
   123 	CRichText* target=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);
   133 	CRichText* target=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);
   124 	test(target->DocumentLength()==0);
   134 	test(target->DocumentLength()==0);
   125 	test(!target->HasMarkupData());
   135 	test(!target->HasMarkupData());
   126 
   136 
   136 	//
   146 	//
   137 	// Calculate and display result
   147 	// Calculate and display result
   138 	test(ii==aTestLoopCount);
   148 	test(ii==aTestLoopCount);
   139 	TBuf<60> context;
   149 	TBuf<60> context;
   140 	context.Format(_L("        Append %d rich text's: %d\n"),aTestLoopCount,finish.MicroSecondsFrom(start).Int64());
   150 	context.Format(_L("        Append %d rich text's: %d\n"),aTestLoopCount,finish.MicroSecondsFrom(start).Int64());
   141 	test.Printf(context);
   151 	INFO_PRINTF1(context);
   142 	delete target;
   152 	delete target;
   143 	}
   153 	}
   144 
   154 
   145 
   155 
   146 LOCAL_C void GetBenchmarkAppendTestTimeL(const CRichText* aSource,TInt aTestLoopCount)
   156 void CT_TTIMES1::GetBenchmarkAppendTestTimeL(const CRichText* aSource,TInt aTestLoopCount)
   147 	{
   157 	{
   148 	CRichText** target=new CRichText*[aTestLoopCount];
   158 	CRichText** target=new CRichText*[aTestLoopCount];
   149 	CBufStore** store=new CBufStore*[aTestLoopCount];	
   159 	CBufStore** store=new CBufStore*[aTestLoopCount];	
   150 	TInt ii = 0;
   160 	TInt ii = 0;
   151 	for (ii=0;ii<aTestLoopCount;ii++)
   161 	for (ii=0;ii<aTestLoopCount;ii++)
   173 	//
   183 	//
   174 	// Calculate and display result
   184 	// Calculate and display result
   175 	test(ii==aTestLoopCount);
   185 	test(ii==aTestLoopCount);
   176 	TBuf<70> context2;
   186 	TBuf<70> context2;
   177 	context2.Format(_L("        Benchmark              : %d\n"),finish.MicroSecondsFrom(start).Int64());
   187 	context2.Format(_L("        Benchmark              : %d\n"),finish.MicroSecondsFrom(start).Int64());
   178 	test.Printf(context2);
   188 	INFO_PRINTF1(context2);
   179 	}
   189 	}
   180 
   190 
   181 
   191 
   182 LOCAL_C void AppendTest1L()
   192 void CT_TTIMES1::AppendTest1L()
   183 //
   193 //
   184 	{
   194 	{
   185 	TInt testLoopCount=900;
   195 	TInt testLoopCount=900;
   186 	CRichText* source=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);
   196 	CRichText* source=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);
   187 	source->InsertL(source->DocumentLength(),_L("A bit of text that pretends to be an entry's title"));
   197 	source->InsertL(source->DocumentLength(),_L("A bit of text that pretends to be an entry's title"));
   194 	// tidy up
   204 	// tidy up
   195 	delete source;
   205 	delete source;
   196 	}
   206 	}
   197 
   207 
   198 
   208 
   199 LOCAL_C void AppendTest2L()
   209 void CT_TTIMES1::AppendTest2L()
   200 //
   210 //
   201 	{
   211 	{
   202 	KillGlobalLayers();  // they are replaced by the ones read in from the PML file.
   212 	KillGlobalLayers();  // they are replaced by the ones read in from the PML file.
   203 	TInt testLoopCount=266;
   213 	TInt testLoopCount=266;
   204 	TFileName file=_L("z:\\test\\app-framework\\etext\\ttimes1.pml");
   214 	TFileName file=_L("z:\\test\\app-framework\\etext\\ttimes1.pml");
   212 	// tidy up
   222 	// tidy up
   213 	delete source;
   223 	delete source;
   214 	}
   224 	}
   215 
   225 
   216 
   226 
   217 LOCAL_C void AppendTestsL()
   227 void CT_TTIMES1::AppendTestsL()
   218 //
   228 //
   219 	{
   229 	{
   220 	GenerateGlobalLayersL();
   230 	GenerateGlobalLayersL();
   221 	//
   231 	//
   222 	test.Start(_L("Plain Text Component Only"));
   232 	INFO_PRINTF1(_L("Plain Text Component Only"));
   223 	TRAPD(ret,
   233 	TRAPD(ret,
   224 	AppendTest1L());
   234 	AppendTest1L());
   225 	test(ret==KErrNone);
   235 	test(ret==KErrNone);
   226 	//
   236 	//
   227 	test.Next(_L("Plain Text with limited Markup - no pictures"));
   237 	INFO_PRINTF1(_L("Plain Text with limited Markup - no pictures"));
   228 	TRAP(ret,
   238 	TRAP(ret,
   229 	AppendTest2L());
   239 	AppendTest2L());
   230 	test(ret==KErrNone);
   240 	test(ret==KErrNone);
   231 	//
   241 	//
   232 	KillGlobalLayers();
   242 	KillGlobalLayers();
   233 	test.End();
       
   234 	}
   243 	}
   235 	
   244 	
   236 	
   245 	
   237 LOCAL_C void DoTestsL()
   246 void CT_TTIMES1::DoTestsL()
   238 //
   247 //
   239 	{
   248 	{
   240 	test.Start(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TTIMES1-0001 Creation Tests "));
   249 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TTIMES1-0001 Creation Tests "));
   241 	CreationTestsL();
   250 	CreationTestsL();
   242 	test.Next(_L("Appending Tests"));
   251 	INFO_PRINTF1(_L("Appending Tests"));
   243 	AppendTestsL();
   252 	AppendTestsL();
   244 	//
   253 	//
   245 	}
   254 	}
   246 
   255 
   247 
   256 
   248 LOCAL_C void setupCleanup()
   257 void CT_TTIMES1::setupCleanup()
   249 //
   258 //
   250 // Initialise the cleanup stack.
   259 // Initialise the cleanup stack.
   251 //
   260 //
   252     {
   261     {
   253 
   262 
   259 		test(r==KErrNone);\
   268 		test(r==KErrNone);\
   260 		CleanupStack::Pop(KTestCleanupStack);\
   269 		CleanupStack::Pop(KTestCleanupStack);\
   261 		});
   270 		});
   262 	}
   271 	}
   263 
   272 
   264 
   273 CT_TTIMES1::CT_TTIMES1()
   265 
       
   266 GLDEF_C TInt E32Main()
       
   267 //
       
   268 // Test the Document Model Services.
       
   269 //
       
   270     {
   274     {
   271 	setupCleanup();
   275     SetTestStepName(KTestStep_T_TTIMES1);
   272 	test.Title();	
       
   273 	__UHEAP_MARK;
       
   274 	
       
   275 	TRAPD(ret,DoTestsL());
       
   276     test(ret == KErrNone);
       
   277 	
       
   278 	test.End();
       
   279 	test.Close();
       
   280 	__UHEAP_MARKEND;
       
   281 	delete TheTrapCleanup;
       
   282 	return(0);
       
   283     }
   276     }
       
   277 
       
   278 TVerdict CT_TTIMES1::doTestStepL()
       
   279     {
       
   280     SetTestStepResult(EFail);
       
   281 
       
   282     __UHEAP_MARK;
       
   283 
       
   284     setupCleanup();
       
   285     
       
   286     INFO_PRINTF1(_L("CRichText Document"));
       
   287     TRAPD(error1, DoTestsL());
       
   288 
       
   289     delete TheTrapCleanup;
       
   290 
       
   291     __UHEAP_MARKEND;
       
   292 
       
   293     if(error1 == KErrNone)
       
   294         {
       
   295         SetTestStepResult(EPass);
       
   296         }
       
   297 
       
   298     return TestStepResult();
       
   299     }