diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 189 | ||||
-rw-r--r-- | tests/dummy-indicator-blank.c | 6 | ||||
-rw-r--r-- | tests/dummy-indicator-null.c | 23 | ||||
-rw-r--r-- | tests/dummy-indicator-simple.c | 28 | ||||
-rw-r--r-- | tests/service-manager-connect-service.c | 46 | ||||
-rw-r--r-- | tests/service-manager-connect.c | 47 | ||||
-rw-r--r-- | tests/service-manager-connect.service.in | 3 | ||||
-rw-r--r-- | tests/service-manager-no-connect.c | 47 | ||||
-rw-r--r-- | tests/service-shutdown-timeout.c | 46 | ||||
-rw-r--r-- | tests/session.conf.in | 40 | ||||
-rw-r--r-- | tests/test-loader.c | 109 |
11 files changed, 584 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..7c306bc --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,189 @@ +TESTS = +DISTCLEANFILES = + +check_PROGRAMS = \ + test-loader \ + service-manager-no-connect \ + service-manager-connect \ + service-manager-connect-service \ + service-shutdown-timeout + +lib_LTLIBRARIES = \ + libdummy-indicator-blank.la \ + libdummy-indicator-null.la \ + libdummy-indicator-simple.la + +DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf + +############################# +# Test Loader +############################# + +test_loader_SOURCES = \ + test-loader.c + +test_loader_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) \ + -DBUILD_DIR="\"$(builddir)\"" + +test_loader_LDADD = \ + $(LIBINDICATOR_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a + +############################# +# Dummy Indicator Blank +############################# + +libdummy_indicator_blank_la_SOURCES = \ + dummy-indicator-blank.c + +libdummy_indicator_blank_la_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +libdummy_indicator_blank_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + +libdummy_indicator_blank_la_LDFLAGS = \ + -module \ + -avoid-version + +############################# +# Dummy Indicator NULL +############################# + +libdummy_indicator_null_la_SOURCES = \ + dummy-indicator-null.c + +libdummy_indicator_null_la_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +libdummy_indicator_null_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + +libdummy_indicator_null_la_LDFLAGS = \ + -module \ + -avoid-version + +############################# +# Dummy Indicator Simple +############################# + +libdummy_indicator_simple_la_SOURCES = \ + dummy-indicator-simple.c + +libdummy_indicator_simple_la_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +libdummy_indicator_simple_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + +libdummy_indicator_simple_la_LDFLAGS = \ + -module \ + -avoid-version + +############################# +# Service Shutdown Timeout +############################# + +service_shutdown_timeout_SOURCES = \ + service-shutdown-timeout.c + +service_shutdown_timeout_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_shutdown_timeout_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service-shutdown-timeout-tester: service-shutdown-timeout Makefile + @echo "#!/bin/sh" > service-shutdown-timeout-tester + @echo $(DBUS_RUNNER) --task ./service-shutdown-timeout >> service-shutdown-timeout-tester + @chmod +x service-shutdown-timeout-tester + +TESTS += service-shutdown-timeout-tester +DISTCLEANFILES += service-shutdown-timeout-tester + +############################# +# Service Manager No Connect +############################# + +service_manager_no_connect_SOURCES = \ + service-manager-no-connect.c + +service_manager_no_connect_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_manager_no_connect_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service-manager-no-connect-tester: service-manager-no-connect Makefile.am + @echo "#!/bin/sh" > service-manager-no-connect-tester + @echo $(DBUS_RUNNER) --task ./service-manager-no-connect >> service-manager-no-connect-tester + @chmod +x service-manager-no-connect-tester + +TESTS += service-manager-no-connect-tester +DISTCLEANFILES += service-manager-no-connect-tester + +############################# +# Service Manager Connect +############################# + +session.conf: $(srcdir)/session.conf.in Makefile.am + sed -e "s|\@servicedir\@|$(abspath $(builddir))|" $< > $@ + +service-manager-connect.service: $(srcdir)/service-manager-connect.service.in Makefile.am + sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ + +service_manager_connect_SOURCES = \ + service-manager-connect.c + +service_manager_connect_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_manager_connect_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service_manager_connect_service_SOURCES = \ + service-manager-connect-service.c + +service_manager_connect_service_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_manager_connect_service_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service-manager-connect-tester: service-manager-connect service-manager-connect-service session.conf service-manager-connect.service Makefile.am + @echo "#!/bin/sh" > service-manager-connect-tester + @echo dbus-test-runner --dbus-config $(builddir)/session.conf --task ./service-manager-connect >> service-manager-connect-tester + @chmod +x service-manager-connect-tester + +TESTS += service-manager-connect-tester +DISTCLEANFILES += service-manager-connect-tester session.conf service-manager-connect.service + +############################# +# Test stuff +############################# + +XML_REPORT = loader-check-results.xml +HTML_REPORT = loader-check-results.html + +loader-tester: test-loader libdummy-indicator-null.la libdummy-indicator-simple.la Makefile + @echo "#!/bin/sh" > loader-tester + @echo gtester -k --verbose -o=$(XML_REPORT) ./test-loader >> loader-tester + @chmod +x loader-tester + +TESTS += loader-tester +DISTCLEANFILES += loader-tester + +DISTCLEANFILES += $(XML_REPORT) $(HTML_REPORT) + diff --git a/tests/dummy-indicator-blank.c b/tests/dummy-indicator-blank.c new file mode 100644 index 0000000..41249f2 --- /dev/null +++ b/tests/dummy-indicator-blank.c @@ -0,0 +1,6 @@ + +#include "libindicator/indicator.h" + +INDICATOR_SET_VERSION +INDICATOR_SET_NAME("dummy-indicator-null") + diff --git a/tests/dummy-indicator-null.c b/tests/dummy-indicator-null.c new file mode 100644 index 0000000..ff99d71 --- /dev/null +++ b/tests/dummy-indicator-null.c @@ -0,0 +1,23 @@ + +#include "libindicator/indicator.h" + +INDICATOR_SET_VERSION +INDICATOR_SET_NAME("dummy-indicator-null") + +GtkLabel * +get_label (void) +{ + return NULL; +} + +GtkImage * +get_icon (void) +{ + return NULL; +} + +GtkMenu * +get_menu (void) +{ + return NULL; +} diff --git a/tests/dummy-indicator-simple.c b/tests/dummy-indicator-simple.c new file mode 100644 index 0000000..cee4eac --- /dev/null +++ b/tests/dummy-indicator-simple.c @@ -0,0 +1,28 @@ + +#include "libindicator/indicator.h" + +INDICATOR_SET_VERSION +INDICATOR_SET_NAME("dummy-indicator-simple") + +GtkLabel * +get_label (void) +{ + return GTK_LABEL(gtk_label_new("Simple Item")); +} + +GtkImage * +get_icon (void) +{ + return GTK_IMAGE(gtk_image_new()); +} + +GtkMenu * +get_menu (void) +{ + GtkMenu * main_menu = GTK_MENU(gtk_menu_new()); + GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading..."); + gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item); + gtk_widget_show(GTK_WIDGET(loading_item)); + + return main_menu; +} diff --git a/tests/service-manager-connect-service.c b/tests/service-manager-connect-service.c new file mode 100644 index 0000000..297f3ba --- /dev/null +++ b/tests/service-manager-connect-service.c @@ -0,0 +1,46 @@ + +#include <glib.h> +#include "libindicator/indicator-service.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = TRUE; + g_debug("Timeout with no shutdown."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +shutdown (void) +{ + g_error("Shutdown"); + passed = FALSE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicatorService * is = indicator_service_new("org.ayatana.test"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/service-manager-connect.c b/tests/service-manager-connect.c new file mode 100644 index 0000000..c252542 --- /dev/null +++ b/tests/service-manager-connect.c @@ -0,0 +1,47 @@ + +#include <glib.h> +#include "libindicator/indicator-service-manager.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = FALSE; + g_error("Timeout with no connection."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +connection (void) +{ + g_debug("Connection"); + passed = TRUE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + + IndicatorServiceManager * is = indicator_service_manager_new("org.ayatana.test"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, connection, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/service-manager-connect.service.in b/tests/service-manager-connect.service.in new file mode 100644 index 0000000..7d3da6b --- /dev/null +++ b/tests/service-manager-connect.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.ayatana.test +Exec=@builddir@/service-manager-connect-service diff --git a/tests/service-manager-no-connect.c b/tests/service-manager-no-connect.c new file mode 100644 index 0000000..1c32eb2 --- /dev/null +++ b/tests/service-manager-no-connect.c @@ -0,0 +1,47 @@ + +#include <glib.h> +#include "libindicator/indicator-service-manager.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = TRUE; + g_debug("Timeout with no connection."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +connection (void) +{ + g_debug("Connection"); + passed = FALSE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + + IndicatorServiceManager * is = indicator_service_manager_new("my.test.name"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, connection, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/service-shutdown-timeout.c b/tests/service-shutdown-timeout.c new file mode 100644 index 0000000..666739a --- /dev/null +++ b/tests/service-shutdown-timeout.c @@ -0,0 +1,46 @@ + +#include <glib.h> +#include "libindicator/indicator-service.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = FALSE; + g_error("Timeout with no shutdown."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +shutdown (void) +{ + g_debug("Shutdown"); + passed = TRUE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicatorService * is = indicator_service_new("my.test.name"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/session.conf.in b/tests/session.conf.in new file mode 100644 index 0000000..d1e2805 --- /dev/null +++ b/tests/session.conf.in @@ -0,0 +1,40 @@ +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + <!-- If we fork, keep the user's original umask to avoid affecting + the behavior of child processes. --> + <keep_umask/> + + <listen>unix:tmpdir=/tmp</listen> + + <servicedir>@servicedir@</servicedir> + + <policy context="default"> + <!-- Allow everything to be sent --> + <allow send_destination="*" eavesdrop="true"/> + <!-- Allow everything to be received --> + <allow eavesdrop="true"/> + <!-- Allow anyone to own anything --> + <allow own="*"/> + </policy> + + <!-- raise the service start timeout to 40 seconds as it can timeout + on the live cd on slow machines --> + <limit name="service_start_timeout">60000</limit> + + <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max --> + <limit name="max_incoming_bytes">1000000000</limit> + <limit name="max_outgoing_bytes">1000000000</limit> + <limit name="max_message_size">1000000000</limit> + <limit name="service_start_timeout">120000</limit> + <limit name="auth_timeout">240000</limit> + <limit name="max_completed_connections">100000</limit> + <limit name="max_incomplete_connections">10000</limit> + <limit name="max_connections_per_user">100000</limit> + <limit name="max_pending_service_starts">10000</limit> + <limit name="max_names_per_connection">50000</limit> + <limit name="max_match_rules_per_connection">50000</limit> + <limit name="max_replies_per_connection">50000</limit> + <limit name="reply_timeout">300000</limit> + +</busconfig> diff --git a/tests/test-loader.c b/tests/test-loader.c new file mode 100644 index 0000000..4b2b096 --- /dev/null +++ b/tests/test-loader.c @@ -0,0 +1,109 @@ +#include <gtk/gtk.h> +#include "libindicator/indicator-object.h" + +void destroy_cb (gpointer data, GObject * object); + +void +test_loader_filename_dummy_simple_accessors (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-simple.so"); + g_assert(object != NULL); + + g_assert(indicator_object_get_label(object) != NULL); + g_assert(indicator_object_get_menu(object) != NULL); + g_assert(indicator_object_get_icon(object) != NULL); + + g_object_unref(object); + + return; +} + +void +test_loader_filename_dummy_simple (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-simple.so"); + g_assert(object != NULL); + + gboolean unreffed = FALSE; + g_object_weak_ref(G_OBJECT(object), destroy_cb, &unreffed); + + g_object_unref(object); + g_assert(unreffed == TRUE); + + return; +} + +void +test_loader_filename_dummy_blank (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-blank.so"); + g_assert(object == NULL); + return; +} + +void +test_loader_filename_dummy_null (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-null.so"); + g_assert(object == NULL); + return; +} + +void +test_loader_filename_bad (void) +{ + IndicatorObject * object = indicator_object_new_from_file("/this/file/should/not/exist.so"); + g_assert(object == NULL); + return; +} + +void +destroy_cb (gpointer data, GObject * object) +{ + gboolean * bob = (gboolean *)data; + *bob = TRUE; + return; +} + +void +test_loader_refunref (void) +{ + GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); + + gboolean unreffed = FALSE; + g_object_weak_ref(object, destroy_cb, &unreffed); + + g_object_unref(object); + + g_assert(unreffed == TRUE); + + return; +} + +void +test_loader_creation_deletion_suite (void) +{ + g_test_add_func ("/libindicator/loader/ref_and_unref", test_loader_refunref); + g_test_add_func ("/libindicator/loader/filename_bad", test_loader_filename_bad); + g_test_add_func ("/libindicator/loader/dummy/null_load", test_loader_filename_dummy_null); + g_test_add_func ("/libindicator/loader/dummy/blank_load", test_loader_filename_dummy_null); + g_test_add_func ("/libindicator/loader/dummy/simple_load", test_loader_filename_dummy_simple); + g_test_add_func ("/libindicator/loader/dummy/simple_accessors", test_loader_filename_dummy_simple_accessors); + + return; +} + + +int +main (int argc, char ** argv) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + gtk_init(&argc, &argv); + + test_loader_creation_deletion_suite(); + + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + + return g_test_run(); +} |