root/trunk/libnotify/tests/test-default-action.c

Revision 2954 (checked in by chipx86, 2 years ago)

Added a test program that displays three notifications and then changes the amount of text in one of them.

Line 
1 /*
2  * @file tests/test-default-action.c Unit test: default action
3  *
4  * @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA  02111-1307, USA.
20  */
21
22 #include <libnotify/notify.h>
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <assert.h>
27 #include <string.h>
28
29 #define DBUS_API_SUBJECT_TO_CHANGE
30
31 #include <glib.h>
32 #include <dbus/dbus.h>
33 #include <dbus/dbus-glib.h>
34 #include <dbus/dbus-glib-lowlevel.h>
35
36 static GMainLoop *loop;
37
38 static void callback(NotifyNotification *n, const char *action, void *user_data)
39 {
40     printf("callback\n");
41     assert (action != NULL);
42         assert (strcmp ("default", action) == 0);
43
44     notify_notification_close (n, NULL);
45
46     g_main_loop_quit(loop);
47 }
48
49 int
50 main()
51 {
52         NotifyNotification *n;
53     DBusConnection *conn;
54
55     if (!notify_init("Default Action Test")) exit(1);
56
57     conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
58     loop = g_main_loop_new(NULL, FALSE);
59
60     dbus_connection_setup_with_g_main(conn, NULL);
61
62         n = notify_notification_new ("Matt is online", "", NULL, NULL);
63         notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
64         notify_notification_add_action (n, "default", "Do Default Action",
65                                         (NotifyActionCallback)callback,
66                                         NULL, NULL);
67     notify_notification_set_category (n, "presence.online");
68
69     if (!notify_notification_show (n, NULL)) {
70         fprintf(stderr, "failed to send notification\n");
71         return 1;
72     }
73
74     g_main_loop_run(loop);
75
76     return 0;
77 }
Note: See TracBrowser for help on using the browser.