Debian Codegraph @

bindings/glib/tests/helpers.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* SPDX-FileCopyrightText: 2022-2024 Bartosz Golaszewski <[email protected]> */
3
4 #ifndef __GPIODGLIB_TEST_HELPERS_H__
5 #define __GPIODGLIB_TEST_HELPERS_H__
6
7 #include <glib.h>
8 #include <gpiod-test-common.h>
9
10 #define gpiodglib_test_new_chip_or_fail(_path) \
11 ({ \
12 g_autoptr(GError) _err = NULL; \
13 GpiodglibChip *_chip = gpiodglib_chip_new(_path, &_err); \
14 g_assert_nonnull(_chip); \
15 g_assert_no_error(_err); \
16 gpiod_test_return_if_failed(); \
17 _chip; \
18 })
19
20 #define gpiodglib_test_chip_get_info_or_fail(_chip) \
21 ({ \
22 g_autoptr(GError) _err = NULL; \
23 GpiodglibChipInfo *_info = gpiodglib_chip_get_info(_chip, \
24 &_err); \
25 g_assert_nonnull(_info); \
26 g_assert_no_error(_err); \
27 gpiod_test_return_if_failed(); \
28 _info; \
29 })
30
31 #define gpiodglib_test_chip_get_line_info_or_fail(_chip, _offset) \
32 ({ \
33 g_autoptr(GError) _err = NULL; \
34 GpiodglibLineInfo *_info = \
35 gpiodglib_chip_get_line_info(_chip, _offset, &_err); \
36 g_assert_nonnull(_info); \
37 g_assert_no_error(_err); \
38 gpiod_test_return_if_failed(); \
39 _info; \
40 })
41
42 #define gpiodglib_test_chip_watch_line_info_or_fail(_chip, _offset) \
43 ({ \
44 g_autoptr(GError) _err = NULL; \
45 GpiodglibLineInfo *_info = \
46 gpiodglib_chip_watch_line_info(_chip, _offset, \
47 &_err); \
48 g_assert_nonnull(_info); \
49 g_assert_no_error(_err); \
50 gpiod_test_return_if_failed(); \
51 _info; \
52 })
53
54 #define gpiodglib_test_chip_unwatch_line_info_or_fail(_chip, _offset) \
55 do { \
56 g_autoptr(GError) _err = NULL; \
57 gboolean ret = gpiodglib_chip_unwatch_line_info(_chip, \
58 _offset, \
59 &_err); \
60 g_assert_true(ret); \
61 g_assert_no_error(_err); \
62 gpiod_test_return_if_failed(); \
63 } while (0)
64
65 #define gpiodglib_test_line_config_add_line_settings_or_fail(_config, \
66 _offsets, \
67 _settings) \
68 do { \
69 g_autoptr(GError) _err = NULL; \
70 gboolean _ret = \
71 gpiodglib_line_config_add_line_settings(_config, \
72 _offsets,\
73 _settings, \
74 &_err); \
75 g_assert_true(_ret); \
76 g_assert_no_error(_err); \
77 gpiod_test_return_if_failed(); \
78 } while (0)
79
80 #define gpiodglib_test_line_config_get_line_settings_or_fail(_config, \
81 _offset) \
82 ({ \
83 GpiodglibLineSettings *_settings = \
84 gpiodglib_line_config_get_line_settings(_config, \
85 _offset); \
86 g_assert_nonnull(_settings); \
87 gpiod_test_return_if_failed(); \
88 _settings; \
89 })
90
91 #define gpiodglib_test_line_config_set_output_values_or_fail(_config, \
92 _values) \
93 do { \
94 g_autoptr(GError) _err = NULL; \
95 gboolean _ret = \
96 gpiodglib_line_config_set_output_values(_config, \
97 _values, \
98 &_err); \
99 g_assert_true(_ret); \
100 g_assert_no_error(_err); \
101 gpiod_test_return_if_failed(); \
102 } while (0)
103
104 #define gpiodglib_test_chip_request_lines_or_fail(_chip, _req_cfg, _line_cfg) \
105 ({ \
106 g_autoptr(GError) _err = NULL; \
107 GpiodglibLineRequest *_req = \
108 gpiodglib_chip_request_lines(_chip, _req_cfg, \
109 _line_cfg, &_err); \
110 g_assert_nonnull(_req); \
111 g_assert_no_error(_err); \
112 gpiod_test_return_if_failed(); \
113 _req; \
114 })
115
116 #define gpiodglib_test_request_lines_or_fail(_path, _req_cfg, _line_cfg) \
117 ({ \
118 g_autoptr(GpiodglibChip) _chip = \
119 gpiodglib_test_new_chip_or_fail(_path); \
120 GpiodglibLineRequest *_req = \
121 gpiodglib_test_chip_request_lines_or_fail(_chip, \
122 _req_cfg, \
123 _line_cfg); \
124 _req; \
125 })
126
127 #define gpiodglib_test_check_error_or_fail(_err, _domain, _code) \
128 do { \
129 g_assert_nonnull(_err); \
130 gpiod_test_return_if_failed(); \
131 g_assert_cmpint(_domain, ==, (_err)->domain); \
132 g_assert_cmpint(_code, ==, (_err)->code); \
133 gpiod_test_return_if_failed(); \
134 } while (0)
135
136 GArray *gpiodglib_test_array_from_const(const gconstpointer data, gsize len,
137 gsize elem_size);
138
139 #endif /* __GPIODGLIB_TEST_HELPERS_H__ */
140