/* Unit testing for outcomes
-(C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
+(C) 2013-2020 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
Boost Software License - Version 1.0 - August 17th, 2003
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_monitor.hpp>
+/* Should be this:
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+
+78 move constructor count = 2
+65 move assignment count = 3
+78 move assignment count = 1
+65 move constructor count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+
+78 move constructor count = 1
+65 move assignment count = 2
+78 move assignment count = 0
+65 move assignment count = 1
+78 move assignment count = 0
+*/
+
#ifndef BOOST_NO_EXCEPTIONS
#ifdef _MSC_VER
#pragma warning(push)
{
if(mc)
{
- std::cout << id << " move constructor count = " << count << std::endl;
+ std::cout << " " << id << " move constructor count = " << count << std::endl;
if(!count)
{
+ std::cout << " " << id << " move constructor throws!" << std::endl;
throw std::bad_alloc();
}
}
count = o.count - o.inc;
if(ma)
{
- std::cout << o.id << " move assignment count = " << count << std::endl;
+ std::cout << " " << o.id << " move assignment count = " << count << std::endl;
if(!count)
{
+ std::cout << " " << o.id << " move assignment throws!" << std::endl;
throw std::bad_alloc();
}
}
static_assert(!detail::is_nothrow_swappable<throwy_t>::value, "is_nothrow_swappable is not correct!");
+ std::cout << "Result value first swap succeeds, second swap second move assignment throws:" << std::endl;
{
throwy a(3, 78), b(4, 65);
a.swap(b);
BOOST_CHECK(!a.has_lost_consistency());
BOOST_CHECK(!b.has_lost_consistency());
}
- std::cout << std::endl;
+ std::cout << "\nResult value second move assignment throws, on recover second move assignment throws:" << std::endl;
{
throwy a(2, 78), b(3, 65); // fails on second assignment, cannot restore
try
BOOST_CHECK(b.has_lost_consistency());
}
}
- std::cout << std::endl;
}
+ std::cout << "\nResult error first swap succeeds, second swap first move assignment throws:" << std::endl;
{ // Does swap implement the strong guarantee?
using throwy_t = Throwy<true, true>;
using throwy = resulty2<true, true>;
BOOST_CHECK(!a.has_lost_consistency());
BOOST_CHECK(!b.has_lost_consistency());
}
- std::cout << std::endl;
+ std::cout << "\nResult error second move assignment throws, on recover second move assignment throws:" << std::endl;
{
throwy a(2, 78), b(3, 65); // fails on second assignment, cannot restore
try
BOOST_CHECK(b.has_lost_consistency());
}
}
- std::cout << std::endl;
}
{ // Is noexcept propagated?
static_assert(noexcept(a.swap(b)), "type has a throwing swap!");
}
+ std::cout << "\n\nOutcome value first swap succeeds, second swap first move assignment throws:" << std::endl;
{ // Does swap implement the strong guarantee?
using throwy_t = Throwy<true, true>;
using throwy = outcomey1<true, true>;
BOOST_CHECK(!a.has_lost_consistency());
BOOST_CHECK(!b.has_lost_consistency());
}
- std::cout << std::endl;
+ std::cout << "\nOutcome value second move assignment throws, on recover second move assignment throws:" << std::endl;
{
throwy a(2, 78), b(3, 65); // fails on second assignment, cannot restore
try
BOOST_CHECK(b.has_lost_consistency());
}
}
- std::cout << std::endl;
}
+ std::cout << "\nOutcome error first swap succeeds, second swap first move assignment throws:" << std::endl;
{ // Does swap implement the strong guarantee?
using throwy_t = Throwy<true, true>;
using throwy = outcomey2<true, true>;
BOOST_CHECK(!a.has_lost_consistency());
BOOST_CHECK(!b.has_lost_consistency());
}
- std::cout << std::endl;
+ std::cout << "\nOutcome error second move assignment throws, on recover second move assignment throws:" << std::endl;
{
throwy a(2, 78), b(3, 65); // fails on second assignment, cannot restore
try