decl_post_none.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 postconditions.
  6. #define BOOST_CONTRACT_TEST_NO_A_POST
  7. #define BOOST_CONTRACT_TEST_NO_B_POST
  8. #define BOOST_CONTRACT_TEST_NO_C_POST
  9. #include "decl.hpp"
  10. #include <boost/detail/lightweight_test.hpp>
  11. #include <sstream>
  12. int main() {
  13. std::ostringstream ok; ok // Test nothing fails.
  14. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  15. << "c::static_inv" << std::endl
  16. << "c::inv" << std::endl
  17. << "b::static_inv" << std::endl
  18. << "b::inv" << std::endl
  19. << "a::static_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::static_inv" << std::endl
  33. << "c::inv" << std::endl
  34. << "b::static_inv" << std::endl
  35. << "b::inv" << std::endl
  36. << "a::static_inv" << std::endl
  37. << "a::inv" << std::endl
  38. #endif
  39. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  40. // No postconditions.
  41. << "c::f::old" << std::endl
  42. << "b::f::old" << std::endl
  43. #endif
  44. ;
  45. a aa;
  46. a_post = true;
  47. b_post = true;
  48. c_post = true;
  49. out.str("");
  50. aa.f();
  51. BOOST_TEST(out.eq(ok.str()));
  52. a_post = false;
  53. b_post = true;
  54. c_post = true;
  55. out.str("");
  56. aa.f();
  57. BOOST_TEST(out.eq(ok.str()));
  58. a_post = true;
  59. b_post = false;
  60. c_post = true;
  61. out.str("");
  62. aa.f();
  63. BOOST_TEST(out.eq(ok.str()));
  64. a_post = true;
  65. b_post = true;
  66. c_post = false;
  67. out.str("");
  68. aa.f();
  69. BOOST_TEST(out.eq(ok.str()));
  70. a_post = false;
  71. b_post = false;
  72. c_post = false;
  73. out.str("");
  74. aa.f();
  75. BOOST_TEST(out.eq(ok.str()));
  76. return boost::report_errors();
  77. }