Use consistent style in the tests

This commit is contained in:
William Jon McCann 2010-01-29 02:59:26 -05:00
parent a8524aed6a
commit 5d5a284ca6
14 changed files with 530 additions and 418 deletions

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-basic.c Unit test: basics
*
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
@ -23,22 +24,25 @@
#include <stdio.h>
#include <unistd.h>
int main() {
NotifyNotification *n;
int
main ()
{
NotifyNotification *n;
notify_init("Basics");
notify_init ("Basics");
n = notify_notification_new ("Summary",
n = notify_notification_new ("Summary",
"Content that is very long 8374983278r32j4 rhjjfh dw8f 43jhf 8ds7 ur2389f jdbjkt h8924yf jkdbjkt 892hjfiHER98HEJIF BDSJHF hjdhF JKLH 890YRHEJHFU 89HRJKSHdd dddd ddddd dddd ddddd dddd ddddd dddd dddd ddd ddd dddd Fdd d ddddd dddddddd ddddddddhjkewdkjsjfjk sdhkjf hdkj dadasdadsa adsd asd sd saasd fadskfkhsjf hsdkhfkshfjkhsd kjfhsjdkhfj ksdhfkjshkjfsd sadhfjkhaskd jfhsdajkfhkjs dhfkjsdhfkjs adhjkfhasdkj fhdsakjhfjk asdhkjkfhd akfjshjfsk afhjkasdhf jkhsdaj hf kjsdfahkfh sakjhfksdah kfdashkjf ksdahfj shdjdh",
NULL, NULL);
notify_notification_set_timeout (n, 3000); //3 seconds
NULL,
NULL);
notify_notification_set_timeout (n, 3000); //3 seconds
if (!notify_notification_show (n, NULL)) {
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_object_unref(G_OBJECT(n));
g_object_unref (G_OBJECT (n));
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-default-action.c Unit test: default action
*
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
@ -35,43 +36,50 @@
static GMainLoop *loop;
static void callback(NotifyNotification *n, const char *action, void *user_data)
static void
callback (NotifyNotification *n,
const char *action,
void *user_data)
{
printf("callback\n");
assert (action != NULL);
printf ("callback\n");
assert (action != NULL);
assert (strcmp ("default", action) == 0);
notify_notification_close (n, NULL);
notify_notification_close (n, NULL);
g_main_loop_quit(loop);
g_main_loop_quit (loop);
}
int
main()
main ()
{
NotifyNotification *n;
DBusConnection *conn;
DBusConnection *conn;
if (!notify_init("Default Action Test")) exit(1);
if (!notify_init ("Default Action Test"))
exit (1);
conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new(NULL, FALSE);
conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new (NULL, FALSE);
dbus_connection_setup_with_g_main(conn, NULL);
dbus_connection_setup_with_g_main (conn, NULL);
n = notify_notification_new ("Matt is online", "", NULL, NULL);
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
notify_notification_add_action (n, "default", "Do Default Action",
(NotifyActionCallback)callback,
NULL, NULL);
notify_notification_set_category (n, "presence.online");
notify_notification_add_action (n,
"default",
"Do Default Action",
(NotifyActionCallback) callback,
NULL,
NULL);
notify_notification_set_category (n, "presence.online");
if (!notify_notification_show (n, NULL)) {
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_main_loop_run(loop);
g_main_loop_run (loop);
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-default-action.c Unit test: error handling
*
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
@ -23,26 +24,26 @@
#include <stdio.h>
#include <unistd.h>
int main() {
NotifyNotification *n;
int
main ()
{
NotifyNotification *n;
g_type_init ();
g_type_init ();
notify_init("Error Handling");
notify_init ("Error Handling");
n = notify_notification_new ("Summary",
"Content",
NULL, NULL);
notify_notification_set_timeout (n, 3000); //3 seconds
n = notify_notification_new ("Summary", "Content", NULL, NULL);
notify_notification_set_timeout (n, 3000); //3 seconds
/* TODO: Create an error condition */
/* TODO: Create an error condition */
if (!notify_notification_show (n, NULL)) {
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-image.c Unit test: images
*
* @Copyright(C) 2004 Mike Hearn <mike@navi.cx>
@ -39,77 +40,83 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
GMainLoop *loop;
GMainLoop *loop;
NotifyNotification *n;
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
char *file;
char *uri;
GdkPixbuf *icon;
GtkWidget *helper;
char *file;
char *uri;
GdkPixbuf *icon;
GtkWidget *helper;
gtk_init(&argc, &argv);
gtk_init (&argc, &argv);
if (!notify_init("Images Test"))
exit(1);
if (!notify_init ("Images Test"))
exit (1);
/* Stock icon */
n = notify_notification_new("Icon Test", "Testing stock icon",
"appointment-new", NULL);
/* Stock icon */
n = notify_notification_new ("Icon Test",
"Testing stock icon",
"appointment-new",
NULL);
if (!notify_notification_show(n, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_object_unref(G_OBJECT(n));
g_object_unref (G_OBJECT (n));
file = g_get_current_dir();
uri = g_strdup_printf("file://%s/%s", file, "applet-critical.png");
file = g_get_current_dir ();
uri = g_strdup_printf ("file://%s/%s",
file,
"applet-critical.png");
g_free(file);
printf("sending %s\n", uri);
g_free (file);
printf ("sending %s\n", uri);
/* URIs */
n = notify_notification_new("Alert!", "Testing URI icons", uri, NULL);
/* URIs */
n = notify_notification_new ("Alert!",
"Testing URI icons",
uri,
NULL);
if (!notify_notification_show(n, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_object_unref(G_OBJECT(n));
g_object_unref (G_OBJECT (n));
/* Raw image */
n = notify_notification_new("Raw image test",
"Testing sending raw pixbufs", NULL, NULL);
/* Raw image */
n = notify_notification_new ("Raw image test",
"Testing sending raw pixbufs",
NULL,
NULL);
/*
* This is just a hack to get a stock icon's pixbuf in a realworld app
* if you were sending bitmapped data you would know the file location
* and open it up with a method that could generate a bmp for you
*/
helper = gtk_button_new();
icon = gtk_widget_render_icon(helper,
GTK_STOCK_DIALOG_QUESTION,
GTK_ICON_SIZE_DIALOG,
NULL);
gtk_widget_destroy(helper);
/*
* This is just a hack to get a stock icon's pixbuf in a realworld app
* if you were sending bitmapped data you would know the file location
* and open it up with a method that could generate a bmp for you
*/
helper = gtk_button_new ();
icon = gtk_widget_render_icon (helper,
GTK_STOCK_DIALOG_QUESTION,
GTK_ICON_SIZE_DIALOG,
NULL);
gtk_widget_destroy (helper);
notify_notification_set_icon_from_pixbuf(n, icon);
g_object_unref(G_OBJECT(icon));
notify_notification_set_icon_from_pixbuf (n, icon);
g_object_unref (G_OBJECT (icon));
if (!notify_notification_show(n, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_object_unref(G_OBJECT(n));
g_object_unref (G_OBJECT (n));
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-markup.c Unit test: markup
*
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
@ -23,21 +24,24 @@
#include <stdio.h>
#include <unistd.h>
int main() {
NotifyNotification *n;
int
main ()
{
NotifyNotification *n;
notify_init("Markup");
notify_init ("Markup");
n = notify_notification_new ("Summary",
"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, "
"<a href='http://www.google.com'>linked</a> text",
NULL, NULL);
notify_notification_set_timeout (n, 3000); //3 seconds
n = notify_notification_new ("Summary",
"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, "
"<a href='http://www.google.com'>linked</a> text",
NULL,
NULL);
notify_notification_set_timeout (n, 3000); //3 seconds
if (!notify_notification_show (n, NULL)) {
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-multi-actions.c Unit test: multiple actions
*
* @Copyright(C) 2004 Mike Hearn <mike@navi.cx>
@ -35,83 +36,96 @@
static GMainLoop *loop;
static void
help_callback(NotifyNotification *n, const char *action)
help_callback (NotifyNotification *n,
const char *action)
{
g_assert(action != NULL);
g_assert(strcmp(action, "help") == 0);
g_assert (action != NULL);
g_assert (strcmp (action, "help") == 0);
printf("You clicked Help\n");
printf ("You clicked Help\n");
notify_notification_close(n, NULL);
notify_notification_close (n, NULL);
g_main_loop_quit(loop);
g_main_loop_quit (loop);
}
static void
ignore_callback(NotifyNotification *n, const char *action)
ignore_callback (NotifyNotification *n,
const char *action)
{
g_assert(action != NULL);
g_assert(strcmp(action, "ignore") == 0);
g_assert (action != NULL);
g_assert (strcmp (action, "ignore") == 0);
printf("You clicked Ignore\n");
printf ("You clicked Ignore\n");
notify_notification_close(n, NULL);
notify_notification_close (n, NULL);
g_main_loop_quit(loop);
g_main_loop_quit (loop);
}
static void
empty_callback(NotifyNotification *n, const char *action)
empty_callback (NotifyNotification *n,
const char *action)
{
g_assert(action != NULL);
g_assert(strcmp(action, "empty") == 0);
g_assert (action != NULL);
g_assert (strcmp (action, "empty") == 0);
printf("You clicked Empty Trash\n");
printf ("You clicked Empty Trash\n");
notify_notification_close(n, NULL);
notify_notification_close (n, NULL);
g_main_loop_quit(loop);
g_main_loop_quit (loop);
}
int
main(int argc, char **argv)
main (int argc, char **argv)
{
NotifyNotification *n;
DBusConnection *conn;
NotifyNotification *n;
DBusConnection *conn;
if (!notify_init("Multi Action Test"))
exit(1);
if (!notify_init ("Multi Action Test"))
exit (1);
conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new(NULL, FALSE);
conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new (NULL, FALSE);
dbus_connection_setup_with_g_main(conn, NULL);
dbus_connection_setup_with_g_main (conn, NULL);
n = notify_notification_new("Low disk space",
"You can free up some disk space by "
"emptying the trash can.",
NULL, NULL);
notify_notification_set_urgency(n, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout(n, NOTIFY_EXPIRES_DEFAULT);
notify_notification_add_action(n, "help", "Help",
(NotifyActionCallback)help_callback,
NULL, NULL);
notify_notification_add_action(n, "ignore", "Ignore",
(NotifyActionCallback)ignore_callback,
NULL, NULL);
notify_notification_add_action(n, "empty", "Empty Trash",
(NotifyActionCallback)empty_callback,
NULL, NULL);
notify_notification_set_category(n, "device");
n = notify_notification_new ("Low disk space",
"You can free up some disk space by "
"emptying the trash can.",
NULL,
NULL);
notify_notification_set_urgency (n, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
notify_notification_add_action (n,
"help",
"Help",
(NotifyActionCallback) help_callback,
NULL,
NULL);
notify_notification_add_action (n,
"ignore",
"Ignore",
(NotifyActionCallback)
ignore_callback,
NULL,
NULL);
notify_notification_add_action (n,
"empty",
"Empty Trash",
(NotifyActionCallback) empty_callback,
NULL,
NULL);
notify_notification_set_category (n, "device");
if (!notify_notification_show(n, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_main_loop_run(loop);
g_main_loop_run (loop);
return 0;
return 0;
}

View File

@ -1,67 +1,94 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or(at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <libnotify/notify.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <gtk/gtk.h>
static int count = 0;
static int count = 0;
static void
on_exposed(GtkWidget *widget, GdkEventExpose *ev, void *user_data)
on_exposed (GtkWidget *widget,
GdkEventExpose *ev,
void *user_data)
{
NotifyNotification *n = NOTIFY_NOTIFICATION(user_data);
NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
g_signal_handlers_disconnect_by_func(widget, on_exposed, user_data);
g_signal_handlers_disconnect_by_func (widget, on_exposed, user_data);
notify_notification_show(n, NULL);
notify_notification_show (n, NULL);
}
static void
on_clicked(GtkButton *button, void *user_data)
on_clicked (GtkButton *button,
void *user_data)
{
gchar *buf;
NotifyNotification *n = NOTIFY_NOTIFICATION(user_data);
gchar *buf;
NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
count++;
buf = g_strdup_printf("You clicked the button %i times", count);
notify_notification_update(n, "Widget Attachment Test", buf, NULL);
g_free(buf);
count++;
buf = g_strdup_printf ("You clicked the button %i times", count);
notify_notification_update (n, "Widget Attachment Test", buf, NULL);
g_free (buf);
notify_notification_show(n, NULL);
notify_notification_show (n, NULL);
}
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
NotifyNotification *n;
GtkWidget *window;
GtkWidget *button;
NotifyNotification *n;
GtkWidget *window;
GtkWidget *button;
gtk_init(&argc, &argv);
notify_init("Replace Test");
gtk_init (&argc, &argv);
notify_init ("Replace Test");
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(gtk_main_quit), NULL);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window),
"delete_event",
G_CALLBACK (gtk_main_quit),
NULL);
button = gtk_button_new_with_label("click here to change notification");
gtk_container_add(GTK_CONTAINER(window), button);
button = gtk_button_new_with_label ("click here to change notification");
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show_all(window);
gtk_widget_show_all (window);
n = notify_notification_new("Widget Attachment Test",
"Button has not been clicked yet",
NULL, //no icon
button); //attach to button
n = notify_notification_new ("Widget Attachment Test",
"Button has not been clicked yet",
NULL, //no icon
button); //attach to button
notify_notification_set_timeout(n, 0); //don't timeout
notify_notification_set_timeout (n, 0); //don't timeout
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(on_clicked), n);
g_signal_connect_after(G_OBJECT(button), "expose-event",
G_CALLBACK(on_exposed), n);
g_signal_connect (G_OBJECT (button),
"clicked",
G_CALLBACK (on_clicked),
n);
g_signal_connect_after (G_OBJECT (button),
"expose-event",
G_CALLBACK (on_exposed),
n);
gtk_main();
gtk_main ();
return 0;
return 0;
}

View File

@ -1,41 +1,67 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or(at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <libnotify/notify.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
int main() {
NotifyNotification *n;
GError *error;
error = NULL;
int
main ()
{
NotifyNotification *n;
GError *error;
error = NULL;
g_type_init ();
g_type_init ();
notify_init("Replace Test");
n = notify_notification_new ("Summary", "First message",
NULL, //no icon
NULL); //don't attach to widget
notify_init ("Replace Test");
notify_notification_set_timeout (n, 0); //don't timeout
if (!notify_notification_show (n, &error)) {
fprintf(stderr, "failed to send notification: %s\n", error->message);
g_error_free (error);
return 1;
}
n = notify_notification_new ("Summary",
"First message",
NULL, //no icon
NULL); //don't attach to widget
sleep(3);
notify_notification_update (n, "Second Summary",
"First mesage was replaced", NULL);
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
notify_notification_set_timeout (n, 0); //don't timeout
if (!notify_notification_show (n, &error)) {
fprintf(stderr, "failed to send notification: %s\n", error->message);
g_error_free (error);
return 1;
}
if (!notify_notification_show (n, &error)) {
fprintf (stderr, "failed to send notification: %s\n",
error->message);
g_error_free (error);
return 1;
}
return 0;
sleep (3);
notify_notification_update (n,
"Second Summary",
"First mesage was replaced",
NULL);
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
if (!notify_notification_show (n, &error)) {
fprintf (stderr,
"failed to send notification: %s\n",
error->message);
g_error_free (error);
return 1;
}
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-server-info.c Retrieves the server info and caps
*
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
@ -24,38 +25,36 @@
#include <stdlib.h>
int
main(int argc, char **argv)
main (int argc, char **argv)
{
GList *l, *caps;
char *name, *vendor, *version, *spec_version;
GList *l, *caps;
char *name, *vendor, *version, *spec_version;
notify_init("TestCaps");
notify_init ("TestCaps");
if (!notify_get_server_info(&name, &vendor, &version, &spec_version))
{
fprintf(stderr, "Failed to receive server info.\n");
exit(1);
}
if (!notify_get_server_info (&name, &vendor, &version, &spec_version)) {
fprintf (stderr, "Failed to receive server info.\n");
exit (1);
}
printf("Name: %s\n", name);
printf("Vendor: %s\n", vendor);
printf("Version: %s\n", version);
printf("Spec Version: %s\n", spec_version);
printf("Capabilities:\n");
printf ("Name: %s\n", name);
printf ("Vendor: %s\n", vendor);
printf ("Version: %s\n", version);
printf ("Spec Version: %s\n", spec_version);
printf ("Capabilities:\n");
caps = notify_get_server_caps();
caps = notify_get_server_caps ();
if (caps == NULL)
{
fprintf(stderr, "Failed to receive server caps.\n");
exit(1);
}
if (caps == NULL) {
fprintf (stderr, "Failed to receive server caps.\n");
exit (1);
}
for (l = caps; l != NULL; l = l->next)
printf("\t%s\n", (char *)l->data);
for (l = caps; l != NULL; l = l->next)
printf ("\t%s\n", (char *) l->data);
g_list_foreach(caps, (GFunc)g_free, NULL);
g_list_free(caps);
g_list_foreach (caps, (GFunc) g_free, NULL);
g_list_free (caps);
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-size-changes.c Unit test: Notification size changes
*
* @Copyright (C) 2006 Christian Hammond <chipx86@chipx86.com>
@ -24,61 +25,63 @@
#include <unistd.h>
int
main()
main ()
{
NotifyNotification *n1, *n2, *n3;
NotifyNotification *n1, *n2, *n3;
notify_init("Size Changes");
notify_init ("Size Changes");
n1 = notify_notification_new("Notification 1", "Notification number 1!",
NULL, NULL);
notify_notification_set_timeout(n1, 7000);
n1 = notify_notification_new ("Notification 1",
"Notification number 1!",
NULL,
NULL);
notify_notification_set_timeout (n1, 7000);
if (!notify_notification_show(n1, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n1, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_object_unref(G_OBJECT(n1));
g_object_unref (G_OBJECT (n1));
n2 = notify_notification_new("Notification 2", "Notification number 2!",
NULL, NULL);
notify_notification_set_timeout(n2, 7000);
n2 = notify_notification_new ("Notification 2",
"Notification number 2!",
NULL,
NULL);
notify_notification_set_timeout (n2, 7000);
if (!notify_notification_show(n2, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n2, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
n3 = notify_notification_new("Notification 3", "Notification number 3!",
NULL, NULL);
notify_notification_set_timeout(n3, 7000);
n3 = notify_notification_new ("Notification 3",
"Notification number 3!",
NULL,
NULL);
notify_notification_set_timeout (n3, 7000);
if (!notify_notification_show(n3, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n3, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_object_unref(G_OBJECT(n3));
g_object_unref (G_OBJECT (n3));
sleep(2);
sleep (2);
notify_notification_update(n2, "Longer Notification 2",
"This is a much longer notification.\n"
"Two lines.\n"
"Well, okay, three.\n"
"Last one.",
NULL);
notify_notification_update (n2,
"Longer Notification 2",
"This is a much longer notification.\n"
"Two lines.\n"
"Well, okay, three.\n" "Last one.",
NULL);
if (!notify_notification_show(n2, NULL))
{
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n2, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-urgency.c Unit test: urgency levels
*
* @Copyright(C) 2006 Christian Hammond <chipx8@chipx86.com>
@ -23,51 +24,52 @@
#include <stdlib.h>
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
NotifyNotification *n;
NotifyNotification *n;
notify_init("Urgency");
notify_init ("Urgency");
n = notify_notification_new("Low Urgency", "Joe signed online.",
NULL, NULL);
notify_notification_set_urgency(n, NOTIFY_URGENCY_LOW);
if (!notify_notification_show(n, NULL))
{
fprintf(stderr, "failed to send notification\n");
exit(1);
}
n = notify_notification_new ("Low Urgency",
"Joe signed online.",
NULL,
NULL);
notify_notification_set_urgency (n, NOTIFY_URGENCY_LOW);
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
exit (1);
}
g_object_unref(G_OBJECT(n));
g_object_unref (G_OBJECT (n));
n = notify_notification_new("Normal Urgency",
"You have a meeting in 10 minutes.",
NULL, NULL);
notify_notification_set_urgency(n, NOTIFY_URGENCY_NORMAL);
if (!notify_notification_show(n, NULL))
{
fprintf(stderr, "failed to send notification\n");
exit(1);
}
n = notify_notification_new ("Normal Urgency",
"You have a meeting in 10 minutes.",
NULL,
NULL);
notify_notification_set_urgency (n, NOTIFY_URGENCY_NORMAL);
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
exit (1);
}
g_object_unref(G_OBJECT(n));
g_object_unref (G_OBJECT (n));
n = notify_notification_new("Critical Urgency",
"This message will self-destruct in 10 "
"seconds.",
NULL, NULL);
notify_notification_set_urgency(n, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout(n, 10000); // 10 seconds
n = notify_notification_new ("Critical Urgency",
"This message will self-destruct in 10 "
"seconds.",
NULL,
NULL);
notify_notification_set_urgency (n, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout (n, 10000); // 10 seconds
if (!notify_notification_show(n, NULL))
{
fprintf(stderr, "failed to send notification\n");
exit(1);
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
exit (1);
}
g_object_unref(G_OBJECT(n));
g_object_unref (G_OBJECT (n));
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-xy-actions.c Unit test: X, Y hints and actions
*
* @Copyright (C) 2006 Christian Hammond <chipx86@chipx86.com>
@ -31,46 +32,54 @@
static GMainLoop *loop;
static void
action_cb(NotifyNotification *n, const char *action)
action_cb (NotifyNotification *n,
const char *action)
{
printf("You clicked '%s'\n", action);
printf ("You clicked '%s'\n", action);
g_main_loop_quit(loop);
g_main_loop_quit (loop);
}
int
main(int argc, char **argv)
main (int argc, char **argv)
{
NotifyNotification *n;
DBusConnection *conn;
NotifyNotification *n;
DBusConnection *conn;
notify_init("XY");
notify_init ("XY");
conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new(NULL, FALSE);
conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new (NULL, FALSE);
dbus_connection_setup_with_g_main(conn, NULL);
dbus_connection_setup_with_g_main (conn, NULL);
n = notify_notification_new("System update available",
"New system updates are available. It is "
"recommended that you install the updates.",
NULL, NULL);
n = notify_notification_new ("System update available",
"New system updates are available. It is "
"recommended that you install the updates.",
NULL,
NULL);
notify_notification_set_hint_int32(n, "x", 600);
notify_notification_set_hint_int32(n, "y", 10);
notify_notification_add_action(n, "help", "Help",
(NotifyActionCallback)action_cb,
NULL, NULL);
notify_notification_add_action(n, "update", "Update",
(NotifyActionCallback)action_cb,
NULL, NULL);
notify_notification_set_hint_int32 (n, "x", 600);
notify_notification_set_hint_int32 (n, "y", 10);
notify_notification_add_action (n,
"help",
"Help",
(NotifyActionCallback) action_cb,
NULL,
NULL);
notify_notification_add_action (n,
"update",
"Update",
(NotifyActionCallback) action_cb,
NULL,
NULL);
if (!notify_notification_show(n, NULL)) {
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
g_main_loop_run(loop);
g_main_loop_run (loop);
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-xy.c Unit test: X, Y hints
*
* @Copyright(C) 2005 Christian Hammond <chipx86@chipx86.com>
@ -10,7 +11,7 @@
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
@ -25,68 +26,71 @@
#include <unistd.h>
static void
_handle_closed(GObject *obj)
_handle_closed (GObject * obj)
{
g_message("closing");
g_object_unref(obj);
g_message ("closing");
g_object_unref (obj);
}
static void
emit_notification(int x, int y)
emit_notification (int x, int y)
{
char *buffer;
NotifyNotification *n;
char *buffer;
NotifyNotification *n;
buffer = g_strdup_printf("This notification should point to %d, %d.",
x, y);
buffer = g_strdup_printf ("This notification should point to %d, %d.",
x,
y);
n = notify_notification_new("X, Y Test", buffer, NULL, NULL);
g_free(buffer);
n = notify_notification_new ("X, Y Test", buffer, NULL, NULL);
g_free (buffer);
notify_notification_set_hint_int32(n, "x", x);
notify_notification_set_hint_int32(n, "y", y);
notify_notification_set_hint_int32 (n, "x", x);
notify_notification_set_hint_int32 (n, "y", y);
g_signal_connect(G_OBJECT(n), "closed",
G_CALLBACK(_handle_closed), NULL);
g_signal_connect (G_OBJECT (n),
"closed",
G_CALLBACK (_handle_closed),
NULL);
if (!notify_notification_show(n, NULL))
fprintf(stderr, "failed to send notification\n");
if (!notify_notification_show (n, NULL))
fprintf (stderr, "failed to send notification\n");
}
static gboolean
_popup_random_bubble(gpointer unused)
_popup_random_bubble (gpointer unused)
{
GdkDisplay *display;
GdkScreen *screen;
GdkDisplay *display;
GdkScreen *screen;
int screen_x2, screen_y2;
int x, y;
int screen_x2, screen_y2;
int x, y;
display = gdk_display_get_default();
screen = gdk_display_get_default_screen(display);
screen_x2 = gdk_screen_get_width(screen) - 1;
screen_y2 = gdk_screen_get_height(screen) - 1;
display = gdk_display_get_default ();
screen = gdk_display_get_default_screen (display);
screen_x2 = gdk_screen_get_width (screen) - 1;
screen_y2 = gdk_screen_get_height (screen) - 1;
x = g_random_int_range(0, screen_x2);
y = g_random_int_range(0, screen_y2);
emit_notification(x, y);
x = g_random_int_range (0, screen_x2);
y = g_random_int_range (0, screen_y2);
emit_notification (x, y);
return TRUE;
return TRUE;
}
int
main(int argc, char **argv)
main (int argc, char **argv)
{
GMainLoop *loop;
GMainLoop *loop;
gdk_init(&argc, &argv);
gdk_init (&argc, &argv);
notify_init("XY");
notify_init ("XY");
g_timeout_add(1000, _popup_random_bubble, NULL);
g_timeout_add (1000, _popup_random_bubble, NULL);
loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
return 0;
return 0;
}

View File

@ -1,4 +1,5 @@
/*
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* @file tests/test-xy.c Unit test: X, Y hints
*
* @Copyright (C) 2005 Christian Hammond <chipx86@chipx86.com>
@ -23,22 +24,25 @@
#include <stdio.h>
#include <unistd.h>
int main() {
NotifyNotification *n;
int
main ()
{
NotifyNotification *n;
notify_init("XY");
notify_init ("XY");
n = notify_notification_new ("X, Y Test",
n = notify_notification_new ("X, Y Test",
"This notification should point to 150, 10",
NULL, NULL);
NULL,
NULL);
notify_notification_set_hint_int32 (n, "x", 150);
notify_notification_set_hint_int32 (n, "y", 10);
notify_notification_set_hint_int32 (n, "x", 150);
notify_notification_set_hint_int32 (n, "y", 10);
if (!notify_notification_show (n, NULL)) {
fprintf(stderr, "failed to send notification\n");
return 1;
}
if (!notify_notification_show (n, NULL)) {
fprintf (stderr, "failed to send notification\n");
return 1;
}
return 0;
return 0;
}