[PATCH libinput 1/7] test: add a test for safe_atoi
Hans de Goede
hdegoede at redhat.com
Mon Nov 28 14:36:36 UTC 2016
Hi,
On 28-11-16 06:20, Peter Hutterer wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Entire series looks good to me:
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
Regards,
Hans
> ---
> test/misc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
>
> diff --git a/test/misc.c b/test/misc.c
> index 4afd4d0..95776f7 100644
> --- a/test/misc.c
> +++ b/test/misc.c
> @@ -861,6 +861,47 @@ START_TEST(time_conversion)
> }
> END_TEST
>
> +struct atoi_test {
> + char *str;
> + bool success;
> + int val;
> +};
> +
> +START_TEST(safe_atoi_test)
> +{
> + struct atoi_test tests[] = {
> + { "10", true, 10 },
> + { "20", true, 20 },
> + { "-1", true, -1 },
> + { "2147483647", true, 2147483647 },
> + { "-2147483648", true, -2147483648 },
> + { "4294967295", false, 0 },
> + { "0x0", false, 0 },
> + { "-10x10", false, 0 },
> + { "1x-99", false, 0 },
> + { "", false, 0 },
> + { "abd", false, 0 },
> + { "xabd", false, 0 },
> + { "0xaf", false, 0 },
> + { "0x0x", false, 0 },
> + { "x10", false, 0 },
> + { NULL, false, 0 }
> + };
> + int v;
> + bool success;
> +
> + for (int i = 0; tests[i].str != NULL; i++) {
> + v = 0xad;
> + success = safe_atoi(tests[i].str, &v);
> + ck_assert(success == tests[i].success);
> + if (success)
> + ck_assert_int_eq(v, tests[i].val);
> + else
> + ck_assert_int_eq(v, 0xad);
> + }
> +}
> +END_TEST
> +
> static int open_restricted_leak(const char *path, int flags, void *data)
> {
> return *(int*)data;
> @@ -988,6 +1029,7 @@ litest_setup_tests_misc(void)
> litest_add_no_device("misc:parser", wheel_click_count_parser);
> litest_add_no_device("misc:parser", trackpoint_accel_parser);
> litest_add_no_device("misc:parser", dimension_prop_parser);
> + litest_add_no_device("misc:parser", safe_atoi_test);
> litest_add_no_device("misc:time", time_conversion);
>
> litest_add_no_device("misc:fd", fd_no_event_leak);
>
More information about the wayland-devel
mailing list