resource: add ::reset functions (with tests)
This commit is contained in:
@@ -148,6 +148,19 @@ public:
|
||||
return static_cast<bool>(value);
|
||||
}
|
||||
|
||||
/*! @brief Releases the ownership of the managed resource. */
|
||||
void reset() {
|
||||
value.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Replaces the managed resource.
|
||||
* @param other A handle to a resource.
|
||||
*/
|
||||
void reset(handle_type other) {
|
||||
value = std::move(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the underlying resource handle.
|
||||
* @return The underlying resource handle.
|
||||
|
||||
@@ -56,6 +56,18 @@ TEST(Resource, Functionalities) {
|
||||
ASSERT_TRUE(copy);
|
||||
ASSERT_TRUE(move);
|
||||
ASSERT_EQ(copy, move);
|
||||
|
||||
copy.reset(std::make_shared<derived>());
|
||||
|
||||
ASSERT_TRUE(copy);
|
||||
ASSERT_TRUE(move);
|
||||
ASSERT_NE(copy, move);
|
||||
|
||||
move.reset();
|
||||
|
||||
ASSERT_TRUE(copy);
|
||||
ASSERT_FALSE(move);
|
||||
ASSERT_NE(copy, move);
|
||||
}
|
||||
|
||||
TEST(Resource, DerivedToBase) {
|
||||
|
||||
Reference in New Issue
Block a user