summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-05-31 18:54:44 +0200
committerBenjamin Berg <bberg@redhat.com>2022-06-01 15:28:28 +0200
commit881b84b1d8e915665f43f0d210b6b1b9ccb6c625 (patch)
treec6a149d80f5ba024348db338f1b2f47e284e4644
parent8ef0801aa3fad114fd32a91b83d869f5359a585c (diff)
downloadlibgudev-881b84b1d8e915665f43f0d210b6b1b9ccb6c625.tar.gz
tests: Add test for strv getting
Add a test for it, as it has a custom cache on top of udev.
-rw-r--r--tests/test-sysfsattr.c27
1 files changed, 27 insertions, 0 deletions
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 ();
}