From a1ccd1a94e3b2ec2c7ce60c5b6b8824a2bf04076 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 09:34:10 -0500 Subject: Moving tests to examples --- .bzrignore | 7 +++ Makefile.am | 2 +- configure.ac | 2 +- examples/Makefile.am | 72 +++++++++++++++++++++ examples/im-client.c | 111 ++++++++++++++++++++++++++++++++ examples/indicate-alot.c | 45 +++++++++++++ examples/indicate-and-crash.c | 41 ++++++++++++ examples/listen-and-print.c | 143 ++++++++++++++++++++++++++++++++++++++++++ examples/show-hide-server.c | 44 +++++++++++++ examples/test.js | 6 ++ tests/Makefile.am | 72 --------------------- tests/im-client.c | 111 -------------------------------- tests/indicate-alot.c | 45 ------------- tests/indicate-and-crash.c | 41 ------------ tests/listen-and-print.c | 143 ------------------------------------------ tests/show-hide-server.c | 44 ------------- tests/test.js | 6 -- 17 files changed, 471 insertions(+), 464 deletions(-) create mode 100644 examples/Makefile.am create mode 100644 examples/im-client.c create mode 100644 examples/indicate-alot.c create mode 100644 examples/indicate-and-crash.c create mode 100644 examples/listen-and-print.c create mode 100644 examples/show-hide-server.c create mode 100755 examples/test.js delete mode 100644 tests/Makefile.am delete mode 100644 tests/im-client.c delete mode 100644 tests/indicate-alot.c delete mode 100644 tests/indicate-and-crash.c delete mode 100644 tests/listen-and-print.c delete mode 100644 tests/show-hide-server.c delete mode 100755 tests/test.js diff --git a/.bzrignore b/.bzrignore index 2e5dd36..6d29896 100644 --- a/.bzrignore +++ b/.bzrignore @@ -60,3 +60,10 @@ libindicate/indicate-enum-types.h libindicate/libindicate_la-indicate-enum-types.lo libindicate/s-enum-types-c libindicate/s-enum-types-h +examples/.deps +examples/.libs +examples/im-client +examples/indicate-alot +examples/indicate-and-crash +examples/listen-and-print +examples/show-hide-server diff --git a/Makefile.am b/Makefile.am index d4f7ca2..7230246 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = \ src \ libindicate \ - tests \ + examples \ data \ po \ docs diff --git a/configure.ac b/configure.ac index ca46ff9..bfa784a 100644 --- a/configure.ac +++ b/configure.ac @@ -161,7 +161,7 @@ Makefile src/Makefile libindicate/Makefile libindicate/indicate.pc -tests/Makefile +examples/Makefile data/Makefile po/Makefile.in docs/Makefile diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 0000000..862046e --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,72 @@ + +libexec_PROGRAMS = \ + indicate-and-crash \ + indicate-alot \ + listen-and-print \ + im-client \ + show-hide-server + +indicate_and_crash_SOURCES = \ + indicate-and-crash.c + +indicate_and_crash_CFLAGS = \ + -I $(srcdir)/.. \ + $(LIBINDICATE_CFLAGS) + +indicate_and_crash_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +indicate_alot_SOURCES = \ + indicate-alot.c + +indicate_alot_CFLAGS = \ + -I $(srcdir)/.. \ + $(LIBINDICATE_CFLAGS) + +indicate_alot_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +listen_and_print_SOURCES = \ + listen-and-print.c + +listen_and_print_CFLAGS = \ + -I $(srcdir)/.. \ + $(LIBINDICATE_CFLAGS) + +listen_and_print_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +im_client_SOURCES = \ + im-client.c + +im_client_CFLAGS = \ + -I $(srcdir)/.. \ + $(LIBINDICATE_CFLAGS) + +im_client_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +show_hide_server_SOURCES = \ + show-hide-server.c + +show_hide_server_CFLAGS = \ + -I $(srcdir)/.. \ + $(LIBINDICATE_CFLAGS) + +show_hide_server_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +examplesdir = $(docdir)/examples/ + +examples_DATA = \ + $(indicate_and_crash_SOURCES) \ + $(indicate_alot_SOURCES) \ + $(listen_and_print_SOURCES) \ + $(im_client_SOURCES) + +EXTRA_DIST = $(examples_DATA) diff --git a/examples/im-client.c b/examples/im-client.c new file mode 100644 index 0000000..bf2fbb2 --- /dev/null +++ b/examples/im-client.c @@ -0,0 +1,111 @@ +/* +A test for libindicate to ensure its quality. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include "libindicate/server.h" +#include "libindicate/indicator-message.h" + +gchar * patha = "/usr/share/icons/hicolor/16x16/apps/empathy.png"; +gchar * pathb = "/usr/share/icons/hicolor/22x22/apps/empathy.png"; +gchar * lastpath = NULL; + +static gboolean +timeout_cb (gpointer data) +{ + g_debug("Modifying properties"); + + IndicateIndicator * indicator = INDICATE_INDICATOR(data); + + GTimeVal time; + g_get_current_time(&time); + indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time); + + if (lastpath == patha) { + lastpath = pathb; + } else { + lastpath = patha; + } + + GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(lastpath, NULL); + g_return_val_if_fail(pixbuf != NULL, TRUE); + + indicate_indicator_set_property_icon(INDICATE_INDICATOR(indicator), "icon", pixbuf); + g_object_unref(G_OBJECT(pixbuf)); + + return TRUE; +} + +static void +display (IndicateIndicator * indicator, gpointer data) +{ + g_debug("Ah, my indicator has been displayed"); +} + +static void +server_display (IndicateServer * server, gpointer data) +{ + g_debug("Ah, my server has been displayed"); +} + +static void +interest_added (IndicateServer * server, IndicateInterests interest) +{ + g_debug("Oh, someone is interested in my for: %d", interest); +} + +void +interest_removed (IndicateServer * server, IndicateInterests interest) +{ + g_debug("Someone is no longer interested in my for: %d", interest); +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicateServer * server = indicate_server_ref_default(); + indicate_server_set_type(server, "message.im"); + indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop"); + g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_SERVER_DISPLAY, G_CALLBACK(server_display), NULL); + g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL); + g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_REMOVED, G_CALLBACK(interest_removed), NULL); + + IndicateIndicatorMessage * indicator; + + indicator = indicate_indicator_message_new(); + indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "subtype", "im"); + indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "sender", "IM Client Test"); + GTimeVal time; g_get_current_time(&time); + indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time); + indicate_indicator_show(INDICATE_INDICATOR(indicator)); + + g_get_current_time(&time); + indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time); + + g_signal_connect(G_OBJECT(indicator), INDICATE_INDICATOR_SIGNAL_DISPLAY, G_CALLBACK(display), NULL); + + g_timeout_add_seconds(180, timeout_cb, indicator); + + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + + return 0; +} diff --git a/examples/indicate-alot.c b/examples/indicate-alot.c new file mode 100644 index 0000000..479040b --- /dev/null +++ b/examples/indicate-alot.c @@ -0,0 +1,45 @@ +/* +A test for libindicate to ensure its quality. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + + +#include +#include "libindicate/indicator.h" + +#define ALOT 30 + + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicateIndicator * indicators[ALOT]; + int i; + + for (i = 0; i < ALOT; i++) { + indicators[i] = indicate_indicator_new(); + indicate_indicator_show(indicators[i]); + } + + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + + return 0; +} diff --git a/examples/indicate-and-crash.c b/examples/indicate-and-crash.c new file mode 100644 index 0000000..c002a54 --- /dev/null +++ b/examples/indicate-and-crash.c @@ -0,0 +1,41 @@ +/* +A test for libindicate to ensure its quality. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + + +#include +#include "libindicate/indicator.h" + +gboolean crashfunc (gpointer data) { *(int *)data = 5; return FALSE;} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicateIndicator * indicator = indicate_indicator_new(); + indicate_indicator_show(indicator); + + g_timeout_add_seconds(15, crashfunc, NULL); + + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + + return 0; +} diff --git a/examples/listen-and-print.c b/examples/listen-and-print.c new file mode 100644 index 0000000..dcad92b --- /dev/null +++ b/examples/listen-and-print.c @@ -0,0 +1,143 @@ +/* +A test for libindicate to ensure its quality. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include "libindicate/listener.h" + +static void +show_property_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) +{ + g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, propertydata); + return; +} + +static void +show_property_time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data) +{ + time_t timet; + struct tm * structtm; + + timet = propertydata->tv_sec; + structtm = localtime(&timet); + + gchar timestring[80]; + strftime(timestring, 80, "%I:%M", structtm); + + g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, timestring); + return; +} + +static void +show_property_icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GdkPixbuf * propertydata, gpointer data) +{ + g_debug("Indicator Property: %s %d %s %dx%d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, gdk_pixbuf_get_width(propertydata), gdk_pixbuf_get_height(propertydata)); + g_object_unref(G_OBJECT(propertydata)); + return; +} + +static void +show_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property) +{ + if (!strcmp(property, "icon")) { + indicate_listener_get_property_icon(listener, server, indicator, property, show_property_icon_cb, NULL); + } else if (!strcmp(property, "time")) { + indicate_listener_get_property_time(listener, server, indicator, property, show_property_time_cb, NULL); + } else { + indicate_listener_get_property(listener, server, indicator, property, show_property_cb, NULL); + } + + return; +} + +static void +get_properties (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator) +{ + //TODO: Not in API yet. +} + +static void +indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + g_debug("Indicator Added: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type); + get_properties(listener, server, indicator); +} + +static void +indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + g_debug("Indicator Removed: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type); +} + +static void +indicator_modified (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, gpointer data) +{ + g_debug("Indicator Modified: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type, property); + show_property(listener, server, indicator, property); +} + +static void +type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) +{ + g_debug("Indicator Server Type: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value); +} + +static void +desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) +{ + g_debug("Indicator Server Desktop: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value); +} + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + indicate_listener_server_get_type(listener, server, type_cb, NULL); + indicate_listener_server_get_desktop(listener, server, desktop_cb, NULL); + + indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_DISPLAY); + indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_DISPLAY); + + return; +} + +static void +server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Removed: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), NULL); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), NULL); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED, G_CALLBACK(indicator_modified), NULL); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), NULL); + + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + + return 0; +} diff --git a/examples/show-hide-server.c b/examples/show-hide-server.c new file mode 100644 index 0000000..23c1ea1 --- /dev/null +++ b/examples/show-hide-server.c @@ -0,0 +1,44 @@ +/* From LP: #351537 */ + +#include +#include "libindicate/server.h" +#include "libindicate/indicator-message.h" + +gboolean hidden = TRUE; + +static gboolean +timeout_cb (gpointer data) +{ + IndicateServer * server = INDICATE_SERVER(data); + + if (hidden) { + printf("showing... "); + indicate_server_show(server); + printf("ok\n"); + hidden = FALSE; + } else { + printf("hiding... "); + indicate_server_hide(server); + printf("ok\n"); + hidden = TRUE; + } + + return TRUE; +} + + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicateServer * server = indicate_server_ref_default(); + indicate_server_set_type(server, "message.im"); + indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop"); + g_timeout_add_seconds(1, timeout_cb, server); + + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + + return 0; +} + diff --git a/examples/test.js b/examples/test.js new file mode 100755 index 0000000..45b0d05 --- /dev/null +++ b/examples/test.js @@ -0,0 +1,6 @@ +#!/usr/local/bin/seed +Seed.import_namespace("Indicate"); + +var indicator = new Indicate.Indicator(); + +indicator.show(); diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index 862046e..0000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,72 +0,0 @@ - -libexec_PROGRAMS = \ - indicate-and-crash \ - indicate-alot \ - listen-and-print \ - im-client \ - show-hide-server - -indicate_and_crash_SOURCES = \ - indicate-and-crash.c - -indicate_and_crash_CFLAGS = \ - -I $(srcdir)/.. \ - $(LIBINDICATE_CFLAGS) - -indicate_and_crash_LDADD = \ - ../libindicate/libindicate.la \ - $(LIBINDICATE_LIBS) - -indicate_alot_SOURCES = \ - indicate-alot.c - -indicate_alot_CFLAGS = \ - -I $(srcdir)/.. \ - $(LIBINDICATE_CFLAGS) - -indicate_alot_LDADD = \ - ../libindicate/libindicate.la \ - $(LIBINDICATE_LIBS) - -listen_and_print_SOURCES = \ - listen-and-print.c - -listen_and_print_CFLAGS = \ - -I $(srcdir)/.. \ - $(LIBINDICATE_CFLAGS) - -listen_and_print_LDADD = \ - ../libindicate/libindicate.la \ - $(LIBINDICATE_LIBS) - -im_client_SOURCES = \ - im-client.c - -im_client_CFLAGS = \ - -I $(srcdir)/.. \ - $(LIBINDICATE_CFLAGS) - -im_client_LDADD = \ - ../libindicate/libindicate.la \ - $(LIBINDICATE_LIBS) - -show_hide_server_SOURCES = \ - show-hide-server.c - -show_hide_server_CFLAGS = \ - -I $(srcdir)/.. \ - $(LIBINDICATE_CFLAGS) - -show_hide_server_LDADD = \ - ../libindicate/libindicate.la \ - $(LIBINDICATE_LIBS) - -examplesdir = $(docdir)/examples/ - -examples_DATA = \ - $(indicate_and_crash_SOURCES) \ - $(indicate_alot_SOURCES) \ - $(listen_and_print_SOURCES) \ - $(im_client_SOURCES) - -EXTRA_DIST = $(examples_DATA) diff --git a/tests/im-client.c b/tests/im-client.c deleted file mode 100644 index bf2fbb2..0000000 --- a/tests/im-client.c +++ /dev/null @@ -1,111 +0,0 @@ -/* -A test for libindicate to ensure its quality. - -Copyright 2009 Canonical Ltd. - -Authors: - Ted Gould - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - -#include -#include "libindicate/server.h" -#include "libindicate/indicator-message.h" - -gchar * patha = "/usr/share/icons/hicolor/16x16/apps/empathy.png"; -gchar * pathb = "/usr/share/icons/hicolor/22x22/apps/empathy.png"; -gchar * lastpath = NULL; - -static gboolean -timeout_cb (gpointer data) -{ - g_debug("Modifying properties"); - - IndicateIndicator * indicator = INDICATE_INDICATOR(data); - - GTimeVal time; - g_get_current_time(&time); - indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time); - - if (lastpath == patha) { - lastpath = pathb; - } else { - lastpath = patha; - } - - GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(lastpath, NULL); - g_return_val_if_fail(pixbuf != NULL, TRUE); - - indicate_indicator_set_property_icon(INDICATE_INDICATOR(indicator), "icon", pixbuf); - g_object_unref(G_OBJECT(pixbuf)); - - return TRUE; -} - -static void -display (IndicateIndicator * indicator, gpointer data) -{ - g_debug("Ah, my indicator has been displayed"); -} - -static void -server_display (IndicateServer * server, gpointer data) -{ - g_debug("Ah, my server has been displayed"); -} - -static void -interest_added (IndicateServer * server, IndicateInterests interest) -{ - g_debug("Oh, someone is interested in my for: %d", interest); -} - -void -interest_removed (IndicateServer * server, IndicateInterests interest) -{ - g_debug("Someone is no longer interested in my for: %d", interest); -} - -int -main (int argc, char ** argv) -{ - g_type_init(); - - IndicateServer * server = indicate_server_ref_default(); - indicate_server_set_type(server, "message.im"); - indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop"); - g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_SERVER_DISPLAY, G_CALLBACK(server_display), NULL); - g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL); - g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_REMOVED, G_CALLBACK(interest_removed), NULL); - - IndicateIndicatorMessage * indicator; - - indicator = indicate_indicator_message_new(); - indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "subtype", "im"); - indicate_indicator_set_property(INDICATE_INDICATOR(indicator), "sender", "IM Client Test"); - GTimeVal time; g_get_current_time(&time); - indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time); - indicate_indicator_show(INDICATE_INDICATOR(indicator)); - - g_get_current_time(&time); - indicate_indicator_set_property_time(INDICATE_INDICATOR(indicator), "time", &time); - - g_signal_connect(G_OBJECT(indicator), INDICATE_INDICATOR_SIGNAL_DISPLAY, G_CALLBACK(display), NULL); - - g_timeout_add_seconds(180, timeout_cb, indicator); - - g_main_loop_run(g_main_loop_new(NULL, FALSE)); - - return 0; -} diff --git a/tests/indicate-alot.c b/tests/indicate-alot.c deleted file mode 100644 index 479040b..0000000 --- a/tests/indicate-alot.c +++ /dev/null @@ -1,45 +0,0 @@ -/* -A test for libindicate to ensure its quality. - -Copyright 2009 Canonical Ltd. - -Authors: - Ted Gould - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - - -#include -#include "libindicate/indicator.h" - -#define ALOT 30 - - -int -main (int argc, char ** argv) -{ - g_type_init(); - - IndicateIndicator * indicators[ALOT]; - int i; - - for (i = 0; i < ALOT; i++) { - indicators[i] = indicate_indicator_new(); - indicate_indicator_show(indicators[i]); - } - - g_main_loop_run(g_main_loop_new(NULL, FALSE)); - - return 0; -} diff --git a/tests/indicate-and-crash.c b/tests/indicate-and-crash.c deleted file mode 100644 index c002a54..0000000 --- a/tests/indicate-and-crash.c +++ /dev/null @@ -1,41 +0,0 @@ -/* -A test for libindicate to ensure its quality. - -Copyright 2009 Canonical Ltd. - -Authors: - Ted Gould - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - - -#include -#include "libindicate/indicator.h" - -gboolean crashfunc (gpointer data) { *(int *)data = 5; return FALSE;} - -int -main (int argc, char ** argv) -{ - g_type_init(); - - IndicateIndicator * indicator = indicate_indicator_new(); - indicate_indicator_show(indicator); - - g_timeout_add_seconds(15, crashfunc, NULL); - - g_main_loop_run(g_main_loop_new(NULL, FALSE)); - - return 0; -} diff --git a/tests/listen-and-print.c b/tests/listen-and-print.c deleted file mode 100644 index dcad92b..0000000 --- a/tests/listen-and-print.c +++ /dev/null @@ -1,143 +0,0 @@ -/* -A test for libindicate to ensure its quality. - -Copyright 2009 Canonical Ltd. - -Authors: - Ted Gould - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - -#include -#include "libindicate/listener.h" - -static void -show_property_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) -{ - g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, propertydata); - return; -} - -static void -show_property_time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data) -{ - time_t timet; - struct tm * structtm; - - timet = propertydata->tv_sec; - structtm = localtime(&timet); - - gchar timestring[80]; - strftime(timestring, 80, "%I:%M", structtm); - - g_debug("Indicator Property: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, timestring); - return; -} - -static void -show_property_icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GdkPixbuf * propertydata, gpointer data) -{ - g_debug("Indicator Property: %s %d %s %dx%d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), property, gdk_pixbuf_get_width(propertydata), gdk_pixbuf_get_height(propertydata)); - g_object_unref(G_OBJECT(propertydata)); - return; -} - -static void -show_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property) -{ - if (!strcmp(property, "icon")) { - indicate_listener_get_property_icon(listener, server, indicator, property, show_property_icon_cb, NULL); - } else if (!strcmp(property, "time")) { - indicate_listener_get_property_time(listener, server, indicator, property, show_property_time_cb, NULL); - } else { - indicate_listener_get_property(listener, server, indicator, property, show_property_cb, NULL); - } - - return; -} - -static void -get_properties (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator) -{ - //TODO: Not in API yet. -} - -static void -indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) -{ - g_debug("Indicator Added: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type); - get_properties(listener, server, indicator); -} - -static void -indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) -{ - g_debug("Indicator Removed: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type); -} - -static void -indicator_modified (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, gpointer data) -{ - g_debug("Indicator Modified: %s %d %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type, property); - show_property(listener, server, indicator, property); -} - -static void -type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) -{ - g_debug("Indicator Server Type: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value); -} - -static void -desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) -{ - g_debug("Indicator Server Desktop: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), value); -} - -static void -server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) -{ - g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); - indicate_listener_server_get_type(listener, server, type_cb, NULL); - indicate_listener_server_get_desktop(listener, server, desktop_cb, NULL); - - indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_DISPLAY); - indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_DISPLAY); - - return; -} - -static void -server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) -{ - g_debug("Indicator Server Removed: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); -} - -int -main (int argc, char ** argv) -{ - g_type_init(); - - IndicateListener * listener = indicate_listener_ref_default(); - - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), NULL); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), NULL); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED, G_CALLBACK(indicator_modified), NULL); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), NULL); - - g_main_loop_run(g_main_loop_new(NULL, FALSE)); - - return 0; -} diff --git a/tests/show-hide-server.c b/tests/show-hide-server.c deleted file mode 100644 index 23c1ea1..0000000 --- a/tests/show-hide-server.c +++ /dev/null @@ -1,44 +0,0 @@ -/* From LP: #351537 */ - -#include -#include "libindicate/server.h" -#include "libindicate/indicator-message.h" - -gboolean hidden = TRUE; - -static gboolean -timeout_cb (gpointer data) -{ - IndicateServer * server = INDICATE_SERVER(data); - - if (hidden) { - printf("showing... "); - indicate_server_show(server); - printf("ok\n"); - hidden = FALSE; - } else { - printf("hiding... "); - indicate_server_hide(server); - printf("ok\n"); - hidden = TRUE; - } - - return TRUE; -} - - -int -main (int argc, char ** argv) -{ - g_type_init(); - - IndicateServer * server = indicate_server_ref_default(); - indicate_server_set_type(server, "message.im"); - indicate_server_set_desktop_file(server, "/usr/share/applications/empathy.desktop"); - g_timeout_add_seconds(1, timeout_cb, server); - - g_main_loop_run(g_main_loop_new(NULL, FALSE)); - - return 0; -} - diff --git a/tests/test.js b/tests/test.js deleted file mode 100755 index 45b0d05..0000000 --- a/tests/test.js +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/local/bin/seed -Seed.import_namespace("Indicate"); - -var indicator = new Indicate.Indicator(); - -indicator.show(); -- cgit v1.2.3 From ecfb1c26cdb0908e552a33ccad288f3224038f97 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 10:57:57 -0500 Subject: Build infrastructure for first test --- Makefile.am | 1 + configure.ac | 1 + tests/Makefile.am | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/Makefile.am diff --git a/Makefile.am b/Makefile.am index 7230246..2f11251 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = \ src \ libindicate \ examples \ + tests \ data \ po \ docs diff --git a/configure.ac b/configure.ac index bfa784a..496ae6a 100644 --- a/configure.ac +++ b/configure.ac @@ -162,6 +162,7 @@ src/Makefile libindicate/Makefile libindicate/indicate.pc examples/Makefile +tests/Makefile data/Makefile po/Makefile.in docs/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..8f290f9 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,29 @@ + +DBUS_RUNNER=/home/ted/Development/dbus-fun/dbus-test-runner --dbus-config /home/ted/Development/dbus-fun/session.conf + +TESTS = \ + test_simple + +test_simple: test_simple_c test_simple_s + $(DBUS_RUNNER) --task ./test_simple_c --task-name Client --task ./test_simple_s --task-name Server + +test_simple_c_SOURCES = \ + test-simple-c.c + +test_simple_c_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_simple_c_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_simple_s_SOURCES = \ + test-simple-s.c + +test_simple_s_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_simple_s_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + -- cgit v1.2.3 From 8162f7196b7be52d014160b7559a98264e5f2b8a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 11:25:33 -0500 Subject: Adding in a simple test --- .bzrignore | 2 ++ tests/Makefile.am | 25 +++++++++++++------------ tests/test-simple-client.c | 30 ++++++++++++++++++++++++++++++ tests/test-simple-server.c | 39 +++++++++++++++++++++++++++++++++++++++ tests/test_simple | 5 +++++ 5 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 tests/test-simple-client.c create mode 100644 tests/test-simple-server.c create mode 100755 tests/test_simple diff --git a/.bzrignore b/.bzrignore index 6d29896..f9d8412 100644 --- a/.bzrignore +++ b/.bzrignore @@ -67,3 +67,5 @@ examples/indicate-alot examples/indicate-and-crash examples/listen-and-print examples/show-hide-server +test-simple-client +test-simple-server diff --git a/tests/Makefile.am b/tests/Makefile.am index 8f290f9..9f1c6d3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,29 +1,30 @@ -DBUS_RUNNER=/home/ted/Development/dbus-fun/dbus-test-runner --dbus-config /home/ted/Development/dbus-fun/session.conf - TESTS = \ test_simple -test_simple: test_simple_c test_simple_s - $(DBUS_RUNNER) --task ./test_simple_c --task-name Client --task ./test_simple_s --task-name Server +libexec_PROGRAMS = \ + test-simple-client \ + test-simple-server + +test_simple: test-simple-client test-simple-server -test_simple_c_SOURCES = \ - test-simple-c.c +test_simple_client_SOURCES = \ + test-simple-client.c -test_simple_c_CFLAGS = \ +test_simple_client_CFLAGS = \ $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. -test_simple_c_LDADD = \ +test_simple_client_LDADD = \ ../libindicate/libindicate.la \ $(LIBINDICATE_LIBS) -test_simple_s_SOURCES = \ - test-simple-s.c +test_simple_server_SOURCES = \ + test-simple-server.c -test_simple_s_CFLAGS = \ +test_simple_server_CFLAGS = \ $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. -test_simple_s_LDADD = \ +test_simple_server_LDADD = \ ../libindicate/libindicate.la \ $(LIBINDICATE_LIBS) diff --git a/tests/test-simple-client.c b/tests/test-simple-client.c new file mode 100644 index 0000000..f8db55a --- /dev/null +++ b/tests/test-simple-client.c @@ -0,0 +1,30 @@ + +#include +#include "libindicate/indicator.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static gboolean +done_timeout_cb (gpointer data) +{ + g_debug("All done."); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateIndicator * indicator = indicate_indicator_new(); + indicate_indicator_show(indicator); + + g_timeout_add_seconds(2, done_timeout_cb, indicator); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-simple-server.c b/tests/test-simple-server.c new file mode 100644 index 0000000..0a04e85 --- /dev/null +++ b/tests/test-simple-server.c @@ -0,0 +1,39 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + g_main_loop_quit(mainloop); +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Failed to get a server in 5 seconds."); + passed = FALSE; + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(5, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test_simple b/tests/test_simple new file mode 100755 index 0000000..8c4263e --- /dev/null +++ b/tests/test_simple @@ -0,0 +1,5 @@ +#!/bin/sh + +DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" + +${DBUS_RUNNER} --task ./test-simple-client --task-name Client --task ./test-simple-server --task-name Server -- cgit v1.2.3 From 443c83ab353b818227270aa63f655fb2cbdbeba7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 12:16:33 -0500 Subject: Woot, now we do distcheck too --- tests/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 9f1c6d3..36818b8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,9 @@ libexec_PROGRAMS = \ test-simple-client \ test-simple-server +EXTRA_DIST = \ + $(TESTS) + test_simple: test-simple-client test-simple-server test_simple_client_SOURCES = \ -- cgit v1.2.3 From 38c6ce2a36d6416016f64e5963deee29bc02f8b3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 12:36:07 -0500 Subject: Adding an interests test --- .bzrignore | 2 ++ tests/Makefile.am | 27 ++++++++++++++++++- tests/test-interests-client.c | 63 +++++++++++++++++++++++++++++++++++++++++++ tests/test-interests-server.c | 45 +++++++++++++++++++++++++++++++ tests/test_interests | 5 ++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 tests/test-interests-client.c create mode 100644 tests/test-interests-server.c create mode 100755 tests/test_interests diff --git a/.bzrignore b/.bzrignore index f9d8412..b7d186d 100644 --- a/.bzrignore +++ b/.bzrignore @@ -69,3 +69,5 @@ examples/listen-and-print examples/show-hide-server test-simple-client test-simple-server +test-interests-client +test-interests-server diff --git a/tests/Makefile.am b/tests/Makefile.am index 36818b8..256a699 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,8 +1,11 @@ TESTS = \ - test_simple + test_simple \ + test_interests libexec_PROGRAMS = \ + test-interests-client \ + test-interests-server \ test-simple-client \ test-simple-server @@ -31,3 +34,25 @@ test_simple_server_LDADD = \ ../libindicate/libindicate.la \ $(LIBINDICATE_LIBS) +test_interests: test-interests-client test-interests-server + +test_interests_client_SOURCES = \ + test-interests-client.c + +test_interests_client_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_client_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_interests_server_SOURCES = \ + test-interests-server.c + +test_interests_server_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_server_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + diff --git a/tests/test-interests-client.c b/tests/test-interests-client.c new file mode 100644 index 0000000..0fe8587 --- /dev/null +++ b/tests/test-interests-client.c @@ -0,0 +1,63 @@ + +#include +#include "libindicate/indicator.h" +#include "libindicate/server.h" +#include "libindicate/interests.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; +static gboolean interests[INDICATE_INTEREST_LAST] = {0}; + +static gboolean +check_interests (void) +{ + guint i; + for (i = INDICATE_INTEREST_NONE; i < INDICATE_INTEREST_LAST; i++) { + if (!interests[i]) { + return FALSE; + } + } + + return TRUE; +} + +static void +interest_added (IndicateServer * server, IndicateInterests interest) +{ + g_debug("Oh, someone is interested in my for: %d", interest); + interests[interest] = TRUE; + + if (check_interests()) { + g_main_loop_quit(mainloop); + } + + return; +} + +static gboolean +done_timeout_cb (gpointer data) +{ + g_debug("All interests not set"); + passed = FALSE; + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateIndicator * indicator = indicate_indicator_new(); + indicate_indicator_show(indicator); + + IndicateServer * server = indicate_server_ref_default(); + g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL); + + g_timeout_add_seconds(10, done_timeout_cb, indicator); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-interests-server.c b/tests/test-interests-server.c new file mode 100644 index 0000000..82cab3c --- /dev/null +++ b/tests/test-interests-server.c @@ -0,0 +1,45 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + + guint i; + for (i = INDICATE_INTEREST_NONE; i < INDICATE_INTEREST_LAST; i++) { + g_debug("Indicating Interests: %d", i); + indicate_listener_server_show_interest(listener, server, i); + } + + return; +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Done indicatating interest"); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(2, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test_interests b/tests/test_interests new file mode 100755 index 0000000..b37189f --- /dev/null +++ b/tests/test_interests @@ -0,0 +1,5 @@ +#!/bin/sh + +DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" + +${DBUS_RUNNER} --task ./test-interests-client --task-name Client --task ./test-interests-server --task-name Server -- cgit v1.2.3 From 76d5d0d2ad09b22fd49ca49761a12554a1d6383c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 13:13:04 -0500 Subject: Gaurding against setting bad interests --- libindicate/listener.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libindicate/listener.c b/libindicate/listener.c index fddeb71..bd3639d 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -1003,6 +1003,10 @@ interest_cb (DBusGProxy *proxy, GError *error, gpointer userdata) void indicate_listener_server_show_interest (IndicateListener * listener, IndicateListenerServer * server, IndicateInterests interest) { + if (!(interest > INDICATE_INTEREST_NONE && interest < INDICATE_INTEREST_LAST)) { + return; + } + if (!server->interests[interest]) { org_freedesktop_indicator_show_interest_async (server->proxy, interest_to_string(interest), interest_cb, server); server->interests[interest] = TRUE; -- cgit v1.2.3 From c5cc32d7fa7c6abe909f3d19a7e1deb529bcc4a9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 13:16:14 -0500 Subject: Expanding range of interest test and not checking to see if we got none, we shouldn't get it. --- tests/test-interests-client.c | 4 ++-- tests/test-interests-server.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-interests-client.c b/tests/test-interests-client.c index 0fe8587..bde3b26 100644 --- a/tests/test-interests-client.c +++ b/tests/test-interests-client.c @@ -12,7 +12,7 @@ static gboolean check_interests (void) { guint i; - for (i = INDICATE_INTEREST_NONE; i < INDICATE_INTEREST_LAST; i++) { + for (i = INDICATE_INTEREST_NONE + 1; i < INDICATE_INTEREST_LAST; i++) { if (!interests[i]) { return FALSE; } @@ -54,7 +54,7 @@ main (int argc, char * argv) IndicateServer * server = indicate_server_ref_default(); g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL); - g_timeout_add_seconds(10, done_timeout_cb, indicator); + g_timeout_add_seconds(2, done_timeout_cb, indicator); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/tests/test-interests-server.c b/tests/test-interests-server.c index 82cab3c..e1433d8 100644 --- a/tests/test-interests-server.c +++ b/tests/test-interests-server.c @@ -10,8 +10,8 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha { g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); - guint i; - for (i = INDICATE_INTEREST_NONE; i < INDICATE_INTEREST_LAST; i++) { + gint i; + for (i = INDICATE_INTEREST_NONE - 2; i < INDICATE_INTEREST_LAST + 2; i++) { g_debug("Indicating Interests: %d", i); indicate_listener_server_show_interest(listener, server, i); } -- cgit v1.2.3 From ecad1e36dce18875461e76d2a47d8a0e11570ff6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 14:44:25 -0500 Subject: Adding in multiple servers connecting in to declare interest test --- .bzrignore | 5 ++++ tests/Makefile.am | 60 +++++++++++++++++++++++++++++++++++++++++- tests/test-interests-server1.c | 41 +++++++++++++++++++++++++++++ tests/test-interests-server2.c | 41 +++++++++++++++++++++++++++++ tests/test-interests-server3.c | 41 +++++++++++++++++++++++++++++ tests/test-interests-server4.c | 41 +++++++++++++++++++++++++++++ tests/test-interests-server5.c | 41 +++++++++++++++++++++++++++++ tests/test_interests_multi | 5 ++++ 8 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 tests/test-interests-server1.c create mode 100644 tests/test-interests-server2.c create mode 100644 tests/test-interests-server3.c create mode 100644 tests/test-interests-server4.c create mode 100644 tests/test-interests-server5.c create mode 100755 tests/test_interests_multi diff --git a/.bzrignore b/.bzrignore index b7d186d..13cd507 100644 --- a/.bzrignore +++ b/.bzrignore @@ -71,3 +71,8 @@ test-simple-client test-simple-server test-interests-client test-interests-server +test-interests-server1 +test-interests-server2 +test-interests-server3 +test-interests-server4 +test-interests-server5 diff --git a/tests/Makefile.am b/tests/Makefile.am index 256a699..6117bee 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,11 +1,17 @@ TESTS = \ test_simple \ - test_interests + test_interests \ + test_interests_multi libexec_PROGRAMS = \ test-interests-client \ test-interests-server \ + test-interests-server1 \ + test-interests-server2 \ + test-interests-server3 \ + test-interests-server4 \ + test-interests-server5 \ test-simple-client \ test-simple-server @@ -56,3 +62,55 @@ test_interests_server_LDADD = \ ../libindicate/libindicate.la \ $(LIBINDICATE_LIBS) +test_interests_multi: test-interests-client test-interests-server1 test-interests-server2 test-interests-server3 test-interests-server4 test-interests-server5 + +test_interests_server1_SOURCES = \ + test-interests-server1.c + +test_interests_server1_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_server1_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_interests_server2_SOURCES = \ + test-interests-server2.c + +test_interests_server2_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_server2_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_interests_server3_SOURCES = \ + test-interests-server3.c + +test_interests_server3_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_server3_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_interests_server4_SOURCES = \ + test-interests-server4.c + +test_interests_server4_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_server4_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_interests_server5_SOURCES = \ + test-interests-server5.c + +test_interests_server5_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_server5_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + diff --git a/tests/test-interests-server1.c b/tests/test-interests-server1.c new file mode 100644 index 0000000..e0d77f3 --- /dev/null +++ b/tests/test-interests-server1.c @@ -0,0 +1,41 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + #define INTEREST 1 + g_debug("Setting Interest: %d", INTEREST); + indicate_listener_server_show_interest(listener, server, INTEREST); + return; +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Done indicatating interest"); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(2, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-interests-server2.c b/tests/test-interests-server2.c new file mode 100644 index 0000000..0416c21 --- /dev/null +++ b/tests/test-interests-server2.c @@ -0,0 +1,41 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + #define INTEREST 2 + g_debug("Setting Interest: %d", INTEREST); + indicate_listener_server_show_interest(listener, server, INTEREST); + return; +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Done indicatating interest"); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(2, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-interests-server3.c b/tests/test-interests-server3.c new file mode 100644 index 0000000..7d889b1 --- /dev/null +++ b/tests/test-interests-server3.c @@ -0,0 +1,41 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + #define INTEREST 3 + g_debug("Setting Interest: %d", INTEREST); + indicate_listener_server_show_interest(listener, server, INTEREST); + return; +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Done indicatating interest"); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(2, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-interests-server4.c b/tests/test-interests-server4.c new file mode 100644 index 0000000..50e6db1 --- /dev/null +++ b/tests/test-interests-server4.c @@ -0,0 +1,41 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + #define INTEREST 4 + g_debug("Setting Interest: %d", INTEREST); + indicate_listener_server_show_interest(listener, server, INTEREST); + return; +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Done indicatating interest"); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(2, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-interests-server5.c b/tests/test-interests-server5.c new file mode 100644 index 0000000..d415716 --- /dev/null +++ b/tests/test-interests-server5.c @@ -0,0 +1,41 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + #define INTEREST 5 + g_debug("Setting Interest: %d", INTEREST); + indicate_listener_server_show_interest(listener, server, INTEREST); + return; +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Done indicatating interest"); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(2, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test_interests_multi b/tests/test_interests_multi new file mode 100755 index 0000000..96b23c9 --- /dev/null +++ b/tests/test_interests_multi @@ -0,0 +1,5 @@ +#!/bin/sh + +DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" + +${DBUS_RUNNER} --task ./test-interests-client --task-name Client --task ./test-interests-server1 --task-name Server1 --task ./test-interests-server2 --task-name Server2 --task ./test-interests-server3 --task-name Server3 --task ./test-interests-server4 --task-name Server4 --task ./test-interests-server5 --task-name Server5 -- cgit v1.2.3 From 6f87e9c09f9894db7fd6f42f65c8eb147c42a6e8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Apr 2009 15:39:42 -0500 Subject: Adding a test to build a bunch of indicators --- .bzrignore | 2 ++ tests/Makefile.am | 27 ++++++++++++++++++++- tests/test-thousand-indicators-client.c | 34 ++++++++++++++++++++++++++ tests/test-thousand-indicators-server.c | 43 +++++++++++++++++++++++++++++++++ tests/test_thousand_indicators | 5 ++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/test-thousand-indicators-client.c create mode 100644 tests/test-thousand-indicators-server.c create mode 100755 tests/test_thousand_indicators diff --git a/.bzrignore b/.bzrignore index 13cd507..a3a1e57 100644 --- a/.bzrignore +++ b/.bzrignore @@ -76,3 +76,5 @@ test-interests-server2 test-interests-server3 test-interests-server4 test-interests-server5 +test-thousand-indicators-server +test-thousand-indicators-client diff --git a/tests/Makefile.am b/tests/Makefile.am index 6117bee..7d72047 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,8 @@ TESTS = \ test_simple \ test_interests \ - test_interests_multi + test_interests_multi \ + test_thousand_indicators libexec_PROGRAMS = \ test-interests-client \ @@ -12,6 +13,8 @@ libexec_PROGRAMS = \ test-interests-server3 \ test-interests-server4 \ test-interests-server5 \ + test-thousand-indicators-client \ + test-thousand-indicators-server test-simple-client \ test-simple-server @@ -114,3 +117,25 @@ test_interests_server5_LDADD = \ ../libindicate/libindicate.la \ $(LIBINDICATE_LIBS) +test_thousand_indicators: test-thousand-indicators-client test-thousand-indicators-server + +test_thousand_indicators_client_SOURCES = \ + test-thousand-indicators-client.c + +test_thousand_indicators_client_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_thousand_indicators_client_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_thousand_indicators_server_SOURCES = \ + test-thousand-indicators-server.c + +test_thousand_indicators_server_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_thousand_indicators_server_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + diff --git a/tests/test-thousand-indicators-client.c b/tests/test-thousand-indicators-client.c new file mode 100644 index 0000000..0ac7305 --- /dev/null +++ b/tests/test-thousand-indicators-client.c @@ -0,0 +1,34 @@ + +#include +#include "libindicate/indicator.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static gboolean +done_timeout_cb (gpointer data) +{ + g_debug("All done."); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + int i; + for (i = 0; i < 1000; i++) { + /* Memory leak :) */ + IndicateIndicator * indicator = indicate_indicator_new(); + indicate_indicator_show(indicator); + } + + g_timeout_add_seconds(2, done_timeout_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-thousand-indicators-server.c b/tests/test-thousand-indicators-server.c new file mode 100644 index 0000000..285e56b --- /dev/null +++ b/tests/test-thousand-indicators-server.c @@ -0,0 +1,43 @@ + +#include +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; +static guint indicator_count = 0; + +static void +indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + g_debug("Indicator Added: %s %d %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator), type); + indicator_count++; + if (indicator_count == 1000) { + g_main_loop_quit(mainloop); + } +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Failed to get a server in 5 seconds."); + passed = FALSE; + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), NULL); + + g_timeout_add_seconds(5, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test_thousand_indicators b/tests/test_thousand_indicators new file mode 100755 index 0000000..4dd7fae --- /dev/null +++ b/tests/test_thousand_indicators @@ -0,0 +1,5 @@ +#!/bin/sh + +DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" + +${DBUS_RUNNER} --task ./test-thousand-indicators-client --task-name Client --task ./test-thousand-indicators-server --task-name Server -- cgit v1.2.3 From 5899a3f246b8eeac2c820013a27cde0301ad69ee Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Apr 2009 10:39:20 -0500 Subject: Switching to system dbus-test-runner --- tests/test_interests | 2 +- tests/test_interests_multi | 2 +- tests/test_simple | 2 +- tests/test_thousand_indicators | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_interests b/tests/test_interests index b37189f..750a789 100755 --- a/tests/test_interests +++ b/tests/test_interests @@ -1,5 +1,5 @@ #!/bin/sh -DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" +DBUS_RUNNER="dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf" ${DBUS_RUNNER} --task ./test-interests-client --task-name Client --task ./test-interests-server --task-name Server diff --git a/tests/test_interests_multi b/tests/test_interests_multi index 96b23c9..4dbdee8 100755 --- a/tests/test_interests_multi +++ b/tests/test_interests_multi @@ -1,5 +1,5 @@ #!/bin/sh -DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" +DBUS_RUNNER="dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf" ${DBUS_RUNNER} --task ./test-interests-client --task-name Client --task ./test-interests-server1 --task-name Server1 --task ./test-interests-server2 --task-name Server2 --task ./test-interests-server3 --task-name Server3 --task ./test-interests-server4 --task-name Server4 --task ./test-interests-server5 --task-name Server5 diff --git a/tests/test_simple b/tests/test_simple index 8c4263e..1b0dc4c 100755 --- a/tests/test_simple +++ b/tests/test_simple @@ -1,5 +1,5 @@ #!/bin/sh -DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" +DBUS_RUNNER="dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf" ${DBUS_RUNNER} --task ./test-simple-client --task-name Client --task ./test-simple-server --task-name Server diff --git a/tests/test_thousand_indicators b/tests/test_thousand_indicators index 4dd7fae..fb1079d 100755 --- a/tests/test_thousand_indicators +++ b/tests/test_thousand_indicators @@ -1,5 +1,5 @@ #!/bin/sh -DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" +DBUS_RUNNER="dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf" ${DBUS_RUNNER} --task ./test-thousand-indicators-client --task-name Client --task ./test-thousand-indicators-server --task-name Server -- cgit v1.2.3 From 0f174a8a4904e33f912fae70a6345a861306b474 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Apr 2009 10:48:38 -0500 Subject: How important a simple backslash is :) --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 7d72047..03bd980 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,7 +14,7 @@ libexec_PROGRAMS = \ test-interests-server4 \ test-interests-server5 \ test-thousand-indicators-client \ - test-thousand-indicators-server + test-thousand-indicators-server \ test-simple-client \ test-simple-server -- cgit v1.2.3