| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <glib.h> |
| 5 |
#include <gpiod-glib.h> |
| 6 |
#include <gpiod-test.h> |
| 7 |
#include <gpiod-test-common.h> |
| 8 |
#include <gpiosim-glib.h> |
| 9 |
|
| 10 |
#define GPIOD_TEST_GROUP "glib/misc" |
| 11 |
|
| 12 |
GPIOD_TEST_CASE(is_gpiochip_bad) |
| 13 |
{ |
| 14 |
g_assert_false(gpiodglib_is_gpiochip_device("/dev/null")); |
| 15 |
g_assert_false(gpiodglib_is_gpiochip_device("/dev/nonexistent")); |
| 16 |
} |
| 17 |
|
| 18 |
GPIOD_TEST_CASE(is_gpiochip_good) |
| 19 |
{ |
| 20 |
g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL); |
| 21 |
|
| 22 |
g_assert_true(gpiodglib_is_gpiochip_device( |
| 23 |
g_gpiosim_chip_get_dev_path(sim))); |
| 24 |
} |
| 25 |
|
| 26 |
GPIOD_TEST_CASE(is_gpiochip_link_bad) |
| 27 |
{ |
| 28 |
g_autofree gchar *link = NULL; |
| 29 |
gint ret; |
| 30 |
|
| 31 |
link = g_strdup_printf("/tmp/gpiod-test-link.%u", getpid()); |
| 32 |
ret = symlink("/dev/null", link); |
| 33 |
g_assert_cmpint(ret, ==, 0); |
| 34 |
gpiod_test_return_if_failed(); |
| 35 |
|
| 36 |
g_assert_false(gpiodglib_is_gpiochip_device(link)); |
| 37 |
ret = unlink(link); |
| 38 |
g_assert_cmpint(ret, ==, 0); |
| 39 |
} |
| 40 |
|
| 41 |
GPIOD_TEST_CASE(is_gpiochip_link_good) |
| 42 |
{ |
| 43 |
g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL); |
| 44 |
g_autofree gchar *link = NULL; |
| 45 |
gint ret; |
| 46 |
|
| 47 |
link = g_strdup_printf("/tmp/gpiod-test-link.%u", getpid()); |
| 48 |
ret = symlink(g_gpiosim_chip_get_dev_path(sim), link); |
| 49 |
g_assert_cmpint(ret, ==, 0); |
| 50 |
gpiod_test_return_if_failed(); |
| 51 |
|
| 52 |
g_assert_true(gpiodglib_is_gpiochip_device(link)); |
| 53 |
ret = unlink(link); |
| 54 |
g_assert_cmpint(ret, ==, 0); |
| 55 |
} |
| 56 |
|
| 57 |
GPIOD_TEST_CASE(version_string) |
| 58 |
{ |
| 59 |
static const gchar *const pattern = "^\\d+\\.\\d+(\\.\\d+|\\-devel|\\-rc\\d+)?$"; |
| 60 |
|
| 61 |
g_autoptr(GError) err = NULL; |
| 62 |
g_autoptr(GRegex) regex = NULL; |
| 63 |
g_autoptr(GMatchInfo) match = NULL; |
| 64 |
g_autofree gchar *res = NULL; |
| 65 |
const gchar *ver; |
| 66 |
gboolean ret; |
| 67 |
|
| 68 |
ver = gpiodglib_api_version(); |
| 69 |
g_assert_nonnull(ver); |
| 70 |
gpiod_test_return_if_failed(); |
| 71 |
|
| 72 |
regex = g_regex_new(pattern, 0, 0, &err); |
| 73 |
g_assert_nonnull(regex); |
| 74 |
g_assert_no_error(err); |
| 75 |
gpiod_test_return_if_failed(); |
| 76 |
|
| 77 |
ret = g_regex_match(regex, ver, 0, &match); |
| 78 |
g_assert_true(ret); |
| 79 |
gpiod_test_return_if_failed(); |
| 80 |
|
| 81 |
g_assert_true(g_match_info_matches(match)); |
| 82 |
res = g_match_info_fetch(match, 0); |
| 83 |
g_assert_nonnull(res); |
| 84 |
g_assert_cmpstr(res, ==, ver); |
| 85 |
g_match_info_next(match, &err); |
| 86 |
g_assert_no_error(err); |
| 87 |
g_assert_false(g_match_info_matches(match)); |
| 88 |
} |