mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-14 01:43:11 +02:00
tests: Convert g_assert() to g_assert_*() in glib/tests/mappedfile.c
g_assert_*() give more informative failure messages, and aren’t compiled out when building with G_DISABLE_ASSERT. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
a1aebf7437
commit
ba84f45f96
@ -40,7 +40,7 @@ test_empty (void)
|
|||||||
file = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "empty", NULL), 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_no_error (error);
|
||||||
|
|
||||||
g_assert (g_mapped_file_get_contents (file) == NULL);
|
g_assert_null (g_mapped_file_get_contents (file));
|
||||||
|
|
||||||
g_mapped_file_free (file);
|
g_mapped_file_free (file);
|
||||||
}
|
}
|
||||||
@ -53,10 +53,10 @@ test_device (void)
|
|||||||
GMappedFile *file;
|
GMappedFile *file;
|
||||||
|
|
||||||
file = g_mapped_file_new ("/dev/null", FALSE, &error);
|
file = g_mapped_file_new ("/dev/null", FALSE, &error);
|
||||||
g_assert (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_INVAL) ||
|
g_assert_true (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_NODEV) ||
|
||||||
g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM));
|
g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM));
|
||||||
g_assert (file == NULL);
|
g_assert_null (file);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -71,7 +71,7 @@ test_nonexisting (void)
|
|||||||
file = g_mapped_file_new ("no-such-file", FALSE, &error);
|
file = g_mapped_file_new ("no-such-file", FALSE, &error);
|
||||||
g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
|
g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
g_assert (file == NULL);
|
g_assert_null (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -98,10 +98,10 @@ test_writable (void)
|
|||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
contents = g_mapped_file_get_contents (file);
|
contents = g_mapped_file_get_contents (file);
|
||||||
g_assert (strncmp (contents, old, strlen (old)) == 0);
|
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
|
||||||
|
|
||||||
memcpy (contents, new, strlen (new));
|
memcpy (contents, new, strlen (new));
|
||||||
g_assert (strncmp (contents, new, strlen (new)) == 0);
|
g_assert_cmpuint (strncmp (contents, new, strlen (new)), ==, 0);
|
||||||
|
|
||||||
g_mapped_file_free (file);
|
g_mapped_file_free (file);
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ test_writable (void)
|
|||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
contents = g_mapped_file_get_contents (file);
|
contents = g_mapped_file_get_contents (file);
|
||||||
g_assert (strncmp (contents, old, strlen (old)) == 0);
|
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
|
||||||
|
|
||||||
g_mapped_file_free (file);
|
g_mapped_file_free (file);
|
||||||
|
|
||||||
@ -139,27 +139,27 @@ test_writable_fd (void)
|
|||||||
g_free (contents);
|
g_free (contents);
|
||||||
|
|
||||||
fd = g_open (tmp_copy_path, O_RDWR, 0);
|
fd = g_open (tmp_copy_path, O_RDWR, 0);
|
||||||
g_assert (fd != -1);
|
g_assert_cmpint (fd, !=, -1);
|
||||||
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
|
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
contents = g_mapped_file_get_contents (file);
|
contents = g_mapped_file_get_contents (file);
|
||||||
g_assert (strncmp (contents, old, strlen (old)) == 0);
|
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
|
||||||
|
|
||||||
memcpy (contents, new, strlen (new));
|
memcpy (contents, new, strlen (new));
|
||||||
g_assert (strncmp (contents, new, strlen (new)) == 0);
|
g_assert_cmpuint (strncmp (contents, new, strlen (new)), ==, 0);
|
||||||
|
|
||||||
g_mapped_file_free (file);
|
g_mapped_file_free (file);
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
fd = g_open (tmp_copy_path, O_RDWR, 0);
|
fd = g_open (tmp_copy_path, O_RDWR, 0);
|
||||||
g_assert (fd != -1);
|
g_assert_cmpint (fd, !=, -1);
|
||||||
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
|
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
contents = g_mapped_file_get_contents (file);
|
contents = g_mapped_file_get_contents (file);
|
||||||
g_assert (strncmp (contents, old, strlen (old)) == 0);
|
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
|
||||||
|
|
||||||
g_mapped_file_free (file);
|
g_mapped_file_free (file);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user