1 // (C) Copyright Raffi Enficiaud 2018.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 //! @file
9 //! checking the clashing names, ticket trac #12597
10 // *****************************************************************************
11
12 #define BOOST_TEST_MODULE test_clashing_names
13 #include <boost/test/unit_test.hpp>
14 #include <boost/test/utils/string_cast.hpp>
15 #include <boost/mpl/list.hpp>
16 #include <boost/bind.hpp>
17
suite1_test1()18 void suite1_test1()
19 {
20 BOOST_CHECK(true);
21 }
22
BOOST_AUTO_TEST_CASE(test_clashing_suites)23 BOOST_AUTO_TEST_CASE( test_clashing_suites )
24 {
25 using namespace boost::unit_test;
26 test_suite* master_ts = BOOST_TEST_SUITE("local master");
27 test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
28 test_suite* t_suite2 = BOOST_TEST_SUITE( "suite1" );
29 master_ts->add(t_suite1);
30 BOOST_CHECK_NO_THROW( master_ts->add(t_suite2) );
31
32 master_ts->p_default_status.value = test_unit::RS_ENABLED;
33 BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
34 boost::unit_test::framework::setup_error );
35 }
36
BOOST_AUTO_TEST_CASE(test_clashing_cases)37 BOOST_AUTO_TEST_CASE( test_clashing_cases )
38 {
39 using namespace boost::unit_test;
40 test_suite* master_ts = BOOST_TEST_SUITE("local master");
41 test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
42 test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" );
43 master_ts->add(t_suite1);
44 master_ts->add(t_suite2);
45
46 t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) );
47 BOOST_CHECK_NO_THROW( t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) ) );
48 BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
49 boost::unit_test::framework::setup_error );
50
51 BOOST_CHECK_NO_THROW( t_suite2->add( BOOST_TEST_CASE( suite1_test1 ) ) );
52 }
53
BOOST_TEST_CASE_TEMPLATE_FUNCTION(template_test_case,T)54 BOOST_TEST_CASE_TEMPLATE_FUNCTION( template_test_case, T )
55 {
56 BOOST_TEST( sizeof(T) == 4U );
57 }
58
BOOST_AUTO_TEST_CASE(test_clashing_cases_template_test_case)59 BOOST_AUTO_TEST_CASE( test_clashing_cases_template_test_case )
60 {
61 using namespace boost::unit_test;
62 test_suite* master_ts = BOOST_TEST_SUITE("local master");
63 test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
64 test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" );
65 master_ts->add(t_suite1);
66 master_ts->add(t_suite2);
67
68 typedef boost::mpl::list<int, long, unsigned char> test_types1;
69 typedef boost::mpl::list<int, long, unsigned char, int> test_types2;
70
71 BOOST_CHECK_NO_THROW( t_suite2->add( BOOST_TEST_CASE_TEMPLATE( template_test_case, test_types1 ) ) );
72 BOOST_CHECK_NO_THROW(framework::finalize_setup_phase( master_ts->p_id ));
73
74 BOOST_CHECK_NO_THROW( t_suite1->add( BOOST_TEST_CASE_TEMPLATE( template_test_case, test_types2 ) ) );
75 BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
76 boost::unit_test::framework::setup_error );
77 }
78
test2(int value)79 void test2(int value)
80 {
81 BOOST_TEST(value >= 0);
82 }
83
84
BOOST_AUTO_TEST_CASE(test_clashing_cases_with_name)85 BOOST_AUTO_TEST_CASE( test_clashing_cases_with_name )
86 {
87 using namespace boost::unit_test;
88 test_suite* master_ts = BOOST_TEST_SUITE("local master");
89
90 test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
91 master_ts->add(t_suite1);
92 t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) );
93 t_suite1->add( BOOST_TEST_CASE( boost::bind( test2, 0 ) ) );
94 BOOST_CHECK_NO_THROW( t_suite1->add( BOOST_TEST_CASE( boost::bind( test2, 0 ) ) ) );
95 BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
96 boost::unit_test::framework::setup_error );
97
98 for(int i = 0; i < 10; i++) {
99 t_suite1->add( BOOST_TEST_CASE_NAME( boost::bind( test2, i ), "test-X-" + boost::unit_test::utils::string_cast(i) ) );
100 }
101 }
102