decl_entry_static_inv_none.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 entry 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. int main() {
  14. std::ostringstream ok; ok // Test nothing fails.
  15. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  16. << "c::inv" << std::endl
  17. << "b::inv" << std::endl
  18. << "a::inv" << std::endl
  19. #endif
  20. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
  21. << "c::f::pre" << std::endl
  22. #endif
  23. #ifndef BOOST_CONTRACT_NO_OLDS
  24. << "c::f::old" << std::endl
  25. << "b::f::old" << std::endl
  26. << "a::f::old" << std::endl
  27. #endif
  28. << "a::f::body" << std::endl
  29. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  30. << "c::inv" << std::endl
  31. << "b::inv" << std::endl
  32. << "a::inv" << std::endl
  33. #endif
  34. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  35. << "c::f::old" << std::endl
  36. << "c::f::post" << std::endl
  37. << "b::f::old" << std::endl
  38. << "b::f::post" << std::endl
  39. << "a::f::post" << std::endl
  40. #endif
  41. ;
  42. #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  43. #define BOOST_CONTRACT_TEST_entry_inv 0
  44. #else
  45. #define BOOST_CONTRACT_TEST_entry_inv 1
  46. #endif
  47. a aa;
  48. a_entry_static_inv = true;
  49. b_entry_static_inv = true;
  50. c_entry_static_inv = true;
  51. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  52. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  53. out.str("");
  54. aa.f();
  55. BOOST_TEST(out.eq(ok.str()));
  56. a_entry_static_inv = false;
  57. b_entry_static_inv = true;
  58. c_entry_static_inv = true;
  59. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  60. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  61. out.str("");
  62. aa.f();
  63. BOOST_TEST(out.eq(ok.str()));
  64. a_entry_static_inv = true;
  65. b_entry_static_inv = false;
  66. c_entry_static_inv = true;
  67. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  68. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  69. out.str("");
  70. aa.f();
  71. BOOST_TEST(out.eq(ok.str()));
  72. a_entry_static_inv = true;
  73. b_entry_static_inv = true;
  74. c_entry_static_inv = false;
  75. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  76. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  77. out.str("");
  78. aa.f();
  79. BOOST_TEST(out.eq(ok.str()));
  80. a_entry_static_inv = false;
  81. b_entry_static_inv = false;
  82. c_entry_static_inv = false;
  83. a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
  84. BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
  85. out.str("");
  86. aa.f();
  87. BOOST_TEST(out.eq(ok.str()));
  88. #undef BOOST_CONTRACT_TEST_entry_inv
  89. return boost::report_errors();
  90. }