decl_exit_inv_none.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 grandparent classes (ends) with exit 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/detail/lightweight_test.hpp>
  11. #include <sstream>
  12. int main() {
  13. std::ostringstream ok; ok // Test nothing fails.
  14. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
  15. << "a::ctor::pre" << std::endl
  16. << "b::ctor::pre" << std::endl
  17. << "c::ctor::pre" << std::endl
  18. #endif
  19. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  20. << "c::static_inv" << std::endl
  21. #endif
  22. #ifndef BOOST_CONTRACT_NO_OLDS
  23. << "c::ctor::old" << std::endl
  24. #endif
  25. << "c::ctor::body" << std::endl
  26. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  27. << "c::static_inv" << std::endl
  28. #endif
  29. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  30. << "c::ctor::post" << std::endl
  31. #endif
  32. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  33. << "b::static_inv" << std::endl
  34. #endif
  35. #ifndef BOOST_CONTRACT_NO_OLDS
  36. << "b::ctor::old" << std::endl
  37. #endif
  38. << "b::ctor::body" << std::endl
  39. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  40. << "b::static_inv" << std::endl
  41. #endif
  42. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  43. << "b::ctor::post" << std::endl
  44. #endif
  45. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
  46. << "a::static_inv" << std::endl
  47. #endif
  48. #ifndef BOOST_CONTRACT_NO_OLDS
  49. << "a::ctor::old" << std::endl
  50. #endif
  51. << "a::ctor::body" << std::endl
  52. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
  53. << "a::static_inv" << std::endl
  54. #endif
  55. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
  56. << "a::ctor::post" << std::endl
  57. #endif
  58. ;
  59. a_exit_inv = true;
  60. b_exit_inv = true;
  61. c_exit_inv = true;
  62. {
  63. out.str("");
  64. a aa;
  65. BOOST_TEST(out.eq(ok.str()));
  66. }
  67. a_exit_inv = false;
  68. b_exit_inv = true;
  69. c_exit_inv = true;
  70. {
  71. out.str("");
  72. a aa;
  73. BOOST_TEST(out.eq(ok.str()));
  74. }
  75. a_exit_inv = true;
  76. b_exit_inv = false;
  77. c_exit_inv = true;
  78. {
  79. out.str("");
  80. a aa;
  81. BOOST_TEST(out.eq(ok.str()));
  82. }
  83. a_exit_inv = true;
  84. b_exit_inv = true;
  85. c_exit_inv = false;
  86. {
  87. out.str("");
  88. a aa;
  89. BOOST_TEST(out.eq(ok.str()));
  90. }
  91. a_exit_inv = false;
  92. b_exit_inv = false;
  93. c_exit_inv = false;
  94. {
  95. out.str("");
  96. a aa;
  97. BOOST_TEST(out.eq(ok.str()));
  98. }
  99. return boost::report_errors();
  100. }