Modify AppCoreBase implementation 54/305454/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 1 Feb 2024 22:51:21 +0000 (07:51 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 1 Feb 2024 23:21:26 +0000 (08:21 +0900)
This patch is to fix the failure issue of unit tests.
- Releasing the GCancellable instance is not needed in the GAsyncReadyCallback.
- The glib idler related to the suspend event initialization is removed.
- The default behaviors related to gdbus API are defined.

Change-Id: I0c809dc9da4f246fdbae1b7ad58542da1dbb527d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
tizen-cpp/app-core-cpp/app_core_base.cc
tizen-cpp/app-core-cpp/suspend_event_private.cc
unittests/main.cc
unittests/mock/dbus_mock.h

index fd2b915..d7a854f 100644 (file)
@@ -941,14 +941,7 @@ void AppCoreBase::Init(int argc, char** argv) {
   impl_->PluginInit(argc, argv);
   traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
 
-  GLib::IdleAdd(
-      [](gpointer data) -> gboolean {
-        AppCoreBase* base = reinterpret_cast<AppCoreBase*>(data);
-        base->impl_->InitSuspend();
-        return G_SOURCE_REMOVE;
-      },
-      this);
-
+  impl_->InitSuspend();
   traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:SET_SYSTEM_EVENT");
   if (!impl_->dirty_) {
     impl_->dirty_ = true;
index 2c88ed8..c2378a8 100644 (file)
@@ -57,9 +57,6 @@ SuspendEvent::~SuspendEvent() {
 void SuspendEvent::GAsyncReadyCb(GObject* source_object, GAsyncResult* res,
                                  gpointer user_data) {
   auto* event = static_cast<SuspendEvent*>(user_data);
-  g_object_unref(event->cancellable_);
-  event->cancellable_ = nullptr;
-
   GError* error = nullptr;
   event->conn_ = g_bus_get_finish(res, &error);
   if (event->conn_ == nullptr) {
index db16de3..acd26a9 100644 (file)
  * limitations under the License.
  */
 
-#include <gmock/gmock.h>
-
-//#define LOG_INTERNAL
-
-#ifdef LOG_INTERNAL
 #include <dlog.h>
+#include <gmock/gmock.h>
 
-extern "C" int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...) {
+extern "C" int __dlog_print(log_id_t log_id, int prio, const char* tag,
+                            const char* fmt, ...) {
   printf("%s:", tag);
   va_list ap;
   va_start(ap, fmt);
   vprintf(fmt, ap);
   va_end(ap);
   printf("\n");
-
   return 0;
 }
-#endif
 
 int main(int argc, char* argv[]) {
   int ret = 0;
index f1b5143..2515d4e 100644 (file)
@@ -34,6 +34,20 @@ class DbusMock : public virtual ModuleMock {
     conn_ = reinterpret_cast<GDBusConnection*>(&dummy);
 
     ON_CALL(*this, g_bus_get_sync(_, _, _)).WillByDefault(Return(conn_));
+    ON_CALL(*this, g_bus_get(_, _, _, _))
+        .WillByDefault(Invoke(
+            [&](GBusType, GCancellable*, GAsyncReadyCallback, gpointer) {}));
+    ON_CALL(*this,
+            g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _))
+        .WillByDefault(Return(1));
+    ON_CALL(*this, g_dbus_connection_signal_unsubscribe(_, _))
+        .WillByDefault(Invoke([&](GDBusConnection*, guint) {}));
+    ON_CALL(*this, g_bus_get_finish(_, _)).WillByDefault(Return(conn_));
+    ON_CALL(*this, g_cancellable_new())
+        .WillByDefault(Return(reinterpret_cast<GCancellable*>(&dummy)));
+    ON_CALL(*this, g_cancellable_cancel(_))
+        .WillByDefault(Invoke([&](GCancellable*) {}));
+    ON_CALL(*this, g_object_unref(_)).WillByDefault(Invoke([&](gpointer) {}));
   }
 
   MOCK_METHOD3(g_bus_get_sync,