camerasrv_plat/camera_application_engine_api/tsrc/inc/TestFrameWork/testCaller.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 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: CTestCaller
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CPPUNIT_TESTCALLER_H
       
    21 #define CPPUNIT_TESTCALLER_H
       
    22 
       
    23 #include "TestFrameWork/testCase.h"
       
    24 
       
    25 
       
    26 /* 
       
    27  * A test caller provides access to a test case method 
       
    28  * on a test case class.  Test callers are useful when 
       
    29  * you want to run an individual test or add it to a suite.
       
    30  * 
       
    31  * Here is an example:
       
    32  * 
       
    33  * class CMathTest : public CTestCase 
       
    34  * {
       
    35  *     public:
       
    36  *         void         setUpL ();
       
    37  *         void         tearDown ();
       
    38  *
       
    39  *     protected:
       
    40  *         void         testAddL ();
       
    41  *         void         testSubtractL ();
       
    42  * };
       
    43  *
       
    44  * CTest* CMathTest::suiteL () 
       
    45  * {
       
    46  *     CTestSuite *suite = CTestSuite::NewL();
       
    47  *     suite->addTestL(CTestCaller<MathTest>::NewL(_L("testAddL") testAddL));
       
    48  *     suite->addTestL(CTestCaller<MathTest>::NewL(_L("testSubtractL") testSubtractL));
       
    49  *     return suite;
       
    50  * }
       
    51  *
       
    52  * You can use a CTestCaller to bind any test method on a CTestCase
       
    53  * class, as long as it does not have parameters and returns void.
       
    54  * 
       
    55  * See CTestCase
       
    56  */
       
    57 
       
    58 
       
    59 template <class Fixture> class CTestCaller : public CTestCase
       
    60 	{
       
    61 public:
       
    62 
       
    63     typedef void (Fixture::*TestMethod)();
       
    64 
       
    65     static CTestCaller* NewLC (const TDesC8& aName, TestMethod aTest);
       
    66     static CTestCaller* NewL (const TDesC8& aName, TestMethod aTest);
       
    67 	~CTestCaller();
       
    68 
       
    69 protected:
       
    70  
       
    71     // From CTestCase:
       
    72     void setUpL ()       { iFixture->setUpL (); }
       
    73     void executeTestL () { (iFixture->*iTest)(); } 
       
    74     void tearDown ()     { iFixture->tearDown (); }
       
    75 
       
    76 private:
       
    77 
       
    78     CTestCaller (TestMethod aTest) : iTest(aTest) { }
       
    79     void ConstructL (const TDesC8& aName);
       
    80 
       
    81     TestMethod iTest;
       
    82     Fixture    *iFixture;
       
    83 	};
       
    84 
       
    85 
       
    86 template <class Fixture>
       
    87 CTestCaller<Fixture>* CTestCaller<Fixture>::NewLC (const TDesC8& aName,
       
    88                                                    TestMethod aTest)
       
    89 	{
       
    90 	CTestCaller* self = new(ELeave) CTestCaller(aTest);
       
    91 	CleanupStack::PushL(self);
       
    92 	self->ConstructL(aName);
       
    93 	return self;
       
    94 	}
       
    95 
       
    96 template <class Fixture> 
       
    97 CTestCaller<Fixture>* CTestCaller<Fixture>::NewL (const TDesC8& aName,
       
    98                                                   TestMethod aTest)
       
    99 	{
       
   100 	CTestCaller* self = NewLC(aName, aTest);
       
   101 	CleanupStack::Pop();
       
   102 	return self;
       
   103 	}
       
   104 
       
   105 
       
   106 template <class Fixture>
       
   107 void CTestCaller<Fixture>::ConstructL (const TDesC8& aName)
       
   108 	{
       
   109 	CTestCase::ConstructL(aName);
       
   110 	iFixture = new(ELeave)Fixture;
       
   111 	}
       
   112 
       
   113 
       
   114 template <class Fixture>
       
   115 CTestCaller<Fixture>::~CTestCaller () 
       
   116 	{
       
   117 	delete iFixture;
       
   118 	}
       
   119 
       
   120 #endif