| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef __GPIODBUS_TEST_INTERNAL_H__ |
| 5 |
#define __GPIODBUS_TEST_INTERNAL_H__ |
| 6 |
|
| 7 |
#include <gio/gio.h> |
| 8 |
#include <glib.h> |
| 9 |
#include <gpiodbus.h> |
| 10 |
#include <gpiosim-glib.h> |
| 11 |
|
| 12 |
#define __gpiodbus_test_check_gboolean_and_error(_ret, _err) \ |
| 13 |
do { \ |
| 14 |
g_assert_true(_ret); \ |
| 15 |
g_assert_no_error(_err); \ |
| 16 |
gpiod_test_return_if_failed(); \ |
| 17 |
} while (0) |
| 18 |
|
| 19 |
#define __gpiodbus_test_check_nonnull_and_error(_ptr, _err) \ |
| 20 |
do { \ |
| 21 |
g_assert_nonnull(_ptr); \ |
| 22 |
g_assert_no_error(_err); \ |
| 23 |
gpiod_test_return_if_failed(); \ |
| 24 |
} while (0) |
| 25 |
|
| 26 |
#define gpiodbus_test_get_chip_proxy_or_fail(_obj_path) \ |
| 27 |
({ \ |
| 28 |
g_autoptr(GDBusConnection) _con = NULL; \ |
| 29 |
g_autoptr(GError) _err = NULL; \ |
| 30 |
g_autoptr(GpiodbusChip) _chip = NULL; \ |
| 31 |
_con = gpiodbus_test_get_dbus_connection(); \ |
| 32 |
_chip = gpiodbus_chip_proxy_new_sync(_con, \ |
| 33 |
G_DBUS_PROXY_FLAGS_NONE, \ |
| 34 |
"io.gpiod1", _obj_path, \ |
| 35 |
NULL, &_err); \ |
| 36 |
__gpiodbus_test_check_nonnull_and_error(_chip, _err); \ |
| 37 |
g_object_ref(_chip); \ |
| 38 |
}) |
| 39 |
|
| 40 |
#define gpiodbus_test_get_line_proxy_or_fail(_obj_path) \ |
| 41 |
({ \ |
| 42 |
g_autoptr(GDBusConnection) _con = NULL; \ |
| 43 |
g_autoptr(GError) _err = NULL; \ |
| 44 |
g_autoptr(GpiodbusLine) _line = NULL; \ |
| 45 |
_con = gpiodbus_test_get_dbus_connection(); \ |
| 46 |
_line = gpiodbus_line_proxy_new_sync(_con, \ |
| 47 |
G_DBUS_PROXY_FLAGS_NONE, \ |
| 48 |
"io.gpiod1", _obj_path, \ |
| 49 |
NULL, &_err); \ |
| 50 |
__gpiodbus_test_check_nonnull_and_error(_line, _err); \ |
| 51 |
g_object_ref(_line); \ |
| 52 |
}) |
| 53 |
|
| 54 |
#define gpiodbus_test_get_request_proxy_or_fail(_obj_path) \ |
| 55 |
({ \ |
| 56 |
g_autoptr(GDBusConnection) _con = NULL; \ |
| 57 |
g_autoptr(GError) _err = NULL; \ |
| 58 |
g_autoptr(GpiodbusRequest) _req = NULL; \ |
| 59 |
_con = gpiodbus_test_get_dbus_connection(); \ |
| 60 |
_req = gpiodbus_request_proxy_new_sync(_con, \ |
| 61 |
G_DBUS_PROXY_FLAGS_NONE, \ |
| 62 |
"io.gpiod1", _obj_path, \ |
| 63 |
NULL, &_err); \ |
| 64 |
__gpiodbus_test_check_nonnull_and_error(_req, _err); \ |
| 65 |
g_object_ref(_req); \ |
| 66 |
}) |
| 67 |
|
| 68 |
#define gpiodbus_test_get_chip_object_manager_or_fail() \ |
| 69 |
({ \ |
| 70 |
g_autoptr(GDBusObjectManager) _manager = NULL; \ |
| 71 |
g_autoptr(GDBusConnection) _con = NULL; \ |
| 72 |
g_autoptr(GError) _err = NULL; \ |
| 73 |
_con = gpiodbus_test_get_dbus_connection(); \ |
| 74 |
_manager = gpiodbus_object_manager_client_new_sync( \ |
| 75 |
_con, \ |
| 76 |
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, \ |
| 77 |
"io.gpiod1", "/io/gpiod1/chips", NULL, \ |
| 78 |
&_err); \ |
| 79 |
__gpiodbus_test_check_nonnull_and_error(_manager, _err); \ |
| 80 |
g_object_ref(_manager); \ |
| 81 |
}) |
| 82 |
|
| 83 |
#define gpiodbus_test_chip_call_request_lines_sync_or_fail(_chip, \ |
| 84 |
_line_config, \ |
| 85 |
_request_config, \ |
| 86 |
_request_path) \ |
| 87 |
do { \ |
| 88 |
g_autoptr(GError) _err = NULL; \ |
| 89 |
gboolean _ret; \ |
| 90 |
_ret = gpiodbus_chip_call_request_lines_sync( \ |
| 91 |
_chip, _line_config, \ |
| 92 |
_request_config, \ |
| 93 |
G_DBUS_CALL_FLAGS_NONE, -1, \ |
| 94 |
_request_path, NULL, &_err); \ |
| 95 |
__gpiodbus_test_check_gboolean_and_error(_ret, _err); \ |
| 96 |
} while (0) |
| 97 |
|
| 98 |
#define gpiodbus_test_request_call_release_sync_or_fail(_request) \ |
| 99 |
do { \ |
| 100 |
g_autoptr(GError) _err = NULL; \ |
| 101 |
gboolean _ret; \ |
| 102 |
_ret = gpiodbus_request_call_release_sync( \ |
| 103 |
_request, \ |
| 104 |
G_DBUS_CALL_FLAGS_NONE, \ |
| 105 |
-1, NULL, &_err); \ |
| 106 |
__gpiodbus_test_check_gboolean_and_error(_ret, _err); \ |
| 107 |
} while (0) |
| 108 |
|
| 109 |
GDBusConnection *gpiodbus_test_get_dbus_connection(void); |
| 110 |
void gpiodbus_test_wait_for_sim_intf(GPIOSimChip *sim); |
| 111 |
GVariant *gpiodbus_test_make_empty_request_config(void); |
| 112 |
|
| 113 |
#endif |