diff options
author | Ted Gould <ted@gould.cx> | 2010-02-16 22:51:13 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-02-16 22:51:13 -0600 |
commit | a9e097f3f87fa3aac7a06ddbc137c6122c65c9dc (patch) | |
tree | 42360c9b2d858b2c97ac8dea8cef91f2afcaa1bd /tests | |
parent | 72ef75fa51c63e533ff2883bffc75bfc86a2c521 (diff) | |
parent | 6665fd01b1b85646f5c21aa393a3c3e6a8e4ab97 (diff) | |
download | libayatana-indicator-a9e097f3f87fa3aac7a06ddbc137c6122c65c9dc.tar.gz libayatana-indicator-a9e097f3f87fa3aac7a06ddbc137c6122c65c9dc.tar.bz2 libayatana-indicator-a9e097f3f87fa3aac7a06ddbc137c6122c65c9dc.zip |
* Upstream merge
* Adding new object for parsing desktop files for Shortcuts
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 36 | ||||
-rw-r--r-- | tests/test-desktop-shortcuts.c | 137 | ||||
-rw-r--r-- | tests/test-well-formed.desktop | 24 |
3 files changed, 197 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index b111655..cd1a958 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -34,6 +34,42 @@ test_loader_LDADD = \ -lindicator ############################# +# Test Desktop Shortcuts +############################# + +check_PROGRAMS += test-desktop-shortcuts + +test_desktop_shortcuts_SOURCES = \ + test-desktop-shortcuts.c + +test_desktop_shortcuts_CFLAGS = \ + -Wall -Werror \ + -DSRCDIR="\"$(srcdir)\"" \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) \ + -DBUILD_DIR="\"$(builddir)\"" + +test_desktop_shortcuts_LDADD = \ + $(LIBINDICATOR_LIBS) \ + -L$(top_builddir)/libindicator/.libs \ + -lindicator + +DS_XML_REPORT = desktop-shortcuts-check-results.xml +DS_HTML_REPORT = desktop-shortcuts-check-results.html + +test-desktop-shortcuts-tester: test-desktop-shortcuts Makefile.am + @echo "#!/bin/bash" > $@ + @echo $(XVFB_RUN) >> $@ + @echo gtester -k --verbose -o=$(XML_REPORT) ./test-desktop-shortcuts >> $@ + @chmod +x $@ + +TESTS += test-desktop-shortcuts-tester +DISTCLEANFILES += test-desktop-shortcuts-tester \ + test-desktop-shortcuts-touch-test \ + $(DS_XML_REPORT) \ + $(DS_HTML_REPORT) +EXTRA_DIST += test-well-formed.desktop + +############################# # Dummy Indicator Blank ############################# diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c new file mode 100644 index 0000000..1a655f7 --- /dev/null +++ b/tests/test-desktop-shortcuts.c @@ -0,0 +1,137 @@ +#include <gtk/gtk.h> +#include "libindicator/indicator-desktop-shortcuts.h" + +/* Basic object creation and destruction. Stop big + f*** ups here. */ +void +test_desktop_shortcuts_creation (void) +{ + + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France"); + g_assert(ids != NULL); + + g_object_add_weak_pointer(G_OBJECT(ids), (gpointer *)&ids); + g_object_unref(G_OBJECT(ids)); + + g_assert(ids == NULL); + return; +} + +/* Tests that the NotShowIn the desktop group is watched + for */ +void +test_desktop_shortcuts_globalnoshow (void) +{ + + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "Germany"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + g_assert(nicks[0] == NULL); + + g_object_unref(ids); + + return; +} + +gboolean +nicks_contains (const gchar ** nicks, const gchar * search) +{ + if (nicks[0] == NULL) + return FALSE; + if (g_strcmp0(nicks[0], search) == 0) + return TRUE; + return nicks_contains(&nicks[1], search); +} + +/* Checking that the local show OnlyIn works. */ +void +test_desktop_shortcuts_localfilter (void) +{ + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + + g_assert(nicks_contains(nicks, "bob")); + g_assert(nicks_contains(nicks, "alvin")); + g_assert(!nicks_contains(nicks, "jim")); + + g_object_unref(ids); + + return; +} + +/* Nick names -- checks to see they all have names */ +void +test_desktop_shortcuts_nicknames (void) +{ + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + gint i = 0; + while (nicks[i] != NULL) { + gchar * expectedstr = g_strdup_printf("%s's shortcut", nicks[i]); + gchar * name = indicator_desktop_shortcuts_nick_get_name(ids, nicks[i]); + g_assert(name != NULL); + + gboolean same = (g_strcmp0(expectedstr, name) == 0); + + g_free(name); + g_free(expectedstr); + + g_assert(same); + + i++; + } + + + g_object_unref(ids); + + return; +} + +/* Try executing a shortcut which will touch a file */ +void +test_desktop_shortcuts_launch (void) +{ + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "TouchTest"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + g_assert(nicks_contains(nicks, "touch")); + + g_assert(indicator_desktop_shortcuts_nick_exec(ids, "touch")); + g_assert(g_file_test(BUILD_DIR "/test-desktop-shortcuts-touch-test", G_FILE_TEST_EXISTS)); + + g_object_unref(ids); + + return; +} + +/* Build our test suite */ +void +test_desktop_shortcuts_suite (void) +{ + g_test_add_func ("/libindicator/desktopshortcuts/creation", test_desktop_shortcuts_creation); + g_test_add_func ("/libindicator/desktopshortcuts/globalnosho", test_desktop_shortcuts_globalnoshow); + g_test_add_func ("/libindicator/desktopshortcuts/nicknames", test_desktop_shortcuts_nicknames); + g_test_add_func ("/libindicator/desktopshortcuts/launch", test_desktop_shortcuts_launch); + + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + gtk_init(&argc, &argv); + + test_desktop_shortcuts_suite(); + + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + + return g_test_run(); +} diff --git a/tests/test-well-formed.desktop b/tests/test-well-formed.desktop new file mode 100644 index 0000000..84e2e02 --- /dev/null +++ b/tests/test-well-formed.desktop @@ -0,0 +1,24 @@ +[Desktop Entry] +Name=My Application +Exec=ls +NotShowIn=Germany +X-Ayatana-Desktop-Shortcuts=bob;alvin;jim;touch + +[bob Shortcut Group] +Name=bob's shortcut +Exec=ls bob + +[alvin Shortcut Group] +Name=alvin's shortcut +Exec=ls alvin +OnlyShowIn=France + +[jim Shortcut Group] +Name=Jim's shortcut +Exec=ls jim +NotShowIn=France + +[touch Shortcut Group] +Name=Touch Test +Exec=touch test-desktop-shortcuts-touch-test +OnlyShowIn=TouchTest |