tests: add more test cases for gpiod_line_config_set_output_values()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 15 Mar 2023 19:52:53 +0000 (20:52 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 15 Mar 2023 19:56:21 +0000 (20:56 +0100)
Add test cases that check proper sanitization of input arguments of
gpiod_line_config_set_output_values().

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tests/tests-line-config.c

index bbc423a8347e9f29ba48ea13e5eda8ffc7d08059..38bc00301789a31ceff561f9fc63adb822cbd5a5 100644 (file)
@@ -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);
+}