tests: add a test-case for looking up non-standard GPIO line names
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 27 Feb 2023 09:33:36 +0000 (10:33 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 3 Mar 2023 14:04:32 +0000 (15:04 +0100)
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>
tests/tests-chip.c

index a25663fa4fe033ddb1ab169eb8ddc67093cb2664..815b4c70847b4476f7d8898baaa2b7e718102f83 100644 (file)
@@ -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);