mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-30 13:53:30 +02:00
Merge branch 'test-path-fixes' into 'main'
tests: Various fixes to create temporary files in /tmp rather than the build directory See merge request GNOME/glib!4561
This commit is contained in:
@@ -4232,13 +4232,17 @@ g_file_move_finish (GFile *file,
|
||||
* %NULL to ignore
|
||||
* @error: a #GError, or %NULL
|
||||
*
|
||||
* Creates a directory. Note that this will only create a child directory
|
||||
* Creates a directory.
|
||||
*
|
||||
* Note that this will only create a child directory
|
||||
* of the immediate parent directory of the path or URI given by the #GFile.
|
||||
* To recursively create directories, see g_file_make_directory_with_parents().
|
||||
*
|
||||
* This function will fail if the parent directory does not exist, setting
|
||||
* @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support
|
||||
* creating directories, this function will fail, setting @error to
|
||||
* %G_IO_ERROR_NOT_SUPPORTED.
|
||||
* %G_IO_ERROR_NOT_SUPPORTED. If the directory already exists,
|
||||
* [error@Gio.IOErrorEnum.EXISTS] will be returned.
|
||||
*
|
||||
* For a local #GFile the newly created directory will have the default
|
||||
* (current) ownership and permissions of the current process.
|
||||
|
@@ -2843,7 +2843,7 @@ test_measure_async (void)
|
||||
static void
|
||||
test_load_bytes (void)
|
||||
{
|
||||
gchar filename[] = "g_file_load_bytes_XXXXXX";
|
||||
char *filename = NULL;
|
||||
GError *error = NULL;
|
||||
GBytes *bytes;
|
||||
GFile *file;
|
||||
@@ -2851,6 +2851,7 @@ test_load_bytes (void)
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
filename = g_build_filename (g_get_tmp_dir (), "g_file_load_bytes_XXXXXX", NULL);
|
||||
fd = g_mkstemp (filename);
|
||||
g_assert_cmpint (fd, !=, -1);
|
||||
len = strlen ("test_load_bytes");
|
||||
@@ -2870,6 +2871,7 @@ test_load_bytes (void)
|
||||
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (file);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
@@ -2899,12 +2901,13 @@ static void
|
||||
test_load_bytes_async (void)
|
||||
{
|
||||
LoadBytesAsyncData data = { 0 };
|
||||
gchar filename[] = "g_file_load_bytes_XXXXXX";
|
||||
char *filename = NULL;
|
||||
GError *error = NULL;
|
||||
int len;
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
filename = g_build_filename (g_get_tmp_dir (), "g_file_load_bytes_XXXXXX", NULL);
|
||||
fd = g_mkstemp (filename);
|
||||
g_assert_cmpint (fd, !=, -1);
|
||||
len = strlen ("test_load_bytes_async");
|
||||
@@ -2926,6 +2929,7 @@ test_load_bytes_async (void)
|
||||
g_object_unref (data.file);
|
||||
g_bytes_unref (data.bytes);
|
||||
g_main_loop_unref (data.main_loop);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
#if GLIB_SIZEOF_SIZE_T > 4
|
||||
@@ -2987,15 +2991,19 @@ check_testfile_4gb_contents (const char *data,
|
||||
static void
|
||||
test_load_contents_4gb (void)
|
||||
{
|
||||
char filename[] = "g_file_load_contents_4gb_XXXXXX";
|
||||
char *filename = NULL;
|
||||
GError *error = NULL;
|
||||
gboolean result;
|
||||
char *data;
|
||||
gsize len;
|
||||
GFile *file;
|
||||
|
||||
filename = g_build_filename (g_get_tmp_dir (), "g_file_load_contents_4gb_XXXXXX", NULL);
|
||||
if (!create_testfile_4gb_or_skip (filename))
|
||||
return;
|
||||
{
|
||||
g_free (filename);
|
||||
return;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (filename);
|
||||
result = g_file_load_contents (file, NULL, &data, &len, NULL, &error);
|
||||
@@ -3008,6 +3016,7 @@ test_load_contents_4gb (void)
|
||||
|
||||
g_free (data);
|
||||
g_object_unref (file);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -3026,7 +3035,7 @@ load_contents_4gb_cb (GObject *object,
|
||||
static void
|
||||
test_load_contents_4gb_async (void)
|
||||
{
|
||||
char filename[] = "g_file_load_contents_4gb_async_XXXXXX";
|
||||
char *filename = NULL;
|
||||
GFile *file;
|
||||
GAsyncResult *async_result = NULL;
|
||||
GError *error = NULL;
|
||||
@@ -3034,8 +3043,12 @@ test_load_contents_4gb_async (void)
|
||||
gsize len;
|
||||
gboolean ret;
|
||||
|
||||
filename = g_build_filename (g_get_tmp_dir (), "g_file_load_contents_4gb_async_XXXXXX", NULL);
|
||||
if (!create_testfile_4gb_or_skip (filename))
|
||||
return;
|
||||
{
|
||||
g_free (filename);
|
||||
return;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (filename);
|
||||
g_file_load_contents_async (file, NULL, load_contents_4gb_cb, &async_result);
|
||||
@@ -3054,18 +3067,23 @@ test_load_contents_4gb_async (void)
|
||||
g_free (data);
|
||||
g_object_unref (async_result);
|
||||
g_object_unref (file);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static void
|
||||
test_load_bytes_4gb (void)
|
||||
{
|
||||
char filename[] = "g_file_load_bytes_4gb_XXXXXX";
|
||||
char *filename = NULL;
|
||||
GError *error = NULL;
|
||||
GBytes *bytes;
|
||||
GFile *file;
|
||||
|
||||
filename = g_build_filename (g_get_tmp_dir (), "g_file_load_bytes_4gb_XXXXXX", NULL);
|
||||
if (!create_testfile_4gb_or_skip (filename))
|
||||
return;
|
||||
{
|
||||
g_free (filename);
|
||||
return;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (filename);
|
||||
bytes = g_file_load_bytes (file, NULL, NULL, &error);
|
||||
@@ -3078,6 +3096,7 @@ test_load_bytes_4gb (void)
|
||||
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (file);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -96,7 +96,8 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
GFile *mounted_file;
|
||||
GUnixMountMonitor *mount_monitor = NULL;
|
||||
gchar *bindfs, *fusermount;
|
||||
gchar *curdir, *dir_to_mount, *dir_mountpoint;
|
||||
const char *curdir;
|
||||
char *dir_to_mount = NULL, *dir_mountpoint = NULL;
|
||||
gchar *file_in_mount, *file_in_mountpoint;
|
||||
GError *error = NULL;
|
||||
|
||||
@@ -127,10 +128,10 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
return;
|
||||
}
|
||||
|
||||
curdir = g_get_current_dir ();
|
||||
dir_to_mount = g_strdup_printf ("%s/dir_bindfs_to_mount", curdir);
|
||||
file_in_mount = g_strdup_printf ("%s/example.txt", dir_to_mount);
|
||||
dir_mountpoint = g_strdup_printf ("%s/dir_bindfs_mountpoint", curdir);
|
||||
curdir = g_get_tmp_dir ();
|
||||
dir_to_mount = g_build_filename (curdir, "dir_bindfs_to_mount", NULL);
|
||||
file_in_mount = g_build_filename (dir_to_mount, "example.txt", NULL);
|
||||
dir_mountpoint = g_build_filename (curdir, "dir_bindfs_mountpoint", NULL);
|
||||
|
||||
g_mkdir (dir_to_mount, 0777);
|
||||
g_mkdir (dir_mountpoint, 0777);
|
||||
@@ -141,7 +142,6 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
g_free (dir_mountpoint);
|
||||
g_free (file_in_mount);
|
||||
g_free (dir_to_mount);
|
||||
g_free (curdir);
|
||||
g_free (fusermount);
|
||||
g_free (bindfs);
|
||||
return;
|
||||
@@ -164,7 +164,6 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
g_free (dir_mountpoint);
|
||||
g_free (file_in_mount);
|
||||
g_free (dir_to_mount);
|
||||
g_free (curdir);
|
||||
g_free (fusermount);
|
||||
g_free (bindfs);
|
||||
|
||||
@@ -172,7 +171,7 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
}
|
||||
|
||||
/* Let's check now, that the file is in indeed in a readonly filesystem */
|
||||
file_in_mountpoint = g_strdup_printf ("%s/example.txt", dir_mountpoint);
|
||||
file_in_mountpoint = g_build_filename (dir_mountpoint, "example.txt", NULL);
|
||||
mounted_file = g_file_new_for_path (file_in_mountpoint);
|
||||
|
||||
if (with_mount_monitor)
|
||||
@@ -197,7 +196,6 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
g_free (dir_mountpoint);
|
||||
g_free (file_in_mount);
|
||||
g_free (dir_to_mount);
|
||||
g_free (curdir);
|
||||
g_free (fusermount);
|
||||
g_free (bindfs);
|
||||
|
||||
@@ -241,7 +239,6 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
|
||||
g_free (bindfs);
|
||||
g_free (fusermount);
|
||||
g_free (curdir);
|
||||
g_free (dir_to_mount);
|
||||
g_free (dir_mountpoint);
|
||||
g_free (file_in_mount);
|
||||
@@ -254,7 +251,7 @@ main (int argc, char *argv[])
|
||||
/* To avoid unnecessary D-Bus calls, see http://goo.gl/ir56j2 */
|
||||
g_setenv ("GIO_USE_VFS", "local", FALSE);
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
|
||||
g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=787731");
|
||||
|
||||
|
@@ -3289,7 +3289,7 @@ main (int argc, char *argv[])
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
|
||||
if (!g_test_subprocess ())
|
||||
{
|
||||
|
@@ -32,8 +32,6 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define DEFAULT_TEST_DIR "testdir_live-g-file"
|
||||
|
||||
#define PATTERN_FILE_SIZE 0x10000
|
||||
#define TEST_HANDLE_SPECIAL TRUE
|
||||
|
||||
@@ -1342,9 +1340,10 @@ int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
static gboolean only_create_struct;
|
||||
const char *target_path;
|
||||
char *target_path = NULL;
|
||||
GError *error;
|
||||
GOptionContext *context;
|
||||
int retval;
|
||||
|
||||
static GOptionEntry cmd_entries[] = {
|
||||
{"read-write", 'w', 0, G_OPTION_ARG_NONE, &write_test,
|
||||
@@ -1365,7 +1364,7 @@ main (int argc, char *argv[])
|
||||
posix_compat = FALSE;
|
||||
|
||||
/* strip all gtester-specific args */
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
|
||||
/* no extra parameters specified, assume we're executed from glib test suite */
|
||||
if (argc < 2)
|
||||
@@ -1374,7 +1373,7 @@ main (int argc, char *argv[])
|
||||
verbose = TRUE;
|
||||
write_test = TRUE;
|
||||
only_create_struct = FALSE;
|
||||
target_path = DEFAULT_TEST_DIR;
|
||||
target_path = g_build_filename (g_get_tmp_dir (), "testdir_live-g-file", NULL);
|
||||
#ifdef G_PLATFORM_WIN32
|
||||
posix_compat = FALSE;
|
||||
#else
|
||||
@@ -1394,7 +1393,7 @@ main (int argc, char *argv[])
|
||||
|
||||
/* remaining arg should is the target path; we don't care of the extra args here */
|
||||
if (argc >= 2)
|
||||
target_path = strdup (argv[1]);
|
||||
target_path = g_strdup (argv[1]);
|
||||
|
||||
if (! target_path)
|
||||
{
|
||||
@@ -1471,6 +1470,9 @@ main (int argc, char *argv[])
|
||||
g_test_add_data_func ("/live-g-file/final_clean", target_path,
|
||||
prep_clean_structure);
|
||||
|
||||
return g_test_run ();
|
||||
retval = g_test_run ();
|
||||
|
||||
g_free (target_path);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@@ -1597,8 +1597,9 @@ wrap_g_open (const gchar *filename,
|
||||
* @tmpl: (type filename): template directory name
|
||||
* @mode: permissions to create the temporary directory with
|
||||
*
|
||||
* Creates a temporary directory. See the mkdtemp() documentation
|
||||
* on most UNIX-like systems.
|
||||
* Creates a temporary directory in the current directory.
|
||||
*
|
||||
* See the [`mkdtemp()`](man:mkdtemp(3)) documentation on most UNIX-like systems.
|
||||
*
|
||||
* The parameter is a string that should follow the rules for
|
||||
* mkdtemp() templates, i.e. contain the string "XXXXXX".
|
||||
@@ -1633,8 +1634,9 @@ g_mkdtemp_full (gchar *tmpl,
|
||||
* g_mkdtemp: (skip)
|
||||
* @tmpl: (type filename): template directory name
|
||||
*
|
||||
* Creates a temporary directory. See the mkdtemp() documentation
|
||||
* on most UNIX-like systems.
|
||||
* Creates a temporary directory in the current directory.
|
||||
*
|
||||
* See the [`mkdtemp()`](man:mkdtemp(3)) documentation on most UNIX-like systems.
|
||||
*
|
||||
* The parameter is a string that should follow the rules for
|
||||
* mkdtemp() templates, i.e. contain the string "XXXXXX".
|
||||
@@ -1668,8 +1670,9 @@ g_mkdtemp (gchar *tmpl)
|
||||
* and O_CREAT, which are passed automatically
|
||||
* @mode: permissions to create the temporary file with
|
||||
*
|
||||
* Opens a temporary file. See the mkstemp() documentation
|
||||
* on most UNIX-like systems.
|
||||
* Opens a temporary file in the current directory.
|
||||
*
|
||||
* See the [`mkstemp()`](man:mkstemp(3)) documentation on most UNIX-like systems.
|
||||
*
|
||||
* The parameter is a string that should follow the rules for
|
||||
* mkstemp() templates, i.e. contain the string "XXXXXX".
|
||||
@@ -1701,8 +1704,9 @@ g_mkstemp_full (gchar *tmpl,
|
||||
* g_mkstemp: (skip)
|
||||
* @tmpl: (type filename): template filename
|
||||
*
|
||||
* Opens a temporary file. See the mkstemp() documentation
|
||||
* on most UNIX-like systems.
|
||||
* Opens a temporary file in the current directory.
|
||||
*
|
||||
* See the [`mkstemp()`](man:mkstemp(3)) documentation on most UNIX-like systems.
|
||||
*
|
||||
* The parameter is a string that should follow the rules for
|
||||
* mkstemp() templates, i.e. contain the string "XXXXXX".
|
||||
|
@@ -1050,6 +1050,13 @@ g_key_file_load_from_bytes (GKeyFile *key_file,
|
||||
* Looks for a key file named @file in the paths specified in @search_dirs,
|
||||
* loads the file into @key_file and returns the file’s full path in @full_path.
|
||||
*
|
||||
* @search_dirs are checked in the order listed in the array, with the highest
|
||||
* priority directory listed first. Within each directory, @file is looked for.
|
||||
* If it’s not found, `-` characters in @file are progressively replaced with
|
||||
* directory separators to search subdirectories of the search directory. If the
|
||||
* file has not been found after all `-` characters have been replaced, the next
|
||||
* search directory in @search_dirs is checked.
|
||||
*
|
||||
* If the file could not be found in any of the @search_dirs,
|
||||
* [error@GLib.KeyFileError.NOT_FOUND] is returned. If
|
||||
* the file is found but the OS returns an error when opening or reading the
|
||||
@@ -1125,8 +1132,10 @@ g_key_file_load_from_dirs (GKeyFile *key_file,
|
||||
* @error: return location for a [struct@GLib.Error]
|
||||
*
|
||||
* Looks for a key file named @file in the paths returned from
|
||||
* [func@GLib.get_user_data_dir] and [func@GLib.get_system_data_dirs],
|
||||
* loads the file into @key_file and returns the file’s full path in
|
||||
* [func@GLib.get_user_data_dir] and [func@GLib.get_system_data_dirs].
|
||||
*
|
||||
* The search algorithm from [method@GLib.KeyFile.load_from_dirs] is used. If
|
||||
* @file is found, it’s loaded into @key_file and its full path is returned in
|
||||
* @full_path.
|
||||
*
|
||||
* If the file could not be loaded then either a [error@GLib.FileError] or
|
||||
|
@@ -153,6 +153,7 @@ test_corner_cases (void)
|
||||
gchar *message, **messages;
|
||||
GError *error = NULL;
|
||||
GBookmarkFile *bookmark;
|
||||
char *path = NULL;
|
||||
|
||||
bookmark = g_bookmark_file_new ();
|
||||
|
||||
@@ -669,8 +670,10 @@ test_corner_cases (void)
|
||||
g_clear_error (&error);
|
||||
|
||||
/* g_bookmark_file_to_file() */
|
||||
g_assert_true (g_bookmark_file_to_file (bookmark, "a", &error));
|
||||
path = g_build_filename (g_get_tmp_dir (), "corner-case-bookmark-file.xbel", NULL);
|
||||
g_assert_true (g_bookmark_file_to_file (bookmark, path, &error));
|
||||
g_assert_no_error (error);
|
||||
g_free (path);
|
||||
|
||||
/* g_bookmark_file_remove_group() */
|
||||
g_assert_false (g_bookmark_file_remove_group (bookmark, "a", NULL, NULL));
|
||||
|
@@ -32,13 +32,15 @@ static void
|
||||
test_dir_nonexisting (void)
|
||||
{
|
||||
GDir *dir;
|
||||
GError *error;
|
||||
GError *error = NULL;
|
||||
char *path = NULL;
|
||||
|
||||
error = NULL;
|
||||
dir = g_dir_open ("/pfrkstrf", 0, &error);
|
||||
g_assert (dir == NULL);
|
||||
path = g_build_filename (g_get_tmp_dir (), "does-not-exist", NULL);
|
||||
dir = g_dir_open (path, 0, &error);
|
||||
g_assert_null (dir);
|
||||
g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
|
||||
g_error_free (error);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -664,7 +664,7 @@ test_build_filenamev (void)
|
||||
static void
|
||||
test_mkdir_with_parents_1 (const gchar *base)
|
||||
{
|
||||
char *p0 = g_build_filename (base, "fum", NULL);
|
||||
char *p0 = g_build_filename (g_get_tmp_dir (), base, "fum", NULL);
|
||||
char *p1 = g_build_filename (p0, "tem", NULL);
|
||||
char *p2 = g_build_filename (p1, "zap", NULL);
|
||||
FILE *f;
|
||||
@@ -817,21 +817,18 @@ test_mkdir_with_parents (void)
|
||||
#ifndef G_OS_WIN32
|
||||
gboolean can_override_dac = check_cap_dac_override (NULL);
|
||||
#endif
|
||||
if (g_test_verbose())
|
||||
g_printerr ("checking g_mkdir_with_parents() in subdir ./hum/");
|
||||
|
||||
g_test_message ("Checking g_mkdir_with_parents() in subdir ./hum/");
|
||||
test_mkdir_with_parents_1 ("hum");
|
||||
g_remove ("hum");
|
||||
if (g_test_verbose())
|
||||
g_printerr ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
|
||||
|
||||
g_test_message ("Checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
|
||||
test_mkdir_with_parents_1 ("./hii///haa/hee///");
|
||||
g_remove ("hii/haa/hee");
|
||||
g_remove ("hii/haa");
|
||||
g_remove ("hii");
|
||||
cwd = g_get_current_dir ();
|
||||
if (g_test_verbose())
|
||||
g_printerr ("checking g_mkdir_with_parents() in cwd: %s", cwd);
|
||||
test_mkdir_with_parents_1 (cwd);
|
||||
|
||||
cwd = g_get_current_dir ();
|
||||
new_path = g_build_filename (cwd, "new", NULL);
|
||||
g_assert_cmpint (g_mkdir_with_parents (new_path, 0), ==, 0);
|
||||
g_assert_cmpint (g_rmdir (new_path), ==, 0);
|
||||
@@ -1343,7 +1340,7 @@ test_mkstemp (void)
|
||||
g_free (name);
|
||||
|
||||
/* Test normal case */
|
||||
name = g_strdup ("testXXXXXXtest"),
|
||||
name = g_build_filename (g_get_tmp_dir (), "testXXXXXXtest", NULL),
|
||||
fd = g_mkstemp (name);
|
||||
g_assert_cmpint (fd, !=, -1);
|
||||
g_assert_null (strstr (name, "XXXXXX"));
|
||||
@@ -1359,8 +1356,8 @@ test_mkstemp (void)
|
||||
strcpy (template, "foobarXXX");
|
||||
g_assert_cmpint (g_mkstemp (template), ==, -1);
|
||||
|
||||
strcpy (template, "fooXXXXXX");
|
||||
fd = g_mkstemp (template);
|
||||
name = g_build_filename (g_get_tmp_dir (), "fooXXXXXX", NULL);
|
||||
fd = g_mkstemp (name);
|
||||
g_assert_cmpint (fd, !=, -1);
|
||||
result = write (fd, hello, hellolen);
|
||||
g_assert_cmpint (result, !=, -1);
|
||||
@@ -1375,15 +1372,16 @@ test_mkstemp (void)
|
||||
g_assert_cmpstr (chars, ==, hello);
|
||||
|
||||
close (fd);
|
||||
remove (template);
|
||||
remove (name);
|
||||
g_free (name);
|
||||
|
||||
/* Check that is does not work for "fooXXXXXX.pdf" */
|
||||
strcpy (template, "fooXXXXXX.pdf");
|
||||
fd = g_mkstemp (template);
|
||||
/* Check that it works for "fooXXXXXX.pdf" */
|
||||
name = g_build_filename (g_get_tmp_dir (), "fooXXXXXX.pdf", NULL);
|
||||
fd = g_mkstemp (name);
|
||||
g_assert_cmpint (fd, !=, -1);
|
||||
|
||||
close (fd);
|
||||
remove (template);
|
||||
remove (name);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1391,12 +1389,12 @@ test_mkdtemp (void)
|
||||
{
|
||||
gint fd;
|
||||
gchar *ret;
|
||||
gchar *name;
|
||||
gchar *name, *name2;
|
||||
char template[32];
|
||||
|
||||
name = g_strdup ("testXXXXXXtest"),
|
||||
name = g_build_filename (g_get_tmp_dir (), "testXXXXXXtest", NULL),
|
||||
ret = g_mkdtemp (name);
|
||||
g_assert (ret == name);
|
||||
g_assert_true (ret == name);
|
||||
g_assert_null (strstr (name, "XXXXXX"));
|
||||
g_rmdir (name);
|
||||
g_free (name);
|
||||
@@ -1412,27 +1410,29 @@ test_mkdtemp (void)
|
||||
strcpy (template, "foodir");
|
||||
g_assert_null (g_mkdtemp (template));
|
||||
|
||||
strcpy (template, "fooXXXXXX");
|
||||
ret = g_mkdtemp (template);
|
||||
name = g_build_filename (g_get_tmp_dir (), "fooXXXXXX", NULL);
|
||||
ret = g_mkdtemp (name);
|
||||
g_assert_nonnull (ret);
|
||||
g_assert_true (ret == template);
|
||||
g_assert_false (g_file_test (template, G_FILE_TEST_IS_REGULAR));
|
||||
g_assert_true (g_file_test (template, G_FILE_TEST_IS_DIR));
|
||||
g_assert_true (ret == name);
|
||||
g_assert_false (g_file_test (name, G_FILE_TEST_IS_REGULAR));
|
||||
g_assert_true (g_file_test (name, G_FILE_TEST_IS_DIR));
|
||||
|
||||
strcat (template, "/abc");
|
||||
fd = g_open (template, O_WRONLY | O_CREAT, 0600);
|
||||
name2 = g_build_filename (name, "abc", NULL);
|
||||
fd = g_open (name2, O_WRONLY | O_CREAT, 0600);
|
||||
g_assert_cmpint (fd, !=, -1);
|
||||
close (fd);
|
||||
g_assert_true (g_file_test (template, G_FILE_TEST_IS_REGULAR));
|
||||
g_assert_cmpint (g_unlink (template), !=, -1);
|
||||
g_assert_true (g_file_test (name2, G_FILE_TEST_IS_REGULAR));
|
||||
g_assert_cmpint (g_unlink (name2), !=, -1);
|
||||
g_free (name2);
|
||||
|
||||
template[9] = '\0';
|
||||
g_assert_cmpint (g_rmdir (template), !=, -1);
|
||||
g_assert_cmpint (g_rmdir (name), !=, -1);
|
||||
g_free (name);
|
||||
|
||||
strcpy (template, "fooXXXXXX.dir");
|
||||
g_assert_nonnull (g_mkdtemp (template));
|
||||
g_assert_true (g_file_test (template, G_FILE_TEST_IS_DIR));
|
||||
g_rmdir (template);
|
||||
name = g_build_filename (g_get_tmp_dir (), "fooXXXXXX.dir", NULL);
|
||||
g_assert_nonnull (g_mkdtemp (name));
|
||||
g_assert_true (g_file_test (name, G_FILE_TEST_IS_DIR));
|
||||
g_rmdir (name);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1443,7 +1443,7 @@ test_get_contents (void)
|
||||
gchar *contents;
|
||||
GError *error = NULL;
|
||||
const gchar *text = "abcdefghijklmnopqrstuvwxyz";
|
||||
const gchar *filename = "file-test-get-contents";
|
||||
char *filename = g_build_filename (g_get_tmp_dir (), "file-test-get-contents", NULL);
|
||||
gsize bytes_written;
|
||||
|
||||
f = g_fopen (filename, "w");
|
||||
@@ -1472,6 +1472,7 @@ test_get_contents (void)
|
||||
|
||||
g_free (contents);
|
||||
g_remove (filename);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -2093,7 +2094,7 @@ test_stdio_wrappers (void)
|
||||
|
||||
g_remove ("mkdir-test/test-create");
|
||||
ret = g_rmdir ("mkdir-test");
|
||||
g_assert (ret == 0 || errno == ENOENT);
|
||||
g_assert_true (ret == 0 || errno == ENOENT);
|
||||
|
||||
ret = g_stat ("mkdir-test", &buf);
|
||||
g_assert_cmpint (ret, ==, -1);
|
||||
@@ -2194,7 +2195,7 @@ test_stdio_wrappers (void)
|
||||
static void
|
||||
test_fopen_modes (void)
|
||||
{
|
||||
char *path = g_build_filename ("temp-fopen", NULL);
|
||||
char *path = g_build_filename (g_get_tmp_dir (), "temp-fopen", NULL);
|
||||
gsize i;
|
||||
const gchar *modes[] =
|
||||
{
|
||||
|
@@ -39,8 +39,10 @@ test_small_writes (void)
|
||||
guint bytes_remaining;
|
||||
gchar tmp;
|
||||
GError *local_error = NULL;
|
||||
char *path = NULL;
|
||||
|
||||
io = g_io_channel_new_file ("iochannel-test-outfile", "w", &local_error);
|
||||
path = g_build_filename (g_get_tmp_dir (), "iochannel-test-outfile", NULL);
|
||||
io = g_io_channel_new_file (path, "w", &local_error);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
g_io_channel_set_encoding (io, NULL, NULL);
|
||||
@@ -61,7 +63,8 @@ test_small_writes (void)
|
||||
g_assert_cmpint (status, ==, G_IO_STATUS_NORMAL);
|
||||
|
||||
g_io_channel_unref (io);
|
||||
g_remove ("iochannel-test-outfile");
|
||||
g_remove (path);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -70,7 +73,7 @@ test_read_write (void)
|
||||
GIOChannel *gio_r, *gio_w ;
|
||||
GError *local_error = NULL;
|
||||
GString *buffer;
|
||||
char *filename;
|
||||
char *in_path = NULL, *out_path = NULL;
|
||||
gint rlength = 0;
|
||||
glong wlength = 0;
|
||||
gsize length_out;
|
||||
@@ -78,14 +81,15 @@ test_read_write (void)
|
||||
GIOStatus status;
|
||||
const gsize buffer_size_bytes = 1024;
|
||||
|
||||
filename = g_test_build_filename (G_TEST_DIST, "iochannel-test-infile", NULL);
|
||||
in_path = g_test_build_filename (G_TEST_DIST, "iochannel-test-infile", NULL);
|
||||
|
||||
setbuf (stdout, NULL); /* For debugging */
|
||||
|
||||
gio_r = g_io_channel_new_file (filename, "r", &local_error);
|
||||
gio_r = g_io_channel_new_file (in_path, "r", &local_error);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
gio_w = g_io_channel_new_file ("iochannel-test-outfile", "w", &local_error);
|
||||
out_path = g_build_filename (g_get_tmp_dir (), "iochannel-test-outfile", NULL);
|
||||
gio_w = g_io_channel_new_file (out_path, "w", &local_error);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
g_io_channel_set_encoding (gio_r, encoding, &local_error);
|
||||
@@ -164,7 +168,8 @@ test_read_write (void)
|
||||
|
||||
test_small_writes ();
|
||||
|
||||
g_free (filename);
|
||||
g_free (in_path);
|
||||
g_free (out_path);
|
||||
g_string_free (buffer, TRUE);
|
||||
}
|
||||
|
||||
@@ -227,7 +232,7 @@ int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
|
||||
g_test_add_func ("/io-channel/read-write", test_read_write);
|
||||
g_test_add_func ("/io-channel/read-line/embedded-nuls", test_read_line_embedded_nuls);
|
||||
|
@@ -1534,6 +1534,30 @@ test_int64 (void)
|
||||
g_key_file_free (file);
|
||||
}
|
||||
|
||||
#ifdef G_OS_UNIX
|
||||
static void
|
||||
copy_file (const char *source,
|
||||
const char *dest)
|
||||
{
|
||||
char *dest_dir = NULL;
|
||||
guint8 *file_contents = NULL;
|
||||
size_t file_contents_len = 0;
|
||||
GError *local_error = NULL;
|
||||
|
||||
dest_dir = g_path_get_dirname (dest);
|
||||
g_mkdir_with_parents (dest_dir, 0700);
|
||||
g_free (dest_dir);
|
||||
|
||||
g_file_get_contents (source, (char **) &file_contents, &file_contents_len, &local_error);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
g_file_set_contents (dest, (const char *) file_contents, file_contents_len, &local_error);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
g_free (file_contents);
|
||||
}
|
||||
#endif /* G_OS_UNIX */
|
||||
|
||||
static void
|
||||
test_load (void)
|
||||
{
|
||||
@@ -1541,11 +1565,20 @@ test_load (void)
|
||||
GError *error;
|
||||
gboolean bools[2] = { TRUE, FALSE };
|
||||
gboolean loaded;
|
||||
#ifdef G_OS_UNIX
|
||||
char *xdg_data_home_test_file = NULL;
|
||||
#endif
|
||||
|
||||
file = g_key_file_new ();
|
||||
error = NULL;
|
||||
#ifdef G_OS_UNIX
|
||||
/* Uses the value of $XDG_DATA_HOME we set in main() */
|
||||
/* Uses the value of $XDG_DATA_HOME set by G_TEST_OPTION_ISOLATE_DIRS in main(),
|
||||
* so we need to copy the test file to that temporary directory */
|
||||
xdg_data_home_test_file = g_build_filename (g_get_user_data_dir (), "keyfiletest.ini", NULL);
|
||||
copy_file (g_test_get_filename (G_TEST_DIST, "keyfiletest.ini", NULL),
|
||||
xdg_data_home_test_file);
|
||||
g_free (xdg_data_home_test_file);
|
||||
|
||||
loaded = g_key_file_load_from_data_dirs (file, "keyfiletest.ini", NULL, 0, &error);
|
||||
#else
|
||||
loaded = g_key_file_load_from_file (file, g_test_get_filename (G_TEST_DIST, "keyfiletest.ini", NULL), 0, &error);
|
||||
@@ -1592,7 +1625,7 @@ test_save (void)
|
||||
ok = g_key_file_load_from_data (kf, data, strlen (data), 0, NULL);
|
||||
g_assert_true (ok);
|
||||
|
||||
file = g_strdup ("key_file_XXXXXX");
|
||||
file = g_build_filename (g_get_tmp_dir (), "key_file_XXXXXX", NULL);
|
||||
fd = g_mkstemp (file);
|
||||
g_assert_cmpint (fd, !=, -1);
|
||||
ok = g_close (fd, &error);
|
||||
@@ -1963,7 +1996,7 @@ test_free_when_not_last_ref (void)
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
|
||||
#ifdef G_OS_UNIX
|
||||
g_setenv ("XDG_DATA_HOME", g_test_get_dir (G_TEST_DIST), TRUE);
|
||||
|
@@ -50,7 +50,11 @@ check_stop (gpointer data)
|
||||
GMainLoop *loop = data;
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
stop = g_file_test ("STOP", G_FILE_TEST_EXISTS);
|
||||
char *stop_name = NULL;
|
||||
|
||||
stop_name = g_build_filename (g_get_tmp_dir (), "maptest.stop", NULL);
|
||||
stop = g_file_test (stop_name, G_FILE_TEST_EXISTS);
|
||||
g_free (stop_name);
|
||||
#endif
|
||||
|
||||
if (stop)
|
||||
@@ -99,9 +103,10 @@ child_main (void)
|
||||
{
|
||||
GMappedFile *map;
|
||||
GMainLoop *loop;
|
||||
gchar *dir, *global_filename, *childname;
|
||||
const char *dir;
|
||||
char *global_filename = NULL, *childname = NULL;
|
||||
|
||||
dir = g_get_current_dir ();
|
||||
dir = g_get_tmp_dir ();
|
||||
global_filename = g_build_filename (dir, "maptest", NULL);
|
||||
childname = g_build_filename (dir, "mapchild", NULL);
|
||||
|
||||
@@ -124,7 +129,6 @@ child_main (void)
|
||||
|
||||
g_free (childname);
|
||||
g_free (global_filename);
|
||||
g_free (dir);
|
||||
g_mapped_file_unref (map);
|
||||
|
||||
signal_parent (NULL);
|
||||
@@ -134,9 +138,10 @@ static void
|
||||
test_mapping_flags (void)
|
||||
{
|
||||
GMappedFile *map;
|
||||
gchar *dir, *global_filename;
|
||||
const char *dir;
|
||||
char *global_filename = NULL;
|
||||
|
||||
dir = g_get_current_dir ();
|
||||
dir = g_get_tmp_dir ();
|
||||
global_filename = g_build_filename (dir, "maptest", NULL);
|
||||
|
||||
write_or_die (global_filename, "ABC", -1);
|
||||
@@ -151,10 +156,9 @@ test_mapping_flags (void)
|
||||
g_test_message ("test_mapping: ok");
|
||||
|
||||
/* Cleaning left over files */
|
||||
g_remove ("maptest");
|
||||
g_remove (global_filename);
|
||||
|
||||
g_free (global_filename);
|
||||
g_free (dir);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -165,9 +169,10 @@ test_private (void)
|
||||
gboolean result;
|
||||
gchar *buffer;
|
||||
gsize len;
|
||||
gchar *dir, *global_filename;
|
||||
const char *dir;
|
||||
char *global_filename = NULL;
|
||||
|
||||
dir = g_get_current_dir ();
|
||||
dir = g_get_tmp_dir ();
|
||||
global_filename = g_build_filename (dir, "maptest", NULL);
|
||||
|
||||
write_or_die (global_filename, "ABC", -1);
|
||||
@@ -186,11 +191,10 @@ test_private (void)
|
||||
g_assert_cmpstr (buffer, ==, "ABC");
|
||||
g_free (buffer);
|
||||
|
||||
g_free (global_filename);
|
||||
g_free (dir);
|
||||
|
||||
/* Cleaning left over files */
|
||||
g_remove ("maptest");
|
||||
g_remove (global_filename);
|
||||
|
||||
g_free (global_filename);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -209,16 +213,18 @@ test_child_private (void)
|
||||
int wait_status;
|
||||
#endif
|
||||
gchar pid[100];
|
||||
gchar *dir, *global_filename, *childname;
|
||||
const char *dir;
|
||||
char *global_filename = NULL, *childname = NULL, *stop_name = NULL;
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
g_remove ("STOP");
|
||||
g_assert_false (g_file_test ("STOP", G_FILE_TEST_EXISTS));
|
||||
#endif
|
||||
|
||||
dir = g_get_current_dir ();
|
||||
dir = g_get_tmp_dir ();
|
||||
global_filename = g_build_filename (dir, "maptest", NULL);
|
||||
childname = g_build_filename (dir, "mapchild", NULL);
|
||||
stop_name = g_build_filename (dir, "maptest.stop", NULL);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
g_remove (stop_name);
|
||||
g_assert_false (g_file_test (stop_name, G_FILE_TEST_EXISTS));
|
||||
#endif
|
||||
|
||||
write_or_die (global_filename, "ABC", -1);
|
||||
map = map_or_die (global_filename, TRUE);
|
||||
@@ -260,7 +266,7 @@ test_child_private (void)
|
||||
#ifndef G_OS_WIN32
|
||||
kill (child_pid, SIGUSR1);
|
||||
#else
|
||||
g_file_set_contents ("STOP", "Hey there\n", -1, NULL);
|
||||
g_file_set_contents (stop_name, "Hey there\n", -1, NULL);
|
||||
#endif
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
@@ -283,13 +289,14 @@ test_child_private (void)
|
||||
g_assert_cmpstr (buffer, ==, "ABC");
|
||||
g_free (buffer);
|
||||
|
||||
/* Cleaning left over files */
|
||||
g_remove (childname);
|
||||
g_remove (global_filename);
|
||||
g_remove (stop_name);
|
||||
|
||||
g_free (childname);
|
||||
g_free (global_filename);
|
||||
g_free (dir);
|
||||
|
||||
/* Cleaning left over files */
|
||||
g_remove ("mapchild");
|
||||
g_remove ("maptest");
|
||||
g_free (stop_name);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -308,7 +315,7 @@ main (int argc,
|
||||
}
|
||||
#endif
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
local_argv = argv;
|
||||
|
||||
if (argc > 1)
|
||||
|
@@ -195,8 +195,11 @@ test_spawn_basics (void)
|
||||
{
|
||||
gboolean result;
|
||||
GError *err = NULL;
|
||||
char *tmp_filename = NULL, *tmp_filename_quoted = NULL;
|
||||
int fd = -1;
|
||||
gchar *output = NULL;
|
||||
gchar *erroutput = NULL;
|
||||
char full_cmdline[1000] = {0};
|
||||
#ifdef G_OS_WIN32
|
||||
size_t n;
|
||||
char buf[100];
|
||||
@@ -205,7 +208,6 @@ test_spawn_basics (void)
|
||||
gchar **envp = g_get_environ ();
|
||||
gchar *system_directory;
|
||||
gchar spawn_binary[1000] = {0};
|
||||
gchar full_cmdline[1000] = {0};
|
||||
GList *cmd_shell_env_vars = NULL;
|
||||
const LCID old_lcid = GetThreadUILanguage ();
|
||||
const unsigned int initial_cp = GetConsoleOutputCP ();
|
||||
@@ -254,18 +256,23 @@ test_spawn_basics (void)
|
||||
* important e.g for the MSYS2 environment, which provides coreutils
|
||||
* sort.exe
|
||||
*/
|
||||
g_file_set_contents ("spawn-test-created-file.txt",
|
||||
fd = g_file_open_tmp ("spawn-test-created-file-XXXXXX.txt", &tmp_filename, NULL);
|
||||
g_assert_cmpint (fd, >, -1);
|
||||
g_close (fd, NULL);
|
||||
|
||||
g_file_set_contents (tmp_filename,
|
||||
"line first\nline 2\nline last\n", -1, &err);
|
||||
g_assert_no_error(err);
|
||||
|
||||
tmp_filename_quoted = g_shell_quote (tmp_filename);
|
||||
#ifndef G_OS_WIN32
|
||||
result = g_spawn_command_line_sync ("sort spawn-test-created-file.txt",
|
||||
&output, &erroutput, NULL, &err);
|
||||
g_snprintf (full_cmdline, sizeof (full_cmdline),
|
||||
"sort %s", tmp_filename_quoted);
|
||||
#else
|
||||
g_snprintf (full_cmdline, sizeof (full_cmdline),
|
||||
"'%s\\sort.exe' spawn-test-created-file.txt", system_directory);
|
||||
result = g_spawn_command_line_sync (full_cmdline, &output, &erroutput, NULL, &err);
|
||||
"'%s\\sort.exe' %s", system_directory, tmp_filename_quoted);
|
||||
#endif
|
||||
result = g_spawn_command_line_sync (full_cmdline, &output, &erroutput, NULL, &err);
|
||||
g_assert_no_error (err);
|
||||
g_assert_true (result);
|
||||
g_assert_nonnull (output);
|
||||
@@ -305,7 +312,9 @@ test_spawn_basics (void)
|
||||
#endif
|
||||
g_free (erroutput);
|
||||
erroutput = NULL;
|
||||
g_unlink ("spawn-test-created-file.txt");
|
||||
g_unlink (tmp_filename);
|
||||
g_free (tmp_filename);
|
||||
g_free (tmp_filename_quoted);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
g_test_message ("Running spawn-test-win32-gui in various ways.");
|
||||
@@ -533,7 +542,7 @@ main (int argc,
|
||||
dirname = g_path_get_dirname (argv[0]);
|
||||
#endif
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
|
||||
g_test_add_func ("/spawn/basics", test_spawn_basics);
|
||||
#ifdef G_OS_UNIX
|
||||
|
Reference in New Issue
Block a user