From 881b84b1d8e915665f43f0d210b6b1b9ccb6c625 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 31 May 2022 18:54:44 +0200 Subject: tests: Add test for strv getting Add a test for it, as it has a custom cache on top of udev. --- tests/test-sysfsattr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test-sysfsattr.c b/tests/test-sysfsattr.c index dbca3ed..f6eab00 100644 --- a/tests/test-sysfsattr.c +++ b/tests/test-sysfsattr.c @@ -112,6 +112,28 @@ test_sysfs_attr_keys (Fixture *f, G_GNUC_UNUSED const void *data) g_assert_cmpstrv (g_udev_device_get_sysfs_attr_keys (dev), expected); } +static void +test_sysfs_attr_as_strv (Fixture *f, G_GNUC_UNUSED const void *data) +{ + const char *expected[] = { "1", "2", "3", "4", "5", "6", NULL }; + const char *empty[] = { NULL }; + g_autoptr(GUdevDevice) dev = NULL; + + dev = create_single_dev (f, "P: /devices/dev1\n" + "E: SUBSYSTEM=platform\n" + "A: test=1\\n2 3\\r4\\t5 \\t\\n6\n" + "E: ID_MODEL=KoolGadget"); + + /* Reading gives the expected result, even after updating the file */ + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv (dev, "test"), expected); + write_sysfs_attr (dev, "test", "\n"); + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv (dev, "test"), expected); + + /* _uncached variant gets the new content and updates the cache */ + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv_uncached (dev, "test"), empty); + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv (dev, "test"), empty); +} + int main(int argc, char **argv) { setlocale (LC_ALL, NULL); @@ -127,5 +149,10 @@ int main(int argc, char **argv) test_sysfs_attr_keys, fixture_teardown); + g_test_add ("/gudev/sysfs_attr_as_strv", Fixture, NULL, + fixture_setup, + test_sysfs_attr_as_strv, + fixture_teardown); + return g_test_run (); } -- cgit v1.2.1