diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index b0143d1cb..97c2d5050 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -429,22 +429,66 @@ test_case_check_xserver_stacking (TestCase *test, } static int -maybe_divide (const char *str, - int value) +maybe_multiply (const char *str, + int value, + const char **out_str) { - if (strstr (str, "/") == str) + *out_str = str; + + if (str[0] == '*') { - int divisor; + double multiplier; str += 1; - divisor = atoi (str); + multiplier = g_strtod (str, (char **) out_str); - value /= divisor; + value = round (multiplier * value); } return value; } +static int +maybe_divide (const char *str, + int value, + const char **out_str) +{ + *out_str = str; + + if (str[0] == '/') + { + double divider; + + str += 1; + divider = g_strtod (str, (char **) out_str); + + value = round (value / divider); + } + + return value; +} + +static int +maybe_do_math (const char *str, + int value, + const char **out_str) +{ + switch (str[0]) + { + case '*': + value = maybe_multiply (str, value, &str); + break; + case '/': + value = maybe_divide (str, value, &str); + break; + default: + *out_str = str; + return value; + } + + return maybe_do_math (str, value, out_str); +} + static int parse_window_size (MetaWindow *window, const char *size_str) @@ -462,13 +506,13 @@ parse_window_size (MetaWindow *window, { value = logical_monitor_layout.width; size_str += strlen ("MONITOR_WIDTH"); - value = maybe_divide (size_str, value); + value = maybe_do_math (size_str, value, &size_str); } else if (strstr (size_str, "MONITOR_HEIGHT") == size_str) { value = logical_monitor_layout.height; size_str += strlen ("MONITOR_HEIGHT"); - value = maybe_divide (size_str, value); + value = maybe_do_math (size_str, value, &size_str); } else {