[coco] Unlink Object's Def on destruction (#1457)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 11 Sep 2018 10:36:40 +0000 (19:36 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 11 Sep 2018 10:36:40 +0000 (19:36 +0900)
This commit revises DefSlot<T> to unlink linked Def from Object on
destruction.

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

index 996b2e1..edfe392 100644 (file)
@@ -15,6 +15,9 @@ public:
   }
 
 public:
+  ~DefSlot() { value(nullptr); }
+
+public:
   T *value(void) const { return _value; }
 
 public:
index b790cf4..26a9681 100644 (file)
@@ -4,10 +4,14 @@
 
 #include "coco/IR/FeatureObject.h"
 
+#include "nncc/foundation/Memory.h"
+
 #include "Def.mock.h"
 
 #include <gtest/gtest.h>
 
+using nncc::foundation::make_unique;
+
 namespace
 {
 class DefSlotTest : public ::testing::Test
@@ -49,3 +53,21 @@ TEST_F(DefSlotTest, value)
 
   ASSERT_EQ(o->def(), nullptr);
 }
+
+TEST_F(DefSlotTest, unlink_on_destruction)
+{
+  auto o = obj_mgr.create(nncc::core::ADT::feature::Shape{1, 1, 1});
+
+  ::mock::Def def;
+
+  auto slot = make_unique<coco::DefSlot<coco::FeatureObject>>(&obj_link, &def);
+
+  slot->value(o);
+  ASSERT_EQ(o->def(), &def);
+
+  // Let's destruct the allocated slot
+  slot.reset(nullptr);
+
+  // The def of Object SHOULD BE updated
+  ASSERT_EQ(o->def(), nullptr);
+}