Change unittest package name and improves code coverage
[platform/core/appfw/appcore-widget.git] / src / base / widget_base.cc
index 45ec082..20c10e1 100644 (file)
@@ -26,6 +26,8 @@
 #include <widget_errno.h>
 #include <widget_instance.h>
 
+#include <stdexcept>
+
 #include <app_core_multi_window_base.hh>
 
 #include "common/log_private.hh"
@@ -43,9 +45,11 @@ class AppContext {
     app_id_ = app_id;
   }
 
+/* LCOV_EXCL_START */
   const std::string& GetAppId() const {
     return app_id_;
   }
+/* LCOV_EXCL_STOP */
 
   void SetPackageId(const std::string& package_id) {
     package_id_ = package_id;
@@ -70,7 +74,7 @@ class AppContext {
   bool IsPermanent() const {
     return permanent_;
   }
-
+/* LCOV_EXCL_START */
   void SetFgSignal(bool fg_signal) {
     fg_signal_ = fg_signal;
   }
@@ -78,6 +82,7 @@ class AppContext {
   bool IsFgSignal() const {
     return fg_signal_;
   }
+/* LCOV_EXCL_STOP */
 
   int SendUpdateStatus(const std::string& class_id,
       const std::string& instance_id, int status, int err,
@@ -160,9 +165,9 @@ class WidgetContext::Impl {
 
   std::unique_ptr<tizen_base::Bundle> args_;
   std::string content_;
-  double period_;
+  double period_ = 0.0f;
   guint periodic_timer_ = 0;
-  bool pending_update_;
+  bool pending_update_ = false;
   std::string pending_content_;
 };
 
@@ -497,6 +502,7 @@ int WidgetBase::OnControl(tizen_base::Bundle b) {
   return 0;
 }
 
+/* LCOV_EXCL_START */
 void WidgetContext::Impl::OnUpdate(bool force) {
   parent_->OnUpdate(pending_content_.empty() ? tizen_base::Bundle() :
       tizen_base::Bundle(pending_content_), force);
@@ -507,6 +513,7 @@ void WidgetContext::Impl::OnUpdate(bool force) {
       WIDGET_INSTANCE_EVENT_UPDATE, 0, nullptr);
   _D("Updated: %s", id.c_str());
 }
+/* LCOV_EXCL_STOP */
 
 void WidgetContext::Impl::UpdateProcess(const tizen_base::Bundle& b) {
   bool force;
@@ -532,6 +539,7 @@ void WidgetContext::Impl::UpdateProcess(const tizen_base::Bundle& b) {
   }
 }
 
+/* LCOV_EXCL_START */
 void WidgetContext::Impl::SetPeriod(double period) {
   period_ = period;
 }
@@ -546,6 +554,7 @@ void WidgetContext::Impl::SetPeriodicTimer() {
         TimedOutCb, parent_);
   }
 }
+/* LCOV_EXCL_STOP */
 
 void WidgetContext::Impl::UnsetPeriodicTimer() {
   if (periodic_timer_) {
@@ -555,6 +564,7 @@ void WidgetContext::Impl::UnsetPeriodicTimer() {
   }
 }
 
+/* LCOV_EXCL_START */
 gboolean WidgetContext::Impl::TimedOutCb(gpointer user_data) {
   WidgetContext* wc = reinterpret_cast<WidgetContext*>(user_data);
   if (wc->IsResumed()) {
@@ -571,6 +581,7 @@ gboolean WidgetContext::Impl::TimedOutCb(gpointer user_data) {
 
   return G_SOURCE_CONTINUE;
 }
+/* LCOV_EXCL_STOP */
 
 WidgetContext::WidgetContext(std::string context_id, std::string inst_id,
     AppCoreMultiWindowBase* app)
@@ -581,6 +592,7 @@ WidgetContext::WidgetContext(std::string context_id, std::string inst_id,
 
 WidgetContext::~WidgetContext() = default;
 
+/* LCOV_EXCL_START */
 void WidgetContext::OnPause() {
   std::string id = GetInstId();
   _D("WidgetContext(%s) is paused", id.c_str());
@@ -615,6 +627,7 @@ void WidgetContext::OnResume() {
     __context.SetFgSignal(true);
   }
 }
+/* LCOV_EXCL_STOP */
 
 void WidgetContext::OnResize(int w, int h) {
 }
@@ -662,6 +675,15 @@ int WidgetContext::SetContents(const tizen_base::Bundle& contents) {
     return WIDGET_ERROR_FAULT;
   }
 
+  try {
+    auto contents_raw = const_cast<tizen_base::Bundle&>(contents).ToRaw();
+    impl_->content_ = std::string(
+        reinterpret_cast<char*>(contents_raw.first.get()));
+  } catch (const std::bad_alloc& e) {
+    impl_->content_ = "";
+    _E("Exception(%s) occurs", e.what());
+  }
+
   return WIDGET_ERROR_NONE;
 }
 
@@ -756,8 +778,13 @@ void WidgetContext::OnTerminate() {
       reason = DestroyType::PERMANENT;
   }
 
-  tizen_base::Bundle content_info = impl_->content_.empty() ?
-      tizen_base::Bundle() : tizen_base::Bundle(impl_->content_);
+  tizen_base::Bundle content_info;
+  try {
+    if (!impl_->content_.empty())
+      content_info = tizen_base::Bundle(impl_->content_);
+  } catch (const std::bad_alloc& e) {
+    _E("Exception(%s) occurs", e.what());
+  }
 
   OnDestroy(reason, content_info);