From 6c75ba2b902602c90fe239346e557aa1284eb667 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 23 Dec 2013 12:11:03 -0500 Subject: [PATCH] Add tests for x-content type sniffing This test exercises the tree matching parts of gcontenttype.c --- gio/tests/Makefile.am | 4 +++ gio/tests/contenttype.c | 31 +++++++++++++++++++ .../image-dcf/DCIM/Camera/20130831_203925.jpg | 0 .../image-dcf/DCIM/Camera/20130831_203928.jpg | 0 gio/tests/x-content/unix-software/autorun.sh | 3 ++ .../x-content/win32-software/autorun.exe | 0 6 files changed, 38 insertions(+) create mode 100644 gio/tests/x-content/image-dcf/DCIM/Camera/20130831_203925.jpg create mode 100644 gio/tests/x-content/image-dcf/DCIM/Camera/20130831_203928.jpg create mode 100644 gio/tests/x-content/unix-software/autorun.sh create mode 100755 gio/tests/x-content/win32-software/autorun.exe diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index b3e51efda..d3a2162c7 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -299,6 +299,10 @@ dist_test_data += \ appinfo-test2.desktop \ file.c \ org.gtk.test.dbusappinfo.desktop \ + x-content/image-dcf/DCIM/Camera/20130831_203925.jpg \ + x-content/image-dcf/DCIM/Camera/20130831_203928.jpg \ + x-content/unix-software/autorun.sh \ + x-content/win32-software/autorun.exe \ $(NULL) test_extra_programs += \ diff --git a/gio/tests/contenttype.c b/gio/tests/contenttype.c index 645bddcc1..aa8ff8281 100644 --- a/gio/tests/contenttype.c +++ b/gio/tests/contenttype.c @@ -97,6 +97,13 @@ test_guess (void) g_assert (!uncertain); g_free (res); g_free (expected); + + 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_free (res); + g_free (expected); } static void @@ -211,6 +218,29 @@ test_icon (void) g_free (type); } +static void +test_tree (void) +{ + const gchar *tests[] = { + "x-content/image-dcf", + "x-content/unix-software", + "x-content/win32-software" + }; + const gchar *path; + GFile *file; + gchar **types; + gint i; + + for (i = 0; i < G_N_ELEMENTS (tests); i++) + { + path = g_test_get_filename (G_TEST_DIST, tests[i], NULL); + file = g_file_new_for_path (path); + types = g_content_type_guess_for_tree (file); + g_assert_content_type_equals (types[0], tests[i]); + g_strfreev (types); + g_object_unref (file); + } +} int main (int argc, char *argv[]) @@ -224,6 +254,7 @@ main (int argc, char *argv[]) g_test_add_func ("/contenttype/executable", test_executable); g_test_add_func ("/contenttype/description", test_description); g_test_add_func ("/contenttype/icon", test_icon); + g_test_add_func ("/contenttype/tree", test_tree); return g_test_run (); } diff --git a/gio/tests/x-content/image-dcf/DCIM/Camera/20130831_203925.jpg b/gio/tests/x-content/image-dcf/DCIM/Camera/20130831_203925.jpg new file mode 100644 index 000000000..e69de29bb diff --git a/gio/tests/x-content/image-dcf/DCIM/Camera/20130831_203928.jpg b/gio/tests/x-content/image-dcf/DCIM/Camera/20130831_203928.jpg new file mode 100644 index 000000000..e69de29bb diff --git a/gio/tests/x-content/unix-software/autorun.sh b/gio/tests/x-content/unix-software/autorun.sh new file mode 100644 index 000000000..6dfc55944 --- /dev/null +++ b/gio/tests/x-content/unix-software/autorun.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +do something here diff --git a/gio/tests/x-content/win32-software/autorun.exe b/gio/tests/x-content/win32-software/autorun.exe new file mode 100755 index 000000000..e69de29bb