tests: Use g_assert_*() instead of g_assert() in contenttype tests

g_assert_*() give more helpful error messages on failure, and aren’t
compiled out by G_DISABLE_ASSERT.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2019-03-19 11:18:07 +00:00
parent 41f68f8b19
commit d586ab4c73

View File

@ -39,7 +39,7 @@ test_guess (void)
g_free (existing_directory);
expected = g_content_type_from_mime_type ("inode/directory");
g_assert_content_type_equals (expected, res);
g_assert (uncertain);
g_assert_true (uncertain);
g_free (res);
g_free (expected);
@ -52,7 +52,7 @@ test_guess (void)
res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("text/plain");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
@ -61,21 +61,21 @@ test_guess (void)
res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("text/plain");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
res = g_content_type_guess ("foo.desktop", data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("application/x-desktop");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
expected = g_content_type_from_mime_type ("application/x-desktop");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
@ -84,14 +84,14 @@ test_guess (void)
res = g_content_type_guess ("test.pot", (guchar *)"ABC abc", 7, &uncertain);
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
res = g_content_type_guess ("test.pot", (guchar *)"msgid \"", 7, &uncertain);
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
@ -107,7 +107,7 @@ test_guess (void)
res = g_content_type_guess ("test.otf", (guchar *)"OTTO", 4, &uncertain);
expected = g_content_type_from_mime_type ("application/x-font-otf");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
#endif
@ -115,7 +115,7 @@ test_guess (void)
res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain);
expected = g_content_type_from_mime_type ("image/x-eps");
g_assert_content_type_equals (expected, res);
g_assert (!uncertain);
g_assert_false (uncertain);
g_free (res);
g_free (expected);
}
@ -127,7 +127,7 @@ test_unknown (void)
gchar *str;
unknown = g_content_type_from_mime_type ("application/octet-stream");
g_assert (g_content_type_is_unknown (unknown));
g_assert_true (g_content_type_is_unknown (unknown));
str = g_content_type_get_mime_type (unknown);
g_assert_cmpstr (str, ==, "application/octet-stream");
g_free (str);
@ -143,8 +143,8 @@ test_subtype (void)
plain = g_content_type_from_mime_type ("text/plain");
xml = g_content_type_from_mime_type ("application/xml");
g_assert (g_content_type_is_a (xml, plain));
g_assert (g_content_type_is_mime_type (xml, "text/plain"));
g_assert_true (g_content_type_is_a (xml, plain));
g_assert_true (g_content_type_is_mime_type (xml, "text/plain"));
g_free (plain);
g_free (xml);
@ -175,11 +175,11 @@ test_list (void)
types = g_content_types_get_registered ();
g_assert (g_list_length (types) > 1);
g_assert_cmpuint (g_list_length (types), >, 1);
/* just check that some types are in the list */
g_assert (g_list_find_custom (types, plain, find_mime) != NULL);
g_assert (g_list_find_custom (types, xml, find_mime) != NULL);
g_assert_nonnull (g_list_find_custom (types, plain, find_mime));
g_assert_nonnull (g_list_find_custom (types, xml, find_mime));
g_list_free_full (types, g_free);
@ -193,15 +193,15 @@ test_executable (void)
gchar *type;
type = g_content_type_from_mime_type ("application/x-executable");
g_assert (g_content_type_can_be_executable (type));
g_assert_true (g_content_type_can_be_executable (type));
g_free (type);
type = g_content_type_from_mime_type ("text/plain");
g_assert (g_content_type_can_be_executable (type));
g_assert_true (g_content_type_can_be_executable (type));
g_free (type);
type = g_content_type_from_mime_type ("image/png");
g_assert (!g_content_type_can_be_executable (type));
g_assert_false (g_content_type_can_be_executable (type));
g_free (type);
}
@ -213,7 +213,7 @@ test_description (void)
type = g_content_type_from_mime_type ("text/plain");
desc = g_content_type_get_description (type);
g_assert (desc != NULL);
g_assert_nonnull (desc);
g_free (desc);
g_free (type);
@ -227,17 +227,17 @@ test_icon (void)
type = g_content_type_from_mime_type ("text/plain");
icon = g_content_type_get_icon (type);
g_assert (G_IS_ICON (icon));
g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
#ifdef __APPLE__
g_assert (g_strv_contains (names, "text-*"));
g_assert_true (g_strv_contains (names, "text-*"));
#else
g_assert (g_strv_contains (names, "text-plain"));
g_assert (g_strv_contains (names, "text-x-generic"));
g_assert_true (g_strv_contains (names, "text-plain"));
g_assert_true (g_strv_contains (names, "text-x-generic"));
#endif
}
g_object_unref (icon);
@ -245,15 +245,15 @@ test_icon (void)
type = g_content_type_from_mime_type ("application/rtf");
icon = g_content_type_get_icon (type);
g_assert (G_IS_ICON (icon));
g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
g_assert (g_strv_contains (names, "application-rtf"));
g_assert_true (g_strv_contains (names, "application-rtf"));
#ifndef __APPLE__
g_assert (g_strv_contains (names, "x-office-document"));
g_assert_true (g_strv_contains (names, "x-office-document"));
#endif
}
g_object_unref (icon);
@ -269,20 +269,20 @@ test_symbolic_icon (void)
type = g_content_type_from_mime_type ("text/plain");
icon = g_content_type_get_symbolic_icon (type);
g_assert (G_IS_ICON (icon));
g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
#ifdef __APPLE__
g_assert (g_strv_contains (names, "text-*-symbolic"));
g_assert (g_strv_contains (names, "text-*"));
g_assert_true (g_strv_contains (names, "text-*-symbolic"));
g_assert_true (g_strv_contains (names, "text-*"));
#else
g_assert (g_strv_contains (names, "text-plain-symbolic"));
g_assert (g_strv_contains (names, "text-x-generic-symbolic"));
g_assert (g_strv_contains (names, "text-plain"));
g_assert (g_strv_contains (names, "text-x-generic"));
g_assert_true (g_strv_contains (names, "text-plain-symbolic"));
g_assert_true (g_strv_contains (names, "text-x-generic-symbolic"));
g_assert_true (g_strv_contains (names, "text-plain"));
g_assert_true (g_strv_contains (names, "text-x-generic"));
#endif
}
g_object_unref (icon);
@ -290,17 +290,17 @@ test_symbolic_icon (void)
type = g_content_type_from_mime_type ("application/rtf");
icon = g_content_type_get_symbolic_icon (type);
g_assert (G_IS_ICON (icon));
g_assert_true (G_IS_ICON (icon));
if (G_IS_THEMED_ICON (icon))
{
const gchar *const *names;
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
g_assert (g_strv_contains (names, "application-rtf-symbolic"));
g_assert (g_strv_contains (names, "application-rtf"));
g_assert_true (g_strv_contains (names, "application-rtf-symbolic"));
g_assert_true (g_strv_contains (names, "application-rtf"));
#ifndef __APPLE__
g_assert (g_strv_contains (names, "x-office-document-symbolic"));
g_assert (g_strv_contains (names, "x-office-document"));
g_assert_true (g_strv_contains (names, "x-office-document-symbolic"));
g_assert_true (g_strv_contains (names, "x-office-document"));
#endif
}
g_object_unref (icon);