Back to index

libcitadel  8.12
test-mime.c
Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2003,2004  Red Hat, Inc.
00003  * Copyright (C) 2003,2004  Jonathan Blandford <jrb@alum.mit.edu>
00004  *
00005  * Licensed under the Academic Free License version 2.0
00006  * Or under the following terms:
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021  * Boston, MA 02111-1307, USA.
00022  */
00023 #include "xdgmime.h"
00024 #include "xdgmimeglob.h"
00025 #include <string.h>
00026 #include <stdio.h>
00027 
00028 
00029 static void
00030 test_individual_glob (const char  *glob,
00031                     XdgGlobType  expected_type)
00032 {
00033   XdgGlobType test_type;
00034 
00035   test_type = _xdg_glob_determine_type (glob);
00036   if (test_type != expected_type)
00037     {
00038       printf ("Test Failed: %s is of type %s, but %s is expected\n",
00039              glob,
00040              ((test_type == XDG_GLOB_LITERAL)?"XDG_GLOB_LITERAL":
00041               ((test_type == XDG_GLOB_SIMPLE)?"XDG_GLOB_SIMPLE":"XDG_GLOB_FULL")),
00042              ((expected_type == XDG_GLOB_LITERAL)?"XDG_GLOB_LITERAL":
00043               ((expected_type == XDG_GLOB_SIMPLE)?"XDG_GLOB_SIMPLE":"XDG_GLOB_COMPLEX")));
00044     }
00045 }
00046 
00047 static void
00048 test_glob_type (void)
00049 {
00050   test_individual_glob ("*.gif", XDG_GLOB_SIMPLE);
00051   test_individual_glob ("Foo*.gif", XDG_GLOB_FULL);
00052   test_individual_glob ("*[4].gif", XDG_GLOB_FULL);
00053   test_individual_glob ("Makefile", XDG_GLOB_LITERAL);
00054   test_individual_glob ("sldkfjvlsdf\\\\slkdjf", XDG_GLOB_FULL);
00055   test_individual_glob ("tree.[ch]", XDG_GLOB_FULL);
00056 }
00057 
00058 static void
00059 test_alias (const char *mime_a,
00060            const char *mime_b,
00061            int         expected)
00062 {
00063   int actual;
00064 
00065   actual = xdg_mime_mime_type_equal (mime_a, mime_b);
00066 
00067   if (actual != expected)
00068     {
00069       printf ("Test Failed: %s is %s to %s\n", 
00070              mime_a, actual ? "equal" : "not equal", mime_b);
00071     }
00072 }
00073 
00074 static void
00075 test_aliasing (void)
00076 {
00077   test_alias ("application/wordperfect", "application/vnd.wordperfect", 1);
00078   test_alias ("application/x-gnome-app-info", "application/x-desktop", 1);
00079   test_alias ("application/x-wordperfect", "application/vnd.wordperfect", 1);
00080   test_alias ("application/x-wordperfect", "audio/x-midi", 0);
00081   test_alias ("/", "vnd/vnd", 0);
00082   test_alias ("application/octet-stream", "text/plain", 0);
00083   test_alias ("text/plain", "text/*", 0);
00084 }
00085 
00086 static void
00087 test_subclass (const char *mime_a,
00088               const char *mime_b,
00089               int         expected)
00090 {
00091   int actual;
00092 
00093   actual = xdg_mime_mime_type_subclass (mime_a, mime_b);
00094 
00095   if (actual != expected)
00096     {
00097       printf ("Test Failed: %s is %s of %s\n", 
00098              mime_a, actual ? "subclass" : "not subclass", mime_b);
00099     }
00100 }
00101 
00102 static void
00103 test_subclassing (void)
00104 {
00105   test_subclass ("application/rtf", "text/plain", 1);
00106   test_subclass ("message/news", "text/plain", 1);
00107   test_subclass ("message/news", "message/*", 1);
00108   test_subclass ("message/news", "text/*", 1);
00109   test_subclass ("message/news", "application/octet-stream", 1);
00110   test_subclass ("application/rtf", "application/octet-stream", 1);
00111   test_subclass ("application/x-gnome-app-info", "text/plain", 1);
00112   test_subclass ("image/x-djvu", "image/vnd.djvu", 1);
00113   test_subclass ("image/vnd.djvu", "image/x-djvu", 1);
00114   test_subclass ("image/vnd.djvu", "text/plain", 0);
00115   test_subclass ("image/vnd.djvu", "text/*", 0);
00116   test_subclass ("text/*", "text/plain", 0);
00117 }
00118 
00119 int
00120 main (int argc, char *argv[])
00121 {
00122   const char *result;
00123   const char *file_name;
00124   int i;
00125 
00126   test_glob_type ();
00127   test_aliasing ();
00128   test_subclassing ();
00129 
00130   for (i = 1; i < argc; i++)
00131     {
00132       file_name = argv[i];
00133       result = xdg_mime_get_mime_type_for_file (file_name, NULL);
00134       printf ("File \"%s\" has a mime-type of %s\n", file_name, result);
00135     }
00136 
00137 #if 0
00138   xdg_mime_dump ();
00139 #endif
00140   return 0;
00141 }
00142