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