]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
tests/loopback: do not hardcode /tmp for !unix
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 17 Mar 2022 13:12:41 +0000 (17:12 +0400)
committerSimon McVittie <smcv@collabora.com>
Fri, 15 Jul 2022 15:26:54 +0000 (16:26 +0100)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
test/loopback.c

index b1746803149122f1e37e50905a7eb6568df238ee..e1b76b09e519149b2387d1e67b7c84291e54ec24 100644 (file)
@@ -166,7 +166,9 @@ setup_no_runtime (Fixture *f,
   g_test_message ("listening at %s", listening_at);
   /* we have fallen back to something in /tmp, either abstract or not */
   g_assert (g_str_has_prefix (listening_at, "unix:"));
+#ifdef DBUS_UNIX
   g_assert (strstr (listening_at, "=/tmp" DBUS_DIR_SEPARATOR_S) != NULL);
+#endif
 
   dbus_free (listening_at);
 }
@@ -222,7 +224,7 @@ test_connect (Fixture *f,
                        !=, NULL);
     }
 #ifdef DBUS_UNIX
-  else if (g_strcmp0 (listening_address, "unix:tmpdir=/tmp") == 0)
+  else if (g_str_has_prefix (listening_address, "unix:tmpdir="))
     {
       g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
 
@@ -241,20 +243,24 @@ test_connect (Fixture *f,
                                                            "path");
 
           g_assert_nonnull (path);
+#ifdef DBUS_UNIX
           g_assert_true (g_str_has_prefix (path, "/tmp" DBUS_DIR_SEPARATOR_S "dbus-"));
+#endif
         }
     }
-  else if (g_strcmp0 (listening_address, "unix:dir=/tmp") == 0)
+  else if (g_str_has_prefix (listening_address, "unix:dir="))
     {
       const char *path = dbus_address_entry_get_value (entries[0],
                                                        "path");
 
       g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
       g_assert_nonnull (path);
+#ifdef DBUS_UNIX
       g_assert_true (g_str_has_prefix (path, "/tmp" DBUS_DIR_SEPARATOR_S "dbus-"));
+#endif
     }
-  else if (g_strcmp0 (listening_address,
-                      "unix:runtime=yes;unix:tmpdir=/tmp") == 0)
+  else if (g_str_has_prefix (listening_address,
+                             "unix:runtime=yes;unix:tmpdir="))
     {
       g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
       /* No particular statement about the path here: for that see
@@ -486,6 +492,14 @@ main (int argc,
     char **argv)
 {
   int ret;
+#ifdef DBUS_UNIX
+  char *tmp = _dbus_strdup ("/tmp");
+#else
+  char *tmp = dbus_address_escape_value (g_get_tmp_dir ());
+#endif
+  gchar *unix_tmpdir = g_strdup_printf ("unix:tmpdir=%s", tmp);
+  gchar *unix_dir = g_strdup_printf ("unix:dir=%s", tmp);
+  gchar *unix_runtime_or_fallback = g_strdup_printf ("unix:runtime=yes;%s", unix_tmpdir);
 
   test_init (&argc, &argv);
 
@@ -503,27 +517,32 @@ main (int argc,
       test_bad_guid, teardown);
 
 #ifdef DBUS_UNIX
-  g_test_add ("/connect/unix/tmpdir", Fixture, "unix:tmpdir=/tmp", setup,
+  g_test_add ("/connect/unix/tmpdir", Fixture, unix_tmpdir, setup,
       test_connect, teardown);
-  g_test_add ("/message/unix/tmpdir", Fixture, "unix:tmpdir=/tmp", setup,
+  g_test_add ("/message/unix/tmpdir", Fixture, unix_tmpdir, setup,
       test_message, teardown);
-  g_test_add ("/connect/unix/dir", Fixture, "unix:dir=/tmp", setup,
+  g_test_add ("/connect/unix/dir", Fixture, unix_dir, setup,
       test_connect, teardown);
-  g_test_add ("/message/unix/dir", Fixture, "unix:dir=/tmp", setup,
+  g_test_add ("/message/unix/dir", Fixture, unix_dir, setup,
       test_message, teardown);
 
   g_test_add ("/connect/unix/runtime", Fixture,
-      "unix:runtime=yes;unix:tmpdir=/tmp", setup_runtime, test_connect,
+      unix_runtime_or_fallback, setup_runtime, test_connect,
       teardown_runtime);
   g_test_add ("/connect/unix/no-runtime", Fixture,
-      "unix:runtime=yes;unix:tmpdir=/tmp", setup_no_runtime, test_connect,
+      unix_runtime_or_fallback, setup_no_runtime, test_connect,
       teardown_no_runtime);
 
-  g_test_add ("/message/bad-guid/unix", Fixture, "unix:tmpdir=/tmp", setup,
+  g_test_add ("/message/bad-guid/unix", Fixture, unix_tmpdir, setup,
       test_bad_guid, teardown);
 #endif
 
   ret = g_test_run ();
   dbus_shutdown ();
+
+  g_free (unix_tmpdir);
+  g_free (unix_dir);
+  g_free (unix_runtime_or_fallback);
+  dbus_free (tmp);
   return ret;
 }