[libgudev/benzea/fix-newline-stripping] tests: Move testbed creation into fixture
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgudev/benzea/fix-newline-stripping] tests: Move testbed creation into fixture
- Date: Tue, 31 May 2022 16:55:18 +0000 (UTC)
commit eac55b91a6a1e9bca1304aaf3fd48682edd69881
Author: Benjamin Berg <bberg redhat com>
Date: Tue May 31 18:00:15 2022 +0200
tests: Move testbed creation into fixture
No need to duplicate this between tests once we add more tests. Also, it
fixes the issue that the testbed was not free'ed resulting in the test
directory to not be deleted.
tests/test-double.c | 27 +++++++++++++++++++++------
tests/test-enumerator-filter.c | 31 +++++++++++++++++++++++--------
tests/test-sysfsattr.c | 27 +++++++++++++++++++++------
3 files changed, 65 insertions(+), 20 deletions(-)
---
diff --git a/tests/test-double.c b/tests/test-double.c
index 886fa02..91e77c9 100644
--- a/tests/test-double.c
+++ b/tests/test-double.c
@@ -18,18 +18,30 @@
#define GNU_SKIP_RETURNCODE 77
+typedef struct {
+ UMockdevTestbed *testbed;
+} Fixture;
+
static void
-test_double (void)
+fixture_setup (Fixture *f, G_GNUC_UNUSED const void *data)
{
- /* create test bed */
- UMockdevTestbed *testbed = umockdev_testbed_new ();
+ f->testbed = umockdev_testbed_new ();
- /* Relies on a test bed having been set up */
g_assert (umockdev_in_mock_environment ());
+}
+
+static void
+fixture_teardown (Fixture *f, G_GNUC_UNUSED const void *data)
+{
+ g_clear_object (&f->testbed);
+}
+static void
+test_double (Fixture *f, G_GNUC_UNUSED const void *data)
+{
g_assert_cmpstr (nl_langinfo(RADIXCHAR), ==, ",");
- umockdev_testbed_add_device (testbed, "platform", "dev1", NULL,
+ umockdev_testbed_add_device (f->testbed, "platform", "dev1", NULL,
"in_accel_scale", "0.0000098", NULL,
"ID_MODEL", "KoolGadget", "SCALE", "0.0000098", NULL);
@@ -63,7 +75,10 @@ int main(int argc, char **argv)
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/gudev/double", test_double);
+ g_test_add ("/gudev/double", Fixture, NULL,
+ fixture_setup,
+ test_double,
+ fixture_teardown);
return g_test_run ();
}
diff --git a/tests/test-enumerator-filter.c b/tests/test-enumerator-filter.c
index 6e9a073..0faf34f 100644
--- a/tests/test-enumerator-filter.c
+++ b/tests/test-enumerator-filter.c
@@ -20,25 +20,37 @@
#include <gudev/gudev.h>
+typedef struct {
+ UMockdevTestbed *testbed;
+} Fixture;
+
static void
-test_enumerator_filter (void)
+fixture_setup (Fixture *f, G_GNUC_UNUSED const void *data)
{
- /* create test bed */
- UMockdevTestbed *testbed = umockdev_testbed_new ();
+ f->testbed = umockdev_testbed_new ();
- /* Relies on a test bed having been set up */
g_assert (umockdev_in_mock_environment ());
+}
+
+static void
+fixture_teardown (Fixture *f, G_GNUC_UNUSED const void *data)
+{
+ g_clear_object (&f->testbed);
+}
+static void
+test_enumerator_filter (Fixture *f, G_GNUC_UNUSED const void *data)
+{
/* Add 2 devices in the USB subsystem, and one in the DRM subsystem */
- umockdev_testbed_add_device (testbed, "usb", "dev1", NULL,
+ umockdev_testbed_add_device (f->testbed, "usb", "dev1", NULL,
"idVendor", "0815", "idProduct", "AFFE", NULL,
"ID_MODEL", "KoolGadget", NULL);
- umockdev_testbed_add_device (testbed, "usb", "dev2", NULL,
+ umockdev_testbed_add_device (f->testbed, "usb", "dev2", NULL,
"idVendor", "0815", "idProduct", "AFFF", NULL,
"ID_MODEL", "KoolGadget 2", NULL);
- umockdev_testbed_add_device (testbed, "drm", "dev3", NULL,
+ umockdev_testbed_add_device (f->testbed, "drm", "dev3", NULL,
"ID_FOR_SEAT", "drm-pci-0000_00_02_0", NULL,
NULL);
@@ -66,7 +78,10 @@ int main(int argc, char **argv)
setlocale (LC_ALL, NULL);
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/gudev/enumerator_filter", test_enumerator_filter);
+ g_test_add ("/gudev/enumerator_filter", Fixture, NULL,
+ fixture_setup,
+ test_enumerator_filter,
+ fixture_teardown);
return g_test_run ();
}
diff --git a/tests/test-sysfsattr.c b/tests/test-sysfsattr.c
index 9c2f769..13f4a5b 100644
--- a/tests/test-sysfsattr.c
+++ b/tests/test-sysfsattr.c
@@ -15,16 +15,28 @@
#include <gudev/gudev.h>
+typedef struct {
+ UMockdevTestbed *testbed;
+} Fixture;
+
static void
-test_uncached_sysfs_attr (void)
+fixture_setup (Fixture *f, G_GNUC_UNUSED const void *data)
{
- /* create test bed */
- UMockdevTestbed *testbed = umockdev_testbed_new ();
+ f->testbed = umockdev_testbed_new ();
- /* Relies on a test bed having been set up */
g_assert (umockdev_in_mock_environment ());
+}
+
+static void
+fixture_teardown (Fixture *f, G_GNUC_UNUSED const void *data)
+{
+ g_clear_object (&f->testbed);
+}
- umockdev_testbed_add_device (testbed, "platform", "dev1", NULL,
+static void
+test_uncached_sysfs_attr (Fixture *f, G_GNUC_UNUSED const void *data)
+{
+ umockdev_testbed_add_device (f->testbed, "platform", "dev1", NULL,
"dytc_lapmode", "1", "console", "Y\n", NULL,
"ID_MODEL", "KoolGadget", NULL);
@@ -73,7 +85,10 @@ int main(int argc, char **argv)
setlocale (LC_ALL, NULL);
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/gudev/uncached_sysfs_attr", test_uncached_sysfs_attr);
+ g_test_add ("/gudev/uncached_sysfs_attr", Fixture, NULL,
+ fixture_setup,
+ test_uncached_sysfs_attr,
+ fixture_teardown);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]