diff options
Diffstat (limited to 'glib/tests')
-rw-r--r-- | glib/tests/mappedfile.c | 35 | ||||
-rw-r--r-- | glib/tests/strfuncs.c | 13 |
2 files changed, 27 insertions, 21 deletions
diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c index 5387a643f..1c979c3fb 100644 --- a/glib/tests/mappedfile.c +++ b/glib/tests/mappedfile.c @@ -13,30 +13,30 @@ static void test_basic (void) { - GMappedFile *file; + GBytes *file; GError *error; error = NULL; file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error); g_assert_no_error (error); - g_mapped_file_ref (file); - g_mapped_file_unref (file); + g_bytes_ref (file); + g_bytes_unref (file); - g_mapped_file_unref (file); + g_bytes_unref (file); } static void test_empty (void) { - GMappedFile *file; + GBytes *file; GError *error; error = NULL; file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error); g_assert_no_error (error); - g_assert (g_mapped_file_get_contents (file) == NULL); + g_assert (g_bytes_get_data (file, NULL) == NULL); g_mapped_file_free (file); } @@ -45,7 +45,7 @@ static void test_device (void) { GError *error = NULL; - GMappedFile *file; + GBytes *file; file = g_mapped_file_new ("/dev/null", FALSE, &error); g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL); @@ -56,7 +56,7 @@ test_device (void) static void test_nonexisting (void) { - GMappedFile *file; + GBytes *file; GError *error; error = NULL; @@ -69,9 +69,10 @@ test_nonexisting (void) static void test_writable (void) { - GMappedFile *file; + GBytes *file; GError *error; gchar *contents; + gsize size; const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM"; const gchar *new = "abcdefghijklmnopqrstuvxyz"; @@ -85,7 +86,8 @@ test_writable (void) file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); memcpy (contents, new, strlen (new)); @@ -97,7 +99,8 @@ test_writable (void) file = g_mapped_file_new (SRCDIR "/4096-random-bytes", TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); g_mapped_file_free (file); @@ -106,9 +109,10 @@ test_writable (void) static void test_writable_fd (void) { - GMappedFile *file; + GBytes *file; GError *error; gchar *contents; + gsize size; const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM"; const gchar *new = "abcdefghijklmnopqrstuvxyz"; int fd; @@ -125,7 +129,8 @@ test_writable_fd (void) file = g_mapped_file_new_from_fd (fd, TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); memcpy (contents, new, strlen (new)); @@ -140,11 +145,11 @@ test_writable_fd (void) file = g_mapped_file_new_from_fd (fd, TRUE, &error); g_assert_no_error (error); - contents = g_mapped_file_get_contents (file); + contents = (gchar *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); g_assert (strncmp (contents, old, strlen (old)) == 0); g_mapped_file_free (file); - } int diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c index 358bc58d5..e83f9c3d7 100644 --- a/glib/tests/strfuncs.c +++ b/glib/tests/strfuncs.c @@ -1074,11 +1074,12 @@ test_strtoll (void) static void test_bounds (void) { - GMappedFile *file, *before, *after; + GBytes *file, *before, *after; char buffer[4097]; char *tmp, *tmp2; char **array; char *string; + gsize size; /* if we allocate the file between two others and then free those * other two, then hopefully we end up with unmapped memory on either @@ -1092,12 +1093,12 @@ test_bounds (void) file = g_mapped_file_new ("4096-random-bytes", TRUE, NULL); after = g_mapped_file_new ("4096-random-bytes", TRUE, NULL); - g_mapped_file_unref (before); - g_mapped_file_unref (after); + g_bytes_unref (before); + g_bytes_unref (after); g_assert (file != NULL); - g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096); - string = g_mapped_file_get_contents (file); + string = (char *) g_bytes_get_data (file, &size); + g_assert_cmpint (size, ==, 4096); /* ensure they're all non-nul */ g_assert (memchr (string, '\0', 4096) == NULL); @@ -1227,7 +1228,7 @@ test_bounds (void) g_free (tmp2); g_free (tmp); - g_mapped_file_unref (file); + g_bytes_unref (file); } static void |