decl_entry_inv_none.cpp 3.2 KB

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