textrendering/texthandling/ttext/T_TIMES.CPP
branchRCL_3
changeset 55 336bee5c2d35
parent 54 748ec5531811
equal deleted inserted replaced
54:748ec5531811 55:336bee5c2d35
     1 /*
     1 /*
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2009 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>
    19 #include <e32svr.h>
    20 #include <e32svr.h>
    20 
    21 
    21 #include <txtrich.h>
    22 #include <txtrich.h>
    22 #include <txtglobl.h>
    23 #include <txtglobl.h>
    23 #include "T_TIMES.h"
       
    24 
       
    25 LOCAL_D CTestStep *pTestStep = NULL;
       
    26 #define test(cond)											\
       
    27 	{														\
       
    28 	TBool __bb = (cond);									\
       
    29 	pTestStep->TEST(__bb);									\
       
    30 	if (!__bb)												\
       
    31 		{													\
       
    32 		pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed"));	\
       
    33 		User::Leave(1);										\
       
    34 		}													\
       
    35 	}
       
    36 #undef INFO_PRINTF1
       
    37 #undef INFO_PRINTF2
       
    38 // copy from tefexportconst.h
       
    39 #define INFO_PRINTF1(p1)        pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1))
       
    40 #define INFO_PRINTF2(p1, p2)    pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2))
       
    41 
       
    42 
    24 
    43 /* this fixes a MSVC link warning */
    25 /* this fixes a MSVC link warning */
    44 #ifdef __VC32__
    26 #ifdef __VC32__
    45 #pragma comment (linker, "/opt:noref") 
    27 #pragma comment (linker, "/opt:noref") 
    46 #endif
    28 #endif
    71 const TInt KCharFormatLayerTest=100000;
    53 const TInt KCharFormatLayerTest=100000;
    72 #endif
    54 #endif
    73 
    55 
    74 
    56 
    75 LOCAL_D CTrapCleanup* TheTrapCleanup;
    57 LOCAL_D CTrapCleanup* TheTrapCleanup;
       
    58 LOCAL_D RTest test(_L("CRichText Document"));
    76 LOCAL_D CGlobalText* TheText;
    59 LOCAL_D CGlobalText* TheText;
    77 LOCAL_D CParaFormatLayer* TheParaFormatLayer;
    60 LOCAL_D CParaFormatLayer* TheParaFormatLayer;
    78 LOCAL_D CCharFormatLayer* TheCharFormatLayer;
    61 LOCAL_D CCharFormatLayer* TheCharFormatLayer;
    79 LOCAL_D const TInt KTestCleanupStack=0x200;
    62 LOCAL_D const TInt KTestCleanupStack=0x200;
    80 
    63 
   171 	TInt documentLength=TheText->DocumentLength();
   154 	TInt documentLength=TheText->DocumentLength();
   172 	TInt paraCount=TheText->ParagraphCount();
   155 	TInt paraCount=TheText->ParagraphCount();
   173 	TInt wordCount=TheText->WordCount();
   156 	TInt wordCount=TheText->WordCount();
   174 	TBuf<80> stats;
   157 	TBuf<80> stats;
   175 	stats.Format(_L("Document Stats:\nChars: %d\nWords: %d\nParas: %d\n"),documentLength,wordCount,paraCount);
   158 	stats.Format(_L("Document Stats:\nChars: %d\nWords: %d\nParas: %d\n"),documentLength,wordCount,paraCount);
   176 	INFO_PRINTF1(stats);
   159 	test.Printf(stats);
   177 	RDebug::Print(_L("%S"),&stats);
   160 	RDebug::Print(_L("%S"),&stats);
   178 	TBuf<80> testTitle;
   161 	TBuf<80> testTitle;
   179 	//
   162 	//
   180 	testTitle.Format(_L("Pos: 0-100  %d times"),aTest1Count);
   163 	testTitle.Format(_L("Pos: 0-100  %d times"),aTest1Count);
   181 	INFO_PRINTF1(testTitle);
   164 	test.Start(testTitle);
   182 	GetTimesForGetChars(aTest1Count,0,100,50);
   165 	GetTimesForGetChars(aTest1Count,0,100,50);
   183 	//
   166 	//
   184 	testTitle.Format(_L("Pos: 18200-18300 %d times"),aTest2Count);
   167 	testTitle.Format(_L("Pos: 18200-18300 %d times"),aTest2Count);
   185 	INFO_PRINTF1(testTitle);
   168 	test.Next(testTitle);
   186 	GetTimesForGetChars(aTest2Count,18200,100,50);
   169 	GetTimesForGetChars(aTest2Count,18200,100,50);
   187 	//
   170 	//
   188 	testTitle.Format(_L("Pos: all %d times"),aTest3Count);
   171 	testTitle.Format(_L("Pos: all %d times"),aTest3Count);
   189 	INFO_PRINTF1(testTitle);
   172 	test.Next(testTitle);
   190 	GetTimesForGetChars(aTest3Count,0,documentLength,50);
   173 	GetTimesForGetChars(aTest3Count,0,documentLength,50);
   191 	//
   174 	//
   192 	
   175 	test.End();
   193 	}
   176 	}
   194 
   177 
   195 
   178 
   196 LOCAL_C void DoGetCharFormatLayerReadTimesL(TInt aLoopCount)
   179 LOCAL_C void DoGetCharFormatLayerReadTimesL(TInt aLoopCount)
   197 //
   180 //
   208 
   191 
   209 		}
   192 		}
   210 	// Display the metric
   193 	// Display the metric
   211 	TBuf<60> context;
   194 	TBuf<60> context;
   212 	context.Format(_L("10 att X %d loops=%d atts\n"),aLoopCount,10*aLoopCount);
   195 	context.Format(_L("10 att X %d loops=%d atts\n"),aLoopCount,10*aLoopCount);
   213 	INFO_PRINTF1(context);
   196 	test.Printf(context);
   214 	RDebug::Print(_L("%S"),&context);
   197 	RDebug::Print(_L("%S"),&context);
   215 	}
   198 	}
   216 
   199 
   217 
   200 
   218 LOCAL_C void DoEmptyCharFormatLayerReadL(TInt aLoopCount)
   201 LOCAL_C void DoEmptyCharFormatLayerReadL(TInt aLoopCount)
   237 
   220 
   238 LOCAL_C void FormatLayerTestL()
   221 LOCAL_C void FormatLayerTestL()
   239 // Time tests on format layer access.
   222 // Time tests on format layer access.
   240 //
   223 //
   241 	{
   224 	{
   242 	INFO_PRINTF1(_L("CCharFormatLayer - Attribute reads"));
   225 	test.Start(_L("CCharFormatLayer - Attribute reads"));
   243 	GenerateGlobalLayersL();
   226 	GenerateGlobalLayersL();
   244 	//
   227 	//
   245 	TBuf<80> testTitle;
   228 	TBuf<80> testTitle;
   246 	testTitle.Format(_L("Reading empty char format layer %d times"),KCharFormatLayerTest);
   229 	testTitle.Format(_L("Reading empty char format layer %d times"),KCharFormatLayerTest);
   247 	INFO_PRINTF1(testTitle);
   230 	test.Next(testTitle);
   248 	DoEmptyCharFormatLayerReadL(KCharFormatLayerTest);
   231 	DoEmptyCharFormatLayerReadL(KCharFormatLayerTest);
   249 	//
   232 	//
   250 	testTitle.Format(_L("Read 10 attributes from layer %d times"),KCharFormatLayerTest);
   233 	testTitle.Format(_L("Read 10 attributes from layer %d times"),KCharFormatLayerTest);
   251 	INFO_PRINTF1(testTitle);
   234 	test.Next(testTitle);
   252 	TRAPD(ret, DoCharFormatLayerReadL(KCharFormatLayerTest));
   235 	TRAPD(ret, DoCharFormatLayerReadL(KCharFormatLayerTest));
   253 	test(ret==KErrNone);
   236 	test(ret==KErrNone);
   254 	//
   237 	//
   255 	KillGlobalLayers();
   238 	KillGlobalLayers();
   256 	
   239 	test.End();
   257 	}
   240 	}
   258 
   241 
   259 
   242 
   260 LOCAL_C void LongDocumentTestL()
   243 LOCAL_C void LongDocumentTestL()
   261 //
   244 //
   262 	{
   245 	{
   263 	//
   246 	//
   264 	INFO_PRINTF1(_L("Global text - Empty layers"));
   247 	test.Start(_L("Global text - Empty layers"));
   265 	GenerateGlobalTextL();
   248 	GenerateGlobalTextL();
   266 	DoLongDocumentTestL(KGlobalTextATest1,KGlobalTextATest2,KGlobalTextATest3);
   249 	DoLongDocumentTestL(KGlobalTextATest1,KGlobalTextATest2,KGlobalTextATest3);
   267 	KillText();
   250 	KillText();
   268 	//
   251 	//
   269 	INFO_PRINTF1(_L("Rich text - Empty layers"));
   252 	test.Next(_L("Rich text - Empty layers"));
   270 	GenerateBasicRichTextL();
   253 	GenerateBasicRichTextL();
   271 	DoLongDocumentTestL(KRichTextTest1,KRichTextTest2,KRichTextTest3);
   254 	DoLongDocumentTestL(KRichTextTest1,KRichTextTest2,KRichTextTest3);
   272 	KillText();
   255 	KillText();
   273 	KillGlobalLayers();
   256 	KillGlobalLayers();
   274 	//
   257 	//
   275 	INFO_PRINTF1(_L("Global text - 2 character attributes stored"));
   258 	test.Next(_L("Global text - 2 character attributes stored"));
   276 	GenerateGlobalTextL();
   259 	GenerateGlobalTextL();
   277 	TBuf<5> name=_L("SWiss");
   260 	TBuf<5> name=_L("SWiss");
   278 	TCharFormat charFormat(name,178);
   261 	TCharFormat charFormat(name,178);
   279 	TCharFormatMask charMask;
   262 	TCharFormatMask charMask;
   280 	charMask.SetAttrib(EAttFontTypeface);
   263 	charMask.SetAttrib(EAttFontTypeface);
   283 	TheCharFormatLayer->SetL(charFormat,charMask));
   266 	TheCharFormatLayer->SetL(charFormat,charMask));
   284 	test(ret==KErrNone);
   267 	test(ret==KErrNone);
   285 	DoLongDocumentTestL(KGlobalTextBTest1,KGlobalTextBTest2,KGlobalTextBTest3);
   268 	DoLongDocumentTestL(KGlobalTextBTest1,KGlobalTextBTest2,KGlobalTextBTest3);
   286 	KillText();
   269 	KillText();
   287 	//
   270 	//
   288 	INFO_PRINTF1(_L("Rich text - 2 charcter attributes stored"));
   271 	test.Next(_L("Rich text - 2 charcter attributes stored"));
   289 	GenerateBasicRichTextL();
   272 	GenerateBasicRichTextL();
   290 	DoLongDocumentTestL(KRichTextTest1,KRichTextTest2,KRichTextTest3);
   273 	DoLongDocumentTestL(KRichTextTest1,KRichTextTest2,KRichTextTest3);
   291 	KillText();
   274 	KillText();
   292 	//
   275 	//
   293 	KillGlobalLayers();
   276 	KillGlobalLayers();
       
   277 	test.End();
       
   278 	}
   294 	
   279 	
   295 	}
       
   296 	
       
   297 
   280 
   298 LOCAL_C void DoTestsL()
   281 LOCAL_C void DoTestsL()
   299 //
   282 //
   300 	{
   283 	{
   301 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TIMES-0001 Long document tests "));
   284 	test.Start(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TIMES-0001 Long document tests "));
   302 	LongDocumentTestL();
   285 	LongDocumentTestL();
   303 	//
   286 	//
   304 	INFO_PRINTF1(_L("Format layer tests"));
   287 	test.Next(_L("Format layer tests"));
   305 	FormatLayerTestL();
   288 	FormatLayerTestL();
   306 	//
   289 	//
   307 	}
   290 	}
   308 
   291 
   309 
   292 
   321 		test(r==KErrNone);\
   304 		test(r==KErrNone);\
   322 		CleanupStack::Pop(KTestCleanupStack);\
   305 		CleanupStack::Pop(KTestCleanupStack);\
   323 		});
   306 		});
   324 	}
   307 	}
   325 
   308 
   326 CT_TIMES::CT_TIMES()
   309 
       
   310 
       
   311 GLDEF_C TInt E32Main()
       
   312 //
       
   313 // Test the Document Model Services.
       
   314 //
   327     {
   315     {
   328     SetTestStepName(KTestStep_T_TIMES);
   316 	setupCleanup();
   329     pTestStep = this;
   317 	test.Title();	
       
   318 	__UHEAP_MARK;
       
   319 	
       
   320 	TRAPD(ret,DoTestsL());
       
   321     test(ret == KErrNone);
       
   322 	
       
   323 	test.End();
       
   324 	test.Close();
       
   325 	__UHEAP_MARKEND;
       
   326 	delete TheTrapCleanup;
       
   327 	return(0);
   330     }
   328     }
   331 
       
   332 TVerdict CT_TIMES::doTestStepL()
       
   333     {
       
   334     SetTestStepResult(EFail);
       
   335 
       
   336     setupCleanup();
       
   337     INFO_PRINTF1(_L("CRichText Document"));   
       
   338     __UHEAP_MARK;
       
   339     
       
   340     TRAPD(ret,DoTestsL());
       
   341     
       
   342     __UHEAP_MARKEND;
       
   343     delete TheTrapCleanup;
       
   344     
       
   345     if (ret == KErrNone)
       
   346         {
       
   347         SetTestStepResult(EPass);
       
   348         }
       
   349 
       
   350     return TestStepResult();
       
   351     }