textrendering/texthandling/ttext/TTIMES1.CPP
changeset 0 1fb32624e06b
child 51 a7c938434754
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <e32svr.h>
       
    21 
       
    22 #include <s32mem.h>
       
    23 
       
    24 #include <txtrich.h>
       
    25 #include <txtglobl.h>
       
    26 
       
    27 #include "../incp/T_PMLPAR.H"
       
    28 
       
    29 #define UNUSED_VAR(a) a = a
       
    30 
       
    31 LOCAL_D CTrapCleanup* TheTrapCleanup;
       
    32 LOCAL_D RTest test(_L("CRichText Document"));
       
    33 LOCAL_D CParaFormatLayer* TheGlobalParaFormatLayer;
       
    34 LOCAL_D CCharFormatLayer* TheGlobalCharFormatLayer;
       
    35 LOCAL_D CParser* TheParser;
       
    36 
       
    37 LOCAL_D const TInt KTestCleanupStack=0x200;
       
    38 LOCAL_D const TInt KCreateRichTextCount=1000;
       
    39 
       
    40 LOCAL_D CRichText* TheText[KCreateRichTextCount];
       
    41 
       
    42 LOCAL_C void GenerateGlobalLayersL()
       
    43 // Provides the base layers for globl text and below
       
    44 //
       
    45 	{
       
    46 	TParaFormatMask paraMask;
       
    47 	TheGlobalParaFormatLayer=CParaFormatLayer::NewL((CParaFormat*)NULL,paraMask);
       
    48 	TCharFormat charFormat;
       
    49 	TCharFormatMask charMask;
       
    50 	TheGlobalCharFormatLayer=CCharFormatLayer::NewL(charFormat,charMask);
       
    51 	}
       
    52 
       
    53 
       
    54 LOCAL_C void KillGlobalLayers()
       
    55 // Destroy the base layers for global text and below
       
    56 //
       
    57 	{
       
    58 	delete TheGlobalParaFormatLayer;
       
    59 	delete TheGlobalCharFormatLayer;
       
    60 	TheGlobalParaFormatLayer=NULL;
       
    61 	TheGlobalCharFormatLayer=NULL;
       
    62 	}
       
    63 
       
    64 LOCAL_C void KillText()
       
    65 	{
       
    66 	for (TInt ii=0; ii<KCreateRichTextCount;ii++)
       
    67 		{
       
    68 		delete TheText[ii];
       
    69 		TheText[ii]=NULL;
       
    70 		}
       
    71 	}
       
    72 
       
    73 
       
    74 struct TNow : public TTime 
       
    75 	{
       
    76 	TNow() { HomeTime(); }
       
    77 	};
       
    78 
       
    79 LOCAL_C void CreationTestsL()
       
    80 //
       
    81 	{
       
    82 	GenerateGlobalLayersL();
       
    83 
       
    84 	TNow start;
       
    85 	TInt ii = 0;
       
    86 	for (ii=0; ii<KCreateRichTextCount;ii++)
       
    87 		{
       
    88 		TheText[ii]=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);			
       
    89 		}
       
    90 	TNow finish;
       
    91 	KillText();
       
    92 	test(ii==KCreateRichTextCount);
       
    93 	//
       
    94 	// Display the metric
       
    95 	TBuf<60> context;
       
    96 	context.Format(_L("        Create rich text %d times: %d\n"),KCreateRichTextCount,finish.MicroSecondsFrom(start).Int64());
       
    97 	test.Printf(context);
       
    98 	//
       
    99 	// Tidy up
       
   100 	KillText();
       
   101 	KillGlobalLayers();
       
   102 	}
       
   103 
       
   104 
       
   105 LOCAL_C CRichText* LoadIntoTextL(TFileName& aFileName)
       
   106 //
       
   107 	{
       
   108 	TRAPD(ret,
       
   109 	TheParser=CParser::NewL());
       
   110 	CRichText* text=NULL;
       
   111 	TRAP(ret,
       
   112 	text=TheParser->ParseL(aFileName));
       
   113 	TheGlobalParaFormatLayer=(CParaFormatLayer*)text->GlobalParaFormatLayer();
       
   114 	TheGlobalCharFormatLayer=(CCharFormatLayer*)text->GlobalCharFormatLayer();
       
   115 	delete TheParser;
       
   116 	TheParser=NULL;
       
   117 	return text;
       
   118 	}
       
   119 
       
   120 
       
   121 LOCAL_C void GetAppendTestTimeL(const CRichText* aSource,TInt aTestLoopCount)
       
   122 	{
       
   123 	CRichText* target=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);
       
   124 	test(target->DocumentLength()==0);
       
   125 	test(!target->HasMarkupData());
       
   126 
       
   127 	TNow start;
       
   128 	TInt ii = 0;
       
   129 	for (ii=0;ii<aTestLoopCount;ii++)
       
   130 		{
       
   131 		target->AppendTakingSolePictureOwnershipL(*aSource);
       
   132 		}
       
   133 	TNow finish;
       
   134 	TInt charSum=aTestLoopCount*(aSource->DocumentLength()+1)-1;
       
   135 	test(target->DocumentLength()==charSum);
       
   136 	//
       
   137 	// Calculate and display result
       
   138 	test(ii==aTestLoopCount);
       
   139 	TBuf<60> context;
       
   140 	context.Format(_L("        Append %d rich text's: %d\n"),aTestLoopCount,finish.MicroSecondsFrom(start).Int64());
       
   141 	test.Printf(context);
       
   142 	delete target;
       
   143 	}
       
   144 
       
   145 
       
   146 LOCAL_C void GetBenchmarkAppendTestTimeL(const CRichText* aSource,TInt aTestLoopCount)
       
   147 	{
       
   148 	CRichText** target=new CRichText*[aTestLoopCount];
       
   149 	CBufStore** store=new CBufStore*[aTestLoopCount];	
       
   150 	TInt ii = 0;
       
   151 	for (ii=0;ii<aTestLoopCount;ii++)
       
   152 		{
       
   153 		target[ii]=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);
       
   154 		store[ii]=CBufStore::NewL(128);	
       
   155 		test(target[ii]->DocumentLength()==0);
       
   156 		test(!target[ii]->HasMarkupData());
       
   157 		}
       
   158 	TNow start;
       
   159 	for (ii=0;ii<aTestLoopCount;ii++)
       
   160 		{
       
   161 		TStreamId id=aSource->StoreL(*store[ii]);
       
   162 		target[ii]->RestoreL(*store[ii],id);
       
   163 		}
       
   164 	TNow finish;
       
   165 
       
   166 	for (ii=0;ii<aTestLoopCount;ii++)
       
   167 		{
       
   168 		delete target[ii];
       
   169 		delete store[ii];
       
   170 		}
       
   171 	delete []target;
       
   172 	delete []store;
       
   173 	//
       
   174 	// Calculate and display result
       
   175 	test(ii==aTestLoopCount);
       
   176 	TBuf<70> context2;
       
   177 	context2.Format(_L("        Benchmark              : %d\n"),finish.MicroSecondsFrom(start).Int64());
       
   178 	test.Printf(context2);
       
   179 	}
       
   180 
       
   181 
       
   182 LOCAL_C void AppendTest1L()
       
   183 //
       
   184 	{
       
   185 	TInt testLoopCount=900;
       
   186 	CRichText* source=CRichText::NewL(TheGlobalParaFormatLayer,TheGlobalCharFormatLayer);
       
   187 	source->InsertL(source->DocumentLength(),_L("A bit of text that pretends to be an entry's title"));
       
   188 	test(!source->HasMarkupData());
       
   189 	GetAppendTestTimeL(source,testLoopCount);
       
   190 	//
       
   191 	// Now the benchmark against which we should measure.
       
   192 	GetBenchmarkAppendTestTimeL(source,testLoopCount);
       
   193 	//
       
   194 	// tidy up
       
   195 	delete source;
       
   196 	}
       
   197 
       
   198 
       
   199 LOCAL_C void AppendTest2L()
       
   200 //
       
   201 	{
       
   202 	KillGlobalLayers();  // they are replaced by the ones read in from the PML file.
       
   203 	TInt testLoopCount=266;
       
   204 	TFileName file=_L("z:\\test\\app-framework\\etext\\ttimes1.pml");
       
   205 	CRichText* source=LoadIntoTextL(file);
       
   206 	test(source->HasMarkupData());
       
   207 	GetAppendTestTimeL(source,testLoopCount);
       
   208 	//
       
   209 	// Now the benchmark against which we should measure.
       
   210 	GetBenchmarkAppendTestTimeL(source,testLoopCount);
       
   211 	//
       
   212 	// tidy up
       
   213 	delete source;
       
   214 	}
       
   215 
       
   216 
       
   217 LOCAL_C void AppendTestsL()
       
   218 //
       
   219 	{
       
   220 	GenerateGlobalLayersL();
       
   221 	//
       
   222 	test.Start(_L("Plain Text Component Only"));
       
   223 	TRAPD(ret,
       
   224 	AppendTest1L());
       
   225 	test(ret==KErrNone);
       
   226 	//
       
   227 	test.Next(_L("Plain Text with limited Markup - no pictures"));
       
   228 	TRAP(ret,
       
   229 	AppendTest2L());
       
   230 	test(ret==KErrNone);
       
   231 	//
       
   232 	KillGlobalLayers();
       
   233 	test.End();
       
   234 	}
       
   235 	
       
   236 	
       
   237 LOCAL_C void DoTestsL()
       
   238 //
       
   239 	{
       
   240 	test.Start(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TTIMES1-0001 Creation Tests "));
       
   241 	CreationTestsL();
       
   242 	test.Next(_L("Appending Tests"));
       
   243 	AppendTestsL();
       
   244 	//
       
   245 	}
       
   246 
       
   247 
       
   248 LOCAL_C void setupCleanup()
       
   249 //
       
   250 // Initialise the cleanup stack.
       
   251 //
       
   252     {
       
   253 
       
   254 	TheTrapCleanup=CTrapCleanup::New();
       
   255 	TRAPD(r,\
       
   256 		{\
       
   257 		for (TInt i=KTestCleanupStack;i>0;i--)\
       
   258 			CleanupStack::PushL((TAny*)1);\
       
   259 		test(r==KErrNone);\
       
   260 		CleanupStack::Pop(KTestCleanupStack);\
       
   261 		});
       
   262 	}
       
   263 
       
   264 
       
   265 
       
   266 GLDEF_C TInt E32Main()
       
   267 //
       
   268 // Test the Document Model Services.
       
   269 //
       
   270     {
       
   271 	setupCleanup();
       
   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     }