[gegl] Make extension comparisions case insensitive



commit c3bc22cc4561b268eb03a34a2c0235fc2c049604
Author: Martin Nordholts <martinn src gnome org>
Date:   Tue May 11 21:04:06 2010 +0200

    Make extension comparisions case insensitive
    
    Make gegl_extension_handler_register() extension comparisions case
    insensitive and add a test case for it.

 gegl/operation/gegl-extension-handler.c |   14 ++++++--
 tests/.gitignore                        |    1 +
 tests/Makefile.am                       |    5 ++-
 tests/test-misc.c                       |   54 +++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 5 deletions(-)
---
diff --git a/gegl/operation/gegl-extension-handler.c b/gegl/operation/gegl-extension-handler.c
index 52e3ec7..9b15dbc 100644
--- a/gegl/operation/gegl-extension-handler.c
+++ b/gegl/operation/gegl-extension-handler.c
@@ -26,21 +26,29 @@ void
 gegl_extension_handler_register (const gchar *extension,
                                  const gchar *handler)
 {
+  /* Case fold so we get case insensitive extension comparisions */
+  gchar *ext = g_utf8_casefold (extension, -1);
+
   if (!handlers)
     handlers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
-  g_hash_table_insert (handlers, g_strdup (extension), g_strdup (handler));
+  g_hash_table_insert (handlers, ext, g_strdup (handler));
 }
 
 const gchar *
 gegl_extension_handler_get (const gchar *extension)
 {
-  const gchar *handler;
+  const gchar *handler = NULL;
+  gchar *ext = NULL;
 
   if (!handlers)
     return NULL;
 
-  handler = g_hash_table_lookup (handlers, extension);
+  /* Case fold so we get case insensitive extension comparisions */
+  ext = g_utf8_casefold (extension, -1);
+  handler = g_hash_table_lookup (handlers, ext);
+  g_free (ext);
+
   if (handler)
     return handler;
 
diff --git a/tests/.gitignore b/tests/.gitignore
index 041e596..cf352bf 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -7,4 +7,5 @@
 /test-change-processor-rect*
 /test-color-op*
 /test-gegl-rectangle*
+/test-misc*
 /test-proxynop-processing*
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7165a33..c801ca0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,9 +7,10 @@ TESTS_ENVIRONMENT = \
 # The tests
 TESTS = \
 	test-change-processor-rect	\
-	test-proxynop-processing	\
 	test-color-op			\
-	test-gegl-rectangle
+	test-gegl-rectangle		\
+	test-misc			\
+	test-proxynop-processing
 noinst_PROGRAMS = $(TESTS)
 
 # Common CPPFLAGS
diff --git a/tests/test-misc.c b/tests/test-misc.c
new file mode 100644
index 0000000..5a660bd
--- /dev/null
+++ b/tests/test-misc.c
@@ -0,0 +1,54 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2010 Martin Nordholts
+ */
+
+#include "config.h"
+
+#include "gegl.h"
+#include "gegl-plugin.h"
+
+#define SUCCESS  0
+#define FAILURE -1
+
+static int
+test_misc_case_insensitive_extension_handler (void)
+{
+  gint result = SUCCESS;
+  const gchar *handler = "gegl:foo-handler";
+  const gchar *lowercase = "fooext";
+  const gchar *uppercase = "FOOEXT";
+  const gchar *received_handler = NULL;
+
+  gegl_extension_handler_register (lowercase, handler);
+
+  /* Make sure comparisions are case insensitive */
+  received_handler = gegl_extension_handler_get (uppercase);
+  if (! strcmp (received_handler, handler) == 0)
+    result = FAILURE;
+
+  return result;
+}
+
+
+int main(int argc, char *argv[])
+{
+  gint result = SUCCESS;
+
+  if (result == SUCCESS)
+    result = test_misc_case_insensitive_extension_handler ();
+
+  return result;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]