resolved most todo and recompiled most examples and tests

This commit is contained in:
Lorenzo Caminiti
2016-06-04 09:41:03 -07:00
parent 128a42c004
commit 21f228d80b
39 changed files with 430 additions and 128 deletions

View File

@@ -187,9 +187,6 @@ test-suite function
[ subdir-run-with-no function : body_throw ]
[ subdir-run-with-no function : old_throw ]
[ subdir-run-with-no function : check_if ]
[ subdir-compile-fail function : no_check_if_error ]
;
test-suite result
@@ -245,22 +242,27 @@ test-suite disable
<library>disable-lib_x <library>disable-lib_y ]
;
test-suite set
test-suite specify
:
[ subdir-run-with-no set : pre_old_post ]
[ subdir-run-with-no set : pre_old ]
[ subdir-run-with-no set : old_post ]
[ subdir-run-with-no set : pre_post ]
[ subdir-run-with-no set : pre ]
[ subdir-run-with-no set : old ]
[ subdir-run-with-no set : post ]
[ subdir-run-with-no set : nothing ]
[ subdir-run-with-no specify : pre_old_post ]
[ subdir-run-with-no specify : pre_old ]
[ subdir-run-with-no specify : old_post ]
[ subdir-run-with-no specify : pre_post ]
[ subdir-run-with-no specify : pre ]
[ subdir-run-with-no specify : old ]
[ subdir-run-with-no specify : post ]
[ subdir-run-with-no specify : nothing ]
[ subdir-run-with-no set : no_guard ]
[ subdir-run-with-no specify : no_guard ]
[ subdir-compile-fail set : old_pre_error ]
[ subdir-compile-fail set : post_old_error ]
[ subdir-compile-fail set : post_pre_error ]
[ subdir-compile-fail specify : old_pre_error ]
[ subdir-compile-fail specify : post_old_error ]
[ subdir-compile-fail specify : post_pre_error ]
;
test-suite misc
:
[ subdir-run-with-no misc : mutex ]
;
test-suite call_if
@@ -272,6 +274,9 @@ test-suite call_if
[ subdir-run call_if : false_void ]
[ subdir-run call_if : equal_to ]
[ subdir-run-with-no call_if : check_if ]
[ subdir-compile-fail call_if : no_check_if_error ]
;
# C++14 supported only by Clang... so in its own test-suite and explicit.

View File

@@ -36,32 +36,32 @@ int a::f(x_type& x) {
void a::disable_pre_failure() {
boost::contract::set_precondition_failure([] (boost::contract::from)
{ out("a::pre_failure"); });
{ out("a::pre_failure\n"); });
}
void a::disable_post_failure() {
boost::contract::set_postcondition_failure([] (boost::contract::from)
{ out("a::post_failure"); });
{ out("a::post_failure\n"); });
}
void a::disable_entry_inv_failure() {
boost::contract::set_entry_invariant_failure([] (boost::contract::from)
{ out("a::entry_inv_failure"); });
{ out("a::entry_inv_failure\n"); });
}
void a::disable_exit_inv_failure() {
boost::contract::set_exit_invariant_failure([] (boost::contract::from)
{ out("a::exit_inv_failure"); });
{ out("a::exit_inv_failure\n"); });
}
void a::disable_inv_failure() {
boost::contract::set_invariant_failure([] (boost::contract::from)
{ out("a::inv_failure"); });
{ out("a::inv_failure\n"); });
}
void a::disable_failure() {
boost::contract::set_failure([] (boost::contract::from)
{ out("a::failure"); });
{ out("a::failure\n"); });
}
#endif // #include guard

View File

@@ -50,7 +50,7 @@ int main() {
// Test preconditions have disabled no contract (incorrect, but
// only possible behaviour if shared linking not used ad doc).
<< ok_f()
#elif defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NOTHING)
#elif defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION)
// Test preconditions have disabled no contract.
<< ok_f()
#else
@@ -82,7 +82,7 @@ int main() {
// Test old values not copied for disabled contracts.
unsigned const cnt =
#if defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NOTHING) && \
#if defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION) && \
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
1
@@ -105,53 +105,53 @@ int main() {
out("");
boost::contract::precondition_failure(boost::contract::from());
BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(),
"a::pre_failure"));
"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"));
"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"));
"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"));
"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"));
"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"));
"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"));
"a::failure\n"));
out("");
boost::contract::postcondition_failure(boost::contract::from());
BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(),
"a::failure"));
"a::failure\n"));
out("");
boost::contract::entry_invariant_failure(boost::contract::from());
BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(),
"a::failure"));
"a::failure\n"));
out("");
boost::contract::exit_invariant_failure(boost::contract::from());
BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(),
"a::failure"));
"a::failure\n"));
// Test setting failure handlers (from a lib using another lib).

