testexecfw/symbianunittestfw/sutfw/sutfwui/sutfwconsoleui/src/symbianunittestconsoleui.cpp
changeset 1 bbd31066657e
parent 0 3e07fef1e154
equal deleted inserted replaced
0:3e07fef1e154 1:bbd31066657e
    13 *
    13 *
    14 * Description:  
    14 * Description:  
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <e32debug.h>
       
    19 
    18 #include "symbianunittestconsoleui.h"
    20 #include "symbianunittestconsoleui.h"
    19 #include "symbianunittestcommandlineparser.h"
    21 #include "symbianunittestcommandlineparser.h"
    20 #include "symbianunittestrunner.h"
    22 #include "symbianunittestrunner.h"
    21 #include "symbianunittestversion.h"
    23 #include "symbianunittestversion.h"
    22 
    24 
    26 _LIT( KExecutingTestsTxt, "  Executing...\n" );
    28 _LIT( KExecutingTestsTxt, "  Executing...\n" );
    27 _LIT( KTestRunnerFailedTxt, "  Test run failed!\n  Reason: %d\n" );
    29 _LIT( KTestRunnerFailedTxt, "  Test run failed!\n  Reason: %d\n" );
    28 _LIT( KNoTestsFoundTxt, "  No tests found!\n" );
    30 _LIT( KNoTestsFoundTxt, "  No tests found!\n" );
    29 _LIT( KTestsExecutedTxt, "  Executed: %d / %d\n" );
    31 _LIT( KTestsExecutedTxt, "  Executed: %d / %d\n" );
    30 _LIT( KPassedTestsTxt, "  Passed: %d\n" );
    32 _LIT( KPassedTestsTxt, "  Passed: %d\n" );
    31 _LIT( KFailedTestsTxt, "  Failed: %d\n" );
    33 //_LIT( KFailedTestsTxt, "  Failed: %d\n" );
       
    34 _LIT( KFailedTestsTxt2, "  Failed: %S\n" );
       
    35 _LIT( KWindowName, "SymbianUnit" );
    32 _LIT( KSymbianUnitTestPanic, "SymbianUnit creation" );
    36 _LIT( KSymbianUnitTestPanic, "SymbianUnit creation" );
    33 _LIT( KWindowName, "SymbianUnit" );
       
    34 _LIT( KPressAnyKeyTxt, "\n==[ press any key ]==\n    " );
    37 _LIT( KPressAnyKeyTxt, "\n==[ press any key ]==\n    " );
    35 
    38 
    36 _LIT( KHelpTxt, 
    39 _LIT( KHelpTxt, 
    37 "Allowed arguments:\n\n\
    40 "Allowed arguments:\n\n\
    38 -tests|t=<dll,dll,...>\n\
    41 -tests|t=<dll,dll,...>\n\
    39 -cases|c=<case,case,...>\n\
    42 -cases|c=<case,case,...>\n\
    40 -alloc|a\n\
    43 -alloc|a\n\
       
    44 -background|b\n\
    41 -help|h\n\
    45 -help|h\n\
    42 -output|o=<html|xml|txt>\n\
    46 -output|o=<html|xml|txt>\n\
    43 -timeout|to\n\
    47 -timeout|to\n\
    44 -noprompt\n" );
    48 -noprompt\n" );
    45 
    49 
    48 //
    52 //
    49 // -----------------------------------------------------------------------------
    53 // -----------------------------------------------------------------------------
    50 //
    54 //
    51 GLDEF_C TInt E32Main() 
    55 GLDEF_C TInt E32Main() 
    52     {
    56     {
       
    57     //__UHEAP_MARK;
    53     CTrapCleanup* cleanup = CTrapCleanup::New();
    58     CTrapCleanup* cleanup = CTrapCleanup::New();
    54     TRAPD( err, MainL() );
    59     TRAPD( err, MainL() );
    55     __ASSERT_ALWAYS( 
    60     __ASSERT_ALWAYS( 
    56         err == KErrNone, User::Panic( KSymbianUnitTestPanic, err ) );
    61         err == KErrNone, User::Panic( KSymbianUnitTestPanic, err ) );
    57     delete cleanup;
    62     delete cleanup;
       
    63     //__UHEAP_MARKEND;
    58     User::Heap().Reset();
    64     User::Heap().Reset();
    59     return err;
    65     return err;
    60     }
    66     }
    61 
    67 
    62 // -----------------------------------------------------------------------------
    68 // -----------------------------------------------------------------------------
    63 //
    69 //
    64 // -----------------------------------------------------------------------------
    70 // -----------------------------------------------------------------------------
    65 //
    71 //
    66 LOCAL_C void MainL() 
    72 LOCAL_C void MainL() 
    67     {
    73     {
    68     RThread().SetPriority( EPriorityAbsoluteForeground );    
       
    69     // install an active scheduler
    74     // install an active scheduler
    70     CActiveScheduler* scheduler = new( ELeave )CActiveScheduler;
    75     CActiveScheduler* scheduler = new( ELeave )CActiveScheduler;
    71     CActiveScheduler::Install( scheduler );
    76     CActiveScheduler::Install( scheduler );
    72     CleanupStack::PushL( scheduler );
    77     CleanupStack::PushL( scheduler );
    73 
       
    74     TSize size( KConsFullScreen, KConsFullScreen );
       
    75     CConsoleBase* console = Console::NewL( KWindowName, size );
       
    76     CleanupStack::Pop( scheduler );
    78     CleanupStack::Pop( scheduler );
    77 
    79 
    78     CSymbianUnitTestConsoleUi* main = NULL;
    80     CSymbianUnitTestConsoleUi* main = NULL;
    79     TRAPD( err, main = CSymbianUnitTestConsoleUi::NewL( *console ) );
    81 
       
    82     TRAPD( err, main = CSymbianUnitTestConsoleUi::NewL() );
    80     if ( err == KErrNone ) 
    83     if ( err == KErrNone ) 
    81         {
    84         {
    82         CActiveScheduler::Start();
    85         CActiveScheduler::Start();
    83         }
    86         }
    84     delete main;
    87     delete main;
    85     delete scheduler;
    88     delete scheduler;
    86     // Do not delete console. It will check for memory leaks.
    89     // Do not delete console. It will check for memory leaks.
    87     // This is not what is wanted if running tests without 
    90     // This is not what is wanted if running tests without 
    88     // memory leak detection.
    91     // memory leak detection.
    89     }
    92     //delete console;
    90 
    93     }
    91 // -----------------------------------------------------------------------------
    94 
    92 //
    95 // -----------------------------------------------------------------------------
    93 // -----------------------------------------------------------------------------
    96 //
    94 //
    97 // -----------------------------------------------------------------------------
    95 CSymbianUnitTestConsoleUi* CSymbianUnitTestConsoleUi::NewLC( 
    98 //
    96     CConsoleBase& aConsole )
    99 CSymbianUnitTestConsoleUi* CSymbianUnitTestConsoleUi::NewLC()
    97     {
   100     {
    98     CSymbianUnitTestConsoleUi* self = 
   101     CSymbianUnitTestConsoleUi* self = 
    99         new( ELeave )CSymbianUnitTestConsoleUi( aConsole );
   102         new( ELeave )CSymbianUnitTestConsoleUi();
   100     CleanupStack::PushL( self );
   103     CleanupStack::PushL( self );
   101     self->ConstructL();
   104     self->ConstructL();
   102     return self;
   105     return self;
   103     }
   106     }
   104 
   107 
   105 // -----------------------------------------------------------------------------
   108 // -----------------------------------------------------------------------------
   106 //
   109 //
   107 // -----------------------------------------------------------------------------
   110 // -----------------------------------------------------------------------------
   108 //
   111 //
   109 CSymbianUnitTestConsoleUi* CSymbianUnitTestConsoleUi::NewL( 
   112 CSymbianUnitTestConsoleUi* CSymbianUnitTestConsoleUi::NewL()
   110     CConsoleBase& aConsole )
       
   111     {
   113     {
   112     CSymbianUnitTestConsoleUi* self = 
   114     CSymbianUnitTestConsoleUi* self = 
   113         CSymbianUnitTestConsoleUi::NewLC( aConsole );
   115         CSymbianUnitTestConsoleUi::NewLC();
   114     CleanupStack::Pop( self );
   116     CleanupStack::Pop( self );
   115     return self;
   117     return self;
   116     }
   118     }
   117 
   119 
   118 // -----------------------------------------------------------------------------
   120 // -----------------------------------------------------------------------------
   119 //
   121 //
   120 // -----------------------------------------------------------------------------
   122 // -----------------------------------------------------------------------------
   121 //
   123 //
   122 CSymbianUnitTestConsoleUi::CSymbianUnitTestConsoleUi( CConsoleBase& aConsole )
   124 CSymbianUnitTestConsoleUi::CSymbianUnitTestConsoleUi()
   123  : CActive( EPriorityStandard ),
   125  : CActive( EPriorityStandard )
   124    iConsole( aConsole )
       
   125     {
   126     {
   126     }
   127     }
   127 
   128 
   128 // -----------------------------------------------------------------------------
   129 // -----------------------------------------------------------------------------
   129 //
   130 //
   132 void CSymbianUnitTestConsoleUi::ConstructL()
   133 void CSymbianUnitTestConsoleUi::ConstructL()
   133     {
   134     {
   134     User::SetJustInTime( EFalse ); // Do not stop on test case panics
   135     User::SetJustInTime( EFalse ); // Do not stop on test case panics
   135     iCommandLineParser = CSymbianUnitTestCommandLineParser::NewL();
   136     iCommandLineParser = CSymbianUnitTestCommandLineParser::NewL();
   136     iTestRunner = CSymbianUnitTestRunner::NewL( *this );
   137     iTestRunner = CSymbianUnitTestRunner::NewL( *this );
       
   138     if( !iCommandLineParser->Background() ) 
       
   139         {
       
   140         TSize size( KConsFullScreen, KConsFullScreen );
       
   141         iConsole = Console::NewL( KWindowName, size );
       
   142         RThread().SetPriority( EPriorityAbsoluteForeground );    
       
   143         }
       
   144     else 
       
   145         {
       
   146         RThread().SetPriority( EPriorityAbsoluteBackground );    
       
   147         }
       
   148 
   137     CActiveScheduler::Add( this );
   149     CActiveScheduler::Add( this );
   138     // Set ready to run immediately
   150     // Set ready to run immediately
   139     TRequestStatus *status = &iStatus;
   151     TRequestStatus *status = &iStatus;
   140     User::RequestComplete( status, KErrNone );
   152     User::RequestComplete( status, KErrNone );
   141     SetActive ();
   153     SetActive ();
   148 CSymbianUnitTestConsoleUi::~CSymbianUnitTestConsoleUi()
   160 CSymbianUnitTestConsoleUi::~CSymbianUnitTestConsoleUi()
   149     {
   161     {
   150     Cancel();
   162     Cancel();
   151     delete iTestRunner;
   163     delete iTestRunner;
   152     delete iCommandLineParser;
   164     delete iCommandLineParser;
       
   165     delete iConsole;
   153     }
   166     }
   154 
   167 
   155 // -----------------------------------------------------------------------------
   168 // -----------------------------------------------------------------------------
   156 // From CActive
   169 // From CActive
   157 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   158 //
   171 //
   159 void CSymbianUnitTestConsoleUi::RunL()
   172 void CSymbianUnitTestConsoleUi::RunL()
   160     {
   173     {
   161     iConsole.Printf( KTitleTxt, SUT_MAJOR_VERSION, SUT_MINOR_VERSION, SUT_BUILD_VERSION);
   174     if (iCommandLineParser->Background()) 
   162     if ( iCommandLineParser->ShowHelp() )
   175         {
   163         {
   176         //run in background
   164         iConsole.Printf( KHelpTxt );
       
   165         }
       
   166     else
       
   167         {
       
   168         PrintAllocFailureSimulationText();
       
   169         iConsole.Printf( KExecutingTestsTxt );
       
   170         TRAPD( err, 
   177         TRAPD( err, 
   171             iTestRunner->ExecuteTestsL( 
   178         iTestRunner->ExecuteTestsL( 
   172                 iCommandLineParser->TestDllNames(),
   179             iCommandLineParser->TestDllNames(),
   173                 iCommandLineParser->MemoryAllocationFailureSimulation(),
   180             iCommandLineParser->MemoryAllocationFailureSimulation(),
   174                 iCommandLineParser->OutputFileName(),
   181             iCommandLineParser->OutputFileName(),
   175                 iCommandLineParser->OutputFormat(),
   182             iCommandLineParser->OutputFormat(),
   176 	        iCommandLineParser->TestCaseNames(),
   183             iCommandLineParser->TestCaseNames(),
   177 		iCommandLineParser->Timeout()) )
   184             iCommandLineParser->Timeout()) )
   178         if ( err != KErrNone )
   185 	if ( err != KErrNone)
       
   186 	    {
       
   187 		    RDebug::Print( KTestRunnerFailedTxt, err );
       
   188 	    }
       
   189         }
       
   190     else 
       
   191         {
       
   192         iConsole->Printf( KTitleTxt, SUT_MAJOR_VERSION, SUT_MINOR_VERSION, SUT_BUILD_VERSION);
       
   193         if ( iCommandLineParser->ShowHelp() )
   179             {
   194             {
   180             iConsole.Printf( KTestRunnerFailedTxt, err );
   195             InfoMsg( KHelpTxt );
   181             }
   196             }
   182         else 
   197         else
   183             {
   198            {
   184             if ( iExecutedTestCount == 0 )
   199             PrintAllocFailureSimulationText();
       
   200             InfoMsg( KExecutingTestsTxt );
       
   201             TRAPD( err, 
       
   202                 iTestRunner->ExecuteTestsL( 
       
   203                     iCommandLineParser->TestDllNames(),
       
   204                     iCommandLineParser->MemoryAllocationFailureSimulation(),
       
   205                     iCommandLineParser->OutputFileName(),
       
   206                     iCommandLineParser->OutputFormat(),
       
   207     	        iCommandLineParser->TestCaseNames(),
       
   208     		iCommandLineParser->Timeout()) )
       
   209             if ( err != KErrNone )
   185                 {
   210                 {
   186                 iConsole.Printf( KNoTestsFoundTxt );
   211                     iConsole->Printf( KTestRunnerFailedTxt, err );
       
   212                 }
       
   213             else 
       
   214                 {
       
   215                 if ( iExecutedTestCount == 0 )
       
   216                     {
       
   217                     InfoMsg( KNoTestsFoundTxt );
       
   218                     }
   187                 }
   219                 }
   188             }
   220             }
   189         }
   221         if ( iCommandLineParser->PromptUser() )
   190     if ( iCommandLineParser->PromptUser() )
   222             {
   191         {
   223             InfoMsg( KPressAnyKeyTxt );
   192         iConsole.Printf( KPressAnyKeyTxt );
   224             iConsole->Getch(); // get and ignore character        
   193         iConsole.Getch(); // get and ignore character        
   225             }
   194         }
   226         }
   195     CActiveScheduler::Stop();
   227     CActiveScheduler::Stop();
   196     }
   228     }
   197 
   229 
   198 // -----------------------------------------------------------------------------
   230 // -----------------------------------------------------------------------------
   207 // From MSymbianUnitTestUiCallBack
   239 // From MSymbianUnitTestUiCallBack
   208 // -----------------------------------------------------------------------------
   240 // -----------------------------------------------------------------------------
   209 //
   241 //
   210 void CSymbianUnitTestConsoleUi::InfoMsg( const TDesC& aMessage )
   242 void CSymbianUnitTestConsoleUi::InfoMsg( const TDesC& aMessage )
   211     {
   243     {
   212     iConsole.Printf( aMessage );
   244     iConsole->Printf( aMessage );
   213     }
   245     }
   214 
   246 
   215 // -----------------------------------------------------------------------------
   247 // -----------------------------------------------------------------------------
   216 // From MSymbianUnitTestUiCallBack
   248 // From MSymbianUnitTestUiCallBack
   217 // -----------------------------------------------------------------------------
   249 // -----------------------------------------------------------------------------
   218 //
   250 //
   219 void CSymbianUnitTestConsoleUi::InfoMsg( 
   251 void CSymbianUnitTestConsoleUi::InfoMsg( 
   220     const TDesC& aFormat, 
   252     const TDesC& aFormat, 
   221     const TDesC& aMessage )
   253     const TDesC& aMessage )
   222     {
   254     {
   223     iConsole.Printf( aFormat, &aMessage );
   255     iConsole->Printf( aFormat, &aMessage );
   224     }
   256     }
   225 
   257 
   226 // -----------------------------------------------------------------------------
   258 // -----------------------------------------------------------------------------
   227 // From MSymbianUnitTestUiCallBack
   259 // From MSymbianUnitTestUiCallBack
   228 // -----------------------------------------------------------------------------
   260 // -----------------------------------------------------------------------------
   229 //
   261 //
   230 void CSymbianUnitTestConsoleUi::IncrementExecutedTestsCount()
   262 void CSymbianUnitTestConsoleUi::IncrementExecutedTestsCount()
   231     {
   263     {
   232     TPoint pos = iConsole.CursorPos();
   264     if (iCommandLineParser->Background()) 
       
   265         {
       
   266         return;
       
   267         }
       
   268     TPoint pos = iConsole->CursorPos();
   233     pos.iY -= 1;
   269     pos.iY -= 1;
   234     if ( iExecutedTestCount > 0 )
   270     if ( iExecutedTestCount > 0 )
   235         {
   271         {
   236         pos.iY -= 2;
   272         pos.iY -= 2;
   237         }
   273         }
   238     iConsole.SetCursorPosAbs( pos );
   274     iConsole->SetCursorPosAbs( pos );
       
   275     
   239     iExecutedTestCount++;
   276     iExecutedTestCount++;
   240     iConsole.Printf( 
   277     iConsole->Printf( 
   241         KTestsExecutedTxt, iExecutedTestCount, iTestRunner->TestCount());
   278         KTestsExecutedTxt, iExecutedTestCount, iTestRunner->TestCount());
       
   279     
   242     TInt passedTestCount = iExecutedTestCount - iTestRunner->FailedTestCount();
   280     TInt passedTestCount = iExecutedTestCount - iTestRunner->FailedTestCount();
   243     iConsole.Printf( KPassedTestsTxt, passedTestCount );
   281         iConsole->Printf( KPassedTestsTxt, passedTestCount );
   244     iConsole.Printf( KFailedTestsTxt, iTestRunner->FailedTestCount() );
   282     
       
   283     TInt count = iTestRunner->FailedTestCount();
       
   284     TBuf<10> txtCount;
       
   285     txtCount.AppendFormat( _L("%d"), count );
       
   286     InfoMsg( KFailedTestsTxt2, txtCount );
   245     }
   287     }
   246 
   288 
   247 // -----------------------------------------------------------------------------
   289 // -----------------------------------------------------------------------------
   248 //
   290 //
   249 // -----------------------------------------------------------------------------
   291 // -----------------------------------------------------------------------------
   250 //
   292 //
   251 void CSymbianUnitTestConsoleUi::PrintAllocFailureSimulationText()
   293 void CSymbianUnitTestConsoleUi::PrintAllocFailureSimulationText()
   252     {
   294     {
   253     if ( iCommandLineParser->MemoryAllocationFailureSimulation() )
   295     if ( iCommandLineParser->MemoryAllocationFailureSimulation() )
   254         {
   296         {
   255         iConsole.Printf( KAllocOnTxt );
   297         InfoMsg( KAllocOnTxt );
   256         }
   298         }
   257     else
   299     else
   258         {
   300         {
   259         iConsole.Printf( KAllocOffTxt );
   301         InfoMsg( KAllocOffTxt );
   260         }
   302         }
   261     }
   303     }