decl_pre_none.cpp 2.8 KB

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