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);
40 test_nonexisting (void)
46 file = g_mapped_file_new ("no-such-file", FALSE, &error);
47 g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
48 g_clear_error (&error);
49 g_assert (file == NULL);
58 const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM";
59 const gchar *new = "abcdefghijklmnopqrstuvxyz";
61 if (access (SRCDIR "/4096-random-bytes", W_OK) != 0)
63 g_test_message ("Skipping writable mapping test");
68 file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error);
69 g_assert_no_error (error);
71 contents = g_mapped_file_get_contents (file);
72 g_assert (strncmp (contents, old, strlen (old)) == 0);
74 memcpy (contents, new, strlen (new));
75 g_assert (strncmp (contents, new, strlen (new)) == 0);
77 g_mapped_file_free (file);
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 g_mapped_file_free (file);
90 main (int argc, char *argv[])
92 g_test_init (&argc, &argv, NULL);
94 g_test_add_func ("/mappedfile/basic", test_basic);
95 g_test_add_func ("/mappedfile/empty", test_empty);
96 g_test_add_func ("/mappedfile/nonexisting", test_nonexisting);
97 g_test_add_func ("/mappedfile/writable", test_writable);