example82_contexts.run-fail.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 example82
  8. #include <boost/test/included/unit_test.hpp>
  9. struct Processor
  10. {
  11. int level;
  12. void optimization_level(int l) { level = l; }
  13. bool op1(int) { return level < 2; }
  14. bool op2(int, int) { return level < 1; }
  15. };
  16. void test_operations(Processor& processor, int limit)
  17. {
  18. for (int i = 0; i < limit; ++i) {
  19. BOOST_TEST_CONTEXT("With parameter i = " << i) {
  20. BOOST_TEST(processor.op1(i));
  21. for (int j = 0; j < i; ++j) {
  22. BOOST_TEST_INFO("With parameter j = " << j);
  23. BOOST_TEST(processor.op2(i, j));
  24. }
  25. }
  26. }
  27. }
  28. BOOST_AUTO_TEST_CASE(test1)
  29. {
  30. Processor processor;
  31. for (int level = 0; level < 3; ++level) {
  32. BOOST_TEST_CONTEXT("With optimization level " << level) {
  33. processor.optimization_level(level);
  34. test_operations(processor, 2);
  35. }
  36. }
  37. }
  38. //]