uifw/AvKon/tsrc/bc/bctestlauncher/src/bctestrunner.cpp
changeset 0 2f259fa3e83a
child 12 941195f2d488
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Base class for autotest application starters.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <vwsdef.h>
       
    20 
       
    21 #include "bctestrunner.h"
       
    22 #include "bctestlauncher.hrh"
       
    23 #include "bctestapplication.h"
       
    24 #include "bctestconf.h"
       
    25 #include "bcteststrmlogger.h"
       
    26 
       
    27 using namespace BCTest;
       
    28 
       
    29 // CONSTANTS
       
    30 _LIT( KTimeFormat, "%:0%J%:1%T%:2%S%:3%+B" );
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS =============================
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CBCTestRunner::NewL
       
    36 // Two-phased constructor.
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CBCTestRunner* CBCTestRunner::NewL()
       
    40     {
       
    41     CBCTestRunner* self = new( ELeave ) CBCTestRunner();
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CBCTestRunner::CBCTestRunner()
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CBCTestRunner::CBCTestRunner()
       
    55     {
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CBCTestRunner::~CBCTestRunner()
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CBCTestRunner::~CBCTestRunner()
       
    63     {
       
    64     for ( TInt i = 0; i < iTestApps.Count(); i++ )
       
    65         {
       
    66         delete iTestApps[ i ];
       
    67         }
       
    68     iTestApps.Close();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CBCTestRunner::ConstructL
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CBCTestRunner::ConstructL( /*CAknAtLogWriter* aLogWriter*/ )
       
    77     {
       
    78     CBCTestConf* conf = CBCTestConf::NewLC();
       
    79     while( conf->NextL() )
       
    80         {
       
    81         AddTestAppL( CBCTestApplication::NewL(
       
    82             conf->Name(), conf->AppUID(), conf->ViewUID(),
       
    83             conf->Timeout(), conf->Version() ) );
       
    84         }
       
    85     CleanupStack::PopAndDestroy();  //conf
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CBCTestRunner::AddTestAppL(CBCTestApplication* aApp)
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CBCTestRunner::AddTestAppL( CBCTestApplication* aApp )
       
    93     {
       
    94     iTestApps.AppendL( aApp );
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CBCTestRunner::RunTestL( TInt aCommand )
       
    99 // Starts test application and returns after test has been run
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TBool CBCTestRunner::RunL( TInt aCommand )
       
   103     {
       
   104     _LIT( KTEST, "test runner run." );
       
   105     LOG << KTEST << EndLine << End;
       
   106     for ( TInt i = 0; i < iTestApps.Count(); ++i )
       
   107         {
       
   108         TRAPD( errno, iTestApps[ i ]->RunL( aCommand ) );
       
   109         switch( errno )
       
   110         {
       
   111         case KErrNone:
       
   112         	{
       
   113         	User::After(8000000);
       
   114         	break;
       
   115         	}
       
   116         case KErrNotFound:
       
   117             {
       
   118             _LIT( KNOTFOUND, ": not found!" );
       
   119             LOG << iTestApps[ i ]->Name() << KNOTFOUND << EndLine << End;
       
   120             break;
       
   121             }
       
   122         case KErrTimedOut:
       
   123             {
       
   124             _LIT( KTIMEOUT, ": timeout." );
       
   125             LOG << iTestApps[ i ]->Name() << KTIMEOUT << EndLine << End;
       
   126             break;
       
   127             }
       
   128         default:
       
   129             break;
       
   130         }
       
   131     }
       
   132     return ETrue;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CBCTestRunner::CreateTimeStamp
       
   137 // Creates time stamp.
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CBCTestRunner::CreateTimeStamp()
       
   141     {
       
   142     _LIT( KTIMEFAILED, "Getting time failed" );
       
   143     TTime homeTime;
       
   144     homeTime.HomeTime();
       
   145     TRAPD( err, homeTime.FormatL( iTempBuf, KTimeFormat ) );
       
   146     if ( err != KErrNone ) // FormatL failed
       
   147         iTempBuf = KTIMEFAILED();
       
   148     iBuf.Append( iTempBuf );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CBCTestRunner::Apps()
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 RArray<CBCTestApplication*>* CBCTestRunner::Apps()
       
   156     {
       
   157     return &iTestApps;
       
   158     }