From e8ecc3d0c13fcfcf78923373de76d4ab1fd15b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 24 Mar 2025 11:04:53 +0100 Subject: [PATCH] libfeedback: Only cancel feedbacks if ever inited MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If lfb_init() wasn't called before lfb_uninit() we'd otherwise raise a critical which isn't nice for a library. Signed-off-by: Guido Günther --- libfeedback/lfb-main.c | 3 ++- tests/meson.build | 22 ++++++++++++---------- tests/test-lfb-main.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 tests/test-lfb-main.c diff --git a/libfeedback/lfb-main.c b/libfeedback/lfb-main.c index 7059f9e..fd220ef 100644 --- a/libfeedback/lfb-main.c +++ b/libfeedback/lfb-main.c @@ -112,7 +112,8 @@ lfb_uninit (void) _initted = FALSE; /* Cancel all feedbacks that the client forgot to clean up */ - lfb_cancel_feedbacks (); + if (_active_ids) + lfb_cancel_feedbacks (); g_clear_pointer (&_active_ids, g_hash_table_destroy); g_clear_pointer (&_app_id, g_free); g_clear_object (&_proxy); diff --git a/tests/meson.build b/tests/meson.build index 71e7bd6..a4f8bda 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -44,16 +44,18 @@ if get_option('tests') test(test, t, env: test_env, depends: fbd_exe) endif - test = 'lfb-event' - t = executable( - 'test-@0@'.format(test), - ['test-@0@.c'.format(test)], - c_args: test_lfb_cflags, - pie: true, - link_args: test_lfb_link_args, - dependencies: test_lfb_deps, - ) - test(test, t, env: test_env) + unit_tests = ['lfb-event', 'lfb-main'] + foreach test : unit_tests + t = executable( + 'test-@0@'.format(test), + ['test-@0@.c'.format(test)], + c_args: test_lfb_cflags, + pie: true, + link_args: test_lfb_link_args, + dependencies: test_lfb_deps, + ) + test(test, t, env: test_env) + endforeach # Daemon Unit tests if get_option('daemon') diff --git a/tests/test-lfb-main.c b/tests/test-lfb-main.c new file mode 100644 index 0000000..241250c --- /dev/null +++ b/tests/test-lfb-main.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2025 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0+ + * + * Author: Guido Günther + */ + +#include "libfeedback.h" +#include + +/* unpaired uninit not raise any criticals */ +static void +test_lfb_main_uninit (void) +{ + g_assert_false (lfb_is_initted ()); + lfb_uninit (); + g_assert_false (lfb_is_initted ()); +} + +gint +main (gint argc, gchar *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_autoptr(GTestDBus) bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + + g_test_add_func ("/feedbackd/libfeedback/lfb-main/uninit", test_lfb_main_uninit); + + return g_test_run(); +}