diff options
-rw-r--r-- | .bzrignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 14 | ||||
-rw-r--r-- | tests/test-glib-layout-client.c | 0 | ||||
-rw-r--r-- | tests/test-glib-layout-server.c | 61 | ||||
-rw-r--r-- | tests/test-glib-layout.h | 58 |
5 files changed, 133 insertions, 1 deletions
@@ -26,3 +26,4 @@ libdbusmenu_glib_la-server-marshal.lo .deps .libs glib-server-nomenu +test-glib-layout-server diff --git a/tests/Makefile.am b/tests/Makefile.am index 3c58cf0..f00a7e7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ libexec_PROGRAMS = \ - glib-server-nomenu + glib-server-nomenu \ + test-glib-layout-server glib_server_nomenu_SOURCES = \ glib-server-nomenu.c @@ -13,6 +14,17 @@ glib_server_nomenu_LDADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ $(DBUSMENUGLIB_LIBS) +test_glib_layout_server_SOURCES = \ + test-glib-layout-server.c + +test_glib_layout_server_CFLAGS = \ + -I $(srcdir)/.. \ + $(DBUSMENUGLIB_CFLAGS) -Wall -Werror + +test_glib_layout_server_LDADD = \ + ../libdbusmenu-glib/libdbusmenu-glib.la \ + $(DBUSMENUGLIB_LIBS) + diff --git a/tests/test-glib-layout-client.c b/tests/test-glib-layout-client.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test-glib-layout-client.c diff --git a/tests/test-glib-layout-server.c b/tests/test-glib-layout-server.c new file mode 100644 index 0000000..6ec9b0c --- /dev/null +++ b/tests/test-glib-layout-server.c @@ -0,0 +1,61 @@ + +#include <glib.h> + +#include <libdbusmenu-glib/server.h> +#include <libdbusmenu-glib/menuitem.h> + +#include "test-glib-layout.h" + + +static DbusmenuMenuitem * +layout2menuitem (layout_t * layout) +{ + if (layout == NULL || layout->id == 0) return NULL; + + DbusmenuMenuitem * local = dbusmenu_menuitem_new_with_id(layout->id); + + if (layout->submenu != NULL) { + guint count; + for (count = 0; layout->submenu[count].id != 0; count++) { + DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]); + if (child != NULL) { + dbusmenu_menuitem_child_append(local, child); + } + } + } + + return local; +} + +static guint layouton = 0; +static DbusmenuServer * server = NULL; +static GMainLoop * mainloop = NULL; + +static gboolean +timer_func (gpointer data) +{ + if (layouts[layouton].id == 0) { + g_main_loop_quit(mainloop); + return FALSE; + } + + dbusmenu_server_set_root(server, layout2menuitem(&layouts[layouton++])); + + return TRUE; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + server = dbusmenu_server_new("/org/test"); + + timer_func(NULL); + g_timeout_add(100, timer_func, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return 0; +} diff --git a/tests/test-glib-layout.h b/tests/test-glib-layout.h new file mode 100644 index 0000000..d315e90 --- /dev/null +++ b/tests/test-glib-layout.h @@ -0,0 +1,58 @@ + +typedef struct _layout_t layout_t; +struct _layout_t { + guint id; + layout_t * submenu; +}; + +layout_t submenu_2[] = { + {id: 2, submenu: NULL}, + {id: 3, submenu: NULL}, + {id: 0, submenu: NULL} +}; +layout_t submenu_3_1[] = { + {id: 3, submenu: NULL}, + {id: 4, submenu: NULL}, + {id: 5, submenu: NULL}, + {id: 0, submenu: NULL} +}; +layout_t submenu_3_2[] = { + {id: 7, submenu: NULL}, + {id: 8, submenu: NULL}, + {id: 9, submenu: NULL}, + {id: 0, submenu: NULL} +}; +layout_t submenu_3[] = { + {id: 2, submenu: submenu_3_1}, + {id: 6, submenu: submenu_3_2}, + {id: 0, submenu: NULL} +}; +layout_t submenu_4_1[] = { + {id: 6, submenu: NULL}, + {id: 0, submenu: NULL} +}; +layout_t submenu_4_2[] = { + {id: 5, submenu: submenu_4_1}, + {id: 0, submenu: NULL} +}; +layout_t submenu_4_3[] = { + {id: 4, submenu: submenu_4_2}, + {id: 0, submenu: NULL} +}; +layout_t submenu_4_4[] = { + {id: 3, submenu: submenu_4_3}, + {id: 0, submenu: NULL} +}; +layout_t submenu_4_5[] = { + {id: 2, submenu: submenu_4_4}, + {id: 0, submenu: NULL} +}; + +layout_t layouts[] = { + {id: 5, submenu: NULL}, + {id: 1, submenu: submenu_2}, + {id: 1, submenu: submenu_3}, + {id: 1, submenu: submenu_4_5}, + {id: 0, submenu: NULL} +}; + |