[gnome-scan] Tests module filename validation



commit 6e9deee60f33b45c73217983560207963aa8ef2e
Author: Ã?tienne Bersac <bersace gnome org>
Date:   Sat Feb 20 22:31:25 2010 +0100

    Tests module filename validation

 lib/gnome-scan-module-manager.vala |   16 +++---
 lib/tests/Makefile.am              |    4 ++
 lib/tests/module.c                 |   97 ++++++++++++++++++++++++++++++++++++
 lib/tests/options.c                |    4 +-
 4 files changed, 112 insertions(+), 9 deletions(-)
---
diff --git a/lib/gnome-scan-module-manager.vala b/lib/gnome-scan-module-manager.vala
index 6b69c0c..4a2b593 100644
--- a/lib/gnome-scan-module-manager.vala
+++ b/lib/gnome-scan-module-manager.vala
@@ -64,7 +64,14 @@ namespace Gnome.Scan {
 			this.path = path;
 		}
 
-		string module_name_from_filename(string filename) throws ModuleError {
+		public static bool is_valid_module_name (string name)
+		{
+			return name.has_prefix ("lib")
+			&& (name.has_suffix (GLib.Module.SUFFIX)
+				|| name.has_suffix (".la"));
+		}
+
+		public static string module_name_from_filename(string filename) throws ModuleError {
 			try {
 				string name;
 				var regex = new Regex ("lib(.*)\\..*$");
@@ -151,12 +158,5 @@ namespace Gnome.Scan {
 			foreach (TypeModule module in modules)
 			module.unuse ();
 		}
-
-		private static bool is_valid_module_name (string name)
-		{
-			return name.has_prefix ("lib")
-			&& (name.has_suffix (GLib.Module.SUFFIX)
-				|| name.has_suffix (".la"));
-		}
 	}
 }
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index 1976e4f..e382580 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -14,3 +14,7 @@ noinst_PROGRAMS = $(TEST_PROGS)
 TEST_PROGS	+= options
 options_SOURCES	 = options.c
 options_LDADD	 = $(LIBS)
+
+TEST_PROGS	+= module
+module_SOURCES	 = module.c
+module_LDADD	 = $(LIBS)
diff --git a/lib/tests/module.c b/lib/tests/module.c
new file mode 100644
index 0000000..221223b
--- /dev/null
+++ b/lib/tests/module.c
@@ -0,0 +1,97 @@
+/* GNOME Scan - Scan as easy as you print
+ * Copyright © 2006-2008  �tienne Bersac <bersace gnome org>
+ *
+ * GNOME Scan is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * GNOME Scan 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GNOME Scan. If not, write to:
+ *
+ *	the Free Software Foundation, Inc.
+ *	51 Franklin Street, Fifth Floor
+ *	Boston, MA 02110-1301, USA
+ */
+
+#include <glib.h>
+#include <gnome-scan.h>
+
+static void
+name_extract ()
+{
+	gchar* name;
+	GError *error = NULL;
+
+	name = gnome_scan_module_manager_module_name_from_filename("libgsane.so", &error);
+
+	g_assert_no_error(error);
+	g_assert_cmpstr(name, ==, "gsane");
+
+	g_free (name);
+}
+
+static void
+name_validate_so ()
+{
+	const gchar* name = "libgsane.so";
+	gboolean valid;
+
+	valid = gnome_scan_module_manager_is_valid_module_name(name);
+
+	g_assert (valid);
+}
+
+static void
+name_validate_la ()
+{
+	const gchar* name = "libgsane.la";
+	gboolean valid;
+
+	valid = gnome_scan_module_manager_is_valid_module_name(name);
+
+	g_assert (valid);
+}
+
+static void
+name_validate_a ()
+{
+	const gchar* name = "libgsane.a";
+	gboolean valid;
+
+	valid = gnome_scan_module_manager_is_valid_module_name(name);
+
+	g_assert (!valid);
+}
+
+static void
+name_validate_not_lib ()
+{
+	const gchar* name = "gsane.a";
+	gboolean valid;
+
+	valid = gnome_scan_module_manager_is_valid_module_name(name);
+
+	g_assert (!valid);
+}
+
+
+gint
+main(gint argc, gchar**argv)
+{
+	g_set_prgname("module");
+	g_type_init();
+	g_test_init(&argc, &argv, NULL);
+	gnome_scan_init(&argc, &argv);
+	g_test_add_func("/module/name/extract", name_extract);
+	g_test_add_func("/module/name/validate/so", name_validate_so);
+	g_test_add_func("/module/name/validate/la", name_validate_la);
+	g_test_add_func("/module/name/validate/a", name_validate_a);
+	g_test_add_func("/module/name/validate/not_lib", name_validate_not_lib);
+	return g_test_run();
+}
diff --git a/lib/tests/options.c b/lib/tests/options.c
index e3e6629..7a5461e 100644
--- a/lib/tests/options.c
+++ b/lib/tests/options.c
@@ -19,10 +19,12 @@
  *	Boston, MA 02110-1301, USA
  */
 
-#include <glib.h>
+#include <glib-object.h>
 
 gint main(gint argc, gchar**argv)
 {
+	g_set_prgname("options");
+	g_type_init();
 	g_test_init(&argc, &argv, NULL);
 	return g_test_run();
 }



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