testexecfw/symbianunittestfw/sutfw/sutfwcore/sutfwtestrunner/src/symbianunittestrunner.cpp
changeset 0 3e07fef1e154
child 1 bbd31066657e
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "symbianunittestrunner.h"
       
    19 #include "symbianunittestuicallback.h"
       
    20 #include "symbianunittestoutputformatter.h"
       
    21 #include "symbianunittestoutputfactory.h"
       
    22 #include "symbianunittestresult.h"
       
    23 #include "symbianunittestversion.h"
       
    24 #include "sutlogger.h"
       
    25 #include <symbianunittestinterface.h>
       
    26 #include <e32uid.h>
       
    27 
       
    28 
       
    29 // Failures while loading dll:
       
    30 _LIT( KFailedToFindDll, "Failed to find DLL:\n\"%S\"\n" );
       
    31 _LIT( KNonCompatibleUIDs, "Cannot use DLL with non-compatible UIDs!\n" );
       
    32 _LIT( KExportFuncNotFound, "Cannot find EXPORT function from test DLL!\n" );
       
    33 _LIT( KLogVersion, "SymbianUnitTest v%d.%d.%d" );
       
    34 _LIT( KLogFinish, "SymbianUnitTest finished" );
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CSymbianUnitTestRunner* CSymbianUnitTestRunner::NewLC( 
       
    41     MSymbianUnitTestUiCallBack& aUiCallBack )
       
    42     {
       
    43     CSymbianUnitTestRunner* self = 
       
    44         new( ELeave )CSymbianUnitTestRunner( aUiCallBack );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     return self;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C CSymbianUnitTestRunner* CSymbianUnitTestRunner::NewL( 
       
    55     MSymbianUnitTestUiCallBack& aUiCallBack )
       
    56     {
       
    57     CSymbianUnitTestRunner* self = CSymbianUnitTestRunner::NewLC( aUiCallBack );
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CSymbianUnitTestRunner::CSymbianUnitTestRunner( 
       
    67     MSymbianUnitTestUiCallBack& aUiCallBack )
       
    68     : iUiCallBack( aUiCallBack )
       
    69     {
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CSymbianUnitTestRunner::ConstructL()
       
    77     {
       
    78     iResult = CSymbianUnitTestResult::NewL();
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CSymbianUnitTestRunner::~CSymbianUnitTestRunner()
       
    86     {
       
    87     delete iResult;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // From MSymbianUnitTestObserver
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CSymbianUnitTestRunner::IncrementExecutedTestsCount()
       
    95     {
       
    96     iUiCallBack.IncrementExecutedTestsCount();
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C TInt CSymbianUnitTestRunner::TestCount()
       
   104     {
       
   105     return iTestCount;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void CSymbianUnitTestRunner::ExecuteTestsL(
       
   113     const MDesCArray& aTestDllNames,
       
   114     TBool aMemoryAllocationFailureSimulation,
       
   115     const TDesC& aOutputFileName,
       
   116     const TDesC& aOutputFormat,
       
   117     const CDesCArray& aTestCaseNames,
       
   118     TInt  aTimeout )
       
   119     {
       
   120     //init logger
       
   121     TBuf<50> version;
       
   122     version.Format(KLogVersion, SUT_MAJOR_VERSION, SUT_MINOR_VERSION, SUT_BUILD_VERSION);
       
   123     SUT_LOG_START(version);
       
   124     
       
   125     iTestCount = 0;
       
   126     
       
   127     MSymbianUnitTestInterface::TFailureSimulation failureSimulation = 
       
   128         MSymbianUnitTestInterface::ENoFailureSimulation;
       
   129     if ( aMemoryAllocationFailureSimulation )
       
   130         {
       
   131         failureSimulation = 
       
   132             MSymbianUnitTestInterface::EMemAllocFailureSimulation;
       
   133         }
       
   134     
       
   135     for ( TInt i = 0; i < aTestDllNames.MdcaCount(); i++ )
       
   136         {
       
   137         TPtrC16 testDllName( aTestDllNames.MdcaPoint( i ) );
       
   138         RLibrary library;
       
   139         if ( library.Load( testDllName ) != KErrNone )
       
   140             {
       
   141             iUiCallBack.InfoMsg( KFailedToFindDll, testDllName );
       
   142 	    SUT_LOG_FORMAT(KFailedToFindDll, &testDllName);
       
   143             User::Leave( KErrNotFound );
       
   144             } 
       
   145         CleanupClosePushL( library );
       
   146         // The second UID of the dll to be used must be compatible
       
   147         if ( library.Type()[ 1 ] != KSymbianUnitTestDllUid )
       
   148             {
       
   149             iUiCallBack.InfoMsg( KNonCompatibleUIDs );
       
   150             User::Leave( KErrNotFound );
       
   151             }  
       
   152         TLibraryFunction entryFunction = library.Lookup( 1 );
       
   153         if ( !entryFunction )
       
   154             {
       
   155             iUiCallBack.InfoMsg( KExportFuncNotFound );
       
   156             User::Leave( KErrNotFound );
       
   157             }
       
   158         
       
   159         MSymbianUnitTestInterface* test = 
       
   160             reinterpret_cast< MSymbianUnitTestInterface* >( 
       
   161                 entryFunction() );
       
   162         TCleanupItem cleanupItem( DeleteTest, test );
       
   163         CleanupStack::PushL( cleanupItem );
       
   164         iTestCount += test->TestCaseCount();
       
   165         test->ExecuteL( *this, *iResult, failureSimulation, aTestCaseNames, aTimeout);
       
   166         CleanupStack::PopAndDestroy(); // cleanupItem
       
   167         
       
   168         CleanupStack::PopAndDestroy( &library ); 
       
   169         }
       
   170     
       
   171     CSymbianUnitTestOutputFormatter* outputFormatter = 
       
   172         SymbianUnitTestOutputFactory::CreateOutputLC( 
       
   173             aOutputFileName, aOutputFormat );
       
   174     outputFormatter->PrintL( *iResult );
       
   175     CleanupStack::PopAndDestroy( outputFormatter );    
       
   176     SUT_LOG_INFO(KLogFinish);
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 EXPORT_C TInt CSymbianUnitTestRunner::FailedTestCount()
       
   184     {
       
   185     return iResult->Failures().Count();
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // 
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CSymbianUnitTestRunner::DeleteTest( TAny* aTest )
       
   193     {
       
   194     MSymbianUnitTestInterface* test = 
       
   195         reinterpret_cast< MSymbianUnitTestInterface* >( aTest );
       
   196     delete test;
       
   197     }