diff options
Diffstat (limited to 'src/boost/libs/contract/test/check')
-rw-r--r-- | src/boost/libs/contract/test/check/audit.cpp | 11 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/audit.hpp | 36 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/audit_disabled.cpp | 8 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/audit_disabled_error.cpp | 9 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/audit_error.cpp | 9 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/axiom.cpp | 8 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/axiom.hpp | 23 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/axiom_error.cpp | 9 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/decl.hpp | 66 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/decl_class.cpp | 11 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/decl_macro.cpp | 11 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/ifdef.cpp | 90 | ||||
-rw-r--r-- | src/boost/libs/contract/test/check/ifdef_macro.cpp | 63 |
13 files changed, 354 insertions, 0 deletions
diff --git a/src/boost/libs/contract/test/check/audit.cpp b/src/boost/libs/contract/test/check/audit.cpp new file mode 100644 index 00000000..cb0765ea --- /dev/null +++ b/src/boost/libs/contract/test/check/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/check/audit.hpp b/src/boost/libs/contract/test/check/audit.hpp new file mode 100644 index 00000000..0b649ed9 --- /dev/null +++ b/src/boost/libs/contract/test/check/audit.hpp @@ -0,0 +1,36 @@ + +// 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/check.hpp> +#include <boost/contract/core/exception.hpp> +#include <boost/detail/lightweight_test.hpp> + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + boost::contract::set_check_failure([] { throw err(); }); + + bool threw = false; + try { + #ifdef BOOST_CONTRACT_TEST_ERROR + BOOST_CONTRACT_CHECK_AUDIT( + BOOST_CONTRACT_TEST_ERROR_expected_undeclared_identifier); + #else + BOOST_CONTRACT_CHECK_AUDIT(false); + #endif + } catch(err const&) { threw = true; } + + #if defined(BOOST_CONTRACT_AUDITS) && !defined(BOOST_CONTRACT_NO_CHECKS) + BOOST_TEST(threw); + #else + BOOST_TEST(!threw); + #endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/check/audit_disabled.cpp b/src/boost/libs/contract/test/check/audit_disabled.cpp new file mode 100644 index 00000000..18c6ad03 --- /dev/null +++ b/src/boost/libs/contract/test/check/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/check/audit_disabled_error.cpp b/src/boost/libs/contract/test/check/audit_disabled_error.cpp new file mode 100644 index 00000000..c58714dc --- /dev/null +++ b/src/boost/libs/contract/test/check/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/check/audit_error.cpp b/src/boost/libs/contract/test/check/audit_error.cpp new file mode 100644 index 00000000..c58714dc --- /dev/null +++ b/src/boost/libs/contract/test/check/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/check/axiom.cpp b/src/boost/libs/contract/test/check/axiom.cpp new file mode 100644 index 00000000..b24af7a4 --- /dev/null +++ b/src/boost/libs/contract/test/check/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/check/axiom.hpp b/src/boost/libs/contract/test/check/axiom.hpp new file mode 100644 index 00000000..ddf87f8c --- /dev/null +++ b/src/boost/libs/contract/test/check/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/check.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_CHECK_AXIOM( + BOOST_CONTRACT_TEST_ERROR_expected_undeclared_identifier); + #else + BOOST_CONTRACT_CHECK_AXIOM(false); // Test always false, OK. + BOOST_CONTRACT_CHECK_AXIOM(no_impl()); // Test no implementation, OK. + #endif + return 0; +} + diff --git a/src/boost/libs/contract/test/check/axiom_error.cpp b/src/boost/libs/contract/test/check/axiom_error.cpp new file mode 100644 index 00000000..a7c4c406 --- /dev/null +++ b/src/boost/libs/contract/test/check/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/check/decl.hpp b/src/boost/libs/contract/test/check/decl.hpp new file mode 100644 index 00000000..1b592fb3 --- /dev/null +++ b/src/boost/libs/contract/test/check/decl.hpp @@ -0,0 +1,66 @@ + +// 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 check (class and macro). + +#include "../detail/oteststream.hpp" +#include <boost/contract/check.hpp> +#include <boost/contract/assert.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +void f(bool check) { + #ifdef BOOST_CONTRACT_TEST_CHECK_MACRO + BOOST_CONTRACT_CHECK([&] () -> bool { + out << "f::check" << std::endl; + return check; + }()); + #else + boost::contract::check c = [&] { + out << "f::check" << std::endl; + BOOST_CONTRACT_ASSERT(check); + }; + #endif + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(true); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_CHECKS + << "f::check" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + boost::contract::set_check_failure([] { throw err(); }); + + out.str(""); + try { + f(false); + #ifndef BOOST_CONTRACT_NO_CHECKS + BOOST_TEST(false); + } catch(err const&) { + ok.str(""); + ok << "f::check" << std::endl; + #else + ok.str(""); + ok << "f::body" << std::endl; + #endif + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/check/decl_class.cpp b/src/boost/libs/contract/test/check/decl_class.cpp new file mode 100644 index 00000000..eb586341 --- /dev/null +++ b/src/boost/libs/contract/test/check/decl_class.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 + +// Test check class. + +#undef BOOST_CONTRACT_TEST_CHECK_MACRO +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/check/decl_macro.cpp b/src/boost/libs/contract/test/check/decl_macro.cpp new file mode 100644 index 00000000..f36ce189 --- /dev/null +++ b/src/boost/libs/contract/test/check/decl_macro.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 + +// Test check macro. + +#define BOOST_CONTRACT_TEST_CHECK_MACRO +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/check/ifdef.cpp b/src/boost/libs/contract/test/check/ifdef.cpp new file mode 100644 index 00000000..561eb76e --- /dev/null +++ b/src/boost/libs/contract/test/check/ifdef.cpp @@ -0,0 +1,90 @@ + +// 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 contract compilation on/off. + +#include "../detail/oteststream.hpp" +#include <boost/contract/core/config.hpp> +#ifndef BOOST_CONTRACT_NO_CHECKS + #include <boost/contract/check.hpp> + #include <boost/contract/assert.hpp> +#else + #include <boost/contract/core/check_macro.hpp> + #include <boost/contract/core/exception.hpp> +#endif +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f(bool check1, bool check2) { + BOOST_CONTRACT_CHECK([&] () -> bool { // Macro already so #ifdef needed. + out << "f::check1" << std::endl; + return check1; + }()); + #ifndef BOOST_CONTRACT_NO_CHECKS + boost::contract::check c = [&] { + out << "f::check2" << std::endl; + BOOST_CONTRACT_ASSERT(check2); + }; + #endif + out << "f::body" << std::endl; +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + out.str(""); + f(true, true); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_CHECKS + << "f::check1" << std::endl + << "f::check2" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + boost::contract::set_check_failure([] { throw err(); }); + + out.str(""); + try { + f(false, true); + #ifndef BOOST_CONTRACT_NO_CHECKS + BOOST_TEST(false); + } catch(err const&) { + ok.str(""); + ok << "f::check1" << std::endl; + #else + ok.str(""); + ok << "f::body" << std::endl; + #endif + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + out.str(""); + try { + f(true, false); + #ifndef BOOST_CONTRACT_NO_CHECKS + BOOST_TEST(false); + } catch(err const&) { + ok.str(""); + ok << "f::check1" << std::endl; + ok << "f::check2" << std::endl; + #else + ok.str(""); + ok << "f::body" << std::endl; + #endif + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + // No need to test `f(false, false)` because same as `f(false, true)`. + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/check/ifdef_macro.cpp b/src/boost/libs/contract/test/check/ifdef_macro.cpp new file mode 100644 index 00000000..67616a89 --- /dev/null +++ b/src/boost/libs/contract/test/check/ifdef_macro.cpp @@ -0,0 +1,63 @@ + +// 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 contract compilation on/off (using macro interface only). + +#include "../detail/oteststream.hpp" +#include "../detail/unprotected_commas.hpp" +#include <boost/contract_macro.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f(bool check) { + BOOST_CONTRACT_CHECK(( + [&] () -> bool { + boost::contract::test::detail::unprotected_commas<void, void, void> + ::call(); + out << "f::check" << std::endl; + return check; + }() + )); + out << "f::body" << std::endl; +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + out.str(""); + f(true); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_CHECKS + << "f::check" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + boost::contract::set_check_failure([] { throw err(); }); + + out.str(""); + try { + f(false); + #ifndef BOOST_CONTRACT_NO_CHECKS + BOOST_TEST(false); + } catch(err const&) { + ok.str(""); + ok << "f::check" << std::endl; + #else + ok.str(""); + ok << "f::body" << std::endl; + #endif + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + |