From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> Add a helper for getting line settings from line config that allows to shrink the test code a bit. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> --- tests/gpiod-test-helpers.h | 10 ++++++++++ tests/tests-line-config.c | 13 ++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/gpiod-test-helpers.h b/tests/gpiod-test-helpers.h index b40b820..fb3fd7d 100644 --- a/tests/gpiod-test-helpers.h +++ b/tests/gpiod-test-helpers.h @@ -126,6 +126,16 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_edge_event_buffer, gpiod_test_return_if_failed(); \ } while (0) +#define gpiod_test_line_config_get_line_settings_or_fail(_line_cfg, _offset) \ + ({ \ + struct gpiod_line_settings *_settings = \ + gpiod_line_config_get_line_settings(_line_cfg, \ + _offset); \ + g_assert_nonnull(_settings); \ + gpiod_test_return_if_failed(); \ + _settings; \ + }) + #define gpiod_test_create_request_config_or_fail() \ ({ \ struct gpiod_request_config *_config = \ diff --git a/tests/tests-line-config.c b/tests/tests-line-config.c index ef85c3a..7f5e4b1 100644 --- a/tests/tests-line-config.c +++ b/tests/tests-line-config.c @@ -46,9 +46,7 @@ GPIOD_TEST_CASE(get_line_settings) gpiod_test_line_config_add_line_settings_or_fail(config, offsets, 4, settings); - retrieved = gpiod_line_config_get_line_settings(config, 2); - g_assert_nonnull(retrieved); - gpiod_test_return_if_failed(); + retrieved = gpiod_test_line_config_get_line_settings_or_fail(config, 2); g_assert_cmpint(gpiod_line_settings_get_direction(settings), ==, GPIOD_LINE_DIRECTION_INPUT); @@ -146,9 +144,7 @@ GPIOD_TEST_CASE(null_settings) gpiod_test_line_config_add_line_settings_or_fail(config, offsets, 4, NULL); - settings = gpiod_line_config_get_line_settings(config, 2); - g_assert_nonnull(settings); - gpiod_test_return_if_failed(); + settings = gpiod_test_line_config_get_line_settings_or_fail(config, 2); g_assert_cmpint(gpiod_line_settings_get_drive(settings), ==, GPIOD_LINE_DIRECTION_AS_IS); @@ -171,9 +167,8 @@ GPIOD_TEST_CASE(reset_config) gpiod_test_line_config_add_line_settings_or_fail(config, offsets, 4, settings); - retrieved0 = gpiod_line_config_get_line_settings(config, 2); - g_assert_nonnull(retrieved0); - gpiod_test_return_if_failed(); + retrieved0 = gpiod_test_line_config_get_line_settings_or_fail(config, + 2); g_assert_cmpint(gpiod_line_settings_get_direction(retrieved0), ==, GPIOD_LINE_DIRECTION_INPUT); -- 2.37.2