os/textandloc/fontservices/fontstore/tfs/T_fontsessioncache.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 "t_fontsessioncache.h"
    26 #include "T_IsolatedFontStore.h"
    27 
    28 _LIT(KWorkerProcess,"tfontsessioncacheproc");
    29 _LIT(KSharedChunk,"TestSharedChunk_T_FontSessionCache");
    30 
    31 const TInt KNumOfProc = 4;
    32 const TInt KRunningTime = 1000 * 1000 * 5;
    33 
    34 //Make sure font is large enough that font and session caches are used sufficiently. 
    35 const TInt KFontHeight = 250;   
    36 
    37 // This class is a data mirror to CBitmapFont in order to check its private 
    38 // member iOpenFont. It is only used by TestOpenFontForQtL().
    39 class CBitmapFontDummy:public CFont
    40     {
    41 public:
    42     TFontSpec iFontSpecInTwips;
    43     TAlgStyle iAlgStyle;        
    44     RHeap* iHeap;
    45     TInt iFontBitmapOffset;
    46     COpenFont* iOpenFont; 
    47     TUint32 iReserved;
    48     TUint32 iUniqueFontId;     
    49     };
    50 
    51 class CTFontSessionCache : public CTGraphicsBase
    52     {
    53 public:
    54     CTFontSessionCache(CTestStep* aStep);
    55     ~CTFontSessionCache();
    56     TInt Base();
    57 
    58 protected:
    59 // From CTGraphicsStep
    60     virtual void RunTestCaseL(TInt aCurTestCase);
    61     virtual void ConstructL();
    62 private:
    63     void TestOpenFontForQtL();
    64     void RunMultiWorkerProcessL();
    65     
    66     void FlushCaches();
    67     
    68 private:
    69     CTIsolatedFontStore *iIFontStore;
    70     RHeap   *iSharedHeap;
    71     RChunk  iChunk;
    72     CFont *iFont;
    73     };
    74 
    75 CTFontSessionCache::CTFontSessionCache(CTestStep* aStep)
    76  :  CTGraphicsBase(aStep)
    77     {
    78 
    79     }
    80 
    81 CTFontSessionCache::~CTFontSessionCache()
    82     {
    83     iIFontStore->iFs->ReleaseFont(iFont);
    84     delete iIFontStore;
    85     iChunk.Close(); 
    86     }
    87 
    88 inline TInt CTFontSessionCache::Base() 
    89     {
    90     return reinterpret_cast<TInt>(iChunk.Base());
    91     }
    92 
    93 void CTFontSessionCache::ConstructL()
    94     {
    95     User::LeaveIfError(iChunk.CreateGlobal(KNullDesC,0x10000,0x10000));
    96     iSharedHeap = UserHeap::ChunkHeap(iChunk,0x10000,0x1000,0x10000,0,EFalse,0);
    97     if(iSharedHeap == NULL)
    98         {
    99         RDebug::Print(_L("iSharedHeap = NULL"));
   100         User::Leave(KErrNoMemory);
   101         }
   102     iIFontStore = CTIsolatedFontStore::NewL(iSharedHeap);
   103     iIFontStore->LoadRasterizersL();
   104     iIFontStore->iFs->LoadFontsAtStartupL();
   105     
   106     _LIT(KTypefaceName, "DejaVu Sans Condensed");
   107     TFontSpec spec(KTypefaceName, KFontHeight);   
   108     
   109     TInt ret = iIFontStore->iFs->GetNearestFontToDesignHeightInPixels(iFont,spec);
   110     TEST(ret == KErrNone);
   111  
   112     }
   113 
   114 void CTFontSessionCache::FlushCaches()
   115     {
   116     TText ch;
   117     TOpenFontGlyphData *glyphData = NULL;
   118     for (TInt sHandle = 0; sHandle < KNumOfProc; sHandle++)
   119         {
   120         for (ch = 'A'; ch <= 'z'; ch++)
   121             {
   122             static_cast<CBitmapFont*> (iFont)->Rasterize(sHandle, ch, glyphData);
   123             }
   124         }
   125     }
   126 
   127 /**
   128     @SYMTestCaseID
   129     TI18N-FNTSTORE-UT--4003
   130 
   131     @SYMTestCaseDesc
   132     Qt needs the last bit of iOpenFont to be set 1 as a workaround to maintain
   133     its compatibility across difference Symbian OS versions.
   134 
   135     @SYMTestActions
   136     1. Get a CBitmapFont in the constructor
   137     2. Check the LSB of its iOpenFont by using CBitmapFontDummy
   138         
   139     @SYMTestExpectedResults
   140     Test should pass
   141 */
   142 
   143 void CTFontSessionCache::TestOpenFontForQtL()
   144     {    
   145     TEST(reinterpret_cast<TInt>(reinterpret_cast<CBitmapFontDummy*>(iFont)->iOpenFont) & 1);
   146     }
   147 
   148 /**
   149     @SYMTestCaseID
   150     TI18N-FNTSTORE-CIT-4002
   151 
   152     @SYMTestCaseDesc
   153     This case is to test the safty of actions over the shared heap.
   154 
   155     @SYMTestActions
   156     1. Shared heap is initialised in the constructor
   157     2. Run rasterizing function to Flush the font caches(glyph tree and session cache).
   158     3. Launch KNumOfProc worker processes running with random latency at beginning, which
   159        is to seach the cache from different processes. The globle chunk and font handles are
   160        passed via process environment variables.
   161     4. Each one lasts about 1 sec. Within duration of 5 sec, if one terminates, re-launch it.   
   162         
   163     @SYMTestExpectedResults
   164     Test should pass without any Panic.
   165 */
   166 void CTFontSessionCache::RunMultiWorkerProcessL()
   167     {
   168     RProcess ProcArray[KNumOfProc];
   169     TRequestStatus *completeStatus[KNumOfProc];
   170 
   171     FlushCaches();
   172     
   173     for (TInt i = 0; i < KNumOfProc; i++)
   174         {                    
   175         RDebug::Print(_L(">>> Launching %d..."),i);
   176         TInt err;
   177         err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
   178         User::LeaveIfError(err);
   179 
   180         TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
   181         ProcArray[i].SetParameter(1,iChunk);        
   182         ProcArray[i].SetParameter(2,FontOffset);
   183         ProcArray[i].SetParameter(3,i);
   184         
   185         completeStatus[i] = new(ELeave) TRequestStatus; 
   186         CleanupStack::PushL(completeStatus[i]);
   187         *completeStatus[i] = KRequestPending;
   188         
   189         ProcArray[i].Logon(*completeStatus[i]);
   190         ProcArray[i].Resume(); //start the process
   191         }
   192       
   193     RTimer timer;
   194     timer.CreateLocal();
   195     TRequestStatus timerStatus = KRequestPending;
   196     TTimeIntervalMicroSeconds32 timeout(KRunningTime);
   197     timer.After(timerStatus, timeout);
   198     
   199     do
   200         {     
   201         User::WaitForNRequest(completeStatus, KNumOfProc);
   202         TInt i = 0;
   203         for(;i < KNumOfProc;i++ )
   204             {
   205                 if (*completeStatus[i] != KRequestPending)
   206                 {
   207                 break;
   208                 }
   209             }
   210 
   211         TExitType exit = ProcArray[i].ExitType();
   212         TEST(exit == EExitKill);
   213         TInt reason = ProcArray[i].ExitReason();
   214         TEST (reason == 0);
   215 
   216         RDebug::Print(_L("<<< Close %d..."), i);
   217         ProcArray[i].Close();
   218 
   219         RDebug::Print(_L(">>> Launching %d..."), i);
   220         TInt err;
   221         err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
   222         User::LeaveIfError(err);
   223         
   224         TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
   225         ProcArray[i].SetParameter(1,iChunk);        
   226         ProcArray[i].SetParameter(2,FontOffset);
   227         ProcArray[i].SetParameter(3,i);
   228         
   229         //run process 1
   230         *completeStatus[i] = KRequestPending;
   231         ProcArray[i].Logon(*completeStatus[i]);
   232         ProcArray[i].Resume(); //start the process
   233         }
   234     while (timerStatus == KRequestPending);
   235     
   236     for (TInt i = 0; i < KNumOfProc; i++)
   237         {
   238         if(*completeStatus[i] == KRequestPending)
   239             {
   240             User::WaitForRequest(*completeStatus[i]);
   241             }       
   242         RDebug::Print(_L("<<< Tear down Close %d..."),i);
   243         ProcArray[i].Close(); //tear down
   244         }        
   245     CleanupStack::PopAndDestroy(KNumOfProc);
   246     }
   247 
   248 void CTFontSessionCache::RunTestCaseL( TInt aCurTestCase )
   249     {
   250     ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   251 
   252     switch (aCurTestCase)
   253         {
   254         case 1:
   255             ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-UT--4003"));
   256             INFO_PRINTF1(_L("Test CBitmapFont::iOpenFont last bit for Qt\n"));
   257             TestOpenFontForQtL();
   258             break;
   259 
   260         case 2:
   261             ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-CIT-4002"));
   262             INFO_PRINTF1(_L("Test GetCharacterData() in muti-process client\n"));
   263             RunMultiWorkerProcessL();
   264             break;
   265             
   266         case 3:
   267             ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   268             ((CTFontSessionCacheStep*) iStep)->CloseTMSGraphicsStep();
   269             TestComplete();
   270             break;
   271         }
   272     ((CTFontSessionCacheStep*)iStep)->RecordTestResultL();
   273     }
   274 
   275 // --------------
   276 __CONSTRUCT_STEP__(FontSessionCache)