g_assert (!a.did_run);
}
+static void
+test_name (void)
+{
+ g_assert (!g_action_name_is_valid (""));
+ g_assert (!g_action_name_is_valid ("("));
+ g_assert (!g_action_name_is_valid ("%abc"));
+ g_assert (!g_action_name_is_valid ("$x1"));
+ g_assert (g_action_name_is_valid ("abc.def"));
+ g_assert (g_action_name_is_valid ("ABC-DEF"));
+}
+
static gboolean
strv_has_string (gchar **haystack,
const gchar *needle)
return res;
}
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
static void
test_simple_group (void)
{
action = g_simple_action_group_lookup (group, "bar");
g_assert (action == NULL);
+ simple = g_simple_action_new ("foo", NULL);
+ g_simple_action_group_insert (group, G_ACTION (simple));
+ g_object_unref (simple);
+
a.did_run = FALSE;
g_object_unref (group);
g_assert (!a.did_run);
}
+G_GNUC_END_IGNORE_DEPRECATIONS
+
static void
test_stateful (void)
{
g_object_unref (action);
}
+static void
+test_default_activate (void)
+{
+ GSimpleAction *action;
+ GVariant *state;
+
+ /* Test changing state via activation with parameter */
+ action = g_simple_action_new_stateful ("foo", G_VARIANT_TYPE_STRING, g_variant_new_string ("hihi"));
+ g_action_activate (G_ACTION (action), g_variant_new_string ("bye"));
+ state = g_action_get_state (G_ACTION (action));
+ g_assert_cmpstr (g_variant_get_string (state, NULL), ==, "bye");
+ g_variant_unref (state);
+ g_object_unref (action);
+
+ /* Test toggling a boolean action via activation with no parameter */
+ action = g_simple_action_new_stateful ("foo", NULL, g_variant_new_boolean (FALSE));
+ g_action_activate (G_ACTION (action), NULL);
+ state = g_action_get_state (G_ACTION (action));
+ g_assert (g_variant_get_boolean (state));
+ g_variant_unref (state);
+ /* and back again */
+ g_action_activate (G_ACTION (action), NULL);
+ state = g_action_get_state (G_ACTION (action));
+ g_assert (!g_variant_get_boolean (state));
+ g_variant_unref (state);
+ g_object_unref (action);
+}
+
static gboolean foo_activated = FALSE;
static gboolean bar_activated = FALSE;
g_simple_action_set_state (action, value);
}
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
static void
test_entries (void)
{
g_object_unref (actions);
}
+G_GNUC_END_IGNORE_DEPRECATIONS
+
static void
test_parse_detailed (void)
{
const gchar *expected_name;
const gchar *expected_target;
const gchar *expected_error;
+ const gchar *detailed_roundtrip;
} testcases[] = {
- { "abc", "abc", NULL, NULL },
- { " abc", NULL, NULL, "invalid format" },
- { " abc", NULL, NULL, "invalid format" },
- { "abc:", NULL, NULL, "invalid format" },
- { ":abc", NULL, NULL, "invalid format" },
- { "abc(", NULL, NULL, "invalid format" },
- { "abc)", NULL, NULL, "invalid format" },
- { "(abc", NULL, NULL, "invalid format" },
- { ")abc", NULL, NULL, "invalid format" },
- { "abc::xyz", "abc", "'xyz'", NULL },
- { "abc('xyz')", "abc", "'xyz'", NULL },
- { "abc(42)", "abc", "42", NULL },
- { "abc(int32 42)", "abc", "42", NULL },
- { "abc(@i 42)", "abc", "42", NULL },
- { "abc (42)", NULL, NULL, "invalid format" },
- { "abc(42abc)", NULL, NULL, "invalid character in number" },
- { "abc(42, 4)", "abc", "(42, 4)", "expected end of input" },
- { "abc(42,)", "abc", "(42,)", "expected end of input" }
+ { "abc", "abc", NULL, NULL, "abc" },
+ { " abc", NULL, NULL, "invalid format", NULL },
+ { " abc", NULL, NULL, "invalid format", NULL },
+ { "abc:", NULL, NULL, "invalid format", NULL },
+ { ":abc", NULL, NULL, "invalid format", NULL },
+ { "abc(", NULL, NULL, "invalid format", NULL },
+ { "abc)", NULL, NULL, "invalid format", NULL },
+ { "(abc", NULL, NULL, "invalid format", NULL },
+ { ")abc", NULL, NULL, "invalid format", NULL },
+ { "abc::xyz", "abc", "'xyz'", NULL, "abc::xyz" },
+ { "abc('xyz')", "abc", "'xyz'", NULL, "abc::xyz" },
+ { "abc(42)", "abc", "42", NULL, "abc(42)" },
+ { "abc(int32 42)", "abc", "42", NULL, "abc(42)" },
+ { "abc(@i 42)", "abc", "42", NULL, "abc(42)" },
+ { "abc (42)", NULL, NULL, "invalid format", NULL },
+ { "abc(42abc)", NULL, NULL, "invalid character in number", NULL },
+ { "abc(42, 4)", "abc", "(42, 4)", "expected end of input", NULL },
+ { "abc(42,)", "abc", "(42,)", "expected end of input", NULL }
};
gint i;
g_assert_cmpstr (name, ==, testcases[i].expected_name);
g_assert ((target == NULL) == (testcases[i].expected_target == NULL));
+
+ if (success)
+ {
+ gchar *detailed;
+
+ detailed = g_action_print_detailed_name (name, target);
+ g_assert_cmpstr (detailed, ==, testcases[i].detailed_roundtrip);
+ g_free (detailed);
+ }
+
if (target)
{
GVariant *expected;
return G_SOURCE_REMOVE;
}
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
static void
test_dbus_export (void)
{
session_bus_down ();
}
+G_GNUC_END_IGNORE_DEPRECATIONS
+
static void
test_bug679509 (void)
{
GPropertyAction *action;
GSocketClient *client;
GApplication *app;
+ gchar *name;
+ GVariantType *ptype, *stype;
+ gboolean enabled;
+ GVariant *state;
group = g_simple_action_group_new ();
g_signal_connect (group, "action-state-changed", G_CALLBACK (state_changed), NULL);
/* uint... */
action = g_property_action_new ("keepalive", app, "inactivity-timeout");
+ g_object_get (action, "name", &name, "parameter-type", &ptype, "enabled", &enabled, "state-type", &stype, "state", &state, NULL);
+ g_assert_cmpstr (name, ==, "keepalive");
+ g_assert (enabled);
+ g_free (name);
+ g_variant_unref (state);
+
g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action));
g_object_unref (action);
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/actions/basic", test_basic);
+ g_test_add_func ("/actions/name", test_name);
g_test_add_func ("/actions/simplegroup", test_simple_group);
g_test_add_func ("/actions/stateful", test_stateful);
+ g_test_add_func ("/actions/default-activate", test_default_activate);
g_test_add_func ("/actions/entries", test_entries);
g_test_add_func ("/actions/parse-detailed", test_parse_detailed);
g_test_add_func ("/actions/dbus/export", test_dbus_export);
g_test_add_func ("/actions/dbus/threaded", test_dbus_threaded);
+ g_test_add_func ("/actions/dbus/bug679509", test_bug679509);
g_test_add_func ("/actions/property", test_property_actions);
return g_test_run ();