1 /* Regression test for https://bugs.freedesktop.org/show_bug.cgi?id=15306
2 *
3 * Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/>
4 * Copyright (C) 2007-2008 Nokia Corporation
5 *
6 * Copying and distribution of this file, with or without modification,
7 * are permitted in any medium without royalty provided the copyright
8 * notice and this notice are preserved.
9 */
10
11 #include "config.h"
12
13 #include <telepathy-glib/connection.h>
14 #include <telepathy-glib/dbus.h>
15 #include <telepathy-glib/debug.h>
16 #include <telepathy-glib/interfaces.h>
17
18 #include "tests/lib/myassert.h"
19 #include "tests/lib/simple-conn.h"
20 #include "tests/lib/util.h"
21
22 static GType bug15306_connection_get_type (void);
23
24 typedef TpTestsSimpleConnection Bug15306Connection;
25 typedef TpTestsSimpleConnectionClass Bug15306ConnectionClass;
26
27 static void bug15306_conn_iface_init (gpointer, gpointer);
28
G_DEFINE_TYPE_WITH_CODE(Bug15306Connection,bug15306_connection,TP_TESTS_TYPE_SIMPLE_CONNECTION,G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION,bug15306_conn_iface_init))29 G_DEFINE_TYPE_WITH_CODE (Bug15306Connection,
30 bug15306_connection,
31 TP_TESTS_TYPE_SIMPLE_CONNECTION,
32 G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION, bug15306_conn_iface_init))
33
34 static void
35 bug15306_connection_init (Bug15306Connection *self)
36 {
37 }
38
39 static void
bug15306_connection_class_init(Bug15306ConnectionClass * klass)40 bug15306_connection_class_init (Bug15306ConnectionClass *klass)
41 {
42 }
43
44 static void
bug15306_get_interfaces(TpSvcConnection * iface,DBusGMethodInvocation * context)45 bug15306_get_interfaces (TpSvcConnection *iface,
46 DBusGMethodInvocation *context)
47 {
48 GError e = { TP_ERROR, TP_ERROR_NOT_AVAILABLE, "testing fd.o #15306" };
49
50 dbus_g_method_return_error (context, &e);
51 }
52
53 static void
bug15306_conn_iface_init(gpointer g_iface,gpointer iface_data)54 bug15306_conn_iface_init (gpointer g_iface,
55 gpointer iface_data)
56 {
57 TpSvcConnectionClass *klass = g_iface;
58
59 #define IMPLEMENT(x) tp_svc_connection_implement_##x (klass, \
60 bug15306_##x)
61 IMPLEMENT (get_interfaces);
62 #undef IMPLEMENT
63 }
64
65 static GMainLoop *mainloop;
66
67 static void
on_status_changed(TpConnection * connection,guint status,guint reason,gpointer user_data,GObject * weak_object)68 on_status_changed (TpConnection *connection,
69 guint status,
70 guint reason,
71 gpointer user_data,
72 GObject *weak_object)
73 {
74 MYASSERT (status == TP_CONNECTION_STATUS_DISCONNECTED, "%u", status);
75 }
76
77 static void
on_shutdown_finished(TpBaseConnection * base_conn,gpointer user_data)78 on_shutdown_finished (TpBaseConnection *base_conn,
79 gpointer user_data)
80 {
81 g_main_loop_quit (mainloop);
82 }
83
84 int
main(int argc,char ** argv)85 main (int argc,
86 char **argv)
87 {
88 TpTestsSimpleConnection *service_conn;
89 TpBaseConnection *service_conn_as_base;
90 TpDBusDaemon *dbus;
91 TpConnection *conn;
92 GError *error = NULL;
93 gchar *name;
94 gchar *conn_path;
95
96 tp_tests_abort_after (10);
97 tp_debug_set_flags ("all");
98 mainloop = g_main_loop_new (NULL, FALSE);
99 dbus = tp_tests_dbus_daemon_dup_or_die ();
100
101 service_conn = TP_TESTS_SIMPLE_CONNECTION (tp_tests_object_new_static_class (
102 bug15306_connection_get_type (),
103 "account", "me@example.com",
104 "protocol", "simple",
105 NULL));
106 service_conn_as_base = TP_BASE_CONNECTION (service_conn);
107 MYASSERT (service_conn != NULL, "");
108 MYASSERT (service_conn_as_base != NULL, "");
109
110 g_signal_connect (service_conn, "shutdown-finished",
111 G_CALLBACK (on_shutdown_finished), NULL);
112
113 MYASSERT (tp_base_connection_register (service_conn_as_base, "simple",
114 &name, &conn_path, &error), "");
115 g_assert_no_error (error);
116
117 conn = tp_connection_new (dbus, name, conn_path, &error);
118 MYASSERT (conn != NULL, "");
119 g_assert_no_error (error);
120
121 MYASSERT (tp_connection_run_until_ready (conn, TRUE, &error, NULL),
122 "");
123 g_assert_no_error (error);
124
125 /* disconnect the service_conn */
126 MYASSERT (tp_cli_connection_connect_to_status_changed (conn,
127 on_status_changed, NULL, NULL, NULL, NULL), "");
128 tp_tests_simple_connection_inject_disconnect (service_conn);
129 g_main_loop_run (mainloop);
130
131 g_object_unref (conn);
132
133 service_conn_as_base = NULL;
134 g_object_unref (service_conn);
135 g_object_unref (dbus);
136 g_main_loop_unref (mainloop);
137 g_free (name);
138 g_free (conn_path);
139
140 return 0;
141 }
142