1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/*=============================================================================
Copyright (c) 2017 Daniel James
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include <vector>
#include <boost/core/lightweight_test.hpp>
#include "cleanup.hpp"
struct counted
{
static int count;
static std::vector<int> destroyed;
static void reset()
{
count = 0;
destroyed.clear();
}
int value;
counted(int v) : value(v)
{
BOOST_TEST(value != -1);
++count;
}
counted(counted const& x) : value(x.value)
{
BOOST_TEST(value != -1);
++count;
}
~counted()
{
BOOST_TEST(value != -1);
destroyed.push_back(value);
value = -1;
BOOST_TEST(count > 0);
--count;
}
};
int counted::count = 0;
std::vector<int> counted::destroyed;
int main()
{
counted::reset();
{
quickbook::cleanup c;
}
BOOST_TEST(counted::count == 0);
counted::reset();
{
quickbook::cleanup c;
counted& v1 = c.add(new counted(1));
counted& v2 = c.add(new counted(2));
BOOST_TEST(v1.value == 1);
BOOST_TEST(v2.value == 2);
}
BOOST_TEST(counted::count == 0);
BOOST_TEST(counted::destroyed.size() == 2);
BOOST_TEST(counted::destroyed[0] == 2);
BOOST_TEST(counted::destroyed[1] == 1);
counted::reset();
{
quickbook::cleanup c;
int& x = c.add(new int(10));
BOOST_TEST(x == 10);
}
return boost::report_errors();
}
|