unit_test_example_04.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // (C) Copyright Gennadiy Rozental 2005-2014.
  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. // See http://www.boost.org/libs/test for the library home page.
  6. // Boost.Test
  7. #define BOOST_TEST_MODULE Unit_test_example_04
  8. #include <boost/test/unit_test.hpp>
  9. namespace bt=boost::unit_test;
  10. //____________________________________________________________________________//
  11. struct suite_fixture {
  12. suite_fixture() { BOOST_TEST_MESSAGE( "Running some test suite setup" ); }
  13. ~suite_fixture() { BOOST_TEST_MESSAGE( "Running some test suite teardown" ); }
  14. };
  15. struct suite_fixture2 {
  16. suite_fixture2() { BOOST_TEST_MESSAGE( "Running some more test suite setup" ); }
  17. ~suite_fixture2() { BOOST_TEST_MESSAGE( "Running some more test suite teardown" ); }
  18. };
  19. // automatically registered test cases could be organized in test suites
  20. BOOST_AUTO_TEST_SUITE( my_suite1,
  21. * bt::fixture<suite_fixture>()
  22. * bt::fixture<suite_fixture2>() )
  23. BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(my_test1,1)
  24. void some_setup()
  25. {
  26. BOOST_TEST_MESSAGE( "Running some extra setup" );
  27. }
  28. auto& d =
  29. * bt::label( "L1" )
  30. * bt::label( "L2" )
  31. * bt::description( "test case 1 description" )
  32. * bt::fixture( &some_setup );
  33. BOOST_AUTO_TEST_CASE( my_test1 )
  34. {
  35. BOOST_TEST( 2 == 1 );
  36. }
  37. //____________________________________________________________________________//
  38. // this test case belongs to suite1 test suite
  39. BOOST_AUTO_TEST_CASE( my_test2, * bt::description( "test case 2 description" ) )
  40. {
  41. int i = 0;
  42. BOOST_TEST( i == 2 );
  43. BOOST_TEST( i == 0 );
  44. }
  45. BOOST_AUTO_TEST_SUITE_END()
  46. //____________________________________________________________________________//
  47. // this test case belongs to master test suite
  48. BOOST_AUTO_TEST_CASE( my_test3 )
  49. {
  50. int i = 0;
  51. BOOST_TEST( i == 0 );
  52. }
  53. //____________________________________________________________________________//
  54. BOOST_TEST_DECORATOR(
  55. * bt::label( "L3" )
  56. * bt::description( "suite description" )
  57. )
  58. BOOST_AUTO_TEST_SUITE( my_suite2 )
  59. // this test case belongs to suite2 test suite
  60. BOOST_AUTO_TEST_CASE( my_test4, * bt::depends_on( "my_suite2/internal_suite/my_test5" ) )
  61. {
  62. int i = 0;
  63. BOOST_CHECK_EQUAL( i, 1 );
  64. }
  65. BOOST_AUTO_TEST_SUITE( internal_suite )
  66. // this test case belongs to my_suite2:internal_suite test suite
  67. BOOST_TEST_DECORATOR(
  68. * bt::timeout( 100 )
  69. )
  70. BOOST_AUTO_TEST_CASE( my_test5, * bt::expected_failures( 1 ) )
  71. {
  72. int i = 0;
  73. BOOST_CHECK_EQUAL( i, 1 );
  74. }
  75. BOOST_AUTO_TEST_CASE( my_test6, *bt::disabled() )
  76. {
  77. }
  78. BOOST_AUTO_TEST_CASE( this_should_also_be_disabled,
  79. * bt::depends_on( "my_suite2/internal_suite/disabled_suite/my_test7" ) )
  80. {
  81. }
  82. BOOST_AUTO_TEST_SUITE( disabled_suite, * bt::disabled() )
  83. BOOST_AUTO_TEST_CASE( my_test7 ) {}
  84. BOOST_AUTO_TEST_SUITE_END()
  85. BOOST_AUTO_TEST_SUITE_END()
  86. BOOST_AUTO_TEST_SUITE_END()
  87. //____________________________________________________________________________//
  88. // EOF