os/textandloc/fontservices/fontstore/tfs/T_fontsessioncacheproc.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @test
sl@0
    21
 @internalComponent - Internal Symbian test code
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "FNTSTORE.H"
sl@0
    25
#include <e32math.h>
sl@0
    26
sl@0
    27
_LIT(KOpenFont, "DejaVu Sans Condensed");
sl@0
    28
sl@0
    29
#ifdef __WINSCW__
sl@0
    30
//this is used for winscw breakpoints
sl@0
    31
#define BR _asm( int 3);
sl@0
    32
#endif
sl@0
    33
sl@0
    34
const TInt KTimeOut = 1000 * 1000;
sl@0
    35
sl@0
    36
sl@0
    37
_LIT(KTCacheDeletionProcess,"T_fontsessioncacheproc");
sl@0
    38
sl@0
    39
/* it is expected that the main in this file will be called to test multiple 
sl@0
    40
process cache searching which is in the shared heap.
sl@0
    41
*/
sl@0
    42
sl@0
    43
class CRunProc: public CBase
sl@0
    44
    {
sl@0
    45
public:
sl@0
    46
    void RunTestL();
sl@0
    47
    CRunProc();
sl@0
    48
    ~CRunProc();
sl@0
    49
    
sl@0
    50
    inline void setFont(CFont*);
sl@0
    51
    inline void setHandle(TInt);
sl@0
    52
private:
sl@0
    53
    void CreateFontL();
sl@0
    54
sl@0
    55
private:
sl@0
    56
    CBitmapFont* iFont;
sl@0
    57
    TInt iSessionHandle;
sl@0
    58
    };
sl@0
    59
sl@0
    60
CRunProc::CRunProc()
sl@0
    61
    {
sl@0
    62
    
sl@0
    63
    }
sl@0
    64
sl@0
    65
CRunProc::~CRunProc()
sl@0
    66
    {
sl@0
    67
    
sl@0
    68
    }
sl@0
    69
sl@0
    70
inline void CRunProc::setFont(CFont* aFont)
sl@0
    71
    {
sl@0
    72
    iFont = static_cast<CBitmapFont*>(aFont);
sl@0
    73
    }
sl@0
    74
sl@0
    75
inline void CRunProc::setHandle(TInt aSessionHandle)
sl@0
    76
    {
sl@0
    77
    iSessionHandle = aSessionHandle;
sl@0
    78
    }
sl@0
    79
sl@0
    80
sl@0
    81
void CRunProc::RunTestL()
sl@0
    82
    {
sl@0
    83
    TTime theTime;
sl@0
    84
    theTime.UniversalTime();
sl@0
    85
    TInt64 randSeed(theTime.Int64());
sl@0
    86
    TInt random(Math::Rand(randSeed) % (1000 * 1000));
sl@0
    87
    User::After(random);
sl@0
    88
sl@0
    89
    RTimer timer;
sl@0
    90
    timer.CreateLocal();
sl@0
    91
    TRequestStatus timerStatus = KRequestPending;
sl@0
    92
    TTimeIntervalMicroSeconds32 timeout(KTimeOut);
sl@0
    93
    timer.After(timerStatus, timeout);
sl@0
    94
sl@0
    95
    TText ch;
sl@0
    96
    const TUint8 *bitmap = NULL;
sl@0
    97
    TSize bitmapsize;
sl@0
    98
    TOpenFontCharMetrics Metrics;    
sl@0
    99
    do
sl@0
   100
        {
sl@0
   101
        TInt hitcount = 0;
sl@0
   102
        for (ch = 'A'; ch <= 'z'; ch++)
sl@0
   103
            {
sl@0
   104
            if(iFont->GetCharacterData(iSessionHandle, (TInt)ch, Metrics,bitmap))
sl@0
   105
                {
sl@0
   106
                //RDebug::Print(_L("%c hit bitmap[0]=%x"),ch,bitmap[0]);
sl@0
   107
                TUint8 testbyte = bitmap[0];
sl@0
   108
                testbyte += testbyte;
sl@0
   109
                __ASSERT_ALWAYS((testbyte & 0x01) == 0, User::Panic(KTCacheDeletionProcess, KErrGeneral));
sl@0
   110
                hitcount++;
sl@0
   111
                }
sl@0
   112
            else 
sl@0
   113
                {
sl@0
   114
                //RDebug::Print(_L("%c missed"),ch);
sl@0
   115
                }
sl@0
   116
            }
sl@0
   117
        __ASSERT_ALWAYS(hitcount > 0, User::Panic(KTCacheDeletionProcess, KErrNotFound));
sl@0
   118
        }
sl@0
   119
    while (timerStatus == KRequestPending);
sl@0
   120
sl@0
   121
    timer.Cancel();
sl@0
   122
    timer.Close();
sl@0
   123
    }
sl@0
   124
sl@0
   125
void MainL()
sl@0
   126
    {
sl@0
   127
    RChunk gChunk;
sl@0
   128
    User::LeaveIfError(gChunk.Open(1));
sl@0
   129
    CleanupClosePushL(gChunk);
sl@0
   130
    
sl@0
   131
    TInt offset;
sl@0
   132
    User::LeaveIfError(User::GetTIntParameter(2,offset));
sl@0
   133
    TInt SessionHandle;
sl@0
   134
    User::LeaveIfError(User::GetTIntParameter(3,SessionHandle));
sl@0
   135
    
sl@0
   136
    CRunProc *test = new (ELeave) CRunProc;
sl@0
   137
    
sl@0
   138
    test->setFont(reinterpret_cast<CFont*>(offset + reinterpret_cast<TInt>(gChunk.Base())));
sl@0
   139
    test->setHandle(SessionHandle);
sl@0
   140
    CleanupStack::PushL(test);
sl@0
   141
sl@0
   142
    RDebug::Print(_L("T_fontsessioncacheproc MainL()"));
sl@0
   143
    test->RunTestL();
sl@0
   144
    
sl@0
   145
    CleanupStack::PopAndDestroy(2);
sl@0
   146
    }
sl@0
   147
sl@0
   148
// Cleanup stack harness
sl@0
   149
GLDEF_C TInt E32Main()
sl@0
   150
    {
sl@0
   151
    __UHEAP_MARK;
sl@0
   152
    CTrapCleanup* cleanupStack = CTrapCleanup::New();
sl@0
   153
    TRAPD(error, MainL());    
sl@0
   154
    __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error));
sl@0
   155
    delete cleanupStack;
sl@0
   156
    __UHEAP_MARKEND;
sl@0
   157
    return 0;
sl@0
   158
    }