tests: add a helper for reading back line settings from line config
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 12 Jan 2023 18:16:38 +0000 (19:16 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 18 Jan 2023 15:17:18 +0000 (16:17 +0100)
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@linaro.org>
tests/gpiod-test-helpers.h
tests/tests-line-config.c

index b40b820b767c80ac6b6efb2fde3ce2738f1b087f..fb3fd7daf98bf2c2f68100582ed0354a41f6b45b 100644 (file)
@@ -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 = \
index ed348c8079b23763ac872d35963cbe0771a9aac2..230581012fbcc8d5ef71e76143b1ac1fafd477ba 100644 (file)
@@ -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);