Back to index

libindicator  12.10.0
service-manager-nostart-connect.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 
00027 static GMainLoop * mainloop = NULL;
00028 static gboolean passed = FALSE;
00029 
00030 gboolean
00031 timeout (gpointer data)
00032 {
00033        passed = FALSE;
00034        g_error("Timeout with no connection.");
00035        g_main_loop_quit(mainloop);
00036        return FALSE;
00037 }
00038 
00039 void
00040 connection (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
00041 {
00042        static gboolean has_connected = FALSE;
00043 
00044        if (has_connected && connected) {
00045               g_warning("We got two connected signals.  FAIL.");
00046               passed = FALSE;
00047               return;
00048        }
00049 
00050        if (!connected) {
00051               g_debug("Not connected");
00052               return;
00053        }
00054 
00055        has_connected = TRUE;
00056        g_debug("Connection");
00057        passed = TRUE;
00058        g_main_loop_quit(mainloop);
00059        return;
00060 }
00061 
00062 int
00063 main (int argc, char ** argv)
00064 {
00065        g_type_init();
00066        g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
00067 
00068        g_usleep(150000);
00069 
00070        IndicatorServiceManager * is = indicator_service_manager_new("org.ayatana.test");
00071        g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection), NULL);
00072 
00073        g_timeout_add_seconds(1, timeout, NULL);
00074 
00075        mainloop = g_main_loop_new(NULL, FALSE);
00076        g_main_loop_run(mainloop);
00077 
00078        g_object_unref(is);
00079 
00080        g_debug("Quiting");
00081        if (passed) {
00082               g_debug("Passed");
00083               return 0;
00084        }
00085        g_debug("Failed");
00086        return 1;
00087 }