// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
//
void CSymbianUnitTestResult::StartTestL( const TDesC& aTestName )
    {
    SUT_LOG_FORMAT(_L("StartCase[%S]"), &aTestName);
    HBufC* tmp = aTestName.AllocL();
    delete iCurrentTestName;
    iCurrentTestName = tmp;
    iTestCount++;
    iCurrentResult = ETrue; 
    iTime.UniversalTime();
    }
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
//
void CSymbianUnitTestResult::AddFailureL(
    const TDesC8& aFailureText,
    TInt aAllocFailureRate )
    {
    CSymbianUnitTestFailure* failure = NULL;
    if ( aAllocFailureRate > 0 )
        {
        const TInt KLength = 
            aFailureText.Length() + 
            KSymbianUnitTestAllocFailureRateFormat().Length() + 
            KMax64BitUintLengthAsDescriptor;
        HBufC8* failureMsg = HBufC8::NewLC( KLength );
        failureMsg->Des() = aFailureText;
        failureMsg->Des().AppendFormat(
            KSymbianUnitTestAllocFailureRateFormat, aAllocFailureRate );
        failure = CSymbianUnitTestFailure::NewL( 
            *iCurrentTestName, *failureMsg, KErrNotFound, KNullDesC8 );
        CleanupStack::PopAndDestroy( failureMsg );
        CleanupStack::PushL( failure );
        }
    else
        {
        failure = CSymbianUnitTestFailure::NewLC( 
            *iCurrentTestName, aFailureText, KErrNotFound, KNullDesC8 );
        }
        
    TBuf8<KMaxLength> strLine;
    strLine.Format( KSymbianUnitTestFailed, &aFailureText );
    while(strLine.Length() > 120) 
        {
        TBuf8<KMaxLength> line = strLine.MidTPtr( 0, 120 );
        line.Append( '-' );
        SUT_LOG_FORMAT(_L8("%S"), &line );
        line = strLine.Mid( 120 );
        strLine = line;
        }
    SUT_LOG_FORMAT(_L8("%S"), &strLine );
    //SUT_LOG_FORMAT(KSymbianUnitTestFailed, &aFailureText);
    iCurrentResult = EFalse;
    iFailures.AppendL( failure );
    CleanupStack::Pop( failure ); 
    }
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
//
void CSymbianUnitTestResult::AddAssertFailureL(
    const TDesC8& aFailureMessage,
    TInt aLineNumber,
    const TDesC8& aFileName )
    {
    CSymbianUnitTestFailure* failure = 
        CSymbianUnitTestFailure::NewLC( 
            *iCurrentTestName, aFailureMessage, aLineNumber, aFileName );
    TBuf8<KMaxLength> strLine;
    strLine.Format( KSymbianUnitTestErrorFormat, &aFileName, aLineNumber, &aFailureMessage );
    while(strLine.Length() > 120) 
        {
        TBuf8<KMaxLength> line = strLine.MidTPtr( 0, 120 );
        line.Append( '-' );
        SUT_LOG_FORMAT(_L8("%S"), &line );
        line = strLine.Mid( 120 );
        strLine = line;
        }
    SUT_LOG_FORMAT(_L8("%S"), &strLine );
    iCurrentResult = EFalse;
    iFailures.AppendL( failure );
    CleanupStack::Pop( failure );
    }	
예제 #4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
//
EXPORT_C void CSymbianUnitTestRunner::ExecuteTestsL(
    const MDesCArray& aTestDllNames,
    TBool aMemoryAllocationFailureSimulation,
    const TDesC& aOutputFileName,
    const TDesC& aOutputFormat,
    const CDesCArray& aTestCaseNames,
    TInt  aTimeout )
    {
    //init logger
    TBuf<50> version;
    version.Format(KLogVersion, SUT_MAJOR_VERSION, SUT_MINOR_VERSION, SUT_BUILD_VERSION);
    SUT_LOG_START(version);
    
    iTestCount = 0;
    
    MSymbianUnitTestInterface::TFailureSimulation failureSimulation = 
        MSymbianUnitTestInterface::ENoFailureSimulation;
    if ( aMemoryAllocationFailureSimulation )
        {
        failureSimulation = 
            MSymbianUnitTestInterface::EMemAllocFailureSimulation;
        }
    
    for ( TInt i = 0; i < aTestDllNames.MdcaCount(); i++ )
        {
        TPtrC16 testDllName( aTestDllNames.MdcaPoint( i ) );
        RLibrary library;
        TInt ret;
        ret = library.Load( testDllName );
        if ( ret != KErrNone )
            {
            iUiCallBack.InfoMsg( KFailedToFindDll, testDllName );
            SUT_LOG_FORMAT(KFailedToFindDll, &testDllName);
            //User::Leave( KErrNotFound );
            User::Leave( ret );
            } 
        CleanupClosePushL( library );
        // The second UID of the dll to be used must be compatible
        if ( library.Type()[ 1 ] != KSymbianUnitTestDllUid )
            {
            iUiCallBack.InfoMsg( KNonCompatibleUIDs );
            User::Leave( KErrNotFound );
            }  
        TLibraryFunction entryFunction = library.Lookup( 1 );
        if ( !entryFunction )
            {
            iUiCallBack.InfoMsg( KExportFuncNotFound );
            User::Leave( KErrNotFound );
            }
        
        MSymbianUnitTestInterface* test = 
            reinterpret_cast< MSymbianUnitTestInterface* >( 
                entryFunction() );
        TCleanupItem cleanupItem( DeleteTest, test );
        CleanupStack::PushL( cleanupItem );
        iTestCount += test->TestCaseCount();
        test->ExecuteL( *this, *iResult, failureSimulation, aTestCaseNames, aTimeout);
        CleanupStack::PopAndDestroy(); // cleanupItem
        
        CleanupStack::PopAndDestroy( &library ); 
        }
    
    CSymbianUnitTestOutputFormatter* outputFormatter = 
        SymbianUnitTestOutputFactory::CreateOutputLC( 
            aOutputFileName, aOutputFormat );
    outputFormatter->PrintL( *iResult );
    CleanupStack::PopAndDestroy( outputFormatter );    
    SUT_LOG_INFO(KLogFinish);
    }