#!/bin/sh # autopkgtest check: Build and run a program against libnotify, to verify that # the headers and pkg-config file are installed correctly # (C) 2013 Vibhav Pant # (C) 2022 Marco Trevisan # Author: Vibhav Pant # Author: Marco Trevisan set -e WORKDIR=$(mktemp -d) NOTIFICATION_DAEMON_PID=0 trap 'kill "$NOTIFICATION_DAEMON_PID"; rm -rf "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM cd "$WORKDIR" if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then CROSS_COMPILE="$DEB_HOST_GNU_TYPE-" else CROSS_COMPILE= fi cat < libnotify_test.c #include int main(void) { NotifyNotification *notify; GError *error = NULL; GList *caps; int id, prev_id; g_assert_true(notify_init("autopkgtest")); g_assert_true(notify_is_initted()); caps = notify_get_server_caps(); g_assert_cmpuint(g_list_length(caps), >, 0); g_assert_true(g_list_find_custom(caps, "body", (GCompareFunc) g_ascii_strcasecmp)); g_clear_list(&caps, g_free); notify = notify_notification_new("autopkgtest", "Testing libnotify", NULL); notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL); notify_notification_set_timeout(notify, 500); g_object_get(G_OBJECT(notify), "id", &id, NULL); g_assert_cmpint(id, ==, 0); notify_notification_show(notify, &error); g_assert_no_error(error); g_object_get(G_OBJECT(notify), "id", &id, NULL); g_assert_cmpint(id, >, 0); g_object_unref(notify); prev_id = id; notify = notify_notification_new("autopkgtest2", "Testing libnotify2", NULL); notify_notification_show(notify, &error); g_object_get(G_OBJECT(notify), "id", &id, NULL); g_assert_no_error(error); g_assert_cmpint(id, !=, prev_id); g_object_unref(notify); notify_uninit(); return 0; } EOF # deliberately word-splitting pkg-config output: # shellcheck disable=SC2046 "${CROSS_COMPILE}gcc" -o libnotify_test libnotify_test.c \ $("${CROSS_COMPILE}pkg-config" --cflags --libs libnotify) -Wall -Werror echo "build: OK" [ -x libnotify_test ] python3 -m dbusmock -t notification_daemon & NOTIFICATION_DAEMON_PID=$! while ! dbus-send --session --print-reply \ --dest=org.freedesktop.Notifications \ /org/freedesktop/Notifications \ org.freedesktop.Notifications.GetCapabilities; do sleep 0.5 done env G_MESSAGES_DEBUG=all ./libnotify_test echo "run: OK"