camerasrv_plat/asynchronous_file_saving_queue_api/tsrc/inc/TestFramework/testCase.h
branchRCL_3
changeset 20 e3cdd00b5ae3
parent 19 18fa9327a158
child 21 27fe719c32e6
equal deleted inserted replaced
19:18fa9327a158 20:e3cdd00b5ae3
     1 /*
       
     2 * Copyright (c) 2002-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:  FSQ Test DLL
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __CPPUNIT_CTESTCASE_H
       
    21 #define __CPPUNIT_CTESTCASE_H
       
    22 
       
    23 #include <e32base.h>
       
    24 #include "TestFramework/test.h"
       
    25 #include <StifTestModule.h>
       
    26 class CAssertFailure;
       
    27 class CTestResult;
       
    28 class CppUnitLog;
       
    29 
       
    30 /*
       
    31  * A test case defines the fixture to run multiple tests. To define a test case
       
    32  * 1) implement a subclass of CTestCase
       
    33  * 2) define instance variables that store the state of the fixture
       
    34  * 3) initialize the fixture state by overriding setUp
       
    35  * 4) clean-up after a test by overriding tearDown.
       
    36  *
       
    37  * Each test runs in its own fixture so there can be no side effects 
       
    38  * among test runs. Here is an example:
       
    39  * 
       
    40  * class CMathTest : public CTestCase 
       
    41  * {
       
    42  *     public:
       
    43  *
       
    44  *     void setUpL () 
       
    45  *     {
       
    46  *         iValue1 = 2;
       
    47  *         iValue2 = 3;
       
    48  *     }
       
    49  *     
       
    50  *     private:
       
    51  *
       
    52  *     TInt iValue1, iValue2;
       
    53  * }
       
    54  * 
       
    55  * For each test implement a method which interacts with the fixture.
       
    56  * Verify the expected results with assertions specified
       
    57  * by calling assert on the expression you want to test:
       
    58  * 
       
    59  *    protected: 
       
    60  *    void testAddL ()
       
    61  *    {
       
    62  *        TInt result = value1 + value2;
       
    63  *        assertL (result == 5);
       
    64  *    }
       
    65  * 
       
    66  * The tests to be run can be collected into a CTestSuite:
       
    67  * 
       
    68  * public: 
       
    69  * static CMathTest::suiteL ()
       
    70  * {
       
    71  *      CTestSuite *suiteOfTests = CTestSuite::NewL(_L8("aSuite"));
       
    72  *      suiteOfTests->addTestL(CTestCaller<MathTest>::NewL(_L8("testAddL"), testAddL));
       
    73  *      return suiteOfTests;
       
    74  * }
       
    75  *
       
    76  * see CTestSuite and CTestCaller
       
    77  *
       
    78  */
       
    79 
       
    80 
       
    81 class CTestCase : public MTest, public CBase 
       
    82 	{
       
    83 public:
       
    84 
       
    85      ~CTestCase ();
       
    86 
       
    87     // From MTest:
       
    88      void ExecuteL (TTestResult& aResult);
       
    89 
       
    90 	// From MTest:
       
    91      TInt CountTestCases ();
       
    92 	
       
    93 	// From MTest:
       
    94      const TDesC8& Name ();
       
    95 
       
    96     // From MTest:
       
    97      void ExecuteTestL(TTestResult& aResult,
       
    98                       TInt aIndex);
       
    99 
       
   100     // From MTest:
       
   101      const TDesC8& TestCaseName (TInt aIndex);
       
   102 
       
   103 protected:
       
   104 
       
   105      virtual void ConstructL (const TDesC8& aName);
       
   106 
       
   107      void AssertL (TBool aCondition, 
       
   108                            const TDesC8& aConditionExpression,
       
   109                            TInt  aLineNumber,
       
   110                            const TDesC8& aFileName);
       
   111 
       
   112      void AssertEqualsL (TInt  aExpected, 
       
   113                                  TInt  aActual,
       
   114                                  TInt  aLineNumber,
       
   115                                  const TDesC8& aFileName);
       
   116 
       
   117      void AssertEqualsL (TReal aExpected,
       
   118                                  TReal aActual, 
       
   119                                  TReal aDelta, 
       
   120                                  TInt  aLineNumber,
       
   121                                  const TDesC8& aFileName);
       
   122 
       
   123      void AssertEqualsL (const TDesC8&  aExpected, 
       
   124                                  const TDesC8&  aActual,
       
   125                                  TInt           aLineNumber,
       
   126                                  const          TDesC8& aFileName);
       
   127 
       
   128      void AssertEqualsL (const TDesC16& aExpected, 
       
   129                                  const TDesC16& aActual,
       
   130                                  TInt           aLineNumber,
       
   131                                  const          TDesC8& aFileName);
       
   132 
       
   133 	 void AllocFailureSimulation (TBool aSwitchedOn);
       
   134 
       
   135     virtual void setUpL () = 0;
       
   136     virtual void executeTestL () { }
       
   137     virtual void tearDown () = 0;
       
   138 
       
   139 	 CTestCase ();
       
   140 
       
   141 private:
       
   142 
       
   143 	TInt ExecuteImplL ();
       
   144 
       
   145     HBufC8* NotEqualsMessageLC (const TDesC8& aExpected,
       
   146                                 const TDesC8& aActual);
       
   147 
       
   148     HBufC8* NotEqualsMessageLC (const TDesC16& aExpected,
       
   149                                 const TDesC16& aActual);
       
   150 
       
   151 	void AssertFailureToTlsL (const TDesC8& aMessage,
       
   152 	                          TInt  aLineNumber,
       
   153 	                          const TDesC8& aFileName);
       
   154 
       
   155 	CAssertFailure* AssertFailureFromTlsL ();
       
   156 
       
   157 	TInt HeapCellsReservedByAssertFailure ();
       
   158 
       
   159     // data
       
   160     HBufC8* iName;
       
   161 	RHeap::TAllocFail iAllocFailureType;
       
   162 	TUint iAllocFailureRate;
       
   163 	};
       
   164 
       
   165 
       
   166 // A set of macros which allow us to get the line number
       
   167 // and file name at the point of an assertion failure:
       
   168 
       
   169 #undef assertL
       
   170 #define assertL(condition)\
       
   171         (this->AssertL ((condition), TPtrC8((TText8*)(#condition)),\
       
   172                         __LINE__, TPtrC8((TText8*)__FILE__)))
       
   173 
       
   174 // Macros for primitive value comparisons
       
   175 #define assertTIntsEqualL(expected,actual)\
       
   176         (this->AssertEqualsL ((expected), (actual),\
       
   177                               __LINE__, TPtrC8((TText8*)__FILE__)))
       
   178 
       
   179 #define assertTRealsEqualL(expected,actual,delta)\
       
   180         (this->AssertEqualsL ((expected), (actual), (delta),\
       
   181                               __LINE__,TPtrC8((TText8*)__FILE__)))
       
   182 
       
   183 
       
   184 // Macros for descriptor comparisons
       
   185 #define assertTDesC8sEqualL(expected,actual)\
       
   186         (this->AssertEqualsL ((expected), (actual),\
       
   187                               __LINE__, TPtrC8((TText8*)__FILE__)))
       
   188 
       
   189 #define assertTDesC16sEqualL(expected,actual)\
       
   190         (this->AssertEqualsL ((expected), (actual),\
       
   191                               __LINE__, TPtrC8((TText8*)__FILE__)))
       
   192 
       
   193 #if defined(_UNICODE)
       
   194 #define assertTDesCsEqualL(expected,actual) assertTDesC16sEqualL(expected,actual)
       
   195 #else
       
   196 #define assertTDesCsEqualL(expected,actual) assertTDesC8sEqualL(expected,actual)
       
   197 #endif
       
   198 
       
   199 
       
   200 #endif