15 file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
16 g_assert_no_error (error);
18 g_mapped_file_ref (file);
19 g_mapped_file_unref (file);
21 g_mapped_file_unref (file);
31 file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
32 g_assert_no_error (error);
34 g_assert (g_mapped_file_get_contents (file) == NULL);
36 g_mapped_file_free (file);
45 file = g_mapped_file_new ("/dev/null", FALSE, &error);
46 g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL);
47 g_assert (file == NULL);
52 test_nonexisting (void)
58 file = g_mapped_file_new ("no-such-file", FALSE, &error);
59 g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
60 g_clear_error (&error);
61 g_assert (file == NULL);
70 const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM";
71 const gchar *new = "abcdefghijklmnopqrstuvxyz";
73 if (access (SRCDIR "/4096-random-bytes", W_OK) != 0)
75 g_test_message ("Skipping writable mapping test");
80 file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error);
81 g_assert_no_error (error);
83 contents = g_mapped_file_get_contents (file);
84 g_assert (strncmp (contents, old, strlen (old)) == 0);
86 memcpy (contents, new, strlen (new));
87 g_assert (strncmp (contents, new, strlen (new)) == 0);
89 g_mapped_file_free (file);
92 file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error);
93 g_assert_no_error (error);
95 contents = g_mapped_file_get_contents (file);
96 g_assert (strncmp (contents, old, strlen (old)) == 0);
98 g_mapped_file_free (file);
102 main (int argc, char *argv[])
104 g_test_init (&argc, &argv, NULL);
106 g_test_add_func ("/mappedfile/basic", test_basic);
107 g_test_add_func ("/mappedfile/empty", test_empty);
108 g_test_add_func ("/mappedfile/nonexisting", test_nonexisting);
109 g_test_add_func ("/mappedfile/writable", test_writable);
111 return g_test_run ();