From 602ecc08865900681f50333f59b3d168dec2a287 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 2 Feb 2024 07:51:21 +0900 Subject: [PATCH] Modify AppCoreBase implementation 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 --- tizen-cpp/app-core-cpp/app_core_base.cc | 9 +-------- tizen-cpp/app-core-cpp/suspend_event_private.cc | 3 --- unittests/main.cc | 11 +++-------- unittests/mock/dbus_mock.h | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/tizen-cpp/app-core-cpp/app_core_base.cc b/tizen-cpp/app-core-cpp/app_core_base.cc index fd2b915..d7a854f 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -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(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; diff --git a/tizen-cpp/app-core-cpp/suspend_event_private.cc b/tizen-cpp/app-core-cpp/suspend_event_private.cc index 2c88ed8..c2378a8 100644 --- a/tizen-cpp/app-core-cpp/suspend_event_private.cc +++ b/tizen-cpp/app-core-cpp/suspend_event_private.cc @@ -57,9 +57,6 @@ SuspendEvent::~SuspendEvent() { void SuspendEvent::GAsyncReadyCb(GObject* source_object, GAsyncResult* res, gpointer user_data) { auto* event = static_cast(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) { diff --git a/unittests/main.cc b/unittests/main.cc index db16de3..acd26a9 100644 --- a/unittests/main.cc +++ b/unittests/main.cc @@ -14,24 +14,19 @@ * limitations under the License. */ -#include - -//#define LOG_INTERNAL - -#ifdef LOG_INTERNAL #include +#include -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; diff --git a/unittests/mock/dbus_mock.h b/unittests/mock/dbus_mock.h index f1b5143..2515d4e 100644 --- a/unittests/mock/dbus_mock.h +++ b/unittests/mock/dbus_mock.h @@ -34,6 +34,20 @@ class DbusMock : public virtual ModuleMock { conn_ = reinterpret_cast(&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(&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, -- 2.7.4