Back to index

libindicate  12.10.0
test-properties-server.c
Go to the documentation of this file.
00001 
00002 #include <glib.h>
00003 #include "libindicate/listener.h"
00004 
00005 static gboolean passed = TRUE;
00006 static GMainLoop * mainloop = NULL;
00007 static gint tests = 0;
00008 
00009 static void
00010 string_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data)
00011 {
00012        g_debug("Got string property '%s' value '%s'", property, propertydata);
00013        if (g_strcmp0(propertydata, (gchar *)data)) {
00014               passed = FALSE;
00015               g_debug("\tExpecting '%s'", (gchar *)data);
00016        }
00017        tests--;
00018        if (tests == 0) {
00019               g_main_loop_quit(mainloop);
00020        }
00021        return;
00022 }
00023 
00024 static void
00025 int_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gint propertydata, gpointer data)
00026 {
00027        g_debug("Got int property '%s' value '%d'", property, propertydata);
00028        if (propertydata != GPOINTER_TO_INT(data)) {
00029               passed = FALSE;
00030               g_debug("\tExpecting '%d'", GPOINTER_TO_INT(data));
00031        }
00032        tests--;
00033        if (tests == 0) {
00034               g_main_loop_quit(mainloop);
00035        }
00036        return;
00037 }
00038 
00039 static void
00040 bool_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gboolean propertydata, gpointer data)
00041 {
00042        g_debug("Got bool property '%s' value '%d'", property, propertydata);
00043        if (propertydata != GPOINTER_TO_INT(data)) {
00044               passed = FALSE;
00045               g_debug("\tExpecting '%d'", GPOINTER_TO_INT(data));
00046        }
00047        tests--;
00048        if (tests == 0) {
00049               g_main_loop_quit(mainloop);
00050        }
00051        return;
00052 }
00053 
00054 static void
00055 indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gpointer data)
00056 {
00057        g_debug("Indicator Added:   %s %d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), indicate_listener_indicator_get_id(indicator));
00058 
00059        indicate_listener_get_property(listener, server, indicator, "string-value", string_cb, "my-value");
00060        tests++;
00061        indicate_listener_get_property_int(listener, server, indicator, "int-value", int_cb, GINT_TO_POINTER(42));
00062        tests++;
00063        indicate_listener_get_property_bool(listener, server, indicator, "bool-value", bool_cb, GINT_TO_POINTER(TRUE));
00064        tests++;
00065        indicate_listener_get_property_bool(listener, server, indicator, "no-bool-value", bool_cb, GINT_TO_POINTER(FALSE));
00066        tests++;
00067 
00068        return;
00069 }
00070 
00071 static gboolean
00072 failed_cb (gpointer data)
00073 {
00074        g_debug("Failed to get a server in 5 seconds.");
00075        passed = FALSE;
00076        g_main_loop_quit(mainloop);
00077        return FALSE;
00078 }
00079 
00080 int
00081 main (int argc, char * argv)
00082 {
00083        g_type_init();
00084 
00085        IndicateListener * listener = indicate_listener_ref_default();
00086 
00087        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), NULL);
00088 
00089        g_timeout_add_seconds(5, failed_cb, NULL);
00090 
00091        mainloop = g_main_loop_new(NULL, FALSE);
00092        g_main_loop_run(mainloop);
00093 
00094        return !passed;
00095 }