GVariant: support serialising to GVariantVectors
[platform/upstream/glib.git] / glib / tests / mappedfile.c
index caa3ee6..ccaea34 100644 (file)
@@ -1,16 +1,19 @@
 #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>
 
+#ifdef G_OS_UNIX
+#include <unistd.h>
+#endif
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
+
 static void
 test_basic (void)
 {
@@ -18,7 +21,7 @@ test_basic (void)
   GError *error;
 
   error = NULL;
-  file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
+  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);
@@ -34,7 +37,7 @@ test_empty (void)
   GError *error;
 
   error = NULL;
-  file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
+  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);
@@ -51,6 +54,7 @@ test_device (void)
 
   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);
@@ -79,13 +83,11 @@ test_writable (void)
   gsize len;
   const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM";
   const gchar *new = "abcdefghijklmnopqrstuvxyz";
-  char *srcpath;
   gchar *tmp_copy_path;
 
-  srcpath = g_build_filename (SRCDIR, "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);
@@ -112,7 +114,6 @@ test_writable (void)
 
   g_mapped_file_free (file);
 
-  g_free (srcpath);
   g_free (tmp_copy_path);
 }
 
@@ -126,13 +127,11 @@ test_writable_fd (void)
   const gchar *new = "abcdefghijklmnopqrstuvxyz";
   gsize len;
   int fd;
-  char *srcpath;
   gchar *tmp_copy_path;
 
-  srcpath = g_build_filename (SRCDIR, "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);
@@ -164,7 +163,6 @@ test_writable_fd (void)
 
   g_mapped_file_free (file);
 
-  g_free (srcpath);
   g_free (tmp_copy_path);
 }
 
@@ -176,7 +174,7 @@ test_gbytes (void)
   GError *error;
 
   error = NULL;
-  file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
+  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);