[coco] Unlink Update from Bag on desturction (#1439)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 11 Sep 2018 04:36:18 +0000 (13:36 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 11 Sep 2018 04:36:18 +0000 (13:36 +0900)
With this commit, Update unlinks itself from a linked bag if it exists.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Update.h
contrib/coco/core/src/IR/Update.cpp
contrib/coco/core/src/IR/Update.test.cpp

index 6d2603d..12dd867 100644 (file)
@@ -22,6 +22,9 @@ public:
   }
 
 public:
+  ~Update();
+
+public:
   void link(const PtrLink<Bag, BagInfo> *l) { _link = l; }
 
 public:
index 709b1ba..68fe253 100644 (file)
@@ -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)
index 7b7db7e..84c0e03 100644 (file)
@@ -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);
+}