Rewrite legacy code to C++ for vconf handler 85/284685/4
authorInkyun Kil <inkyun.kil@samsung.com>
Wed, 23 Nov 2022 07:42:18 +0000 (16:42 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Wed, 7 Dec 2022 07:12:31 +0000 (16:12 +0900)
Change-Id: I9e83b91c111b145c131b502374c96776bb818c1d
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/modules/dbus_event/dbus_event_module.cc
src/modules/dbus_event/dbus_event_module.hh
src/modules/dbus_event/esd_system_event.cc [deleted file]
src/modules/dbus_event/vconf_event_handler.cc [new file with mode: 0644]
src/modules/dbus_event/vconf_event_handler.hh [new file with mode: 0644]
tests/mock/eventsystem_mock.cc [new file with mode: 0644]
tests/mock/eventsystem_mock.h [new file with mode: 0644]
tests/unit_tests/CMakeLists.txt
tests/unit_tests/src/test_vconf_handler.cc [new file with mode: 0644]

index 9090cd02d5502b86c43d846772156508018d649d..1077f59497d0690621d4c2f5c24d3013b9baf430 100644 (file)
@@ -30,8 +30,6 @@
   } \
 } while (0)
 
-int __esd_register_vconf_callbacks();
-
 namespace {
 
 #include "introspection_cb.hh"
@@ -1313,7 +1311,9 @@ void __esd_on_name_acquired(GDBusConnection *connection,
   eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b);
   bundle_free(b);
 
-  __esd_register_vconf_callbacks();
+  esd::module::DbusEventModule* mod =
+      static_cast<esd::module::DbusEventModule*>(user_data);
+  mod->SetVconfHandler();
 
   __esd_trusted_busname_print_items();
 
@@ -1811,6 +1811,11 @@ bool DbusEventModule::BeforeLoop() {
   return true;
 }
 
+void DbusEventModule::SetVconfHandler() {
+  vconf_handler_ = std::make_unique<VconfEventHandler>();
+  vconf_handler_->SetDefaultEvents();
+}
+
 void DbusEventModule::HandleMethodCallCb(GDBusConnection *connection,
   const gchar *sender, const gchar *object_path,
   const gchar *interface_name, const gchar *method_name,
index 29788a9dbc9c7202c9d77712c0b522f401b58b73..c4d63990f34f7d0677921d63f01f0ef82eb09a7b 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <imodule.hh>
 
+#include "vconf_event_handler.hh"
+
 namespace esd::module {
 
 class DbusEventModule : public api::IModule {
@@ -32,6 +34,8 @@ class DbusEventModule : public api::IModule {
   bool Startup(api::ToolBox* tools) override;
   void Shutdown() override;
 
+  void SetVconfHandler();
+
   static void HandleMethodCallCb(GDBusConnection *connection,
       const gchar *sender, const gchar *object_path,
       const gchar *interface_name, const gchar *method_name,
@@ -86,6 +90,7 @@ class DbusEventModule : public api::IModule {
 
  private:
   api::ToolBox* tools_ = nullptr;
+  std::unique_ptr<VconfEventHandler> vconf_handler_;
 };
 
 }  // namespace esd::module
diff --git a/src/modules/dbus_event/esd_system_event.cc b/src/modules/dbus_event/esd_system_event.cc
deleted file mode 100644 (file)
index 816353e..0000000
+++ /dev/null
@@ -1,561 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <vconf.h>
-#include <bundle.h>
-#include <eventsystem.h>
-
-#include <log.hh>
-
-namespace {
-
-/* table item : sent system-event by esd */
-static GHashTable *esd_sent_table;
-
-typedef struct __esd_sent_table_item {
-  char *event_name;
-  bundle *event_data;
-} esd_sent_item;
-
-struct esd_vconf_handler {
-  const char *key;
-  void (*esd_vconfcb_fn) (keynode_t *node, void *user_data);
-};
-
-int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key) {
-  int ret = 0;
-  int tmp1 = 0;
-  int tmp2 = 0;
-  char *str1 = NULL;
-  char *str2 = NULL;
-
-  if (bundle_get_count(b1) == bundle_get_count(b2)) {
-    tmp1 = bundle_get_str(b1, key, &str1);
-    tmp2 = bundle_get_str(b2, key, &str2);
-    if (tmp1 == BUNDLE_ERROR_NONE && tmp2 == BUNDLE_ERROR_NONE) {
-      if (strcmp(str1, str2) != 0) {
-        _D("new event_data : value check");
-        ret = 1;
-      }
-    }
-  } else {
-    _D("new event_data : bundle_count check");
-    ret = 1;
-  }
-
-  if (ret == 0)
-    _D("same event_data");
-
-  return ret;
-}
-
-int __esd_send_system_event(const char *event_name, bundle *b, const char *key) {
-  int ret = ES_R_OK;
-  esd_sent_item *item =
-    (esd_sent_item *)g_hash_table_lookup(esd_sent_table, event_name);
-
-  if (item && __esd_event_data_compare(item->event_data, b, key) == 0) {
-    _D("skip send: same with previous data");
-  } else {
-    ret = eventsystem_send_system_event(event_name, b);
-    if (ret != ES_R_OK) {
-      _E("failed to send event");
-      goto out;
-    }
-
-    if (item) {
-      bundle_free(item->event_data);
-      item->event_data = bundle_dup(b);
-    } else {
-      item = (esd_sent_item *)calloc(1, sizeof(esd_sent_item));
-      if (item == NULL) {
-        _E("memory alloc failed");
-        ret = ES_R_ERROR;
-        goto out;
-      }
-      item->event_name = strdup(event_name);
-      if (item->event_name == NULL) {
-        _E("out of memory");
-        free(item);
-        item = nullptr;
-        ret = ES_R_ERROR;
-        goto out;
-      }
-      item->event_data = bundle_dup(b);
-    }
-
-    g_hash_table_insert(esd_sent_table, item->event_name, item);
-  }
-
-out:
-  return ret;
-}
-
-void __esd_vconfcb_location_use_mylocation(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int enabled = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-  const char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enabled);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  key = EVT_KEY_LOCATION_ENABLE_STATE;
-
-  if (enabled)
-    val = EVT_VAL_LOCATION_ENABLED;
-  else
-    val = EVT_VAL_LOCATION_DISABLED;
-
-  b = bundle_create();
-  bundle_add_str(b, key, val);
-
-  if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-}
-
-void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int enabled = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-  const char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enabled);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  key = EVT_KEY_GPS_ENABLE_STATE;
-
-  if (enabled)
-    val = EVT_VAL_GPS_ENABLED;
-  else
-    val = EVT_VAL_GPS_DISABLED;
-
-  b = bundle_create();
-  bundle_add_str(b, key, val);
-
-  if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-}
-
-void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int enabled = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-  const char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  key = EVT_KEY_NPS_ENABLE_STATE;
-
-  if (enabled)
-    val = EVT_VAL_NPS_ENABLED;
-  else
-    val = EVT_VAL_NPS_DISABLED;
-
-  b = bundle_create();
-  bundle_add_str(b, key, val);
-
-  if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-}
-
-void __esd_vconfcb_language_set(keynode_t *node, void *user_data) {
-  char *str = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-
-  _D("vconfcb called");
-
-  str = vconf_get_str(VCONFKEY_LANGSET);
-  if (str == NULL) {
-    _E("failed to get vconf str");
-    return;
-  }
-
-  key = EVT_KEY_LANGUAGE_SET;
-
-  b = bundle_create();
-  bundle_add_str(b, key, str);
-
-  if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-  if (str)
-    free(str);
-}
-
-void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int hours = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-  const char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &hours);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  key = EVT_KEY_HOUR_FORMAT;
-
-  if (hours == VCONFKEY_TIME_FORMAT_24)
-    val = EVT_VAL_HOURFORMAT_24;
-  else
-    val = EVT_VAL_HOURFORMAT_12;
-
-  b = bundle_create();
-  bundle_add_str(b, key, val);
-
-  if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-}
-
-void __esd_vconfcb_region_format(keynode_t *node, void *user_data) {
-  char *str = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-
-  _D("vconfcb called");
-
-  str = vconf_get_str(VCONFKEY_REGIONFORMAT);
-  if (str == NULL) {
-    _E("failed to get vconf str");
-    return;
-  }
-
-  key = EVT_KEY_REGION_FORMAT;
-
-  b = bundle_create();
-  bundle_add_str(b, key, str);
-
-  if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-  if (str)
-    free(str);
-}
-
-void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int vibration_on = 0;
-  int sound_on = 0;
-  bundle *b = NULL;
-  char *key = NULL;
-  char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  if (vibration_on) {
-    key = EVT_KEY_VIBRATION_STATE;
-    val = EVT_VAL_VIBRATION_ON;
-    b = bundle_create();
-    bundle_add_str(b, key, val);
-    if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK)
-      _E("failed to send event");
-
-    if (b)
-      bundle_free(b);
-
-    key = EVT_KEY_SILENT_MODE;
-    val = EVT_VAL_SILENTMODE_OFF;
-    b = bundle_create();
-    bundle_add_str(b, key, val);
-    if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
-      _E("failed to send event");
-
-    if (b)
-      bundle_free(b);
-  } else {
-    key = EVT_KEY_VIBRATION_STATE;
-    val = EVT_VAL_VIBRATION_OFF;
-    b = bundle_create();
-    bundle_add_str(b, key, val);
-    if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK)
-      _E("failed to send event");
-
-    if (b)
-      bundle_free(b);
-
-    if (!sound_on) {
-      key = EVT_KEY_SILENT_MODE;
-      val = EVT_VAL_SILENTMODE_ON;
-      b = bundle_create();
-      bundle_add_str(b, key, val);
-      if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
-        _E("failed to send event");
-
-      if (b)
-        bundle_free(b);
-    }
-  }
-}
-
-void __esd_vconfcb_sound_status(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int vibration_on = 0;
-  int sound_on = 0;
-  bundle *b = NULL;
-  char *key = NULL;
-  char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  if (sound_on) {
-    key = EVT_KEY_VIBRATION_STATE;
-    val = EVT_VAL_VIBRATION_OFF;
-    b = bundle_create();
-    bundle_add_str(b, key, val);
-    if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK)
-      _E("failed to send event");
-
-    if (b)
-      bundle_free(b);
-
-    key = EVT_KEY_SILENT_MODE;
-    val = EVT_VAL_SILENTMODE_OFF;
-    b = bundle_create();
-    bundle_add_str(b, key, val);
-    if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
-      _E("failed to send event");
-
-    if (b)
-      bundle_free(b);
-  } else {
-    if (!vibration_on) {
-      key = EVT_KEY_SILENT_MODE;
-      val = EVT_VAL_SILENTMODE_ON;
-      b = bundle_create();
-      bundle_add_str(b, key, val);
-      if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
-        _E("failed to send event");
-
-      if (b)
-        bundle_free(b);
-    }
-  }
-}
-
-void __esd_vconfcb_auto_rotate(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int enabled = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-  const char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &enabled);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  key = EVT_KEY_SCREEN_AUTOROTATE_STATE;
-
-  if (enabled)
-    val = EVT_VAL_SCREEN_AUTOROTATE_ON;
-  else
-    val = EVT_VAL_SCREEN_AUTOROTATE_OFF;
-
-  b = bundle_create();
-  bundle_add_str(b, key, val);
-
-  if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-}
-
-void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int enabled = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-  const char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_bool(VCONFKEY_3G_ENABLE, &enabled);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  key = EVT_KEY_MOBILE_DATA_STATE;
-
-  if (enabled)
-    val = EVT_VAL_MOBILE_DATA_ON;
-  else
-    val = EVT_VAL_MOBILE_DATA_OFF;
-
-  b = bundle_create();
-  bundle_add_str(b, key, val);
-
-  if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-}
-
-void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data) {
-  int ret = 0;
-  int enabled = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-  const char *val = NULL;
-
-  _D("vconfcb called");
-
-  ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &enabled);
-  if (ret != VCONF_OK) {
-    _E("failed to get vconf (%d)", ret);
-    return;
-  }
-
-  key = EVT_KEY_DATA_ROAMING_STATE;
-
-  if (enabled)
-    val = EVT_VAL_DATA_ROAMING_ON;
-  else
-    val = EVT_VAL_DATA_ROAMING_OFF;
-
-  b = bundle_create();
-  bundle_add_str(b, key, val);
-
-  if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-}
-
-void __esd_vconfcb_font_set(keynode_t *node, void *user_data) {
-  char *str = 0;
-  bundle *b = NULL;
-  const char *key = NULL;
-
-  _D("vconfcb called");
-
-  str = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME);
-  if (str == NULL) {
-    _E("failed to get vconf str");
-    return;
-  }
-
-  key = EVT_KEY_FONT_SET;
-
-  b = bundle_create();
-  bundle_add_str(b, key, str);
-
-  if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK)
-    _E("failed to send event");
-
-  if (b)
-    bundle_free(b);
-  if (str)
-    free(str);
-}
-
-struct esd_vconf_handler vconf_callbacks[] = {
-  {VCONFKEY_LOCATION_USE_MY_LOCATION, __esd_vconfcb_location_use_mylocation},
-  {VCONFKEY_LOCATION_ENABLED, __esd_vconfcb_location_enabled},
-  {VCONFKEY_LOCATION_NETWORK_ENABLED, __esd_vconfcb_location_network_enabled},
-  {VCONFKEY_LANGSET, __esd_vconfcb_language_set},
-  {VCONFKEY_REGIONFORMAT_TIME1224, __esd_vconfcb_hour_format},
-  {VCONFKEY_REGIONFORMAT, __esd_vconfcb_region_format},
-  {VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, __esd_vconfcb_vibration_status},
-  {VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, __esd_vconfcb_sound_status},
-  {VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __esd_vconfcb_auto_rotate},
-  {VCONFKEY_3G_ENABLE, __esd_vconfcb_mobiledata_state},
-  {VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, __esd_vconfcb_roaming_state},
-  {VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, __esd_vconfcb_font_set},
-};
-
-int vconfcbs_size = sizeof(vconf_callbacks)/sizeof(struct esd_vconf_handler);
-
-}  // namespace
-
-int __esd_register_vconf_callbacks() {
-  int i = 0;
-  int ret = 0;
-  int result = ES_R_OK;
-
-  esd_sent_table = g_hash_table_new(g_str_hash, g_str_equal);
-
-  _D("vconf callbacks size(%d)", vconfcbs_size);
-  for (i = 0; i < vconfcbs_size; i++) {
-    ret = vconf_notify_key_changed(vconf_callbacks[i].key,
-      vconf_callbacks[i].esd_vconfcb_fn, NULL);
-    if (ret != VCONF_OK) {
-      _E("failed to register vconf callback (%s)", vconf_callbacks[i].key);
-      result = ES_R_ERROR;
-      break;
-    }
-  }
-
-  return result;
-}
diff --git a/src/modules/dbus_event/vconf_event_handler.cc b/src/modules/dbus_event/vconf_event_handler.cc
new file mode 100644 (file)
index 0000000..b76bf84
--- /dev/null
@@ -0,0 +1,540 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vconf_event_handler.hh"
+
+#include <memory>
+#include <log.hh>
+#include <eventsystem.h>
+
+namespace esd::module {
+
+void VconfEventHandler::LocationUseMyLocationCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int enabled = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+  const char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enabled);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  key = EVT_KEY_LOCATION_ENABLE_STATE;
+
+  if (enabled)
+    val = EVT_VAL_LOCATION_ENABLED;
+  else
+    val = EVT_VAL_LOCATION_DISABLED;
+
+  b = bundle_create();
+  bundle_add_str(b, key, val);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_LOCATION_ENABLE_STATE), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+};
+
+void VconfEventHandler::LocationEnabledCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int enabled = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+  const char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enabled);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  key = EVT_KEY_GPS_ENABLE_STATE;
+
+  if (enabled)
+    val = EVT_VAL_GPS_ENABLED;
+  else
+    val = EVT_VAL_GPS_DISABLED;
+
+  b = bundle_create();
+  bundle_add_str(b, key, val);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_GPS_ENABLE_STATE), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+};
+
+void VconfEventHandler::LocationNetworkEnabledCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int enabled = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+  const char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  key = EVT_KEY_NPS_ENABLE_STATE;
+
+  if (enabled)
+    val = EVT_VAL_NPS_ENABLED;
+  else
+    val = EVT_VAL_NPS_DISABLED;
+
+  b = bundle_create();
+  bundle_add_str(b, key, val);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_NPS_ENABLE_STATE), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+};
+
+void VconfEventHandler::LangsetCb(keynode_t *node, void *user_data) {
+  char *str = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+
+  _D("vconfcb called");
+
+  str = vconf_get_str(VCONFKEY_LANGSET);
+  if (str == NULL) {
+    _E("failed to get vconf str");
+    return;
+  }
+
+  key = EVT_KEY_LANGUAGE_SET;
+
+  b = bundle_create();
+  bundle_add_str(b, key, str);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_LANGUAGE_SET), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+  if (str)
+    free(str);
+};
+
+void VconfEventHandler::RegionFormatHourCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int hours = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+  const char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &hours);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  key = EVT_KEY_HOUR_FORMAT;
+
+  if (hours == VCONFKEY_TIME_FORMAT_24)
+    val = EVT_VAL_HOURFORMAT_24;
+  else
+    val = EVT_VAL_HOURFORMAT_12;
+
+  b = bundle_create();
+  bundle_add_str(b, key, val);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_HOUR_FORMAT), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+};
+
+void VconfEventHandler::RegionFormatCb(keynode_t *node, void *user_data) {
+  char *str = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+
+  _D("vconfcb called");
+
+  str = vconf_get_str(VCONFKEY_REGIONFORMAT);
+  if (str == NULL) {
+    _E("failed to get vconf str");
+    return;
+  }
+
+  key = EVT_KEY_REGION_FORMAT;
+
+  b = bundle_create();
+  bundle_add_str(b, key, str);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_REGION_FORMAT), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+  if (str)
+    free(str);
+};
+
+void VconfEventHandler::VibrationStatusCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int vibration_on = 0;
+  int sound_on = 0;
+  bundle *b = NULL;
+  char *key = NULL;
+  char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  if (vibration_on) {
+    key = EVT_KEY_VIBRATION_STATE;
+    val = EVT_VAL_VIBRATION_ON;
+    b = bundle_create();
+    bundle_add_str(b, key, val);
+    if (SendSytemEvent(std::string(SYS_EVENT_VIBRATION_STATE), b,
+        std::string(key)) != ES_R_OK)
+      _E("failed to send event");
+
+    if (b)
+      bundle_free(b);
+
+    key = EVT_KEY_SILENT_MODE;
+    val = EVT_VAL_SILENTMODE_OFF;
+    b = bundle_create();
+    bundle_add_str(b, key, val);
+    if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
+        std::string(key)) != ES_R_OK)
+      _E("failed to send event");
+
+    if (b)
+      bundle_free(b);
+  } else {
+    key = EVT_KEY_VIBRATION_STATE;
+    val = EVT_VAL_VIBRATION_OFF;
+    b = bundle_create();
+    bundle_add_str(b, key, val);
+    if (SendSytemEvent(std::string(SYS_EVENT_VIBRATION_STATE), b,
+        std::string(key)) != ES_R_OK)
+      _E("failed to send event");
+
+    if (b)
+      bundle_free(b);
+
+    if (!sound_on) {
+      key = EVT_KEY_SILENT_MODE;
+      val = EVT_VAL_SILENTMODE_ON;
+      b = bundle_create();
+      bundle_add_str(b, key, val);
+      if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
+          std::string(key)) != ES_R_OK)
+        _E("failed to send event");
+
+      if (b)
+        bundle_free(b);
+    }
+  }
+};
+
+void VconfEventHandler::SoundStatusCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int vibration_on = 0;
+  int sound_on = 0;
+  bundle *b = NULL;
+  char *key = NULL;
+  char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  if (sound_on) {
+    key = EVT_KEY_VIBRATION_STATE;
+    val = EVT_VAL_VIBRATION_OFF;
+    b = bundle_create();
+    bundle_add_str(b, key, val);
+    if (SendSytemEvent(std::string(SYS_EVENT_VIBRATION_STATE), b,
+        std::string(key)) != ES_R_OK)
+      _E("failed to send event");
+
+    if (b)
+      bundle_free(b);
+
+    key = EVT_KEY_SILENT_MODE;
+    val = EVT_VAL_SILENTMODE_OFF;
+    b = bundle_create();
+    bundle_add_str(b, key, val);
+    if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
+        std::string(key)) != ES_R_OK)
+      _E("failed to send event");
+
+    if (b)
+      bundle_free(b);
+  } else {
+    if (!vibration_on) {
+      key = EVT_KEY_SILENT_MODE;
+      val = EVT_VAL_SILENTMODE_ON;
+      b = bundle_create();
+      bundle_add_str(b, key, val);
+      if (SendSytemEvent(std::string(SYS_EVENT_SILENT_MODE), b,
+          std::string(key)) != ES_R_OK)
+        _E("failed to send event");
+
+      if (b)
+        bundle_free(b);
+    }
+  }
+};
+
+void VconfEventHandler::AutoRotateCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int enabled = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+  const char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &enabled);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  key = EVT_KEY_SCREEN_AUTOROTATE_STATE;
+
+  if (enabled)
+    val = EVT_VAL_SCREEN_AUTOROTATE_ON;
+  else
+    val = EVT_VAL_SCREEN_AUTOROTATE_OFF;
+
+  b = bundle_create();
+  bundle_add_str(b, key, val);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_SCREEN_AUTOROTATE_STATE), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+};
+
+void VconfEventHandler::MobileDataStateCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int enabled = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+  const char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_bool(VCONFKEY_3G_ENABLE, &enabled);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  key = EVT_KEY_MOBILE_DATA_STATE;
+
+  if (enabled)
+    val = EVT_VAL_MOBILE_DATA_ON;
+  else
+    val = EVT_VAL_MOBILE_DATA_OFF;
+
+  b = bundle_create();
+  bundle_add_str(b, key, val);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_MOBILE_DATA_STATE), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+};
+
+void VconfEventHandler::RoamingStateCb(keynode_t *node, void *user_data) {
+  int ret = 0;
+  int enabled = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+  const char *val = NULL;
+
+  _D("vconfcb called");
+
+  ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &enabled);
+  if (ret != VCONF_OK) {
+    _E("failed to get vconf (%d)", ret);
+    return;
+  }
+
+  key = EVT_KEY_DATA_ROAMING_STATE;
+
+  if (enabled)
+    val = EVT_VAL_DATA_ROAMING_ON;
+  else
+    val = EVT_VAL_DATA_ROAMING_OFF;
+
+  b = bundle_create();
+  bundle_add_str(b, key, val);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_DATA_ROAMING_STATE), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+};
+
+void VconfEventHandler::FontSetCb(keynode_t *node, void *user_data) {
+  char *str = 0;
+  bundle *b = NULL;
+  const char *key = NULL;
+
+  _D("vconfcb called");
+
+  str = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME);
+  if (str == NULL) {
+    _E("failed to get vconf str");
+    return;
+  }
+
+  key = EVT_KEY_FONT_SET;
+
+  b = bundle_create();
+  bundle_add_str(b, key, str);
+
+  if (SendSytemEvent(std::string(SYS_EVENT_FONT_SET), b,
+      std::string(key)) != ES_R_OK)
+    _E("failed to send event");
+
+  if (b)
+    bundle_free(b);
+  if (str)
+    free(str);
+};
+
+void VconfEventHandler::SetDefaultEvents() {
+  vconf_notify_key_changed(VCONFKEY_LOCATION_USE_MY_LOCATION, LocationUseMyLocationCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, LocationEnabledCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, LocationNetworkEnabledCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_LANGSET, LangsetCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, RegionFormatHourCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, RegionFormatCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, VibrationStatusCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, SoundStatusCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, AutoRotateCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_3G_ENABLE, MobileDataStateCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, RoamingStateCb, NULL);
+  vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, FontSetCb, NULL);
+}
+
+std::map<std::string, bundle*> VconfEventHandler::event_table_;
+
+int VconfEventHandler::SendSytemEvent(std::string event_name, bundle *b, std::string key) {
+  int ret = ES_R_OK;
+  bundle* data = nullptr;
+  const auto& it = event_table_.find(event_name);
+  if (it != event_table_.end())
+    data = it->second;
+
+  if (data && EventDataCompare(data, b, key) == 0) {
+    _D("skip send: same with previous data");
+  } else {
+    ret = eventsystem_send_system_event(event_name.c_str(), b);
+    if (ret != ES_R_OK) {
+      _E("failed to send event");
+      return ret;
+    }
+
+    if (data)
+      bundle_free(data);
+
+    event_table_[event_name] = bundle_dup(b);
+  }
+
+  return ret;
+}
+
+int VconfEventHandler::EventDataCompare(bundle* b1, bundle* b2, std::string key) {
+  int ret = 0;
+  int tmp1 = 0;
+  int tmp2 = 0;
+  char *str1 = NULL;
+  char *str2 = NULL;
+
+  if (bundle_get_count(b1) == bundle_get_count(b2)) {
+    tmp1 = bundle_get_str(b1, key.c_str(), &str1);
+    tmp2 = bundle_get_str(b2, key.c_str(), &str2);
+    if (tmp1 == BUNDLE_ERROR_NONE && tmp2 == BUNDLE_ERROR_NONE) {
+      if (strcmp(str1, str2) != 0) {
+        _D("new event_data : value check");
+        ret = 1;
+      }
+    }
+  } else {
+    _D("new event_data : bundle_count check");
+    ret = 1;
+  }
+
+  if (ret == 0)
+    _D("same event_data");
+
+  return ret;
+}
+
+}  // namespace
\ No newline at end of file
diff --git a/src/modules/dbus_event/vconf_event_handler.hh b/src/modules/dbus_event/vconf_event_handler.hh
new file mode 100644 (file)
index 0000000..5828600
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef EVENTSYSTEM_MODULES_DBUS_EVENT_VCONF_EVENT_HANDLER_HH_
+#define EVENTSYSTEM_MODULES_DBUS_EVENT_VCONF_EVENT_HANDLER_HH_
+
+#include <map>
+#include <string>
+#include <vconf.h>
+#include <bundle.h>
+
+namespace esd::module {
+
+class VconfEventHandler {
+ public:
+  static int SendSytemEvent(std::string event_name, bundle *b, std::string key);
+  static int EventDataCompare(bundle *b1, bundle *b2, std::string key);
+  void SetDefaultEvents();
+
+ private:
+  static void LocationUseMyLocationCb(keynode_t *node, void *user_data);
+  static void LocationEnabledCb(keynode_t *node, void *user_data);
+  static void LocationNetworkEnabledCb(keynode_t *node, void *user_data);
+  static void LangsetCb(keynode_t *node, void *user_data);
+  static void RegionFormatHourCb(keynode_t *node, void *user_data);
+  static void RegionFormatCb(keynode_t *node, void *user_data);
+  static void VibrationStatusCb(keynode_t *node, void *user_data);
+  static void SoundStatusCb(keynode_t *node, void *user_data);
+  static void AutoRotateCb(keynode_t *node, void *user_data);
+  static void MobileDataStateCb(keynode_t *node, void *user_data);
+  static void RoamingStateCb(keynode_t *node, void *user_data);
+  static void FontSetCb(keynode_t *node, void *user_data);
+
+ private:
+  static std::map<std::string, bundle*> event_table_;
+};
+
+}  // namespace
+
+#endif  // EVENTSYSTEM_MODULES_DBUS_EVENT_VCONF_EVENT_HANDLER_HH_
\ No newline at end of file
diff --git a/tests/mock/eventsystem_mock.cc b/tests/mock/eventsystem_mock.cc
new file mode 100644 (file)
index 0000000..d992e1a
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "eventsystem_mock.h"
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int eventsystem_send_system_event(const char* arg0, bundle* arg1) {
+  return MOCK_HOOK_P2(EventSystemMock, eventsystem_send_system_event, arg0, arg1);
+}
+
diff --git a/tests/mock/eventsystem_mock.h b/tests/mock/eventsystem_mock.h
new file mode 100644 (file)
index 0000000..75fa309
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MOCK_EVENTSYSTEM_MOCK_H_
+#define MOCK_EVENTSYSTEM_MOCK_H_
+
+#include <bundle.h>
+#include <eventsystem.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class EventSystemMock : public virtual ModuleMock {
+ public:
+  virtual ~EventSystemMock() {}
+
+  MOCK_METHOD2(eventsystem_send_system_event, int (const char*, bundle*));
+
+};
+
+#endif  // MOCK_EVENTSYSTEM_MOCK_H_
\ No newline at end of file
index 90e8a31b27e30d10229c0196ec1ac29d405a46cb..56e001d5456a4ed96d0169fc1faf749789b48fe4 100644 (file)
@@ -33,21 +33,24 @@ FOREACH(flag ${${PROJECT_NAME}-unittests_CFLAGS})
 ENDFOREACH(flag)\r
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror")\r
 \r
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14")\r
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++17")\r
 SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")\r
 SET(CMAKE_CXX_FLAGS_RELEASE "-O2")\r
 \r
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include)\r
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/modules/dbus_event)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/dbus_event)\r
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock)\r
 \r
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src TEST_SOURCES)\r
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES)\r
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/modules/dbus_event/* LIB_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib LIB_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/dbus_event DBUS_SOURCES)\r
 \r
 ADD_EXECUTABLE(${PROJECT_NAME}\r
     ${TEST_SOURCES}\r
     ${LIB_SOURCES}\r
+    ${DBUS_SOURCES}\r
     ${MOCK_SOURCES}\r
 )\r
 \r
diff --git a/tests/unit_tests/src/test_vconf_handler.cc b/tests/unit_tests/src/test_vconf_handler.cc
new file mode 100644 (file)
index 0000000..07d57b8
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <bundle.h>
+#include <eventsystem_internal.h>
+#include <vconf.h>
+
+#include "test_fixture.h"
+#include "eventsystem_mock.h"
+#include "vconf_event_handler.hh"
+
+// using namespace tizen_base;
+using ::testing::_;
+using ::testing::Return;
+
+class Mocks : public ::testing::NiceMock<EventSystemMock> {};
+
+class VconfHandlerTest : public TestFixture {
+ public:
+  VconfHandlerTest() : TestFixture(std::make_unique<Mocks>()) {}
+  virtual ~VconfHandlerTest() {}
+
+  virtual void SetUp() {
+    handler_ = std::make_unique<esd::module::VconfEventHandler>();
+  }
+
+  virtual void TearDown() {
+  }
+
+  std::unique_ptr<esd::module::VconfEventHandler> handler_;
+};
+
+TEST_F(VconfHandlerTest, SendSytemEvent) {
+EXPECT_CALL(GetMock<EventSystemMock>(),
+    eventsystem_send_system_event(_, _))
+        .WillOnce(Return(ES_R_OK));
+  bundle* b = bundle_create();
+  int ret = handler_->SendSytemEvent(SYS_EVENT_WIFI_STATE, b,
+        std::string("key"));
+  EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(VconfHandlerTest, EventDataCompare) {
+  bundle* b1 = bundle_create();
+  bundle* b2 = bundle_create();
+  bundle_add_str(b1, "test_key", "val");
+  bundle_add_str(b2, "test_key", "val");
+  int ret = handler_->EventDataCompare(b1, b2, std::string("test_key"));
+  EXPECT_NE(ret, 1);
+  bundle_free(b1);
+  bundle_free(b2);
+}
\ No newline at end of file