LCOV - code coverage report
Current view: top level - usr/include/cppunit/extensions - TestSuiteBuilderContext.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 6 6 100.0 %
Date: 2025-08-24 09:11:10 Functions: 93 99 93.9 %

          Line data    Source code
       1             : #ifndef CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
       2             : #define CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
       3             : 
       4             : #include <cppunit/Portability.h>
       5             : #include <map>
       6             : #include <string>
       7             : 
       8             : #if CPPUNIT_NEED_DLL_DECL
       9             : #pragma warning( push )
      10             : #pragma warning( disable: 4251 )  // X needs to have dll-interface to be used by clients of class Z
      11             : #endif
      12             : 
      13             : 
      14             : CPPUNIT_NS_BEGIN
      15             : 
      16             : class TestSuite;
      17             : class TestFixture;
      18             : class TestFixtureFactory;
      19             : class TestNamer;
      20             : 
      21             : /*! \brief Context used when creating test suite in HelperMacros.
      22             :  *
      23             :  * Base class for all context used when creating test suite. The
      24             :  * actual context type during test suite creation is TestSuiteBuilderContext.
      25             :  *
      26             :  * \sa CPPUNIT_TEST_SUITE, CPPUNIT_TEST_SUITE_ADD_TEST, 
      27             :  *     CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS.
      28             :  */
      29             : class CPPUNIT_API TestSuiteBuilderContextBase
      30             : {
      31             : public:
      32             :   /*! \brief Constructs a new context.
      33             :    *
      34             :    * You should not use this. The context is created in 
      35             :    * CPPUNIT_TEST_SUITE().
      36             :    */
      37             :   TestSuiteBuilderContextBase( TestSuite &suite,
      38             :                                const TestNamer &namer,
      39             :                                TestFixtureFactory &factory );
      40             : 
      41             :   virtual ~TestSuiteBuilderContextBase();
      42             : 
      43          46 :   TestSuiteBuilderContextBase(TestSuiteBuilderContextBase const &) = default;
      44             :   TestSuiteBuilderContextBase(TestSuiteBuilderContextBase &&) = default;
      45             :   TestSuiteBuilderContextBase & operator =(TestSuiteBuilderContextBase const &) = delete;
      46             :   TestSuiteBuilderContextBase & operator =(TestSuiteBuilderContextBase &&) = delete;
      47             : 
      48             :   /*! \brief Adds a test to the fixture suite.
      49             :    *
      50             :    * \param test Test to add to the fixture suite. Must not be \c NULL.
      51             :    */
      52             :   void addTest( Test *test );
      53             : 
      54             :   /*! \brief Returns the fixture name.
      55             :    * \return Fixture name. It is the name used to name the fixture
      56             :    *         suite.
      57             :    */
      58             :   std::string getFixtureName() const;
      59             : 
      60             :   /*! \brief Returns the name of the test for the specified method.
      61             :    *
      62             :    * \param testMethodName Name of the method that implements a test.
      63             :    * \return A string that is the concatenation of the test fixture name 
      64             :    *         (returned by getFixtureName()) and\a testMethodName, 
      65             :    *         separated using '::'. This provides a fairly unique name for a given
      66             :    *         test.
      67             :    */
      68             :   std::string getTestNameFor( const std::string &testMethodName ) const;
      69             : 
      70             :   /*! \brief Returns the name of the test for the specified method with the corresponding parameter.
      71             :    *
      72             :    * \param testMethodName Name (including a parameter) of the method that implements a test.
      73             :    * \return A string that is the concatenation of the test fixture name
      74             :    *         (returned by getFixtureName()), \a testMethodName,
      75             :    *         separated using '::' and the parameter. This provides a fairly unique name for a given
      76             :    *         test. The parameter must be convertable to std::string through operator<<
      77             :    *         or a specialization of CPPUNIT_NS::StringHelper::toString needs to exist.
      78             :    */
      79             :   template<typename T>
      80             :   std::string getTestNameFor( const std::string &testMethodName, const T& value ) const
      81             :   {
      82             :       return m_namer.getTestNameFor(testMethodName, value);
      83             :   }
      84             : 
      85             :   /*! \brief Adds property pair.
      86             :    * \param key   PropertyKey string to add.
      87             :    * \param value PropertyValue string to add.
      88             :    */
      89             :   void addProperty( const std::string &key, 
      90             :                     const std::string &value );
      91             :   
      92             :   /*! \brief Returns property value assigned to param key.
      93             :    * \param key PropertyKey string.
      94             :    */
      95             :   const std::string getStringProperty( const std::string &key ) const;
      96             : 
      97             : protected:
      98             :   TestFixture *makeTestFixture() const;
      99             : 
     100             :   // Notes: we use a vector here instead of a map to work-around the
     101             :   // shared std::map in dll bug in VC6.
     102             :   // See http://www.dinkumware.com/vc_fixes.html for detail.
     103             :   typedef std::pair<std::string,std::string> Property;
     104             :   typedef std::vector<Property> Properties;
     105             : 
     106             :   TestSuite &m_suite;
     107             :   const TestNamer &m_namer;
     108             :   TestFixtureFactory &m_factory;
     109             : 
     110             : private:
     111             :   Properties m_properties;
     112             : };
     113             : 
     114             : 
     115             : /*! \brief Type-sage context used when creating test suite in HelperMacros.
     116             :  * 
     117             :  * \sa TestSuiteBuilderContextBase.
     118             :  */
     119             : template<class Fixture>
     120             : class TestSuiteBuilderContext : public TestSuiteBuilderContextBase
     121             : {
     122             : public:
     123             :   typedef Fixture FixtureType;
     124             : 
     125          46 :   TestSuiteBuilderContext( TestSuiteBuilderContextBase &contextBase )
     126          46 :       : TestSuiteBuilderContextBase( contextBase )
     127             :   {
     128          46 :   }
     129             : 
     130             :   /*! \brief Returns a new TestFixture instance.
     131             :    * \return A new fixture instance. The fixture instance is returned by
     132             :    *         the TestFixtureFactory passed on construction. The actual type 
     133             :    *         is that of the fixture on which the static method suite() 
     134             :    *         was called.
     135             :    */
     136         287 :   FixtureType *makeFixture() const
     137             :   {
     138         287 :     return CPPUNIT_STATIC_CAST( FixtureType *, 
     139             :                                 TestSuiteBuilderContextBase::makeTestFixture() );
     140             :   }
     141             : };
     142             : 
     143             : 
     144             : CPPUNIT_NS_END
     145             : 
     146             : #if CPPUNIT_NEED_DLL_DECL
     147             : #pragma warning( pop )
     148             : #endif
     149             : 
     150             : #endif // CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
     151             : 

Generated by: LCOV version 1.14