| 1 |
#!/bin/sh |
| 2 |
# autopkgtest check: Build and run a program against libnotify, to verify that |
| 3 |
# the headers and pkg-config file are installed correctly |
| 4 |
# (C) 2013 Vibhav Pant |
| 5 |
# (C) 2022 Marco Trevisan |
| 6 |
# Author: Vibhav Pant <[email protected]> |
| 7 |
# Author: Marco Trevisan <[email protected]> |
| 8 |
|
| 9 |
set -e |
| 10 |
|
| 11 |
WORKDIR=$(mktemp -d) |
| 12 |
NOTIFICATION_DAEMON_PID=0 |
| 13 |
|
| 14 |
trap 'kill "$NOTIFICATION_DAEMON_PID"; rm -rf "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM |
| 15 |
cd "$WORKDIR" |
| 16 |
|
| 17 |
if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then |
| 18 |
CROSS_COMPILE="$DEB_HOST_GNU_TYPE-" |
| 19 |
else |
| 20 |
CROSS_COMPILE= |
| 21 |
fi |
| 22 |
|
| 23 |
cat <<EOF > libnotify_test.c |
| 24 |
#include <libnotify/notify.h> |
| 25 |
|
| 26 |
int main(void) |
| 27 |
{ |
| 28 |
NotifyNotification *notify; |
| 29 |
GError *error = NULL; |
| 30 |
GList *caps; |
| 31 |
int id, prev_id; |
| 32 |
|
| 33 |
g_assert_true(notify_init("autopkgtest")); |
| 34 |
g_assert_true(notify_is_initted()); |
| 35 |
|
| 36 |
caps = notify_get_server_caps(); |
| 37 |
g_assert_cmpuint(g_list_length(caps), >, 0); |
| 38 |
g_assert_true(g_list_find_custom(caps, "body", |
| 39 |
(GCompareFunc) g_ascii_strcasecmp)); |
| 40 |
g_clear_list(&caps, g_free); |
| 41 |
|
| 42 |
notify = notify_notification_new("autopkgtest", |
| 43 |
"Testing libnotify", |
| 44 |
NULL); |
| 45 |
notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL); |
| 46 |
|
| 47 |
notify_notification_set_timeout(notify, 500); |
| 48 |
g_object_get(G_OBJECT(notify), "id", &id, NULL); |
| 49 |
g_assert_cmpint(id, ==, 0); |
| 50 |
|
| 51 |
notify_notification_show(notify, &error); |
| 52 |
g_assert_no_error(error); |
| 53 |
|
| 54 |
g_object_get(G_OBJECT(notify), "id", &id, NULL); |
| 55 |
g_assert_cmpint(id, >, 0); |
| 56 |
g_object_unref(notify); |
| 57 |
|
| 58 |
prev_id = id; |
| 59 |
notify = notify_notification_new("autopkgtest2", |
| 60 |
"Testing libnotify2", |
| 61 |
NULL); |
| 62 |
|
| 63 |
notify_notification_show(notify, &error); |
| 64 |
g_object_get(G_OBJECT(notify), "id", &id, NULL); |
| 65 |
g_assert_no_error(error); |
| 66 |
g_assert_cmpint(id, !=, prev_id); |
| 67 |
g_object_unref(notify); |
| 68 |
|
| 69 |
notify_uninit(); |
| 70 |
return 0; |
| 71 |
} |
| 72 |
EOF |
| 73 |
|
| 74 |
# deliberately word-splitting pkg-config output: |
| 75 |
# shellcheck disable=SC2046 |
| 76 |
"${CROSS_COMPILE}gcc" -o libnotify_test libnotify_test.c \ |
| 77 |
$("${CROSS_COMPILE}pkg-config" --cflags --libs libnotify) -Wall -Werror |
| 78 |
echo "build: OK" |
| 79 |
|
| 80 |
[ -x libnotify_test ] |
| 81 |
|
| 82 |
python3 -m dbusmock -t notification_daemon & |
| 83 |
NOTIFICATION_DAEMON_PID=$! |
| 84 |
|
| 85 |
while ! dbus-send --session --print-reply \ |
| 86 |
--dest=org.freedesktop.Notifications \ |
| 87 |
/org/freedesktop/Notifications \ |
| 88 |
org.freedesktop.Notifications.GetCapabilities; do |
| 89 |
sleep 0.5 |
| 90 |
done |
| 91 |
|
| 92 |
env G_MESSAGES_DEBUG=all ./libnotify_test |
| 93 |
|
| 94 |
echo "run: OK" |