decl_pre_none.cpp 2.4 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 preconditions.
  6. #define BOOST_CONTRACT_TEST_NO_A_PRE
  7. #define BOOST_CONTRACT_TEST_NO_B_PRE
  8. #define BOOST_CONTRACT_TEST_NO_C_PRE
  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. // No preconditions here.
  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::static_inv" << std::endl
  31. << "c::inv" << std::endl
  32. << "b::static_inv" << std::endl
  33. << "b::inv" << std::endl
  34. << "a::static_inv" << std::endl
  35. << "a::inv" << std::endl
  36. #endif
  37. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  38. << "c::f::old" << std::endl // Old only if post (or except) run.
  39. << "c::f::post" << std::endl
  40. << "b::f::old" << std::endl
  41. << "b::f::post" << std::endl
  42. << "a::f::post" << std::endl
  43. #endif
  44. ;
  45. a aa;
  46. a_pre = true;
  47. b_pre = true;
  48. c_pre = true;
  49. out.str("");
  50. aa.f();
  51. BOOST_TEST(out.eq(ok.str()));
  52. a_pre = true;
  53. b_pre = false;
  54. c_pre = false;
  55. out.str("");
  56. aa.f();
  57. BOOST_TEST(out.eq(ok.str()));
  58. a_pre = false;
  59. b_pre = true;
  60. c_pre = false;
  61. out.str("");
  62. aa.f();
  63. BOOST_TEST(out.eq(ok.str()));
  64. a_pre = false;
  65. b_pre = false;
  66. c_pre = true;
  67. out.str("");
  68. aa.f();
  69. BOOST_TEST(out.eq(ok.str()));
  70. a_pre = false;
  71. b_pre = false;
  72. c_pre = false;
  73. out.str("");
  74. aa.f();
  75. BOOST_TEST(out.eq(ok.str()));
  76. return boost::report_errors();
  77. }