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