[vlc-devel] [PATCH v3 3/14] tests: make use of config_GetTempPath()

Lyndon Brown jnqnfe at gmail.com
Wed Oct 14 04:52:37 CEST 2020


From: Lyndon Brown <jnqnfe at gmail.com>
Date: Tue, 6 Oct 2020 00:40:25 +0100
Subject: tests: make use of config_GetTempPath()

and thus work properly cross platform

diff --git a/test/modules/keystore/test.c b/test/modules/keystore/test.c
index 38e9ad9aab..1ca13cac54 100644
--- a/test/modules/keystore/test.c
+++ b/test/modules/keystore/test.c
@@ -30,6 +30,7 @@
 #include <vlc_modules.h>
 #include <vlc_interrupt.h>
 #include <vlc_fs.h>
+#include <vlc_configuration.h>
 #include <vlc_keystore.h>
 
 #undef NDEBUG
@@ -319,13 +320,19 @@ main(int i_argc, char *ppsz_argv[])
             int i_vlc_argc = 1;
             char *ppsz_vlc_argv[2] = { 0 };
             int i_tmp_fd = -1;
-            char psz_tmp_path[] = "/tmp/libvlc_XXXXXX";
+            char *psz_tmp_path = NULL;
 
             assert(asprintf(&ppsz_vlc_argv[0], "--keystore=%s,none",
                    psz_module) != -1);
 
             if (strcmp(psz_module, "file") == 0)
             {
+                char *psz_tmp_dir = config_GetTempPath();
+                assert(psz_tmp_dir != NULL);
+
+                assert(asprintf(&psz_tmp_path, "%s" DIR_SEP "libvlc_XXXXXX", psz_tmp_dir) >= 0);
+                free(psz_tmp_dir);
+
                 assert((i_tmp_fd = vlc_mkstemp(psz_tmp_path)) != -1);
                 printf("plaintext tmp file: '%s'\n", psz_tmp_path);
                 assert(asprintf(&ppsz_vlc_argv[1],
@@ -340,6 +347,7 @@ main(int i_argc, char *ppsz_argv[])
             {
                 vlc_close(i_tmp_fd);
                 unlink(psz_tmp_path);
+                free(psz_tmp_path);
             }
             free(ppsz_vlc_argv[0]);
             free(ppsz_vlc_argv[1]);
diff --git a/test/src/input/stream.c b/test/src/input/stream.c
index 3b7ef19fc5..2aac35530c 100644
--- a/test/src/input/stream.c
+++ b/test/src/input/stream.c
@@ -26,6 +26,7 @@
 #include <vlc_stream.h>
 #include <vlc_rand.h>
 #include <vlc_fs.h>
+#include <vlc_configuration.h>
 
 #include <inttypes.h>
 #include <limits.h>
@@ -368,13 +369,23 @@ main( void )
     test_init();
 
 #ifndef TEST_NET
-    char psz_tmp_path[] = "/tmp/libvlc_XXXXXX";
     char *psz_url;
     int i_tmp_fd;
 
     test_log( "Generating random file...\n" );
+
+    char *psz_tmp_dir = config_GetTempPath();
+    assert(psz_tmp_dir != NULL);
+
+    char *psz_tmp_path;
+    assert(asprintf(&psz_tmp_path, "%s" DIR_SEP "libvlc_XXXXXX", psz_tmp_dir) >= 0);
+    free(psz_tmp_dir);
+
     i_tmp_fd = vlc_mkstemp( psz_tmp_path );
+    assert(i_tmp_fd != -1);
+
     fill_rand( i_tmp_fd, RAND_FILE_SIZE );
+
     test_log( "Testing random file with libc, and stream...\n" );
     assert( i_tmp_fd != -1 );
     assert( asprintf( &psz_url, "file://%s", psz_tmp_path ) != -1 );
@@ -382,6 +393,8 @@ main( void )
     assert( ( pp_readers[0] = libc_open( psz_tmp_path ) ) );
     assert( ( pp_readers[1] = stream_open( psz_url ) ) );
 
+    free(psz_tmp_path);
+
     test( pp_readers, 2, NULL );
     for( unsigned int i = 0; i < 2; ++i )
         pp_readers[i]->pf_close( pp_readers[i] );
diff --git a/test/src/misc/keystore.c b/test/src/misc/keystore.c
index d510b5d1cf..f30b913616 100644
--- a/test/src/misc/keystore.c
+++ b/test/src/misc/keystore.c
@@ -33,6 +33,7 @@
 #include <vlc_dialog.h>
 #include <vlc_url.h>
 #include <vlc_fs.h>
+#include <vlc_configuration.h>
 
 #include <assert.h>
 
@@ -339,7 +340,14 @@ main(void)
     test_init();
 
     printf("creating tmp plaintext keystore file\n");
-    char psz_tmp_path[] = "/tmp/libvlc_XXXXXX";
+
+    char *psz_tmp_dir = config_GetTempPath();
+    assert(psz_tmp_dir != NULL);
+
+    char *psz_tmp_path;
+    assert(asprintf(&psz_tmp_path, "%s" DIR_SEP "libvlc_XXXXXX", psz_tmp_dir) >= 0);
+    free(psz_tmp_dir);
+
     int i_tmp_fd = -1;
     i_tmp_fd = vlc_mkstemp(psz_tmp_path);
     assert(i_tmp_fd != -1);
@@ -367,6 +375,7 @@ main(void)
 
     libvlc_release(p_libvlc);
     vlc_close(i_tmp_fd);
+    free(psz_tmp_path);
 
     return 0;
 }



More information about the vlc-devel mailing list