diff --git a/tests/meson.build b/tests/meson.build index b0c084b..c841220 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,7 +1,5 @@ if get_option('tests') -subdir('mock') - test_env = [ 'G_DEBUG=gc-friendly,fatal-warnings', 'GSETTINGS_BACKEND=memory', @@ -23,6 +21,19 @@ test_link_args = [ '-fPIC', ] +dbus_service_conf = configuration_data() +dbus_service_conf.set('CALLS_BUILD_DIR', '@0@'.format(builddir)) +dbus_service_conf.set('CALLS_BUILD_DIR_STR', '"@0@"'.format(builddir)) +dbus_service_conf.set('CALLS_DBUS_NAME', '"org.gnome.Calls"') +dbus_service_conf.set('CALLS_DBUS_OBJECT_PATH', '"/org/gnome/Calls"') + +dbus_config_h = configure_file(output : 'calls-dbus-config.h', + configuration : dbus_service_conf) + +test_includes = include_directories('.') + +subdir('mock') +subdir('services') test_sources = [ 'test-manager.c' ] diff --git a/tests/services/calls-server.c b/tests/services/calls-server.c new file mode 100644 index 0000000..ac33374 --- /dev/null +++ b/tests/services/calls-server.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2023 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Evangelos Ribeiro Tzaras + * + */ + +#include "calls-dbus-config.h" + +#include "calls-manager.h" +#include "calls-dbus-manager.h" + +#include + + +static void +on_bus_acquired (GDBusConnection *connection, + const char *name, + gpointer user_data) +{ + CallsDBusManager *manager = user_data; + g_autoptr (GError) error = NULL; + + g_print ("Bus acquired: %s\n", name); + + g_assert_true (calls_dbus_manager_register (manager, connection, CALLS_DBUS_OBJECT_PATH, &error)); + g_assert_no_error (error); +} + + +static void +on_name_acquired (GDBusConnection *connection, + const char *name, + gpointer user_data) +{ + g_print ("Name acquired: %s\n", name); +} + +static void +on_name_lost (GDBusConnection *connection, + const char *name, + gpointer user_data) +{ + g_print ("Name lost: %s\n", name); +} + + +int +main (int argc, char *argv[]) +{ + g_autoptr (CallsManager) manager = NULL; + CallsDBusManager *dbus_manager = NULL; + g_autoptr (GMainLoop) loop = g_main_loop_new (NULL, FALSE); + guint bus_id; + + /* Setup environment */ + g_setenv ("GSETTINGS_SCHEMA_DIR", CALLS_BUILD_DIR_STR "/data", TRUE); + g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); + g_setenv ("CALLS_PLUGIN_DIR", CALLS_BUILD_DIR_STR "/plugins", TRUE); + + g_print ("Starting up DBus service\n"); + + manager = calls_manager_get_default (); + dbus_manager = calls_dbus_manager_new (); + calls_manager_add_provider (manager, "dummy"); + + bus_id = g_bus_own_name (G_BUS_TYPE_SESSION, + CALLS_DBUS_NAME, + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus_acquired, + on_name_acquired, + on_name_lost, + dbus_manager, + NULL); + + g_main_loop_run (loop); + + g_print ("Shutting down DBus service\n"); + + calls_manager_remove_provider (manager, "dummy"); + + /* The DBus manager unexports any objects it may still have. + * Do this before releasing the DBus name ownership */ + g_assert_finalize_object (dbus_manager); + + g_bus_unown_name (bus_id); + + return 0; +} diff --git a/tests/services/meson.build b/tests/services/meson.build new file mode 100644 index 0000000..2f5672b --- /dev/null +++ b/tests/services/meson.build @@ -0,0 +1,20 @@ +t = executable('calls-dbus-server', 'calls-server.c', + dbus_config_h, + calls_sources, + c_args : test_cflags, + link_args: test_link_args, + pie: true, + link_with : [calls_vala, libcalls], + dependencies: calls_deps, + include_directories : [ + calls_includes, + test_includes, + ] + ) + +service_file = 'org.gnome.Calls.service' + +service = configure_file ( + input : service_file + '.in', + output : service_file, + configuration : dbus_service_conf) diff --git a/tests/services/org.gnome.Calls.service.in b/tests/services/org.gnome.Calls.service.in new file mode 100644 index 0000000..26dc680 --- /dev/null +++ b/tests/services/org.gnome.Calls.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.gnome.Calls +Exec=@CALLS_BUILD_DIR@/tests/services/calls-dbus-server