os/graphics/graphicstest/uibench/src/trenderorientation.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 CTWindowSet::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 CTWindowSet::~CTWindowSet()
    48     {
    49     Destroy();
    50     }
    51 
    52 void CTWindowSet::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 == ENumWindowSets);
    63     
    64     SetTestStepName(KTRenderOrientation);
    65     }
    66 
    67 CTRenderOrientation::~CTRenderOrientation()
    68     {
    69     }
    70 
    71 /**
    72 Gets the Render Orientation as published by window server
    73 
    74 @return TRenderOrienation that was last publised by window server.
    75  */
    76 TRenderOrientation CTRenderOrientation::GetRenderOrientationL()
    77     {    
    78     return GetOrientationL(iWsRenderOrientationProperty);    
    79     }
    80 
    81 /**
    82 Gets the Theme Orientation as published by theme server
    83 
    84 @return TRenderOrienation that was last publised by theme server.
    85  */
    86 TRenderOrientation CTRenderOrientation::GetThemeOrientationL()
    87     {    
    88     return GetOrientationL(iThemeOrientationProperty);    
    89     }
    90 
    91 /**
    92 Gets the orientation as published to the given RProperty
    93 
    94 @return TRenderOrienation that was last publised to the given RProperty
    95  */
    96 TRenderOrientation CTRenderOrientation::GetOrientationL(RProperty& aProperty)
    97     {
    98     TInt orientation=EDisplayOrientationNormal;
    99     User::LeaveIfError(aProperty.Get(orientation));
   100     
   101     TESTL(orientation >= EDisplayOrientationNormal);
   102     TESTL(orientation < EDisplayOrientationAuto);    
   103     
   104     return static_cast<TRenderOrientation>(orientation);    
   105     }
   106 
   107 /**
   108 Tests each usable TRenderOrientation KNumIterations times for the given test phase / use case.
   109 
   110 @param aStepName - the test step ID to use
   111 @param aTestPhase - the internal test phase 
   112  */
   113 void CTRenderOrientation::TestOrientationChangeL(const TDesC& aStepName, TTestPhase aTestPhase)
   114     {
   115     SetTestStepID(aStepName);
   116     
   117     // more preamble to toggle between timing the wserv render orienation property
   118     // and the theme server orientation property
   119     RProperty *orientationProperty = NULL;
   120     switch(aTestPhase)
   121         {          
   122         case EThemeOrientationChangeOnly:
   123             {
   124             // render orientation ignores theme orientation
   125             iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(EDisplayOrientationNormal);
   126             // we want to subscribe and wait for the theme orientation published by the theme server
   127             orientationProperty = &iThemeOrientationProperty;            
   128             break;
   129             }
   130         case EThemeOrientationChange:
   131             {
   132             TESTL(EDisplayOrientationNormal == GetThemeOrientationL());
   133             iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(EDisplayOrientationAuto);
   134             }
   135             // deliberate drop-through
   136         default:
   137             // we want to subscribe and wait for the render orientation published by WServ            
   138             orientationProperty = &iWsRenderOrientationProperty;            
   139             break;
   140         }    
   141     
   142     TInt renderOrientation = GetRenderOrientationL();
   143     
   144     // For consistancy, check that we are starting from the same orientation
   145     TESTL(EDisplayOrientationNormal == renderOrientation);    
   146     
   147     // Set-up the timer
   148     iProfiler->InitResults();
   149     iTimingsTaken = 0;    
   150     
   151     // repeat numerous times to get a decent average
   152     for(TInt iterations=0; iterations < KNumIterations; ++iterations)
   153         {
   154         renderOrientation = GetRenderOrientationL();
   155         // For consistancy, check that we are starting from the same orientation
   156         TESTL(EDisplayOrientationNormal == renderOrientation);           
   157         
   158         // loop through the orientations, ending up changing back to normal
   159         for(++renderOrientation; renderOrientation <= EDisplayOrientationAuto; ++renderOrientation)
   160             {
   161             // % can be slow, do it outside of the timing
   162             TRenderOrientation testOrientation = static_cast<TRenderOrientation>(renderOrientation%EDisplayOrientationAuto);
   163             
   164             orientationProperty->Subscribe(iOrientationStatus);
   165             
   166             // start the timeout timer
   167             iTimeoutTimer.After(iTimeoutStatus, KPublishTimeout);
   168             // start the results timer
   169             iProfiler->StartTimer();
   170                         
   171             switch(aTestPhase)
   172                 {
   173                 case EIndicatedOrientationChange:
   174                     // Do the indicated orientation Change
   175                     iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(testOrientation);
   176                     break;
   177                     
   178                 case EWindowOrdinalChange:
   179                     // move the relevant window group to the front
   180                     // N.B. this will go wrong if the number of orientations and windows are not equal
   181                     iWindowSet[testOrientation].WindowGroup().SetOrdinalPosition(0);
   182                     break;
   183                     
   184                 case EThemeOrientationChange:
   185                     // Needs the focus window to be in auto mode
   186                     // deliberate drop through
   187                 case EThemeOrientationChangeOnly:                                        
   188                     iThemeOrientationProperty.Set(testOrientation);
   189                     break;
   190                     
   191                 default:
   192                     TESTL(EFalse);
   193                 }
   194         
   195             // Wait for the update to have been published ( or time out while waiting )
   196             User::WaitForRequest(iOrientationStatus, iTimeoutStatus);
   197             
   198             iProfiler->MarkResultSetL();
   199             ++iTimingsTaken;
   200             
   201             if(KErrNone != iOrientationStatus.Int())
   202                 {
   203                 // timed out
   204                 iWsRenderOrientationProperty.Cancel();                
   205                 TESTL(EFalse);
   206                 }
   207             else
   208                 {
   209                 // Check that it is actually the expected orientation
   210                 if(EThemeOrientationChangeOnly == aTestPhase)
   211                     TESTL(GetThemeOrientationL() == testOrientation);
   212                 else
   213                     TESTL(GetRenderOrientationL() == testOrientation);                
   214                 }
   215 
   216             if(KRequestPending == iTimeoutStatus.Int())
   217                 {
   218                 // as expected, so cancel the timeout timer
   219                 iTimeoutTimer.Cancel();
   220                 }
   221             else
   222                 {
   223                 // timed out
   224                 TESTL(EFalse);
   225                 }
   226             }
   227         }    
   228     
   229     // wrap it up    
   230     iProfiler->ResultsAnalysis(KTRenderOrientation,KErrNotFound,ENone,ENone,iTimingsTaken);
   231     }
   232 
   233 TVerdict CTRenderOrientation::doTestStepL()
   234     {     
   235     INFO_PRINTF1(_L("Testing: Indicated Orientation Change"));
   236     TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0201"), EIndicatedOrientationChange);
   237     
   238     INFO_PRINTF1(_L("Testing: Window Ordinal Position Change"));
   239     TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0202"), EWindowOrdinalChange);
   240     
   241     INFO_PRINTF1(_L("Testing: Theme Orientation Change"));
   242     TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0203"), EThemeOrientationChange);
   243     
   244     INFO_PRINTF1(_L("Testing: Theme Orientation Change Only"));
   245     TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0204"), EThemeOrientationChangeOnly);    
   246     
   247     return TestStepResult();    
   248     }
   249 
   250 _LIT(KThemeServerPropertyDefine, "twsthemeserverpropertydefine.exe");
   251 _LIT(KThemeServerPropertyDefineCmdDefine, "define");
   252 _LIT(KThemeServerPropertyDefineCmdDelete, "delete");   
   253 
   254 /**
   255 Uses a test executable to define or delete a test version of the theme server rotation RProperty
   256  */
   257 void CTRenderOrientation::ThemeServerProperty(const TDesC& aCmd)
   258     {
   259     /* This Process called with the argument KThemeServerPropertyDefineCmdDefine defines the
   260        theme server RProperty, or with KThemeServerPropertyDefineCmdDelete, deletes 
   261        the theme server RProperty.
   262        This is because an RProperty with this catagory UID can only be defined and deleted
   263        from within a process with the same UID3 as the RProperty catogory you are trying to
   264        define/delete */
   265     RProcess themeServerPropertyDefine;
   266     TInt err = themeServerPropertyDefine.Create(KThemeServerPropertyDefine, aCmd);
   267     if (KErrNone != err)
   268         {
   269         _LIT(KLog, "themeServerPropertyDefine.Create() failed with error: %d");
   270         INFO_PRINTF2(KLog, err);
   271         TEST(EFalse);        
   272         }
   273     
   274     // wait for themeServerPropertyDefine process to terminate
   275     TRequestStatus themeServerPropertyDefineLogonStatus;
   276     themeServerPropertyDefine.Logon(themeServerPropertyDefineLogonStatus);
   277     themeServerPropertyDefine.Resume();
   278     User::WaitForRequest(themeServerPropertyDefineLogonStatus);
   279     if (themeServerPropertyDefineLogonStatus != KErrNone)
   280         {
   281         _LIT(KLog, "themeServerPropertyDefine.Logon() failed with error: %d");
   282         INFO_PRINTF2(KLog, themeServerPropertyDefineLogonStatus);
   283         TEST(EFalse);        
   284         }
   285     themeServerPropertyDefine.Close();    
   286     }
   287 
   288 /*
   289 Initialise for the testing
   290  */
   291 TVerdict CTRenderOrientation::doTestStepPreambleL()
   292     {
   293     // Create in reverse order so that windowSet 0 is at the front/foreground
   294     for(TInt windowSet = ENumWindowSets - 1; windowSet >= 0 ; --windowSet)
   295         {
   296         iWindowSet[windowSet].ConstructL();
   297         TRenderOrientation orientation = static_cast<TRenderOrientation>(windowSet%EDisplayOrientationAuto);
   298         iWindowSet[windowSet].Session().IndicateAppOrientation(orientation);
   299         iWindowSet[windowSet].WindowGroup().SetOrdinalPosition(0);
   300         }
   301     
   302     User::LeaveIfError(iWsRenderOrientationProperty.Attach(KRenderOrientationCategory, KRenderOrientationKey));
   303     
   304     ThemeServerProperty(KThemeServerPropertyDefineCmdDefine);
   305     User::LeaveIfError(iThemeOrientationProperty.Attach(KThemeOrientationCategory, KThemeOrientationKey));
   306     
   307     User::LeaveIfError(iTimeoutTimer.CreateLocal());
   308     
   309     return CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
   310     }
   311 
   312 /*
   313 Tidy up after the testing
   314  */
   315 TVerdict CTRenderOrientation::doTestStepPostambleL()
   316     {
   317     iTimeoutTimer.Close();
   318     
   319     iThemeOrientationProperty.Close();
   320     ThemeServerProperty(KThemeServerPropertyDefineCmdDelete);    
   321     iWsRenderOrientationProperty.Close();
   322     
   323     for(TInt windowThing = 0; windowThing < ENumWindowSets; ++windowThing)
   324         {
   325         iWindowSet[windowThing].Destroy();
   326         }
   327     
   328     return CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL();
   329     }