#define GLIB_DISABLE_DEPRECATION_WARNINGS
-#include <config.h>
#include <glib.h>
#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#include <glib/gstdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
-static const gchar *datapath;
+#ifdef G_OS_UNIX
+#include <unistd.h>
+#endif
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
static void
test_basic (void)
{
GMappedFile *file;
GError *error;
- gchar *path;
error = NULL;
- path = g_build_filename (datapath, "empty", NULL);
- file = g_mapped_file_new (path, FALSE, &error);
- g_free (path);
+ file = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "empty", NULL), FALSE, &error);
g_assert_no_error (error);
g_mapped_file_ref (file);
{
GMappedFile *file;
GError *error;
- gchar *path;
error = NULL;
- path = g_build_filename (datapath, "empty", NULL);
- file = g_mapped_file_new (path, FALSE, &error);
- g_free (path);
+ file = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "empty", NULL), FALSE, &error);
g_assert_no_error (error);
g_assert (g_mapped_file_get_contents (file) == NULL);
file = g_mapped_file_new ("/dev/null", FALSE, &error);
g_assert (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_INVAL) ||
+ g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NODEV) ||
g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM));
g_assert (file == NULL);
g_error_free (error);
gsize len;
const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM";
const gchar *new = "abcdefghijklmnopqrstuvxyz";
- char *srcpath;
gchar *tmp_copy_path;
- srcpath = g_build_filename (datapath, "4096-random-bytes", NULL);
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
- g_file_get_contents (srcpath, &contents, &len, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DIST, "4096-random-bytes", NULL), &contents, &len, &error);
g_assert_no_error (error);
g_file_set_contents (tmp_copy_path, contents, len, &error);
g_assert_no_error (error);
g_mapped_file_free (file);
- g_free (srcpath);
g_free (tmp_copy_path);
}
const gchar *new = "abcdefghijklmnopqrstuvxyz";
gsize len;
int fd;
- char *srcpath;
gchar *tmp_copy_path;
- srcpath = g_build_filename (datapath, "4096-random-bytes", NULL);
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
- g_file_get_contents (srcpath, &contents, &len, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DIST, "4096-random-bytes", NULL), &contents, &len, &error);
g_assert_no_error (error);
g_file_set_contents (tmp_copy_path, contents, len, &error);
g_assert_no_error (error);
g_mapped_file_free (file);
- g_free (srcpath);
g_free (tmp_copy_path);
}
GMappedFile *file;
GBytes *bytes;
GError *error;
- gchar *path;
error = NULL;
- path = g_build_filename (datapath, "empty", NULL);
- file = g_mapped_file_new (path, FALSE, &error);
- g_free (path);
+ file = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "empty", NULL), FALSE, &error);
g_assert_no_error (error);
bytes = g_mapped_file_get_bytes (file);
int
main (int argc, char *argv[])
{
- if (g_getenv ("G_TEST_DATA"))
- datapath = g_getenv ("G_TEST_DATA");
- else
- datapath = SRCDIR;
-
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/mappedfile/basic", test_basic);