| 1 | /* |
| 2 | Copyright 2014 Glen Joseph Fernandes |
| 3 | (glenjofe@gmail.com) |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. |
| 6 | (http://www.boost.org/LICENSE_1_0.txt) |
| 7 | */ |
| 8 | #include <boost/config.hpp> |
| 9 | #if !defined(BOOST_NO_CXX11_SMART_PTR) |
| 10 | #include <boost/core/lightweight_test.hpp> |
| 11 | #include <boost/smart_ptr/make_unique.hpp> |
| 12 | |
| 13 | class type { |
| 14 | public: |
| 15 | static unsigned instances; |
| 16 | |
| 17 | type(int v1 = 0, |
| 18 | int v2 = 0, |
| 19 | int v3 = 0, |
| 20 | int v4 = 0, |
| 21 | int v5 = 0, |
| 22 | int v6 = 0, |
| 23 | int v7 = 0, |
| 24 | int v8 = 0, |
| 25 | int v9 = 0) |
| 26 | : sum_(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) { |
| 27 | ++instances; |
| 28 | } |
| 29 | |
| 30 | ~type() { |
| 31 | --instances; |
| 32 | } |
| 33 | |
| 34 | int sum() const { |
| 35 | return sum_; |
| 36 | } |
| 37 | |
| 38 | private: |
| 39 | int sum_; |
| 40 | |
| 41 | type(const type&); |
| 42 | type& operator=(const type&); |
| 43 | }; |
| 44 | |
| 45 | unsigned type::instances = 0; |
| 46 | |
| 47 | int main() |
| 48 | { |
| 49 | BOOST_TEST(type::instances == 0); |
| 50 | { |
| 51 | std::unique_ptr<type> result = boost::make_unique<type>(); |
| 52 | BOOST_TEST(result.get() != 0); |
| 53 | BOOST_TEST(type::instances == 1); |
| 54 | BOOST_TEST(result->sum() == 0); |
| 55 | result.reset(); |
| 56 | BOOST_TEST(type::instances == 0); |
| 57 | } |
| 58 | |
| 59 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) |
| 60 | { |
| 61 | std::unique_ptr<type> result = boost::make_unique<type>(args: 1); |
| 62 | BOOST_TEST(result.get() != 0); |
| 63 | BOOST_TEST(type::instances == 1); |
| 64 | BOOST_TEST(result->sum() == 1); |
| 65 | result.reset(); |
| 66 | BOOST_TEST(type::instances == 0); |
| 67 | } |
| 68 | |
| 69 | { |
| 70 | std::unique_ptr<type> result = boost::make_unique<type>(args: 1, args: 2); |
| 71 | BOOST_TEST(result.get() != 0); |
| 72 | BOOST_TEST(type::instances == 1); |
| 73 | BOOST_TEST(result->sum() == 1 + 2); |
| 74 | result.reset(); |
| 75 | BOOST_TEST(type::instances == 0); |
| 76 | } |
| 77 | |
| 78 | { |
| 79 | std::unique_ptr<type> result = |
| 80 | boost::make_unique<type>(args: 1, args: 2, args: 3); |
| 81 | BOOST_TEST(result.get() != 0); |
| 82 | BOOST_TEST(type::instances == 1); |
| 83 | BOOST_TEST(result->sum() == 1 + 2 + 3); |
| 84 | result.reset(); |
| 85 | BOOST_TEST(type::instances == 0); |
| 86 | } |
| 87 | |
| 88 | { |
| 89 | std::unique_ptr<type> result = |
| 90 | boost::make_unique<type>(args: 1, args: 2, args: 3, args: 4); |
| 91 | BOOST_TEST(result.get() != 0); |
| 92 | BOOST_TEST(type::instances == 1); |
| 93 | BOOST_TEST(result->sum() == 1 + 2 + 3 + 4); |
| 94 | result.reset(); |
| 95 | BOOST_TEST(type::instances == 0); |
| 96 | } |
| 97 | |
| 98 | { |
| 99 | std::unique_ptr<type> result = |
| 100 | boost::make_unique<type>(args: 1, args: 2, args: 3, args: 4, args: 5); |
| 101 | BOOST_TEST(result.get() != 0); |
| 102 | BOOST_TEST(type::instances == 1); |
| 103 | BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5); |
| 104 | result.reset(); |
| 105 | BOOST_TEST(type::instances == 0); |
| 106 | } |
| 107 | |
| 108 | { |
| 109 | std::unique_ptr<type> result = |
| 110 | boost::make_unique<type>(args: 1, args: 2, args: 3, args: 4, args: 5, args: 6); |
| 111 | BOOST_TEST(result.get() != 0); |
| 112 | BOOST_TEST(type::instances == 1); |
| 113 | BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6); |
| 114 | result.reset(); |
| 115 | BOOST_TEST(type::instances == 0); |
| 116 | } |
| 117 | |
| 118 | { |
| 119 | std::unique_ptr<type> result = |
| 120 | boost::make_unique<type>(args: 1, args: 2, args: 3, args: 4, args: 5, args: 6, args: 7); |
| 121 | BOOST_TEST(result.get() != 0); |
| 122 | BOOST_TEST(type::instances == 1); |
| 123 | BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7); |
| 124 | result.reset(); |
| 125 | BOOST_TEST(type::instances == 0); |
| 126 | } |
| 127 | |
| 128 | { |
| 129 | std::unique_ptr<type> result = |
| 130 | boost::make_unique<type>(args: 1, args: 2, args: 3, args: 4, args: 5, args: 6, args: 7, args: 8); |
| 131 | BOOST_TEST(result.get() != 0); |
| 132 | BOOST_TEST(type::instances == 1); |
| 133 | BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); |
| 134 | result.reset(); |
| 135 | BOOST_TEST(type::instances == 0); |
| 136 | } |
| 137 | |
| 138 | { |
| 139 | std::unique_ptr<type> result = |
| 140 | boost::make_unique<type>(args: 1, args: 2, args: 3, args: 4, args: 5, args: 6, args: 7, args: 8, args: 9); |
| 141 | BOOST_TEST(result.get() != 0); |
| 142 | BOOST_TEST(type::instances == 1); |
| 143 | BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); |
| 144 | result.reset(); |
| 145 | BOOST_TEST(type::instances == 0); |
| 146 | } |
| 147 | #endif |
| 148 | return boost::report_errors(); |
| 149 | } |
| 150 | #else |
| 151 | int main() |
| 152 | { |
| 153 | return 0; |
| 154 | } |
| 155 | #endif |
| 156 | |