Add theme_is_key_exist() 81/252781/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 2 Feb 2021 08:00:00 +0000 (17:00 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 2 Feb 2021 10:26:53 +0000 (19:26 +0900)
Change-Id: Idd9157da297f9dc285247c7d07a71607042384f0
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/api/theme.cc
src/api/theme.h
src/theme/loader/theme_info.cc
src/theme/loader/theme_info.h
test/unit_tests/test_theme.cc

index b54a02783b185f518b8091127d0459eedec6358f..0bfb59ff8e11620d9deb8b2a468ac085e425a625 100644 (file)
@@ -348,6 +348,19 @@ extern "C" EXPORT_API int theme_get_bool(theme_h handle, const char* key,
   return THEME_MANAGER_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int theme_is_key_exist(theme_h handle, const char* key,
+    bool* val) {
+  if (handle == nullptr || key == nullptr || val == nullptr) {
+    LOG(ERROR) << "Invalid parameter";
+    return THEME_MANAGER_ERROR_INVALID_PARAMETER;
+  }
+
+  auto p = *static_cast<std::shared_ptr<ThemeInfo>*>(handle);
+  *val = p->HasKey(std::string(key));
+
+  return THEME_MANAGER_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int theme_clone(theme_h handle, theme_h* new_handle) {
   if (handle == nullptr || new_handle == nullptr) {
     LOG(ERROR) << "Invalid parameter";
index 5c49ace7ac119ffa5e44c6f42e49e6d2be98b0b0..1e7c165cb410f80d55e4b35a05f7bf07d8695376 100644 (file)
@@ -246,6 +246,19 @@ int theme_get_float(theme_h handle, const char *key, float *val);
  */
 int theme_get_bool(theme_h handle, const char *key, bool *val);
 
+/**
+ * @brief Check the given key is exist or not.
+ * @since_tizen 6.5
+ * @param[in]  handle     The theme information
+ * @param[in]  key        String key to check existence
+ * @param[out] val        Value corresponding to given key
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #THEME_MANAGER_ERROR_NONE              Successful
+ * @retval #THEME_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int theme_is_key_exist(theme_h handle, const char *key, bool *val);
+
 /**
  * @brief Clones the given theme information.
  * @since_tizen 6.0
index 651a04b058c5f3aebaec29a205c13c3ea439e24c..2451658e4f850b06b8452d57a9351a89698c6270 100644 (file)
@@ -185,6 +185,10 @@ bool ThemeInfo::GetBool(const std::string& key) const {
     throw std::invalid_argument("Required key not available");
 }
 
+bool ThemeInfo::HasKey(const std::string& key) const {
+  return (bundle_.GetType(key) != BUNDLE_TYPE_NONE);
+}
+
 tizen_base::Bundle ThemeInfo::Serialize() const {
   return bundle_;
 }
index 734b5ca810e09f4c028d9671d2b7ffd064ce4821..00ef10c59f2bd264696e8d6b4e9afd8003da1e1a 100644 (file)
@@ -50,6 +50,7 @@ class ThemeInfo {
   int GetInt(const std::string& key) const;
   float GetFloat(const std::string& key) const;
   bool GetBool(const std::string& key) const;
+  bool HasKey(const std::string& key) const;
 
   tizen_base::Bundle Serialize() const;
 
index 41597bb35922f9a60b8bfd1133bdc98e8e0f7d91..abf49383b16e90952e762b07124ce4824dbb4d6d 100644 (file)
@@ -541,3 +541,30 @@ TEST_F(ThemeTest, Theme_GetPathArray_N) {
   int ret = theme_get_path_array(nullptr, "/arraykey", &paths, &count);
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
 }
+
+TEST_F(ThemeTest, Theme_IsKeyExist_P) {
+  std::shared_ptr<ThemeInfo> info(new ThemeInfo(b_));
+
+  theme_h handle = static_cast<void*>(&info);
+  bool val;
+  int ret = theme_is_key_exist(handle, "/intkey", &val);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(val, true);
+
+  ret = theme_is_key_exist(handle, "/notexist", &val);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_EQ(val, false);
+}
+
+TEST_F(ThemeTest, Theme_IsKeyExist_N) {
+  std::shared_ptr<ThemeInfo> info(new ThemeInfo());
+
+  theme_h handle = static_cast<void*>(&info);
+  bool val;
+  int ret = theme_is_key_exist(nullptr, "/intkey", &val);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
+  ret = theme_is_key_exist(handle, nullptr, &val);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
+  ret = theme_is_key_exist(handle, "/intkey", nullptr);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
+}