symbianunittestfw/sutfw/sutfwcore/sutfwframework/tsrc/src/ut_symbianunittest.cpp
branchRCL_3
changeset 3 9397a16b6eb8
parent 1 6edeef394eb7
equal deleted inserted replaced
1:6edeef394eb7 3:9397a16b6eb8
     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 "sutlogger.h"
       
    19 #include "ut_symbianunittest.h"
       
    20 #include "symbianunittestresult.h"
       
    21 #include <symbianunittestmacros.h>
       
    22 
       
    23 const TInt KTimeInterval( 1000000 );
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 UT_CSymbianUnitTest* UT_CSymbianUnitTest::NewL()
       
    30     {
       
    31     UT_CSymbianUnitTest* self = UT_CSymbianUnitTest::NewLC(); 
       
    32     CleanupStack::Pop( self );
       
    33     return self;
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 UT_CSymbianUnitTest* UT_CSymbianUnitTest::NewLC()
       
    41     {
       
    42     UT_CSymbianUnitTest* self = new( ELeave )UT_CSymbianUnitTest();
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 UT_CSymbianUnitTest::UT_CSymbianUnitTest()
       
    53     {
       
    54     SUT_LOG_DEBUG( "Entering UT_CSymbianUnitTest::UT_CSymbianUnitTest()" )
       
    55     SUT_LOG_DEBUG( "Exiting UT_CSymbianUnitTest::UT_CSymbianUnitTest()" )
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void UT_CSymbianUnitTest::ConstructL()
       
    63     {
       
    64     BASE_CONSTRUCT
       
    65     
       
    66     DEFINE_TEST_CLASS( UT_CSymbianUnitTest )
       
    67     
       
    68     ADD_SUT_WITH_SETUP_AND_TEARDOWN( SetupL, UT_NameL, Teardown )
       
    69     ADD_SUT( UT_IsMemoryAllocationFailureSimulationUsedL )
       
    70     ADD_SUT( UT_PanicInTestL )
       
    71     ADD_SUT( UT_ErrorInSetupL )
       
    72     ADD_SUT( UT_LeaveInTestL )
       
    73     ADD_SUT( UT_MemoryLeakInTestL ) 
       
    74     ADD_SUT( UT_EqualsAssertsL )
       
    75     ADD_SUT( UT_FailingAssertsL )
       
    76     ADD_SUT( UT_PassingAssertsL )
       
    77     ADD_SUT( UT_TestCaseNamesL )
       
    78     ADD_SUT( UT_TimeoutL )
       
    79     ADD_SUT( UT_ResourceLeakInTestL )
       
    80     ADD_SUT( UT_RequestLeakInTestL )
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 UT_CSymbianUnitTest::~UT_CSymbianUnitTest()
       
    88     {   
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // From MSymbianUnitTestObserver
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void UT_CSymbianUnitTest::TestPass(const TDesC& /*aTestCaseName*/)
       
    96     {
       
    97     iExecutedTestCount++;    
       
    98     }
       
    99 void UT_CSymbianUnitTest::TestFailed(const TDesC& /*aTestCaseName*/, const TDesC8& /*aErrMsg*/)
       
   100     {
       
   101     iExecutedTestCount++;    
       
   102     }
       
   103 
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void UT_CSymbianUnitTest::SetupL()
       
   111     {
       
   112     iTestResult = CSymbianUnitTestResult::NewL();
       
   113     iUnitTest = UT_CSymbianUnitTest::NewL();
       
   114     // Remove the test cases added in ConstructL. 
       
   115     // They will be replaced by the functions simulating failures. 
       
   116     iUnitTest->iTestCases.ResetAndDestroy();
       
   117     iTestCaseNames = new (ELeave)CDesCArrayFlat(1);
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void UT_CSymbianUnitTest::Teardown()
       
   125     {
       
   126     delete iUnitTest;
       
   127     iUnitTest = NULL;
       
   128     delete iTestResult;
       
   129     iTestResult = NULL;
       
   130     iExecutedTestCount = 0;
       
   131     delete iTestCaseNames;
       
   132     iTestCaseNames = 0;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void UT_CSymbianUnitTest::UT_NameL()
       
   140     {
       
   141     SUT_ASSERT_EQUALS( _L( "UT_CSymbianUnitTest" ), iUnitTest->Name() )
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void UT_CSymbianUnitTest::UT_IsMemoryAllocationFailureSimulationUsedL()
       
   149     {
       
   150     SUT_ASSERT( !iUnitTest->IsMemoryAllocationFailureSimulationUsed() )
       
   151     
       
   152     iUnitTest->iAllocFailureType = RHeap::EDeterministic;
       
   153     SUT_ASSERT( iUnitTest->IsMemoryAllocationFailureSimulationUsed() )
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void UT_CSymbianUnitTest::UT_PanicInTestL()
       
   161     {
       
   162     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   163     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   164  
       
   165     _LIT( KTestName, "PanicInTest" );
       
   166     iUnitTest->AddTestCaseL( 
       
   167         KTestName, 
       
   168         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   169         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulatePanicL ), 
       
   170         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   171     
       
   172     // Without memory allocation failure simulation
       
   173     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   174     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   175     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   176     
       
   177     // With memory allocation failure simulation
       
   178     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   179     SUT_ASSERT_EQUALS( 2, iTestResult->Failures().Count() )
       
   180     SUT_ASSERT_EQUALS( 2, iExecutedTestCount ) 
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void UT_CSymbianUnitTest::UT_ErrorInSetupL()
       
   188     {
       
   189     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   190     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   191  
       
   192     _LIT( KTestName, "ErrorInSetup" );
       
   193     iUnitTest->AddTestCaseL( 
       
   194         KTestName, 
       
   195         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   196         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateLeaveL ), 
       
   197         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   198     
       
   199     // Without memory allocation failure simulation
       
   200     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   201     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   202     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   203     
       
   204     // With memory allocation failure simulation
       
   205     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   206     SUT_ASSERT_EQUALS( 2, iTestResult->Failures().Count() )
       
   207     SUT_ASSERT_EQUALS( 2, iExecutedTestCount ) 
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void UT_CSymbianUnitTest::UT_LeaveInTestL()
       
   215     {
       
   216     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   217     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   218  
       
   219     _LIT( KTestName, "LeaveInTest" );
       
   220     iUnitTest->AddTestCaseL( 
       
   221         KTestName, 
       
   222         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   223         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateLeaveL ), 
       
   224         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   225     
       
   226     // Without memory allocation failure simulation
       
   227     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0);
       
   228     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   229     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   230     
       
   231     // With memory allocation failure simulation
       
   232     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   233     SUT_ASSERT_EQUALS( 2, iTestResult->Failures().Count() )
       
   234     SUT_ASSERT_EQUALS( 2, iExecutedTestCount )    
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void UT_CSymbianUnitTest::UT_MemoryLeakInTestL()
       
   242     {
       
   243     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   244     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   245     
       
   246     _LIT( KTestName, "MemoryLeakInTest" );
       
   247     iUnitTest->AddTestCaseL( 
       
   248         KTestName, 
       
   249         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   250         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateMemoryLeakL ), 
       
   251         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   252     
       
   253     // Without memory allocation failure simulation
       
   254     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   255     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   256     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   257   
       
   258     // With memory allocation failure simulation
       
   259     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   260     SUT_ASSERT_EQUALS( 2, iTestResult->Failures().Count() )
       
   261     SUT_ASSERT_EQUALS( 2, iExecutedTestCount )
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void UT_CSymbianUnitTest::UT_EqualsAssertsL()
       
   269 	{
       
   270 	SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   271     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   272     
       
   273     _LIT( KTestName, "TestAssertEquals" );
       
   274     
       
   275     iUnitTest->AddTestCaseL( 
       
   276         KTestName, 
       
   277         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   278         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateEqualsAssertWithStringL ),
       
   279         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   280         
       
   281 
       
   282     iUnitTest->AddTestCaseL( 
       
   283         KTestName, 
       
   284         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   285         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateEqualsAssertWithStringFailL ),
       
   286         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   287         
       
   288         
       
   289     iUnitTest->AddTestCaseL( 
       
   290         KTestName, 
       
   291         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   292         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateEqualsAssertWithString8L ),
       
   293         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   294         
       
   295     iUnitTest->AddTestCaseL( 
       
   296         KTestName, 
       
   297         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   298         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateEqualsAssertWithString8FailL ),
       
   299         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   300 
       
   301     iUnitTest->AddTestCaseL( 
       
   302         KTestName, 
       
   303         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   304         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateEqualsAssertWithIntL ),
       
   305         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   306         
       
   307     iUnitTest->AddTestCaseL( 
       
   308         KTestName, 
       
   309         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   310         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateEqualsAssertWithIntFailL ),
       
   311         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   312 
       
   313     // Without memory allocation failure simulation
       
   314     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   315     SUT_ASSERT_EQUALS( 3, iTestResult->Failures().Count() )
       
   316     SUT_ASSERT_EQUALS( 6, iExecutedTestCount )
       
   317     
       
   318     // With memory allocation failure simulation
       
   319     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   320     SUT_ASSERT_EQUALS( 6, iTestResult->Failures().Count() )
       
   321     SUT_ASSERT_EQUALS( 12, iExecutedTestCount )
       
   322 	}
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void UT_CSymbianUnitTest::UT_FailingAssertsL()
       
   329     {
       
   330     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   331     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   332     
       
   333     _LIT( KTestName, "TestAssertFailures" );
       
   334     iUnitTest->AddTestCaseL( 
       
   335         KTestName, 
       
   336         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   337         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateFailingAssertL ),
       
   338         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   339     iUnitTest->AddTestCaseL( 
       
   340         KTestName, 
       
   341         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   342         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateFailingAssertWithIntsL ),
       
   343         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );   
       
   344     iUnitTest->AddTestCaseL( 
       
   345         KTestName, 
       
   346         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   347         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateFailingAssertWithDesC8sL ),
       
   348         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );    
       
   349     iUnitTest->AddTestCaseL( 
       
   350         KTestName, 
       
   351         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   352         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateFailingAssertWithDesC16sL ),
       
   353         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) ); 
       
   354     iUnitTest->AddTestCaseL( 
       
   355         KTestName, 
       
   356         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   357         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateFailingAssertLeaveL ),
       
   358         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   359     iUnitTest->AddTestCaseL( 
       
   360         KTestName, 
       
   361         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   362         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateFailingAssertLeaveWithSpecificValueL ),
       
   363         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   364     
       
   365     // Without memory allocation failure simulation
       
   366     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   367     SUT_ASSERT_EQUALS( 6, iTestResult->Failures().Count() )
       
   368     SUT_ASSERT_EQUALS( 6, iExecutedTestCount )
       
   369     
       
   370     // With memory allocation failure simulation
       
   371     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   372     SUT_ASSERT_EQUALS( 12, iTestResult->Failures().Count() )
       
   373     SUT_ASSERT_EQUALS( 12, iExecutedTestCount )
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void UT_CSymbianUnitTest::UT_PassingAssertsL()
       
   381     {
       
   382     SUT_ASSERT( ETrue )
       
   383     SUT_ASSERT_DESC( ETrue, "test assert with desc")
       
   384     SUT_ASSERT( ETrue == ETrue )
       
   385     SUT_ASSERT( 1 == 1 )
       
   386     HBufC* ptr( NULL );
       
   387     SUT_ASSERT( !ptr )
       
   388     ptr = KNullDesC().AllocLC();
       
   389     SUT_ASSERT( ptr )
       
   390     CleanupStack::PopAndDestroy( ptr );
       
   391     
       
   392     SUT_ASSERT_EQUALS( 1, 1 )
       
   393     SUT_ASSERT_EQUALS_DESC( 1, 1, "test assert equals with desc" )
       
   394     SUT_ASSERT_EQUALS( KNullDesC8, KNullDesC8 )
       
   395     SUT_ASSERT_EQUALS( KNullDesC, KNullDesC )
       
   396     
       
   397     SUT_ASSERT_LEAVE( User::Leave( KErrGeneral ) )
       
   398     
       
   399     SUT_ASSERT_LEAVE_WITH( User::Leave( KErrGeneral ), KErrGeneral )
       
   400     }
       
   401 
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 void UT_CSymbianUnitTest::UT_TestCaseNamesL()
       
   408     {
       
   409     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   410     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   411  
       
   412     _LIT( KTest1Name, "TestCase1" );
       
   413     iUnitTest->AddTestCaseL( 
       
   414         KTest1Name, 
       
   415         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   416         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateLeaveL ), 
       
   417         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   418 
       
   419     _LIT( KTest2Name, "TestCase2" );
       
   420     iUnitTest->AddTestCaseL( 
       
   421         KTest2Name, 
       
   422         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   423         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateLeaveL ), 
       
   424         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   425 
       
   426     _LIT( KTest3Name, "TestCase3" );
       
   427     iUnitTest->AddTestCaseL( 
       
   428         KTest3Name, 
       
   429         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   430         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateLeaveL ), 
       
   431         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   432 
       
   433     _LIT( LTest1FullName, "UT_CSymbianUnitTest::TestCase1");
       
   434     iTestCaseNames->AppendL(LTest1FullName);
       
   435     
       
   436     // Without memory allocation failure simulation
       
   437     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   438     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   439     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   440     }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 void UT_CSymbianUnitTest::UT_TimeoutL()
       
   447     {
       
   448     _LIT( KTestName, "TimeoutTestCase" );
       
   449     iUnitTest->AddTestCaseL( 
       
   450         KTestName, 
       
   451         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   452         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateTimeoutL ), 
       
   453         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   454     //run test case without timeout control
       
   455     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   456     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   457     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   458     //run test case with 3 seconds time out
       
   459     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 3 );
       
   460     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   461     SUT_ASSERT_EQUALS( 2, iExecutedTestCount )
       
   462     }
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 void UT_CSymbianUnitTest::SimulateTimeoutL()
       
   469     {
       
   470     User::After(5* 1000000);
       
   471     /*RTimer timer;
       
   472 	timer.CreateLocal();
       
   473     TRequestStatus status;
       
   474     timer.After( status, 5* 1000000 );
       
   475     User::WaitForRequest( status );
       
   476     timer.Cancel();
       
   477     timer.Close();*/
       
   478     }
       
   479 
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 //
       
   483 // ---------------------------------------------------------------------------
       
   484 //
       
   485 void UT_CSymbianUnitTest::SimulatePanicL()
       
   486     {
       
   487     _LIT( KPanicString, "kkkkkkkkkkkk");
       
   488     TBufC<3> buf( KPanicString );
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 // ---------------------------------------------------------------------------
       
   494 //
       
   495 void UT_CSymbianUnitTest::SimulateLeaveL()
       
   496     {
       
   497     User::Leave( KErrGeneral );
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void UT_CSymbianUnitTest::SimulateMemoryLeakL()
       
   505     {
       
   506     HBufC::NewL( 1 );
       
   507     }
       
   508 
       
   509 // ---------------------------------------------------------------------------
       
   510 //
       
   511 // ---------------------------------------------------------------------------
       
   512 //
       
   513 void UT_CSymbianUnitTest::SimulateFailingAssertL()
       
   514     {
       
   515     SUT_ASSERT( EFalse )
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 void UT_CSymbianUnitTest::SimulateFailingAssertWithIntsL()
       
   523     {
       
   524     const TInt KFirstValue( -1 );
       
   525     const TInt KSecondValue( -2 );
       
   526     SUT_ASSERT_EQUALS( KFirstValue, KSecondValue )
       
   527     }
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 // ---------------------------------------------------------------------------
       
   532 //
       
   533 void UT_CSymbianUnitTest::SimulateFailingAssertWithDesC8sL()
       
   534     {
       
   535     _LIT8( KSomeText, "some text" );
       
   536     SUT_ASSERT_EQUALS( KNullDesC8, KSomeText )
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 void UT_CSymbianUnitTest::SimulateFailingAssertWithDesC16sL()
       
   544     {
       
   545     _LIT( KSomeText, "some text" );
       
   546     SUT_ASSERT_EQUALS( KNullDesC, KSomeText )
       
   547     }
       
   548 
       
   549 // ---------------------------------------------------------------------------
       
   550 //
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void UT_CSymbianUnitTest::SimulateFailingAssertLeaveL()
       
   554     {
       
   555     SUT_ASSERT_LEAVE( Dummy() )
       
   556     }
       
   557 
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 // ---------------------------------------------------------------------------
       
   561 //
       
   562 void UT_CSymbianUnitTest::SimulateFailingAssertLeaveWithSpecificValueL()
       
   563     {
       
   564     SUT_ASSERT_LEAVE_WITH( User::Leave( KErrNotFound ), KErrGeneral )
       
   565     }
       
   566 
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 // ---------------------------------------------------------------------------
       
   570 //
       
   571 void UT_CSymbianUnitTest::Dummy()
       
   572     {
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------------------------
       
   576 //
       
   577 // ---------------------------------------------------------------------------
       
   578 //
       
   579 void UT_CSymbianUnitTest::SimulateEqualsAssertWithStringL()
       
   580 	{
       
   581 	_LIT( KSomeText, "some text" );
       
   582     AssertEqualsL( KSomeText, KSomeText, __LINE__, _L8( __FILE__ ) );	
       
   583 	}
       
   584 
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 void UT_CSymbianUnitTest::SimulateEqualsAssertWithStringFailL()
       
   590 	{
       
   591 	_LIT( KSomeText, "some text" );
       
   592     AssertEqualsL( KNullDesC, KSomeText, __LINE__, _L8( __FILE__ ) );	
       
   593 	}
       
   594 
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 // ---------------------------------------------------------------------------
       
   598 //
       
   599 void UT_CSymbianUnitTest::SimulateEqualsAssertWithString8L()
       
   600 	{
       
   601 	_LIT8( KSomeText, "some text" );
       
   602     AssertEqualsL( KSomeText, KSomeText, __LINE__, _L8( __FILE__ ) );	
       
   603 	}
       
   604 
       
   605 // ---------------------------------------------------------------------------
       
   606 //
       
   607 // ---------------------------------------------------------------------------
       
   608 //
       
   609 void UT_CSymbianUnitTest::SimulateEqualsAssertWithString8FailL()
       
   610 	{
       
   611 	_LIT8( KSomeText, "some text" );
       
   612     AssertEqualsL( KNullDesC8, KSomeText, __LINE__, _L8( __FILE__ ) );	
       
   613 	}
       
   614 	
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 // ---------------------------------------------------------------------------
       
   618 //
       
   619 void UT_CSymbianUnitTest::SimulateEqualsAssertWithIntL()
       
   620 	{
       
   621 	const TInt KAssertValue(123);
       
   622 	AssertEqualsL( 123, KAssertValue, __LINE__, _L8( __FILE__ ) );	
       
   623 	}
       
   624 	
       
   625 // ---------------------------------------------------------------------------
       
   626 //
       
   627 // ---------------------------------------------------------------------------
       
   628 //
       
   629 void UT_CSymbianUnitTest::SimulateEqualsAssertWithIntFailL()
       
   630 	{
       
   631 	const TInt KAssertValue(123);
       
   632 	AssertEqualsL( -1, KAssertValue, __LINE__, _L8( __FILE__ ) );	
       
   633 	}
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 //
       
   637 // ---------------------------------------------------------------------------
       
   638 //
       
   639 void UT_CSymbianUnitTest::UT_ResourceLeakInTestL()
       
   640 	{
       
   641     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   642     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   643     
       
   644     _LIT( KTestName, "ResourceLeakInTest" );
       
   645     iUnitTest->AddTestCaseL( 
       
   646         KTestName, 
       
   647         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   648         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateResourceLeakL ), 
       
   649         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   650     
       
   651     // Without memory allocation failure simulation
       
   652     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   653     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   654     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   655   
       
   656     // With memory allocation failure simulation
       
   657     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   658     SUT_ASSERT_EQUALS( 2, iTestResult->Failures().Count() )
       
   659     SUT_ASSERT_EQUALS( 2, iExecutedTestCount )
       
   660 	}
       
   661 
       
   662 // ---------------------------------------------------------------------------
       
   663 //
       
   664 // ---------------------------------------------------------------------------
       
   665 //
       
   666 void UT_CSymbianUnitTest::SimulateResourceLeakL()
       
   667     {
       
   668     RTimer timer;
       
   669 	timer.CreateLocal();
       
   670     }
       
   671     
       
   672 // ---------------------------------------------------------------------------
       
   673 //
       
   674 // ---------------------------------------------------------------------------
       
   675 //
       
   676 void UT_CSymbianUnitTest::UT_RequestLeakInTestL()
       
   677 	{
       
   678     SUT_ASSERT_EQUALS( 0, iTestResult->Failures().Count() )
       
   679     SUT_ASSERT_EQUALS( 0, iExecutedTestCount )
       
   680     
       
   681     _LIT( KTestName, "RequestLeakInTest" );
       
   682     iUnitTest->AddTestCaseL( 
       
   683         KTestName, 
       
   684         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ), 
       
   685         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::SimulateRequestLeakL ), 
       
   686         CSymbianUnitTest::FunctionPtr( &UT_CSymbianUnitTest::Dummy ) );
       
   687     
       
   688     // Without memory allocation failure simulation
       
   689     iUnitTest->ExecuteL( *this, *iTestResult, ENoFailureSimulation, *iTestCaseNames, 0 );
       
   690     SUT_ASSERT_EQUALS( 1, iTestResult->Failures().Count() )
       
   691     SUT_ASSERT_EQUALS( 1, iExecutedTestCount )
       
   692   
       
   693     // With memory allocation failure simulation
       
   694     iUnitTest->ExecuteL( *this, *iTestResult, EMemAllocFailureSimulation, *iTestCaseNames, 0 );
       
   695     SUT_ASSERT_EQUALS( 2, iTestResult->Failures().Count() )
       
   696     SUT_ASSERT_EQUALS( 2, iExecutedTestCount )
       
   697 	}
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 //
       
   701 // ---------------------------------------------------------------------------
       
   702 //
       
   703 void UT_CSymbianUnitTest::SimulateRequestLeakL()
       
   704     {
       
   705     RTimer timer;
       
   706 	timer.CreateLocal();
       
   707     TRequestStatus status;
       
   708     timer.After( status, KTimeInterval );
       
   709     timer.Close();
       
   710     }
       
   711