1 #include <dazzle.h>
2
3 static void
ensure_menu_merging(DzlApplication * app)4 ensure_menu_merging (DzlApplication *app)
5 {
6 g_autofree gchar *id1 = NULL;
7 g_autofree gchar *id2 = NULL;
8 g_autofree gchar *id3 = NULL;
9 g_autofree gchar *label1 = NULL;
10 g_autoptr(GMenuModel) link1 = NULL;
11 g_autoptr(GMenuModel) link2 = NULL;
12 GMenu *menu;
13 guint len;
14 gboolean r;
15
16 menu = dzl_application_get_menu_by_id (app, "app-menu");
17 g_assert (G_IS_MENU (menu));
18
19 len = g_menu_model_get_n_items (G_MENU_MODEL (menu));
20 g_assert_cmpint (len, ==, 4);
21
22 g_assert (NULL != g_menu_model_get_item_link (G_MENU_MODEL (menu), 0, G_MENU_LINK_SECTION));
23
24 link1 = g_menu_model_get_item_link (G_MENU_MODEL (menu), 1, G_MENU_LINK_SECTION);
25 g_assert (link1 != NULL);
26 g_assert_cmpint (g_menu_model_get_n_items (link1), ==, 2);
27
28 r = g_menu_model_get_item_attribute (link1, 0, "id", "s", &id1);
29 g_assert_cmpint (r, ==, TRUE);
30 g_assert_cmpstr (id1, ==, "section-2-item-1");
31
32 r = g_menu_model_get_item_attribute (link1, 0, "label", "s", &label1);
33 g_assert_cmpint (r, ==, TRUE);
34 g_assert_cmpstr (label1, ==, "Item 2.1");
35
36 r = g_menu_model_get_item_attribute (link1, 1, "id", "s", &id2);
37 g_assert_cmpint (r, ==, TRUE);
38 g_assert_cmpstr (id2, ==, "section-2-item-2");
39
40 g_assert (NULL != g_menu_model_get_item_link (G_MENU_MODEL (menu), 2, G_MENU_LINK_SECTION));
41
42 link2 = g_menu_model_get_item_link (G_MENU_MODEL (menu), 3, G_MENU_LINK_SECTION);
43 g_assert (link2 != NULL);
44 g_assert_cmpint (g_menu_model_get_n_items (link2), ==, 1);
45
46 r = g_menu_model_get_item_attribute (link2, 0, "id", "s", &id3);
47 g_assert_cmpint (r, ==, TRUE);
48 g_assert_cmpstr (id3, ==, "section-4-item-1");
49 }
50
51 static void
ensure_keybinding_merging(DzlApplication * app)52 ensure_keybinding_merging (DzlApplication *app)
53 {
54 DzlShortcutManager *manager;
55 DzlShortcutTheme *theme;
56
57 g_assert (DZL_IS_APPLICATION (app));
58
59 manager = dzl_application_get_shortcut_manager (app);
60 g_assert (DZL_IS_SHORTCUT_MANAGER (manager));
61
62 theme = dzl_shortcut_manager_get_theme_by_name (manager, "default");
63 g_assert (DZL_IS_SHORTCUT_THEME (theme));
64
65 theme = dzl_shortcut_manager_get_theme_by_name (manager, "secondary");
66 g_assert (DZL_IS_SHORTCUT_THEME (theme));
67 g_assert_cmpstr (dzl_shortcut_theme_get_parent_name (theme), ==, "default");
68 }
69
70 static void
on_activate(DzlApplication * app)71 on_activate (DzlApplication *app)
72 {
73 ensure_menu_merging (app);
74 ensure_keybinding_merging (app);
75 }
76
77 gint
main(gint argc,gchar * argv[])78 main (gint argc,
79 gchar *argv[])
80 {
81 g_autoptr(DzlApplication) app = NULL;
82
83 app = g_object_new (DZL_TYPE_APPLICATION,
84 "application-id", "org.gnome.Dazzle.Tests.Shortcuts",
85 "flags", G_APPLICATION_NON_UNIQUE,
86 NULL);
87
88 /* Queue resource adding, which will happen for real during startup */
89 dzl_application_add_resources (app, TEST_DATA_DIR"/shortcuts/0");
90 dzl_application_add_resources (app, TEST_DATA_DIR"/shortcuts/1");
91 dzl_application_add_resources (app, TEST_DATA_DIR"/shortcuts/2");
92
93 g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
94
95 return g_application_run (G_APPLICATION (app), argc, argv);
96 }
97