Add APIs to get/set candidate ID 50/225050/3
authorhyunho <hhstark.kang@samsung.com>
Mon, 17 Feb 2020 05:03:18 +0000 (14:03 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 19 Feb 2020 00:51:55 +0000 (00:51 +0000)
Change-Id: Ief562cdc468b42e7b28d4406c6e4f91494a2dd6f
Signed-off-by: hyunho <hhstark.kang@samsung.com>
unittest/src/test-watchface-editable.cc
watchface-complication/include/watchface-editable-internal.h
watchface-complication/watchface-editable.cc

index 889dc34..6e87dd0 100644 (file)
@@ -265,6 +265,11 @@ TEST_F(CWE, watchface_editable_candidates_color_test)
   int ret = watchface_editable_candidate_create(&candidate, "test");
   EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
 
+  char* id;
+  watchface_editable_candidate_get_id(candidate, &id);
+  EXPECT_STREQ(id, "test");
+  free(id);
+
   watchface_editable_candidate_color_create(&color, 12, 34, 56, 78);
   watchface_editable_candidate_set_color(candidate, color);
   watchface_editable_candidate_color_destroy(color);
@@ -280,8 +285,9 @@ TEST_F(CWE, watchface_editable_candidates_color_test)
   EXPECT_EQ(78, a);
 
   char* name;
+  watchface_editable_candidate_set_name(candidate, "test_name");
   watchface_editable_candidate_get_name(candidate, &name);
-  EXPECT_STREQ(name, "test");
+  EXPECT_STREQ(name, "test_name");
   free(name);
 
   bundle_free(candidate);
index 45846d2..f6334d0 100644 (file)
@@ -29,8 +29,10 @@ extern "C" {
 
 typedef struct editable_color_ *watchface_editable_color_h;
 
-int watchface_editable_candidate_create(bundle **candidate, const char *name);
-int watchface_editable_candidate_get_name(bundle* candidate, char** name);
+int watchface_editable_candidate_create(bundle **candidate, const char *id);
+int watchface_editable_candidate_get_id(bundle *candidate, char **id);
+int watchface_editable_candidate_get_name(bundle *candidate, char** name);
+int watchface_editable_candidate_set_name(bundle *candidate, const char* name);
 int watchface_editable_candidate_set_color(bundle *candidate, watchface_editable_color_h color);
 int watchface_editable_candidate_get_color(bundle *candidate, watchface_editable_color_h *color);
 int watchface_editable_candidate_color_create(watchface_editable_color_h *color, int r, int g, int b, int a);
index a5ef650..ba80e25 100644 (file)
@@ -35,6 +35,7 @@
 
 #define LOG_TAG "WATCHFACE_COMPLICATION"
 
+#define CANDIDATE_ID_KEY "__CANDIDATE_ID_KEY__"
 #define CANDIDATE_NAME_KEY "__CANDIDATE_NAME_KEY__"
 #define CANDIDATE_COLOR_R_KEY "__CANDIDATE_COLOR_R_KEY__"
 #define CANDIDATE_COLOR_G_KEY "__CANDIDATE_COLOR_G_KEY__"
@@ -473,16 +474,16 @@ extern "C" EXPORT_API int watchface_editable_load_current_data(
 }
 
 extern "C" EXPORT_API int watchface_editable_candidate_create(
-    bundle** candidate, const char* name) {
-  if (candidate == nullptr || name == nullptr) {
+    bundle** candidate, const char* id) {
+  if (candidate == nullptr || id == nullptr) {
     LOGE("Invalid parameter");
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
   bundle* data = bundle_create();
-  int ret = bundle_add_str(data, CANDIDATE_NAME_KEY, name);
+  int ret = bundle_add_str(data, CANDIDATE_ID_KEY, id);
   if (ret != BUNDLE_ERROR_NONE) {
-    LOGE("fail to add name (%d)", ret);
+    LOGE("fail to add id (%d)", ret);
     bundle_free(data);
     return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
   }
@@ -491,6 +492,39 @@ extern "C" EXPORT_API int watchface_editable_candidate_create(
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int watchface_editable_candidate_get_id(
+    bundle* candidate, char** id) {
+  if (candidate == nullptr || id == nullptr) {
+    LOGE("Invalid parameter");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  char* data;
+  int ret = bundle_get_str(candidate, CANDIDATE_ID_KEY, &data);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGW("No data");
+    return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+  }
+  *id = strdup(data);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_editable_candidate_set_name(
+    bundle* candidate, const char* name) {
+  if (candidate == nullptr || name == nullptr) {
+    LOGE("Invalid parameter");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  int ret = bundle_add_str(candidate, CANDIDATE_NAME_KEY, name);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("fail to add name (%d)", ret);
+    return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
+  }
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int watchface_editable_candidate_get_name(
     bundle* candidate, char** name) {
   if (candidate == nullptr || name == nullptr) {