| 154 | } |
| 155 | |
| 156 | void memory_test::test_shared_ptr() |
| 157 | { |
| 158 | mock::clear(); |
| 159 | { |
| 160 | auto ptr1 = std::make_shared<mock>(); |
| 161 | test_eq("shared_ptr make_shared", mock::constructor_calls, 1U); |
| 162 | test_eq("shared_ptr unique", ptr1.unique(), true); |
| 163 | { |
| 164 | auto ptr2 = ptr1; |
| 165 | test_eq("shared_ptr copy pt1", ptr1.use_count(), 2L); |
| 166 | test_eq("shared_ptr copy pt2", ptr2.use_count(), 2L); |
| 167 | test_eq("shared_ptr copy no constructor call", mock::copy_constructor_calls, 0U); |
| 168 | test_eq("shared_ptr not unique", ptr1.unique(), false); |
| 169 | |
| 170 | auto ptr3 = std::move(ptr2); |
| 171 | test_eq("shared_ptr move pt1", ptr1.use_count(), 2L); |
| 172 | test_eq("shared_ptr move pt2", ptr3.use_count(), 2L); |
| 173 | test_eq("shared_ptr move pt3", ptr2.use_count(), 0L); |
| 174 | |
| 175 | test_eq("shared_ptr move origin empty", (bool)ptr2, false); |
| 176 | } |
| 177 | test_eq("shared_ptr copy out of scope", mock::destructor_calls, 0U); |
| 178 | } |
| 179 | test_eq("shared_ptr original out of scope", mock::destructor_calls, 1U); |
| 180 | } |
| 181 | |
| 182 | void memory_test::test_weak_ptr() |
| 183 | { |