decl_exit_static_inv_none.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (C) 2008-2018 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  3. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  4. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  5. // Test all derived and base classes without exit static invariants.
  6. #define BOOST_CONTRACT_TEST_NO_A_STATIC_INV
  7. #define BOOST_CONTRACT_TEST_NO_B_STATIC_INV
  8. #define BOOST_CONTRACT_TEST_NO_C_STATIC_INV
  9. #include "decl.hpp"
  10. #include <boost/preprocessor/control/iif.hpp>
  11. #include <boost/detail/lightweight_test.hpp>
  12. #include <sstream>
  13. struct err {}; // Global decl so visible in MSVC10 lambdas.
  14. int main() {
  15. std::ostringstream ok; ok // Test nothing fails.
  16. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  17. // No static invariants.
  18. << "c::inv" << std::endl
  19. << "b::inv" << std::endl
  20. << "a::inv" << std::endl
  21. #endif
  22. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
  23. << "c::f::pre" << std::endl
  24. #endif
  25. #ifndef BOOST_CONTRACT_NO_OLDS
  26. << "c::f::old" << std::endl
  27. << "b::f::old" << std::endl
  28. << "a::f::old" << std::endl
  29. #endif
  30. << "a::f::body" << std::endl
  31. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  32. << "c::inv" << std::endl
  33. << "b::inv" << std::endl
  34. << "a::inv" << std::endl
  35. #endif
  36. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  37. << "c::f::old" << std::endl
  38. << "c::f::post" << std::endl
  39. << "b::f::old" << std::endl
  40. << "b::f::post" << std::endl
  41. << "a::f::post" << std::endl
  42. #endif
  43. ;
  44. boost::contract::set_exit_invariant_failure(
  45. [] (boost::contract::from) { throw err(); });
  46. #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  47. #define BOOST_CONTRACT_TEST_entry_inv 0
  48. #else
  49. #define BOOST_CONTRACT_TEST_entry_inv 1
  50. #endif
  51. a aa;
  52. a_exit_static_inv = true;
  53. b_exit_static_inv = true;
  54. c_exit_static_inv = true;
  55. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  56. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  57. out.str("");
  58. aa.f();
  59. BOOST_TEST(out.eq(ok.str()));
  60. a_exit_static_inv = false;
  61. b_exit_static_inv = true;
  62. c_exit_static_inv = true;
  63. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  64. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  65. out.str("");
  66. aa.f();
  67. BOOST_TEST(out.eq(ok.str()));
  68. a_exit_static_inv = true;
  69. b_exit_static_inv = false;
  70. c_exit_static_inv = true;
  71. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  72. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  73. out.str("");
  74. aa.f();
  75. BOOST_TEST(out.eq(ok.str()));
  76. a_exit_static_inv = true;
  77. b_exit_static_inv = true;
  78. c_exit_static_inv = false;
  79. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  80. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  81. out.str("");
  82. aa.f();
  83. BOOST_TEST(out.eq(ok.str()));
  84. a_exit_static_inv = false;
  85. b_exit_static_inv = false;
  86. c_exit_static_inv = false;
  87. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  88. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  89. out.str("");
  90. aa.f();
  91. BOOST_TEST(out.eq(ok.str()));
  92. #undef BOOST_CONTRACT_TEST_entry_inv
  93. return boost::report_errors();
  94. }