From: Bartosz Golaszewski Date: Wed, 15 Mar 2023 19:52:53 +0000 (+0100) Subject: tests: add more test cases for gpiod_line_config_set_output_values() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b9851e07c2d711e5332aad14653c2fdcd2eda7fd;p=qemu-gpiodev%2Flibgpiod.git tests: add more test cases for gpiod_line_config_set_output_values() Add test cases that check proper sanitization of input arguments of gpiod_line_config_set_output_values(). Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/tests-line-config.c b/tests/tests-line-config.c index bbc423a..38bc003 100644 --- a/tests/tests-line-config.c +++ b/tests/tests-line-config.c @@ -365,3 +365,46 @@ GPIOD_TEST_CASE(set_output_values_invalid_value) ==, -1); gpiod_test_expect_errno(EINVAL); } + +GPIOD_TEST_CASE(set_output_values_bad_args) +{ + static const enum gpiod_line_value values[] = { + GPIOD_LINE_VALUE_ACTIVE, + GPIOD_LINE_VALUE_INACTIVE, + GPIOD_LINE_VALUE_ACTIVE, + GPIOD_LINE_VALUE_INACTIVE, + }; + + g_autoptr(struct_gpiod_line_config) config = NULL; + gint ret; + + config = gpiod_test_create_line_config_or_fail(); + + ret = gpiod_line_config_set_output_values(config, NULL, 4); + g_assert_cmpint(ret, ==, -1); + gpiod_test_expect_errno(EINVAL); + + ret = gpiod_line_config_set_output_values(config, values, 0); + g_assert_cmpint(ret, ==, -1); + gpiod_test_expect_errno(EINVAL); +} + +GPIOD_TEST_CASE(set_output_values_too_many_values) +{ + static const gsize num_values = 65; + + g_autoptr(struct_gpiod_line_config) config = NULL; + g_autofree enum gpiod_line_value *values = NULL; + gint ret; + gsize i; + + config = gpiod_test_create_line_config_or_fail(); + values = g_malloc0(sizeof(*values) * num_values); + + for (i = 0; i < num_values; i++) + values[i] = GPIOD_LINE_VALUE_ACTIVE; + + ret = gpiod_line_config_set_output_values(config, values, num_values); + g_assert_cmpint(ret, ==, -1); + gpiod_test_expect_errno(EINVAL); +}