1 /*
2 * Copyright (c) 2014 Glen Joseph Fernandes
3 * glenfe at live dot com
4 *
5 * Distributed under the Boost Software License,
6 * Version 1.0. (See accompanying file LICENSE_1_0.txt
7 * or copy at 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_object.hpp>
13
14 class type {
15 public:
16 static unsigned int instances;
17
type(int v1=0,int v2=0,int v3=0,int v4=0,int v5=0,int v6=0,int v7=0,int v8=0,int v9=0)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
~type()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
main()44 int main() {
45 BOOST_TEST(type::instances == 0);
46 {
47 std::unique_ptr<type> a1 = boost::make_unique<type>();
48 BOOST_TEST(a1.get() != 0);
49 BOOST_TEST(type::instances == 1);
50 BOOST_TEST(a1->sum == 0);
51 a1.reset();
52 BOOST_TEST(type::instances == 0);
53 }
54
55 #if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES )
56 {
57 std::unique_ptr<type> a1 = boost::make_unique<type>(1);
58 BOOST_TEST(a1.get() != 0);
59 BOOST_TEST(type::instances == 1);
60 BOOST_TEST(a1->sum == 1);
61 a1.reset();
62 BOOST_TEST(type::instances == 0);
63 }
64
65 {
66 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2);
67 BOOST_TEST(a1.get() != 0);
68 BOOST_TEST(type::instances == 1);
69 BOOST_TEST(a1->sum == 1 + 2);
70 a1.reset();
71 BOOST_TEST(type::instances == 0);
72 }
73
74 {
75 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3);
76 BOOST_TEST(a1.get() != 0);
77 BOOST_TEST(type::instances == 1);
78 BOOST_TEST(a1->sum == 1 + 2 + 3);
79 a1.reset();
80 BOOST_TEST(type::instances == 0);
81 }
82
83 {
84 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4);
85 BOOST_TEST(a1.get() != 0);
86 BOOST_TEST(type::instances == 1);
87 BOOST_TEST(a1->sum == 1 + 2 + 3 + 4);
88 a1.reset();
89 BOOST_TEST(type::instances == 0);
90 }
91
92 {
93 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5);
94 BOOST_TEST(a1.get() != 0);
95 BOOST_TEST(type::instances == 1);
96 BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5);
97 a1.reset();
98 BOOST_TEST(type::instances == 0);
99 }
100
101 {
102 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6);
103 BOOST_TEST(a1.get() != 0);
104 BOOST_TEST(type::instances == 1);
105 BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6);
106 a1.reset();
107 BOOST_TEST(type::instances == 0);
108 }
109
110 {
111 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7);
112 BOOST_TEST(a1.get() != 0);
113 BOOST_TEST(type::instances == 1);
114 BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7);
115 a1.reset();
116 BOOST_TEST(type::instances == 0);
117 }
118
119 {
120 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8);
121 BOOST_TEST(a1.get() != 0);
122 BOOST_TEST(type::instances == 1);
123 BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
124 a1.reset();
125 BOOST_TEST(type::instances == 0);
126 }
127
128 {
129 std::unique_ptr<type> a1 = boost::make_unique<type>(1, 2, 3, 4, 5, 6, 7, 8, 9);
130 BOOST_TEST(a1.get() != 0);
131 BOOST_TEST(type::instances == 1);
132 BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
133 a1.reset();
134 BOOST_TEST(type::instances == 0);
135 }
136 #endif
137
138 return boost::report_errors();
139 }
140 #else
141
main()142 int main() {
143 return 0;
144 }
145
146 #endif
147