View File

@@ -39,7 +39,7 @@ bool b::test_disable_pre_failure() {
out("");
boost::contract::precondition_failure(boost::contract::from());
return boost::contract::test::detail::oteststream::eq(out(),
"a::pre_failure");
"a::pre_failure\n");
}
bool b::test_disable_post_failure() {
@@ -47,7 +47,7 @@ bool b::test_disable_post_failure() {
out("");
boost::contract::postcondition_failure(boost::contract::from());
return boost::contract::test::detail::oteststream::eq(out(),
"a::post_failure");
"a::post_failure\n");
}
bool b::test_disable_entry_inv_failure() {
@@ -55,7 +55,7 @@ bool b::test_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");
"a::entry_inv_failure\n");
}
bool b::test_disable_exit_inv_failure() {
@@ -63,7 +63,7 @@ bool b::test_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");
"a::exit_inv_failure\n");
}
bool b::test_disable_inv_failure() {
@@ -71,11 +71,11 @@ bool b::test_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");
"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");
"a::inv_failure\n");
return entry_inv && exit_inv;
}
@@ -84,19 +84,19 @@ bool b::test_disable_failure() {
out("");
boost::contract::precondition_failure(boost::contract::from());
bool pre = boost::contract::test::detail::oteststream::eq(out(),
"a::failure");
"a::failure\n");
out("");
boost::contract::postcondition_failure(boost::contract::from());
bool post = boost::contract::test::detail::oteststream::eq(out(),
"a::failure");
"a::failure\n");
out("");
boost::contract::entry_invariant_failure(boost::contract::from());
bool entry_inv = boost::contract::test::detail::oteststream::eq(out(),
"a::failure");
"a::failure\n");
out("");
boost::contract::exit_invariant_failure(boost::contract::from());
bool exit_inv = boost::contract::test::detail::oteststream::eq(out(),
"a::failure");
"a::failure\n");
return pre && post && entry_inv && exit_inv;
}

View File

@@ -1,7 +1,7 @@
// Test other contract checking but pre disabled within contract checking.
#define BOOST_CONTRACT_PRECONDITIONS_DISABLE_NOTHING
#define BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
#include "lib_a.hpp"
#include "lib_a_inlined.hpp"
#include "lib_b.hpp"

258
test/misc/mutex.cpp Normal file
View File

