Tizen 2.1 base
[platform/upstream/glib2.0.git] / gio / tests / gdbus-tests.h
1 /* GLib testing framework examples and tests
2  *
3  * Copyright (C) 2008-2009 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: David Zeuthen <davidz@redhat.com>
21  */
22
23 #ifndef __TESTS_H__
24 #define __TESTS_H__
25
26 #include <gio/gio.h>
27 #include "gdbus-sessionbus.h"
28
29 G_BEGIN_DECLS
30
31 /* TODO: clean up and move to gtestutils.c
32  *
33  * This is needed because libdbus-1 does not give predictable error messages - e.g. you
34  * get a different error message on connecting to a bus if the socket file is there vs
35  * if the socket file is missing.
36  */
37
38 #define _g_assert_error_domain(err, dom)        do { if (!err || (err)->domain != dom) \
39       g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
40                                  #err, err, dom, -1); } while (0)
41
42 #define _g_assert_property_notify(object, property_name)                \
43   do                                                                    \
44     {                                                                   \
45       if (!G_IS_OBJECT (object))                                        \
46         {                                                               \
47           g_assertion_message (G_LOG_DOMAIN,                            \
48                                __FILE__,                                \
49                                __LINE__,                                \
50                                G_STRFUNC,                               \
51                                "Not a GObject instance");               \
52         }                                                               \
53       if (g_object_class_find_property (G_OBJECT_GET_CLASS (object),    \
54                                         property_name) == NULL)         \
55         {                                                               \
56           g_assertion_message (G_LOG_DOMAIN,                            \
57                                __FILE__,                                \
58                                __LINE__,                                \
59                                G_STRFUNC,                               \
60                                "Property " property_name " does not "   \
61                                "exist on object");                      \
62         }                                                               \
63       if (_g_assert_property_notify_run (object, property_name))        \
64         {                                                               \
65           g_assertion_message (G_LOG_DOMAIN,                            \
66                                __FILE__,                                \
67                                __LINE__,                                \
68                                G_STRFUNC,                               \
69                                "Timed out waiting for notification "    \
70                                "on property " property_name);           \
71         }                                                               \
72     }                                                                   \
73   while (FALSE)
74
75 #define _g_assert_signal_received(object, signal_name)                  \
76   do                                                                    \
77     {                                                                   \
78       if (!G_IS_OBJECT (object))                                        \
79         {                                                               \
80           g_assertion_message (G_LOG_DOMAIN,                            \
81                                __FILE__,                                \
82                                __LINE__,                                \
83                                G_STRFUNC,                               \
84                                "Not a GObject instance");               \
85         }                                                               \
86       if (g_signal_lookup (signal_name,                                 \
87                            G_TYPE_FROM_INSTANCE (object)) == 0)         \
88         {                                                               \
89           g_assertion_message (G_LOG_DOMAIN,                            \
90                                __FILE__,                                \
91                                __LINE__,                                \
92                                G_STRFUNC,                               \
93                                "Signal `" signal_name "' does not "     \
94                                "exist on object");                      \
95         }                                                               \
96       if (_g_assert_signal_received_run (object, signal_name))          \
97         {                                                               \
98           g_assertion_message (G_LOG_DOMAIN,                            \
99                                __FILE__,                                \
100                                __LINE__,                                \
101                                G_STRFUNC,                               \
102                                "Timed out waiting for signal `"         \
103                                signal_name "'");                        \
104         }                                                               \
105     }                                                                   \
106   while (FALSE)
107
108 gboolean _g_assert_property_notify_run (gpointer     object,
109                                         const gchar *property_name);
110
111
112 gboolean _g_assert_signal_received_run (gpointer     object,
113                                         const gchar *signal_name);
114
115 GDBusConnection *_g_bus_get_priv (GBusType            bus_type,
116                                   GCancellable       *cancellable,
117                                   GError            **error);
118
119
120 #define _g_object_wait_for_single_ref(object) \
121   do \
122     { \
123       if (!G_IS_OBJECT (object))                                        \
124         {                                                               \
125           g_assertion_message (G_LOG_DOMAIN,                            \
126                                __FILE__,                                \
127                                __LINE__,                                \
128                                G_STRFUNC,                               \
129                                "Not a GObject instance");               \
130         }                                                               \
131       if (_g_object_wait_for_single_ref_do (object))                    \
132         {                                                               \
133           g_assertion_message (G_LOG_DOMAIN,                            \
134                                __FILE__,                                \
135                                __LINE__,                                \
136                                G_STRFUNC,                               \
137                                "Timed out waiting for single ref");     \
138         }                                                               \
139     }                                                                   \
140   while (FALSE)
141
142 gboolean _g_object_wait_for_single_ref_do (gpointer object);
143
144 G_END_DECLS
145
146 #endif /* __TESTS_H__ */