Back to index

libindicator  12.10.0
service-version-manager.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 
00024 #include <glib.h>
00025 #include "libindicator/indicator-service-manager.h"
00026 #include "service-version-values.h"
00027 
00028 static GMainLoop * mainloop = NULL;
00029 static gboolean con_good = FALSE;
00030 static gboolean con_bad = FALSE;
00031 
00032 gboolean
00033 timeout (gpointer data)
00034 {
00035        g_debug("Timeout.");
00036        g_main_loop_quit(mainloop);
00037        return FALSE;
00038 }
00039 
00040 void
00041 connection_bad (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
00042 {
00043        if (!connected) return;
00044        g_debug("Connection From Bad!");
00045        con_bad = TRUE;
00046        return;
00047 }
00048 
00049 void
00050 connection_good (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
00051 {
00052        if (!connected) return;
00053        g_debug("Connection From Good.");
00054        con_good = TRUE;
00055        return;
00056 }
00057 
00058 int
00059 main (int argc, char ** argv)
00060 {
00061        g_type_init();
00062        g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
00063        g_print("Manager: DBUS_SESSION_BUS_ADDRESS = %s\n", g_getenv("DBUS_SESSION_BUS_ADDRESS"));
00064 
00065        IndicatorServiceManager * goodis = indicator_service_manager_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD);
00066        g_signal_connect(G_OBJECT(goodis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_good), NULL);
00067 
00068        IndicatorServiceManager * badis = indicator_service_manager_new_version("org.ayatana.version.bad", SERVICE_VERSION_GOOD);
00069        g_signal_connect(G_OBJECT(badis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_bad), NULL);
00070 
00071        g_timeout_add_seconds(1, timeout, NULL);
00072 
00073        mainloop = g_main_loop_new(NULL, FALSE);
00074        g_main_loop_run(mainloop);
00075 
00076        g_object_unref(goodis);
00077        g_object_unref(badis);
00078 
00079        g_debug("Quiting");
00080        if (con_good && !con_bad) {
00081               g_debug("Passed");
00082               return 0;
00083        }
00084        g_debug("Failed");
00085        return 1;
00086 }