Checks complication id duplication 45/191745/3
authorhyunho <hhstark.kang@samsung.com>
Tue, 23 Oct 2018 06:49:46 +0000 (15:49 +0900)
committerhyunho <hhstark.kang@samsung.com>
Tue, 30 Oct 2018 00:59:49 +0000 (09:59 +0900)
Change-Id: I82ff7f59a73cc55c58671ac8b910cc69b3a77fb0
Signed-off-by: hyunho <hhstark.kang@samsung.com>
unittest/src/test-complication.cc
watchface-complication/complication-implementation.h
watchface-complication/complication.cc

index 7292ff7..b1e3f4a 100644 (file)
@@ -84,7 +84,7 @@ class WC : public ::testing::Test {
           std::unique_ptr<IEditable::Geometry>(new IEditable::Geometry(0, 0, 100, 100)),
           IEditable::EditableShapeType::Circle)));
 
-    complication2 = new WatchComplication(0, default_type, EventTap,
+    complication2 = new WatchComplication(1, default_type, EventTap,
         providerId2.c_str(), ShortText);
     complication2->Init();
   }
@@ -253,6 +253,19 @@ TEST_F(WC, GetLastContext)
   EXPECT_STREQ(value, "TEST_VALUE");
 }
 
+TEST_F(WC, DuplicateID)
+{
+  WatchComplication* comp = nullptr;
+  try {
+    comp = new WatchComplication(0, default_type, EventTap,
+        providerId.c_str(), ShortText);
+  } catch (Exception &ex) {
+    cout << "Exception " << ex.what() << " (" << ex.GetErrorCode() << ") " << endl;
+    EXPECT_EQ(ex.GetErrorCode(), WATCHFACE_COMPLICATION_ERROR_EXIST_ID);
+  }
+  EXPECT_EQ(comp, nullptr);
+}
+
 TEST_F(WC, ApplyAllowedList)
 {
   std::list<std::unique_ptr<Complication::ProviderInfo>> allowed_list;
index d2794d1..89e38b1 100644 (file)
@@ -114,6 +114,7 @@ class Complication::Impl : IGDBus::IGDBusEvent, IPackageManager::IPackageEvent {
   static const std::string provider_type_key_;
   static const std::string supported_events_error_key_;
   static const std::string privilege_error_key_;
+  static std::list<int> complication_id_list_;
   IEditable::EditableState ed_state_ = Complete;
   guint periodic_timer_ = 0;
   std::map<std::string, int> sender_info_;
index fa94aa7..6e6b039 100644 (file)
@@ -36,7 +36,7 @@
 #define QUERY_MAXLEN 4096
 
 namespace watchface_complication {
-
+std::list<int> Complication::Impl::complication_id_list_;
 const std::string Complication::Impl::provider_id_key_ = "__PROVIDER_ID_KEY__";
 const std::string Complication::Impl::provider_type_key_ = "__PROVIDER_TYPE_KEY__";
 const std::string Complication::Impl::supported_events_error_key_ = "__SUPPORTED_EVENTS_ERROR_KEY__";
@@ -141,6 +141,13 @@ Complication::Impl::Impl(Complication* parent, int id,
     gdbus_(std::unique_ptr<IGDBus>(ComplicationConnector::GetInst(mock).CreateGDBus(mock))),
     package_(std::unique_ptr<IPackageManager>(ComplicationConnector::GetInst(mock).CreatePackageManager(mock))),
     mock_(mock) {
+  for (auto& i : complication_id_list_) {
+    if (i == complication_id_) {
+      LOGE("Exist complication id (%d)", complication_id_);
+      THROW(WATCHFACE_COMPLICATION_ERROR_EXIST_ID);
+    }
+  }
+  complication_id_list_.emplace_back(complication_id_);
   LOGI("complication create %d", complication_id_);
 }
 
@@ -149,6 +156,13 @@ Complication::Impl::~Impl() {
   if (periodic_timer_)
     g_source_remove(periodic_timer_);
   package_.get()->UnWatch(this);
+  for (auto& i : complication_id_list_) {
+    if (i == complication_id_) {
+      complication_id_list_.remove(i);
+      LOGW("remove %d from id list", i);
+      break;
+    }
+  }
 }
 
 void Complication::Impl::OnVanish(const std::string& name) {