tests/stacking: Move string to gboolean conversion to a helper
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2748>
This commit is contained in:
parent
462c1115fe
commit
4727609d2b
@ -474,6 +474,25 @@ parse_window_size (MetaWindow *window,
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
str_to_bool (const char *str,
|
||||||
|
gboolean *val)
|
||||||
|
{
|
||||||
|
if (g_ascii_strcasecmp (str, "true") == 0) {
|
||||||
|
if (val != NULL)
|
||||||
|
*val = true;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_ascii_strcasecmp (str, "false") == 0) {
|
||||||
|
if (val != NULL)
|
||||||
|
*val = false;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
test_case_do (TestCase *test,
|
test_case_do (TestCase *test,
|
||||||
int argc,
|
int argc,
|
||||||
@ -560,9 +579,7 @@ test_case_do (TestCase *test,
|
|||||||
}
|
}
|
||||||
else if (strcmp (argv[0], "accept_focus") == 0)
|
else if (strcmp (argv[0], "accept_focus") == 0)
|
||||||
{
|
{
|
||||||
if (argc != 3 ||
|
if (argc != 3 || !str_to_bool (argv[2], NULL))
|
||||||
(g_ascii_strcasecmp (argv[2], "true") != 0 &&
|
|
||||||
g_ascii_strcasecmp (argv[2], "false") != 0))
|
|
||||||
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|
||||||
@ -579,9 +596,7 @@ test_case_do (TestCase *test,
|
|||||||
}
|
}
|
||||||
else if (strcmp (argv[0], "can_take_focus") == 0)
|
else if (strcmp (argv[0], "can_take_focus") == 0)
|
||||||
{
|
{
|
||||||
if (argc != 3 ||
|
if (argc != 3 || !str_to_bool (argv[2], NULL))
|
||||||
(g_ascii_strcasecmp (argv[2], "true") != 0 &&
|
|
||||||
g_ascii_strcasecmp (argv[2], "false") != 0))
|
|
||||||
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|
||||||
@ -598,9 +613,7 @@ test_case_do (TestCase *test,
|
|||||||
}
|
}
|
||||||
else if (strcmp (argv[0], "accept_take_focus") == 0)
|
else if (strcmp (argv[0], "accept_take_focus") == 0)
|
||||||
{
|
{
|
||||||
if (argc != 3 ||
|
if (argc != 3 || !str_to_bool (argv[2], NULL))
|
||||||
(g_ascii_strcasecmp (argv[2], "true") != 0 &&
|
|
||||||
g_ascii_strcasecmp (argv[2], "false") != 0))
|
|
||||||
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|
||||||
@ -1171,23 +1184,23 @@ test_case_do (TestCase *test,
|
|||||||
}
|
}
|
||||||
else if (strcmp (argv[0], "make_above") == 0)
|
else if (strcmp (argv[0], "make_above") == 0)
|
||||||
{
|
{
|
||||||
if (argc != 3 ||
|
MetaTestClient *client;
|
||||||
(g_ascii_strcasecmp (argv[2], "true") != 0 &&
|
const char *window_id;
|
||||||
g_ascii_strcasecmp (argv[2], "false") != 0))
|
MetaWindow *window;
|
||||||
|
gboolean make_above;
|
||||||
|
|
||||||
|
if (argc != 3 || !str_to_bool (argv[2], &make_above))
|
||||||
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|
||||||
MetaTestClient *client;
|
|
||||||
const char *window_id;
|
|
||||||
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
MetaWindow *window;
|
|
||||||
window = meta_test_client_find_window (client, window_id, error);
|
window = meta_test_client_find_window (client, window_id, error);
|
||||||
if (!window)
|
if (!window)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (g_ascii_strcasecmp (argv[2], "true") == 0)
|
if (make_above)
|
||||||
meta_window_make_above (window);
|
meta_window_make_above (window);
|
||||||
else
|
else
|
||||||
meta_window_unmake_above (window);
|
meta_window_unmake_above (window);
|
||||||
@ -1246,11 +1259,7 @@ test_case_do (TestCase *test,
|
|||||||
if (strcmp (argv[1], "raise-on-click") == 0)
|
if (strcmp (argv[1], "raise-on-click") == 0)
|
||||||
{
|
{
|
||||||
gboolean value;
|
gboolean value;
|
||||||
if (g_ascii_strcasecmp (argv[2], "true") == 0)
|
if (!str_to_bool (argv[2], &value))
|
||||||
value = TRUE;
|
|
||||||
else if (g_ascii_strcasecmp (argv[2], "false") == 0)
|
|
||||||
value = FALSE;
|
|
||||||
else
|
|
||||||
BAD_COMMAND("usage: %s %s [true|false]", argv[0], argv[1]);
|
BAD_COMMAND("usage: %s %s [true|false]", argv[0], argv[1]);
|
||||||
|
|
||||||
g_assert_true (g_settings_set_boolean (wm, "raise-on-click", value));
|
g_assert_true (g_settings_set_boolean (wm, "raise-on-click", value));
|
||||||
@ -1258,11 +1267,7 @@ test_case_do (TestCase *test,
|
|||||||
else if (strcmp (argv[1], "workspaces-only-on-primary") == 0)
|
else if (strcmp (argv[1], "workspaces-only-on-primary") == 0)
|
||||||
{
|
{
|
||||||
gboolean value;
|
gboolean value;
|
||||||
if (g_ascii_strcasecmp (argv[2], "true") == 0)
|
if (!str_to_bool (argv[2], &value))
|
||||||
value = TRUE;
|
|
||||||
else if (g_ascii_strcasecmp (argv[2], "false") == 0)
|
|
||||||
value = FALSE;
|
|
||||||
else
|
|
||||||
BAD_COMMAND("usage: %s %s [true|false]", argv[0], argv[1]);
|
BAD_COMMAND("usage: %s %s [true|false]", argv[0], argv[1]);
|
||||||
|
|
||||||
g_assert_true (g_settings_set_boolean (mutter, "workspaces-only-on-primary", value));
|
g_assert_true (g_settings_set_boolean (mutter, "workspaces-only-on-primary", value));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user