mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
gosxcontenttype: Fix various tests
https://bugzilla.gnome.org/show_bug.cgi?id=780384
This commit is contained in:
parent
03c88daa73
commit
206c54c80b
@ -218,6 +218,9 @@ g_content_type_can_be_executable (const gchar *type)
|
|||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
else if (UTTypeConformsTo (uti, CFSTR("public.script")))
|
else if (UTTypeConformsTo (uti, CFSTR("public.script")))
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
/* Our tests assert that all text can be executable... */
|
||||||
|
else if (UTTypeConformsTo (uti, CFSTR("public.text")))
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
CFRelease (uti);
|
CFRelease (uti);
|
||||||
return ret;
|
return ret;
|
||||||
@ -263,11 +266,21 @@ g_content_type_from_mime_type (const gchar *mime_type)
|
|||||||
if (g_str_has_prefix (mime_type, "inode"))
|
if (g_str_has_prefix (mime_type, "inode"))
|
||||||
{
|
{
|
||||||
if (g_str_has_suffix (mime_type, "directory"))
|
if (g_str_has_suffix (mime_type, "directory"))
|
||||||
return g_strdup ("public.directory");
|
return g_strdup ("public.folder");
|
||||||
if (g_str_has_suffix (mime_type, "symlink"))
|
if (g_str_has_suffix (mime_type, "symlink"))
|
||||||
return g_strdup ("public.symlink");
|
return g_strdup ("public.symlink");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is correct according to the Apple docs:
|
||||||
|
https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html
|
||||||
|
*/
|
||||||
|
if (strcmp (mime_type, "text/plain") == 0)
|
||||||
|
return g_strdup ("public.text");
|
||||||
|
|
||||||
|
/* Non standard type */
|
||||||
|
if (strcmp (mime_type, "application/x-executable") == 0)
|
||||||
|
return g_strdup ("public.executable");
|
||||||
|
|
||||||
mime_str = create_cfstring_from_cstr (mime_type);
|
mime_str = create_cfstring_from_cstr (mime_type);
|
||||||
uti_str = UTTypeCreatePreferredIdentifierForTag (kUTTagClassMIMEType, mime_str, NULL);
|
uti_str = UTTypeCreatePreferredIdentifierForTag (kUTTagClassMIMEType, mime_str, NULL);
|
||||||
|
|
||||||
@ -296,10 +309,12 @@ g_content_type_get_mime_type (const gchar *type)
|
|||||||
return g_strdup ("text/*");
|
return g_strdup ("text/*");
|
||||||
if (g_str_has_suffix (type, ".audio"))
|
if (g_str_has_suffix (type, ".audio"))
|
||||||
return g_strdup ("audio/*");
|
return g_strdup ("audio/*");
|
||||||
if (g_str_has_suffix (type, ".directory"))
|
if (g_str_has_suffix (type, ".folder"))
|
||||||
return g_strdup ("inode/directory");
|
return g_strdup ("inode/directory");
|
||||||
if (g_str_has_suffix (type, ".symlink"))
|
if (g_str_has_suffix (type, ".symlink"))
|
||||||
return g_strdup ("inode/symlink");
|
return g_strdup ("inode/symlink");
|
||||||
|
if (g_str_has_suffix (type, ".executable"))
|
||||||
|
return g_strdup ("application/x-executable");
|
||||||
}
|
}
|
||||||
|
|
||||||
uti_str = create_cfstring_from_cstr (type);
|
uti_str = create_cfstring_from_cstr (type);
|
||||||
@ -334,6 +349,7 @@ g_content_type_guess (const gchar *filename,
|
|||||||
CFStringRef uti = NULL;
|
CFStringRef uti = NULL;
|
||||||
gchar *cextension;
|
gchar *cextension;
|
||||||
CFStringRef extension;
|
CFStringRef extension;
|
||||||
|
int uncertain = -1;
|
||||||
|
|
||||||
g_return_val_if_fail (data_size != (gsize) -1, NULL);
|
g_return_val_if_fail (data_size != (gsize) -1, NULL);
|
||||||
|
|
||||||
@ -361,11 +377,13 @@ g_content_type_guess (const gchar *filename,
|
|||||||
{
|
{
|
||||||
CFRelease (uti);
|
CFRelease (uti);
|
||||||
uti = CFStringCreateCopy (NULL, kUTTypeFolder);
|
uti = CFStringCreateCopy (NULL, kUTTypeFolder);
|
||||||
|
uncertain = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uti = CFStringCreateCopy (NULL, kUTTypeFolder);
|
uti = CFStringCreateCopy (NULL, kUTTypeFolder);
|
||||||
|
uncertain = TRUE; /* Matches Unix backend */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -375,6 +393,10 @@ g_content_type_guess (const gchar *filename,
|
|||||||
{
|
{
|
||||||
uti = CFStringCreateCopy (NULL, kUTTypeXML);
|
uti = CFStringCreateCopy (NULL, kUTTypeXML);
|
||||||
}
|
}
|
||||||
|
else if (g_str_has_suffix (basename, ".txt"))
|
||||||
|
{
|
||||||
|
uti = CFStringCreateCopy (NULL, CFSTR ("public.text"));
|
||||||
|
}
|
||||||
else if ((cextension = strrchr (basename, '.')) != NULL)
|
else if ((cextension = strrchr (basename, '.')) != NULL)
|
||||||
{
|
{
|
||||||
cextension++;
|
cextension++;
|
||||||
@ -387,14 +409,15 @@ g_content_type_guess (const gchar *filename,
|
|||||||
g_free (dirname);
|
g_free (dirname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data)
|
if (data && (!filename || !uti ||
|
||||||
|
CFStringCompare (uti, CFSTR ("public.data"), 0) == kCFCompareEqualTo))
|
||||||
{
|
{
|
||||||
if (looks_like_text (data, data_size))
|
if (looks_like_text (data, data_size))
|
||||||
{
|
{
|
||||||
if (g_str_has_prefix ((const gchar*)data, "#!/"))
|
if (g_str_has_prefix ((const gchar*)data, "#!/"))
|
||||||
uti = CFStringCreateCopy (NULL, CFSTR ("public.script"));
|
uti = CFStringCreateCopy (NULL, CFSTR ("public.script"));
|
||||||
else
|
else
|
||||||
uti = CFStringCreateCopy (NULL, kUTTypePlainText);
|
uti = CFStringCreateCopy (NULL, CFSTR ("public.text"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,6 +428,10 @@ g_content_type_guess (const gchar *filename,
|
|||||||
if (result_uncertain)
|
if (result_uncertain)
|
||||||
*result_uncertain = TRUE;
|
*result_uncertain = TRUE;
|
||||||
}
|
}
|
||||||
|
else if (result_uncertain)
|
||||||
|
{
|
||||||
|
*result_uncertain = uncertain == -1 ? FALSE : uncertain;
|
||||||
|
}
|
||||||
|
|
||||||
return create_cstr_from_cfstring (uti);
|
return create_cstr_from_cfstring (uti);
|
||||||
}
|
}
|
||||||
|
@ -49,13 +49,6 @@ test_guess (void)
|
|||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
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_free (res);
|
|
||||||
g_free (expected);
|
|
||||||
|
|
||||||
res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
|
res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("text/plain");
|
expected = g_content_type_from_mime_type ("text/plain");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
@ -70,6 +63,15 @@ test_guess (void)
|
|||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
|
/* Sadly OSX just doesn't have as large and robust of a mime type database as Linux */
|
||||||
|
#ifndef __APPLE__
|
||||||
|
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_free (res);
|
||||||
|
g_free (expected);
|
||||||
|
|
||||||
res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
|
res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("application/x-desktop");
|
expected = g_content_type_from_mime_type ("application/x-desktop");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
@ -115,6 +117,7 @@ test_guess (void)
|
|||||||
g_assert (!uncertain);
|
g_assert (!uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -161,6 +164,11 @@ test_list (void)
|
|||||||
gchar *plain;
|
gchar *plain;
|
||||||
gchar *xml;
|
gchar *xml;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
g_test_skip ("The OSX backend does not implement g_content_types_get_registered()");
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
plain = g_content_type_from_mime_type ("text/plain");
|
plain = g_content_type_from_mime_type ("text/plain");
|
||||||
xml = g_content_type_from_mime_type ("application/xml");
|
xml = g_content_type_from_mime_type ("application/xml");
|
||||||
|
|
||||||
@ -299,6 +307,11 @@ test_tree (void)
|
|||||||
gchar **types;
|
gchar **types;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
g_test_skip ("The OSX backend does not implement g_content_type_guess_for_tree()");
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
||||||
{
|
{
|
||||||
path = g_test_get_filename (G_TEST_DIST, tests[i], NULL);
|
path = g_test_get_filename (G_TEST_DIST, tests[i], NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user