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.
     1 /*
     2 * Copyright (c) 2006-2010 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  @file
    20  @test
    21  @internalComponent - Internal Symbian test code
    22 */
    23 
    24 #include "FNTSTORE.H"
    25 #include <e32math.h>
    26 
    27 _LIT(KOpenFont, "DejaVu Sans Condensed");
    28 
    29 #ifdef __WINSCW__
    30 //this is used for winscw breakpoints
    31 #define BR _asm( int 3);
    32 #endif
    33 
    34 const TInt KTimeOut = 1000 * 1000;
    35 
    36 
    37 _LIT(KTCacheDeletionProcess,"T_fontsessioncacheproc");
    38 
    39 /* it is expected that the main in this file will be called to test multiple 
    40 process cache searching which is in the shared heap.
    41 */
    42 
    43 class CRunProc: public CBase
    44     {
    45 public:
    46     void RunTestL();
    47     CRunProc();
    48     ~CRunProc();
    49     
    50     inline void setFont(CFont*);
    51     inline void setHandle(TInt);
    52 private:
    53     void CreateFontL();
    54 
    55 private:
    56     CBitmapFont* iFont;
    57     TInt iSessionHandle;
    58     };
    59 
    60 CRunProc::CRunProc()
    61     {
    62     
    63     }
    64 
    65 CRunProc::~CRunProc()
    66     {
    67     
    68     }
    69 
    70 inline void CRunProc::setFont(CFont* aFont)
    71     {
    72     iFont = static_cast<CBitmapFont*>(aFont);
    73     }
    74 
    75 inline void CRunProc::setHandle(TInt aSessionHandle)
    76     {
    77     iSessionHandle = aSessionHandle;
    78     }
    79 
    80 
    81 void CRunProc::RunTestL()
    82     {
    83     TTime theTime;
    84     theTime.UniversalTime();
    85     TInt64 randSeed(theTime.Int64());
    86     TInt random(Math::Rand(randSeed) % (1000 * 1000));
    87     User::After(random);
    88 
    89     RTimer timer;
    90     timer.CreateLocal();
    91     TRequestStatus timerStatus = KRequestPending;
    92     TTimeIntervalMicroSeconds32 timeout(KTimeOut);
    93     timer.After(timerStatus, timeout);
    94 
    95     TText ch;
    96     const TUint8 *bitmap = NULL;
    97     TSize bitmapsize;
    98     TOpenFontCharMetrics Metrics;    
    99     do
   100         {
   101         TInt hitcount = 0;
   102         for (ch = 'A'; ch <= 'z'; ch++)
   103             {
   104             if(iFont->GetCharacterData(iSessionHandle, (TInt)ch, Metrics,bitmap))
   105                 {
   106                 //RDebug::Print(_L("%c hit bitmap[0]=%x"),ch,bitmap[0]);
   107                 TUint8 testbyte = bitmap[0];
   108                 testbyte += testbyte;
   109                 __ASSERT_ALWAYS((testbyte & 0x01) == 0, User::Panic(KTCacheDeletionProcess, KErrGeneral));
   110                 hitcount++;
   111                 }
   112             else 
   113                 {
   114                 //RDebug::Print(_L("%c missed"),ch);
   115                 }
   116             }
   117         __ASSERT_ALWAYS(hitcount > 0, User::Panic(KTCacheDeletionProcess, KErrNotFound));
   118         }
   119     while (timerStatus == KRequestPending);
   120 
   121     timer.Cancel();
   122     timer.Close();
   123     }
   124 
   125 void MainL()
   126     {
   127     RChunk gChunk;
   128     User::LeaveIfError(gChunk.Open(1));
   129     CleanupClosePushL(gChunk);
   130     
   131     TInt offset;
   132     User::LeaveIfError(User::GetTIntParameter(2,offset));
   133     TInt SessionHandle;
   134     User::LeaveIfError(User::GetTIntParameter(3,SessionHandle));
   135     
   136     CRunProc *test = new (ELeave) CRunProc;
   137     
   138     test->setFont(reinterpret_cast<CFont*>(offset + reinterpret_cast<TInt>(gChunk.Base())));
   139     test->setHandle(SessionHandle);
   140     CleanupStack::PushL(test);
   141 
   142     RDebug::Print(_L("T_fontsessioncacheproc MainL()"));
   143     test->RunTestL();
   144     
   145     CleanupStack::PopAndDestroy(2);
   146     }
   147 
   148 // Cleanup stack harness
   149 GLDEF_C TInt E32Main()
   150     {
   151     __UHEAP_MARK;
   152     CTrapCleanup* cleanupStack = CTrapCleanup::New();
   153     TRAPD(error, MainL());    
   154     __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error));
   155     delete cleanupStack;
   156     __UHEAP_MARKEND;
   157     return 0;
   158     }