aboutsummaryrefslogtreecommitdiff
path: root/tests/test-libappindicator.c
blob: c987a8fa1bcc60f288fdf3d16f91f3b87f648598 (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
Tests for the libappindicator library.

Copyright 2009 Canonical Ltd.

Authors:
    Ted Gould <ted@canonical.com>

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 <http://www.gnu.org/licenses/>.
*/


#include <glib.h>
#include <glib-object.h>

#include <libappindicator/app-indicator.h>

void
test_libappindicator_prop_signals_status_helper (AppIndicator * ci, gchar * status, gboolean * signalactivated)
{
	*signalactivated = TRUE;
	return;
}

void
test_libappindicator_prop_signals_helper (AppIndicator * ci, gboolean * signalactivated)
{
	*signalactivated = TRUE;
	return;
}

void
test_libappindicator_prop_signals (void)
{
        AppIndicator * ci = app_indicator_new ("test-app-indicator",
                                               "indicator-messages",
                                               APP_INDICATOR_CATEGORY_APPLICATION_STATUS);

	g_assert(ci != NULL);

	gboolean signaled = FALSE;
	gulong handlerid;

	handlerid = 0;
	handlerid = g_signal_connect(G_OBJECT(ci), "new-icon", G_CALLBACK(test_libappindicator_prop_signals_helper), &signaled);
	g_assert(handlerid != 0);

	handlerid = 0;
	handlerid = g_signal_connect(G_OBJECT(ci), "new-attention-icon", G_CALLBACK(test_libappindicator_prop_signals_helper), &signaled);
	g_assert(handlerid != 0);

	handlerid = 0;
	handlerid = g_signal_connect(G_OBJECT(ci), "new-status", G_CALLBACK(test_libappindicator_prop_signals_status_helper), &signaled);
	g_assert(handlerid != 0);


	signaled = FALSE;
	app_indicator_set_icon(ci, "bob");
	g_assert(signaled);

	signaled = FALSE;
	app_indicator_set_icon(ci, "bob");
	g_assert(!signaled);

	signaled = FALSE;
	app_indicator_set_icon(ci, "al");
	g_assert(signaled);


	signaled = FALSE;
	app_indicator_set_attention_icon(ci, "bob");
	g_assert(signaled);

	signaled = FALSE;
	app_indicator_set_attention_icon(ci, "bob");
	g_assert(!signaled);

	signaled = FALSE;
	app_indicator_set_attention_icon(ci, "al");
	g_assert(signaled);


	signaled = FALSE;
	app_indicator_set_status(ci, APP_INDICATOR_STATUS_PASSIVE);
	g_assert(!signaled);

	signaled = FALSE;
	app_indicator_set_status(ci, APP_INDICATOR_STATUS_ACTIVE);
	g_assert(signaled);

	signaled = FALSE;
	app_indicator_set_status(ci, APP_INDICATOR_STATUS_ACTIVE);
	g_assert(!signaled);

	signaled = FALSE;
	app_indicator_set_status(ci, APP_INDICATOR_STATUS_ATTENTION);
	g_assert(signaled);

	return;
}

void
test_libappindicator_init_set_props (void)
{
        AppIndicator * ci = app_indicator_new ("my-id",
                                               "my-name",
                                               APP_INDICATOR_CATEGORY_APPLICATION_STATUS);

	g_assert(ci != NULL);

	app_indicator_set_status(ci, APP_INDICATOR_STATUS_ACTIVE);
	app_indicator_set_attention_icon(ci, "my-attention-name");

	g_assert(!g_strcmp0("my-id", app_indicator_get_id(ci)));
	g_assert(!g_strcmp0("my-name", app_indicator_get_icon(ci)));
	g_assert(!g_strcmp0("my-attention-name", app_indicator_get_attention_icon(ci)));
	g_assert(app_indicator_get_status(ci) == APP_INDICATOR_STATUS_ACTIVE);
	g_assert(app_indicator_get_category(ci) == APP_INDICATOR_CATEGORY_APPLICATION_STATUS);

	g_object_unref(G_OBJECT(ci));
	return;
}

void
test_libappindicator_init_with_props (void)
{
        AppIndicator * ci = app_indicator_new ("my-id",
                                               "my-name",
                                               APP_INDICATOR_CATEGORY_APPLICATION_STATUS);

        app_indicator_set_status (ci, APP_INDICATOR_STATUS_ACTIVE);
        app_indicator_set_attention_icon (ci, "my-attention-name");

	g_assert(ci != NULL);

	g_assert(!g_strcmp0("my-id", app_indicator_get_id(ci)));
	g_assert(!g_strcmp0("my-name", app_indicator_get_icon(ci)));
	g_assert(!g_strcmp0("my-attention-name", app_indicator_get_attention_icon(ci)));
	g_assert(app_indicator_get_status(ci) == APP_INDICATOR_STATUS_ACTIVE);
	g_assert(app_indicator_get_category(ci) == APP_INDICATOR_CATEGORY_APPLICATION_STATUS);

	g_object_unref(G_OBJECT(ci));
	return;
}

void
test_libappindicator_init (void)
{
        AppIndicator * ci = app_indicator_new ("my-id", "my-name", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
	g_assert(ci != NULL);
	g_object_unref(G_OBJECT(ci));
	return;
}

void
test_libappindicator_props_suite (void)
{
	g_test_add_func ("/indicator-application/libappindicator/init",            test_libappindicator_init);
	g_test_add_func ("/indicator-application/libappindicator/init_props",      test_libappindicator_init_with_props);
	g_test_add_func ("/indicator-application/libappindicator/init_set_props",  test_libappindicator_init_set_props);
	g_test_add_func ("/indicator-application/libappindicator/prop_signals",    test_libappindicator_prop_signals);

	return;
}

gint
main (gint argc, gchar * argv[])
{
	gtk_init(&argc, &argv);
	g_test_init(&argc, &argv, NULL);

	/* Test suites */
	test_libappindicator_props_suite();


	return g_test_run ();
}