@@ -0,0 +1,258 @@
// Test scoped mutex locks before contracts (no need to also test ctors, etc.).
#include "../detail/oteststream.hpp"
#include <boost/contract.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <sstream>
boost::contract::test::detail::oteststream out;
struct b : private boost::contract::constructor_precondition<b> {
static void static_invariant() { out << "b::static_inv" << std::endl; }
void invariant() const { out << "b::inv" << std::endl; }
b() : boost::contract::constructor_precondition<b>(
[&] { out << "b::ctor::pre" << std::endl; }) {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::constructor(this)
.old([&] { out << "b::ctor::old" << std::endl; })
.postcondition([&] { out << "b::ctor::post" << std::endl; })
;
out << "b::ctor::body" << std::endl;
}
virtual ~b() {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::destructor(this)
.old([&] { out << "b::dtor::old" << std::endl; })
.postcondition([&] { out << "b::dtor::post" << std::endl; })
;
out << "b::dtor::body" << std::endl;
}
virtual void f(boost::contract::virtual_* v = 0) const {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::public_function(v, this)
.precondition([&] { out << "b::f::pre" << std::endl; })
.old([&] { out << "b::f::old" << std::endl; })
.postcondition([&] { out << "b::f::post" << std::endl; })
;
out << "b::f::body" << std::endl;
}
virtual void g(boost::contract::virtual_* v = 0) const {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::public_function(v, this)
.precondition([&] { out << "b::g::pre" << std::endl; })
.old([&] { out << "b::g::old" << std::endl; })
.postcondition([&] { out << "b::g::post" << std::endl; })
;
out << "b::g::body" << std::endl;
}
private:
mutable boost::mutex mutex_;
};
struct a
#define BASES private boost::contract::constructor_precondition<a>, public b
: BASES
{
typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
#undef BASES
static void static_invariant() { out << "a::static_inv" << std::endl; }
void invariant() const { out << "a::inv" << std::endl; }
a() : boost::contract::constructor_precondition<a>(
[&] { out << "a::ctor::pre" << std::endl; }) {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::constructor(this)
.old([&] { out << "a::ctor::old" << std::endl; })
.postcondition([&] { out << "a::ctor::post" << std::endl; })
;
out << "a::ctor::body" << std::endl;
}
~a() {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::destructor(this)
.old([&] { out << "a::dtor::old" << std::endl; })
.postcondition([&] { out << "a::dtor::post" << std::endl; })
;
out << "a::dtor::body" << std::endl;
}
void f(boost::contract::virtual_* v = 0) const /* override */ {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::public_function<override_f>(
v, &a::f, this)
.precondition([&] { out << "a::f::pre" << std::endl; })
.old([&] { out << "a::f::old" << std::endl; })
.postcondition([&] { out << "a::f::post" << std::endl; })
;
out << "a::f::body" << std::endl;
}
BOOST_CONTRACT_OVERRIDE(f)
void g(boost::contract::virtual_* v = 0) const /* override */ {
boost::mutex::scoped_lock lock(mutex_);
boost::contract::guard c = boost::contract::public_function<override_g>(
v, &a::g, this)
.precondition([&] { out << "a::g::pre" << std::endl; })
.old([&] { out << "a::g::old" << std::endl; })
.postcondition([&] { out << "a::g::post" << std::endl; })
;
out << "a::g::body" << std::endl;
}
BOOST_CONTRACT_OVERRIDE(g)
private:
mutable boost::mutex mutex_;
};
int main() {
// Unfortunately, I cannot compile Boost.Thread on Cygwin with GCC and
// CLang... I get linker errors even if I use `threadapi=pthread` and add
// `<library>/boost/thread//boost_thread` to the Jamfile.
#ifdef BOOST_MSVC
{
a aa;
boost::thread tf([&aa] { aa.f(); });
boost::thread tg([&aa] { aa.g(); });
tf.join();
tg.join();
}
std::ostringstream ok; ok // Mutexes also guarantee order of text in `out`.
// Test constructor.
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
<< "a::ctor::pre" << std::endl
<< "b::ctor::pre" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
<< "b::static_inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "b::ctor::old" << std::endl
#endif
<< "b::ctor::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::ctor::post" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
<< "a::static_inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "a::ctor::old" << std::endl
#endif
<< "a::ctor::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::ctor::post" << std::endl
#endif
// Test public functions.
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
<< "b::static_inv" << std::endl
<< "b::inv" << std::endl
<< "a::static_inv" << std::endl
<< "a::inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
<< "b::f::pre" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "b::f::old" << std::endl
<< "a::f::old" << std::endl
#endif
<< "a::f::body" << std::endl
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
<< "b::static_inv" << std::endl
<< "b::inv" << std::endl
<< "a::static_inv" << std::endl
<< "a::inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "b::f::old" << std::endl
<< "b::f::post" << std::endl
<< "a::f::post" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
<< "b::static_inv" << std::endl
<< "b::inv" << std::endl
<< "a::static_inv" << std::endl
<< "a::inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
<< "b::g::pre" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "b::g::old" << std::endl
<< "a::g::old" << std::endl
#endif
<< "a::g::body" << std::endl
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
<< "b::static_inv" << std::endl
<< "b::inv" << std::endl
<< "a::static_inv" << std::endl
<< "a::inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "b::g::old" << std::endl
<< "b::g::post" << std::endl
<< "a::g::post" << std::endl
#endif
// Test destructor.
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
<< "a::static_inv" << std::endl
<< "a::inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "a::dtor::old" << std::endl
#endif
<< "a::dtor::body" << std::endl
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
<< "a::static_inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "a::dtor::post" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
<< "b::static_inv" << std::endl
<< "b::inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "b::dtor::old" << std::endl
#endif
<< "b::dtor::body" << std::endl
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
<< "b::static_inv" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "b::dtor::post" << std::endl
#endif
;
BOOST_TEST(out.eq(ok.str()));
#endif
return boost::report_errors();
}