From a62c5fbc630ebca8b30735f1c38c08d17cf0aa51 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 27 Apr 2023 15:28:18 +0200 Subject: [PATCH] tests: move the test case for duplicate configured offsets This test case lives in tests-line-request.c but it doesn't really test request functionality but rather only the behavior of line-config. Limit it to only testing struct gpiod_line_config and move it to tests-line-config.c. Signed-off-by: Bartosz Golaszewski --- tests/tests-line-config.c | 23 +++++++++++++++++++++++ tests/tests-line-request.c | 28 ---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/tests/tests-line-config.c b/tests/tests-line-config.c index cf3e9d1..469500b 100644 --- a/tests/tests-line-config.c +++ b/tests/tests-line-config.c @@ -445,3 +445,26 @@ GPIOD_TEST_CASE(get_num_configured_offsets) g_assert_cmpuint(gpiod_line_config_get_num_configured_offsets(config), ==, 4); } + +GPIOD_TEST_CASE(handle_duplicate_offsets) +{ + static const guint offsets[] = { 0, 2, 2, 3 }; + + g_autoptr(struct_gpiod_line_config) config = NULL; + size_t num_retrieved; + guint retrieved[3]; + + config = gpiod_test_create_line_config_or_fail(); + + gpiod_test_line_config_add_line_settings_or_fail(config, offsets, 4, + NULL); + + g_assert_cmpuint(gpiod_line_config_get_num_configured_offsets(config), + ==, 3); + num_retrieved = gpiod_line_config_get_configured_offsets(config, + retrieved, 3); + g_assert_cmpuint(num_retrieved, ==, 3); + g_assert_cmpuint(retrieved[0], ==, 0); + g_assert_cmpuint(retrieved[1], ==, 2); + g_assert_cmpuint(retrieved[2], ==, 3); +} diff --git a/tests/tests-line-request.c b/tests/tests-line-request.c index 47ba986..0b985e2 100644 --- a/tests/tests-line-request.c +++ b/tests/tests-line-request.c @@ -39,34 +39,6 @@ GPIOD_TEST_CASE(request_fails_with_no_line_config) gpiod_test_expect_errno(EINVAL); } -GPIOD_TEST_CASE(request_fails_with_duplicate_offsets) -{ - static const guint offsets[] = { 0, 2, 2, 3 }; - - g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 4, NULL); - g_autoptr(struct_gpiod_chip) chip = NULL; - g_autoptr(struct_gpiod_line_config) line_cfg = NULL; - g_autoptr(struct_gpiod_line_request) request = NULL; - size_t num_requested_offsets; - guint requested_offsets[3]; - - chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); - line_cfg = gpiod_test_create_line_config_or_fail(); - - gpiod_test_line_config_add_line_settings_or_fail(line_cfg, offsets, 4, - NULL); - - request = gpiod_chip_request_lines(chip, NULL, line_cfg); - g_assert_nonnull(request); - num_requested_offsets = - gpiod_line_request_get_num_requested_lines(request); - g_assert_cmpuint(num_requested_offsets, ==, 3); - gpiod_line_request_get_requested_offsets(request, requested_offsets, 4); - g_assert_cmpuint(requested_offsets[0], ==, 0); - g_assert_cmpuint(requested_offsets[1], ==, 2); - g_assert_cmpuint(requested_offsets[2], ==, 3); -} - GPIOD_TEST_CASE(request_fails_with_offset_out_of_bounds) { static const guint offsets[] = { 2, 6 }; -- 2.30.2