[libgudev/wip/hadess/double-decimal-separator: 2/2] tests: Add test for ", " decimal separator locales
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgudev/wip/hadess/double-decimal-separator: 2/2] tests: Add test for ", " decimal separator locales
- Date: Fri, 13 Aug 2021 11:30:55 +0000 (UTC)
commit 83a36a29e75b819281a8f114232d711b25572add
Author: Bastien Nocera <hadess hadess net>
Date: Fri Aug 13 12:54:38 2021 +0200
tests: Add test for "," decimal separator locales
tests/meson.build | 4 ++++
tests/test-double.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 6995801..55fd09d 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -7,6 +7,10 @@ libgudev_tests = {
'dependencies': [gio_dep, umockdev_dep],
'environment': ['LD_PRELOAD=libumockdev-preload.so.0'],
},
+ 'test-double': {
+ 'dependencies': [gio_dep, umockdev_dep],
+ 'environment': ['LD_PRELOAD=libumockdev-preload.so.0', 'LC_NUMERIC=fr_FR.UTF-8'],
+ },
}
libgudev_tests_deps = [
diff --git a/tests/test-double.c b/tests/test-double.c
new file mode 100644
index 0000000..0092d8b
--- /dev/null
+++ b/tests/test-double.c
@@ -0,0 +1,63 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Red Hat Inc.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * Author: Bastien Nocera <hadess hadess net>
+ */
+
+#include <locale.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/wait.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <umockdev.h>
+#include <langinfo.h>
+
+#include <gudev/gudev.h>
+
+static void
+test_double (void)
+{
+ /* create test bed */
+ UMockdevTestbed *testbed = umockdev_testbed_new ();
+
+ /* Relies on a test bed having been set up */
+ g_assert (umockdev_in_mock_environment ());
+
+ g_assert_cmpstr (nl_langinfo(RADIXCHAR), ==, ",");
+
+ umockdev_testbed_add_device (testbed, "platform", "dev1", NULL,
+ "in_accel_scale", "0.0000098", NULL,
+ "ID_MODEL", "KoolGadget", "SCALE", "0.0000098", NULL);
+
+ /* Check the number of items in GUdevClient */
+ const gchar *subsystems[] = { "platform", NULL};
+ GUdevClient *client = g_udev_client_new (subsystems);
+ GUdevDevice *dev;
+ g_autofree char *path = NULL;
+ gdouble scale;
+
+ GList *devices = g_udev_client_query_by_subsystem (client, NULL);
+ g_assert_cmpint (g_list_length (devices), ==, 1);
+ dev = devices->data;
+
+ scale = g_udev_device_get_sysfs_attr_as_double (dev, "in_accel_scale");
+ g_assert_cmpfloat (scale, ==, 0.0000098);
+
+ scale = g_udev_device_get_property_as_double (dev, "SCALE");
+ g_assert_cmpfloat (scale, ==, 0.0000098);
+
+ g_list_free_full (devices, g_object_unref);
+}
+
+int main(int argc, char **argv)
+{
+ setlocale (LC_ALL, NULL);
+ setlocale (LC_NUMERIC, "fr_FR.UTF-8");
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/gudev/double", test_double);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]