1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/src/trenderorientation.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,329 @@
1.4 +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Nokia test code
1.23 +*/
1.24 +
1.25 +#include <w32std.h>
1.26 +
1.27 +#include <wspublishandsubscribedata.h>
1.28 +#include "trenderorientation.h"
1.29 +
1.30 +const TInt KPublishTimeout = 1000000; // 1 second in microseconds
1.31 +const TInt KNumIterations = 20;
1.32 +
1.33 +// Values for the device orientation that we receive via P&S from the Theme Server
1.34 +// Must match those in renderorientationtracker.h, and, obviously, those used by the real theme server
1.35 +const TUid KThemeOrientationCategory = {0x20022E82}; // == KHbPsHardwareCoarseOrientationCategoryUid
1.36 +const TUint KThemeOrientationKey = 0x4F726965; // == KHbPsHardwareCoarseOrientationKey
1.37 +
1.38 +void CTWindowSet::ConstructL()
1.39 + {
1.40 + User::LeaveIfError(iWs.Connect());
1.41 + iWs.SetAutoFlush(ETrue);
1.42 +
1.43 + iWindowGroup = RWindowGroup(iWs);
1.44 + User::LeaveIfError(iWindowGroup.Construct(reinterpret_cast<TUint32>(&iWindowGroup)));
1.45 +
1.46 + iChildWindow = RWindow(iWs);
1.47 + User::LeaveIfError(iChildWindow.Construct(iWindowGroup, reinterpret_cast<TUint32>(&iChildWindow)));
1.48 + }
1.49 +
1.50 +CTWindowSet::~CTWindowSet()
1.51 + {
1.52 + Destroy();
1.53 + }
1.54 +
1.55 +void CTWindowSet::Destroy()
1.56 + {
1.57 + iChildWindow.Close();
1.58 + iWindowGroup.Close();
1.59 + iWs.Close();
1.60 + }
1.61 +
1.62 +CTRenderOrientation::CTRenderOrientation()
1.63 + {
1.64 + // check that these two enums are aligned
1.65 + __ASSERT_COMPILE(EDisplayOrientationAuto == ENumWindowSets);
1.66 +
1.67 + SetTestStepName(KTRenderOrientation);
1.68 + }
1.69 +
1.70 +CTRenderOrientation::~CTRenderOrientation()
1.71 + {
1.72 + }
1.73 +
1.74 +/**
1.75 +Gets the Render Orientation as published by window server
1.76 +
1.77 +@return TRenderOrienation that was last publised by window server.
1.78 + */
1.79 +TRenderOrientation CTRenderOrientation::GetRenderOrientationL()
1.80 + {
1.81 + return GetOrientationL(iWsRenderOrientationProperty);
1.82 + }
1.83 +
1.84 +/**
1.85 +Gets the Theme Orientation as published by theme server
1.86 +
1.87 +@return TRenderOrienation that was last publised by theme server.
1.88 + */
1.89 +TRenderOrientation CTRenderOrientation::GetThemeOrientationL()
1.90 + {
1.91 + return GetOrientationL(iThemeOrientationProperty);
1.92 + }
1.93 +
1.94 +/**
1.95 +Gets the orientation as published to the given RProperty
1.96 +
1.97 +@return TRenderOrienation that was last publised to the given RProperty
1.98 + */
1.99 +TRenderOrientation CTRenderOrientation::GetOrientationL(RProperty& aProperty)
1.100 + {
1.101 + TInt orientation=EDisplayOrientationNormal;
1.102 + User::LeaveIfError(aProperty.Get(orientation));
1.103 +
1.104 + TESTL(orientation >= EDisplayOrientationNormal);
1.105 + TESTL(orientation < EDisplayOrientationAuto);
1.106 +
1.107 + return static_cast<TRenderOrientation>(orientation);
1.108 + }
1.109 +
1.110 +/**
1.111 +Tests each usable TRenderOrientation KNumIterations times for the given test phase / use case.
1.112 +
1.113 +@param aStepName - the test step ID to use
1.114 +@param aTestPhase - the internal test phase
1.115 + */
1.116 +void CTRenderOrientation::TestOrientationChangeL(const TDesC& aStepName, TTestPhase aTestPhase)
1.117 + {
1.118 + SetTestStepID(aStepName);
1.119 +
1.120 + // more preamble to toggle between timing the wserv render orienation property
1.121 + // and the theme server orientation property
1.122 + RProperty *orientationProperty = NULL;
1.123 + switch(aTestPhase)
1.124 + {
1.125 + case EThemeOrientationChangeOnly:
1.126 + {
1.127 + // render orientation ignores theme orientation
1.128 + iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(EDisplayOrientationNormal);
1.129 + // we want to subscribe and wait for the theme orientation published by the theme server
1.130 + orientationProperty = &iThemeOrientationProperty;
1.131 + break;
1.132 + }
1.133 + case EThemeOrientationChange:
1.134 + {
1.135 + TESTL(EDisplayOrientationNormal == GetThemeOrientationL());
1.136 + iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(EDisplayOrientationAuto);
1.137 + }
1.138 + // deliberate drop-through
1.139 + default:
1.140 + // we want to subscribe and wait for the render orientation published by WServ
1.141 + orientationProperty = &iWsRenderOrientationProperty;
1.142 + break;
1.143 + }
1.144 +
1.145 + TInt renderOrientation = GetRenderOrientationL();
1.146 +
1.147 + // For consistancy, check that we are starting from the same orientation
1.148 + TESTL(EDisplayOrientationNormal == renderOrientation);
1.149 +
1.150 + // Set-up the timer
1.151 + iProfiler->InitResults();
1.152 + iTimingsTaken = 0;
1.153 +
1.154 + // repeat numerous times to get a decent average
1.155 + for(TInt iterations=0; iterations < KNumIterations; ++iterations)
1.156 + {
1.157 + renderOrientation = GetRenderOrientationL();
1.158 + // For consistancy, check that we are starting from the same orientation
1.159 + TESTL(EDisplayOrientationNormal == renderOrientation);
1.160 +
1.161 + // loop through the orientations, ending up changing back to normal
1.162 + for(++renderOrientation; renderOrientation <= EDisplayOrientationAuto; ++renderOrientation)
1.163 + {
1.164 + // % can be slow, do it outside of the timing
1.165 + TRenderOrientation testOrientation = static_cast<TRenderOrientation>(renderOrientation%EDisplayOrientationAuto);
1.166 +
1.167 + orientationProperty->Subscribe(iOrientationStatus);
1.168 +
1.169 + // start the timeout timer
1.170 + iTimeoutTimer.After(iTimeoutStatus, KPublishTimeout);
1.171 + // start the results timer
1.172 + iProfiler->StartTimer();
1.173 +
1.174 + switch(aTestPhase)
1.175 + {
1.176 + case EIndicatedOrientationChange:
1.177 + // Do the indicated orientation Change
1.178 + iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(testOrientation);
1.179 + break;
1.180 +
1.181 + case EWindowOrdinalChange:
1.182 + // move the relevant window group to the front
1.183 + // N.B. this will go wrong if the number of orientations and windows are not equal
1.184 + iWindowSet[testOrientation].WindowGroup().SetOrdinalPosition(0);
1.185 + break;
1.186 +
1.187 + case EThemeOrientationChange:
1.188 + // Needs the focus window to be in auto mode
1.189 + // deliberate drop through
1.190 + case EThemeOrientationChangeOnly:
1.191 + iThemeOrientationProperty.Set(testOrientation);
1.192 + break;
1.193 +
1.194 + default:
1.195 + TESTL(EFalse);
1.196 + }
1.197 +
1.198 + // Wait for the update to have been published ( or time out while waiting )
1.199 + User::WaitForRequest(iOrientationStatus, iTimeoutStatus);
1.200 +
1.201 + iProfiler->MarkResultSetL();
1.202 + ++iTimingsTaken;
1.203 +
1.204 + if(KErrNone != iOrientationStatus.Int())
1.205 + {
1.206 + // timed out
1.207 + iWsRenderOrientationProperty.Cancel();
1.208 + TESTL(EFalse);
1.209 + }
1.210 + else
1.211 + {
1.212 + // Check that it is actually the expected orientation
1.213 + if(EThemeOrientationChangeOnly == aTestPhase)
1.214 + TESTL(GetThemeOrientationL() == testOrientation);
1.215 + else
1.216 + TESTL(GetRenderOrientationL() == testOrientation);
1.217 + }
1.218 +
1.219 + if(KRequestPending == iTimeoutStatus.Int())
1.220 + {
1.221 + // as expected, so cancel the timeout timer
1.222 + iTimeoutTimer.Cancel();
1.223 + }
1.224 + else
1.225 + {
1.226 + // timed out
1.227 + TESTL(EFalse);
1.228 + }
1.229 + }
1.230 + }
1.231 +
1.232 + // wrap it up
1.233 + iProfiler->ResultsAnalysis(KTRenderOrientation,KErrNotFound,ENone,ENone,iTimingsTaken);
1.234 + }
1.235 +
1.236 +TVerdict CTRenderOrientation::doTestStepL()
1.237 + {
1.238 + INFO_PRINTF1(_L("Testing: Indicated Orientation Change"));
1.239 + TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0201"), EIndicatedOrientationChange);
1.240 +
1.241 + INFO_PRINTF1(_L("Testing: Window Ordinal Position Change"));
1.242 + TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0202"), EWindowOrdinalChange);
1.243 +
1.244 + INFO_PRINTF1(_L("Testing: Theme Orientation Change"));
1.245 + TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0203"), EThemeOrientationChange);
1.246 +
1.247 + INFO_PRINTF1(_L("Testing: Theme Orientation Change Only"));
1.248 + TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0204"), EThemeOrientationChangeOnly);
1.249 +
1.250 + return TestStepResult();
1.251 + }
1.252 +
1.253 +_LIT(KThemeServerPropertyDefine, "twsthemeserverpropertydefine.exe");
1.254 +_LIT(KThemeServerPropertyDefineCmdDefine, "define");
1.255 +_LIT(KThemeServerPropertyDefineCmdDelete, "delete");
1.256 +
1.257 +/**
1.258 +Uses a test executable to define or delete a test version of the theme server rotation RProperty
1.259 + */
1.260 +void CTRenderOrientation::ThemeServerProperty(const TDesC& aCmd)
1.261 + {
1.262 + /* This Process called with the argument KThemeServerPropertyDefineCmdDefine defines the
1.263 + theme server RProperty, or with KThemeServerPropertyDefineCmdDelete, deletes
1.264 + the theme server RProperty.
1.265 + This is because an RProperty with this catagory UID can only be defined and deleted
1.266 + from within a process with the same UID3 as the RProperty catogory you are trying to
1.267 + define/delete */
1.268 + RProcess themeServerPropertyDefine;
1.269 + TInt err = themeServerPropertyDefine.Create(KThemeServerPropertyDefine, aCmd);
1.270 + if (KErrNone != err)
1.271 + {
1.272 + _LIT(KLog, "themeServerPropertyDefine.Create() failed with error: %d");
1.273 + INFO_PRINTF2(KLog, err);
1.274 + TEST(EFalse);
1.275 + }
1.276 +
1.277 + // wait for themeServerPropertyDefine process to terminate
1.278 + TRequestStatus themeServerPropertyDefineLogonStatus;
1.279 + themeServerPropertyDefine.Logon(themeServerPropertyDefineLogonStatus);
1.280 + themeServerPropertyDefine.Resume();
1.281 + User::WaitForRequest(themeServerPropertyDefineLogonStatus);
1.282 + if (themeServerPropertyDefineLogonStatus != KErrNone)
1.283 + {
1.284 + _LIT(KLog, "themeServerPropertyDefine.Logon() failed with error: %d");
1.285 + INFO_PRINTF2(KLog, themeServerPropertyDefineLogonStatus);
1.286 + TEST(EFalse);
1.287 + }
1.288 + themeServerPropertyDefine.Close();
1.289 + }
1.290 +
1.291 +/*
1.292 +Initialise for the testing
1.293 + */
1.294 +TVerdict CTRenderOrientation::doTestStepPreambleL()
1.295 + {
1.296 + // Create in reverse order so that windowSet 0 is at the front/foreground
1.297 + for(TInt windowSet = ENumWindowSets - 1; windowSet >= 0 ; --windowSet)
1.298 + {
1.299 + iWindowSet[windowSet].ConstructL();
1.300 + TRenderOrientation orientation = static_cast<TRenderOrientation>(windowSet%EDisplayOrientationAuto);
1.301 + iWindowSet[windowSet].Session().IndicateAppOrientation(orientation);
1.302 + iWindowSet[windowSet].WindowGroup().SetOrdinalPosition(0);
1.303 + }
1.304 +
1.305 + User::LeaveIfError(iWsRenderOrientationProperty.Attach(KRenderOrientationCategory, KRenderOrientationKey));
1.306 +
1.307 + ThemeServerProperty(KThemeServerPropertyDefineCmdDefine);
1.308 + User::LeaveIfError(iThemeOrientationProperty.Attach(KThemeOrientationCategory, KThemeOrientationKey));
1.309 +
1.310 + User::LeaveIfError(iTimeoutTimer.CreateLocal());
1.311 +
1.312 + return CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
1.313 + }
1.314 +
1.315 +/*
1.316 +Tidy up after the testing
1.317 + */
1.318 +TVerdict CTRenderOrientation::doTestStepPostambleL()
1.319 + {
1.320 + iTimeoutTimer.Close();
1.321 +
1.322 + iThemeOrientationProperty.Close();
1.323 + ThemeServerProperty(KThemeServerPropertyDefineCmdDelete);
1.324 + iWsRenderOrientationProperty.Close();
1.325 +
1.326 + for(TInt windowThing = 0; windowThing < ENumWindowSets; ++windowThing)
1.327 + {
1.328 + iWindowSet[windowThing].Destroy();
1.329 + }
1.330 +
1.331 + return CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL();
1.332 + }