summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-06-20 15:17:52 +0200
committerBenjamin Berg <bberg@redhat.com>2022-06-20 15:17:52 +0200
commited42a0c5da70a7e786b55b86bcbd0dc4017fc467 (patch)
treef0086bf4f7c1059c20e1be4792f9895bdcc49dcb /tests
parent51869ed6e6606ca1a1c200d518a83a5a609ac510 (diff)
downloadlibgudev-ed42a0c5da70a7e786b55b86bcbd0dc4017fc467.tar.gz
tests: Add a test for g_udev_device_get_tags
Diffstat (limited to 'tests')
-rw-r--r--tests/meson.build26
-rw-r--r--tests/test-gudevdevice.c55
2 files changed, 70 insertions, 11 deletions
diff --git a/tests/meson.build b/tests/meson.build
index 55fd09d..8c382ae 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,34 +1,38 @@
libgudev_tests = {
+ 'test-gudevdevice': {
+ 'dependencies': [gio_dep, libgudev_dep],
+ 'link_with': [libgudev],
+ 'sources': ['../gudev/gudevdevice.c'],
+ 'include_directories': [include_directories('../')],
+ },
'test-enumerator-filter': {
- 'dependencies': [gio_dep, umockdev_dep],
+ 'dependencies': [libgudev_dep, gio_dep, umockdev_dep],
'environment': ['LD_PRELOAD=libumockdev-preload.so.0'],
},
'test-sysfsattr': {
- 'dependencies': [gio_dep, umockdev_dep],
+ 'dependencies': [libgudev_dep, gio_dep, umockdev_dep],
'environment': ['LD_PRELOAD=libumockdev-preload.so.0'],
},
'test-double': {
- 'dependencies': [gio_dep, umockdev_dep],
+ 'dependencies': [libgudev_dep, gio_dep, umockdev_dep],
'environment': ['LD_PRELOAD=libumockdev-preload.so.0', 'LC_NUMERIC=fr_FR.UTF-8'],
},
}
-libgudev_tests_deps = [
- libgudev_dep,
-]
-
foreach test_name, test_extras: libgudev_tests
test_sources = ['@0@.c'.format(test_name)]
- test_deps = libgudev_tests_deps
- test_env = []
- test_deps += test_extras.get('dependencies', [])
- test_env += test_extras.get('environment', [])
+ test_sources += test_extras.get('sources', [])
+ test_deps = test_extras.get('dependencies', [])
+ test_env = test_extras.get('environment', [])
+ test_include = test_extras.get('include_directories', [])
test_exe = executable(
test_name,
test_sources,
dependencies: test_deps,
+ include_directories: test_include,
+ c_args: ['-D_GUDEV_COMPILATION']
)
test(
diff --git a/tests/test-gudevdevice.c b/tests/test-gudevdevice.c
new file mode 100644
index 0000000..a197c22
--- /dev/null
+++ b/tests/test-gudevdevice.c
@@ -0,0 +1,55 @@
+/*
+ * SPDX-FileCopyrightText: 2022 Red Hat Inc.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * Author: Benjamin Berg <bberg@redhat.com>
+ */
+
+#include <locale.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <libudev.h>
+#include "gudev/gudev.h"
+#include "gudev/gudevprivate.h"
+
+static void
+test_tags ()
+{
+ const char *expected_tags[] = { "tag1", "tag2", "tag3", NULL };
+ struct udev *udev = NULL;
+ struct udev_device *udev_device = NULL;
+ g_autoptr(GUdevDevice) dev = NULL;
+
+ /* Push device information into environment. */
+ g_setenv ("DEVPATH", "/devices/dev1", TRUE);
+ g_setenv ("SUBSYSTEM", "subsystem", TRUE);
+ g_setenv ("ACTION", "add", TRUE);
+ g_setenv ("SEQNUM", "1", TRUE);
+ g_setenv ("TAGS", "tag1:tag2:tag3", TRUE);
+ g_setenv ("CURRENT_TAGS", "tag2:tag3", TRUE);
+
+ udev = udev_new ();
+ udev_device = udev_device_new_from_environment (udev);
+ g_message ("error is: %d, %m", errno);
+ g_message ("tags list entry form udev device %p: %p", udev_device, udev_device_get_tags_list_entry (udev_device));
+
+ dev = _g_udev_device_new (udev_device);
+
+ g_assert_cmpstrv (expected_tags, g_udev_device_get_tags (dev));
+
+ g_clear_pointer (&udev, udev_unref);
+ g_clear_pointer (&udev_device, udev_device_unref);
+}
+
+int main(int argc, char **argv)
+{
+ setlocale (LC_ALL, NULL);
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/gudev/tags", test_tags);
+
+ return g_test_run ();
+}