15 file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
16 g_assert_no_error (error);
18 g_assert (g_mapped_file_get_contents (file) == NULL);
20 g_mapped_file_free (file);
24 test_nonexisting (void)
30 file = g_mapped_file_new ("no-such-file", FALSE, &error);
31 g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
32 g_clear_error (&error);
33 g_assert (file == NULL);
42 const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM";
43 const gchar *new = "abcdefghijklmnopqrstuvxyz";
45 if (access (SRCDIR "/4096-random-bytes", W_OK) != 0)
47 g_test_message ("Skipping writable mapping test");
52 file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error);
53 g_assert_no_error (error);
55 contents = g_mapped_file_get_contents (file);
56 g_assert (strncmp (contents, old, strlen (old)) == 0);
58 memcpy (contents, new, strlen (new));
59 g_assert (strncmp (contents, new, strlen (new)) == 0);
61 g_mapped_file_free (file);
64 file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error);
65 g_assert_no_error (error);
67 contents = g_mapped_file_get_contents (file);
68 g_assert (strncmp (contents, old, strlen (old)) == 0);
70 g_mapped_file_free (file);
74 main (int argc, char *argv[])
76 g_test_init (&argc, &argv, NULL);
78 g_test_add_func ("/mappedfile/empty", test_empty);
79 g_test_add_func ("/mappedfile/nonexisting", test_nonexisting);
80 g_test_add_func ("/mappedfile/writable", test_writable);