With this commit, Update unlinks itself from a linked bag if it exists.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
}
public:
+ ~Update();
+
+public:
void link(const PtrLink<Bag, BagInfo> *l) { _link = l; }
public:
namespace coco
{
+Update::~Update()
+{
+ // Unlink self from a linked bag if it exists
+ bag(nullptr);
+}
+
void Update::bag(Bag *bag)
{
if (_bag)
ASSERT_EQ(updates.size(), 0);
}
}
+
+TEST_F(UpdateTest, unlink_on_destruction)
+{
+ ::mock::Update updater;
+
+ auto bag = bag_mgr.create(1);
+
+ {
+ coco::Update update{&bag_link, &updater};
+ update.bag(bag);
+ ASSERT_EQ(bag->updates().size(), 1);
+ }
+
+ ASSERT_EQ(bag->updates().size(), 0);
+}