[Notification] Method GetNotiHandleFromJson added 78/115378/2
authorSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Fri, 17 Feb 2017 12:51:50 +0000 (13:51 +0100)
committerSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Fri, 17 Feb 2017 13:16:56 +0000 (14:16 +0100)
[Verification] TCT Notification tests passed

Change-Id: I66bfd8f0ae3a4dc8bf3e7ae0741710d1e5b25445
Signed-off-by: Szymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
src/notification/status_notification.cc
src/notification/status_notification.h

index 13fe62c40797c001dba39144a5d305dac6b663fe..c6d7bf354d2835c6f2549c484bc764b932083013 100644 (file)
@@ -1144,9 +1144,9 @@ PlatformResult StatusNotification::ToJson(int id,
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult StatusNotification::FromJson(const picojson::object& args,
-                                            bool is_update,
-                                            picojson::object* out_ptr) {
+PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& args,
+                                       bool is_update,
+                                       notification_h *noti_handle){
   LoggerD("Enter");
   picojson::object noti_obj =
       common::FromJson<picojson::object>(args, "notification");
@@ -1160,32 +1160,29 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
     return status;
 
   int id = NOTIFICATION_PRIV_ID_NONE;
-  int ret;
 
-  notification_h noti_handle = nullptr;
-  app_control_h app_control = NULL;
+  app_control_h app_control = nullptr;
 
   SCOPE_EXIT {
     if (app_control) {
       app_control_destroy(app_control);
     }
-    notification_free(noti_handle);
   };
 
   if (is_update) {
     id = std::stoi(common::FromJson<std::string>(noti_obj, "id"));
 
-    PlatformResult status = GetNotiHandle(id, &noti_handle);
+    PlatformResult status = GetNotiHandle(id, noti_handle);
     if (status.IsError())
       return status;
 
   } else {
-    status = Create(noti_type, &noti_handle);
+    status = Create(noti_type, noti_handle);
     if (status.IsError())
       return status;
   }
 
-  status = SetLayout(noti_handle, status_type);
+  status = SetLayout(*noti_handle, status_type);
   if (status.IsError()) {
     return status;
   }
@@ -1195,7 +1192,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
     const std::string& value_str = common::FromJson<std::string>(noti_obj, "iconPath");
     std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
 
-    status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, real_path);
+    status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, real_path);
     if (status.IsError()) {
       return status;
     }
@@ -1206,7 +1203,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
         common::FromJson<std::string>(noti_obj, "subIconPath");
     std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
 
-    status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path);
+    status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path);
     if (status.IsError()) {
       return status;
     }
@@ -1214,7 +1211,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
 
   if (val.contains("number") && !IsNull(noti_obj, "number")) {
     long number = (long)common::FromJson<double>(noti_obj, "number");
-    status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
+    status = SetText(*noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
     if (status.IsError()) {
       return status;
     }
@@ -1222,28 +1219,28 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
 
   if (val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
     status = SetDetailInfos(
-        noti_handle, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
+        *noti_handle, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
     if (status.IsError()) {
       return status;
     }
   }
 
   if (val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
-    status = SetLedColor(noti_handle,
+    status = SetLedColor(*noti_handle,
                          common::FromJson<std::string>(noti_obj, "ledColor"));
     if (status.IsError()) {
       return status;
     }
   }
 
-  status = SetLedOnPeriod(noti_handle,
+  status = SetLedOnPeriod(*noti_handle,
                           static_cast<unsigned long>(common::FromJson<double>(
                               noti_obj, "ledOnPeriod")));
   if (status.IsError()) {
     return status;
   }
 
-  status = SetLedOffPeriod(noti_handle,
+  status = SetLedOffPeriod(*noti_handle,
                            static_cast<unsigned long>(common::FromJson<double>(
                                noti_obj, "ledOffPeriod")));
   if (status.IsError()) {
@@ -1255,7 +1252,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
     const std::string& value_str = common::FromJson<std::string>(noti_obj, "backgroundImagePath");
     std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
 
-    status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path);
+    status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path);
     if (status.IsError()) {
       return status;
     }
@@ -1263,7 +1260,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
 
   if (val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
     status = SetThumbnails(
-        noti_handle, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
+        *noti_handle, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
     if (status.IsError()) {
       return status;
     }
@@ -1273,14 +1270,14 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
     const std::string& value_str = common::FromJson<std::string>(noti_obj, "soundPath");
     std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
 
-    status = SetSoundPath(noti_handle, real_path);
+    status = SetSoundPath(*noti_handle, real_path);
     if (status.IsError()) {
       return status;
     }
   }
 
   status =
-      SetVibration(noti_handle, common::FromJson<bool>(noti_obj, "vibration"));
+      SetVibration(*noti_handle, common::FromJson<bool>(noti_obj, "vibration"));
   if (status.IsError()) {
     return status;
   }
@@ -1309,14 +1306,14 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
 
   const std::string& progress_type =
       common::FromJson<std::string>(noti_obj, "progressType");
-  status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
+  status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
   if (status.IsError()) {
     return status;
   }
 
   if (val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
     double progressValue = common::FromJson<double>(noti_obj, "progressValue");
-    status = SetProgressValue(noti_handle, progress_type, progressValue,
+    status = SetProgressValue(*noti_handle, progress_type, progressValue,
         is_update);
 
     if (status.IsError()) {
@@ -1324,7 +1321,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
     }
   }
 
-  status = SetText(noti_handle,
+  status = SetText(*noti_handle,
                    NOTIFICATION_TEXT_TYPE_TITLE,
                    common::FromJson<std::string>(noti_obj, "title"));
   if (status.IsError()) {
@@ -1332,7 +1329,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
   }
 
   if (val.contains("content") && !IsNull(noti_obj, "content")) {
-    status = SetText(noti_handle,
+    status = SetText(*noti_handle,
                      NOTIFICATION_TEXT_TYPE_CONTENT,
                      common::FromJson<std::string>(noti_obj, "content"));
     if (status.IsError()) {
@@ -1340,11 +1337,31 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args,
     }
   }
 
-  status = SetAppControl(noti_handle, app_control);
+  status = SetAppControl(*noti_handle, app_control);
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult StatusNotification::FromJson(const picojson::object& args,
+                                            bool is_update,
+                                            picojson::object* out_ptr) {
+  LoggerD("Enter");
+  notification_h noti_handle = nullptr;
+  int ret;
+  int id = NOTIFICATION_PRIV_ID_NONE;
+
+  SCOPE_EXIT {
+    notification_free(noti_handle);
+  };
+
+  PlatformResult status = GetNotiHandleFromJson(args, is_update, &noti_handle);
+
+  if (status.IsError()){
+    return status;
+  }
 
   if (is_update) {
     ret = notification_update(noti_handle);
-
   } else {
     ret = notification_insert(noti_handle, &id);
     if (NOTIFICATION_ERROR_NONE != ret) {
index ae50e8d647dda7b99f9740da9bb647868e57fe21..51aab91f53e8f3fda013d001137432d1564087f5 100644 (file)
@@ -35,6 +35,9 @@ class StatusNotification {
                                        notification_h noti_handle,
                                        app_control_h app_handle,
                                        picojson::object* out_ptr);
+  static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args,
+                                         bool is_update,
+                                         notification_h *noti_handle);
   static common::PlatformResult FromJson(const picojson::object& args,
                                          bool is_update,
                                          picojson::object* out_ptr);