aboutsummaryrefslogtreecommitdiff
path: root/tests/test-desktop-shortcuts.c
blob: 59084dd8e5347f1cf80ec26df65994023462d2e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Test for libayatana-indicator

Copyright 2009 Canonical Ltd.

Authors:
    Ted Gould <ted@canonical.com>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 3.0 as published by the Free Software Foundation.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License version 3.0 for more details.

You should have received a copy of the GNU General Public
License along with this library. If not, see
<http://www.gnu.org/licenses/>.
*/

#include <gtk/gtk.h>
#include "libayatana-indicator/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)
{
    return;
    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_with_context(ids, "touch", NULL));
    g_usleep(100000);
    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 ("/libayatana-indicator/desktopshortcuts/creation",    test_desktop_shortcuts_creation);
    g_test_add_func ("/libayatana-indicator/desktopshortcuts/globalnosho", test_desktop_shortcuts_globalnoshow);
    g_test_add_func ("/libayatana-indicator/desktopshortcuts/nicknames",   test_desktop_shortcuts_nicknames);
    g_test_add_func ("/libayatana-indicator/desktopshortcuts/launch",      test_desktop_shortcuts_launch);

    return;
}

int
main (int argc, char ** argv)
{
    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();
}