From: Mateusz Majewski Date: Thu, 22 Aug 2024 12:23:32 +0000 (+0200) Subject: Handle mocked GDBusConnection a bit more carefully X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_8.0;p=platform%2Fcore%2Fappfw%2Flibeventsystem.git Handle mocked GDBusConnection a bit more carefully Some of the tested functions call g_bus_get_sync twice and unreference the result both times. It seems that without explicit mocking, the second unreference sometimes (not consistently) results in a segfault. Change-Id: Ib76e4ab0b36638a4001ac89e91658f4568f621e4 --- diff --git a/tests/unit_tests/src/test_eventsystem.cc b/tests/unit_tests/src/test_eventsystem.cc index 2f67f11..48d414c 100644 --- a/tests/unit_tests/src/test_eventsystem.cc +++ b/tests/unit_tests/src/test_eventsystem.cc @@ -176,6 +176,10 @@ TEST_F(EventSystemTest, eventsystem_request_sending_system_event) { TEST_F(EventSystemTest, eventsystem_register_application_event) { GDBusProxy* _proxy = (GDBusProxy*)g_object_new(G_TYPE_OBJECT, nullptr); + GDBusConnection* _conn = (GDBusConnection*)g_object_new(G_TYPE_OBJECT, nullptr); + + EXPECT_CALL(GetMock(), g_bus_get_sync(_, _, _)) + .WillRepeatedly(Invoke([&](GBusType t, GCancellable* c, GError** e) { return g_object_ref(_conn); })); EXPECT_CALL(GetMock(), g_dbus_is_interface_name(_)). @@ -210,10 +214,16 @@ TEST_F(EventSystemTest, eventsystem_register_application_event) { int ret = eventsystem_register_application_event("tizen.system.event.test", &id, &type, system_callback, NULL); EXPECT_EQ(ret, ES_R_OK); + + g_object_unref(_conn); } TEST_F(EventSystemTest, eventsystem_unregister_application_event) { GDBusProxy* _proxy = (GDBusProxy*)g_object_new(G_TYPE_OBJECT, nullptr); + GDBusConnection* _conn = (GDBusConnection*)g_object_new(G_TYPE_OBJECT, nullptr); + + EXPECT_CALL(GetMock(), g_bus_get_sync(_, _, _)) + .WillRepeatedly(Invoke([&](GBusType t, GCancellable* c, GError** e) { return g_object_ref(_conn); })); EXPECT_CALL(GetMock(), g_dbus_is_interface_name(_)). @@ -252,6 +262,8 @@ TEST_F(EventSystemTest, eventsystem_unregister_application_event) { ret = eventsystem_unregister_application_event(id); EXPECT_EQ(ret, ES_R_OK); + + g_object_unref(_conn); } TEST_F(EventSystemTest, eventsystem_keep_last_event_data) {