diff options
Diffstat (limited to 'src/boost/libs/contract/test/disable')
27 files changed, 888 insertions, 0 deletions
diff --git a/src/boost/libs/contract/test/disable/audit.cpp b/src/boost/libs/contract/test/disable/audit.cpp new file mode 100644 index 00000000..cb0765ea --- /dev/null +++ b/src/boost/libs/contract/test/disable/audit.cpp @@ -0,0 +1,11 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#ifndef BOOST_CONTRACT_AUDITS + #error "build must define AUDITS" +#endif +#include "audit.hpp" + diff --git a/src/boost/libs/contract/test/disable/audit.hpp b/src/boost/libs/contract/test/disable/audit.hpp new file mode 100644 index 00000000..c2b2236c --- /dev/null +++ b/src/boost/libs/contract/test/disable/audit.hpp @@ -0,0 +1,32 @@ + +// no #include guard + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include <boost/contract/assert.hpp> +#include <boost/contract/core/exception.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() { + bool threw = false; + try { + #ifdef BOOST_CONTRACT_TEST_ERROR + BOOST_CONTRACT_ASSERT_AUDIT( + BOOST_CONTRACT_TEST_ERROR_expected_undeclared_identifier); + #else + BOOST_CONTRACT_ASSERT_AUDIT(false); + #endif + } catch(boost::contract::assertion_failure const&) { threw = true; } + + #if defined(BOOST_CONTRACT_AUDITS) && !defined(BOOST_CONTRACT_NO_ALL) + BOOST_TEST(threw); + #else + BOOST_TEST(!threw); + #endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/disable/audit_disabled.cpp b/src/boost/libs/contract/test/disable/audit_disabled.cpp new file mode 100644 index 00000000..18c6ad03 --- /dev/null +++ b/src/boost/libs/contract/test/disable/audit_disabled.cpp @@ -0,0 +1,8 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "audit.hpp" + diff --git a/src/boost/libs/contract/test/disable/audit_disabled_error.cpp b/src/boost/libs/contract/test/disable/audit_disabled_error.cpp new file mode 100644 index 00000000..c58714dc --- /dev/null +++ b/src/boost/libs/contract/test/disable/audit_disabled_error.cpp @@ -0,0 +1,9 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#define BOOST_CONTRACT_TEST_ERROR +#include "audit.hpp" + diff --git a/src/boost/libs/contract/test/disable/audit_error.cpp b/src/boost/libs/contract/test/disable/audit_error.cpp new file mode 100644 index 00000000..c58714dc --- /dev/null +++ b/src/boost/libs/contract/test/disable/audit_error.cpp @@ -0,0 +1,9 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#define BOOST_CONTRACT_TEST_ERROR +#include "audit.hpp" + diff --git a/src/boost/libs/contract/test/disable/axiom.cpp b/src/boost/libs/contract/test/disable/axiom.cpp new file mode 100644 index 00000000..b24af7a4 --- /dev/null +++ b/src/boost/libs/contract/test/disable/axiom.cpp @@ -0,0 +1,8 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "axiom.hpp" + diff --git a/src/boost/libs/contract/test/disable/axiom.hpp b/src/boost/libs/contract/test/disable/axiom.hpp new file mode 100644 index 00000000..df5231bb --- /dev/null +++ b/src/boost/libs/contract/test/disable/axiom.hpp @@ -0,0 +1,23 @@ + +// no #include guard + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include <boost/contract/assert.hpp> + +bool no_impl(); // Test func that cannot be impl in C++ sill OK in axioms. + +int main() { + #ifdef BOOST_CONTRACT_TEST_ERROR + BOOST_CONTRACT_ASSERT_AXIOM( + BOOST_CONRACT_TEST_ERROR_expected_undeclared_identifier); + #else + BOOST_CONTRACT_ASSERT_AXIOM(false); // Test always false, OK. + BOOST_CONTRACT_ASSERT_AXIOM(no_impl()); // Test no implementation, OK. + #endif + return 0; +} + diff --git a/src/boost/libs/contract/test/disable/axiom_error.cpp b/src/boost/libs/contract/test/disable/axiom_error.cpp new file mode 100644 index 00000000..a7c4c406 --- /dev/null +++ b/src/boost/libs/contract/test/disable/axiom_error.cpp @@ -0,0 +1,9 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#define BOOST_CONTRACT_TEST_ERROR +#include "axiom.hpp" + diff --git a/src/boost/libs/contract/test/disable/lib_a.cpp b/src/boost/libs/contract/test/disable/lib_a.cpp new file mode 100644 index 00000000..a4f283de --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_a.cpp @@ -0,0 +1,14 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#define BOOST_CONTRACT_TEST_LIB_A_SOURCE +#include "lib_a.hpp" +#include <boost/contract.hpp> // All headers so test ODR for entire lib. +#ifndef BOOST_CONTRACT_HEADER_ONLY + #include "lib_a_inlined.hpp" +#endif +#include "../detail/out_inlined.hpp" + diff --git a/src/boost/libs/contract/test/disable/lib_a.hpp b/src/boost/libs/contract/test/disable/lib_a.hpp new file mode 100644 index 00000000..7f26276e --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_a.hpp @@ -0,0 +1,51 @@ + +#ifndef BOOST_CONTRACT_TEST_LIB_A_HPP_ +#define BOOST_CONTRACT_TEST_LIB_A_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "../detail/counter.hpp" +#include <boost/contract.hpp> // All headers so test ODR for entire lib. +#include <boost/config.hpp> +#include <string> + +#ifdef BOOST_CONTRACT_TEST_LIB_A_DYN_LINK + #ifdef BOOST_CONTRACT_TEST_LIB_A_SOURCE + #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC BOOST_SYMBOL_EXPORT + #else + #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC BOOST_SYMBOL_IMPORT + #endif +#else + #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC /* nothing */ +#endif + +#define BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC \ + BOOST_CONTRACT_TEST_LIB_A_DECLSPEC +#include "../detail/out.hpp" + +struct BOOST_CONTRACT_TEST_LIB_A_DECLSPEC a { + static void static_invariant(); + void invariant() const; + + struct x_tag; + typedef boost::contract::test::detail::counter<x_tag, int> x_type; + + int f(x_type& x); + + static void disable_pre_failure(); + static void disable_post_failure(); + static void disable_entry_inv_failure(); + static void disable_exit_inv_failure(); + static void disable_inv_failure(); + static void disable_failure(); +}; + +#ifdef BOOST_CONTRACT_HEADER_ONLY + #include "lib_a_inlined.hpp" +#endif + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/disable/lib_a_inlined.hpp b/src/boost/libs/contract/test/disable/lib_a_inlined.hpp new file mode 100644 index 00000000..f139bd2b --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_a_inlined.hpp @@ -0,0 +1,101 @@ + +#ifndef BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_ +#define BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "lib_a.hpp" +#include <boost/contract.hpp> // All headers so test ODR for entire lib. + +#ifdef BOOST_CONTRACT_HEADER_ONLY + #define BOOST_CONTRACT_TEST_LIB_A_DECLINLINE inline +#else + #define BOOST_CONTRACT_TEST_LIB_A_DECLINLINE /* nothing */ +#endif + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::static_invariant() { + using boost::contract::test::detail::out; + out("a::static_inv\n"); +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::invariant() const { + using boost::contract::test::detail::out; + out("a::inv\n"); +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +int a::f(x_type& x) { + using boost::contract::test::detail::out; + int result; + boost::contract::old_ptr<x_type> old_x = + BOOST_CONTRACT_OLDOF(x_type::eval(x)); + boost::contract::check c = boost::contract::public_function(this) + // Capturing [&] so out() visible in MSVC10 lambdas. + .precondition([&] { out("a::f::pre\n"); }) + .old([&] { out("a::f::old\n"); }) + .postcondition([&] { + out("a::f::post\n"); + BOOST_CONTRACT_ASSERT(x.value == -old_x->value); + BOOST_CONTRACT_ASSERT(result == old_x->value); + }) + ; + out("a::f::body\n"); + result = x.value; + x.value = -x.value; + return result; +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::disable_pre_failure() { + using boost::contract::test::detail::out; + boost::contract::set_precondition_failure([] (boost::contract::from) + { out("a::pre_failure\n"); }); +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::disable_post_failure() { + using boost::contract::test::detail::out; + boost::contract::set_postcondition_failure([] (boost::contract::from) + { out("a::post_failure\n"); }); +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::disable_entry_inv_failure() { + using boost::contract::test::detail::out; + boost::contract::set_entry_invariant_failure([] (boost::contract::from) + { out("a::entry_inv_failure\n"); }); +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::disable_exit_inv_failure() { + using boost::contract::test::detail::out; + boost::contract::set_exit_invariant_failure([] (boost::contract::from) + { out("a::exit_inv_failure\n"); }); +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::disable_inv_failure() { + using boost::contract::test::detail::out; + boost::contract::set_invariant_failure([] (boost::contract::from) + { out("a::inv_failure\n"); }); +} + +BOOST_CONTRACT_TEST_LIB_A_DECLINLINE +void a::disable_failure() { + using boost::contract::test::detail::out; + boost::contract::set_precondition_failure( + boost::contract::set_postcondition_failure( + boost::contract::set_except_failure( + boost::contract::set_old_failure( + boost::contract::set_invariant_failure( + [] (boost::contract::from) { out("a::failure\n"); } + ))))); +} + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/disable/lib_ab.hpp b/src/boost/libs/contract/test/disable/lib_ab.hpp new file mode 100644 index 00000000..f6aafdb3 --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_ab.hpp @@ -0,0 +1,164 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "lib_a.hpp" +#include "lib_b.hpp" +#include "../detail/oteststream.hpp" +#include <boost/contract/core/exception.hpp> +#include <boost/contract/core/config.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_f() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::f::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::f::old" << std::endl + #endif + << "a::f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} + +int main() { + using boost::contract::test::detail::out; + std::ostringstream ok; + b bb; + + out(""); + bb.g(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "b::g::pre" << std::endl + #ifdef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION + // Test preconditions have disabled no contract. + << ok_f() + #else + // Test call while checking executes body (but no contracts). + << "a::f::body" << std::endl + #endif + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::g::old" << std::endl + #endif + << "b::g::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::g::post" << std::endl + // Test call while checking executes body (but no contracts). + << "a::f::body" << std::endl + #endif + ; + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); + + // Test old values not copied for disabled contracts. + + #if defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION) && \ + !defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \ + !defined(BOOST_CONTRACT_NO_OLDS) + #define BOOST_CONTRACT_TEST_old 1u + #else + #define BOOST_CONTRACT_TEST_old 0u + #endif + + BOOST_TEST_EQ(a::x_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(a::x_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(a::x_type::ctors(), a::x_type::dtors()); + + // Double check a call to f outside another contract checks f's contracts. + + out(""); + call_f(); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok_f())); + + // Test setting failure handlers (from this program using a lib). + + a::disable_pre_failure(); + out(""); + boost::contract::precondition_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::pre_failure\n")); + + a::disable_post_failure(); + out(""); + boost::contract::postcondition_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::post_failure\n")); + + a::disable_entry_inv_failure(); + out(""); + boost::contract::entry_invariant_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::entry_inv_failure\n")); + + a::disable_exit_inv_failure(); + out(""); + boost::contract::exit_invariant_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::exit_inv_failure\n")); + + a::disable_inv_failure(); + out(""); + boost::contract::entry_invariant_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::inv_failure\n")); + out(""); + boost::contract::exit_invariant_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::inv_failure\n")); + + a::disable_failure(); + out(""); + boost::contract::precondition_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n")); + out(""); + boost::contract::postcondition_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n")); + out(""); + boost::contract::entry_invariant_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n")); + out(""); + boost::contract::exit_invariant_failure(boost::contract::from()); + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n")); + + // Test setting failure handlers (from a lib using another lib). + + BOOST_TEST(b::test_disable_pre_failure()); + BOOST_TEST(b::test_disable_post_failure()); + BOOST_TEST(b::test_disable_entry_inv_failure()); + BOOST_TEST(b::test_disable_exit_inv_failure()); + BOOST_TEST(b::test_disable_inv_failure()); + BOOST_TEST(b::test_disable_failure()); + + #undef BOOST_CONTRACT_TEST_old + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/disable/lib_b.cpp b/src/boost/libs/contract/test/disable/lib_b.cpp new file mode 100644 index 00000000..7d9a94a9 --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_b.cpp @@ -0,0 +1,9 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#define BOOST_CONTRACT_TEST_LIB_B_SOURCE +#include "lib_b_inlined.hpp" + diff --git a/src/boost/libs/contract/test/disable/lib_b.hpp b/src/boost/libs/contract/test/disable/lib_b.hpp new file mode 100644 index 00000000..8cc34cbc --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_b.hpp @@ -0,0 +1,41 @@ + +#ifndef BOOST_CONTRACT_TEST_LIB_B_HPP_ +#define BOOST_CONTRACT_TEST_LIB_B_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include <boost/config.hpp> + +#ifdef BOOST_CONTRACT_TEST_LIB_B_DYN_LINK + #ifdef BOOST_CONTRACT_TEST_LIB_B_SOURCE + #define BOOST_CONTRACT_TEST_LIB_B_DECLSPEC BOOST_SYMBOL_EXPORT + #else + #define BOOST_CONTRACT_TEST_LIB_B_DECLSPEC BOOST_SYMBOL_IMPORT + #endif +#else + #define BOOST_CONTRACT_TEST_LIB_B_DECLSPEC /* nothing */ +#endif + +bool BOOST_CONTRACT_TEST_LIB_B_DECLSPEC call_f(); + +struct BOOST_CONTRACT_TEST_LIB_B_DECLSPEC b { + static void static_invariant(); + void invariant() const; + + void g(); + + static bool test_disable_pre_failure(); + static bool test_disable_post_failure(); + static bool test_disable_entry_inv_failure(); + static bool test_disable_exit_inv_failure(); + static bool test_disable_inv_failure(); + static bool test_disable_failure(); + +}; + +#endif // #include guard + + diff --git a/src/boost/libs/contract/test/disable/lib_b_inlined.hpp b/src/boost/libs/contract/test/disable/lib_b_inlined.hpp new file mode 100644 index 00000000..0a7bf5a9 --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_b_inlined.hpp @@ -0,0 +1,124 @@ + +#ifndef BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_ +#define BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "lib_b.hpp" +#include "lib_a.hpp" +#include "../detail/oteststream.hpp" +#include <boost/contract.hpp> // All headers to test ODR for entire lib. + +bool call_f() { + a aa; + a::x_type x; x.value = -123; + return aa.f(x) == -123; +} + +void b::static_invariant() { + using boost::contract::test::detail::out; + out("b::static_inv\n"); +} + +void b::invariant() const { + using boost::contract::test::detail::out; + out("b::inv\n"); +} + +void b::g() { + using boost::contract::test::detail::out; + boost::contract::check c = boost::contract::public_function(this) + .precondition([&] { + out("b::g::pre\n"); + BOOST_CONTRACT_ASSERT(call_f()); + }) + .old([&] { out("b::g::old\n"); }) + .postcondition([&] { + out("b::g::post\n"); + BOOST_CONTRACT_ASSERT(call_f()); + }) + ; + out("b::g::body\n"); +} + +bool b::test_disable_pre_failure() { + using boost::contract::test::detail::out; + a::disable_pre_failure(); + out(""); + boost::contract::precondition_failure(boost::contract::from()); + return boost::contract::test::detail::oteststream::eq(out(), + "a::pre_failure\n"); +} + +bool b::test_disable_post_failure() { + using boost::contract::test::detail::out; + a::disable_post_failure(); + out(""); + boost::contract::postcondition_failure(boost::contract::from()); + return boost::contract::test::detail::oteststream::eq(out(), + "a::post_failure\n"); +} + +bool b::test_disable_entry_inv_failure() { + using boost::contract::test::detail::out; + a::disable_entry_inv_failure(); + out(""); + boost::contract::entry_invariant_failure(boost::contract::from()); + return boost::contract::test::detail::oteststream::eq(out(), + "a::entry_inv_failure\n"); +} + +bool b::test_disable_exit_inv_failure() { + using boost::contract::test::detail::out; + a::disable_exit_inv_failure(); + out(""); + boost::contract::exit_invariant_failure(boost::contract::from()); + return boost::contract::test::detail::oteststream::eq(out(), + "a::exit_inv_failure\n"); +} + +bool b::test_disable_inv_failure() { + using boost::contract::test::detail::out; + + a::disable_inv_failure(); + out(""); + boost::contract::entry_invariant_failure(boost::contract::from()); + bool entry_inv = boost::contract::test::detail::oteststream::eq(out(), + "a::inv_failure\n"); + out(""); + boost::contract::exit_invariant_failure(boost::contract::from()); + bool exit_inv = boost::contract::test::detail::oteststream::eq(out(), + "a::inv_failure\n"); + + return entry_inv && exit_inv; +} + +bool b::test_disable_failure() { + using boost::contract::test::detail::out; + + a::disable_failure(); + out(""); + boost::contract::precondition_failure(boost::contract::from()); + bool pre = boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n"); + out(""); + boost::contract::postcondition_failure(boost::contract::from()); + bool post = boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n"); + out(""); + boost::contract::entry_invariant_failure(boost::contract::from()); + bool entry_inv = boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n"); + out(""); + boost::contract::exit_invariant_failure(boost::contract::from()); + bool exit_inv = boost::contract::test::detail::oteststream::eq(out(), + "a::failure\n"); + + return pre && post && entry_inv && exit_inv; +} + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/disable/lib_x.cpp b/src/boost/libs/contract/test/disable/lib_x.cpp new file mode 100644 index 00000000..e928b47e --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_x.cpp @@ -0,0 +1,29 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Force .cpp never check post/except. +#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + #error "build must define NO_POSTCONDITIONS" +#endif +#ifndef BOOST_CONTRACT_NO_EXCEPTS + #error "build must define NO_EXCEPTS" +#endif + +#define BOOST_CONTRACT_TEST_LIB_X_SOURCE +#include "lib_x.hpp" +#include <boost/contract.hpp> // All headers so test ODR for entire lib. +#include "../detail/out_inlined.hpp" + +void x() { + using boost::contract::test::detail::out; + boost::contract::check c = boost::contract::function() + .precondition([] { out("x::pre\n"); }) + .old([] { out("x::old\n"); }) + .postcondition([] { out("x::post\n"); }) + ; + out("x::body\n"); +} + diff --git a/src/boost/libs/contract/test/disable/lib_x.hpp b/src/boost/libs/contract/test/disable/lib_x.hpp new file mode 100644 index 00000000..e64a74cc --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_x.hpp @@ -0,0 +1,30 @@ + +#ifndef BOOST_CONTRACT_TEST_LIB_X_HPP_ +#define BOOST_CONTRACT_TEST_LIB_X_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include <boost/config.hpp> +#include <string> + +#ifdef BOOST_CONTRACT_TEST_LIB_X_DYN_LINK + #ifdef BOOST_CONTRACT_TEST_LIB_X_SOURCE + #define BOOST_CONTRACT_TEST_LIB_X_DECLSPEC BOOST_SYMBOL_EXPORT + #else + #define BOOST_CONTRACT_TEST_LIB_X_DECLSPEC BOOST_SYMBOL_IMPORT + #endif +#else + #define BOOST_CONTRACT_TEST_LIB_X_DECLSPEC /* nothing */ +#endif + +#define BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC \ + BOOST_CONTRACT_TEST_LIB_X_DECLSPEC +#include "../detail/out.hpp" + +void BOOST_CONTRACT_TEST_LIB_X_DECLSPEC x(); + +#endif + diff --git a/src/boost/libs/contract/test/disable/lib_xy.hpp b/src/boost/libs/contract/test/disable/lib_xy.hpp new file mode 100644 index 00000000..0c52262e --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_xy.hpp @@ -0,0 +1,76 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Test contracts in .cpp compiled to never check post/except (but not in .hpp). + +#include "lib_x.hpp" +#include "lib_y.hpp" +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +void f() { + using boost::contract::test::detail::out; + boost::contract::check c = boost::contract::function() + // Capturing [&] so out() visible in MSVC10 lambdas. + .precondition([&] { out("f::pre\n"); }) + .old([&] { out("f::old\n"); }) + .postcondition([&] { out("f::post\n"); }) + ; + out("f::body\n"); +} + +int main() { + using boost::contract::test::detail::out; + std::ostringstream ok; + + out(""); + f(); + ok.str(""); ok // Test normal (no lib) case. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); + + out(""); + x(); + ok.str(""); ok // Test contracts in .cpp so no post (NO_POST in build file). + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "x::pre" << std::endl + #endif + << "x::body" << std::endl + ; + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); + + out(""); + y(); + ok.str(""); ok // Test contracts in .hpp so post (NO_POST in build file). + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "y::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "y::old" << std::endl + #endif + << "y::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "y::post" << std::endl + #endif + ; + BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/disable/lib_y.cpp b/src/boost/libs/contract/test/disable/lib_y.cpp new file mode 100644 index 00000000..eade2541 --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_y.cpp @@ -0,0 +1,24 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Force .cpp never check post/except. +#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + #error "build must define NO_POSTCONDITIONS" +#endif +#ifndef BOOST_CONTRACT_NO_EXCEPTS + #error "build must define NO_EXCEPTS" +#endif + +#define BOOST_CONTRACT_TEST_LIB_Y_SOURCE +#include "lib_y.hpp" + +namespace lib_y_ { + void y_body() { + using boost::contract::test::detail::out; + out("y::body\n"); + } +} + diff --git a/src/boost/libs/contract/test/disable/lib_y.hpp b/src/boost/libs/contract/test/disable/lib_y.hpp new file mode 100644 index 00000000..f2444096 --- /dev/null +++ b/src/boost/libs/contract/test/disable/lib_y.hpp @@ -0,0 +1,40 @@ + +#ifndef BOOST_CONTRACT_TEST_LIB_Y_HPP_ +#define BOOST_CONTRACT_TEST_LIB_Y_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "lib_x.hpp" +#include <boost/contract.hpp> // All headers so test ODR for entire lib. +#include <boost/config.hpp> + +#ifdef BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK + #ifdef BOOST_CONTRACT_TEST_LIB_Y_SOURCE + #define BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC BOOST_SYMBOL_EXPORT + #else + #define BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC BOOST_SYMBOL_IMPORT + #endif +#else + #define BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC /* nothing */ +#endif + +namespace lib_y_ { // Internal namepsace. + void BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC y_body(); +} + +inline void y() { + using boost::contract::test::detail::out; + boost::contract::check c = boost::contract::function() + // Capturing [&] so out() visible in MSVC10 lambdas. + .precondition([&] { out("y::pre\n"); }) + .old([&] { out("y::old\n"); }) + .postcondition([&] { out("y::post\n"); }) + ; + lib_y_::y_body(); +} + +#endif + diff --git a/src/boost/libs/contract/test/disable/no_post_except_lib.cpp b/src/boost/libs/contract/test/disable/no_post_except_lib.cpp new file mode 100644 index 00000000..eaa52e38 --- /dev/null +++ b/src/boost/libs/contract/test/disable/no_post_except_lib.cpp @@ -0,0 +1,10 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Test contracts in .cpp compiled to never check post/except (but not in .hpp). + +#include "lib_xy.hpp" + diff --git a/src/boost/libs/contract/test/disable/no_post_except_unit.cpp b/src/boost/libs/contract/test/disable/no_post_except_unit.cpp new file mode 100644 index 00000000..c5db4a7e --- /dev/null +++ b/src/boost/libs/contract/test/disable/no_post_except_unit.cpp @@ -0,0 +1,10 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Test .cpp never check post/except (in multiple compilation units). + +#include "lib_xy.hpp" + diff --git a/src/boost/libs/contract/test/disable/nothing_for_pre_prog.cpp b/src/boost/libs/contract/test/disable/nothing_for_pre_prog.cpp new file mode 100644 index 00000000..c8286f72 --- /dev/null +++ b/src/boost/libs/contract/test/disable/nothing_for_pre_prog.cpp @@ -0,0 +1,13 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Test pre disable no assertion (in programs, but same for libraries). + +#ifndef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION + #error "build must define PRECONDITIONS_DISABLE_NO_ASSERTION" +#endif +#include "prog.hpp" + diff --git a/src/boost/libs/contract/test/disable/other_assertions_lib.cpp b/src/boost/libs/contract/test/disable/other_assertions_lib.cpp new file mode 100644 index 00000000..2e68b943 --- /dev/null +++ b/src/boost/libs/contract/test/disable/other_assertions_lib.cpp @@ -0,0 +1,10 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Test assertion checking disables other assertion checking (in libraries). + +#include "lib_ab.hpp" + diff --git a/src/boost/libs/contract/test/disable/other_assertions_prog.cpp b/src/boost/libs/contract/test/disable/other_assertions_prog.cpp new file mode 100644 index 00000000..b5fc359c --- /dev/null +++ b/src/boost/libs/contract/test/disable/other_assertions_prog.cpp @@ -0,0 +1,10 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Test assertion checking disables other assertion checking (in programs). + +#include "prog.hpp" + diff --git a/src/boost/libs/contract/test/disable/other_assertions_unit.cpp b/src/boost/libs/contract/test/disable/other_assertions_unit.cpp new file mode 100644 index 00000000..c1bdea41 --- /dev/null +++ b/src/boost/libs/contract/test/disable/other_assertions_unit.cpp @@ -0,0 +1,10 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// Test assertions disables other assertions (in multiple compilation units). + +#include "lib_ab.hpp" + diff --git a/src/boost/libs/contract/test/disable/prog.hpp b/src/boost/libs/contract/test/disable/prog.hpp new file mode 100644 index 00000000..a20bb723 --- /dev/null +++ b/src/boost/libs/contract/test/disable/prog.hpp @@ -0,0 +1,13 @@ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "lib_a.hpp" +#include "lib_a_inlined.hpp" +#include "lib_b.hpp" +#include "lib_b_inlined.hpp" +#include "lib_ab.hpp" +#include "../detail/out_inlined.hpp" + |