mirror of
https://github.com/boostorg/contract.git
synced 2026-02-27 04:52:22 +00:00
added .old(...)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Test contract checking and old value copies disabled within contracts.
|
||||
|
||||
#include "../aux_/oteststream.hpp"
|
||||
#include "../aux_/cpcnt.hpp"
|
||||
#include "../aux_/counter.hpp"
|
||||
#include <boost/contract/oldof.hpp>
|
||||
#include <boost/contract/guard.hpp>
|
||||
#include <boost/contract/public_function.hpp>
|
||||
@@ -17,7 +17,8 @@ struct a {
|
||||
void invariant() const { out << "a::inv" << std::endl; }
|
||||
static void static_invariant() { out << "a::static_inv" << std::endl; }
|
||||
|
||||
struct x_tag; typedef boost::contract::aux::test::cpcnt<x_tag, int> x_type;
|
||||
struct x_tag;
|
||||
typedef boost::contract::aux::test::counter<x_tag, int> x_type;
|
||||
|
||||
int f(x_type& x) {
|
||||
int result;
|
||||
@@ -25,6 +26,7 @@ struct a {
|
||||
x_type::eval(x));
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
.precondition([&] { out << "a::f::pre" << std::endl; })
|
||||
.old([&] { out << "a::f::old" << std::endl; })
|
||||
.postcondition([&] {
|
||||
out << "a::f::post" << std::endl;
|
||||
BOOST_CONTRACT_ASSERT(x.value == -old_x->value);
|
||||
@@ -54,6 +56,7 @@ struct b {
|
||||
out << "b::g::pre" << std::endl;
|
||||
BOOST_CONTRACT_ASSERT(call_f());
|
||||
})
|
||||
.old([&] { out << "b::g::old" << std::endl; })
|
||||
.postcondition([&] {
|
||||
out << "b::g::post" << std::endl;
|
||||
BOOST_CONTRACT_ASSERT(call_f());
|
||||
@@ -77,11 +80,14 @@ int main() {
|
||||
// Test only f's body (but not its contract) executed here.
|
||||
<< "a::f::body" << std::endl
|
||||
|
||||
<< "b::g::old" << std::endl
|
||||
|
||||
<< "b::g::body" << std::endl
|
||||
|
||||
<< "b::static_inv" << std::endl
|
||||
<< "b::inv" << std::endl
|
||||
|
||||
// No old call here because not a base object.
|
||||
<< "b::g::post" << std::endl
|
||||
// Test only f's body (but not its contract) executed here.
|
||||
<< "a::f::body" << std::endl
|
||||
@@ -100,9 +106,11 @@ int main() {
|
||||
<< "a::static_inv" << std::endl
|
||||
<< "a::inv" << std::endl
|
||||
<< "a::f::pre" << std::endl
|
||||
<< "a::f::old" << std::endl
|
||||
<< "a::f::body" << std::endl
|
||||
<< "a::static_inv" << std::endl
|
||||
<< "a::inv" << std::endl
|
||||
// No old call here because not a base object.
|
||||
<< "a::f::post" << std::endl
|
||||
;
|
||||
BOOST_TEST(out.eq(ok.str()));
|
||||
|
||||
Reference in New Issue
Block a user