Link Here
|
1 |
/* |
2 |
* Copyright (C) 2009 Canonical, Ltd. |
3 |
* |
4 |
* This library is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU Lesser General Public |
6 |
* License as published by the Free Software Foundation; either |
7 |
* version 2 of the License, or (at your option) any later version. |
8 |
* |
9 |
* This library is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
* Lesser General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU Lesser General Public |
15 |
* License along with this library; if not, write to the |
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 |
* Boston, MA 02111-1307, USA. |
18 |
* |
19 |
* Authors: Cody Russell <bratsche@gnome.org> |
20 |
*/ |
21 |
|
22 |
#undef GTK_DISABLE_DEPRECATED |
23 |
#include "../gtk/gtk.h" |
24 |
|
25 |
typedef struct _TestProxy TestProxy; |
26 |
typedef struct _TestProxyClass TestProxyClass; |
27 |
|
28 |
//static GType test_proxy_type_id = 0; |
29 |
//static TestProxyClass *test_proxy_parent_class = NULL; |
30 |
|
31 |
#define TEST_TYPE_PROXY (test_proxy_type_id) |
32 |
#define TEST_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_PROXY, TestProxy)) |
33 |
#define TEST_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_PROXY, TestProxyClass)) |
34 |
#define TEST_IS_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_PROXY)) |
35 |
|
36 |
struct _TestProxy |
37 |
{ |
38 |
UbuntuMenuProxy parent_object; |
39 |
}; |
40 |
|
41 |
struct _TestProxyClass |
42 |
{ |
43 |
UbuntuMenuProxyClass parent_class; |
44 |
}; |
45 |
|
46 |
static void test_proxy_insert (UbuntuMenuProxy *proxy, |
47 |
GtkWidget *child, |
48 |
guint position); |
49 |
|
50 |
G_DEFINE_DYNAMIC_TYPE(TestProxy, test_proxy, UBUNTU_TYPE_MENU_PROXY) |
51 |
|
52 |
static void |
53 |
test_proxy_init (TestProxy *proxy) |
54 |
{ |
55 |
} |
56 |
|
57 |
static void |
58 |
test_proxy_class_init (TestProxyClass *class) |
59 |
{ |
60 |
UbuntuMenuProxyClass *proxy_class = UBUNTU_MENU_PROXY_CLASS (class); |
61 |
|
62 |
test_proxy_parent_class = g_type_class_peek_parent (class); |
63 |
|
64 |
proxy_class->insert = test_proxy_insert; |
65 |
} |
66 |
|
67 |
static void |
68 |
test_proxy_class_finalize (TestProxyClass *class) |
69 |
{ |
70 |
} |
71 |
|
72 |
static void |
73 |
test_proxy_insert (UbuntuMenuProxy *proxy, |
74 |
GtkWidget *child, |
75 |
guint position) |
76 |
{ |
77 |
} |
78 |
|
79 |
/* ---------------------------------------------------- */ |
80 |
|
81 |
#define TEST_TYPE_MODULE (test_module_get_type ()) |
82 |
#define TEST_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TEST_TYPE_MODULE, TestModule)) |
83 |
#define TEST_MODULE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TEST_TYPE_MODULE, TestModuleClass)) |
84 |
#define TEST_IS_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TEST_TYPE_MODULE)) |
85 |
#define TEST_IS_MODULE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TEST_TYPE_MODULE)) |
86 |
#define TEST_MODULE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TEST_TYPE_MODULE, TestModuleClass)) |
87 |
|
88 |
|
89 |
typedef struct _TestModule TestModule; |
90 |
typedef struct _TestModuleClass TestModuleClass; |
91 |
|
92 |
struct _TestModule |
93 |
{ |
94 |
GTypeModule parent_instance; |
95 |
}; |
96 |
|
97 |
struct _TestModuleClass |
98 |
{ |
99 |
GTypeModuleClass parent_class; |
100 |
}; |
101 |
|
102 |
static gboolean |
103 |
test_module_load (GTypeModule *module) |
104 |
{ |
105 |
g_print ("registering type...\n"); |
106 |
g_print (" type_id = %d\n", test_proxy_type_id); |
107 |
|
108 |
test_proxy_register_type (G_TYPE_MODULE (module)); |
109 |
|
110 |
//test_proxy_get_type (G_TYPE_MODULE (module)); |
111 |
|
112 |
g_print (" type_id = %d\n", test_proxy_type_id); |
113 |
|
114 |
return TRUE; |
115 |
} |
116 |
|
117 |
static void |
118 |
test_module_unload (GTypeModule *module) |
119 |
{ |
120 |
} |
121 |
|
122 |
static void |
123 |
test_module_class_init (TestModuleClass *class) |
124 |
{ |
125 |
GTypeModuleClass *type_module_class = G_TYPE_MODULE_CLASS (class); |
126 |
|
127 |
type_module_class->load = test_module_load; |
128 |
type_module_class->unload = test_module_unload; |
129 |
} |
130 |
|
131 |
static void |
132 |
test_module_init (TestModule *module) |
133 |
{ |
134 |
} |
135 |
|
136 |
G_DEFINE_TYPE (TestModule, test_module, G_TYPE_TYPE_MODULE); |
137 |
|
138 |
TestModule * |
139 |
test_module_new (void) |
140 |
{ |
141 |
TestModule *module = g_object_new (TEST_TYPE_MODULE, |
142 |
NULL); |
143 |
|
144 |
g_print ("test_module_new(): %p\n", module); |
145 |
|
146 |
return module; |
147 |
} |
148 |
|
149 |
|
150 |
/* ---------------------------------------------------- */ |
151 |
|
152 |
static void |
153 |
non_null_proxy_test (void) |
154 |
{ |
155 |
UbuntuMenuProxyModule *module; |
156 |
|
157 |
/* prevent the module loader from finding a proxy module */ |
158 |
g_unsetenv ("UBUNTU_MENUPROXY"); |
159 |
|
160 |
module = ubuntu_menu_proxy_module_get (); |
161 |
test_proxy_register_type (G_TYPE_MODULE (module)); |
162 |
//test_proxy_get_type (G_TYPE_MODULE (module)); |
163 |
|
164 |
GtkWidget *widget = g_object_new (GTK_TYPE_MENU_BAR, NULL); |
165 |
g_object_ref_sink (widget); |
166 |
|
167 |
g_assert (GTK_IS_MENU_BAR (widget)); |
168 |
//g_assert (GTK_MENU_SHELL (widget)->proxy != NULL); |
169 |
|
170 |
g_object_unref (widget); |
171 |
} |
172 |
|
173 |
static void |
174 |
null_proxy_test (void) |
175 |
{ |
176 |
GtkWidget *widget = g_object_new (GTK_TYPE_MENU_BAR, NULL); |
177 |
g_object_ref_sink (widget); |
178 |
|
179 |
g_assert (GTK_IS_MENU_BAR (widget)); |
180 |
|
181 |
//g_assert (GTK_MENU_SHELL (widget)->proxy == NULL); |
182 |
|
183 |
g_object_unref (widget); |
184 |
} |
185 |
|
186 |
static gboolean inserted_called = FALSE; |
187 |
|
188 |
static void |
189 |
inserted_cb (UbuntuMenuProxy *proxy, |
190 |
GtkWidget *child, |
191 |
guint position, |
192 |
gpointer data) |
193 |
{ |
194 |
g_return_if_fail (UBUNTU_IS_MENU_PROXY (proxy)); |
195 |
g_return_if_fail (GTK_IS_WIDGET (child)); |
196 |
inserted_called = TRUE; |
197 |
} |
198 |
|
199 |
static void |
200 |
menubar_signals_proxy_test (void) |
201 |
{ |
202 |
GtkWidget *widget = NULL; |
203 |
GtkWidget *menuitem = NULL; |
204 |
UbuntuMenuProxy *proxy; |
205 |
|
206 |
//ubuntu_menu_proxy_register_type (test_proxy_get_type ()); |
207 |
|
208 |
widget = g_object_new (GTK_TYPE_MENU_BAR, NULL); |
209 |
g_object_ref_sink (widget); |
210 |
|
211 |
g_assert (GTK_IS_MENU_BAR (widget)); |
212 |
//g_assert (GTK_MENU_SHELL (widget)->proxy != NULL); |
213 |
|
214 |
/* |
215 |
proxy = GTK_MENU_SHELL (widget)->proxy; |
216 |
|
217 |
g_signal_connect (proxy, |
218 |
"inserted", G_CALLBACK (inserted_cb), |
219 |
NULL); |
220 |
*/ |
221 |
|
222 |
// insert menuitem |
223 |
menuitem = gtk_menu_item_new_with_label ("Test Item"); |
224 |
gtk_menu_shell_append (GTK_MENU_SHELL (widget), |
225 |
menuitem); |
226 |
|
227 |
g_assert (inserted_called == TRUE); |
228 |
|
229 |
g_object_unref (widget); |
230 |
} |
231 |
|
232 |
static void |
233 |
proxy_type_exists_test (void) |
234 |
{ |
235 |
#if 0 |
236 |
UbuntuMenuProxyModule *module; |
237 |
|
238 |
g_unsetenv ("GTK_MENUPROXY"); |
239 |
|
240 |
module = ubuntu_menu_proxy_module_get (); |
241 |
test_proxy_get_type (G_TYPE_MODULE (module)); |
242 |
#endif |
243 |
|
244 |
g_assert (ubuntu_menu_proxy_get_type () != 0); |
245 |
} |
246 |
|
247 |
static void |
248 |
can_instantiate_test (void) |
249 |
{ |
250 |
TestModule *module = test_module_new (); |
251 |
|
252 |
g_type_module_use (G_TYPE_MODULE (module)); |
253 |
|
254 |
UbuntuMenuProxy *proxy = ubuntu_menu_proxy_get (); |
255 |
|
256 |
g_assert (proxy != NULL); |
257 |
|
258 |
g_object_ref_sink (proxy); |
259 |
|
260 |
g_assert (TEST_IS_PROXY (proxy)); |
261 |
g_assert (UBUNTU_IS_MENU_PROXY (proxy)); |
262 |
|
263 |
g_object_unref (proxy); |
264 |
} |
265 |
|
266 |
int |
267 |
main (int argc, char *argv[]) |
268 |
{ |
269 |
gtk_test_init (&argc, &argv); |
270 |
|
271 |
g_test_add_func ("/proxy/null-proxy", null_proxy_test); |
272 |
g_test_add_func ("/proxy/type-exists", proxy_type_exists_test); |
273 |
g_test_add_func ("/proxy/can-instantiate", can_instantiate_test); |
274 |
g_test_add_func ("/proxy/non-null-proxy", non_null_proxy_test); |
275 |
g_test_add_func ("/proxy/menubar-signals-proxy", menubar_signals_proxy_test); |
276 |
|
277 |
return g_test_run(); |
278 |
} |