20
22
on_app_action (GApplication *application,
21
23
const gchar *action_name,
22
guint action_timestamp)
24
GVariant *platform_data)
26
gboolean found_timestamp;
29
guint action_timestamp;
24
32
if (g_test_verbose ())
25
g_print ("Action '%s' invoked (timestamp: %u, expected: %u)\n",
34
char *str = g_variant_print (platform_data, FALSE);
35
g_print ("Action '%s' invoked (data: %s, expected: %u)\n",
30
42
g_assert_cmpstr (action_name, ==, "About");
31
g_assert_cmpint (action_timestamp, ==, timestamp);
44
g_variant_get (platform_data, "a{sv}", &iter);
45
found_timestamp = FALSE;
46
while (g_variant_iter_next (iter, "{&sv}",
49
if (g_strcmp0 ("timestamp", key) == 0)
51
found_timestamp = TRUE;
52
g_variant_get (value, "u", &action_timestamp);
57
g_variant_iter_free (iter);
59
g_assert_cmpuint (timestamp, ==, action_timestamp);
33
61
action_invoked = TRUE;
65
create_timestamp_data ()
67
GVariantBuilder builder;
69
timestamp = 42 + timestamp;
71
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
72
g_variant_builder_add (&builder, "{sv}",
73
"timestamp", g_variant_new ("u", timestamp));
75
return g_variant_builder_end (&builder);
37
79
check_invoke_action (gpointer data)
41
83
if (state == INVOKE_ACTION)
43
timestamp = (guint) time (NULL);
45
85
if (g_test_verbose ())
46
86
g_print ("Invoking About...\n");
48
g_application_invoke_action (application, "About", timestamp);
88
g_application_invoke_action (application, "About", create_timestamp_data ());
49
90
state = CHECK_ACTION;
76
117
if (g_test_verbose ())
77
118
g_print ("Invoking disabled About action...\n");
79
g_application_invoke_action (application, "About", (guint) time (NULL));
120
g_application_invoke_action (application, "About", create_timestamp_data ());
80
121
state = CHECK_DISABLED_ACTION;
109
150
GApplication *app;
111
app = g_application_new_and_register ("org.gtk.TestApplication", 0, NULL);
152
app = g_application_new ("org.gtk.TestApplication", 0, NULL);
112
153
g_application_add_action (app, "About", "Print an about message");
114
g_signal_connect (app, "action::About", G_CALLBACK (on_app_action), NULL);
155
g_signal_connect (app, "action-with-data::About", G_CALLBACK (on_app_action), NULL);
116
157
state = INVOKE_ACTION;
117
158
g_timeout_add (100, check_invoke_action, app);
126
167
main (int argc, char *argv[])
129
172
g_test_init (&argc, &argv, NULL);
174
g_unsetenv ("DISPLAY");
175
g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
131
179
g_test_add_func ("/application/basic", test_basic);
133
return g_test_run ();