diff options
author | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2023-02-27 10:33:36 +0100 |
---|---|---|
committer | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2023-03-03 15:04:32 +0100 |
commit | 19c6942f0cbf5ef6c0ec6b9be36d5c3feafc9658 (patch) | |
tree | a687c3618c5a749f7bd06754b03f57d29b4e9aa4 | |
parent | 06f9870df57e08c821d838db8e880d2dfac6ec17 (diff) | |
download | libgpiod-19c6942f0cbf5ef6c0ec6b9be36d5c3feafc9658.tar.gz |
tests: add a test-case for looking up non-standard GPIO line names
Make sure line names with whitespaces or some less common characters (that
can be found in real-life names in mainline .dts files) can be correctly
mapped to offsets.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rw-r--r-- | tests/tests-chip.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/tests-chip.c b/tests/tests-chip.c index a25663fa..815b4c70 100644 --- a/tests/tests-chip.c +++ b/tests/tests-chip.c @@ -155,6 +155,36 @@ GPIOD_TEST_CASE(find_line_duplicate) ==, 2); } +GPIOD_TEST_CASE(find_line_non_standard_names) +{ + static const GPIOSimLineName names[] = { + { .offset = 1, .name = "with whitespace", }, + { .offset = 2, .name = "[:-]chars", }, + { .offset = 3, .name = "l", }, + { .offset = 6, .name = "ALLCAPS", }, + { } + }; + + g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names); + g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 8, + "line-names", vnames, + NULL); + + g_autoptr(struct_gpiod_chip) chip = NULL; + + chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); + + g_assert_cmpint(gpiod_chip_get_line_offset_from_name(chip, + "with whitespace"), + ==, 1); + g_assert_cmpint(gpiod_chip_get_line_offset_from_name(chip, "[:-]chars"), + ==, 2); + g_assert_cmpint(gpiod_chip_get_line_offset_from_name(chip, "l"), + ==, 3); + g_assert_cmpint(gpiod_chip_get_line_offset_from_name(chip, "ALLCAPS"), + ==, 6); +} + GPIOD_TEST_CASE(find_line_null_name) { g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL); |