add tests
This commit is contained in:
parent
5918a785f4
commit
22e87adf07
|
@ -0,0 +1,29 @@
|
|||
bin_PROGRAMS = test-replace test-default-action test-multi-actions test-image test-basic test-error test-animation test-markup
|
||||
|
||||
common_ldflags = \
|
||||
$(top_builddir)/libnotify/libnotify.la \
|
||||
$(PACKAGE_LIBS)
|
||||
|
||||
# FIXME: don't install these
|
||||
|
||||
test_replace_SOURCES = test-replace.c
|
||||
test_replace_LDADD = $(common_ldflags)
|
||||
test_default_action_SOURCES = test-default-action.c
|
||||
test_default_action_LDADD = $(common_ldflags)
|
||||
test_multi_actions_SOURCES = test-multi-actions.c
|
||||
test_multi_actions_LDADD = $(common_ldflags)
|
||||
test_image_SOURCES = test-image.c
|
||||
test_image_LDADD = $(common_ldflags)
|
||||
test_basic_SOURCES = test-basic.c
|
||||
test_basic_LDADD = $(common_ldflags)
|
||||
test_error_SOURCES = test-error.c
|
||||
test_error_LDADD = $(common_ldflags)
|
||||
|
||||
test_animation_SOURCES = test-animation.c
|
||||
test_animation_LDADD = $(common_ldflags)
|
||||
test_animation_LDFLAGS = `pkg-config --libs gdk-pixbuf-2.0`
|
||||
|
||||
test_markup_SOURCES = test-markup.c
|
||||
test_markup_LDADD = $(common_ldflags)
|
||||
|
||||
INCLUDES = $(PACKAGE_CFLAGS) `pkg-config --cflags gdk-pixbuf-2.0`
|
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* @file tests/test-animation.c Unit test: animated images
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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 <math.h>
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
|
||||
/// WRITE ME! ///
|
||||
|
||||
int frames = 10;
|
||||
|
||||
// returns array of pixbufs for a pulsing animation
|
||||
GdkPixbuf **generate_animation()
|
||||
{
|
||||
int i;
|
||||
GdkPixbuf *file = gdk_pixbuf_new_from_file("applet-critical.png");
|
||||
double alpha = 1.0;
|
||||
|
||||
GdkPixbuf **array = malloc(sizeof(GdkPixbuf *) * frames);
|
||||
|
||||
for (i = 0; i < frames; i++)
|
||||
{
|
||||
GdkPixbuf *buf = gdk_pixbuf_copy(file);
|
||||
|
||||
alpha = sin(M_PI + ((M_PI / frames) * i)) + 1.0;
|
||||
|
||||
gdk_pixbuf_composite(file, buf, 0, 0,
|
||||
gdk_pixbuf_get_width(buf),
|
||||
gdk_pixbuf_get_height(buf),
|
||||
0, 0, 1.0, 1.0, GDK_INTERP_NEAREST,
|
||||
alpha);
|
||||
|
||||
array[i] = buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
notify_init("Animations");
|
||||
|
||||
for (int i = 0; i < frames; i++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
"Summary", "Content",
|
||||
NULL, // no icon
|
||||
TRUE, time(NULL) + 5,
|
||||
NULL, // no user data
|
||||
0); // no actions
|
||||
|
||||
if (!n) {
|
||||
fprintf(stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* @file tests/test-basic.c Unit test: basics
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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>
|
||||
|
||||
int main() {
|
||||
notify_init("Basics");
|
||||
|
||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
"Summary", "Content",
|
||||
NULL, // no icon
|
||||
TRUE, time(NULL) + 5,
|
||||
NULL, // no user data
|
||||
0); // no actions
|
||||
|
||||
if (!n) {
|
||||
fprintf(stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* @file tests/test-default-action.c Unit test: default action
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define DBUS_API_SUBJECT_TO_CHANGE 1
|
||||
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
GMainLoop *loop;
|
||||
NotifyHandle *n;
|
||||
|
||||
static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
|
||||
{
|
||||
assert( uid == 0 );
|
||||
|
||||
notify_close(n);
|
||||
|
||||
g_main_loop_quit(loop);
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!notify_init("Default Action Test")) exit(1);
|
||||
|
||||
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
dbus_connection_setup_with_g_main(conn, NULL);
|
||||
|
||||
n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
"Matt is online", NULL,
|
||||
NULL, // no icon
|
||||
FALSE, 0, // does not expire
|
||||
NULL, // no user data
|
||||
1,
|
||||
0, "default", callback); // 1 action
|
||||
|
||||
if (!n) {
|
||||
fprintf(stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_main_loop_run(loop);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* @file tests/test-default-action.c Unit test: error handling
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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>
|
||||
|
||||
int main() {
|
||||
notify_init("Error Handling");
|
||||
|
||||
NotifyIcon *icon = notify_icon_new("/no-such");
|
||||
|
||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
"Summary", "Content",
|
||||
icon, // no icon
|
||||
TRUE, time(NULL) + 5,
|
||||
NULL, // no user data
|
||||
0);
|
||||
|
||||
notify_icon_destroy(icon);
|
||||
|
||||
if (n) {
|
||||
fprintf(stderr, "failed to get an error ??\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* @file tests/test-image.c Unit test: images
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define DBUS_API_SUBJECT_TO_CHANGE 1
|
||||
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
GMainLoop *loop;
|
||||
NotifyHandle *n;
|
||||
|
||||
static void send(char *i, size_t rawlen, char *s, char *b)
|
||||
{
|
||||
NotifyIcon *icon;
|
||||
|
||||
if (rawlen > 0)
|
||||
icon = notify_icon_new_with_data(rawlen, i);
|
||||
else
|
||||
icon = notify_icon_new(i);
|
||||
|
||||
n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
s, b,
|
||||
icon,
|
||||
TRUE, time(NULL) + 5,
|
||||
NULL, // no user data
|
||||
0);
|
||||
|
||||
if (!n) {
|
||||
fprintf(stderr, "failed to send notification\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
notify_icon_destroy(icon);
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!notify_init("Images Test")) exit(1);
|
||||
|
||||
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
dbus_connection_setup_with_g_main(conn, NULL);
|
||||
|
||||
// these images exist on fedora core 2 workstation profile. might not on yours
|
||||
|
||||
send("gnome-starthere",
|
||||
0,
|
||||
"Welcome to Linux!",
|
||||
"This is your first login. To begin exploring the system, click on 'Start Here', 'Computer' or 'Applications'");
|
||||
|
||||
char file[1024];
|
||||
readlink("/proc/self/exe", file, sizeof(file));
|
||||
*strrchr(file, '/') = '\0';
|
||||
strcat(file, "/../applet-critical.png");
|
||||
|
||||
printf("sending %s\n", file);
|
||||
|
||||
send(file,
|
||||
0,
|
||||
"Alert!",
|
||||
"Warning!");
|
||||
|
||||
|
||||
// FIXME: test raw image transfer
|
||||
struct stat buf;
|
||||
if (stat(file, &buf) == -1)
|
||||
{
|
||||
fprintf(stderr, "could not stat %s: %s", file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int fd = open(file, O_RDONLY);
|
||||
|
||||
void *pngbase = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
|
||||
close(fd);
|
||||
|
||||
send(pngbase,
|
||||
buf.st_size,
|
||||
"Raw image test",
|
||||
"This is an image marshalling test");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* @file tests/test-markup.c Unit test: markup
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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>
|
||||
|
||||
int main() {
|
||||
notify_init("Markup");
|
||||
|
||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
"Summary",
|
||||
|
||||
"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, <a href='google.com'>linked</a> text",
|
||||
|
||||
NULL, // no icon
|
||||
TRUE, time(NULL) + 5,
|
||||
NULL, // no user data
|
||||
0); // no actions
|
||||
|
||||
if (!n) {
|
||||
fprintf(stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* @file tests/test-multi-actions.c Unit test: multiple actions
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define DBUS_API_SUBJECT_TO_CHANGE 1
|
||||
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
GMainLoop *loop;
|
||||
NotifyHandle *n;
|
||||
|
||||
static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
|
||||
{
|
||||
char *s = NULL;
|
||||
|
||||
assert( uid >= 0 && uid <= 2 );
|
||||
|
||||
switch (uid)
|
||||
{
|
||||
case 0: s = "the notification"; break;
|
||||
case 1: s = "Empty Trash"; break;
|
||||
case 2: s = "Help Me"; break;
|
||||
}
|
||||
|
||||
printf("You clicked %s\n", s);
|
||||
|
||||
notify_close(n);
|
||||
|
||||
g_main_loop_quit(loop);
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!notify_init("Multi Action Test")) exit(1);
|
||||
|
||||
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
dbus_connection_setup_with_g_main(conn, NULL);
|
||||
|
||||
n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
"Low disk space", "You can free up some disk space by emptying the trash can.",
|
||||
NULL, // no icon
|
||||
FALSE, 0, // does not expire
|
||||
NULL, // no user data
|
||||
|
||||
3, // 3 actions
|
||||
0, "default", callback,
|
||||
1, "Empty Trash", callback,
|
||||
2, "Help Me", callback );
|
||||
|
||||
if (!n) {
|
||||
fprintf(stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_main_loop_run(loop);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* @file tests/test-default-action.c Unit test: atomic replacements
|
||||
*
|
||||
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx>
|
||||
*
|
||||
* 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>
|
||||
|
||||
int main() {
|
||||
notify_init("Replace Test");
|
||||
|
||||
NotifyHandle *n = notify_send_notification(NULL, // replaces nothing
|
||||
NOTIFY_URGENCY_NORMAL,
|
||||
"Summary", "Content",
|
||||
NULL, // no icon
|
||||
FALSE, 0, // does not expire
|
||||
NULL, // no user data
|
||||
0); // no actions
|
||||
|
||||
if (!n) {
|
||||
fprintf(stderr, "failed to send notification\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
sleep(3);
|
||||
|
||||
notify_send_notification(n, NOTIFY_URGENCY_NORMAL, "Second Summary", "Second Content",
|
||||
NULL, TRUE, time(NULL) + 5, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue