1 /*
2 Test for libindicator
3 
4 Copyright 2009 Canonical Ltd.
5 
6 Authors:
7     Ted Gould <ted@canonical.com>
8 
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 3.0 as published by the Free Software Foundation.
12 
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License version 3.0 for more details.
17 
18 You should have received a copy of the GNU General Public
19 License along with this library. If not, see
20 <http://www.gnu.org/licenses/>.
21 */
22 
23 
24 #include <glib.h>
25 #include "libindicator/indicator-service-manager.h"
26 #include "service-version-values.h"
27 
28 static GMainLoop * mainloop = NULL;
29 static gboolean con_good = FALSE;
30 static gboolean con_bad = FALSE;
31 
32 gboolean
timeout(gpointer data)33 timeout (gpointer data)
34 {
35 	g_debug("Timeout.");
36 	g_main_loop_quit(mainloop);
37 	return FALSE;
38 }
39 
40 void
connection_bad(IndicatorServiceManager * sm,gboolean connected,gpointer user_data)41 connection_bad (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
42 {
43 	if (!connected) return;
44 	g_debug("Connection From Bad!");
45 	con_bad = TRUE;
46 	return;
47 }
48 
49 void
connection_good(IndicatorServiceManager * sm,gboolean connected,gpointer user_data)50 connection_good (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
51 {
52 	if (!connected) return;
53 	g_debug("Connection From Good.");
54 	con_good = TRUE;
55 	return;
56 }
57 
58 int
main(int argc,char ** argv)59 main (int argc, char ** argv)
60 {
61 	g_type_init();
62 	g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
63 	g_print("Manager: DBUS_SESSION_BUS_ADDRESS = %s\n", g_getenv("DBUS_SESSION_BUS_ADDRESS"));
64 
65 	IndicatorServiceManager * goodis = indicator_service_manager_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD);
66 	g_signal_connect(G_OBJECT(goodis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_good), NULL);
67 
68 	IndicatorServiceManager * badis = indicator_service_manager_new_version("org.ayatana.version.bad", SERVICE_VERSION_GOOD);
69 	g_signal_connect(G_OBJECT(badis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_bad), NULL);
70 
71 	g_timeout_add_seconds(1, timeout, NULL);
72 
73 	mainloop = g_main_loop_new(NULL, FALSE);
74 	g_main_loop_run(mainloop);
75 
76 	g_object_unref(goodis);
77 	g_object_unref(badis);
78 
79 	g_debug("Quiting");
80 	if (con_good && !con_bad) {
81 		g_debug("Passed");
82 		return 0;
83 	}
84 	g_debug("Failed");
85 	return 1;
86 }
87