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

前端 未结 6 830
名媛妹妹
名媛妹妹 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:29

    Since Boost 1.59 internal details of realization was changed and Omnifarious's solution doesn't compile.

    Reason ot that is changing signature of boost::unit_test::make_test_case function: now it take 2 additional args: __FILE__, __LINE__

    Fixed solution:

    #if BOOST_VERSION > 105800
    #define MY_BOOST_TEST_ADD_ARGS __FILE__, __LINE__,
    #define MY_BOOST_TEST_DEFAULT_DEC_COLLECTOR ,boost::unit_test::decorator::collector::instance()
    #else
    #define MY_BOOST_TEST_ADD_ARGS
    #define MY_BOOST_TEST_DEFAULT_DEC_COLLECTOR
    #endif
    
    #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; \
       void test_method(const param_t &);                                   \
    };                                                                      \
                                                                            \
    void BOOST_AUTO_TC_INVOKER( test_name )(const test_name::param_t ¶m) \
    {                                                                       \
        test_name t;                                                        \
        t.test_method(param);                                               \
    }                                                                       \
                                                                            \
    BOOST_AUTO_TU_REGISTRAR( test_name )(                                   \
        boost::unit_test::make_test_case(                                   \
           &BOOST_AUTO_TC_INVOKER( test_name ), #test_name,                 \
           MY_BOOST_TEST_ADD_ARGS                                           \
           (mbegin), (mend))                                                \
           MY_BOOST_TEST_DEFAULT_DEC_COLLECTOR);                            \
                                                                            \
    void test_name::test_method(const param_t ¶m)                       \
    
    
    
    
    #define BOOST_AUTO_PARAM_TEST_CASE( test_name, mbegin, mend )           \
       BOOST_FIXTURE_PARAM_TEST_CASE( test_name,                            \
                                      BOOST_AUTO_TEST_CASE_FIXTURE,         \
                                      mbegin, mend)
    

提交回复
热议问题