[glib] Add some contenttype tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add some contenttype tests
- Date: Mon, 5 Jul 2010 04:57:36 +0000 (UTC)
commit 14db75381ee7f21f6b62401177cfaa9d6891ddf4
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jul 4 22:27:01 2010 -0400
Add some contenttype tests
gio/tests/Makefile.am | 4 ++
gio/tests/contenttype.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 927900b..552f351 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -80,6 +80,7 @@ SAMPLE_PROGS = \
testapp \
appinfo-test \
icons \
+ contenttype \
$(NULL)
@@ -276,6 +277,9 @@ testapps_LDADD = $(progs_ldadd)
icons_SOURCES = icons.c
icons_LDADD = $(progs_ldadd)
+contenttype_SOURCES = contenttype.c
+contenttype_LDADD = $(progs_ldadd)
+
schema_tests = \
schema-tests/array-default-not-in-choices.gschema.xml \
schema-tests/bad-choice.gschema.xml \
diff --git a/gio/tests/contenttype.c b/gio/tests/contenttype.c
new file mode 100644
index 0000000..5c015a2
--- /dev/null
+++ b/gio/tests/contenttype.c
@@ -0,0 +1,113 @@
+#include <gio/gio.h>
+
+static void
+test_guess (void)
+{
+ gchar *res;
+ gchar *expected;
+ gboolean uncertain;
+
+ res = g_content_type_guess ("/etc/", NULL, 0, &uncertain);
+ expected = g_content_type_from_mime_type ("inode/directory");
+ g_assert (g_content_type_equals (expected, res));
+ g_free (res);
+ g_free (expected);
+
+ res = g_content_type_guess ("foo.txt", NULL, 0, &uncertain);
+ expected = g_content_type_from_mime_type ("text/plain");
+ g_assert (g_content_type_equals (expected, res));
+ g_free (res);
+ g_free (expected);
+}
+
+static void
+test_unknown (void)
+{
+ gchar *unknown;
+ gchar *str;
+
+ unknown = g_content_type_from_mime_type ("application/octet-stream");
+ g_assert (g_content_type_is_unknown (unknown));
+ str = g_content_type_get_mime_type (unknown);
+ g_assert_cmpstr (str, ==, "application/octet-stream");
+ g_free (str);
+ g_free (unknown);
+}
+
+static void
+test_subtype (void)
+{
+ gchar *plain;
+ gchar *xml;
+
+ 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_free (plain);
+ g_free (xml);
+}
+
+static gint
+find_mime (gconstpointer a, gconstpointer b)
+{
+ if (g_content_type_equals (a, b))
+ return 0;
+ return 1;
+}
+
+static void
+test_list (void)
+{
+ GList *types;
+ gchar *plain;
+ gchar *xml;
+
+ plain = g_content_type_from_mime_type ("text/plain");
+ xml = g_content_type_from_mime_type ("application/xml");
+
+ types = g_content_types_get_registered ();
+
+ g_assert (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_list_foreach (types, (GFunc)g_free, NULL);
+ g_list_free (types);
+
+ g_free (plain);
+ g_free (xml);
+}
+
+static void
+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_free (type);
+
+ type = g_content_type_from_mime_type ("text/plain");
+ g_assert (g_content_type_can_be_executable (type));
+ g_free (type);
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_type_init ();
+
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/contenttype/guess", test_guess);
+ g_test_add_func ("/contenttype/unknown", test_unknown);
+ g_test_add_func ("/contenttype/subtype", test_subtype);
+ g_test_add_func ("/contenttype/list", test_list);
+ g_test_add_func ("/contenttype/executable", test_executable);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]