fontservices/fontstore/tfs/T_fontsessioncacheproc.cpp
branchRCL_3
changeset 1 e96e8a131979
child 3 5390220f13c1
equal deleted inserted replaced
0:1fb32624e06b 1:e96e8a131979
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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 the License "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 <e32base.h>
       
    25 #include <e32cons.h>
       
    26 #include <e32test.h>
       
    27 #include <e32std.h>
       
    28 #include <e32debug.h>
       
    29 #include "FNTSTORE.H"
       
    30 #include "FNTBODY.H"
       
    31 #include "FNTSTD.H"
       
    32 #include <fbs.h>
       
    33 #include <bitstd.h>
       
    34 #include <bitdev.h>
       
    35 #include <e32math.h>
       
    36 
       
    37 _LIT(KOpenFont, "DejaVu Sans Condensed");
       
    38 
       
    39 #ifdef __WINSCW__
       
    40 //this is used for winscw breakpoints
       
    41 #define BR _asm( int 3);
       
    42 #endif
       
    43 
       
    44 const TInt KTimeOut = 1000 * 1000;
       
    45 //make sure that the font is large enough to ensure that the session
       
    46 //cache is used.
       
    47 const TInt KTextHight = 220;
       
    48 
       
    49 /* it is expected that the main in this file will be called to test multiple 
       
    50 process output at the same time a process is being deleted (font and bitmap server
       
    51 disconnection.  There are  normally two instances of this process.  Two virtually
       
    52 identical processes are required to ensure that the session ID is the same.
       
    53 
       
    54 The first is with aThirdProcess set. This sets output to run in a loop until
       
    55 the timeout is completed.  These values  are input via program arguments.
       
    56 
       
    57 If aThirdProcess is false then only one font creation, draw text,
       
    58 font deletion cycle is completed. The test code will then repeatedly run
       
    59 this process with aThirdProcess set to false.
       
    60 */
       
    61 
       
    62 
       
    63 class TRunProc: public CBase
       
    64     {
       
    65 public:
       
    66     static TRunProc* NewL();
       
    67     void RunTestL();
       
    68     ~TRunProc();
       
    69 private:
       
    70     TRunProc(){};
       
    71     void ConstructL();
       
    72     void DrawText();
       
    73     void CreateFontL();
       
    74 
       
    75 private:
       
    76     RFbsSession* iFbs;
       
    77     CFbsBitGc* iGc;
       
    78     CFbsScreenDevice* iDev;
       
    79     CFbsFont   *iFbsFont;
       
    80     };
       
    81 
       
    82 TRunProc::~TRunProc()
       
    83     {
       
    84     delete iGc;
       
    85     delete iDev;
       
    86     iFbs->Disconnect();
       
    87     }
       
    88 
       
    89 void TRunProc::ConstructL()
       
    90     {
       
    91     TInt err = RFbsSession::Connect();
       
    92     User::LeaveIfError(err);
       
    93     iFbs = RFbsSession::GetSession();
       
    94     User::LeaveIfNull(iFbs);
       
    95     
       
    96     const TInt KDisplayMode = 3;
       
    97     TDisplayMode mode[KDisplayMode];
       
    98     mode[0] = EColor16MA;
       
    99     mode[1] = EColor16MU;
       
   100     mode[2] = EColor64K;
       
   101 
       
   102     TInt count;
       
   103     for (count = 0; count < KDisplayMode; count++)
       
   104         {
       
   105         TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count]));
       
   106         if (err != KErrNotSupported)
       
   107             {
       
   108             break;
       
   109             }
       
   110         }
       
   111 
       
   112     User::LeaveIfNull(iDev);
       
   113 
       
   114     if(err == KErrNone)
       
   115         {
       
   116         iDev->ChangeScreenDevice(NULL);
       
   117         iDev->SetAutoUpdate(ETrue);
       
   118         iDev->CreateContext(iGc);
       
   119         }
       
   120     User::LeaveIfNull(iGc);
       
   121     }
       
   122 
       
   123 TRunProc* TRunProc::NewL()
       
   124     {
       
   125     TRunProc *ptr = new (ELeave) TRunProc;
       
   126     CleanupStack::PushL(ptr);
       
   127     ptr->ConstructL();
       
   128     CleanupStack::Pop();
       
   129     return ptr;
       
   130     }
       
   131 
       
   132 void TRunProc::CreateFontL()
       
   133     {
       
   134     TOpenFontSpec openFontSpec;
       
   135     openFontSpec.SetName(KOpenFont);
       
   136     openFontSpec.SetHeight(KTextHight);
       
   137     openFontSpec.SetItalic(EFalse);
       
   138     openFontSpec.SetBold(EFalse);
       
   139 
       
   140     TTypeface Typeface;
       
   141     Typeface.iName = KOpenFont;
       
   142     TFontSpec fs;
       
   143     fs.iTypeface = Typeface;
       
   144 
       
   145     fs.iHeight = KTextHight;
       
   146     CFbsFont* font = NULL;
       
   147     TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs);
       
   148 
       
   149     User::LeaveIfNull(font);
       
   150 
       
   151     // Use the font
       
   152     iFbsFont = font;
       
   153     iGc->UseFont(font);
       
   154     iGc->Clear();
       
   155     }
       
   156 
       
   157 void TRunProc::RunTestL()
       
   158     {
       
   159     TTime theTime;
       
   160     theTime.UniversalTime();
       
   161     TInt64 randSeed(theTime.Int64());
       
   162     TInt random(Math::Rand(randSeed) % (1000 * 1000));
       
   163     User::After(random);
       
   164 
       
   165     RTimer timer;
       
   166     timer.CreateLocal();
       
   167     TRequestStatus timerStatus = KRequestPending;
       
   168     TTimeIntervalMicroSeconds32 timeout(KTimeOut);
       
   169     timer.After(timerStatus, timeout);
       
   170 
       
   171     CreateFontL();
       
   172     RDebug::Print(_L("DrawText()random=%d"), random);
       
   173     DrawText();
       
   174 
       
   175     TText ch;
       
   176     const TUint8 *bitmap;
       
   177     TSize bitmapsize;
       
   178     TOpenFontCharMetrics Metrics;
       
   179     do
       
   180         {
       
   181         for (ch = 'A'; ch <= 'Z'; ch++)
       
   182             {
       
   183             iFbsFont->GetCharacterData((TInt) ch, Metrics, bitmap,bitmapsize);
       
   184             }
       
   185         }
       
   186     while (timerStatus == KRequestPending);
       
   187 
       
   188     timer.Cancel();
       
   189     iGc->DiscardFont();
       
   190     timer.Close();
       
   191     }
       
   192     
       
   193 
       
   194 void TRunProc::DrawText()
       
   195     {
       
   196     TText ch[2];
       
   197     ch[1] = '\0';
       
   198     for (ch[0] = 'A';ch[0] <= 'Z';ch[0]++)
       
   199         {
       
   200         TBufC<2> buf(ch);
       
   201         iGc->DrawText(buf,TPoint(10,100));
       
   202         }
       
   203     for (ch[0] = 'a';ch[0] <= 'z';ch[0]++)
       
   204         {
       
   205         TBufC<2> buf(ch);
       
   206         iGc->DrawText(buf,TPoint(10,100));
       
   207         }
       
   208     }
       
   209     
       
   210   
       
   211 
       
   212 void MainL()
       
   213     {
       
   214     TRunProc* test = TRunProc::NewL();
       
   215     CleanupStack::PushL(test);
       
   216 
       
   217     RDebug::Print(_L("T_fontsessioncacheproc MainL()"));
       
   218     test->RunTestL();
       
   219 
       
   220     CleanupStack::PopAndDestroy();
       
   221     }
       
   222 
       
   223 // Cleanup stack harness
       
   224 GLDEF_C TInt E32Main()
       
   225     {
       
   226     __UHEAP_MARK;
       
   227     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   228     TRAPD(error, MainL());
       
   229     _LIT(KTCacheDeletionProcess,"T_fontsessioncacheproc");
       
   230     __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error));
       
   231     delete cleanupStack;
       
   232     __UHEAP_MARKEND;
       
   233     return 0;
       
   234     }