os/textandloc/fontservices/fontstore/tfs/T_fontsessioncacheproc.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_fontsessioncacheproc.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,158 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @test
    1.24 + @internalComponent - Internal Symbian test code
    1.25 +*/
    1.26 +
    1.27 +#include "FNTSTORE.H"
    1.28 +#include <e32math.h>
    1.29 +
    1.30 +_LIT(KOpenFont, "DejaVu Sans Condensed");
    1.31 +
    1.32 +#ifdef __WINSCW__
    1.33 +//this is used for winscw breakpoints
    1.34 +#define BR _asm( int 3);
    1.35 +#endif
    1.36 +
    1.37 +const TInt KTimeOut = 1000 * 1000;
    1.38 +
    1.39 +
    1.40 +_LIT(KTCacheDeletionProcess,"T_fontsessioncacheproc");
    1.41 +
    1.42 +/* it is expected that the main in this file will be called to test multiple 
    1.43 +process cache searching which is in the shared heap.
    1.44 +*/
    1.45 +
    1.46 +class CRunProc: public CBase
    1.47 +    {
    1.48 +public:
    1.49 +    void RunTestL();
    1.50 +    CRunProc();
    1.51 +    ~CRunProc();
    1.52 +    
    1.53 +    inline void setFont(CFont*);
    1.54 +    inline void setHandle(TInt);
    1.55 +private:
    1.56 +    void CreateFontL();
    1.57 +
    1.58 +private:
    1.59 +    CBitmapFont* iFont;
    1.60 +    TInt iSessionHandle;
    1.61 +    };
    1.62 +
    1.63 +CRunProc::CRunProc()
    1.64 +    {
    1.65 +    
    1.66 +    }
    1.67 +
    1.68 +CRunProc::~CRunProc()
    1.69 +    {
    1.70 +    
    1.71 +    }
    1.72 +
    1.73 +inline void CRunProc::setFont(CFont* aFont)
    1.74 +    {
    1.75 +    iFont = static_cast<CBitmapFont*>(aFont);
    1.76 +    }
    1.77 +
    1.78 +inline void CRunProc::setHandle(TInt aSessionHandle)
    1.79 +    {
    1.80 +    iSessionHandle = aSessionHandle;
    1.81 +    }
    1.82 +
    1.83 +
    1.84 +void CRunProc::RunTestL()
    1.85 +    {
    1.86 +    TTime theTime;
    1.87 +    theTime.UniversalTime();
    1.88 +    TInt64 randSeed(theTime.Int64());
    1.89 +    TInt random(Math::Rand(randSeed) % (1000 * 1000));
    1.90 +    User::After(random);
    1.91 +
    1.92 +    RTimer timer;
    1.93 +    timer.CreateLocal();
    1.94 +    TRequestStatus timerStatus = KRequestPending;
    1.95 +    TTimeIntervalMicroSeconds32 timeout(KTimeOut);
    1.96 +    timer.After(timerStatus, timeout);
    1.97 +
    1.98 +    TText ch;
    1.99 +    const TUint8 *bitmap = NULL;
   1.100 +    TSize bitmapsize;
   1.101 +    TOpenFontCharMetrics Metrics;    
   1.102 +    do
   1.103 +        {
   1.104 +        TInt hitcount = 0;
   1.105 +        for (ch = 'A'; ch <= 'z'; ch++)
   1.106 +            {
   1.107 +            if(iFont->GetCharacterData(iSessionHandle, (TInt)ch, Metrics,bitmap))
   1.108 +                {
   1.109 +                //RDebug::Print(_L("%c hit bitmap[0]=%x"),ch,bitmap[0]);
   1.110 +                TUint8 testbyte = bitmap[0];
   1.111 +                testbyte += testbyte;
   1.112 +                __ASSERT_ALWAYS((testbyte & 0x01) == 0, User::Panic(KTCacheDeletionProcess, KErrGeneral));
   1.113 +                hitcount++;
   1.114 +                }
   1.115 +            else 
   1.116 +                {
   1.117 +                //RDebug::Print(_L("%c missed"),ch);
   1.118 +                }
   1.119 +            }
   1.120 +        __ASSERT_ALWAYS(hitcount > 0, User::Panic(KTCacheDeletionProcess, KErrNotFound));
   1.121 +        }
   1.122 +    while (timerStatus == KRequestPending);
   1.123 +
   1.124 +    timer.Cancel();
   1.125 +    timer.Close();
   1.126 +    }
   1.127 +
   1.128 +void MainL()
   1.129 +    {
   1.130 +    RChunk gChunk;
   1.131 +    User::LeaveIfError(gChunk.Open(1));
   1.132 +    CleanupClosePushL(gChunk);
   1.133 +    
   1.134 +    TInt offset;
   1.135 +    User::LeaveIfError(User::GetTIntParameter(2,offset));
   1.136 +    TInt SessionHandle;
   1.137 +    User::LeaveIfError(User::GetTIntParameter(3,SessionHandle));
   1.138 +    
   1.139 +    CRunProc *test = new (ELeave) CRunProc;
   1.140 +    
   1.141 +    test->setFont(reinterpret_cast<CFont*>(offset + reinterpret_cast<TInt>(gChunk.Base())));
   1.142 +    test->setHandle(SessionHandle);
   1.143 +    CleanupStack::PushL(test);
   1.144 +
   1.145 +    RDebug::Print(_L("T_fontsessioncacheproc MainL()"));
   1.146 +    test->RunTestL();
   1.147 +    
   1.148 +    CleanupStack::PopAndDestroy(2);
   1.149 +    }
   1.150 +
   1.151 +// Cleanup stack harness
   1.152 +GLDEF_C TInt E32Main()
   1.153 +    {
   1.154 +    __UHEAP_MARK;
   1.155 +    CTrapCleanup* cleanupStack = CTrapCleanup::New();
   1.156 +    TRAPD(error, MainL());    
   1.157 +    __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error));
   1.158 +    delete cleanupStack;
   1.159 +    __UHEAP_MARKEND;
   1.160 +    return 0;
   1.161 +    }