graphicstest/uibench/src/trenderorientation.cpp
changeset 188 1b081cb0800b
child 136 62bb7c97884c
equal deleted inserted replaced
187:9f66f99ee56f 188:1b081cb0800b
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Nokia test code 
       
    20 */
       
    21 
       
    22 #include <w32std.h>
       
    23 
       
    24 #include <wspublishandsubscribedata.h>
       
    25 #include "trenderorientation.h"
       
    26 
       
    27 const TInt KPublishTimeout  = 1000000;  // 1 second in microseconds
       
    28 const TInt KNumIterations   = 20;
       
    29 
       
    30 // Values for the device orientation that we receive via P&S from the Theme Server
       
    31 // Must match those in renderorientationtracker.h, and, obviously, those used by the real theme server 
       
    32 const TUid  KThemeOrientationCategory   = {0x20022E82}; // == KHbPsHardwareCoarseOrientationCategoryUid 
       
    33 const TUint KThemeOrientationKey        = 0x4F726965; // == KHbPsHardwareCoarseOrientationKey 
       
    34 
       
    35 void CWindowStuff::ConstructL()
       
    36     {
       
    37     User::LeaveIfError(iWs.Connect());
       
    38     iWs.SetAutoFlush(ETrue);
       
    39     
       
    40     iWindowGroup = RWindowGroup(iWs);
       
    41     User::LeaveIfError(iWindowGroup.Construct(reinterpret_cast<TUint32>(&iWindowGroup)));
       
    42     
       
    43     iChildWindow = RWindow(iWs);
       
    44     User::LeaveIfError(iChildWindow.Construct(iWindowGroup, reinterpret_cast<TUint32>(&iChildWindow)));
       
    45     }
       
    46 
       
    47 CWindowStuff::~CWindowStuff()
       
    48     {
       
    49     Destroy();
       
    50     }
       
    51 
       
    52 void CWindowStuff::Destroy()
       
    53     {
       
    54     iChildWindow.Close();
       
    55     iWindowGroup.Close();
       
    56     iWs.Close();    
       
    57     }
       
    58 
       
    59 CTRenderOrientation::CTRenderOrientation()
       
    60     {
       
    61     // check that these two enums are aligned
       
    62     __ASSERT_COMPILE(EDisplayOrientationAuto == ENumWindowThings);
       
    63     
       
    64     SetTestStepName(KTRenderOrientation);
       
    65     }
       
    66 
       
    67 CTRenderOrientation::~CTRenderOrientation()
       
    68     {
       
    69     }
       
    70 
       
    71 TRenderOrientation CTRenderOrientation::GetRenderOrientationL()
       
    72     {    
       
    73     return GetOrientationL(iWsRenderOrientationProperty);    
       
    74     }
       
    75 
       
    76 TRenderOrientation CTRenderOrientation::GetThemeOrientationL()
       
    77     {    
       
    78     return GetOrientationL(iThemeOrientationProperty);    
       
    79     }
       
    80 
       
    81 TRenderOrientation CTRenderOrientation::GetOrientationL(RProperty& aProperty)
       
    82     {
       
    83     TInt orientation=EDisplayOrientationNormal;
       
    84     User::LeaveIfError(aProperty.Get(orientation));
       
    85     
       
    86     TESTL(orientation >= EDisplayOrientationNormal);
       
    87     TESTL(orientation < EDisplayOrientationAuto);    
       
    88     
       
    89     return static_cast<TRenderOrientation>(orientation);    
       
    90     }
       
    91 
       
    92 void CTRenderOrientation::TestOrientationChangeL(const TDesC& aStepName, TTestPhase aTestPhase)
       
    93     {
       
    94     SetTestStepID(aStepName);
       
    95     
       
    96     if(EThemeOrientationChange == aTestPhase)
       
    97         {               
       
    98         TESTL(EDisplayOrientationNormal == GetThemeOrientationL());
       
    99         iWindowStuff[EFirstWindowThing].Session().IndicateAppOrientation(EDisplayOrientationAuto);        
       
   100         }
       
   101     
       
   102     TInt renderOrientation = GetRenderOrientationL();
       
   103     
       
   104     // For consistancy, check that we are starting from the same orientation
       
   105     TESTL(EDisplayOrientationNormal == renderOrientation);    
       
   106     
       
   107     // Set-up the timer
       
   108     iProfiler->InitResults();
       
   109     iTimingsTaken = 0;    
       
   110     
       
   111     // repeat numerous times to get a decent average
       
   112     for(TInt iterations=0; iterations < KNumIterations; ++iterations)
       
   113         {
       
   114         renderOrientation = GetRenderOrientationL();
       
   115         // For consistancy, check that we are starting from the same orientation
       
   116         TESTL(EDisplayOrientationNormal == renderOrientation);           
       
   117         
       
   118         // loop through the orientations, ending up changing back to normal
       
   119         for(++renderOrientation; renderOrientation <= EDisplayOrientationAuto; ++renderOrientation)
       
   120             {
       
   121             // % can be slow, do it outside of the timing
       
   122             TRenderOrientation testOrientation = static_cast<TRenderOrientation>(renderOrientation%EDisplayOrientationAuto);
       
   123             
       
   124             iWsRenderOrientationProperty.Subscribe(iRenderOrientationStatus);            
       
   125             // start the timeout timer
       
   126             iTimeoutTimer.After(iTimeoutStatus, KPublishTimeout);
       
   127             // start the results timer
       
   128             iProfiler->StartTimer();
       
   129             
       
   130             switch(aTestPhase)
       
   131                 {
       
   132                 case EIndicatedOrientationChange:
       
   133                     // Do the indicated orientation Change
       
   134                     iWindowStuff[EFirstWindowThing].Session().IndicateAppOrientation(testOrientation);
       
   135                     break;
       
   136                     
       
   137                 case EWindowOrdinalChange:
       
   138                     // move the relevant window group to the front
       
   139                     // N.B. this will go wrong if the number of orientations and windows are not equal
       
   140                     iWindowStuff[testOrientation].WindowGroup().SetOrdinalPosition(0);
       
   141                     break;
       
   142                     
       
   143                 case EThemeOrientationChange:
       
   144                     // Needs the focus window to be in auto mode
       
   145                     iThemeOrientationProperty.Set(testOrientation);
       
   146                     break;
       
   147                     
       
   148                 default:
       
   149                     TESTL(EFalse);
       
   150                 }
       
   151         
       
   152             // Wait for the update to have been published ( or time out while waiting )
       
   153             User::WaitForRequest(iRenderOrientationStatus, iTimeoutStatus);
       
   154             
       
   155             iProfiler->MarkResultSetL();
       
   156             ++iTimingsTaken;
       
   157             
       
   158             if(KErrNone != iRenderOrientationStatus.Int())
       
   159                 {
       
   160                 // timed out
       
   161                 iWsRenderOrientationProperty.Cancel();                
       
   162                 TESTL(EFalse);
       
   163                 }
       
   164             else
       
   165                 {
       
   166                 // Check that it is actually the expected orientation
       
   167                 TESTL(GetRenderOrientationL() == testOrientation);
       
   168                 }
       
   169 
       
   170             if(KRequestPending == iTimeoutStatus.Int())
       
   171                 {
       
   172                 // as expected, so cancel the timeout timer
       
   173                 iTimeoutTimer.Cancel();
       
   174                 }
       
   175             else
       
   176                 {
       
   177                 // timed out
       
   178                 TESTL(EFalse);
       
   179                 }
       
   180             }
       
   181         }    
       
   182     
       
   183     // wrap it up    
       
   184     iProfiler->ResultsAnalysis(KTRenderOrientation,KErrNotFound,ENone,ENone,iTimingsTaken);
       
   185     }
       
   186 
       
   187 TVerdict CTRenderOrientation::doTestStepL()
       
   188     {     
       
   189     INFO_PRINTF1(_L("Testing: Indicated Orientation Change"));
       
   190     TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0xxx1"), EIndicatedOrientationChange);
       
   191     
       
   192     INFO_PRINTF1(_L("Testing: Window Ordinal Position Change"));
       
   193     TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0xxx2"), EWindowOrdinalChange);
       
   194     
       
   195     INFO_PRINTF1(_L("Testing: Theme Orientation Change"));
       
   196     TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0xxx3"), EThemeOrientationChange);
       
   197     
       
   198     return TestStepResult();    
       
   199     }
       
   200 
       
   201 _LIT(KThemeServerPropertyDefine, "twsthemeserverpropertydefine.exe");
       
   202 _LIT(KThemeServerPropertyDefineCmdDefine, "define");
       
   203 _LIT(KThemeServerPropertyDefineCmdDelete, "delete");   
       
   204    
       
   205 void CTRenderOrientation::ThemeServerProperty(const TDesC& aCmd)
       
   206     {
       
   207     /* This Process called with the argument KThemeServerPropertyDefineCmdDelete, deletes 
       
   208        the theme server RProperty. This is because an RProperty can only be defined and 
       
   209        deleted from within a process with the same UID3 as the RProperty catogory you are 
       
   210        trying to define/delete.*/
       
   211     RProcess themeServerPropertyDefine;
       
   212     TInt err = themeServerPropertyDefine.Create(KThemeServerPropertyDefine, aCmd);
       
   213     if (KErrNone != err)
       
   214         {
       
   215         _LIT(KLog, "themeServerPropertyDefine.Create() failed with error: %d");
       
   216         INFO_PRINTF2(KLog, err);
       
   217         TEST(EFalse);        
       
   218         }
       
   219     
       
   220     //wait for themeServerPropertyDefine process to terminate
       
   221     TRequestStatus themeServerPropertyDefineLogonStatus;
       
   222     themeServerPropertyDefine.Logon(themeServerPropertyDefineLogonStatus);
       
   223     themeServerPropertyDefine.Resume();
       
   224     User::WaitForRequest(themeServerPropertyDefineLogonStatus);
       
   225     if (themeServerPropertyDefineLogonStatus != KErrNone)
       
   226         {
       
   227         _LIT(KLog, "themeServerPropertyDefine.Logon() failed with error: %d");
       
   228         INFO_PRINTF2(KLog, themeServerPropertyDefineLogonStatus);
       
   229         TEST(EFalse);        
       
   230         }
       
   231     themeServerPropertyDefine.Close();    
       
   232     }
       
   233 
       
   234 TVerdict CTRenderOrientation::doTestStepPreambleL()
       
   235     {
       
   236     // Create in reverse order so that windowThing 0 is at the front
       
   237     for(TInt windowThing = ENumWindowThings - 1; windowThing >= 0 ; --windowThing)
       
   238         {
       
   239         iWindowStuff[windowThing].ConstructL();
       
   240         TRenderOrientation orientation = static_cast<TRenderOrientation>(windowThing%EDisplayOrientationAuto);
       
   241         iWindowStuff[windowThing].Session().IndicateAppOrientation(orientation);
       
   242         iWindowStuff[windowThing].WindowGroup().SetOrdinalPosition(0);
       
   243         }
       
   244     
       
   245     User::LeaveIfError(iWsRenderOrientationProperty.Attach(KRenderOrientationCategory, KRenderOrientationKey));
       
   246     
       
   247     ThemeServerProperty(KThemeServerPropertyDefineCmdDefine);
       
   248     User::LeaveIfError(iThemeOrientationProperty.Attach(KThemeOrientationCategory, KThemeOrientationKey));
       
   249     
       
   250     User::LeaveIfError(iTimeoutTimer.CreateLocal());
       
   251     
       
   252     return CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
       
   253     }
       
   254 
       
   255 TVerdict CTRenderOrientation::doTestStepPostambleL()
       
   256     {
       
   257     iTimeoutTimer.Close();
       
   258     
       
   259     iThemeOrientationProperty.Close();
       
   260     ThemeServerProperty(KThemeServerPropertyDefineCmdDelete);    
       
   261     iWsRenderOrientationProperty.Close();
       
   262     
       
   263     for(TInt windowThing = 0; windowThing < ENumWindowThings; ++windowThing)
       
   264         {
       
   265         iWindowStuff[windowThing].Destroy();
       
   266         }
       
   267     
       
   268     return CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL();
       
   269     }