decorator_08.run-fail.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // (C) Copyright Andrzej Krzemienski 2015.
  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. //[example_code
  7. #define BOOST_TEST_MODULE decorator_08
  8. #include <boost/test/included/unit_test.hpp>
  9. namespace utf = boost::unit_test;
  10. namespace tt = boost::test_tools;
  11. BOOST_AUTO_TEST_CASE(test1)
  12. {
  13. BOOST_TEST(true);
  14. }
  15. BOOST_AUTO_TEST_CASE(test2)
  16. {
  17. BOOST_TEST(false);
  18. }
  19. struct if_either
  20. {
  21. std::string tc1, tc2;
  22. if_either(std::string t1, std::string t2)
  23. : tc1(t1), tc2(t2) {}
  24. tt::assertion_result operator()(utf::test_unit_id)
  25. {
  26. auto& master = utf::framework::master_test_suite();
  27. auto& collector = utf::results_collector_t::instance();
  28. auto& test1_result = collector.results(master.get(tc1));
  29. auto& test2_result = collector.results(master.get(tc2));
  30. if (test1_result.passed() || test2_result.passed())
  31. return true;
  32. tt::assertion_result ans(false);
  33. ans.message() << tc1 << " and " << tc2 << " failed";
  34. return ans;
  35. }
  36. };
  37. BOOST_AUTO_TEST_CASE(test3,
  38. * utf::precondition(if_either("test1", "test2")))
  39. {
  40. BOOST_TEST(false);
  41. }
  42. BOOST_AUTO_TEST_CASE(test4,
  43. * utf::precondition(if_either("test2", "test3")))
  44. {
  45. BOOST_TEST(false);
  46. }
  47. //]