fixture_04.run-fail.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // (C) Copyright Raffi Enficiaud 2017.
  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 fixture_04
  8. #include <boost/test/included/unit_test.hpp>
  9. struct MyGlobalFixture {
  10. MyGlobalFixture() {
  11. BOOST_TEST_MESSAGE( "ctor fixture i=" << i );
  12. }
  13. void setup() {
  14. BOOST_TEST_MESSAGE( "setup fixture i=" << i );
  15. i++;
  16. }
  17. void teardown() {
  18. BOOST_TEST_MESSAGE( "teardown fixture i=" << i );
  19. i += 2;
  20. }
  21. ~MyGlobalFixture() {
  22. BOOST_TEST_MESSAGE( "dtor fixture i=" << i );
  23. }
  24. static int i;
  25. };
  26. int MyGlobalFixture::i = 0;
  27. BOOST_TEST_GLOBAL_FIXTURE( MyGlobalFixture );
  28. BOOST_AUTO_TEST_CASE(test_case1)
  29. {
  30. BOOST_TEST_MESSAGE("running test_case1");
  31. BOOST_TEST(MyGlobalFixture::i == 1);
  32. }
  33. BOOST_AUTO_TEST_CASE(test_case2)
  34. {
  35. BOOST_TEST_MESSAGE("running test_case2");
  36. BOOST_TEST(MyGlobalFixture::i == 3);
  37. }
  38. //]