stifui/avkon/stifui/src/TestCaseOutputView.cpp
branchRCL_3
changeset 20 48060abbbeaf
parent 19 d40e813b23c0
child 21 b3cee849fa46
equal deleted inserted replaced
19:d40e813b23c0 20:48060abbbeaf
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This file contains CTestCaseOutputView class 
       
    15 * definition.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include  <eikmenub.h>
       
    21 #include  <aknViewAppUi.h>
       
    22 #include  <akntitle.h>
       
    23 #include  <barsread.h>	//TResourceReader
       
    24 #include  <Stifui.rsg>
       
    25 
       
    26 //#include "UIStoreIf.h"         
       
    27 //#include "UIStore.h"            
       
    28 //#include "UIEngine.h"           
       
    29 //#include "UIEngineContainer.h"  
       
    30 
       
    31 #include <stifinternal/UIStoreIf.h>
       
    32 #include <stifinternal/UIStore.h>
       
    33 #include <stifinternal/UIEngine.h>
       
    34 #include <stifinternal/UIEngineContainer.h>
       
    35 
       
    36 #include  "TestCaseOutputView.h"
       
    37 #include  "TestCaseOutputContainer.h"
       
    38 #include  "AppUIAppUi.h"
       
    39 #include  "Stifui.hrh" 
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 // ----------------------------------------------------------------------------
       
    43 // CTestCaseOutputView::ConstructL
       
    44 // 
       
    45 // Symbian OS two-phased constructor.
       
    46 // ----------------------------------------------------------------------------
       
    47 //
       
    48 void CTestCaseOutputView::ConstructL()
       
    49     {
       
    50     CView::ConstructL();
       
    51     BaseConstructL( R_APPUI_TESTCASEOUTPUTVIEW );
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CTestCaseOutputView::~CTestCaseOutputView
       
    56 // 
       
    57 // Destructor.
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 CTestCaseOutputView::~CTestCaseOutputView()
       
    61     {
       
    62     if ( iContainer )
       
    63         {
       
    64         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    65         delete iContainer;
       
    66         }
       
    67     delete iNaviDecorator;
       
    68     iNaviDecorator = NULL;
       
    69     
       
    70     iCurrentTestCase = NULL;
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // CTestCaseOutputView::Id
       
    75 // 
       
    76 // Returns view´s id.
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 TUid CTestCaseOutputView::Id() const
       
    80     {
       
    81     return TUid::Uid(ETestCaseOutputViewId);
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CTestCaseOutputView::HandleCommandL
       
    86 // 
       
    87 // Handles a command.
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 void CTestCaseOutputView::HandleCommandL(TInt aCommand)
       
    91     {   
       
    92     switch ( aCommand )
       
    93         {
       
    94         case EAknSoftkeyBack:
       
    95             {
       
    96             AppUi()->HandleCommandL(EAppUIGoBack);
       
    97             break;
       
    98             }
       
    99         case ECmdPauseTestCase:
       
   100             {
       
   101             /*
       
   102             TInt index( 0 );
       
   103 			index = ( ( CAppUIAppUi* )AppUi() )->GetTestCaseIndex();
       
   104              CStartedTestCase* startedTestCase = NULL;
       
   105              TRAPD( ret, startedTestCase = &iUIStore->StartedTestCaseL( index ) );
       
   106              if( ret != KErrNone )
       
   107                  {
       
   108                  // Leave
       
   109                  }
       
   110             */
       
   111             CStartedTestCase* startedTestCase = 
       
   112                 ( ( CAppUIAppUi* )AppUi() )->GetStartedTestCase();
       
   113             startedTestCase->UIEngineContainer().PauseTest(); 
       
   114             break;
       
   115             }
       
   116         case ECmdResumeTestCase:
       
   117             {
       
   118             /*
       
   119             TInt index( 0 );
       
   120 			index = ( ( CAppUIAppUi* )AppUi() )->GetTestCaseIndex();
       
   121              CStartedTestCase* startedTestCase = NULL;
       
   122              TRAPD( ret, startedTestCase = &iUIStore->StartedTestCaseL( index ) );
       
   123              if( ret != KErrNone )
       
   124                  {
       
   125                  // Leave
       
   126                  }
       
   127             */
       
   128             CStartedTestCase* startedTestCase = 
       
   129                 ( ( CAppUIAppUi* )AppUi() )->GetStartedTestCase();
       
   130             startedTestCase->UIEngineContainer().ResumeTest();            
       
   131             break;
       
   132             }
       
   133         case ECmdAbortTestCase:
       
   134             {
       
   135             /*
       
   136             TInt index( 0 );
       
   137 			index = ( ( CAppUIAppUi* )AppUi() )->GetTestCaseIndex();
       
   138              CStartedTestCase* startedTestCase = NULL;
       
   139              TRAPD( ret, startedTestCase = &iUIStore->StartedTestCaseL( index ) );
       
   140              if( ret != KErrNone )
       
   141                  {
       
   142                  // Leave
       
   143                  }
       
   144             */
       
   145             CStartedTestCase* startedTestCase = 
       
   146                 ( ( CAppUIAppUi* )AppUi() )->GetStartedTestCase();
       
   147             startedTestCase->UIEngineContainer().CancelTest();             
       
   148             break;
       
   149             }
       
   150         default:
       
   151             {
       
   152             AppUi()->HandleCommandL( aCommand );
       
   153             break;
       
   154             }
       
   155         }
       
   156 
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CTestCaseOutputView::HandleClientRectChange
       
   161 // 
       
   162 // Handles client rect changes.
       
   163 // ----------------------------------------------------------------------------
       
   164 //
       
   165 void CTestCaseOutputView::HandleClientRectChange()
       
   166     {
       
   167     if ( iContainer )
       
   168         {
       
   169         iContainer->SetRect( ClientRect() );
       
   170         }
       
   171 
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // CTestCaseOutputView::DoActivateL
       
   176 // 
       
   177 // Initializes view when activated.
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 void CTestCaseOutputView::DoActivateL(
       
   181    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
       
   182    const TDesC8& /*aCustomMessage*/)
       
   183     {
       
   184     if (!iContainer)
       
   185         {
       
   186         iContainer = new (ELeave) CTestCaseOutputContainer;
       
   187         iContainer->SetMopParent(this);
       
   188 
       
   189         iCurrentTestCase = ( ( CAppUIAppUi* )AppUi() )->GetStartedTestCase();
       
   190         iContainer->ConstructL( ClientRect(), iCurrentTestCase );
       
   191         
       
   192         AppUi()->AddToStackL( *this, iContainer );
       
   193         }
       
   194     PrintTestCaseStateL();
       
   195 	
       
   196 	CEikStatusPane* sp=iEikonEnv->AppUiFactory()->StatusPane();
       
   197 	CAknNavigationControlContainer* np= (CAknNavigationControlContainer *)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
       
   198 	
       
   199 	TResourceReader reader;
       
   200 	iCoeEnv->CreateResourceReaderLC(reader,R_NAVITITLE_TESTCASE_OUTPUT);
       
   201 	iNaviDecorator = np->CreateNavigationLabelL( reader );
       
   202 	CleanupStack::PopAndDestroy(); // resource reader
       
   203 	np->PushL(*iNaviDecorator);
       
   204 	
       
   205     }
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 // CTestCaseOutputView::DoDeactivate
       
   209 // 
       
   210 // Deactivates view.
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 void CTestCaseOutputView::DoDeactivate()
       
   214     {
       
   215     if ( iContainer )
       
   216         {
       
   217         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   218         delete iContainer;
       
   219         iContainer = NULL;
       
   220         }
       
   221     
       
   222     CEikStatusPane* sp=iEikonEnv->AppUiFactory()->StatusPane();
       
   223     // Because DoDeactivate method can't leave we must 
       
   224     // catch unexpected leaves.
       
   225 	TInt ret = KErrNone;
       
   226     TRAP( ret,
       
   227     CAknTitlePane* tp=(CAknTitlePane*)sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
       
   228     if ( tp != NULL )
       
   229     	{
       
   230     	tp->SetTextToDefaultL(); // Set application name.
       
   231     	}
       
   232     ); // TRAPD end
       
   233     
       
   234     delete iNaviDecorator;
       
   235     iNaviDecorator = NULL;
       
   236     
       
   237     iCurrentTestCase = NULL;
       
   238 
       
   239     }
       
   240 
       
   241 // ----------------------------------------------------------------------------
       
   242 // CTestCaseOutputView::DynInitMenuPaneL
       
   243 // 
       
   244 // Initializes menu pane.
       
   245 // ----------------------------------------------------------------------------
       
   246 //
       
   247 void CTestCaseOutputView::DynInitMenuPaneL(
       
   248     TInt aResourceId, CEikMenuPane* aMenuPane)
       
   249     {
       
   250     CStartedTestCase* startedTestCase = 
       
   251         ( ( CAppUIAppUi* )AppUi() )->GetStartedTestCase();
       
   252 
       
   253     if (R_APPUI_TESTCASEOUTPUTVIEW_MENU == aResourceId)
       
   254         {
       
   255   
       
   256         if ( startedTestCase->Status() == CUIStoreIf::EStatusRunning )
       
   257             {
       
   258             if( startedTestCase->UIEngineContainer().State() == CUIEngineContainer::ENotStarted )
       
   259                 {
       
   260                 aMenuPane->SetItemDimmed( ECmdPauseTestCase, ETrue );
       
   261                 aMenuPane->SetItemDimmed( ECmdResumeTestCase, ETrue );
       
   262                 aMenuPane->SetItemDimmed( ECmdAbortTestCase, ETrue );
       
   263                 }
       
   264             else if( startedTestCase->UIEngineContainer().State() == CUIEngineContainer::ERunning )
       
   265                 {
       
   266                 aMenuPane->SetItemDimmed( ECmdResumeTestCase, ETrue );
       
   267                 aMenuPane->SetItemDimmed( ECmdPauseTestCase, EFalse );
       
   268                 }
       
   269             else if( startedTestCase->UIEngineContainer().State() == CUIEngineContainer::EPaused )
       
   270                 {
       
   271                 aMenuPane->SetItemDimmed( ECmdPauseTestCase, ETrue );
       
   272                 aMenuPane->SetItemDimmed( ECmdResumeTestCase, EFalse );
       
   273                 }
       
   274             else if( startedTestCase->UIEngineContainer().State() == CUIEngineContainer::EExecuted )
       
   275                 {
       
   276                 aMenuPane->SetItemDimmed( ECmdPauseTestCase, ETrue );
       
   277                 aMenuPane->SetItemDimmed( ECmdResumeTestCase, ETrue );
       
   278                 aMenuPane->SetItemDimmed( ECmdAbortTestCase, ETrue );
       
   279                 }
       
   280             else if( startedTestCase->UIEngineContainer().State() == CUIEngineContainer::EFinished )
       
   281                 {
       
   282                 aMenuPane->SetItemDimmed( ECmdPauseTestCase, ETrue );
       
   283                 aMenuPane->SetItemDimmed( ECmdResumeTestCase, ETrue );
       
   284                 aMenuPane->SetItemDimmed( ECmdAbortTestCase, ETrue );
       
   285                 }
       
   286                                                                                      
       
   287             }
       
   288 		else
       
   289             {
       
   290             aMenuPane->SetItemDimmed( ECmdPauseTestCase, ETrue );
       
   291             aMenuPane->SetItemDimmed( ECmdResumeTestCase, ETrue );
       
   292             aMenuPane->SetItemDimmed( ECmdAbortTestCase, ETrue );
       
   293             }
       
   294         }
       
   295         
       
   296     }
       
   297 
       
   298 // ----------------------------------------------------------------------------
       
   299 // CTestCaseOutputView::OutputUpdate
       
   300 // 
       
   301 // Receives output update notification from AppUI.
       
   302 // ----------------------------------------------------------------------------
       
   303 //
       
   304 void CTestCaseOutputView::OutputUpdateL( CStartedTestCase* /*aTestCase*/ )
       
   305     {
       
   306     PrintTestCaseStateL();
       
   307     iContainer->OutputUpdateL();
       
   308 
       
   309     }
       
   310 
       
   311 // ----------------------------------------------------------------------------
       
   312 // CTestCaseOutputView::TestCaseStateChangedL
       
   313 // 
       
   314 // Receives test case state changed notification from AppUI.
       
   315 // ----------------------------------------------------------------------------
       
   316 //
       
   317 void CTestCaseOutputView::TestCaseStateChangedL()
       
   318     {
       
   319     PrintTestCaseStateL();
       
   320     iContainer->OutputUpdateL();
       
   321 
       
   322     }
       
   323 
       
   324 // ----------------------------------------------------------------------------
       
   325 // CTestCaseOutputView::PrintTestCaseState
       
   326 // 
       
   327 // Prints test case state to title pane.
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 void CTestCaseOutputView::PrintTestCaseStateL()
       
   331     {
       
   332     TBuf<50> statusMessage;
       
   333     CEikStatusPane* sp=iEikonEnv->AppUiFactory()->StatusPane();
       
   334     CAknTitlePane* tp=(CAknTitlePane*)sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
       
   335 
       
   336     if ( iCurrentTestCase != NULL )
       
   337         {
       
   338         TUint status = iCurrentTestCase->Status();
       
   339 
       
   340         if( status & CUIStoreIf::EStatusRunning )
       
   341             {
       
   342             CEikonEnv::Static()->ReadResource( statusMessage,
       
   343                 R_TESTCASE_STATE_RUNNING );
       
   344             }
       
   345         else if( status & CUIStoreIf::EStatusExecuted && 
       
   346                             status & CUIStoreIf::EStatusPassed )
       
   347             {
       
   348             CEikonEnv::Static()->ReadResource( statusMessage, 
       
   349                 R_TESTCASE_STATE_PASSED );
       
   350             }
       
   351         else if( status & CUIStoreIf::EStatusExecuted && 
       
   352                             status & CUIStoreIf::EStatusFailed )
       
   353             {
       
   354             CEikonEnv::Static()->ReadResource( statusMessage, 
       
   355                 R_TESTCASE_STATE_FAILED );
       
   356             }
       
   357         else if( status & CUIStoreIf::EStatusAborted )
       
   358             {
       
   359             CEikonEnv::Static()->ReadResource( statusMessage, 
       
   360                 R_TESTCASE_STATE_CRASHED_ABORTED );
       
   361             }
       
   362         else if( status & CUIStoreIf::EStatusCrashed )
       
   363             {
       
   364             CEikonEnv::Static()->ReadResource( statusMessage, 
       
   365                 R_TESTCASE_STATE_CRASHED_ABORTED );
       
   366             }
       
   367         else
       
   368             {
       
   369             CEikonEnv::Static()->ReadResource( statusMessage, 
       
   370                 R_TESTCASE_STATE_UNKNOWN );
       
   371             }
       
   372         
       
   373         tp->SetTextL( statusMessage );
       
   374         tp->DrawNow();
       
   375 
       
   376         }
       
   377 
       
   378     }
       
   379 
       
   380 // End of File