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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Nokia test code
24 #include <wspublishandsubscribedata.h>
25 #include "trenderorientation.h"
27 const TInt KPublishTimeout = 1000000; // 1 second in microseconds
28 const TInt KNumIterations = 20;
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
35 void CTWindowSet::ConstructL()
37 User::LeaveIfError(iWs.Connect());
38 iWs.SetAutoFlush(ETrue);
40 iWindowGroup = RWindowGroup(iWs);
41 User::LeaveIfError(iWindowGroup.Construct(reinterpret_cast<TUint32>(&iWindowGroup)));
43 iChildWindow = RWindow(iWs);
44 User::LeaveIfError(iChildWindow.Construct(iWindowGroup, reinterpret_cast<TUint32>(&iChildWindow)));
47 CTWindowSet::~CTWindowSet()
52 void CTWindowSet::Destroy()
59 CTRenderOrientation::CTRenderOrientation()
61 // check that these two enums are aligned
62 __ASSERT_COMPILE(EDisplayOrientationAuto == ENumWindowSets);
64 SetTestStepName(KTRenderOrientation);
67 CTRenderOrientation::~CTRenderOrientation()
72 Gets the Render Orientation as published by window server
74 @return TRenderOrienation that was last publised by window server.
76 TRenderOrientation CTRenderOrientation::GetRenderOrientationL()
78 return GetOrientationL(iWsRenderOrientationProperty);
82 Gets the Theme Orientation as published by theme server
84 @return TRenderOrienation that was last publised by theme server.
86 TRenderOrientation CTRenderOrientation::GetThemeOrientationL()
88 return GetOrientationL(iThemeOrientationProperty);
92 Gets the orientation as published to the given RProperty
94 @return TRenderOrienation that was last publised to the given RProperty
96 TRenderOrientation CTRenderOrientation::GetOrientationL(RProperty& aProperty)
98 TInt orientation=EDisplayOrientationNormal;
99 User::LeaveIfError(aProperty.Get(orientation));
101 TESTL(orientation >= EDisplayOrientationNormal);
102 TESTL(orientation < EDisplayOrientationAuto);
104 return static_cast<TRenderOrientation>(orientation);
108 Tests each usable TRenderOrientation KNumIterations times for the given test phase / use case.
110 @param aStepName - the test step ID to use
111 @param aTestPhase - the internal test phase
113 void CTRenderOrientation::TestOrientationChangeL(const TDesC& aStepName, TTestPhase aTestPhase)
115 SetTestStepID(aStepName);
117 // more preamble to toggle between timing the wserv render orienation property
118 // and the theme server orientation property
119 RProperty *orientationProperty = NULL;
122 case EThemeOrientationChangeOnly:
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;
130 case EThemeOrientationChange:
132 TESTL(EDisplayOrientationNormal == GetThemeOrientationL());
133 iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(EDisplayOrientationAuto);
135 // deliberate drop-through
137 // we want to subscribe and wait for the render orientation published by WServ
138 orientationProperty = &iWsRenderOrientationProperty;
142 TInt renderOrientation = GetRenderOrientationL();
144 // For consistancy, check that we are starting from the same orientation
145 TESTL(EDisplayOrientationNormal == renderOrientation);
148 iProfiler->InitResults();
151 // repeat numerous times to get a decent average
152 for(TInt iterations=0; iterations < KNumIterations; ++iterations)
154 renderOrientation = GetRenderOrientationL();
155 // For consistancy, check that we are starting from the same orientation
156 TESTL(EDisplayOrientationNormal == renderOrientation);
158 // loop through the orientations, ending up changing back to normal
159 for(++renderOrientation; renderOrientation <= EDisplayOrientationAuto; ++renderOrientation)
161 // % can be slow, do it outside of the timing
162 TRenderOrientation testOrientation = static_cast<TRenderOrientation>(renderOrientation%EDisplayOrientationAuto);
164 orientationProperty->Subscribe(iOrientationStatus);
166 // start the timeout timer
167 iTimeoutTimer.After(iTimeoutStatus, KPublishTimeout);
168 // start the results timer
169 iProfiler->StartTimer();
173 case EIndicatedOrientationChange:
174 // Do the indicated orientation Change
175 iWindowSet[EFirstWindowSet].Session().IndicateAppOrientation(testOrientation);
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);
184 case EThemeOrientationChange:
185 // Needs the focus window to be in auto mode
186 // deliberate drop through
187 case EThemeOrientationChangeOnly:
188 iThemeOrientationProperty.Set(testOrientation);
195 // Wait for the update to have been published ( or time out while waiting )
196 User::WaitForRequest(iOrientationStatus, iTimeoutStatus);
198 iProfiler->MarkResultSetL();
201 if(KErrNone != iOrientationStatus.Int())
204 iWsRenderOrientationProperty.Cancel();
209 // Check that it is actually the expected orientation
210 if(EThemeOrientationChangeOnly == aTestPhase)
211 TESTL(GetThemeOrientationL() == testOrientation);
213 TESTL(GetRenderOrientationL() == testOrientation);
216 if(KRequestPending == iTimeoutStatus.Int())
218 // as expected, so cancel the timeout timer
219 iTimeoutTimer.Cancel();
230 iProfiler->ResultsAnalysis(KTRenderOrientation,KErrNotFound,ENone,ENone,iTimingsTaken);
233 TVerdict CTRenderOrientation::doTestStepL()
235 INFO_PRINTF1(_L("Testing: Indicated Orientation Change"));
236 TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0201"), EIndicatedOrientationChange);
238 INFO_PRINTF1(_L("Testing: Window Ordinal Position Change"));
239 TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0202"), EWindowOrdinalChange);
241 INFO_PRINTF1(_L("Testing: Theme Orientation Change"));
242 TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0203"), EThemeOrientationChange);
244 INFO_PRINTF1(_L("Testing: Theme Orientation Change Only"));
245 TestOrientationChangeL(_L("GRAPHICS-UI-BENCH-0204"), EThemeOrientationChangeOnly);
247 return TestStepResult();
250 _LIT(KThemeServerPropertyDefine, "twsthemeserverpropertydefine.exe");
251 _LIT(KThemeServerPropertyDefineCmdDefine, "define");
252 _LIT(KThemeServerPropertyDefineCmdDelete, "delete");
255 Uses a test executable to define or delete a test version of the theme server rotation RProperty
257 void CTRenderOrientation::ThemeServerProperty(const TDesC& aCmd)
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
265 RProcess themeServerPropertyDefine;
266 TInt err = themeServerPropertyDefine.Create(KThemeServerPropertyDefine, aCmd);
269 _LIT(KLog, "themeServerPropertyDefine.Create() failed with error: %d");
270 INFO_PRINTF2(KLog, err);
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)
281 _LIT(KLog, "themeServerPropertyDefine.Logon() failed with error: %d");
282 INFO_PRINTF2(KLog, themeServerPropertyDefineLogonStatus);
285 themeServerPropertyDefine.Close();
289 Initialise for the testing
291 TVerdict CTRenderOrientation::doTestStepPreambleL()
293 // Create in reverse order so that windowSet 0 is at the front/foreground
294 for(TInt windowSet = ENumWindowSets - 1; windowSet >= 0 ; --windowSet)
296 iWindowSet[windowSet].ConstructL();
297 TRenderOrientation orientation = static_cast<TRenderOrientation>(windowSet%EDisplayOrientationAuto);
298 iWindowSet[windowSet].Session().IndicateAppOrientation(orientation);
299 iWindowSet[windowSet].WindowGroup().SetOrdinalPosition(0);
302 User::LeaveIfError(iWsRenderOrientationProperty.Attach(KRenderOrientationCategory, KRenderOrientationKey));
304 ThemeServerProperty(KThemeServerPropertyDefineCmdDefine);
305 User::LeaveIfError(iThemeOrientationProperty.Attach(KThemeOrientationCategory, KThemeOrientationKey));
307 User::LeaveIfError(iTimeoutTimer.CreateLocal());
309 return CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
313 Tidy up after the testing
315 TVerdict CTRenderOrientation::doTestStepPostambleL()
317 iTimeoutTimer.Close();
319 iThemeOrientationProperty.Close();
320 ThemeServerProperty(KThemeServerPropertyDefineCmdDelete);
321 iWsRenderOrientationProperty.Close();
323 for(TInt windowThing = 0; windowThing < ENumWindowSets; ++windowThing)
325 iWindowSet[windowThing].Destroy();
328 return CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL();