Is it possible to use BOOST_PARAM_TEST_CASE with automatic registration on boost::test?

前端 未结 6 833
名媛妹妹
名媛妹妹 2021-02-14 03:50

Is it possible to mix up the BOOST_AUTO_TEST_CASE and BOOST_AUTO_TEST_CASE_TEMPLATE macros with the BOOST_PARAM_TEST_CASE in any way? I\'m

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-14 04:50

    I took Omnifarious' header file and modified it such that the parameter is passed to the constructor of the test fixture rather than to the test method. This requires the test fixture's constructor declaration to take a single argument with the parameter's type. I found this to be super handy--much thanks for the initial question and answer!

    #include 
    #include 
    #include 
    
    #define BOOST_FIXTURE_PARAM_TEST_CASE( test_name, F, mbegin, mend )     \
    struct test_name : public F {                                           \
        typedef ::std::remove_const< ::std::remove_reference< decltype(*(mbegin)) >::type>::type param_t; \
        test_name(const param_t ¶m) : F(param) {}                       \
        void test_method(void);                                             \
    };                                                                      \
                                                                            \
    void BOOST_AUTO_TC_INVOKER( test_name )(const test_name::param_t ¶m)\
    {                                                                       \
        test_name t(param);                                                 \
        t.test_method();                                                    \
    }                                                                       \
                                                                            \
    BOOST_AUTO_TU_REGISTRAR( test_name )(                                   \
        boost::unit_test::make_test_case(                                   \
           &BOOST_AUTO_TC_INVOKER( test_name ), #test_name,                 \
           (mbegin), (mend)));                                              \
                                                                            \
    void test_name::test_method(void)                                       \
    
    // *******
    
    #define BOOST_AUTO_PARAM_TEST_CASE( test_name, mbegin, mend )           \
       BOOST_FIXTURE_PARAM_TEST_CASE( test_name,                            \
                                      BOOST_AUTO_TEST_CASE_FIXTURE,         \
                                      mbegin, mend)
    

提交回复
热议问题