sl@0: // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "tpan.h" sl@0: #include "te_gesturegenerator.h" sl@0: #include "twindow.h" sl@0: sl@0: sl@0: _LIT(KSemaphore, "SemTPanSync"); // Name of the global semaphore sl@0: sl@0: const TInt KGestureGenerationLimit = 50; sl@0: sl@0: // Test bitmap file location sl@0: _LIT(KBigBitmap,"z:\\resource\\apps\\uibench_s60_big.mbm"); sl@0: _LIT(KTestStep0001,"GRAPHICS-UI-BENCH-S60-0001"); sl@0: sl@0: CTPan::CTPan() sl@0: { sl@0: SetTestStepName(KTPan); sl@0: } sl@0: sl@0: TVerdict CTPan::doTestStepPreambleL() sl@0: { sl@0: // The semaphore has to be created before, otherwise the control can't open it. sl@0: TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0)); sl@0: return CTe_ConeStepBase::doTestStepPreambleL(); sl@0: } sl@0: sl@0: TVerdict CTPan::doTestStepPostambleL() sl@0: { sl@0: iSemaphore.Close(); sl@0: return CTe_ConeStepBase::doTestStepPostambleL(); sl@0: } sl@0: sl@0: /** sl@0: Override of base class pure virtual sl@0: Our implementation only gets called if the base class doTestStepPreambleL() did sl@0: not leave. sl@0: sl@0: @return - TVerdict code sl@0: */ sl@0: TVerdict CTPan::doTestStepL() sl@0: { sl@0: SetTestStepID(KTestStep0001); sl@0: PanBitmapL(); sl@0: //RecordTestResultL(); // not possible because of heap panic sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-UI-BENCH-S60-0001 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests how long it takes to pan a bitmap in reaction to pointer events. sl@0: sl@0: @SYMTestActions sl@0: Create the bitmap and generate the pointer events. Depending on the location of the sl@0: pointer the bitmap is drawn to the screen. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass and display the average framerate for the whole test. sl@0: */ sl@0: void CTPan::PanBitmapL() sl@0: { sl@0: iProfiler->InitResults(); sl@0: sl@0: // Simulate some horizontal drag pointer events sl@0: GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(0, 0), sl@0: TPoint(KGestureGenerationLimit, 0)); sl@0: // Simulate some vertical drag pointer events sl@0: GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(KGestureGenerationLimit, 0), sl@0: TPoint(KGestureGenerationLimit, KGestureGenerationLimit)); sl@0: sl@0: iProfiler->MarkResultSetL(); sl@0: TSize screenSize = CTWindow::GetDisplaySizeInPixels(); sl@0: iProfiler->ResultsAnalysisFrameRate(KTestStep0001, 0, 0, 0, sl@0: iAppUi->PanControl()->Iterations(), screenSize.iWidth * screenSize.iHeight); sl@0: } sl@0: sl@0: void CTPan::InitUIL(CCoeEnv* aCoeEnv) sl@0: { sl@0: iAppUi = new(ELeave) CPanAppUi(); sl@0: // iAppUi needs to be put on the cleanupstack until CCoeEnv takes ownership of iAppUi sl@0: CleanupStack::PushL(iAppUi); sl@0: iAppUi->ConstructL(TRect(CTWindow::GetDisplaySizeInPixels())); sl@0: CleanupStack::Pop(iAppUi); sl@0: aCoeEnv->SetAppUi(iAppUi); sl@0: } sl@0: sl@0: //============================================================================= sl@0: sl@0: CPanAppUi::CPanAppUi() sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: CPanAppUi::~CPanAppUi() sl@0: { sl@0: RemoveFromStack(iPanControl); sl@0: delete iPanControl; sl@0: } sl@0: sl@0: void CPanAppUi::ConstructL(const TRect& aRect) sl@0: { sl@0: BaseConstructL(ENoAppResourceFile); sl@0: iPanControl = CPanControl::NewL(aRect); sl@0: AddToStackL(iPanControl); sl@0: } sl@0: sl@0: CPanControl* CPanAppUi::PanControl() sl@0: { sl@0: return iPanControl; sl@0: } sl@0: sl@0: //============================================================================= sl@0: sl@0: CPanControl* CPanControl::NewL(const TRect& aRect, const CCoeControl* aParent) sl@0: { sl@0: CPanControl* self = CPanControl::NewLC(aRect, aParent); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CPanControl* CPanControl::NewLC(const TRect& aRect, const CCoeControl* aParent) sl@0: { sl@0: CPanControl* self = new(ELeave) CPanControl(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aRect, aParent); sl@0: return self; sl@0: } sl@0: sl@0: CPanControl::CPanControl() : iWsSession(CCoeEnv::Static()->WsSession()) sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: CPanControl::~CPanControl() sl@0: { sl@0: delete iSourceBitmap; sl@0: iSemaphore.Close(); sl@0: } sl@0: sl@0: void CPanControl::ConstructL(const TRect& aRect, const CCoeControl* aParent) sl@0: { sl@0: User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore)); sl@0: iSourceBitmap = new(ELeave) CFbsBitmap; sl@0: User::LeaveIfError(iSourceBitmap->Load(KBigBitmap, 0)); sl@0: sl@0: // No owner, so create an own window sl@0: if(!aParent) sl@0: { sl@0: CreateWindowL(); sl@0: DrawableWindow()->PointerFilter(EPointerFilterDrag, 0); sl@0: SetRect(aRect); sl@0: ActivateL(); sl@0: } sl@0: else sl@0: { sl@0: // use parent window as compound control sl@0: SetContainerWindowL(*aParent); sl@0: SetRect(aRect); sl@0: } sl@0: } sl@0: sl@0: void CPanControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) sl@0: { sl@0: if((aPointerEvent.iType == TPointerEvent::EDrag) || (aPointerEvent.iType == TPointerEvent::EButton1Down)) sl@0: { sl@0: iCurrentPointerPos = aPointerEvent.iPosition; sl@0: } sl@0: DrawNow(); // Draws the entire control sl@0: iWsSession.Finish(); // Wait until WServ has finished drawing sl@0: iIterations++; // Update frame counter sl@0: iSemaphore.Signal(); // Signal test that control was drawn sl@0: } sl@0: sl@0: void CPanControl::Draw(const TRect& aRect) const sl@0: { sl@0: CWindowGc& gc = SystemGc(); sl@0: TRect sourceRect = Rect(); sl@0: sourceRect.Move(iCurrentPointerPos); sl@0: gc.DrawBitmap(aRect, iSourceBitmap, sourceRect); sl@0: } sl@0: sl@0: TInt CPanControl::Iterations() sl@0: { sl@0: return iIterations; sl@0: } sl@0: sl@0: CFbsBitmap* CPanControl::Bitmap() sl@0: { sl@0: return iSourceBitmap; sl@0: }