From b8b220987e93fd6b889e265575e3cfe72099c4cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 11 Sep 2018 13:36:18 +0900 Subject: [PATCH] [coco] Unlink Update from Bag on desturction (#1439) With this commit, Update unlinks itself from a linked bag if it exists. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Update.h | 3 +++ contrib/coco/core/src/IR/Update.cpp | 6 ++++++ contrib/coco/core/src/IR/Update.test.cpp | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/contrib/coco/core/include/coco/IR/Update.h b/contrib/coco/core/include/coco/IR/Update.h index 6d2603d..12dd867 100644 --- a/contrib/coco/core/include/coco/IR/Update.h +++ b/contrib/coco/core/include/coco/IR/Update.h @@ -22,6 +22,9 @@ public: } public: + ~Update(); + +public: void link(const PtrLink *l) { _link = l; } public: diff --git a/contrib/coco/core/src/IR/Update.cpp b/contrib/coco/core/src/IR/Update.cpp index 709b1ba..68fe253 100644 --- a/contrib/coco/core/src/IR/Update.cpp +++ b/contrib/coco/core/src/IR/Update.cpp @@ -6,6 +6,12 @@ namespace coco { +Update::~Update() +{ + // Unlink self from a linked bag if it exists + bag(nullptr); +} + void Update::bag(Bag *bag) { if (_bag) diff --git a/contrib/coco/core/src/IR/Update.test.cpp b/contrib/coco/core/src/IR/Update.test.cpp index 7b7db7e..84c0e03 100644 --- a/contrib/coco/core/src/IR/Update.test.cpp +++ b/contrib/coco/core/src/IR/Update.test.cpp @@ -57,3 +57,18 @@ TEST_F(UpdateTest, value) 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); +} -- 2.7.4