Back to index

libindicator  12.10.0
test-desktop-shortcuts.c
Go to the documentation of this file.
00001 /*
00002 Test for libindicator
00003 
00004 Copyright 2009 Canonical Ltd.
00005 
00006 Authors:
00007     Ted Gould <ted@canonical.com>
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 version 3.0 as published by the Free Software Foundation.
00012 
00013 This library is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License version 3.0 for more details.
00017 
00018 You should have received a copy of the GNU General Public
00019 License along with this library. If not, see
00020 <http://www.gnu.org/licenses/>.
00021 */
00022 
00023 #include <gtk/gtk.h>
00024 #include "libindicator/indicator-desktop-shortcuts.h"
00025 
00026 /* Basic object creation and destruction.  Stop big
00027    f*** ups here. */
00028 void
00029 test_desktop_shortcuts_creation (void)
00030 {
00031 
00032        IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France");
00033        g_assert(ids != NULL);
00034 
00035        g_object_add_weak_pointer(G_OBJECT(ids), (gpointer *)&ids);
00036        g_object_unref(G_OBJECT(ids));
00037 
00038        g_assert(ids == NULL);
00039        return;
00040 }
00041 
00042 /* Tests that the NotShowIn the desktop group is watched
00043    for */
00044 void
00045 test_desktop_shortcuts_globalnoshow (void)
00046 {
00047 
00048        IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "Germany");
00049        g_assert(ids != NULL);
00050 
00051        const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids);
00052        g_assert(nicks[0] == NULL);
00053 
00054        g_object_unref(ids);
00055 
00056        return;
00057 }
00058 
00059 gboolean
00060 nicks_contains (const gchar ** nicks, const gchar * search)
00061 {
00062        if (nicks[0] == NULL)
00063               return FALSE;
00064        if (g_strcmp0(nicks[0], search) == 0)
00065               return TRUE;
00066        return nicks_contains(&nicks[1], search);
00067 }
00068 
00069 /* Checking that the local show OnlyIn works. */
00070 void
00071 test_desktop_shortcuts_localfilter (void)
00072 {
00073        IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France");
00074        g_assert(ids != NULL);
00075 
00076        const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids);
00077 
00078        g_assert(nicks_contains(nicks, "bob"));
00079        g_assert(nicks_contains(nicks, "alvin"));
00080        g_assert(!nicks_contains(nicks, "jim"));
00081 
00082        g_object_unref(ids);
00083 
00084        return;
00085 }
00086 
00087 /* Nick names -- checks to see they all have names */
00088 void
00089 test_desktop_shortcuts_nicknames (void)
00090 {
00091        IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France");
00092        g_assert(ids != NULL);
00093 
00094        const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids);
00095        gint i = 0;
00096        while (nicks[i] != NULL) {
00097               gchar * expectedstr = g_strdup_printf("%s's shortcut", nicks[i]);
00098               gchar * name = indicator_desktop_shortcuts_nick_get_name(ids, nicks[i]);
00099               g_assert(name != NULL);
00100 
00101               gboolean same = (g_strcmp0(expectedstr, name) == 0);
00102 
00103               g_free(name);
00104               g_free(expectedstr);
00105 
00106               g_assert(same);
00107 
00108               i++;
00109        }
00110 
00111 
00112        g_object_unref(ids);
00113 
00114        return;
00115 }
00116 
00117 /* Try executing a shortcut which will touch a file */
00118 void
00119 test_desktop_shortcuts_launch (void)
00120 {
00121        return;
00122        IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "TouchTest");
00123        g_assert(ids != NULL);
00124 
00125        const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids);
00126        g_assert(nicks_contains(nicks, "touch"));
00127 
00128        g_assert(indicator_desktop_shortcuts_nick_exec(ids, "touch"));
00129        g_usleep(100000);
00130        g_assert(g_file_test(BUILD_DIR "/test-desktop-shortcuts-touch-test", G_FILE_TEST_EXISTS));
00131 
00132        g_object_unref(ids);
00133 
00134        return;
00135 }
00136 
00137 /* Build our test suite */
00138 void
00139 test_desktop_shortcuts_suite (void)
00140 {
00141        g_test_add_func ("/libindicator/desktopshortcuts/creation",    test_desktop_shortcuts_creation);
00142        g_test_add_func ("/libindicator/desktopshortcuts/globalnosho", test_desktop_shortcuts_globalnoshow);
00143        g_test_add_func ("/libindicator/desktopshortcuts/nicknames",   test_desktop_shortcuts_nicknames);
00144        g_test_add_func ("/libindicator/desktopshortcuts/launch",      test_desktop_shortcuts_launch);
00145 
00146        return;
00147 }
00148 
00149 int
00150 main (int argc, char ** argv)
00151 {
00152        g_type_init (); 
00153        g_test_init (&argc, &argv, NULL);
00154        gtk_init(&argc, &argv);
00155 
00156        test_desktop_shortcuts_suite();
00157 
00158        g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
00159 
00160        return g_test_run();
00161 }