sl@0: /* sl@0: * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include <e32svr.h> sl@0: sl@0: #include <txtrich.h> sl@0: #include <txtglobl.h> sl@0: #include "T_TIMES.h" sl@0: sl@0: LOCAL_D CTestStep *pTestStep = NULL; sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: pTestStep->TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: #undef INFO_PRINTF1 sl@0: #undef INFO_PRINTF2 sl@0: // copy from tefexportconst.h sl@0: #define INFO_PRINTF1(p1) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) sl@0: #define INFO_PRINTF2(p1, p2) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) sl@0: sl@0: sl@0: /* this fixes a MSVC link warning */ sl@0: #ifdef __VC32__ sl@0: #pragma comment (linker, "/opt:noref") sl@0: #endif sl@0: sl@0: #define UNUSED_VAR(a) a = a sl@0: sl@0: #ifdef NDEBUG sl@0: const TInt KGlobalTextATest1=100000; sl@0: const TInt KGlobalTextATest2=100000; sl@0: const TInt KGlobalTextATest3=1000; sl@0: const TInt KRichTextTest1=10000; sl@0: const TInt KRichTextTest2=10000; sl@0: const TInt KRichTextTest3=1000; sl@0: const TInt KGlobalTextBTest1=10000; sl@0: const TInt KGlobalTextBTest2=10000; sl@0: const TInt KGlobalTextBTest3=1000; sl@0: const TInt KCharFormatLayerTest=100000; sl@0: #else sl@0: const TInt KGlobalTextATest1=100000; sl@0: const TInt KGlobalTextATest2=100000; sl@0: const TInt KGlobalTextATest3=1000; sl@0: const TInt KRichTextTest1=5000; sl@0: const TInt KRichTextTest2=5000; sl@0: const TInt KRichTextTest3=100; sl@0: const TInt KGlobalTextBTest1=5000; sl@0: const TInt KGlobalTextBTest2=5000; sl@0: const TInt KGlobalTextBTest3=100; sl@0: const TInt KCharFormatLayerTest=100000; sl@0: #endif sl@0: sl@0: sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup; sl@0: LOCAL_D CGlobalText* TheText; sl@0: LOCAL_D CParaFormatLayer* TheParaFormatLayer; sl@0: LOCAL_D CCharFormatLayer* TheCharFormatLayer; sl@0: LOCAL_D const TInt KTestCleanupStack=0x200; sl@0: sl@0: LOCAL_C void GenerateGlobalLayersL() sl@0: // Provides the base layers for globl text and below sl@0: // sl@0: { sl@0: TParaFormatMask paraMask; sl@0: TheParaFormatLayer=CParaFormatLayer::NewL((CParaFormat*)NULL,paraMask); sl@0: TCharFormat charFormat; sl@0: TCharFormatMask charMask; sl@0: TheCharFormatLayer=CCharFormatLayer::NewL(charFormat,charMask); sl@0: } sl@0: sl@0: LOCAL_C void GenerateGlobalTextL() sl@0: // Provide an instantiated global text object sl@0: // sl@0: { sl@0: GenerateGlobalLayersL(); sl@0: TheText=CGlobalText::NewL(TheParaFormatLayer,TheCharFormatLayer); sl@0: } sl@0: sl@0: LOCAL_C void GenerateBasicRichTextL() sl@0: // Provide a default instantiated rich text object sl@0: // sl@0: {TheText=CRichText::NewL(TheParaFormatLayer,TheCharFormatLayer);} sl@0: sl@0: LOCAL_C void KillGlobalLayers() sl@0: // Destroy the base layers for global text and below sl@0: // sl@0: { sl@0: delete TheParaFormatLayer; sl@0: delete TheCharFormatLayer; sl@0: TheParaFormatLayer=NULL; sl@0: TheCharFormatLayer=NULL; sl@0: } sl@0: sl@0: LOCAL_C void KillText() sl@0: { sl@0: delete TheText; sl@0: TheText=NULL; sl@0: } sl@0: sl@0: sl@0: LOCAL_C void LoadLongDocument() sl@0: // sl@0: { sl@0: TFileName file; sl@0: sl@0: file=(_L("z:\\test\\app-framework\\etext\\climb.txt")); sl@0: TheText->Reset(); sl@0: TInt count=0; sl@0: TRAPD(ret, sl@0: count=TheText->ImportTextFileL(0,file,CPlainText::EOrganiseByParagraph)); sl@0: test(ret==KErrNone); sl@0: test(count>0); // check for equality later sl@0: } sl@0: sl@0: sl@0: LOCAL_C void CallGetChars(TInt aStartPos,TInt aCharacterCount,TInt aLineLength) sl@0: // sl@0: { sl@0: TPtrC view; sl@0: TCharFormat charFormat; sl@0: TInt consumed=aStartPos; sl@0: while (consumed<=aStartPos+aCharacterCount) sl@0: { sl@0: TheText->GetChars(view,charFormat,consumed); sl@0: consumed+=Min(view.Length(),aLineLength); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void GetTimesForGetChars(TInt aLoopCount,TInt aStartPos,TInt aCharacterCount,TInt aLineLength) sl@0: // sl@0: // sl@0: { sl@0: // sl@0: for (TInt loop=0;loop<aLoopCount;loop++) sl@0: { sl@0: CallGetChars(aStartPos,aCharacterCount,aLineLength); sl@0: } sl@0: } sl@0: sl@0: sl@0: LOCAL_C void DoLongDocumentTestL(TInt aTest1Count,TInt aTest2Count,TInt aTest3Count) sl@0: // sl@0: // sl@0: { sl@0: LoadLongDocument(); sl@0: TCharFormat charFormat; sl@0: TCharFormatMask mask; sl@0: mask.SetAttrib(EAttFontStrokeWeight); sl@0: TheText->ApplyCharFormatL(charFormat,mask,100,2); sl@0: TInt documentLength=TheText->DocumentLength(); sl@0: TInt paraCount=TheText->ParagraphCount(); sl@0: TInt wordCount=TheText->WordCount(); sl@0: TBuf<80> stats; sl@0: stats.Format(_L("Document Stats:\nChars: %d\nWords: %d\nParas: %d\n"),documentLength,wordCount,paraCount); sl@0: INFO_PRINTF1(stats); sl@0: RDebug::Print(_L("%S"),&stats); sl@0: TBuf<80> testTitle; sl@0: // sl@0: testTitle.Format(_L("Pos: 0-100 %d times"),aTest1Count); sl@0: INFO_PRINTF1(testTitle); sl@0: GetTimesForGetChars(aTest1Count,0,100,50); sl@0: // sl@0: testTitle.Format(_L("Pos: 18200-18300 %d times"),aTest2Count); sl@0: INFO_PRINTF1(testTitle); sl@0: GetTimesForGetChars(aTest2Count,18200,100,50); sl@0: // sl@0: testTitle.Format(_L("Pos: all %d times"),aTest3Count); sl@0: INFO_PRINTF1(testTitle); sl@0: GetTimesForGetChars(aTest3Count,0,documentLength,50); sl@0: // sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void DoGetCharFormatLayerReadTimesL(TInt aLoopCount) sl@0: // sl@0: { sl@0: // sl@0: // Now take some times. sl@0: TCharFormat charFormat; sl@0: TCharFormatMask charMask; sl@0: for (TInt loop=0;loop<aLoopCount;loop++) sl@0: { sl@0: charMask.ClearAll(); // this is used for readings. sl@0: sl@0: TheCharFormatLayer->Sense(charFormat,charMask); sl@0: sl@0: } sl@0: // Display the metric sl@0: TBuf<60> context; sl@0: context.Format(_L("10 att X %d loops=%d atts\n"),aLoopCount,10*aLoopCount); sl@0: INFO_PRINTF1(context); sl@0: RDebug::Print(_L("%S"),&context); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void DoEmptyCharFormatLayerReadL(TInt aLoopCount) sl@0: // sl@0: {DoGetCharFormatLayerReadTimesL(aLoopCount);} sl@0: sl@0: sl@0: LOCAL_C void DoCharFormatLayerReadL(TInt aLoopCount) sl@0: // tests times of reading attributes from a CCharFormatLayer sl@0: // sl@0: { sl@0: // Fill the character format layer sl@0: TCharFormat charFormat(_L("Times New Roman"),180); sl@0: TCharFormatMask charMask; sl@0: charMask.SetAll(); sl@0: TheCharFormatLayer->SetL(charFormat,charMask); sl@0: // sl@0: // Take times sl@0: DoGetCharFormatLayerReadTimesL(aLoopCount); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void FormatLayerTestL() sl@0: // Time tests on format layer access. sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("CCharFormatLayer - Attribute reads")); sl@0: GenerateGlobalLayersL(); sl@0: // sl@0: TBuf<80> testTitle; sl@0: testTitle.Format(_L("Reading empty char format layer %d times"),KCharFormatLayerTest); sl@0: INFO_PRINTF1(testTitle); sl@0: DoEmptyCharFormatLayerReadL(KCharFormatLayerTest); sl@0: // sl@0: testTitle.Format(_L("Read 10 attributes from layer %d times"),KCharFormatLayerTest); sl@0: INFO_PRINTF1(testTitle); sl@0: TRAPD(ret, DoCharFormatLayerReadL(KCharFormatLayerTest)); sl@0: test(ret==KErrNone); sl@0: // sl@0: KillGlobalLayers(); sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void LongDocumentTestL() sl@0: // sl@0: { sl@0: // sl@0: INFO_PRINTF1(_L("Global text - Empty layers")); sl@0: GenerateGlobalTextL(); sl@0: DoLongDocumentTestL(KGlobalTextATest1,KGlobalTextATest2,KGlobalTextATest3); sl@0: KillText(); sl@0: // sl@0: INFO_PRINTF1(_L("Rich text - Empty layers")); sl@0: GenerateBasicRichTextL(); sl@0: DoLongDocumentTestL(KRichTextTest1,KRichTextTest2,KRichTextTest3); sl@0: KillText(); sl@0: KillGlobalLayers(); sl@0: // sl@0: INFO_PRINTF1(_L("Global text - 2 character attributes stored")); sl@0: GenerateGlobalTextL(); sl@0: TBuf<5> name=_L("SWiss"); sl@0: TCharFormat charFormat(name,178); sl@0: TCharFormatMask charMask; sl@0: charMask.SetAttrib(EAttFontTypeface); sl@0: charMask.SetAttrib(EAttFontHeight); sl@0: TRAPD(ret, sl@0: TheCharFormatLayer->SetL(charFormat,charMask)); sl@0: test(ret==KErrNone); sl@0: DoLongDocumentTestL(KGlobalTextBTest1,KGlobalTextBTest2,KGlobalTextBTest3); sl@0: KillText(); sl@0: // sl@0: INFO_PRINTF1(_L("Rich text - 2 charcter attributes stored")); sl@0: GenerateBasicRichTextL(); sl@0: DoLongDocumentTestL(KRichTextTest1,KRichTextTest2,KRichTextTest3); sl@0: KillText(); sl@0: // sl@0: KillGlobalLayers(); sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void DoTestsL() sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TIMES-0001 Long document tests ")); sl@0: LongDocumentTestL(); sl@0: // sl@0: INFO_PRINTF1(_L("Format layer tests")); sl@0: FormatLayerTestL(); sl@0: // sl@0: } sl@0: sl@0: sl@0: LOCAL_C void setupCleanup() sl@0: // sl@0: // Initialise the cleanup stack. sl@0: // sl@0: { sl@0: sl@0: TheTrapCleanup=CTrapCleanup::New(); sl@0: TRAPD(r,\ sl@0: {\ sl@0: for (TInt i=KTestCleanupStack;i>0;i--)\ sl@0: CleanupStack::PushL((TAny*)1);\ sl@0: test(r==KErrNone);\ sl@0: CleanupStack::Pop(KTestCleanupStack);\ sl@0: }); sl@0: } sl@0: sl@0: CT_TIMES::CT_TIMES() sl@0: { sl@0: SetTestStepName(KTestStep_T_TIMES); sl@0: pTestStep = this; sl@0: } sl@0: sl@0: TVerdict CT_TIMES::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: setupCleanup(); sl@0: INFO_PRINTF1(_L("CRichText Document")); sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(ret,DoTestsL()); sl@0: sl@0: __UHEAP_MARKEND; sl@0: delete TheTrapCleanup; sl@0: sl@0: if (ret == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }