| 262 | |
| 263 | template <typename T> |
| 264 | void CheckHandle(T object, T distinct_object) |
| 265 | { |
| 266 | BOOST_CHECK(object.get() != nullptr); |
| 267 | BOOST_CHECK(distinct_object.get() != nullptr); |
| 268 | BOOST_CHECK(object.get() != distinct_object.get()); |
| 269 | |
| 270 | if constexpr (HasToBytes<T>) { |
| 271 | const auto object_bytes = object.ToBytes(); |
| 272 | const auto distinct_bytes = distinct_object.ToBytes(); |
| 273 | BOOST_CHECK(!std::ranges::equal(object_bytes, distinct_bytes)); |
| 274 | } |
| 275 | |
| 276 | // Copy constructor |
| 277 | T object2(distinct_object); |
| 278 | BOOST_CHECK_NE(distinct_object.get(), object2.get()); |
| 279 | if constexpr (HasToBytes<T>) { |
| 280 | check_equal(distinct_object.ToBytes(), object2.ToBytes()); |
| 281 | } |
| 282 | |
| 283 | // Copy assignment |
| 284 | T object3{distinct_object}; |
| 285 | object2 = object3; |
| 286 | BOOST_CHECK_NE(object3.get(), object2.get()); |
| 287 | if constexpr (HasToBytes<T>) { |
| 288 | check_equal(object3.ToBytes(), object2.ToBytes()); |
| 289 | } |
| 290 | |
| 291 | // Move constructor |
| 292 | auto* original_ptr = object2.get(); |
| 293 | T object4{std::move(object2)}; |
| 294 | BOOST_CHECK_EQUAL(object4.get(), original_ptr); |
| 295 | BOOST_CHECK_EQUAL(object2.get(), nullptr); // NOLINT(bugprone-use-after-move) |
| 296 | if constexpr (HasToBytes<T>) { |
| 297 | check_equal(object4.ToBytes(), object3.ToBytes()); |
| 298 | } |
| 299 | |
| 300 | // Move assignment |
| 301 | original_ptr = object4.get(); |
| 302 | object2 = std::move(object4); |
| 303 | BOOST_CHECK_EQUAL(object2.get(), original_ptr); |
| 304 | BOOST_CHECK_EQUAL(object4.get(), nullptr); // NOLINT(bugprone-use-after-move) |
| 305 | if constexpr (HasToBytes<T>) { |
| 306 | check_equal(object2.ToBytes(), object3.ToBytes()); |
| 307 | } |
| 308 | |
| 309 | // Self move-assignment must not destroy the held resource. |
| 310 | // Use a reference to avoid -Wself-move warnings. |
| 311 | original_ptr = object2.get(); |
| 312 | auto& object2_ref = object2; |
| 313 | object2 = std::move(object2_ref); |
| 314 | BOOST_CHECK_EQUAL(object2.get(), original_ptr); |
| 315 | if constexpr (HasToBytes<T>) { |
| 316 | check_equal(object2.ToBytes(), object3.ToBytes()); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | template <typename RangeType> |
| 321 | requires std::ranges::random_access_range<RangeType> |
no test coverage detected